1
1
# SPDX-License-Identifier: Apache-2.0
2
2
3
+ import functools
3
4
import logging
4
5
import random
5
6
from math import ceil
17
18
TARGET_ADDRESS = 0x5A
18
19
19
20
20
- async def timeout_task (timeout_us = 5 ):
21
- """
22
- A generic task for handling test timeout. Waits a fixed amount of
23
- simulation time and then throws an exception.
24
- """
25
- await Timer (timeout_us , "us" )
26
- raise TimeoutError ("Timeout!" )
21
+ # Wraps cocotb.test with a default timeout
22
+ def cocotb_test (timeout = 200 , unit = "us" , expect_fail = False , expect_error = (), skip = False , stage = 0 ):
23
+ def wrapper (func ):
24
+ @cocotb .test (
25
+ timeout_time = timeout ,
26
+ timeout_unit = unit ,
27
+ expect_fail = expect_fail ,
28
+ expect_error = expect_error ,
29
+ skip = skip ,
30
+ stage = stage ,
31
+ )
32
+ @functools .wraps (func )
33
+ async def runCocotb (* args , ** kwargs ):
34
+ await func (* args , ** kwargs )
35
+
36
+ return runCocotb
37
+ return wrapper
27
38
28
39
29
40
async def test_setup (dut , fclk = 100.0 , fbus = 12.5 ):
@@ -32,7 +43,6 @@ async def test_setup(dut, fclk=100.0, fbus=12.5):
32
43
"""
33
44
34
45
cocotb .log .setLevel (logging .INFO )
35
- cocotb .start_soon (timeout_task (200 ))
36
46
37
47
dut ._log .info (f"fclk = { fclk :.3f} MHz" )
38
48
dut ._log .info (f"fbus = { fbus :.3f} MHz" )
@@ -89,7 +99,7 @@ async def test_setup(dut, fclk=100.0, fbus=12.5):
89
99
return i3c_controller , i3c_target , tb
90
100
91
101
92
- @cocotb . test ()
102
+ @cocotb_test ()
93
103
async def test_i3c_target_write (dut ):
94
104
95
105
test_data = [[0xAA , 0x00 , 0xBB , 0xCC , 0xDD ], [0xDE , 0xAD , 0xBA , 0xBE ]]
@@ -178,7 +188,7 @@ async def rx_agent():
178
188
assert test_data == recv_data
179
189
180
190
181
- @cocotb . test ()
191
+ @cocotb_test ()
182
192
async def test_i3c_target_read (dut ):
183
193
184
194
# Setup
@@ -268,7 +278,7 @@ def compare(expected, received, lnt=None):
268
278
compare (tx_data , rx_data )
269
279
270
280
271
- @cocotb . test ()
281
+ @cocotb_test ()
272
282
async def test_i3c_target_ibi (dut ):
273
283
"""
274
284
IBI test. Sends an IBI with no data and then subsequently IBIs with
@@ -357,7 +367,7 @@ async def test_i3c_target_ibi(dut):
357
367
assert result
358
368
359
369
360
- @cocotb . test ()
370
+ @cocotb_test ()
361
371
async def test_i3c_target_ibi_retry (dut ):
362
372
"""
363
373
Disables IBI ACK-ing in controller, sends an IBI, waits some time for the
@@ -432,7 +442,7 @@ async def test_i3c_target_ibi_retry(dut):
432
442
assert result
433
443
434
444
435
- @cocotb . test ()
445
+ @cocotb_test ()
436
446
async def test_i3c_target_ibi_data (dut ):
437
447
"""
438
448
Set a limit on how many IBI data bytes the controller may accept. Issue
@@ -497,7 +507,7 @@ async def test_i3c_target_ibi_data(dut):
497
507
assert result
498
508
499
509
500
- @cocotb . test ()
510
+ @cocotb_test ()
501
511
async def test_i3c_target_writes_and_reads (dut ):
502
512
503
513
# Setup
@@ -578,7 +588,7 @@ async def test_i3c_target_writes_and_reads(dut):
578
588
assert tx_test_data == recv_data
579
589
580
590
581
- @cocotb . test ()
591
+ @cocotb_test ()
582
592
async def test_i3c_target_pwrite_err_detection (dut ):
583
593
I3C_DIRECT_GETSTATUS = 0x90
584
594
TRANSFER_LENGTH = 4
0 commit comments