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