Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
| dt-code-statem [2011/05/05 11:42] – Testbench eingefügt beckmanf | dt-code-statem [2011/05/10 11:26] (current) – added more tests beckmanf | ||
|---|---|---|---|
| Line 149: | Line 149: | ||
| end architecture; | end architecture; | ||
| </ | </ | ||
| + | |||
| + | The previous testbench only produced a stimuli sequence which results in the output going high. The testbench did not check the output signal however. For checking the output, the assert command is used in VHDL. The following modified testbench checks the output. | ||
| + | |||
| + | <code vhdl> | ||
| + | |||
| + | test : process | ||
| + | begin | ||
| + | reset <= ' | ||
| + | -- Wait for some time | ||
| + | wait for 100 ns; | ||
| + | report " | ||
| + | assert output = ' | ||
| + | wait until falling_edge(clk); | ||
| + | -- Reset Release | ||
| + | reset <= ' | ||
| + | -- Now the positive 101 Sequence | ||
| + | stim <= ' | ||
| + | wait until falling_edge(clk); | ||
| + | assert output = ' | ||
| + | stim <= ' | ||
| + | wait until falling_edge(clk); | ||
| + | assert output = ' | ||
| + | stim <= ' | ||
| + | wait until falling_edge(clk); | ||
| + | assert output = ' | ||
| + | stim <= ' | ||
| + | wait until falling_edge(clk); | ||
| + | wait until falling_edge(clk); | ||
| + | |||
| + | assert false report "End of Simulation" | ||
| + | end process test; | ||
| + | </ | ||
| + | |||
| + | In addition the simulation is stopped with the final assert false statement. The previous stimuli sequence only shows one positive example for the good case. It is not tested that other sequences may also trigger the output going high. | ||
| + | |||
| + | The following code test process produces a random sequence for the input pattern. It is checked if the " | ||
| + | |||
| + | <code vhdl> | ||
| + | use ieee.math_real.all; | ||
| + | |||
| + | --- architecture and begin follows | ||
| + | |||
| + | test2_p : process | ||
| + | variable zufall : real; | ||
| + | variable seed1 : integer := 5; | ||
| + | variable seed2 : integer := 17; | ||
| + | variable inp_letzter, | ||
| + | begin | ||
| + | reset <= ' | ||
| + | wait for 10 ns; | ||
| + | reset <= ' | ||
| + | for count in 0 to 1500 loop | ||
| + | wait until falling_edge(clk); | ||
| + | if (inp_vorletzter = ' | ||
| + | assert output = ' | ||
| + | else | ||
| + | assert output = ' | ||
| + | end if; | ||
| + | inp_vorletzter := inp_letzter; | ||
| + | inp_letzter := stim; | ||
| + | uniform(seed1, | ||
| + | if (zufall <= 0.5) then | ||
| + | stim <= ' | ||
| + | else | ||
| + | stim <= ' | ||
| + | end if; | ||
| + | end loop; | ||
| + | assert false report "End of Simulation" | ||
| + | end process test2_p; | ||
| + | </ | ||
| + | |||
| + | This code simulates 1500 cycles. Also this code does not test all possible input sequences - which is not possible anyway. Without knowledge about the internal state it is not possible to do a 100% verification of the statemachine implementation. | ||