Warm tip: This article is reproduced from serverfault.com, please click

其他-如何将参数从cmd传递到ModelSim的tcl脚本

(其他 - How to pass arguments from cmd to tcl script of ModelSim)

发布于 2017-03-21 09:45:26

我在python程序的cmd中运行Modelsim。我使用以下代码,这些代码调用运行modelim的tcl脚本:

os.system("vsim -c -do top_tb_simulate_reg.tcl " )

tcl脚本包含以下内容:

vsim -voptargs="+acc" +UVM_TESTNAME=test_name +UVM_MAX_QUIT_COUNT=1 +UVM_VERBOSITY=UVM_LOW \
    -t 1ps -L unisims_verm -L generic_baseblocks_v2_1_0 -L axi_infrastructure_v1_1_0 \
    -L dds_compiler_v6_0_12 -lib xil_defaultlib xil_defaultlib.girobo2_tb_top \
    xil_defaultlib.glbl

我希望+ UVM_TESTNAME的值将是我在执行时从cmd传递的参数:

os.system("vsim -c -do top_tb_simulate_reg.tcl " )

我该怎么做?

我没有成功尝试以下方法:

Python脚本:

os.system("vsim -c -do top_tb_simulate_reg.tcl axi_rd_only_test" )

模拟文件(tcl脚本)

vsim -voptargs="+acc" +UVM_TESTNAME=$argv +UVM_MAX_QUIT_COUNT=1 +UVM_VERBOSITY=UVM_LOW \
    -t 1ps -L unisims_verm -L generic_baseblocks_v2_1_0 -L axi_infrastructure_v1_1_0 \
    -L dds_compiler_v6_0_12 -lib xil_defaultlib xil_defaultlib.girobo2_tb_top \
    xil_defaultlib.glbl

我收到以下错误:

#**错误:(vsim-3170)找不到'C:/raft/raftortwo/girobo2/ver/sim/work.axi_rd_only_test'。
Questioner
sara r
Viewed
0
Donal Fellows 2017-03-21 19:28:30

问题在于vsim二进制文件正在对参数进行自己的处理,这会产生干扰。是的,你可以通过阅读vsim文档找到解决此问题的方法,解决此问题的最简单方法是通过环境变量传递值它们从其父进程的一个进程继承而来,非常适合传递大多数内容。(安全令牌是例外,应始终在具有正确设置的权限的文件中传递安全令牌,而不是环境变量命令行参数。)

在你的python代码中:

# Store the value in the *inheritable* environment
os.environ["MY_TEST_CASE"] = "axi_rd_only_test"

# Do the call; the environment gets passed over behind the scenes
os.system("vsim -c -do top_tb_simulate_reg.tcl " )

在你的tcl代码中:

# Read out of the inherited environment
set name $env(MY_TEST_CASE)

# Use it! (Could do this as one line, but that's hard to read)
vsim -voptargs="+acc" +UVM_TESTNAME=$name +UVM_MAX_QUIT_COUNT=1 +UVM_VERBOSITY=UVM_LOW \
    -t 1ps -L unisims_verm -L generic_baseblocks_v2_1_0 -L axi_infrastructure_v1_1_0 \
    -L dds_compiler_v6_0_12 -lib xil_defaultlib xil_defaultlib.girobo2_tb_top \
    xil_defaultlib.glbl