Skip to content

Commit d50c0ac

Browse files
wkkunakgugala
authored andcommitted
tests: i3c_target: Fix timeouts
Previous implementation has scheduled timeout task as a forked coroutine. This doesn't guarantee that the exception raised will be propagated. Instead, use built-in mechanism for setting timeouts. Signed-off-by: Wiktoria Kuna <[email protected]>
1 parent cc600c9 commit d50c0ac

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

verification/cocotb/top/lib_i3c_top/test_i3c_target.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
import functools
34
import logging
45
import random
56
from math import ceil
@@ -17,13 +18,23 @@
1718
TARGET_ADDRESS = 0x5A
1819

1920

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
2738

2839

2940
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):
3243
"""
3344

3445
cocotb.log.setLevel(logging.INFO)
35-
cocotb.start_soon(timeout_task(200))
3646

3747
dut._log.info(f"fclk = {fclk:.3f} MHz")
3848
dut._log.info(f"fbus = {fbus:.3f} MHz")
@@ -89,7 +99,7 @@ async def test_setup(dut, fclk=100.0, fbus=12.5):
8999
return i3c_controller, i3c_target, tb
90100

91101

92-
@cocotb.test()
102+
@cocotb_test()
93103
async def test_i3c_target_write(dut):
94104

95105
test_data = [[0xAA, 0x00, 0xBB, 0xCC, 0xDD], [0xDE, 0xAD, 0xBA, 0xBE]]
@@ -178,7 +188,7 @@ async def rx_agent():
178188
assert test_data == recv_data
179189

180190

181-
@cocotb.test()
191+
@cocotb_test()
182192
async def test_i3c_target_read(dut):
183193

184194
# Setup
@@ -268,7 +278,7 @@ def compare(expected, received, lnt=None):
268278
compare(tx_data, rx_data)
269279

270280

271-
@cocotb.test()
281+
@cocotb_test()
272282
async def test_i3c_target_ibi(dut):
273283
"""
274284
IBI test. Sends an IBI with no data and then subsequently IBIs with
@@ -357,7 +367,7 @@ async def test_i3c_target_ibi(dut):
357367
assert result
358368

359369

360-
@cocotb.test()
370+
@cocotb_test()
361371
async def test_i3c_target_ibi_retry(dut):
362372
"""
363373
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):
432442
assert result
433443

434444

435-
@cocotb.test()
445+
@cocotb_test()
436446
async def test_i3c_target_ibi_data(dut):
437447
"""
438448
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):
497507
assert result
498508

499509

500-
@cocotb.test()
510+
@cocotb_test()
501511
async def test_i3c_target_writes_and_reads(dut):
502512

503513
# Setup
@@ -578,7 +588,7 @@ async def test_i3c_target_writes_and_reads(dut):
578588
assert tx_test_data == recv_data
579589

580590

581-
@cocotb.test()
591+
@cocotb_test()
582592
async def test_i3c_target_pwrite_err_detection(dut):
583593
I3C_DIRECT_GETSTATUS = 0x90
584594
TRANSFER_LENGTH = 4

verification/cocotb/top/lib_i3c_top/test_interrupts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def test_setup(dut, timeout_us=50):
3434
"""
3535

3636
cocotb.log.setLevel(logging.INFO)
37-
cocotb.start_soon(timeout_task(timeout_us))
37+
await cocotb.start(timeout_task(timeout_us))
3838

3939
i3c_controller = I3cController(
4040
sda_i=dut.bus_sda,

0 commit comments

Comments
 (0)