2021-01-25 16:28:43 +00:00
#!/usr/bin/python3
##################################
#
2022-01-07 17:47:38 +00:00
# regression-wally
2021-01-25 16:28:43 +00:00
# David_Harris@Hmc.edu 25 January 2021
2021-05-04 22:58:23 +00:00
# Modified by Jarred Allen <jaallen@g.hmc.edu>
2021-01-25 16:28:43 +00:00
#
2021-05-04 22:58:23 +00:00
# Run a regression with multiple configurations in parallel and exit with
# non-zero status code if an error happened, as well as printing human-readable
# output.
2021-01-25 16:28:43 +00:00
#
##################################
2022-12-15 18:24:58 +00:00
import sys,os,shutil
2021-01-25 16:28:43 +00:00
2022-01-27 04:40:32 +00:00
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
2021-04-22 17:29:55 +00:00
from collections import namedtuple
2021-12-07 19:16:43 +00:00
regressionDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(regressionDir)
2022-12-15 18:24:58 +00:00
2023-03-09 23:59:57 +00:00
coverage = '-coverage' in sys.argv
2023-04-19 20:07:07 +00:00
fp = '-fp' in sys.argv
2023-03-09 23:59:57 +00:00
2021-12-30 00:53:39 +00:00
TestCase = namedtuple("TestCase", ['name', 'variant', 'cmd', 'grepstr'])
2021-05-04 22:58:23 +00:00
# name: the name of this test configuration (used in printing human-readable
# output and picking logfile names)
# cmd: the command to run to test (should include the logfile as '{}', and
# the command needs to write to that file)
# grepstr: the string to grep through the log file for. The test succeeds iff
# grep finds that string in the logfile (is used by grep, so it may
# be any pattern grep accepts, see `man 1 grep` for more info).
2021-04-22 17:29:55 +00:00
2021-05-04 22:58:23 +00:00
# edit this list to add more test cases
2021-04-22 17:29:55 +00:00
configs = [
2021-05-04 22:58:23 +00:00
TestCase(
2021-05-03 21:32:05 +00:00
name="lints",
2021-12-30 00:53:39 +00:00
variant="all",
2022-05-20 01:30:59 +00:00
cmd="./lint-wally | tee {}",
2021-05-03 21:32:05 +00:00
grepstr="All lints run with no errors or warnings"
2021-10-23 20:17:30 +00:00
)
2021-04-22 17:29:55 +00:00
]
2022-06-29 20:40:11 +00:00
def getBuildrootTC(boot):
2022-04-18 01:29:38 +00:00
INSTR_LIMIT = 4000000 # multiple of 100000; 4M is interesting because it gets into the kernel and enabling VM
2022-05-26 00:40:57 +00:00
MAX_EXPECTED = 246000000 # *** TODO: replace this with a search for the login prompt.
2022-06-29 20:40:11 +00:00
if boot:
name="buildrootboot"
2023-02-04 12:38:41 +00:00
BRcmd="vsim > {} -c <<!\ndo wally.do buildroot buildroot-no-trace $RISCV 0 1 0\n!"
2022-06-29 20:40:11 +00:00
BRgrepstr="WallyHostname login:"
else:
name="buildroot"
2023-03-31 16:15:15 +00:00
if (coverage):
print( "buildroot coverage")
BRcmd="vsim > {} -c <<!\ndo wally-batch.do buildroot buildroot $RISCV "+str(INSTR_LIMIT)+" 1 0 -coverage\n!"
else:
print( "buildroot no coverage")
BRcmd="vsim > {} -c <<!\ndo wally-batch.do buildroot buildroot $RISCV "+str(INSTR_LIMIT)+" 1 0\n!"
2021-10-23 20:17:30 +00:00
BRgrepstr=str(INSTR_LIMIT)+" instructions"
2022-06-29 20:40:11 +00:00
return TestCase(name,variant="rv64gc",cmd=BRcmd,grepstr=BRgrepstr)
2021-01-25 16:28:43 +00:00
2021-11-21 03:42:53 +00:00
tc = TestCase(
name="buildroot-checkpoint",
2022-02-02 16:35:52 +00:00
variant="rv64gc",
2023-02-04 12:38:41 +00:00
cmd="vsim > {} -c <<!\ndo wally-batch.do buildroot buildroot-checkpoint $RISCV 400100000 400000001 400000000\n!", # *** will this work with rv64gc rather than buildroot config?
2021-11-21 03:42:53 +00:00
grepstr="400100000 instructions")
2022-03-02 16:00:19 +00:00
configs.append(tc)
2021-11-21 03:42:53 +00:00
2023-01-16 15:01:07 +00:00
tests64gcimperas = ["imperas64i", "imperas64f", "imperas64d", "imperas64m", "imperas64c"] # unused
2022-05-04 21:20:01 +00:00
2022-10-10 17:22:12 +00:00
tests64i = ["arch64i"]
2022-10-10 16:10:55 +00:00
for test in tests64i:
tc = TestCase(
name=test,
variant="rv64i",
2023-02-04 12:38:41 +00:00
cmd="vsim > {} -c <<!\ndo wally-batch.do rv64i "+test+"\n!",
2022-10-10 16:10:55 +00:00
grepstr="All tests ran without failures")
configs.append(tc)
2023-01-16 15:01:07 +00:00
tests32gcimperas = ["imperas32i", "imperas32f", "imperas32m", "imperas32c"] # unused
2023-02-23 04:18:05 +00:00
tests32gc = ["arch32f", "arch32d", "arch32i", "arch32priv", "arch32c", "arch32m", "arch32zi", "arch32zba", "arch32zbb", "arch32zbc", "arch32zbs", "wally32a", "wally32priv", "wally32periph"]
2021-12-30 00:53:39 +00:00
for test in tests32gc:
2021-10-10 22:07:51 +00:00
tc = TestCase(
name=test,
2021-12-30 00:53:39 +00:00
variant="rv32gc",
2023-02-04 12:38:41 +00:00
cmd="vsim > {} -c <<!\ndo wally-batch.do rv32gc "+test+"\n!",
2021-10-10 22:07:51 +00:00
grepstr="All tests ran without failures")
configs.append(tc)
2023-01-29 19:33:54 +00:00
tests32imcimperas = ["imperas32i", "imperas32c"] # unused
tests32imc = ["arch32i", "arch32c", "arch32m", "wally32periph"]
for test in tests32imc:
2021-12-30 00:53:39 +00:00
tc = TestCase(
name=test,
2023-01-29 19:33:54 +00:00
variant="rv32imc",
2023-02-04 12:38:41 +00:00
cmd="vsim > {} -c <<!\ndo wally-batch.do rv32imc "+test+"\n!",
2021-12-30 00:53:39 +00:00
grepstr="All tests ran without failures")
configs.append(tc)
2021-10-10 22:07:51 +00:00
2022-10-10 17:22:12 +00:00
tests32i = ["arch32i"]
2022-09-07 16:37:59 +00:00
for test in tests32i:
tc = TestCase(
name=test,
variant="rv32i",
2023-02-04 12:38:41 +00:00
cmd="vsim > {} -c <<!\ndo wally-batch.do rv32i "+test+"\n!",
2022-09-07 16:37:59 +00:00
grepstr="All tests ran without failures")
configs.append(tc)
2022-02-08 12:18:13 +00:00
tests32e = ["wally32e"]
for test in tests32e:
tc = TestCase(
name=test,
variant="rv32e",
2023-02-04 12:38:41 +00:00
cmd="vsim > {} -c <<!\ndo wally-batch.do rv32e "+test+"\n!",
2022-02-08 12:18:13 +00:00
grepstr="All tests ran without failures")
configs.append(tc)
2022-01-14 17:13:06 +00:00
2022-09-07 17:03:58 +00:00
ahbTests = [("0", "0"), ("0", "1"), ("1", "0"), ("1", "1"), ("2", "0"), ("2", "1")]
for test in ahbTests:
tc = TestCase(
2022-09-07 17:06:15 +00:00
name="ram_latency_" + test[0] + "_burst_en_" + test[1],
2022-09-07 17:03:58 +00:00
variant="ahb",
2023-02-04 12:38:41 +00:00
cmd="vsim > {} -c <<!\ndo wally-batch.do rv64gc ahb "+test[0]+" "+test[1]+"\n!",
2022-09-07 17:03:58 +00:00
grepstr="All tests ran without failures")
configs.append(tc)
2023-03-09 23:59:57 +00:00
2023-03-23 16:06:05 +00:00
tests64gc = ["arch64f", "arch64d", "arch64i", "arch64zba", "arch64zbb", "arch64zbc", "arch64zbs",
"arch64priv", "arch64c", "arch64m", "arch64zi", "wally64a", "wally64periph", "wally64priv"]
2023-03-09 23:59:57 +00:00
if (coverage): # delete all but 64gc tests when running coverage
configs = []
2023-03-31 16:15:15 +00:00
# tests64gc = ["coverage64gc", "arch64f", "arch64d", "arch64i", "arch64priv", "arch64c", "arch64m",
2023-03-23 17:55:32 +00:00
tests64gc = ["coverage64gc", "arch64i", "arch64priv", "arch64c", "arch64m",
2023-03-23 16:06:05 +00:00
"arch64zi", "wally64a", "wally64periph", "wally64priv",
"arch64zba", "arch64zbb", "arch64zbc", "arch64zbs",
"imperas64f", "imperas64d", "imperas64c", "imperas64i"]
2023-04-19 20:07:07 +00:00
if (fp):
tests64gc.append("arch64f")
tests64gc.append("arch64d")
2023-03-09 23:59:57 +00:00
coverStr = '-coverage'
else:
coverStr = ''
for test in tests64gc:
tc = TestCase(
name=test,
variant="rv64gc",
cmd="vsim > {} -c <<!\ndo wally-batch.do rv64gc "+test+" " + coverStr + "\n!",
grepstr="All tests ran without failures")
configs.append(tc)
2022-09-07 17:03:58 +00:00
2021-10-10 22:07:51 +00:00
2021-05-17 22:44:47 +00:00
import os
from multiprocessing import Pool, TimeoutError
2021-01-25 16:28:43 +00:00
2021-02-02 22:20:45 +00:00
def search_log_for_text(text, logfile):
"""Search through the given log file for text, returning True if it is found or False if it is not"""
grepcmd = "grep -e '%s' '%s' > /dev/null" % (text, logfile)
return os.system(grepcmd) == 0
2021-05-17 22:44:47 +00:00
def run_test_case(config):
2021-05-04 22:58:23 +00:00
"""Run the given test case, and return 0 if the test suceeds and 1 if it fails"""
2021-12-30 00:53:39 +00:00
logname = "logs/"+config.variant+"_"+config.name+".log"
2021-05-17 22:44:47 +00:00
cmd = config.cmd.format(logname)
2023-03-24 15:11:15 +00:00
# print(cmd)
2021-12-07 21:13:30 +00:00
os.chdir(regressionDir)
2021-02-02 22:05:35 +00:00
os.system(cmd)
2021-05-17 22:44:47 +00:00
if search_log_for_text(config.grepstr, logname):
2022-01-27 04:40:32 +00:00
print(f"{bcolors.OKGREEN}%s_%s: Success{bcolors.ENDC}" % (config.variant, config.name))
2021-04-22 17:29:55 +00:00
return 0
else:
2022-01-27 04:40:32 +00:00
print(f"{bcolors.FAIL}%s_%s: Failures detected in output{bcolors.ENDC}" % (config.variant, config.name))
2021-05-17 22:44:47 +00:00
print(" Check %s" % logname)
2021-04-22 17:29:55 +00:00
return 1
2021-02-02 22:20:45 +00:00
2021-05-04 22:58:23 +00:00
def main():
"""Run the tests and count the failures"""
2023-03-09 23:59:57 +00:00
global configs, coverage
2021-12-06 23:37:33 +00:00
try:
2021-12-07 21:13:30 +00:00
os.chdir(regressionDir)
2021-12-06 23:37:33 +00:00
os.mkdir("logs")
except:
pass
2022-12-16 18:51:21 +00:00
try:
shutil.rmtree("wkdir")
except:
pass
finally:
os.mkdir("wkdir")
2022-12-15 18:24:58 +00:00
2021-12-06 23:37:33 +00:00
if '-makeTests' in sys.argv:
2021-12-07 21:13:30 +00:00
os.chdir(regressionDir)
2021-12-06 23:37:33 +00:00
os.system('./make-tests.sh | tee ./logs/make-tests.log')
2021-10-23 20:17:30 +00:00
if '-all' in sys.argv:
2022-06-29 20:40:11 +00:00
TIMEOUT_DUR = 30*7200 # seconds
configs.append(getBuildrootTC(boot=True))
2021-12-06 22:13:58 +00:00
elif '-buildroot' in sys.argv:
2022-06-29 20:40:11 +00:00
TIMEOUT_DUR = 30*7200 # seconds
configs=[getBuildrootTC(boot=True)]
2023-03-09 23:59:57 +00:00
elif '-coverage' in sys.argv:
2023-03-31 16:59:38 +00:00
TIMEOUT_DUR = 20*60 # seconds
# Presently don't run buildroot because it has a different config and can't be merged with the rv64gc coverage.
# Also it is slow to run.
# configs.append(getBuildrootTC(boot=False))
os.system('rm -f cov/*.ucdb')
2021-10-23 20:17:30 +00:00
else:
2022-05-03 11:56:31 +00:00
TIMEOUT_DUR = 10*60 # seconds
2022-06-29 20:40:11 +00:00
configs.append(getBuildrootTC(boot=False))
2021-10-23 20:17:30 +00:00
2021-12-06 23:37:33 +00:00
# Scale the number of concurrent processes to the number of test cases, but
# max out at a limited number of concurrent processes to not overwhelm the system
2022-01-27 14:45:25 +00:00
with Pool(processes=min(len(configs),40)) as pool:
2021-05-17 22:44:47 +00:00
num_fail = 0
results = {}
for config in configs:
results[config] = pool.apply_async(run_test_case,(config,))
for (config,result) in results.items():
try:
num_fail+=result.get(timeout=TIMEOUT_DUR)
except TimeoutError:
num_fail+=1
2022-01-27 04:40:32 +00:00
print(f"{bcolors.FAIL}%s_%s: Timeout - runtime exceeded %d seconds{bcolors.ENDC}" % (config.variant, config.name, TIMEOUT_DUR))
2021-05-17 22:44:47 +00:00
2023-03-09 23:59:57 +00:00
# Coverage report
if coverage:
2023-03-22 11:34:49 +00:00
os.system('make coverage')
2021-05-04 22:58:23 +00:00
# Count the number of failures
if num_fail:
2022-01-27 04:40:32 +00:00
print(f"{bcolors.FAIL}Regression failed with %s failed configurations{bcolors.ENDC}" % num_fail)
2021-05-04 22:58:23 +00:00
else:
2022-01-27 04:40:32 +00:00
print(f"{bcolors.OKGREEN}SUCCESS! All tests ran without failures{bcolors.ENDC}")
2021-05-04 22:58:23 +00:00
return num_fail
2021-01-25 16:28:43 +00:00
2021-05-04 22:58:23 +00:00
if __name__ == '__main__':
exit(main())