Re: [myhdl-list] Best way to think in test driven development using MyHDL coming from VHDL?
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2014-07-15 18:02:33
|
On 7/15/2014 9:51 AM, André Prado wrote: <snip> > > Is this the best way to do it? > > I am evaluation it by running: > > py.test tb_cordic.py -v > > It does work but I don't know if it's the best way to do it, I don't know if there is a "best", many like to use py.test, less scaffolding other prefer the Python included unittest. The great thing, MyHDL is Python - we can use the Python references to investigate [1][2]. I haven't reviewed you code fully but I tend to use a similar approach (that is use py.test), I use this template def testbench(args): # all dut port instantiations clock = Signal(bool(0)) reset = ResetSignal(0, active=0, async=True) # ... def _test(): tbdut = # ... return tbdut, tbstim, ... Simulation(traceSignals(_test)).run() I use the inner function because I often want to view my testbench signals in the waveform and it also allows multiple tests to be defined using the same port definitions and arguments. Typically, I use argparse to fill the test arguments, this might be things like number of loop iterations etc. > > I also have two functions doing almost the same thing, (random_bench and > fft_bench), this violates the DRY mantra, but I could'nt find a way to do > it generic enough. > > Taking all the DRY stuff (that also appears on my tests) that I messed up > while testing, any good tips? Am I in the right path? You could use the inner function to define your "stimulus" and have the generic generators in the outer function. This will allow you to reuse definitions and generic generators: def testbench(): # signal instantiations @always(delay(3)) def tbclk(): clock.next = not clock @instance def tbmon(): #monitor # ... def _test_fft(): tbdut = # dut needs to be in the func to be traced # ... @instance def tbstim() # ... return tbclk, tbmon, tbdut, tbstim, .... def _test_rand(): tbdut = ... @instance def tbstim(): # ... return tbclk, tbmon, tbdut, tbstim, ... if args.run == 'fft': tb = traceSignals(_test_fft) else: tb = traceSignals(_test_rand) Simulation(tb).run() Regards, Chris [1] http://docs.python-guide.org/en/latest/writing/tests/ [2] http://www.ibm.com/developerworks/aix/library/au-python_test/ |