(Tcl?) Script to run modelsim with testbench as parameter from shell
I want to create a script that can be executed from the shell like:. / myscript -test1 or tclsh myscript.tcl -test1
I want it to open ModelSim, compile the units, load the desired test bench, run the simulation. The test name will be the parameter. I've already made macro files (.do) containing the modelsim commands to compile and simulate the desired units (+ adding signals to the waveform). I ask because scripting is not my area of expertise.
So here are my questions:
-
How does ,, 'Modelim (at startup) execute commands in the specified file?
-
Is TCL the language I'm looking for // does this apply in TCL? If so, which teams should I be familiar with?
-
Or maybe a shell script is enough and I should look for specific Modelsim commands in the reference manual?
Thank you for your time!
EDIT: Posting a small example I made for everyone to use. Usage: ./ foo.tcl testname
#!/usr/bin/tclsh
# params
set testname [lindex $argv 0]
set testlist {test1 test2 test3}
# run vsim test $testname
if { [ lsearch $testlist $testname ] >= 0 } {
puts "Test found. Executing..."
open "|vsim -do $testname "
} else { puts "Test not found on the list!" }
source to share
You can run vsim
with arbitrary commands using the command line option -do <arg>
. The argument can be either the name of a .do file containing arbitrary Tcl code, or a string of Tcl commands ("run -all; quit" is useful for non-interactive command line mode c -c
).
Tcl is a fully featured scripting language. It can handle any automation task you have to complete. Ultimately, you cannot escape Tcl with Modelsim, as almost everything goes through it internally. I would recommend that you put together what you need in a .do file and run it with a parameter -do
.
source to share
If you create a .tcl script (.do files can run QuestaSim / ModelSim commands and tcl commands), you can do whatever you want, including running other .do / .tcl files. For example:
Command line ModelSim / QuestaSim:
just like you used to ...
$: do MyDoFile.do
... instead use a Tcl file that can call your .do files:
$: source ./MyDirectory/MyTCLScript.tcl
Inside that MyTCLScript.tcl, you can literally have the following:
Inside
MyTCLScript.tcl
:
... #Use tabs for aliases source ./MyDirectory/OtherDirectory/OtherTCLScript.tcl MyAlias1 MyAlias2 do ./MyDoFile.do ...
Finally, so that you can use commands to run individual testbeds and sorting, I suggest looking at the Tcl documentation on aliases. Here's an example:
Inside
OtherTCLScript.tcl
:
... alias MyAlias1 { eval <command><command flags> } alias MyAlias2 { eval <command><command flags> } ...
Sources: 1. Experience 2. Questa SIM User Guide
source to share