tb: Refactor out with_valids

Parametrizing a test over different methods of generating valid data
will be useful for other tests as well. Refactor it out. We have to bind
valids early in with_valids.test, otherwise we will end up binding
with_valids.valid by reference (causing all tests to use saw_valid).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
This commit is contained in:
Sean Anderson 2022-08-24 12:25:07 -04:00
parent 15ae994ad6
commit 592ba14091
2 changed files with 10 additions and 3 deletions

View File

@ -268,6 +268,4 @@ async def test_rx(pcs, valids):
for _ in range(10): for _ in range(10):
assert [0x5, 0x5] == await alist(mii_recv_packet(pcs)) assert [0x5, 0x5] == await alist(mii_recv_packet(pcs))
rx_tests = TestFactory(test_rx) with_valids(globals(), test_rx)
rx_tests.add_option('valids', (one_valid, two_valid, rand_valid, saw_valid()))
rx_tests.generate_tests()

View File

@ -89,6 +89,15 @@ class saw_valid:
self.last = 0 self.last = 0
return self.last return self.last
def with_valids(g, f):
for valids in (one_valid, two_valid, rand_valid, saw_valid()):
async def test(*args, valids=valids, **kwargs):
await f(*args, valids=valids, **kwargs)
test.__name__ = f"{f.__name__}_{valids.__qualname__}"
test.__qualname__ = f"{f.__qualname__}_{valids.__qualname__}"
test.valids = valids
g[test.__name__] = cocotb.test()(test)
async def send_recovered_bits(clk, data, valid, bits, valids): async def send_recovered_bits(clk, data, valid, bits, valids):
bits = iter(bits) bits = iter(bits)
await FallingEdge(clk) await FallingEdge(clk)