
Compared to tests in the repository root, tests in the package have many downsides: * Unless explicitly excluded in find_packages(), tests and their support code effectively become a part of public API. This, unfortunately, happened with FHDLTestCase, which was never intended for downstream use. * Even if explicitly excluded from the setuptools package, using an editable install, or setting PYTHONPATH still allows accessing the tests. * Having a sub-package that is present in the source tree but not exported (or, worse, exported only sometimes) is confusing. * The name `nmigen.test` cannot be used for anything else, such as testing utilities that *are* intended for downstream use.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import unittest
|
|
from itertools import count
|
|
|
|
from nmigen.compat import *
|
|
from nmigen.compat.genlib.fifo import SyncFIFO
|
|
|
|
from .support import SimCase
|
|
|
|
|
|
class SyncFIFOCase(SimCase, unittest.TestCase):
|
|
class TestBench(Module):
|
|
def __init__(self):
|
|
self.submodules.dut = SyncFIFO(64, 2)
|
|
|
|
self.sync += [
|
|
If(self.dut.we & self.dut.writable,
|
|
self.dut.din[:32].eq(self.dut.din[:32] + 1),
|
|
self.dut.din[32:].eq(self.dut.din[32:] + 2)
|
|
)
|
|
]
|
|
|
|
def test_run_sequence(self):
|
|
seq = list(range(20))
|
|
def gen():
|
|
for cycle in count():
|
|
# fire re and we at "random"
|
|
yield self.tb.dut.we.eq(cycle % 2 == 0)
|
|
yield self.tb.dut.re.eq(cycle % 3 == 0)
|
|
# the output if valid must be correct
|
|
if (yield self.tb.dut.readable) and (yield self.tb.dut.re):
|
|
try:
|
|
i = seq.pop(0)
|
|
except IndexError:
|
|
break
|
|
self.assertEqual((yield self.tb.dut.dout[:32]), i)
|
|
self.assertEqual((yield self.tb.dut.dout[32:]), i*2)
|
|
yield
|
|
self.run_with(gen())
|