Skip to content

Commit

Permalink
crypto: ccp - Fix ioctl unit tests
Browse files Browse the repository at this point in the history
A local environment change was importing ioctl_opt which is required
for ioctl tests to pass.  Add the missing import for it.

Fixes: 15f8aa7 ("crypto: ccp - Add unit tests for dynamic boost control")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Mario Limonciello authored and Herbert Xu committed Sep 15, 2023
1 parent 53f7f77 commit 7f71c3e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tools/crypto/ccp/test_dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import os
import time
import glob
import fcntl
try:
import ioctl_opt as ioctl
except ImportError:
ioctl = None
pass
from dbc import *

# Artificial delay between set commands
Expand Down Expand Up @@ -64,13 +70,16 @@ def __init__(self, data) -> None:
def setUp(self) -> None:
if not os.path.exists(DEVICE_NODE):
self.skipTest("system is unsupported")
if not ioctl:
self.skipTest("unable to test IOCTLs without ioctl_opt")

return super().setUp()

def test_invalid_nonce_ioctl(self) -> None:
"""tries to call get_nonce ioctl with invalid data structures"""

# 0x1 (get nonce), and invalid data
INVALID1 = IOWR(ord("D"), 0x01, invalid_param)
INVALID1 = ioctl.IOWR(ord("D"), 0x01, invalid_param)
with self.assertRaises(OSError) as error:
fcntl.ioctl(self.d, INVALID1, self.data, True)
self.assertEqual(error.exception.errno, 22)
Expand All @@ -79,7 +88,7 @@ def test_invalid_setuid_ioctl(self) -> None:
"""tries to call set_uid ioctl with invalid data structures"""

# 0x2 (set uid), and invalid data
INVALID2 = IOW(ord("D"), 0x02, invalid_param)
INVALID2 = ioctl.IOW(ord("D"), 0x02, invalid_param)
with self.assertRaises(OSError) as error:
fcntl.ioctl(self.d, INVALID2, self.data, True)
self.assertEqual(error.exception.errno, 22)
Expand All @@ -88,23 +97,23 @@ def test_invalid_setuid_rw_ioctl(self) -> None:
"""tries to call set_uid ioctl with invalid data structures"""

# 0x2 as RW (set uid), and invalid data
INVALID3 = IOWR(ord("D"), 0x02, invalid_param)
INVALID3 = ioctl.IOWR(ord("D"), 0x02, invalid_param)
with self.assertRaises(OSError) as error:
fcntl.ioctl(self.d, INVALID3, self.data, True)
self.assertEqual(error.exception.errno, 22)

def test_invalid_param_ioctl(self) -> None:
"""tries to call param ioctl with invalid data structures"""
# 0x3 (param), and invalid data
INVALID4 = IOWR(ord("D"), 0x03, invalid_param)
INVALID4 = ioctl.IOWR(ord("D"), 0x03, invalid_param)
with self.assertRaises(OSError) as error:
fcntl.ioctl(self.d, INVALID4, self.data, True)
self.assertEqual(error.exception.errno, 22)

def test_invalid_call_ioctl(self) -> None:
"""tries to call the DBC ioctl with invalid data structures"""
# 0x4, and invalid data
INVALID5 = IOWR(ord("D"), 0x04, invalid_param)
INVALID5 = ioctl.IOWR(ord("D"), 0x04, invalid_param)
with self.assertRaises(OSError) as error:
fcntl.ioctl(self.d, INVALID5, self.data, True)
self.assertEqual(error.exception.errno, 22)
Expand Down

0 comments on commit 7f71c3e

Please sign in to comment.