runtests: use argparse for argument parsing, and support passing a different tb executable

This commit is contained in:
Luke Wren 2024-06-02 10:36:29 +01:00
parent a9ba69f4dd
commit b026814674
2 changed files with 14 additions and 10 deletions

View File

@ -9,8 +9,8 @@ endif
CCFLAGS ?= CCFLAGS ?=
LDSCRIPT ?= ../common/memmap.ld LDSCRIPT ?= ../common/memmap.ld
CROSS_PREFIX ?= riscv32-unknown-elf- CROSS_PREFIX ?= riscv32-unknown-elf-
TBDIR ?= ../tb_cxxrtl
TBEXEC ?= $(TBDIR)/tb TBEXEC ?= $(TBDIR)/tb
TBDIR := $(dir $(abspath $(TBEXEC)))
INCDIR ?= ../common INCDIR ?= ../common
MAX_CYCLES ?= 100000 MAX_CYCLES ?= 100000
TMP_PREFIX ?= tmp/ TMP_PREFIX ?= tmp/

View File

@ -3,16 +3,19 @@
import os import os
import subprocess import subprocess
import sys import sys
import argparse
args = sys.argv[1:] args = sys.argv[1:]
generate_vcd = False parser = argparse.ArgumentParser()
if "--vcd" in args: parser.add_argument("tests", nargs="*", help="List of tests to run. Empty to run all tests. Each test corresponds to one C file.")
generate_vcd = True parser.add_argument("--vcd", action="store_true", help="Pass --vcd flag to simulator, to generate waveform dumps.")
del args[args.index("--vcd")] parser.add_argument("--tb", default="../tb_cxxrtl/tb", help="Pass tb executable to run tests.")
args = parser.parse_args()
if len(args) > 0: testlist = args.tests
testlist = args
if len(testlist) > 0:
# This happens a lot when autocomplete is used: # This happens a lot when autocomplete is used:
for i, n in enumerate(testlist): for i, n in enumerate(testlist):
if n.endswith(".c"): if n.endswith(".c"):
@ -25,8 +28,9 @@ else:
testlist = sorted(testlist) testlist = sorted(testlist)
tb_dir = os.path.join(*os.path.split(os.path.abspath(args.tb))[:-1])
tb_build_ret = subprocess.run( tb_build_ret = subprocess.run(
["make", "-C", "../tb_cxxrtl", "tb"], ["make", "-C", tb_dir, "all"],
timeout=300 timeout=300
) )
if tb_build_ret.returncode != 0: if tb_build_ret.returncode != 0:
@ -46,8 +50,8 @@ for test in testlist:
all_passed = False all_passed = False
continue continue
cmdline = ["../tb_cxxrtl/tb", "--bin", f"tmp/{test}.bin", "--cycles", "1000000"] cmdline = [args.tb, "--bin", f"tmp/{test}.bin", "--cycles", "1000000"]
if generate_vcd: if args.vcd:
cmdline += ["--vcd", f"tmp/{test}.vcd"] cmdline += ["--vcd", f"tmp/{test}.vcd"]
try: try: