3 #![allow(unused_must_use)]
4 #![allow(stable_features)]
6 #![allow(unused_imports)]
7 // compile-flags:--test
8 // ignore-cloudabi no processes
9 // ignore-emscripten no processes
10 // ignore-sgx no processes
11 // ignore-vxworks no 'cat' and 'sleep'
13 // N.B., these tests kill child processes. Valgrind sees these children as leaking
14 // memory, which makes for some *confusing* logs. That's why these are here
17 #![feature(rustc_private, duration)]
21 use std::process::{self, Command, Child, Output, Stdio};
23 use std::sync::mpsc::channel;
25 use std::time::Duration;
28 ($e:expr) => (match $e { Ok(e) => e, Err(e) => panic!("error: {}", e) })
32 fn test_destroy_once() {
33 let mut p = sleeper();
38 pub fn sleeper() -> Child {
39 t!(Command::new("sleep").arg("1000").spawn())
42 pub fn sleeper() -> Child {
43 // There's a `timeout` command on windows, but it doesn't like having
44 // its output piped, so instead just ping ourselves a few times with
45 // gaps in between so we're sure this process is alive for awhile
46 t!(Command::new("ping").arg("127.0.0.1").arg("-n").arg("1000").spawn())
50 fn test_destroy_twice() {
51 let mut p = sleeper();
52 t!(p.kill()); // this shouldn't crash...
53 let _ = p.kill(); // ...and nor should this (and nor should the destructor)
57 fn test_destroy_actually_kills() {
58 let cmd = if cfg!(windows) {
60 } else if cfg!(target_os = "android") {
66 // this process will stay alive indefinitely trying to read from stdin
67 let mut p = t!(Command::new(cmd)
68 .stdin(Stdio::piped())
73 // Don't let this test time out, this should be quick
74 let (tx, rx) = channel();
75 thread::spawn(move|| {
76 thread::sleep_ms(1000);
77 if rx.try_recv().is_err() {
81 let code = t!(p.wait()).code();
83 assert!(code.is_some());
85 assert!(code.is_none());