Skip to content

Commit fe68e0d

Browse files
committed
verification: cocotb: common: utils: Reimplemented target_test and controller_test to be cocotb.test-based decorator classes
Signed-off-by: Grzegorz Latosinski <[email protected]>
1 parent afadd10 commit fe68e0d

File tree

1 file changed

+44
-52
lines changed

1 file changed

+44
-52
lines changed

verification/cocotb/common/utils.py

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,72 +16,64 @@
1616
_T = TypeVar("_T")
1717

1818

19-
def target_test(
20-
timeout_time=None,
21-
timeout_unit="step",
22-
expect_fail=False,
23-
expect_error=(),
24-
skip=False,
25-
stage=0,
26-
):
19+
class target_test(cocotb.test):
2720
"""
2821
Custom decorator wrapping cocotb.test to automatically skip test when its run without
2922
I3C target support configured.
3023
Has an effect only when test suite is executed within nox session.
3124
"""
32-
if os.getenv("NOX_SESSION", False):
33-
skip = any([skip, "TargetSupport" not in cocotb.plusargs])
34-
35-
def wrapper(func):
36-
@cocotb.test(
37-
timeout_time=timeout_time,
38-
timeout_unit=timeout_unit,
39-
expect_fail=expect_fail,
40-
expect_error=expect_error,
41-
skip=skip,
42-
stage=stage,
25+
def __init__(
26+
self,
27+
f,
28+
timeout_time=None,
29+
timeout_unit="step",
30+
expect_fail=False,
31+
expect_error=(),
32+
skip=False,
33+
stage=0,
34+
):
35+
if os.getenv("NOX_SESSION", False):
36+
skip = any([skip, "TargetSupport" not in cocotb.plusargs])
37+
38+
super().__init__(
39+
f,
40+
timeout_time,
41+
timeout_unit,
42+
expect_fail,
43+
expect_error,
44+
skip,
45+
stage
4346
)
44-
@functools.wraps(func)
45-
async def run(*args, **kwargs):
46-
await func(*args, **kwargs)
47-
48-
return run
49-
50-
return wrapper
5147

5248

53-
def controller_test(
54-
timeout_time=None,
55-
timeout_unit="step",
56-
expect_fail=False,
57-
expect_error=(),
58-
skip=False,
59-
stage=0,
60-
):
49+
class controller_test(cocotb.test):
6150
"""
6251
Custom decorator wrapping cocotb.test to automatically skip test when its run without
6352
I3C controller support configured.
6453
Has an effect only when test suite is executed within nox session.
6554
"""
66-
if os.getenv("NOX_SESSION", False):
67-
skip = any([skip, "ControllerSupport" not in cocotb.plusargs])
68-
69-
def wrapper(func):
70-
@cocotb.test(
71-
timeout_time=timeout_time,
72-
timeout_unit=timeout_unit,
73-
expect_fail=expect_fail,
74-
expect_error=expect_error,
75-
skip=skip,
76-
stage=stage,
55+
def __init__(
56+
self,
57+
f,
58+
timeout_time=None,
59+
timeout_unit="step",
60+
expect_fail=False,
61+
expect_error=(),
62+
skip=False,
63+
stage=0,
64+
):
65+
if os.getenv("NOX_SESSION", False):
66+
skip = any([skip, "ControllerSupport" not in cocotb.plusargs])
67+
68+
super().__init__(
69+
f,
70+
timeout_time,
71+
timeout_unit,
72+
expect_fail,
73+
expect_error,
74+
skip,
75+
stage
7776
)
78-
@functools.wraps(func)
79-
async def run(*args, **kwargs):
80-
await func(*args, **kwargs)
81-
82-
return run
83-
84-
return wrapper
8577

8678

8779
def get_current_time_ns():

0 commit comments

Comments
 (0)