Skip to content

Fix subprocess exit code checking in Pyxsim to report errors properly#55

Open
xross wants to merge 3 commits into
xmos:developfrom
xross:fix/subprocess-error-reporting
Open

Fix subprocess exit code checking in Pyxsim to report errors properly#55
xross wants to merge 3 commits into
xmos:developfrom
xross:fix/subprocess-error-reporting

Conversation

@xross
Copy link
Copy Markdown
Contributor

@xross xross commented May 22, 2026

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.

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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, raising TestError on non-zero exit.
  • Make run_with_pyxsim() return a success boolean and have run_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.

Comment on lines +218 to +222
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}"
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems low risk.

Comment thread lib/python/Pyxsim/__init__.py
Comment thread lib/python/Pyxsim/xmostest_subprocess.py
Comment on lines +276 to +280
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}"
Copy link
Copy Markdown
Contributor Author

@xross xross May 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems low risk?

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@xross xross force-pushed the fix/subprocess-error-reporting branch from b935bb3 to 983acc5 Compare May 22, 2026 13:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment on lines 124 to 129
ev.wait()
except KeyboardInterrupt:
pstreekill(process)
finally:
process.join()

Comment on lines +220 to +224
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}"
)
Comment on lines +279 to +280
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)
Comment thread lib/python/Pyxsim/__init__.py
Copy link
Copy Markdown

@humphrey-xmos humphrey-xmos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe my lack of understanding, but what is the significance of process[3], rather than process.

Copy link
Copy Markdown
Contributor Author

@xross xross May 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process is the entire tuple returned by create_cmd_process
the process object is at index 3 :)

https://github.com/xross/test_support/blob/983acc53685e2fc37c1b9aed517eb03a2d32eccb/lib/python/Pyxsim/xmostest_subprocess.py#L160

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could have been cleaner with a class..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants