mirror of
https://github.com/openhwgroup/cvw
synced 2025-01-23 13:04:28 +00:00
e008999030
example wsim rv64gc ../../tests/riscof/work/riscv-arch-test/rv64i_m/I/src/add-01.S/ref/ref.elf --elf --lockstep
105 lines
4.3 KiB
Python
Executable File
105 lines
4.3 KiB
Python
Executable File
#!/usr/bin/python3
|
|
#
|
|
# wsim
|
|
# David_Harris@hmc.edu 5 April 2024
|
|
# Invoke a Wally simulation for a desired configuration and test suite or ELF on the specified simulator
|
|
# usage: wsim CONFIG TESTSUITE [-s/--sim SIMULATOR] [-g/--gui]
|
|
# example: wsim rv64gc arch64i
|
|
# example: wsim rv64gc tests/riscof/work/riscv-arch-test/rv64i_m/I/src/ref/ref.elf
|
|
# example: wsim rv32i arch32i -s verilator
|
|
# example: wsim fdqh_ieee_rv64gc add -t testbench_fp # run TestFloat
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
|
|
|
import argparse
|
|
import os
|
|
|
|
# Parse arguments
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("config", help="Configuration file")
|
|
parser.add_argument("testsuite", help="Test suite or ELF file")
|
|
parser.add_argument("--elf", "-e", help="Elf file", action="store_true")
|
|
parser.add_argument("--sim", "-s", help="Simulator", choices=["questa", "verilator", "vcs"], default="questa")
|
|
parser.add_argument("--tb", "-t", help="Testbench", choices=["testbench", "testbench_fp"], default="testbench")
|
|
parser.add_argument("--gui", "-g", help="Simulate with GUI", action="store_true")
|
|
parser.add_argument("--coverage", "-c", help="Code & Functional Coverage", action="store_true")
|
|
parser.add_argument("--args", "-a", help="Optional arguments passed to simulator via $value$plusargs", default="")
|
|
parser.add_argument("--vcd", "-v", help="Generate testbench.vcd", action="store_true")
|
|
parser.add_argument("--lockstep", "-l", help="Run ImperasDV lock, step, and compare.", action="store_true")
|
|
parser.add_argument("--locksteplog", "-b", help="Retired instruction number to be begin logging.", default=0)
|
|
args = parser.parse_args()
|
|
print("Config=" + args.config + " tests=" + args.testsuite + " sim=" + args.sim + " gui=" + str(args.gui) + " args='" + args.args + "'")
|
|
ElfFile=""
|
|
|
|
if(args.elf):
|
|
ElfFile = "+ElfFile=" + args.testsuite
|
|
args.testsuite = "none"
|
|
|
|
# Validate arguments
|
|
if (args.gui):
|
|
if args.sim not in ["questa", "vcs"]:
|
|
print("GUI option only supported for Questa and VCS")
|
|
exit(1)
|
|
|
|
if (args.coverage):
|
|
if args.sim not in ["questa", "vcs"]:
|
|
print("Coverage option only available for Questa and VCS")
|
|
exit(1)
|
|
|
|
if (args.vcd):
|
|
args.args += " -DMAKEVCD=1"
|
|
|
|
# create the output sub-directories.
|
|
WALLY = os.environ.get('WALLY')
|
|
regressionDir = WALLY + '/sim/'
|
|
for d in ["logs", "wkdir", "cov"]:
|
|
try:
|
|
os.mkdir(regressionDir+args.sim+"/"+d)
|
|
except:
|
|
pass
|
|
|
|
|
|
# Launch selected simulator
|
|
cd = "cd $WALLY/sim/" +args.sim
|
|
if (args.sim == "questa"):
|
|
if (args.lockstep):
|
|
Instret = str(args.locksteplog)
|
|
prefix ="IMPERAS_TOOLS=" + WALLY + "/sim/imperas.ic OTHERFLAGS=\"+IDV_TRACE2LOG=" + Instret + " +IDV_TRACE2COV=" + Instret + "\" ";
|
|
suffix = "--lockstep"
|
|
else:
|
|
prefix = ""
|
|
suffix = ""
|
|
if (args.tb == "testbench_fp"):
|
|
args.args = " -GTEST=\"" + args.testsuite + "\" " + args.args
|
|
cmd = "do wally.do " + args.config + " " + args.testsuite + " " + args.tb + " " + args.args + " " + ElfFile + " " + suffix
|
|
if (args.coverage):
|
|
cmd += " --coverage"
|
|
if (args.gui): # launch Questa with GUI; add +acc to keep variables accessible
|
|
if(args.tb == "testbench"):
|
|
cmd = cd + "; " + prefix + " vsim -do \"" + cmd + " +acc -GDEBUG=1\""
|
|
elif(args.tb == "testbench_fp"):
|
|
cmd = cd + "; " + prefix + " vsim -do \"" + cmd + " +acc\""
|
|
else: # launch Questa in batch mode
|
|
cmd = cd + "; " + prefix + " vsim -c -do \"" + cmd + "\""
|
|
print("Running Questa with command: " + cmd)
|
|
os.system(cmd)
|
|
elif (args.sim == "verilator"):
|
|
# PWD=${WALLY}/sim CONFIG=rv64gc TESTSUITE=arch64i
|
|
print(f"Running Verilator on {args.config} {args.testsuite}")
|
|
if (args.coverage):
|
|
print("Coverage option not available for Verilator")
|
|
exit(1)
|
|
if (args.gui):
|
|
print("GUI option not available for Verilator")
|
|
exit(1)
|
|
os.system(f"/usr/bin/make -C {regressionDir}/verilator WALLYCONF={args.config} TEST={args.testsuite} TESTBENCH={args.tb} EXTRA_ARGS='{args.args}'")
|
|
elif (args.sim == "vcs"):
|
|
print(f"Running VCS on " + args.config + " " + args.testsuite)
|
|
if (args.gui):
|
|
args.args += "gui"
|
|
elif (args.coverage):
|
|
args.args += "coverage"
|
|
cmd = cd + "; ./run_vcs " + args.config + " " + args.testsuite + " " + args.args
|
|
print(cmd)
|
|
os.system(cmd)
|