Tests: Make xrun fail on stop (#7547)

This commit is contained in:
Todd Strader 2026-05-08 07:39:38 -04:00 committed by GitHub
parent 7c5069c7df
commit aa68ae953e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 4 deletions

View File

@ -1606,13 +1606,20 @@ class VlTest:
pli_opt = ""
if param['use_libvpi']:
pli_opt = "-loadvpi " + self.obj_dir + "/libvpi.so:vpi_compat_bootstrap"
done = "XRUN_DONE"
cmd = [
"echo q | " + run_env + VtOs.getenv_def('VERILATOR_XRUN', "xrun"),
run_env + VtOs.getenv_def('VERILATOR_XRUN', "xrun"),
' '.join(param['xrun_run_flags']),
' '.join(param['xrun_flags2']),
' '.join(param['v_flags']),
' '.join(param['all_run_flags']),
pli_opt,
'-input',
'@run',
'-input',
f'"@puts {done}"',
'-input',
'@exit',
param['top_filename'],
]
self.run(cmd=cmd,
@ -1621,6 +1628,8 @@ class VlTest:
expect_filename=param.get('xrun_run_expect_filename', None),
fails=param['fails'],
logfile=param.get('logfile', self.obj_dir + "/xrun_sim.log"),
stop_re=r'Simulation stopped via',
done_re=done,
tee=param['tee'])
elif param['xsim']:
cmd = [
@ -1832,6 +1841,8 @@ class VlTest:
expect_filename=None, # Filename that should match logfile
fails=False, # True: normal 1 exit code, 'any': any exit code
logfile=None, # Filename to write putput to
stop_re=None, # Regex for $stop
done_re=None, # Regex for sim completion
tee=True,
verilator_run=False) -> bool: # Move gcov data to parallel area
@ -1950,14 +1961,17 @@ class VlTest:
return False
# Read the log file a couple of times to allow for NFS delays
if check_finished:
if stop_re and not done_re:
self.error("Must provide done_re when using stop_re")
if check_finished or stop_re or done_re:
delay = 0.25
for tryn in range(Args.log_retries - 1, -1, -1):
if tryn != Args.log_retries - 1:
time.sleep(delay)
delay = min(1, delay * 2)
moretry = tryn != 0
if not self._run_log_try(logfile, check_finished, moretry):
if not self._run_log_try(logfile, check_finished, moretry, stop_re, done_re):
break
if expect_filename:
self.files_identical(logfile, expect_filename, is_logfile=True)
@ -1976,7 +1990,8 @@ class VlTest:
if logfh:
logfh.write(data)
def _run_log_try(self, logfile: str, check_finished: bool, moretry: bool) -> bool:
def _run_log_try(self, logfile: str, check_finished: bool, moretry: bool,
stop_re: Optional[str], done_re: Optional[str]) -> bool:
# If moretry, then return true to try again
with open(logfile, 'r', encoding='latin-1', newline='\n') as fh:
if not fh and moretry:
@ -1989,6 +2004,14 @@ class VlTest:
return True
self.error("Missing '*-* All Finished *-*'")
if done_re and not re.search(done_re, wholefile):
if moretry:
return True
self.error(f"Missing '{done_re}'")
if stop_re and re.search(stop_re, wholefile):
self.error("Found $stop")
return False
#######################################################################