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:
parent
15ae994ad6
commit
592ba14091
|
@ -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()
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue