aboutsummaryrefslogtreecommitdiffstats
path: root/fpga
diff options
context:
space:
mode:
authorWade Fife <wade.fife@ettus.com>2021-06-11 17:01:55 -0500
committerWade Fife <wade.fife@ettus.com>2021-06-17 08:16:59 -0500
commit574146ec8909da367c3441189c2877a287892f7e (patch)
treec9f15fc104571a1ceed1ffe730af91f677f64acd /fpga
parentb85b796cbc1f897a69ded1f3ecfba8ec92684c11 (diff)
downloaduhd-574146ec8909da367c3441189c2877a287892f7e.tar.gz
uhd-574146ec8909da367c3441189c2877a287892f7e.tar.bz2
uhd-574146ec8909da367c3441189c2877a287892f7e.zip
fpga: tools: Detect assertions in ModelSim simulation
This change allows assertion errors/failures in ModelSim to be detected and causes ModelSim to return a non-zero value when such an assertion error occurs. This allows the return value of ModelSim to be used to determine whether or not the testbench passed.
Diffstat (limited to 'fpga')
-rwxr-xr-xfpga/usrp3/tools/scripts/launch_modelsim.sh24
1 files changed, 22 insertions, 2 deletions
diff --git a/fpga/usrp3/tools/scripts/launch_modelsim.sh b/fpga/usrp3/tools/scripts/launch_modelsim.sh
index ad71c473c..77476b9f9 100755
--- a/fpga/usrp3/tools/scripts/launch_modelsim.sh
+++ b/fpga/usrp3/tools/scripts/launch_modelsim.sh
@@ -45,7 +45,27 @@ function print_color {
# Using -voptargs=+acc makes everything visible in the simulator for GUI mode
# and avoids some cases where simulation mismatch could otherwise occur.
-MSIM_DEFAULT="-voptargs=+acc -quiet -L unisims_ver"
+# Setting -onfinish to "stop" prevents the simulator from immediately trying to
+# exit when finish() is called. This is annoying in the GUI and important for
+# error detection in batch mode.
+MSIM_DEFAULT="-voptargs=+acc -quiet -L unisims_ver -onfinish stop"
+
+# DO file to execute in batch mode. This script runs the simulation and adds
+# detection of error/failure assertions so that non-zero values are returned by
+# ModelSim when the testbench doesn't pass. Calling std.env.finish() or
+# $finish() will return 0. Detecting $fatal() requires that -onfinish be set to
+# stop so the simulator doesn't quit before the DO file finishes.
+DO_SCRIPT="\
+quietly set BreakOnAssertion 2 ;\
+quietly set SIM_ERROR 0 ;\
+onbreak { ;\
+ quietly set FINISH [lindex [runStatus -full] 2] ;\
+ if {\$FINISH eq \"unknown\"} { set SIM_ERROR 255 } ;\
+} ;\
+onerror { set SIM_ERROR 255 } ;\
+run -all ;\
+quit -force -code \$SIM_ERROR ;\
+"
# Use specified modelsim.ini, if set
if [[ -z $MSIM_MODELSIM_INI ]]; then
@@ -72,7 +92,7 @@ if [ $MSIM_MODE == "gui" ]; then
if [ ${exit_status} -ne 0 ]; then exit ${exit_status}; fi
elif [ $MSIM_MODE == "batch" ]; then
echo "* Launching ModelSim"
- vsim -batch -do "run -all; quit -f" $MODELSIMINI_ARG $MSIM_DEFAULT $MSIM_ARGS $MSIM_LIB_ARGS $MSIM_SIM_TOP 2>&1 | while IFS= read -r line; do
+ vsim -batch -do "$DO_SCRIPT" $MODELSIMINI_ARG $MSIM_DEFAULT $MSIM_ARGS $MSIM_LIB_ARGS $MSIM_SIM_TOP 2>&1 | while IFS= read -r line; do
print_color $line
done
exit_status=${PIPESTATUS[0]}