3

I am trying to create a self-testing VHDL testbench in which I need to true or false status (1 or 0) to the command line/shell that is calling the vsim commands to convey the overall pass/fail status of the testbench.

My simulator tool is modelsim. Is there a way to accomplish this?

user2913869
  • 481
  • 2
  • 5
  • 23
  • VHDL 2008 allows return codes using std.env.stop(CODE) or std.env.finish(CODE). I dont know if they work properly with modelsim - ActiveHDL certainly doesnt return the code to the shell properly. You need to do a workaround using TCL to examine a signal in the TB to get pass/fail status. – Tricky Aug 20 '19 at 13:36
  • 1
    I haven't use modelsim for a while but with Vivado, you have a **simulate.log** file that you can populate with some **asserts**. Or you can use the textio library to fill a file. – Gautitho Aug 20 '19 at 13:38

4 Answers4

1

The VHDL-2008 standard doesn't define how the code provided with stop(code) and finish(code) should be used. It's for the simulator vendor to decide. The only simulator I know of that will return that value is GHDL.

If you use VUnit with Modelsim or any of the other supported simulators you will get the exit code you expect for a wide range of different error cases (VHDL asserts, PSL asserts, simulator crashes like null pointer dereferencing etc). A full range of VHDL error case examples can be found on EdaPlayground.

You can also use VUnit with SystemVerilog and UVM for the same purpose as shown here. Note that UVM doesn't provide such error detection capabilities on its own.

Disclaimer: I'm one of the authors for VUnit.

lasplund
  • 1,350
  • 1
  • 8
  • 17
  • 1
    +1 I'm not an author of VUnit, so I can say objectively that VUnit solves a large number of annoyances like this. – Harry Jul 13 '21 at 11:56
1

The normal way to do this is the onbreak command. Search for the exit command in the manual, which gives an example. Basically, you call onbreak, do a run -all, and an assertion failure in your code will then let you return to the tcl and exit with a given error code.

However, this isn't a great idea. It's simulator-specific and gives you very little reporting and control. A much better solution is to create a log file from your testbench, and then compare it to one or more known good golden logfiles. This is straightforward to script and gives you much better confidence that your testbench actually did something, instead of mistakenly exiting when it shouldn't have done.

EML
  • 9,619
  • 6
  • 46
  • 78
0

You can use the report statement.

If you declared the status of your simulation as:

signal simulation_status : std_logic;

Then you can use:

report "simulation status = " & std_logic'image(simulation_status);

Of course, you want to wait until the end of the simulation before reporting the status, in your testbench you can create an apposite process to do so:

process
begin 
    wait for 1000 ns; -- until the end of your simulation
    report "simulation status = " & std_logic'image(simulation_status);
    wait;
end process;

By default report has severity note, but you can also use warning, error and failure, for example:

report "simulation status = " & std_logic'image(simulation_status) severity failure; 

When a report with severity failure is reached, it will stop the simulation.

Giampietro Seu
  • 786
  • 9
  • 16
  • 1
    This doesnt answer the question about ending the simulation with correct return code to the shell. – Tricky Aug 20 '19 at 14:18
  • I think he only wants to print out the result of the simulation to the shell, but maybe I'm wrong. – Giampietro Seu Aug 20 '19 at 14:22
  • 1
    In a shell a program returns/exits with 0 (normal) or non-0 (error code). For example, in tcl, you can call `exit 1` to quit the simulator or synth tool with an error, or replace 1 with some value deduced from the simulation/environment. CI tools usually use the return code to determine if a test/build has passed or failed. Its quite disconcerting when you see something like this in a CI log `ERROR: Test has failed program exited with code (0) Test Passed ` probably because your script wasnt correct. – Tricky Aug 20 '19 at 15:50
0

vsim supports an enhanced exit command, so to return an error code simply use exit -force -error_number.

Batch file example:

vsim -c ... -do "exit -force -code 3"

IF %ERRORLEVEL% EQU 3 GOTO xxxx:

HTLab
  • 74
  • 2