]> git.lizzy.rs Git - rust.git/commitdiff
panic tests: Command: Test that we do not unwind past fork
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 7 Feb 2021 11:42:44 +0000 (11:42 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 7 May 2021 10:17:44 +0000 (11:17 +0100)
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 <ijackson@chiark.greenend.org.uk>
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
library/std/src/sys/unix/process/process_unix/tests.rs

index 02c469fbcdfd80c5e2298b798a84b4cf5ff6e96c..61b2e4a145f80b669b5c85daccd26fb013185809 100644 (file)
@@ -1,3 +1,7 @@
+use crate::os::unix::process::{CommandExt, ExitStatusExt};
+use crate::panic::catch_unwind;
+use crate::process::Command;
+
 #[test]
 fn exitstatus_display_tests() {
     // In practice this is the same on every Unix.
@@ -28,3 +32,22 @@ fn exitstatus_display_tests() {
         t(0x000ff, "unrecognised wait status: 255 0xff");
     }
 }
+
+#[test]
+fn test_command_fork_no_unwind() {
+    let got = catch_unwind(|| {
+        let mut c = Command::new("echo");
+        c.arg("hi");
+        unsafe {
+            c.pre_exec(|| panic!("{}", "crash now!"));
+        }
+        let st = c.status().expect("failed to get command status");
+        dbg!(st);
+        st
+    });
+    dbg!(&got);
+    let status = got.expect("panic unexpectedly propagated");
+    dbg!(status);
+    let signal = status.signal().expect("expected child process to die of signal");
+    assert!(signal == libc::SIGABRT || signal == libc::SIGILL);
+}