From d5159d35a2bd69eb85ca5f0cf9caadc49f491867 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Mon, 2 Dec 2024 13:32:23 -0800 Subject: [PATCH 01/19] Remove locksteplog --- bin/wsim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bin/wsim b/bin/wsim index 91f8e30ab..740193e0f 100755 --- a/bin/wsim +++ b/bin/wsim @@ -31,7 +31,6 @@ def parseArgs(): parser.add_argument("--params", "-p", help="Optional top-level parameter overrides of the form param=value", 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) parser.add_argument("--lockstepverbose", "-lv", help="Run ImperasDV lock, step, and compare with tracing enabled", action="store_true") parser.add_argument("--covlog", "-d", help="Log coverage after n instructions.", default=0) parser.add_argument("--rvvi", "-r", help="Simulate rvvi hardware interface and ethernet.", action="store_true") @@ -99,8 +98,6 @@ def lockstepSetup(args): suffix = "" ImperasPlusArgs = "" - if(int(args.locksteplog) >= 1): EnableLog = 1 - else: EnableLog = 0 if (args.lockstep or args.lockstepverbose or args.fcov): imperasicPath = os.path.join(WALLY, "config", args.config, "imperas.ic") if not os.path.isfile(imperasicPath): # If config is a derivative, look for imperas.ic in derivative configs @@ -111,7 +108,6 @@ def lockstepSetup(args): prefix += f"IMPERAS_TOOLS={imperasicPath}" if (args.lockstep or args.lockstepverbose): - if(args.locksteplog != 0): ImperasPlusArgs = f" +IDV_TRACE2LOG={EnableLog} +IDV_TRACE2LOG_AFTER={args.locksteplog}" if(args.fcov): CovEnableStr = "1" if int(args.covlog) > 0 else "0" if(args.covlog >= 1): EnableLog = 1 From 783b81f8b8fcca56483167d1b86bedaa871dd1ad Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Mon, 2 Dec 2024 13:52:44 -0800 Subject: [PATCH 02/19] VCD support in all simulators --- bin/wsim | 2 +- testbench/testbench.sv | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/wsim b/bin/wsim index 740193e0f..9defcc1c9 100755 --- a/bin/wsim +++ b/bin/wsim @@ -78,7 +78,7 @@ def elfFileCheck(args): def prepSim(args, ElfFile): flags = "" if args.vcd: - args.args += " -DMAKEVCD=1" + args.params += " MAKE_VCD=1 " if args.rvvi: args.params += " RVVI_SYNTH_SUPPORTED=1 " if args.tb == "testbench_fp": diff --git a/testbench/testbench.sv b/testbench/testbench.sv index c777fdf3f..40f5410ef 100644 --- a/testbench/testbench.sv +++ b/testbench/testbench.sv @@ -44,6 +44,7 @@ module testbench; parameter I_CACHE_ADDR_LOGGER=0; parameter D_CACHE_ADDR_LOGGER=0; parameter RVVI_SYNTH_SUPPORTED=0; + parameter MAKE_VCD=0; `ifdef USE_IMPERAS_DV import idvPkg::*; @@ -230,10 +231,10 @@ module testbench; end $finish; end -`ifdef MAKEVCD - $dumpfile("testbench.vcd"); - $dumpvars; -`endif + if (MAKE_VCD) begin + $dumpfile("testbench.vcd"); + $dumpvars; + end end // initial begin // Model the testbench as an fsm. From edf96a7211763ebdd5f413d417121eacd76b3e9d Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Mon, 2 Dec 2024 13:56:34 -0800 Subject: [PATCH 03/19] Move wsim debug flag to common flags section --- bin/wsim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/wsim b/bin/wsim index 9defcc1c9..8766957b1 100755 --- a/bin/wsim +++ b/bin/wsim @@ -85,6 +85,8 @@ def prepSim(args, ElfFile): args.params += f' TEST="{args.testsuite}" ' if ElfFile != "": args.args += f" {ElfFile}" + if args.gui and args.tb == "testbench": + args.params += " DEBUG=1 " if args.ccov: flags += " --ccov" if args.fcov: @@ -135,8 +137,6 @@ def runSim(args, flags, prefix): def runQuesta(args, flags, prefix): # Force Questa to use 64-bit mode, sometimes it defaults to 32-bit even on 64-bit machines prefix = "MTI_VCO_MODE=64 " + prefix - if (args.gui) and (args.tb == "testbench"): - args.params += "DEBUG=1" if (args.args != ""): args.args = f' --args \\"{args.args}\\"' if (args.params != ""): From 479c6667fe7a0d408ba4e27e874e19e9a9873650 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Mon, 2 Dec 2024 14:02:33 -0800 Subject: [PATCH 04/19] Generalize wsim gui flag and simplify questa launch command --- bin/wsim | 9 +++------ sim/questa/wally.do | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/bin/wsim b/bin/wsim index 8766957b1..512ee5e42 100755 --- a/bin/wsim +++ b/bin/wsim @@ -91,6 +91,8 @@ def prepSim(args, ElfFile): flags += " --ccov" if args.fcov: flags += " --fcov" + if args.gui: + flags += " --gui" prefix, suffix = lockstepSetup(args) flags += suffix return flags, prefix @@ -143,10 +145,7 @@ def runQuesta(args, flags, prefix): args.params = f' --params \\"{args.params}\\"' # Questa cannot accept more than 9 arguments. fcov implies lockstep cmd = f"do wally.do {args.config} {args.testsuite} {args.tb} {args.args} {args.params} {flags}" - if (args.gui): # launch Questa with GUI; add +acc to keep variables accessible - cmd = f'cd $WALLY/sim/questa; {prefix} vsim -do "{cmd} +acc"' - else: # launch Questa in batch mode - cmd = f'cd $WALLY/sim/questa; {prefix} vsim -c -do "{cmd}"' + cmd = f'cd $WALLY/sim/questa; {prefix} vsim {"-c" if not args.gui else ""} -do "{cmd}"' print(f"Running Questa with command: {cmd}") os.system(cmd) @@ -156,8 +155,6 @@ def runVerilator(args, flags, prefix): def runVCS(args, flags, prefix): print(f"Running VCS on {args.config} {args.testsuite}") - # if (args.gui): - # flags += " --gui" if (args.args != ""): args.args = f' --args "{args.args}" ' if (args.params != ""): diff --git a/sim/questa/wally.do b/sim/questa/wally.do index f42bf4930..3935d7a25 100644 --- a/sim/questa/wally.do +++ b/sim/questa/wally.do @@ -8,7 +8,7 @@ # # Takes 1:10 to run RV64IC tests using gui -# Usage: do wally.do [--ccov] [--fcov] [+acc] [--args "any number of +value"] [--params "any number of VAR=VAL parameter overrides"] +# Usage: do wally.do [--ccov] [--fcov] [--gui] [--args "any number of +value"] [--params "any number of VAR=VAL parameter overrides"] # Example: do wally.do rv64gc arch64i testbench # Use this wally.do file to run this example. @@ -91,7 +91,7 @@ echo "number of args = $argc" echo "lst = $lst" # if +acc found set flag and remove from list -if {[lcheck lst "+acc"]} { +if {[lcheck lst "--gui"]} { set GUI 1 set accFlag "+acc" } From bd9ca6ada6d0fac5dd67b3ac7a1cedc31c1ac91e Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Tue, 3 Dec 2024 00:18:00 -0800 Subject: [PATCH 05/19] Remove covlog --- bin/wsim | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bin/wsim b/bin/wsim index 512ee5e42..1b0a848bf 100755 --- a/bin/wsim +++ b/bin/wsim @@ -32,7 +32,6 @@ def parseArgs(): 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("--lockstepverbose", "-lv", help="Run ImperasDV lock, step, and compare with tracing enabled", action="store_true") - parser.add_argument("--covlog", "-d", help="Log coverage after n instructions.", default=0) parser.add_argument("--rvvi", "-r", help="Simulate rvvi hardware interface and ethernet.", action="store_true") return parser.parse_args() @@ -113,10 +112,7 @@ def lockstepSetup(args): if (args.lockstep or args.lockstepverbose): if(args.fcov): - CovEnableStr = "1" if int(args.covlog) > 0 else "0" - if(args.covlog >= 1): EnableLog = 1 - else: EnableLog = 0 - ImperasPlusArgs = f" +IDV_TRACE2COV={EnableLog} +TRACE2LOG_AFTER={args.covlog} +TRACE2COV_ENABLE={CovEnableStr}" + ImperasPlusArgs = f" +IDV_TRACE2COV={0} +TRACE2LOG_AFTER={0} +TRACE2COV_ENABLE={0}" else: suffix = "--lockstep" if(args.lockstepverbose): From 9f92572f2bd9fe3c4061a36a3b612761154072a4 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Tue, 3 Dec 2024 01:26:31 -0800 Subject: [PATCH 06/19] Significantly simplify lockstepSetup function now that covlog and locksteplog are removed --- bin/wsim | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/bin/wsim b/bin/wsim index 1b0a848bf..0db6bb68d 100755 --- a/bin/wsim +++ b/bin/wsim @@ -76,6 +76,7 @@ def elfFileCheck(args): def prepSim(args, ElfFile): flags = "" + prefix = "" if args.vcd: args.params += " MAKE_VCD=1 " if args.rvvi: @@ -92,33 +93,22 @@ def prepSim(args, ElfFile): flags += " --fcov" if args.gui: flags += " --gui" - prefix, suffix = lockstepSetup(args) - flags += suffix + if args.lockstep or args.lockstepverbose: + flags += " --lockstep" + if args.lockstep or args.lockstepverbose or args.fcov: + prefix = lockstepSetup(args) return flags, prefix def lockstepSetup(args): - prefix = "" - suffix = "" - ImperasPlusArgs = "" - - if (args.lockstep or args.lockstepverbose or args.fcov): - imperasicPath = os.path.join(WALLY, "config", args.config, "imperas.ic") - if not os.path.isfile(imperasicPath): # If config is a derivative, look for imperas.ic in derivative configs - imperasicPath = os.path.join(WALLY, "config", "deriv", args.config, "imperas.ic") - if not os.path.isfile(imperasicPath): - print("Error: imperas.ic not found") - exit(1) - prefix += f"IMPERAS_TOOLS={imperasicPath}" - - if (args.lockstep or args.lockstepverbose): - if(args.fcov): - ImperasPlusArgs = f" +IDV_TRACE2COV={0} +TRACE2LOG_AFTER={0} +TRACE2COV_ENABLE={0}" - else: - suffix = "--lockstep" - if(args.lockstepverbose): - prefix += f":{WALLY}/sim/imperas-verbose.ic" - args.args += ImperasPlusArgs - return prefix, suffix + imperasicVerbosePath = os.path.join(WALLY, "sim", "imperas-verbose.ic") + imperasicPath = os.path.join(WALLY, "config", args.config, "imperas.ic") + if not os.path.isfile(imperasicPath): # If config is a derivative, look for imperas.ic in derivative configs + imperasicPath = os.path.join(WALLY, "config", "deriv", args.config, "imperas.ic") + if not os.path.isfile(imperasicPath): + print("Error: imperas.ic not found") + exit(1) + prefix = f"IMPERAS_TOOLS={imperasicPath}{f':{imperasicVerbosePath}' if args.lockstepverbose else ''} " + return prefix def createDirs(args): for d in ["logs", "wkdir", "cov", "ucdb", "fcov", "fcov_ucdb"]: From 8bd4b8b235bb8e843ccf9d54a6e12eabbb6944d3 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Tue, 3 Dec 2024 04:08:23 -0800 Subject: [PATCH 07/19] Simplify wsim createDirs function --- bin/wsim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/wsim b/bin/wsim index 0db6bb68d..a2527205a 100755 --- a/bin/wsim +++ b/bin/wsim @@ -110,9 +110,9 @@ def lockstepSetup(args): prefix = f"IMPERAS_TOOLS={imperasicPath}{f':{imperasicVerbosePath}' if args.lockstepverbose else ''} " return prefix -def createDirs(args): +def createDirs(sim): for d in ["logs", "wkdir", "cov", "ucdb", "fcov", "fcov_ucdb"]: - os.makedirs(os.path.join(WALLY, "sim", args.sim, d), exist_ok=True) + os.makedirs(os.path.join(WALLY, "sim", sim, d), exist_ok=True) def runSim(args, flags, prefix): if (args.sim == "questa"): @@ -155,5 +155,5 @@ if __name__ == "__main__": print(f"Config={args.config} tests={args.testsuite} sim={args.sim} gui={args.gui} args='{args.args}' params='{args.params}'") ElfFile = elfFileCheck(args) flags, prefix = prepSim(args, ElfFile) - createDirs(args) + createDirs(args.sim) exit(runSim(args, flags, prefix)) From a3cd2669672f8566e6710cf7277632ad93c8f7a9 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 12:54:51 -0800 Subject: [PATCH 08/19] Fix run_vcs code coverage flag --- sim/vcs/run_vcs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sim/vcs/run_vcs b/sim/vcs/run_vcs index 1234ac4c8..fb04d0fd2 100755 --- a/sim/vcs/run_vcs +++ b/sim/vcs/run_vcs @@ -24,8 +24,8 @@ parser = argparse.ArgumentParser() parser.add_argument("config", help="Configuration file") parser.add_argument("testsuite", help="Test suite (or none, when running a single ELF file) ") parser.add_argument("--tb", "-t", help="Testbench", choices=["testbench", "testbench_fp"], default="testbench") -parser.add_argument("--coverage", "-c", help="Code & Functional Coverage", action="store_true") -parser.add_argument("--fcov", "-f", help="Code & Functional Coverage", action="store_true") +parser.add_argument("--ccov", "-c", help="Code Coverage", action="store_true") +parser.add_argument("--fcov", "-f", help="Functional Coverage", action="store_true") parser.add_argument("--args", "-a", help="Optional arguments passed to simulator via $value$plusargs", default="") parser.add_argument("--params", "-p", help="Optional top-level parameter overrides of the form param=value", default="") parser.add_argument("--lockstep", "-l", help="Run ImperasDV lock, step, and compare.", action="store_true") @@ -65,7 +65,7 @@ else: LOCKSTEP_SIMV = "" # coverage mode -if (args.coverage): +if (args.ccov): COV_OPTIONS = "-cm line+cond+branch+fsm+tgl -cm_log " + wkdir + "/coverage.log -cm_dir " + wkdir + "/coverage" else: COV_OPTIONS = "" @@ -93,6 +93,6 @@ SIMV_CMD= wkdir + "/" + OUTPUT + " +TEST=" + args.testsuite + " " + args.args + print("Executing: " + str(VCS) ) subprocess.run(VCS, shell=True) subprocess.run(SIMV_CMD, shell=True) -if (args.coverage): +if (args.ccov): COV_RUN = "urg -dir " + wkdir + "/coverage.vdb -format text -report IndividualCovReport/" + args.config + "_" + args.testsuite subprocess.run(COV_RUN, shell=True) From 14ad03cde13b3d33cd6d56f538d6ccf00baca3c4 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 12:55:48 -0800 Subject: [PATCH 09/19] Add .memfile to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9a0f35cc1..1a8b66e80 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ *.map *.elf* *.list +*.memfile # General directories to ignore .vscode/ From 95a5070a729915f7bd56330e7e88746a48802ba4 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 12:56:12 -0800 Subject: [PATCH 10/19] Move IMPERAS_HOME in wally.do to avoid issue if not set --- sim/questa/wally.do | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sim/questa/wally.do b/sim/questa/wally.do index 3935d7a25..6e073ea87 100644 --- a/sim/questa/wally.do +++ b/sim/questa/wally.do @@ -40,7 +40,6 @@ set TESTSUITE ${2} set TESTBENCH ${3} set WKDIR wkdir/${CFG}_${TESTSUITE} set WALLY $::env(WALLY) -set IMPERAS_HOME $::env(IMPERAS_HOME) set CONFIG ${WALLY}/config set SRC ${WALLY}/src set TB ${WALLY}/testbench @@ -118,6 +117,7 @@ if {[lcheck lst "--fcov"]} { # if --lockstep or --fcov found set flag and remove from list if {[lcheck lst "--lockstep"] || $FunctCoverage == 1} { + set IMPERAS_HOME $::env(IMPERAS_HOME) set lockstep 1 set lockstepvlog "+define+USE_IMPERAS_DV \ +incdir+${IMPERAS_HOME}/ImpPublic/include/host \ From 25cdf83aaee202eeb4c4c371f090efe0552ef884 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 13:13:35 -0800 Subject: [PATCH 11/19] Remove extra spaces and use lists for assembling args and params --- bin/wsim | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/bin/wsim b/bin/wsim index a2527205a..1fde4eda1 100755 --- a/bin/wsim +++ b/bin/wsim @@ -39,7 +39,7 @@ def validateArgs(args): if not args.testsuite and not args.elf: print("Error: Missing test suite or ELF file") exit(1) - if args.lockstep and not args.testsuite.endswith('.elf') and args.testsuite != "buildroot" : + if args.lockstep and not args.testsuite.endswith('.elf') and args.testsuite != "buildroot": print(f"Invalid Options. Cannot run a testsuite, {args.testsuite} with lockstep. Must run a single elf or buildroot.") exit(1) elif (args.gui or args.ccov or args.fcov or args.lockstep or args.lockstepverbose) and args.sim not in ["questa", "vcs"]: @@ -75,28 +75,34 @@ def elfFileCheck(args): return ElfFile def prepSim(args, ElfFile): - flags = "" prefix = "" + params = [] + args = [] + flags = [] if args.vcd: - args.params += " MAKE_VCD=1 " + params.append("MAKE_VCD=1") if args.rvvi: - args.params += " RVVI_SYNTH_SUPPORTED=1 " + params.append("RVVI_SYNTH_SUPPORTED=1") if args.tb == "testbench_fp": - args.params += f' TEST="{args.testsuite}" ' - if ElfFile != "": - args.args += f" {ElfFile}" + params.append(f'TEST="{args.testsuite}"') + if ElfFile: + args.append += f"{ElfFile}" if args.gui and args.tb == "testbench": - args.params += " DEBUG=1 " + params.append("DEBUG=1") if args.ccov: - flags += " --ccov" + flags.append("--ccov") if args.fcov: - flags += " --fcov" + flags.append("--fcov") if args.gui: - flags += " --gui" + flags.append("--gui") if args.lockstep or args.lockstepverbose: - flags += " --lockstep" + flags.append("--lockstep") if args.lockstep or args.lockstepverbose or args.fcov: prefix = lockstepSetup(args) + # Combine into a single string + args.args += " ".join(args) + args.params += " ".join(params) + flags = " ".join(flags) return flags, prefix def lockstepSetup(args): @@ -107,7 +113,7 @@ def lockstepSetup(args): if not os.path.isfile(imperasicPath): print("Error: imperas.ic not found") exit(1) - prefix = f"IMPERAS_TOOLS={imperasicPath}{f':{imperasicVerbosePath}' if args.lockstepverbose else ''} " + prefix = f"IMPERAS_TOOLS={imperasicPath}{f':{imperasicVerbosePath}' if args.lockstepverbose else ''}" return prefix def createDirs(sim): @@ -126,9 +132,9 @@ def runQuesta(args, flags, prefix): # Force Questa to use 64-bit mode, sometimes it defaults to 32-bit even on 64-bit machines prefix = "MTI_VCO_MODE=64 " + prefix if (args.args != ""): - args.args = f' --args \\"{args.args}\\"' + args.args = fr'--args \"{args.args}\"' if (args.params != ""): - args.params = f' --params \\"{args.params}\\"' + args.params = fr'--params \"{args.params}\"' # Questa cannot accept more than 9 arguments. fcov implies lockstep cmd = f"do wally.do {args.config} {args.testsuite} {args.tb} {args.args} {args.params} {flags}" cmd = f'cd $WALLY/sim/questa; {prefix} vsim {"-c" if not args.gui else ""} -do "{cmd}"' @@ -142,9 +148,9 @@ def runVerilator(args, flags, prefix): def runVCS(args, flags, prefix): print(f"Running VCS on {args.config} {args.testsuite}") if (args.args != ""): - args.args = f' --args "{args.args}" ' + args.args = f'--args "{args.args}"' if (args.params != ""): - args.params = f' --params "{args.params}" ' + args.params = f'--params "{args.params}"' cmd = f"cd $WALLY/sim/vcs; {prefix} ./run_vcs {args.config} {args.testsuite} --tb {args.tb} {args.args} {args.params} {flags}" print(cmd) os.system(cmd) From bdc20243a6d183ca73bd8d7d9e317c46becdf551 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 13:18:03 -0800 Subject: [PATCH 12/19] Fix overriding args --- bin/wsim | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/bin/wsim b/bin/wsim index 1fde4eda1..9bc3252bc 100755 --- a/bin/wsim +++ b/bin/wsim @@ -76,33 +76,33 @@ def elfFileCheck(args): def prepSim(args, ElfFile): prefix = "" - params = [] - args = [] - flags = [] + paramsList = [] + argsList = [] + flagsList = [] if args.vcd: - params.append("MAKE_VCD=1") + paramsList.append("MAKE_VCD=1") if args.rvvi: - params.append("RVVI_SYNTH_SUPPORTED=1") + paramsList.append("RVVI_SYNTH_SUPPORTED=1") if args.tb == "testbench_fp": - params.append(f'TEST="{args.testsuite}"') + paramsList.append(f'TEST="{args.testsuite}"') if ElfFile: - args.append += f"{ElfFile}" + argsList.append += f"{ElfFile}" if args.gui and args.tb == "testbench": - params.append("DEBUG=1") + paramsList.append("DEBUG=1") if args.ccov: - flags.append("--ccov") + flagsList.append("--ccov") if args.fcov: - flags.append("--fcov") + flagsList.append("--fcov") if args.gui: - flags.append("--gui") + flagsList.append("--gui") if args.lockstep or args.lockstepverbose: - flags.append("--lockstep") + flagsList.append("--lockstep") if args.lockstep or args.lockstepverbose or args.fcov: prefix = lockstepSetup(args) # Combine into a single string - args.args += " ".join(args) - args.params += " ".join(params) - flags = " ".join(flags) + args.args += " ".join(argsList) + args.params += " ".join(paramsList) + flags = " ".join(flagsList) return flags, prefix def lockstepSetup(args): From 59bedb78c58377df3844d27cdafcf97e65226856 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 13:24:10 -0800 Subject: [PATCH 13/19] Cleanup verilator paths --- sim/verilator/Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sim/verilator/Makefile b/sim/verilator/Makefile index 6a6ad267a..666516c2d 100644 --- a/sim/verilator/Makefile +++ b/sim/verilator/Makefile @@ -17,12 +17,10 @@ EXPANDED_PARAM_ARGS:=$(patsubst %,-G%,$(PARAM_ARGS)) WALLYCONF?=rv64gc TEST?=arch64i -TESTBENCH?=testbench +TESTBENCH?=testbench # constants # assume WALLY variable is correctly configured in the shell environment -WORKING_DIR=${WALLY}/sim/verilator -TARGET=$(WORKING_DIR)/target # INCLUDE_PATH are pathes that Verilator should search for files it needs INCLUDE_PATH="-I${WALLY}/config/shared" "-I${WALLY}/config/$(WALLYCONF)" "-I${WALLY}/config/deriv/$(WALLYCONF)" # SOURCES are source files @@ -30,6 +28,8 @@ SOURCES=${WALLY}/src/cvw.sv ${WALLY}/testbench/${TESTBENCH}.sv ${WALLY}/testbenc # DEPENDENCIES are configuration files and source files, which leads to recompilation of executables DEPENDENCIES=${WALLY}/config/shared/*.vh $(SOURCES) +WORKDIR = $(VERILATOR_DIR)/wkdir/$(WALLYCONF)_$(TEST) + # regular testbench requires a wrapper defining getenvval ifeq ($(TESTBENCH), testbench) WRAPPER=${WALLY}/sim/verilator/wrapper.c @@ -41,9 +41,9 @@ endif default: run -run: wkdir/$(WALLYCONF)_$(TEST)/V${TESTBENCH} +run: $(WORKDIR)/V${TESTBENCH} mkdir -p $(VERILATOR_DIR)/logs - wkdir/$(WALLYCONF)_$(TEST)/V${TESTBENCH} ${ARGTEST} $(PLUS_ARGS) + $(WORKDIR)/V${TESTBENCH} ${ARGTEST} $(PLUS_ARGS) profile: obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF) $(VERILATOR_DIR)/obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF) ${ARGTEST} @@ -54,10 +54,10 @@ profile: obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF) mv gmon_$(WALLYCONF)* $(VERILATOR_DIR)/logs_profiling echo "Please check $(VERILATOR_DIR)/logs_profiling/gmon_$(WALLYCONF)* for logs and output files." -wkdir/$(WALLYCONF)_$(TEST)/V${TESTBENCH}: $(DEPENDENCIES) - mkdir -p wkdir/$(WALLYCONF)_$(TEST) +$(WORKDIR)/V${TESTBENCH}: $(DEPENDENCIES) + mkdir -p $(WORKDIR) verilator \ - --Mdir wkdir/$(WALLYCONF)_$(TEST) -o V${TESTBENCH} \ + --Mdir $(WORKDIR) -o V${TESTBENCH} \ --binary --trace \ $(OPT) $(PARAMS) $(NONPROF) \ --top-module ${TESTBENCH} --relative-includes \ From 8b2a053bd430972b74122ef935359500d1b0bc17 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 13:32:56 -0800 Subject: [PATCH 14/19] Remove unnecessary parentheses in wsim --- bin/wsim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/wsim b/bin/wsim index 9bc3252bc..597d7f111 100755 --- a/bin/wsim +++ b/bin/wsim @@ -121,19 +121,19 @@ def createDirs(sim): os.makedirs(os.path.join(WALLY, "sim", sim, d), exist_ok=True) def runSim(args, flags, prefix): - if (args.sim == "questa"): + if args.sim == "questa": runQuesta(args, flags, prefix) - elif (args.sim == "verilator"): + elif args.sim == "verilator": runVerilator(args, flags, prefix) - elif (args.sim == "vcs"): + elif args.sim == "vcs": runVCS(args, flags, prefix) def runQuesta(args, flags, prefix): # Force Questa to use 64-bit mode, sometimes it defaults to 32-bit even on 64-bit machines prefix = "MTI_VCO_MODE=64 " + prefix - if (args.args != ""): + if args.args != "": args.args = fr'--args \"{args.args}\"' - if (args.params != ""): + if args.params != "": args.params = fr'--params \"{args.params}\"' # Questa cannot accept more than 9 arguments. fcov implies lockstep cmd = f"do wally.do {args.config} {args.testsuite} {args.tb} {args.args} {args.params} {flags}" From 8fc907a4966a0ace4998d9d681e492cf759eee3c Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 13:33:14 -0800 Subject: [PATCH 15/19] Switch to sys.exit in wsim --- bin/wsim | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/bin/wsim b/bin/wsim index 597d7f111..95bbda312 100755 --- a/bin/wsim +++ b/bin/wsim @@ -13,6 +13,7 @@ import argparse import os +import sys # Global variable WALLY = os.environ.get('WALLY') @@ -38,16 +39,16 @@ def parseArgs(): def validateArgs(args): if not args.testsuite and not args.elf: print("Error: Missing test suite or ELF file") - exit(1) + sys.exit(1) if args.lockstep and not args.testsuite.endswith('.elf') and args.testsuite != "buildroot": print(f"Invalid Options. Cannot run a testsuite, {args.testsuite} with lockstep. Must run a single elf or buildroot.") - exit(1) + sys.exit(1) elif (args.gui or args.ccov or args.fcov or args.lockstep or args.lockstepverbose) and args.sim not in ["questa", "vcs"]: print("Option only supported for Questa and VCS") - exit(1) + sys.exit(1) elif (args.tb == "testbench_fp" and args.sim != "questa"): print("Error: testbench_fp presently only supported by Questa, not VCS or Verilator, because of a touchy testbench") - exit(1) + sys.exit(1) def elfFileCheck(args): ElfFile = "" @@ -55,23 +56,23 @@ def elfFileCheck(args): ElfFile = f"+ElfFile={os.path.abspath(args.elf)}" elif args.elf != "": print(f"ELF file not found: {args.elf}") - exit(1) + sys.exit(1) elif args.testsuite.endswith('.elf'): # No --elf argument; check if testsuite has a .elf extension and use that instead if os.path.isfile(args.testsuite): ElfFile = f"+ElfFile={os.path.abspath(args.testsuite)}" # extract the elf name from the path to be the test suite fields = args.testsuite.rsplit('/', 3) # if the name is just ref.elf in a deep path (riscv-arch-test/wally-riscv-arch-test), then use the directory name as the test suite to make it unique; otherwise work directory will have duplicates. - if (len(fields) > 3): - if (fields[2] == "ref"): + if len(fields) > 3: + if fields[2] == "ref": args.testsuite = f"{fields[1]}_{fields[3]}" else: args.testsuite = f"{fields[2]}_{fields[3]}" - elif ('/' in args.testsuite): + elif '/' in args.testsuite: args.testsuite=args.testsuite.rsplit('/', 1)[1] # strip off path if present else: print(f"ELF file not found: {args.testsuite}") - exit(1) + sys.exit(1) return ElfFile def prepSim(args, ElfFile): @@ -112,7 +113,7 @@ def lockstepSetup(args): imperasicPath = os.path.join(WALLY, "config", "deriv", args.config, "imperas.ic") if not os.path.isfile(imperasicPath): print("Error: imperas.ic not found") - exit(1) + sys.exit(1) prefix = f"IMPERAS_TOOLS={imperasicPath}{f':{imperasicVerbosePath}' if args.lockstepverbose else ''}" return prefix @@ -147,9 +148,9 @@ def runVerilator(args, flags, prefix): def runVCS(args, flags, prefix): print(f"Running VCS on {args.config} {args.testsuite}") - if (args.args != ""): + if args.args != "": args.args = f'--args "{args.args}"' - if (args.params != ""): + if args.params != "": args.params = f'--params "{args.params}"' cmd = f"cd $WALLY/sim/vcs; {prefix} ./run_vcs {args.config} {args.testsuite} --tb {args.tb} {args.args} {args.params} {flags}" print(cmd) @@ -162,4 +163,4 @@ if __name__ == "__main__": ElfFile = elfFileCheck(args) flags, prefix = prepSim(args, ElfFile) createDirs(args.sim) - exit(runSim(args, flags, prefix)) + sys.exit(runSim(args, flags, prefix)) From c178180b0f50cda7de4098e46a2d51fdddc2491e Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 13:53:18 -0800 Subject: [PATCH 16/19] A bit more cleanup --- bin/wsim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/wsim b/bin/wsim index 95bbda312..dbe106280 100755 --- a/bin/wsim +++ b/bin/wsim @@ -43,7 +43,7 @@ def validateArgs(args): if args.lockstep and not args.testsuite.endswith('.elf') and args.testsuite != "buildroot": print(f"Invalid Options. Cannot run a testsuite, {args.testsuite} with lockstep. Must run a single elf or buildroot.") sys.exit(1) - elif (args.gui or args.ccov or args.fcov or args.lockstep or args.lockstepverbose) and args.sim not in ["questa", "vcs"]: + elif any([args.gui, args.ccov, args.fcov, args.lockstep, args.lockstepverbose]) and args.sim not in ["questa", "vcs"]: print("Option only supported for Questa and VCS") sys.exit(1) elif (args.tb == "testbench_fp" and args.sim != "questa"): @@ -125,7 +125,7 @@ def runSim(args, flags, prefix): if args.sim == "questa": runQuesta(args, flags, prefix) elif args.sim == "verilator": - runVerilator(args, flags, prefix) + runVerilator(args) elif args.sim == "vcs": runVCS(args, flags, prefix) @@ -142,7 +142,7 @@ def runQuesta(args, flags, prefix): print(f"Running Questa with command: {cmd}") os.system(cmd) -def runVerilator(args, flags, prefix): +def runVerilator(args): print(f"Running Verilator on {args.config} {args.testsuite}") os.system(f'make -C {WALLY}/sim/verilator WALLYCONF={args.config} TEST={args.testsuite} TESTBENCH={args.tb} PLUS_ARGS="{args.args}" PARAM_ARGS="{args.params}"') From c9885ff495ad6f314cb6bfddeb888336db6008b8 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 13:54:47 -0800 Subject: [PATCH 17/19] Change wsim main function for potential use as imported module in regression-wally --- bin/wsim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/wsim b/bin/wsim index dbe106280..55ca015e6 100755 --- a/bin/wsim +++ b/bin/wsim @@ -156,11 +156,14 @@ def runVCS(args, flags, prefix): print(cmd) os.system(cmd) -if __name__ == "__main__": - args = parseArgs() +def main(args): validateArgs(args) print(f"Config={args.config} tests={args.testsuite} sim={args.sim} gui={args.gui} args='{args.args}' params='{args.params}'") ElfFile = elfFileCheck(args) flags, prefix = prepSim(args, ElfFile) createDirs(args.sim) sys.exit(runSim(args, flags, prefix)) + +if __name__ == "__main__": + args = parseArgs() + main(args) From 464a516e989309a2a134e3be48bcb6da47666147 Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 13:58:45 -0800 Subject: [PATCH 18/19] Disable fcov on testsuite --- bin/wsim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/wsim b/bin/wsim index 55ca015e6..e8862ec95 100755 --- a/bin/wsim +++ b/bin/wsim @@ -40,8 +40,8 @@ def validateArgs(args): if not args.testsuite and not args.elf: print("Error: Missing test suite or ELF file") sys.exit(1) - if args.lockstep and not args.testsuite.endswith('.elf') and args.testsuite != "buildroot": - print(f"Invalid Options. Cannot run a testsuite, {args.testsuite} with lockstep. Must run a single elf or buildroot.") + if any([args.lockstep, args.lockstepverbose, args.fcov]) and not (args.testsuite.endswith('.elf') or args.elf) and args.testsuite != "buildroot": + print(f"Invalid Options. Cannot run a testsuite, {args.testsuite} with lockstep or fcov. Must run a single elf or buildroot.") sys.exit(1) elif any([args.gui, args.ccov, args.fcov, args.lockstep, args.lockstepverbose]) and args.sim not in ["questa", "vcs"]: print("Option only supported for Questa and VCS") From 256211e4dcc3bfb806ba5d97ea25886aa06a8f4d Mon Sep 17 00:00:00 2001 From: Jordan Carlin Date: Sat, 7 Dec 2024 14:06:31 -0800 Subject: [PATCH 19/19] Fix wsim elfile handling --- bin/wsim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/wsim b/bin/wsim index e8862ec95..ebee44883 100755 --- a/bin/wsim +++ b/bin/wsim @@ -87,7 +87,7 @@ def prepSim(args, ElfFile): if args.tb == "testbench_fp": paramsList.append(f'TEST="{args.testsuite}"') if ElfFile: - argsList.append += f"{ElfFile}" + argsList.append(f"{ElfFile}") if args.gui and args.tb == "testbench": paramsList.append("DEBUG=1") if args.ccov: