Skip to content

Commit c04b2d5

Browse files
committed
exit code handling
1 parent d9911dd commit c04b2d5

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

scripts/ci/run_pvs2c_tests.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ def tail(text: str, lines: int = 60) -> str:
122122
return "\n".join(split[-lines:])
123123

124124

125-
def run_logged(command: list[str], cwd: Path, log_path: Path, env: dict[str, str]) -> str:
125+
def run_logged(
126+
command: list[str],
127+
cwd: Path,
128+
log_path: Path,
129+
env: dict[str, str],
130+
check: bool = True,
131+
) -> tuple[int, str]:
126132
log_path.parent.mkdir(parents=True, exist_ok=True)
127133
print(f"+ ({cwd}) {command_text(command)}")
128134
output_parts: list[str] = []
@@ -144,13 +150,13 @@ def run_logged(command: list[str], cwd: Path, log_path: Path, env: dict[str, str
144150
sys.stdout.write(line)
145151
return_code = process.wait()
146152
output = "".join(output_parts)
147-
if return_code != 0:
153+
if check and return_code != 0:
148154
raise StepError(
149155
f"Command failed with exit {return_code}: {command_text(command)}\n"
150156
f"Log: {log_path}\n"
151157
f"{tail(output)}"
152158
)
153-
return output
159+
return return_code, output
154160

155161

156162
def pvs_expr_for_typecheck(theory: str) -> str:
@@ -236,7 +242,7 @@ def run_theory(
236242
print(f"\n==> {rel_dir}/{theory.file.name}:{theory.theory} ({len(theory.tests)} tests)")
237243

238244
typecheck_log = log_prefix.with_name(log_prefix.name + "-typecheck.log")
239-
typecheck_output = run_logged(
245+
_, typecheck_output = run_logged(
240246
[str(pvs), "-raw", "-E", pvs_expr_for_typecheck(theory.theory)],
241247
theory.directory,
242248
typecheck_log,
@@ -245,18 +251,24 @@ def run_theory(
245251
assert_pvs_log_ok(theory, "typecheck", typecheck_output, typecheck_log)
246252

247253
pvs2c_log = log_prefix.with_name(log_prefix.name + "-pvs2c.log")
248-
pvs2c_output = run_logged(
254+
pvs2c_status, pvs2c_output = run_logged(
249255
[str(pvs), "-raw", "-E", pvs_expr_for_pvs2c(theory.theory)],
250256
theory.directory,
251257
pvs2c_log,
252258
env,
259+
check=False,
253260
)
254261
assert_pvs_log_ok(theory, "pvs2c-theory", pvs2c_output, pvs2c_log)
255262

256263
generated_mk = theory.directory / "pvs2c" / "include" / f"{theory.theory}.mk"
257264
generated_bin = theory.directory / "pvs2c" / "bin" / theory.theory
258265
if not generated_mk.exists():
259-
raise StepError(f"pvs2c-theory did not generate {generated_mk}")
266+
raise StepError(
267+
f"pvs2c-theory exited {pvs2c_status} and did not generate {generated_mk}; see {pvs2c_log}\n"
268+
f"{tail(pvs2c_output)}"
269+
)
270+
if pvs2c_status != 0:
271+
print(f"WARNING: pvs2c-theory for {theory.theory} exited {pvs2c_status}, but generated files are present; continuing to compile and run them.")
260272

261273
make_env = env.copy()
262274
make_env["PVS2C_DEMOS_ROOT"] = str(demo_root)
@@ -271,7 +283,7 @@ def run_theory(
271283
raise StepError(f"make did not produce {generated_bin}")
272284

273285
run_log = log_prefix.with_name(log_prefix.name + "-run.log")
274-
run_output = run_logged([str(generated_bin)], theory.directory, run_log, env)
286+
_, run_output = run_logged([str(generated_bin)], theory.directory, run_log, env)
275287
assert_run_output(theory, run_output, run_log)
276288
return len(theory.tests)
277289

0 commit comments

Comments
 (0)