Wednesday, July 24, 2013

Automating ModelSim/QuestaSim Regressions

Implementing a makefile driven regression setup to automate the execution of testcases of varying length requires some method of gracefully ending the simulation. Verilog supports the use of $finish to signal the end of the simulation. VHDL 2008 introduces the 'env' package to the 'std' library that includes a method similar to Verilog:
library std;use std.env.all;.......stop(0);--orfinish(0);-- For both STOP and FINISH the STATUS values are those used-- in the Verilog $finish task-- 0 prints nothing-- 1 prints simulation time and location-- 2 prints simulation time, location, and statistics about-- the memory and CPU times used in simulation-- Other STATUS values are interpreted as 0.
If the project requires VHDL 93, then the following method can be used instead.
  1. Add a signal to the testbench top level that can be asserted by the testcase to indicate the end of the simulation.
  2. Add the following to the do-file used to execute the simulation:
## Initialize broken variable to 0set broken 0set finished 0## assert statments with a severity of failure cause breakpoints## when a breakpoint is encountered the following routine runs## which sets the broken variable.onbreak {  if {$finished} {    resume  } else {    set broken 1    resume  }}when -label end_of_simulation {sim_done_s == '1'} {echo "simulation finished"; set finished 1; stop;}## run until breakrun -all## if the sim was brokenif {$broken } {puts "Test Failed to Complete"} else {puts "Test Successfully Completed"}quit -f
In this example, I added a signal to my testbench called "sim_done_s" which is initialized to '0'. At the end of the testcase, sim_done_s is assigned to '1'.

Alternatively, the more common approach is to simply apply an assertion of the appropriate level to cause the simulator to break.  This is set in the modelsim.ini file and defaults to a level of Failure.  I personally don't like this method because I don't want to see the word Failure in my transcript if there isn't actually a failure.  This way I can automate the regressions and run a grep on the logs for the word Failure or Error.

No comments:

Post a Comment