Closed whitequark closed 5 years ago
There are many ways to write test benches. Does it help with the ARTIQ ones?
Yes. In fact this style of writing testbenches is modelled directly after ARTIQ's more structured ones, since that was where I learned. I think that most if not all ARTIQ gateware testbenches can be converted to the style above, and many will become nicer, too.
I use something very similar. One thing I would like to request that I don't think will work with the above @simulation_test
approach is that I almost always want to run multiple generators for one test.
Many of my modules have multiple independent interfaces, and it's very hard to control these from a single generator - much easier to have one generator per interface, and if needed they share some information via a common variable (e.g. an attribute of the testbench). Other modules are meant to connect to external interfaces (e.g. DRAM controller) that need to have their behavior simulated, and that's a generator that belongs to the interface, not whatever module happens to use it. I also like to add a gen_selfcheck to my modules to continuously check some invariants during integration tests (it helps me to get alerted to problems close to the source), and there's no reason not to have those running during the unit test too.
And one more generator I always add is the "timeout" generator (passive, calls self.fail after a specified number of cycles), because the usual failure mode is that the test never terminates. By the time I am sure that that is indeed what happened and interrupt it, the vcd is often so large that gtkwave crashes on loading... that is a generic enough problem that I think timeout could be an optional keyword argument somewhere.
There are many ways to write test benches.
I agree. Adding this as suggested would be premature, and I am not certain of the best design here.
I'm currently copying this file between my projects:
It allows writing test cases like this:
Should something like this be integrated in Migen? Also,
assertState
andassertSignal
would be handy there.