From cf1e834b3ae79854414453b2c1a670807789bf30 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Thu, 5 Sep 2024 06:49:41 +0300 Subject: [PATCH] Fix race condition in dff_cocotb test There is no constraint on tb.stop() action with regards to all other coroutines waiting for clock rising edge. This may lead to mismatching transactions and expectations being sent to Scoreboard and the following error: AssertionError: Received a transaction but wasn't expecting anything Waiting on ReadOnly trigger ensures that all other coroutines have performed their actions before the testbetch is stopped. --- examples/dff/tests/dff_cocotb.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/dff/tests/dff_cocotb.py b/examples/dff/tests/dff_cocotb.py index 2eabc2c6..a5292319 100644 --- a/examples/dff/tests/dff_cocotb.py +++ b/examples/dff/tests/dff_cocotb.py @@ -30,7 +30,7 @@ import cocotb from cocotb.clock import Clock -from cocotb.triggers import RisingEdge +from cocotb.triggers import ReadOnly, RisingEdge from cocotb.binary import BinaryValue from cocotb.regression import TestFactory @@ -149,6 +149,8 @@ async def run_test(dut): # Stop generation of input data. One more clock cycle is needed to capture # the resulting output of the DUT. + + await ReadOnly() tb.stop() await clkedge