2024-04-06 01:19:46 +00:00
|
|
|
#!/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
|
2024-04-06 15:22:39 +00:00
|
|
|
# example: wsim fdqh_ieee_rv64gc add -t testbench_fp # run TestFloat
|
2024-04-06 01:19:46 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
|
|
|
|
|
|
|
import argparse
|
2024-04-06 02:08:14 +00:00
|
|
|
import os
|
2024-04-06 01:19:46 +00:00
|
|
|
|
2024-06-27 18:16:17 +00:00
|
|
|
########################
|
|
|
|
# main wsim script
|
|
|
|
########################
|
|
|
|
|
2024-04-06 15:22:39 +00:00
|
|
|
# Parse arguments
|
2024-04-06 01:19:46 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("config", help="Configuration file")
|
2024-07-14 04:59:26 +00:00
|
|
|
parser.add_argument("testsuite", help="Test suite or path to .elf file")
|
|
|
|
parser.add_argument("--elf", "-e", help="ELF File name; use if name does not end in .elf", default="")
|
2024-04-06 01:19:46 +00:00
|
|
|
parser.add_argument("--sim", "-s", help="Simulator", choices=["questa", "verilator", "vcs"], default="questa")
|
2024-04-06 15:22:39 +00:00
|
|
|
parser.add_argument("--tb", "-t", help="Testbench", choices=["testbench", "testbench_fp"], default="testbench")
|
2024-04-06 01:19:46 +00:00
|
|
|
parser.add_argument("--gui", "-g", help="Simulate with GUI", action="store_true")
|
2024-07-15 12:32:16 +00:00
|
|
|
parser.add_argument("--ccov", "-c", help="Code Coverage", action="store_true")
|
2024-07-17 13:04:21 +00:00
|
|
|
parser.add_argument("--fcov", "-f", help="Functional Coverage, implies lockstep", action="store_true")
|
2024-04-06 18:42:41 +00:00
|
|
|
parser.add_argument("--args", "-a", help="Optional arguments passed to simulator via $value$plusargs", default="")
|
2024-04-22 20:03:51 +00:00
|
|
|
parser.add_argument("--vcd", "-v", help="Generate testbench.vcd", action="store_true")
|
2024-05-17 22:10:15 +00:00
|
|
|
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)
|
2024-05-27 23:15:04 +00:00
|
|
|
parser.add_argument("--covlog", "-d", help="Log coverage after n instructions.", default=0)
|
2024-04-06 01:19:46 +00:00
|
|
|
args = parser.parse_args()
|
2024-04-06 18:42:41 +00:00
|
|
|
print("Config=" + args.config + " tests=" + args.testsuite + " sim=" + args.sim + " gui=" + str(args.gui) + " args='" + args.args + "'")
|
2024-05-16 20:14:49 +00:00
|
|
|
ElfFile=""
|
2024-06-27 18:16:17 +00:00
|
|
|
WALLY = os.environ.get('WALLY')
|
2024-05-17 22:10:15 +00:00
|
|
|
|
2024-07-03 21:54:46 +00:00
|
|
|
if(os.path.isfile(args.elf)):
|
2024-07-03 22:10:02 +00:00
|
|
|
ElfFile = "+ElfFile=" + os.path.abspath(args.elf)
|
2024-07-14 16:49:15 +00:00
|
|
|
elif (args.elf != ""):
|
2024-07-14 04:59:26 +00:00
|
|
|
print("ELF file not found: " + args.elf)
|
|
|
|
exit(1)
|
2024-04-06 01:19:46 +00:00
|
|
|
|
2024-07-15 10:44:14 +00:00
|
|
|
if(args.testsuite.endswith('.elf') and args.elf == ""): # No --elf argument; check if testsuite has a .elf extension and use that instead
|
2024-07-14 16:49:15 +00:00
|
|
|
if (os.path.isfile(args.testsuite)):
|
|
|
|
ElfFile = "+ElfFile=" + os.path.abspath(args.testsuite)
|
2024-07-16 16:28:05 +00:00
|
|
|
if ('/' in args.testsuite):
|
|
|
|
args.testsuite=args.testsuite.rsplit('/', 1)[1] # strip off path if present
|
2024-07-14 16:49:15 +00:00
|
|
|
else:
|
|
|
|
print("ELF file not found: " + args.testsuite)
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-06 15:22:39 +00:00
|
|
|
# Validate arguments
|
2024-07-15 12:32:16 +00:00
|
|
|
if (args.gui or args.ccov or args.fcov or args.lockstep):
|
2024-05-02 18:52:54 +00:00
|
|
|
if args.sim not in ["questa", "vcs"]:
|
2024-06-27 18:16:17 +00:00
|
|
|
print("Option only supported for Questa and VCS")
|
2024-04-06 15:22:39 +00:00
|
|
|
exit(1)
|
|
|
|
|
2024-04-22 20:03:51 +00:00
|
|
|
if (args.vcd):
|
|
|
|
args.args += " -DMAKEVCD=1"
|
2024-04-06 23:04:48 +00:00
|
|
|
|
2024-06-27 18:16:17 +00:00
|
|
|
# if lockstep is enabled, then we need to pass the Imperas lockstep arguments
|
|
|
|
if(int(args.locksteplog) >= 1): EnableLog = 1
|
|
|
|
else: EnableLog = 0
|
|
|
|
if (args.lockstep):
|
|
|
|
prefix = "IMPERAS_TOOLS=" + WALLY + "/sim/imperas.ic"
|
|
|
|
if(args.locksteplog != 0): ImperasPlusArgs = " +IDV_TRACE2LOG=" + str(EnableLog) + " +IDV_TRACE2LOG_AFTER=" + str(args.locksteplog)
|
|
|
|
else: ImperasPlusArgs = ""
|
|
|
|
if(args.fcov):
|
|
|
|
CovEnableStr = "1" if int(args.covlog) > 0 else "0";
|
|
|
|
if(args.covlog >= 1): EnableLog = 1
|
|
|
|
else: EnableLog = 0
|
|
|
|
ImperasPlusArgs = " +IDV_TRACE2COV=" + str(EnableLog) + " +TRACE2LOG_AFTER=" + str(args.covlog) + " +TRACE2COV_ENABLE=" + CovEnableStr;
|
|
|
|
suffix = ""
|
|
|
|
else:
|
|
|
|
CovEnableStr = ""
|
|
|
|
suffix = "--lockstep"
|
|
|
|
else:
|
|
|
|
prefix = ""
|
|
|
|
ImperasPlusArgs = ""
|
|
|
|
suffix = ""
|
2024-06-28 14:19:03 +00:00
|
|
|
flags = suffix + " " + ImperasPlusArgs
|
2024-06-27 18:16:17 +00:00
|
|
|
|
|
|
|
# other flags
|
2024-07-15 12:32:16 +00:00
|
|
|
if (args.ccov):
|
|
|
|
flags += " --ccov"
|
2024-06-27 18:16:17 +00:00
|
|
|
if (args.fcov):
|
|
|
|
flags += " --fcov"
|
|
|
|
|
2024-04-06 23:04:48 +00:00
|
|
|
# create the output sub-directories.
|
|
|
|
regressionDir = WALLY + '/sim/'
|
2024-07-15 21:20:48 +00:00
|
|
|
for d in ["logs", "wkdir", "cov", "ucdb", "fcov", "fcov_ucdb"]:
|
2024-04-06 23:04:48 +00:00
|
|
|
try:
|
|
|
|
os.mkdir(regressionDir+args.sim+"/"+d)
|
|
|
|
except:
|
|
|
|
pass
|
2024-05-17 22:10:15 +00:00
|
|
|
|
2024-07-03 21:54:46 +00:00
|
|
|
cd = "cd $WALLY/sim/" +args.sim
|
|
|
|
|
|
|
|
# per-simulator launch
|
|
|
|
if (args.sim == "questa"):
|
|
|
|
# Questa cannot accept more than 9 arguments. fcov implies lockstep
|
|
|
|
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 + " " + flags
|
|
|
|
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}")
|
|
|
|
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"
|
|
|
|
if (args.args == ""):
|
|
|
|
vcsargs = ""
|
|
|
|
else:
|
|
|
|
vcsargs = " --args " + args.args
|
|
|
|
if (ElfFile != ""):
|
|
|
|
ElfFile = " --elffile " + ElfFile
|
2024-07-04 19:31:00 +00:00
|
|
|
cmd = cd + "; " + prefix + " ./run_vcs " + args.config + " " + args.testsuite + vcsargs + ElfFile + " " + flags
|
2024-07-03 21:54:46 +00:00
|
|
|
print(cmd)
|
|
|
|
os.system(cmd)
|