1 #![allow(unused_must_use)]
2 #![allow(stable_features)]
4 #![allow(unused_imports)]
5 // compile-flags:--test
6 // ignore-cloudabi no processes
7 // ignore-emscripten no processes
8 // ignore-sgx no processes
10 // N.B., these tests kill child processes. Valgrind sees these children as leaking
11 // memory, which makes for some *confusing* logs. That's why these are here
14 #![feature(rustc_private, duration)]
18 use std::process::{self, Command, Child, Output, Stdio};
20 use std::sync::mpsc::channel;
22 use std::time::Duration;
25 ($e:expr) => (match $e { Ok(e) => e, Err(e) => panic!("error: {}", e) })
29 fn test_destroy_once() {
30 let mut p = sleeper();
35 pub fn sleeper() -> Child {
36 t!(Command::new("sleep").arg("1000").spawn())
39 pub fn sleeper() -> Child {
40 // There's a `timeout` command on windows, but it doesn't like having
41 // its output piped, so instead just ping ourselves a few times with
42 // gaps in between so we're sure this process is alive for awhile
43 t!(Command::new("ping").arg("127.0.0.1").arg("-n").arg("1000").spawn())
47 fn test_destroy_twice() {
48 let mut p = sleeper();
49 t!(p.kill()); // this shouldn't crash...
50 let _ = p.kill(); // ...and nor should this (and nor should the destructor)
54 fn test_destroy_actually_kills() {
55 let cmd = if cfg!(windows) {
57 } else if cfg!(target_os = "android") {
63 // this process will stay alive indefinitely trying to read from stdin
64 let mut p = t!(Command::new(cmd)
65 .stdin(Stdio::piped())
70 // Don't let this test time out, this should be quick
71 let (tx, rx) = channel();
72 thread::spawn(move|| {
73 thread::sleep_ms(1000);
74 if rx.try_recv().is_err() {
78 let code = t!(p.wait()).code();
80 assert!(code.is_some());
82 assert!(code.is_none());