Skip to content

Commit

Permalink
Rollup merge of #127594 - c6c7:fuchsia-status-code-match-arm, r=tmandry
Browse files Browse the repository at this point in the history
Fuchsia status code match arm

Adds a match arm for the Fuchsia status code upon a process abort. An additional change moves the Windows status code down into the match arm itself instead of being defined as a constant elsewhere.

r​? tmandry
  • Loading branch information
matthiaskrgr committed Jul 18, 2024
2 parents 7c1bf86 + deb8ebb commit c1bbe34
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
15 changes: 13 additions & 2 deletions library/test/src/test_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ pub const TR_OK: i32 = 50;
// On Windows we use __fastfail to abort, which is documented to use this
// exception code.
#[cfg(windows)]
const STATUS_ABORTED: i32 = 0xC0000409u32 as i32;
const STATUS_FAIL_FAST_EXCEPTION: i32 = 0xC0000409u32 as i32;

// On Zircon (the Fuchsia kernel), an abort from userspace calls the
// LLVM implementation of __builtin_trap(), e.g., ud2 on x86, which
// raises a kernel exception. If a userspace process does not
// otherwise arrange exception handling, the kernel kills the process
// with this return code.
#[cfg(target_os = "fuchsia")]
const ZX_TASK_RETCODE_EXCEPTION_KILL: i32 = -1028;

#[derive(Debug, Clone, PartialEq)]
pub enum TestResult {
Expand Down Expand Up @@ -96,7 +104,7 @@ pub fn get_result_from_exit_code(
let result = match status.code() {
Some(TR_OK) => TestResult::TrOk,
#[cfg(windows)]
Some(STATUS_ABORTED) => TestResult::TrFailed,
Some(STATUS_FAIL_FAST_EXCEPTION) => TestResult::TrFailed,
#[cfg(unix)]
None => match status.signal() {
Some(libc::SIGABRT) => TestResult::TrFailed,
Expand All @@ -105,6 +113,9 @@ pub fn get_result_from_exit_code(
}
None => unreachable!("status.code() returned None but status.signal() was None"),
},
// Upon an abort, Fuchsia returns the status code ZX_TASK_RETCODE_EXCEPTION_KILL.
#[cfg(target_os = "fuchsia")]
Some(ZX_TASK_RETCODE_EXCEPTION_KILL) => TestResult::TrFailed,
#[cfg(not(unix))]
None => TestResult::TrFailedMsg(format!("unknown return code")),
#[cfg(any(windows, unix))]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/test-attrs/test-panic-abort-nocapture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//@ ignore-wasm no panic or subprocess support
//@ ignore-emscripten no panic or subprocess support
//@ ignore-sgx no subprocess support
//@ ignore-fuchsia code returned as ZX_TASK_RETCODE_EXCEPTION_KILL, FIXME (#127539)

#![cfg(test)]

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/test-attrs/test-panic-abort-nocapture.run.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
thread 'main' panicked at $DIR/test-panic-abort-nocapture.rs:35:5:
thread 'main' panicked at $DIR/test-panic-abort-nocapture.rs:34:5:
assertion `left == right` failed
left: 2
right: 4
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at $DIR/test-panic-abort-nocapture.rs:29:5:
thread 'main' panicked at $DIR/test-panic-abort-nocapture.rs:28:5:
assertion `left == right` failed
left: 2
right: 4
Expand Down
1 change: 0 additions & 1 deletion tests/ui/test-attrs/test-panic-abort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//@ ignore-wasm no panic or subprocess support
//@ ignore-emscripten no panic or subprocess support
//@ ignore-sgx no subprocess support
//@ ignore-fuchsia code returned as ZX_TASK_RETCODE_EXCEPTION_KILL, FIXME (#127539)

#![cfg(test)]
#![feature(test)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test-attrs/test-panic-abort.run.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ hello, world
testing123
---- it_fails stderr ----
testing321
thread 'main' panicked at $DIR/test-panic-abort.rs:40:5:
thread 'main' panicked at $DIR/test-panic-abort.rs:39:5:
assertion `left == right` failed
left: 2
right: 5
Expand Down

0 comments on commit c1bbe34

Please sign in to comment.