Skip to content

Commit ec8190e

Browse files
ijacksonm-ou-se
andcommitted
panic tests: Command: Test that we do not unwind past fork
This is safe (does not involve heap allocation) but we don't yet have a test to ensure that stays true. That will come in a moment. Signed-off-by: Ian Jackson <[email protected]> Co-authored-by: Mara Bos <[email protected]>
1 parent 91e47be commit ec8190e

File tree

1 file changed

+23
-0
lines changed
  • std/src/sys/unix/process/process_unix

1 file changed

+23
-0
lines changed

std/src/sys/unix/process/process_unix/tests.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use crate::os::unix::process::{CommandExt, ExitStatusExt};
2+
use crate::panic::catch_unwind;
3+
use crate::process::Command;
4+
15
#[test]
26
fn exitstatus_display_tests() {
37
// In practice this is the same on every Unix.
@@ -28,3 +32,22 @@ fn exitstatus_display_tests() {
2832
t(0x000ff, "unrecognised wait status: 255 0xff");
2933
}
3034
}
35+
36+
#[test]
37+
fn test_command_fork_no_unwind() {
38+
let got = catch_unwind(|| {
39+
let mut c = Command::new("echo");
40+
c.arg("hi");
41+
unsafe {
42+
c.pre_exec(|| panic!("{}", "crash now!"));
43+
}
44+
let st = c.status().expect("failed to get command status");
45+
dbg!(st);
46+
st
47+
});
48+
dbg!(&got);
49+
let status = got.expect("panic unexpectedly propagated");
50+
dbg!(status);
51+
let signal = status.signal().expect("expected child process to die of signal");
52+
assert!(signal == libc::SIGABRT || signal == libc::SIGILL);
53+
}

0 commit comments

Comments
 (0)