Repository navigation
ci: let a cancelled job's test harness stop its VMs and remove its scratch #975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Pedro Henrique Penna (ppenna)
merged 6 commits into
dev
from
agents/issue-946-harness-cancellation
Oct 29, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e7342b
scripts: let SIGTERM interrupt nvx.py as SIGINT does
ppenna cf6b76a
sandbox: stop an interrupted acceptance's sandboxes
ppenna ac35cf4
microvm: build the time ABI monitor before OpenVMM starts
ppenna 04d78a3
scripts: end OpenVMM with the harness that started it on Linux
ppenna 94d17c5
ci: let a cancellation reach the test harness
ppenna 8b3dbca
ci: remove the scratch directories that earlier jobs left
ppenna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # shellcheck shell=bash | ||
| # Sourced by the Linux steps of run-benchmark, which run the test harness | ||
| # among other commands (see doc/ci.md#cancellation). | ||
| # | ||
| # When a job is cancelled, the runner sends SIGINT, and then SIGTERM, to the | ||
| # step's shell alone, and Bash runs a trap only once its foreground command | ||
| # ends. So sourcing this file traps both signals: one that arrives while | ||
| # run_harness runs a command reaches that command as SIGTERM, which nvx.py | ||
| # handles as SIGINT, so that it stops its OpenVMM processes and removes its | ||
| # scratch directories, and ends the step once the command exits; one that | ||
| # arrives at any other time ends the step at once. | ||
|
|
||
| harness_pid= | ||
| starting= | ||
| deferred= | ||
| cancelled= | ||
|
|
||
| on_cancellation() { | ||
| cancelled=$1 | ||
| if [[ -n "${starting}" ]]; then | ||
| # The command may have started, but run_harness doesn't know its PID | ||
| # yet, so it passes the signal on once it does. | ||
| deferred=1 | ||
| elif [[ -n "${harness_pid}" ]]; then | ||
| # The command may have exited already, so that the signal reaches nothing. | ||
| kill -TERM "${harness_pid}" 2>/dev/null || true | ||
| else | ||
| exit "$1" | ||
| fi | ||
| } | ||
|
|
||
| trap 'on_cancellation 130' INT | ||
| trap 'on_cancellation 143' TERM | ||
|
|
||
| # Runs a command in the background, where Bash would ignore SIGINT unless the | ||
| # command restored it, and returns its exit status once it exits. A | ||
| # cancellation reaches the command as SIGTERM, which it never ignores, not | ||
| # even before it has restored SIGINT, as it has not when a cancellation that | ||
| # arrived as it started reaches it. | ||
| run_harness() { | ||
| starting=1 | ||
| ( | ||
| trap - INT | ||
| exec "$@" | ||
| ) & | ||
| harness_pid=$! | ||
| starting= | ||
| if [[ -n "${deferred}" ]]; then | ||
| deferred= | ||
| kill -TERM "${harness_pid}" 2>/dev/null || true | ||
| fi | ||
| local status=0 | ||
| wait "${harness_pid}" || status=$? | ||
| # A trapped signal ends the wait before the command exits. | ||
| while kill -0 "${harness_pid}" 2>/dev/null; do | ||
| status=0 | ||
| wait "${harness_pid}" || status=$? | ||
| done | ||
| harness_pid= | ||
| if [[ -n "${cancelled}" ]]; then | ||
| exit "${cancelled}" | ||
| fi | ||
| return "${status}" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.