1 use crate::os::unix::process::{CommandExt, ExitStatusExt};
2 use crate::panic::catch_unwind;
3 use crate::process::Command;
5 // Many of the other aspects of this situation, including heap alloc concurrency
6 // safety etc., are tested in tests/ui/process/process-panic-after-fork.rs
9 fn exitstatus_display_tests() {
10 // In practice this is the same on every Unix.
11 // If some weird platform turns out to be different, and this test fails, use #[cfg].
12 use crate::os::unix::process::ExitStatusExt;
13 use crate::process::ExitStatus;
15 let t = |v, s| assert_eq!(s, format!("{}", <ExitStatus as ExitStatusExt>::from_raw(v)));
17 t(0x0000f, "signal: 15 (SIGTERM)");
18 t(0x0008b, "signal: 11 (SIGSEGV) (core dumped)");
19 t(0x00000, "exit status: 0");
20 t(0x0ff00, "exit status: 255");
22 // On MacOS, 0x0137f is WIFCONTINUED, not WIFSTOPPED. Probably *BSD is similar.
23 // https://github.com/rust-lang/rust/pull/82749#issuecomment-790525956
24 // The purpose of this test is to test our string formatting, not our understanding of the wait
25 // status magic numbers. So restrict these to Linux.
26 if cfg!(target_os = "linux") {
27 t(0x0137f, "stopped (not terminated) by signal: 19 (SIGSTOP)");
28 t(0x0ffff, "continued (WIFCONTINUED)");
31 // Testing "unrecognised wait status" is hard because the wait.h macros typically
32 // assume that the value came from wait and isn't mad. With the glibc I have here
34 if cfg!(all(target_os = "linux", target_env = "gnu")) {
35 t(0x000ff, "unrecognised wait status: 255 0xff");
40 #[cfg_attr(target_os = "emscripten", ignore)]
41 fn test_command_fork_no_unwind() {
42 let got = catch_unwind(|| {
43 let mut c = Command::new("echo");
46 c.pre_exec(|| panic!("{}", "crash now!"));
48 let st = c.status().expect("failed to get command status");
53 let status = got.expect("panic unexpectedly propagated");
55 let signal = status.signal().expect("expected child process to die of signal");
57 signal == libc::SIGABRT
58 || signal == libc::SIGILL
59 || signal == libc::SIGTRAP
60 || signal == libc::SIGSEGV