Fix subprocess exit code checking in Pyxsim to report errors properly#55
Fix subprocess exit code checking in Pyxsim to report errors properly#55xross wants to merge 3 commits into
Conversation
Previously, subprocess failures in run_with_pyxsim() were silently ignored because the exit code wasn't checked. Now returns False on failure and propagates errors to run_on_simulator_() for proper test failure reporting.
There was a problem hiding this comment.
Pull request overview
This PR improves failure reporting in the Pyxsim test harness by ensuring subprocess/simulator failures are detected and surfaced, rather than being silently ignored.
Changes:
- Capture and propagate subprocess exit codes from the multiprocessing wrapper in
xmostest_subprocess.py, raisingTestErroron non-zero exit. - Make
run_with_pyxsim()return a success boolean and haverun_on_simulator_()fail fast when simulation fails or times out. - Document the behavior change in
CHANGELOG.rst.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/python/Pyxsim/xmostest_subprocess.py | Records subprocess exit codes and raises TestError when commands fail. |
| lib/python/Pyxsim/init.py | Propagates simulator failure/timeout via boolean return values. |
| CHANGELOG.rst | Notes the new exit-code checking behavior under UNRELEASED fixes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if retval != 0: | ||
| output = "".join(line.decode("utf-8") if isinstance(line, bytes) else line for line in stdout_lines) | ||
| raise TestError( | ||
| f"Command failed with exit code {retval}: {cmd_str}\nOutput:\n{output}" | ||
| ) |
| if retval != 0: | ||
| stdout_str = "".join(line.decode("utf-8") if isinstance(line, bytes) else line for line in stdout_lines) | ||
| stderr_str = "".join(line.decode("utf-8") if isinstance(line, bytes) else line for line in stderr_lines) | ||
| raise TestError( | ||
| f"Command failed with exit code {retval}: {cmd_str}\nStdout:\n{stdout_str}\nStderr:\n{stderr_str}" |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
b935bb3 to
983acc5
Compare
| ev.wait() | ||
| except KeyboardInterrupt: | ||
| pstreekill(process) | ||
| finally: | ||
| process.join() | ||
|
|
| if retval != 0: | ||
| output = "".join(line.decode("utf-8") if isinstance(line, bytes) else line for line in stdout_lines) | ||
| raise TestError( | ||
| f"Command failed with exit code {retval}: {cmd_str}\nOutput:\n{output}" | ||
| ) |
| stdout_str = "".join(line.decode("utf-8") if isinstance(line, bytes) else line for line in stdout_lines) | ||
| stderr_str = "".join(line.decode("utf-8") if isinstance(line, bytes) else line for line in stderr_lines) |
humphrey-xmos
left a comment
There was a problem hiding this comment.
A useful update. Only a minor comment
| while process[2].is_alive(): | ||
| sys.stdout.write("Waiting for PID %d to terminate\n" % process[2].pid) | ||
| process[2].join(timeout=1.0) | ||
| process[3].terminate() |
There was a problem hiding this comment.
Maybe my lack of understanding, but what is the significance of process[3], rather than process.
There was a problem hiding this comment.
process is the entire tuple returned by create_cmd_process
the process object is at index 3 :)
There was a problem hiding this comment.
could have been cleaner with a class..
Previously, subprocess failures in run_with_pyxsim() were silently ignored because the exit code wasn't checked. Now returns False on failure and propagates errors to run_on_simulator_() for proper test failure reporting.