Lots of f-strings

This commit is contained in:
Jordan Carlin 2024-12-11 23:20:10 -08:00
parent 356c6fae80
commit bdfc9dac71
No known key found for this signature in database
3 changed files with 39 additions and 40 deletions

View File

@ -53,8 +53,8 @@ class CacheLine:
self.dirty = False self.dirty = False
def __str__(self): def __str__(self):
string = "(V: " + str(self.valid) + ", D: " + str(self.dirty) string = f"(V: {self.valid}, D: {self.dirty}"
string += ", Tag: " + str(hex(self.tag)) + ")" string += f", Tag: {hex(self.tag)})"
return string return string
def __repr__(self): def __repr__(self):
@ -193,9 +193,9 @@ class Cache:
def __str__(self): def __str__(self):
string = "" string = ""
for i in range(self.numways): for i in range(self.numways):
string += "Way " + str(i) + ": " string += f"Way {i}: "
for line in self.ways[i]: for line in self.ways[i]:
string += str(line) + ", " string += f"{line}, "
string += "\n\n" string += "\n\n"
return string return string
@ -285,13 +285,13 @@ def main(args):
atoms += 1 atoms += 1
if not result == lninfo[2]: if not result == lninfo[2]:
print("Result mismatch at address", lninfo[0]+ ". Wally:", lninfo[2]+", Sim:", result) print(f"Result mismatch at address {lninfo[0]}. Wally: {lninfo[2]}, Sim: {result}")
mismatches += 1 mismatches += 1
if args.dist: if args.dist:
percent_loads = str(round(100*loads/totalops)) percent_loads = str(round(100*loads/totalops))
percent_stores = str(round(100*stores/totalops)) percent_stores = str(round(100*stores/totalops))
percent_atoms = str(round(100*atoms/totalops)) percent_atoms = str(round(100*atoms/totalops))
print("This log had", percent_loads+"% loads,", percent_stores+"% stores, and", percent_atoms+"% atomic operations.") print(f"This log had {percent_loads}% loads, {percent_stores}% stores, and {percent_atoms}% atomic operations.")
if args.perf: if args.perf:
ratio = round(hits/misses,3) ratio = round(hits/misses,3)

View File

@ -30,7 +30,6 @@ def search_log_for_mismatches(logfile):
greperr = "grep -H Error: " + logfile greperr = "grep -H Error: " + logfile
os.system(greperr) os.system(greperr)
grepcmd = f"grep -a -e 'Mismatches : 0' '{logfile}' > /dev/null" grepcmd = f"grep -a -e 'Mismatches : 0' '{logfile}' > /dev/null"
# print(" search_log_for_text invoking %s" % grepcmd)
return os.system(grepcmd) == 0 return os.system(grepcmd) == 0
def run_test_case(elf): def run_test_case(elf):
@ -47,14 +46,14 @@ def run_test_case(elf):
# print("cmd = " + cmd) # print("cmd = " + cmd)
os.system(cmd) os.system(cmd)
if search_log_for_mismatches(logfile): if search_log_for_mismatches(logfile):
print(f"{bcolors.OKGREEN}%s: Success{bcolors.ENDC}" % (cmd)) print(f"{bcolors.OKGREEN}{cmd}: Success{bcolors.ENDC}")
return 0 return 0
elif "WALLY-cbom-01" in elf: elif "WALLY-cbom-01" in elf:
# Remove this when CBO instructions are modeled in ImperasDV # Remove this when CBO instructions are modeled in ImperasDV
print(f"{bcolors.OKCYAN}%s: Expected mismatch because ImperasDV does not yet model cache for CBO instructions {bcolors.ENDC}" % (cmd)) print(f"{bcolors.OKCYAN}{cmd}: Expected mismatch because ImperasDV does not yet model cache for CBO instructions {bcolors.ENDC}")
return 0 return 0
else: else:
print(f"{bcolors.FAIL}%s: Failures detected in output{bcolors.ENDC}" % (cmd)) print(f"{bcolors.FAIL}{cmd}: Failures detected in output{bcolors.ENDC}")
print(f" Check {logfile}") print(f" Check {logfile}")
return 1 return 1
@ -99,9 +98,9 @@ with Pool(processes=min(len(ElfList),multiprocessing.cpu_count(), ImperasDVLicen
num_fail+=result.get(timeout=TIMEOUT_DUR) num_fail+=result.get(timeout=TIMEOUT_DUR)
except MPTimeoutError: except MPTimeoutError:
num_fail+=1 num_fail+=1
print(f"{bcolors.FAIL}%s: Timeout - runtime exceeded %d seconds{bcolors.ENDC}" % (elf, TIMEOUT_DUR)) print(f"{bcolors.FAIL}{elf}: Timeout - runtime exceeded {TIMEOUT_DUR} seconds{bcolors.ENDC}")
if num_fail == 0: if num_fail == 0:
print(f"{bcolors.OKGREEN}SUCCESS! All tests ran without failures{bcolors.ENDC}") print(f"{bcolors.OKGREEN}SUCCESS! All tests ran without failures{bcolors.ENDC}")
else: else:
print(f"{bcolors.FAIL}Completed %d tests with %d failures{bcolors.ENDC}" % (len(ElfList), num_fail)) print(f"{bcolors.FAIL}Completed {len(ElfList)} tests with {num_fail} failures{bcolors.ENDC}")

View File

@ -264,21 +264,21 @@ class bcolors:
UNDERLINE = '\033[4m' UNDERLINE = '\033[4m'
def addTests(tests, sim): def addTests(tests, sim):
sim_logdir = WALLY+ "/sim/" + sim + "/logs/" sim_logdir = f"{WALLY}/sim/{sim}/logs/"
for test in tests: for test in tests:
config = test[0] config = test[0]
suites = test[1] suites = test[1]
if len(test) >= 3: if len(test) >= 3:
args = " --args " + " ".join(test[2]) args = f" --args {test[2]}"
else: else:
args = "" args = ""
if len(test) >= 4: if len(test) >= 4:
gs = test[3] gs = test[3]
else: else:
gs = "All tests ran without failures" gs = "All tests ran without failures"
cmdPrefix="wsim --sim " + sim + " " + coverStr + " " + config cmdPrefix=f"wsim --sim {sim} {coverStr} {config}"
for t in suites: for t in suites:
sim_log = sim_logdir + config + "_" + t + ".log" sim_log = f"{sim_logdir}{config}_{t}.log"
if len(test) >= 5: if len(test) >= 5:
grepfile = sim_logdir + test[4] grepfile = sim_logdir + test[4]
else: else:
@ -286,7 +286,7 @@ def addTests(tests, sim):
tc = TestCase( tc = TestCase(
name=t, name=t,
variant=config, variant=config,
cmd=cmdPrefix + " " + t + args + " > " + sim_log, cmd=f"{cmdPrefix} {t} {args} > {sim_log}",
grepstr=gs, grepstr=gs,
grepfile = grepfile) grepfile = grepfile)
configs.append(tc) configs.append(tc)
@ -294,27 +294,27 @@ def addTests(tests, sim):
def addTestsByDir(testDir, config, sim, lockstepMode=0): def addTestsByDir(testDir, config, sim, lockstepMode=0):
if os.path.isdir(testDir): if os.path.isdir(testDir):
sim_logdir = WALLY+ "/sim/" + sim + "/logs/" sim_logdir = f"{WALLY}/sim/{sim}/logs/"
if coverStr == "--fcov": # use --fcov in place of --lockstep if coverStr == "--fcov": # use --fcov in place of --lockstep
cmdPrefix="wsim --sim " + sim + " " + coverStr + " " + config cmdPrefix=f"wsim --sim {sim} {coverStr} {config}"
gs="Mismatches : 0" gs="Mismatches : 0"
if ("cvw-arch-verif/tests" in testDir and not "priv" in testDir): if ("cvw-arch-verif/tests" in testDir and not "priv" in testDir):
fileEnd = "ALL.elf" fileEnd = "ALL.elf"
else: else:
fileEnd = ".elf" fileEnd = ".elf"
elif coverStr == "--ccov": elif coverStr == "--ccov":
cmdPrefix="wsim --sim " + sim + " " + coverStr + " " + config cmdPrefix=f"wsim --sim {sim} {coverStr} {config}"
gs="Single Elf file tests are not signatured verified." gs="Single Elf file tests are not signatured verified."
if ("cvw-arch-verif/tests" in testDir and not "priv" in testDir): if ("cvw-arch-verif/tests" in testDir and not "priv" in testDir):
fileEnd = "ALL.elf" fileEnd = "ALL.elf"
else: else:
fileEnd = ".elf" fileEnd = ".elf"
elif lockstepMode: elif lockstepMode:
cmdPrefix="wsim --lockstep --sim " + sim + " " + config cmdPrefix=f"wsim --lockstep --sim {sim} {config}"
gs="Mismatches : 0" gs="Mismatches : 0"
fileEnd = ".elf" fileEnd = ".elf"
else: else:
cmdPrefix="wsim --sim " + sim + " " + config cmdPrefix=f"wsim --sim {sim} {config}"
gs="Single Elf file tests are not signatured verified." gs="Single Elf file tests are not signatured verified."
fileEnd = ".elf" fileEnd = ".elf"
for dirpath, _, filenames in os.walk(os.path.abspath(testDir)): for dirpath, _, filenames in os.walk(os.path.abspath(testDir)):
@ -324,29 +324,29 @@ def addTestsByDir(testDir, config, sim, lockstepMode=0):
fullfile = os.path.join(dirpath, file) fullfile = os.path.join(dirpath, file)
fields = fullfile.rsplit('/', 3) fields = fullfile.rsplit('/', 3)
if fields[2] == "ref": if fields[2] == "ref":
shortelf = fields[1] + "_" + fields[3] shortelf = f"{fields[1]}_{fields[3]}"
else: else:
shortelf = fields[2] + "_" + fields[3] shortelf = f"{fields[2]}_{fields[3]}"
if shortelf in lockstepwaivers: # skip tests that itch bugs in ImperasDV if shortelf in lockstepwaivers: # skip tests that itch bugs in ImperasDV
print(f"{bcolors.WARNING}Skipping waived test {shortelf}{bcolors.ENDC}") print(f"{bcolors.WARNING}Skipping waived test {shortelf}{bcolors.ENDC}")
continue continue
sim_log = sim_logdir + config + "_" + shortelf + ".log" sim_log = f"{sim_logdir}{config}_{shortelf}.log"
tc = TestCase( tc = TestCase(
name=file, name=file,
variant=config, variant=config,
cmd=cmdPrefix + " " + fullfile + " > " + sim_log, cmd=f"{cmdPrefix} {fullfile} > {sim_log}",
grepstr=gs, grepstr=gs,
grepfile = sim_log) grepfile = sim_log)
configs.append(tc) configs.append(tc)
else: else:
print("Error: Directory not found: " + testDir) print(f"Error: Directory not found: {testDir}")
sys.exit(1) sys.exit(1)
def search_log_for_text(text, grepfile): def search_log_for_text(text, grepfile):
"""Search through the given log file for text, returning True if it is found or False if it is not""" """Search through the given log file for text, returning True if it is found or False if it is not"""
grepwarn = "grep -i -H Warning: " + grepfile grepwarn = f"grep -i -H Warning: {grepfile}"
os.system(grepwarn) os.system(grepwarn)
greperr = "grep -i -H Error: " + grepfile greperr = f"grep -i -H Error: {grepfile}"
os.system(greperr) os.system(greperr)
grepcmd = f"grep -a -e '{text}' '{grepfile}' > /dev/null" grepcmd = f"grep -a -e '{text}' '{grepfile}' > /dev/null"
return os.system(grepcmd) == 0 return os.system(grepcmd) == 0
@ -367,10 +367,10 @@ def run_test_case(config, dryrun: bool = False):
os.system(cmd) os.system(cmd)
if search_log_for_text(config.grepstr, grepfile): if search_log_for_text(config.grepstr, grepfile):
# Flush is needed to flush output to stdout when running in multiprocessing Pool # Flush is needed to flush output to stdout when running in multiprocessing Pool
print(f"{bcolors.OKGREEN}%s: Success{bcolors.ENDC}" % (config.cmd), flush=True) print(f"{bcolors.OKGREEN}{config.cmd}: Success{bcolors.ENDC}", flush=True)
return 0 return 0
else: else:
print(f"{bcolors.FAIL}%s: Failures detected in output{bcolors.ENDC}" % (config.cmd), flush=True) print(f"{bcolors.FAIL}{config.cmd}: Failures detected in output{bcolors.ENDC}", flush=True)
print(f" Check {grepfile}", flush=True) print(f" Check {grepfile}", flush=True)
return 1 return 1
@ -418,9 +418,9 @@ configs = [
TestCase( TestCase(
name="lints", name="lints",
variant="all", variant="all",
cmd="lint-wally " + nightMode + " | tee " + WALLY + "/sim/verilator/logs/all_lints.log", cmd=f"lint-wally {nightMode} | tee {WALLY}/sim/verilator/logs/all_lints.log",
grepstr="lints run with no errors or warnings", grepstr="lints run with no errors or warnings",
grepfile = WALLY + "/sim/verilator/logs/all_lints.log") grepfile = f"{WALLY}/sim/verilator/logs/all_lints.log")
] ]
@ -467,11 +467,11 @@ if (args.testfloat or args.nightly): # for nightly, run testfloat along with oth
if "f_" in config: if "f_" in config:
tests.remove("cvtfp") tests.remove("cvtfp")
for test in tests: for test in tests:
sim_log = WALLY + "/sim/" + testfloatsim + "/logs/"+config+"_"+test+".log" sim_log = f"{WALLY}/sim/{testfloatsim}/logs/{config}_{test}.log"
tc = TestCase( tc = TestCase(
name=test, name=test,
variant=config, variant=config,
cmd="wsim --tb testbench_fp --sim " + testfloatsim + " " + config + " " + test + " > " + sim_log, cmd=f"wsim --tb testbench_fp --sim {testfloatsim} {config} {test} > {sim_log}",
grepstr="All Tests completed with 0 errors", grepstr="All Tests completed with 0 errors",
grepfile = sim_log) grepfile = sim_log)
configs.append(tc) configs.append(tc)
@ -509,13 +509,13 @@ if (args.testfloat or args.nightly): # for nightly, run testfloat along with oth
if "f_" in config: if "f_" in config:
tests.remove("cvtfp") tests.remove("cvtfp")
for test in tests: for test in tests:
sim_log = WALLY + "/sim/questa/logs/"+config+"_"+test+".log" sim_log = f"{WALLY}/sim/{testfloatsim}/logs/{config}_{test}.log"
tc = TestCase( tc = TestCase(
name=test, name=test,
variant=config, variant=config,
cmd="wsim --tb testbench_fp " + config + " " + test + " > " + sim_log, cmd=f"wsim --tb testbench_fp --sim {testfloatsim} {config} {test} > {sim_log}",
grepstr="All Tests completed with 0 errors", grepstr="All Tests completed with 0 errors",
grepfile = WALLY + "/sim/questa/logs/"+config+"_"+test+".log") grepfile = f"{WALLY}/sim/{testfloatsim}/logs/{config}_{test}.log")
configs.append(tc) configs.append(tc)
@ -560,7 +560,7 @@ def main():
except MPTimeoutError: except MPTimeoutError:
pool.terminate() pool.terminate()
num_fail+=1 num_fail+=1
print(f"{bcolors.FAIL}%s: Timeout - runtime exceeded %d seconds{bcolors.ENDC}" % (config.cmd, TIMEOUT_DUR)) print(f"{bcolors.FAIL}{config.cmd}: Timeout - runtime exceeded {TIMEOUT_DUR} seconds{bcolors.ENDC}")
# Coverage report # Coverage report
if args.ccov: if args.ccov:
@ -569,7 +569,7 @@ def main():
os.system('make -C '+WALLY+'/addins/cvw-arch-verif merge') os.system('make -C '+WALLY+'/addins/cvw-arch-verif merge')
# Count the number of failures # Count the number of failures
if num_fail: if num_fail:
print(f"{bcolors.FAIL}Regression failed with %s failed configurations{bcolors.ENDC}" % num_fail) print(f"{bcolors.FAIL}Regression failed with {num_fail} failed configurations{bcolors.ENDC}")
else: else:
print(f"{bcolors.OKGREEN}SUCCESS! All tests ran without failures{bcolors.ENDC}") print(f"{bcolors.OKGREEN}SUCCESS! All tests ran without failures{bcolors.ENDC}")
return num_fail return num_fail