From 592ba1409121858d46170d039125615bb7c42e5b Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 24 Aug 2022 12:25:07 -0400 Subject: [PATCH] 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 --- tb/pcs.py | 4 +--- tb/util.py | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tb/pcs.py b/tb/pcs.py index c73993a..2a7a846 100644 --- a/tb/pcs.py +++ b/tb/pcs.py @@ -268,6 +268,4 @@ async def test_rx(pcs, valids): for _ in range(10): assert [0x5, 0x5] == await alist(mii_recv_packet(pcs)) -rx_tests = TestFactory(test_rx) -rx_tests.add_option('valids', (one_valid, two_valid, rand_valid, saw_valid())) -rx_tests.generate_tests() +with_valids(globals(), test_rx) diff --git a/tb/util.py b/tb/util.py index ed8c12f..537d708 100644 --- a/tb/util.py +++ b/tb/util.py @@ -89,6 +89,15 @@ class saw_valid: self.last = 0 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): bits = iter(bits) await FallingEdge(clk)