[libre-riscv-dev] Tests in soc/fu
Jacob Lifshay
programmerjake at gmail.com
Sun Jun 21 22:12:13 BST 2020
On Sat, Jun 20, 2020, 10:20 Luke Kenneth Casson Leighton <lkcl at lkcl.net>
wrote:
> On Sat, Jun 20, 2020 at 4:56 PM Yehowshua <yimmanuel3 at gatech.edu> wrote:
> >
> > Michael and I were discussing about unit tests.
> > I recently realized its possible to maintain simulator
> > state while popping on more unit tests.
>
> yes. ah. i'm glad you brought this up.
>
> unit test classes in particular, have setup and teardown functions (i
> think they're actually called that).
>
> https://docs.python.org/3/library/unittest.html#setupclass-and-teardownclass
>
> they are. encountered them a couple of years ago. with so much else
> going on i just haven't had time to raise it / mention it.
>
> > You can do the following as many times as you want:
> >
> > ```python3
> >
> > sim.add_sync_process(process1)
> > sim.run()
> >
> > sim.add_sync_process(process2)
> > sim.run()
> >
> > sim.add_sync_process(process3)
> > sim.run()
> > ```
>
> yes. and, thus, the the setup function would establish the "sim"
> object, placing it as a member of the unit test class, and teardown
> would do any cleanup such as deleting temporary files or etc. etc. (if
> needed). so it would be more:
>
> class TestSim(UnitTest)
> def setupClass(self):
> self.dut = Module()
> self.dut.m.submodules.blah = SomethingToTest()
> self.sim = Simulator()
>
> def process1(self):
> yield something
> self.assertEqual something else
>
> def test_fred(self):
> self.sim.add_sync_process(self.process1)
> self.sim.run()
>
> something like that.
>
> > This comes in handy when running many very
> > short tests on an rtl unit. You no longer have
> > to rebuild the simulator for each test.
>
Please do *not* use that on tests that take more than a second or two to
run between them all, since IIRC that prevents the test runner from running
multiple test functions in parallel (when enabled). Running tests in
parallel resulting in a large (>10x for me) speed-up on multi-core
processors.
Jacob
>
More information about the libre-riscv-dev
mailing list