Skip to content

Commit de80712

Browse files
committed
Move core::run tests of process killing into standalone run-pass tests
These cause valgrind errors in subprocesses. I don't *think* these errors lead to actual test failures but they are very confusing.
1 parent 4332f81 commit de80712

File tree

2 files changed

+89
-70
lines changed

2 files changed

+89
-70
lines changed

src/libcore/run.rs

-70
Original file line numberDiff line numberDiff line change
@@ -855,74 +855,4 @@ mod tests {
855855
fn waitpid_non_existant_pid() {
856856
run::waitpid(123456789); // assume that this pid doesn't exist
857857
}
858-
859-
#[test]
860-
fn test_destroy_once() {
861-
let mut p = run::start_program("echo", []);
862-
p.destroy(); // this shouldn't crash (and nor should the destructor)
863-
}
864-
865-
#[test]
866-
fn test_destroy_twice() {
867-
let mut p = run::start_program("echo", []);
868-
p.destroy(); // this shouldnt crash...
869-
p.destroy(); // ...and nor should this (and nor should the destructor)
870-
}
871-
872-
fn test_destroy_actually_kills(force: bool) {
873-
874-
#[cfg(unix)]
875-
static BLOCK_COMMAND: &'static str = "cat";
876-
877-
#[cfg(windows)]
878-
static BLOCK_COMMAND: &'static str = "cmd";
879-
880-
#[cfg(unix)]
881-
fn process_exists(pid: libc::pid_t) -> bool {
882-
run::program_output("ps", [~"-p", pid.to_str()]).out.contains(pid.to_str())
883-
}
884-
885-
#[cfg(windows)]
886-
fn process_exists(pid: libc::pid_t) -> bool {
887-
888-
use libc::types::os::arch::extra::DWORD;
889-
use libc::funcs::extra::kernel32::{CloseHandle, GetExitCodeProcess, OpenProcess};
890-
use libc::consts::os::extra::{FALSE, PROCESS_QUERY_INFORMATION, STILL_ACTIVE };
891-
892-
unsafe {
893-
let proc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid as DWORD);
894-
if proc.is_null() {
895-
return false;
896-
}
897-
// proc will be non-null if the process is alive, or if it died recently
898-
let mut status = 0;
899-
GetExitCodeProcess(proc, &mut status);
900-
CloseHandle(proc);
901-
return status == STILL_ACTIVE;
902-
}
903-
}
904-
905-
// this program will stay alive indefinitely trying to read from stdin
906-
let mut p = run::start_program(BLOCK_COMMAND, []);
907-
908-
assert!(process_exists(p.get_id()));
909-
910-
if force {
911-
p.force_destroy();
912-
} else {
913-
p.destroy();
914-
}
915-
916-
assert!(!process_exists(p.get_id()));
917-
}
918-
919-
#[test]
920-
fn test_unforced_destroy_actually_kills() {
921-
test_destroy_actually_kills(false);
922-
}
923-
924-
#[test]
925-
fn test_forced_destroy_actually_kills() {
926-
test_destroy_actually_kills(true);
927-
}
928858
}

src/test/run-pass/core-run-destroy.rs

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-fast
12+
// compile-flags:--test
13+
14+
// NB: These tests kill child processes. Valgrind sees these children as leaking
15+
// memory, which makes for some *confusing* logs. That's why these are here
16+
// instead of in core.
17+
18+
use core::run;
19+
use core::run::*;
20+
21+
#[test]
22+
fn test_destroy_once() {
23+
let mut p = run::start_program("echo", []);
24+
p.destroy(); // this shouldn't crash (and nor should the destructor)
25+
}
26+
27+
#[test]
28+
fn test_destroy_twice() {
29+
let mut p = run::start_program("echo", []);
30+
p.destroy(); // this shouldnt crash...
31+
p.destroy(); // ...and nor should this (and nor should the destructor)
32+
}
33+
34+
fn test_destroy_actually_kills(force: bool) {
35+
36+
#[cfg(unix)]
37+
static BLOCK_COMMAND: &'static str = "cat";
38+
39+
#[cfg(windows)]
40+
static BLOCK_COMMAND: &'static str = "cmd";
41+
42+
#[cfg(unix)]
43+
fn process_exists(pid: libc::pid_t) -> bool {
44+
run::program_output("ps", [~"-p", pid.to_str()]).out.contains(pid.to_str())
45+
}
46+
47+
#[cfg(windows)]
48+
fn process_exists(pid: libc::pid_t) -> bool {
49+
50+
use core::libc::types::os::arch::extra::DWORD;
51+
use core::libc::funcs::extra::kernel32::{CloseHandle, GetExitCodeProcess, OpenProcess};
52+
use core::libc::consts::os::extra::{FALSE, PROCESS_QUERY_INFORMATION, STILL_ACTIVE };
53+
54+
unsafe {
55+
let proc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid as DWORD);
56+
if proc.is_null() {
57+
return false;
58+
}
59+
// proc will be non-null if the process is alive, or if it died recently
60+
let mut status = 0;
61+
GetExitCodeProcess(proc, &mut status);
62+
CloseHandle(proc);
63+
return status == STILL_ACTIVE;
64+
}
65+
}
66+
67+
// this program will stay alive indefinitely trying to read from stdin
68+
let mut p = run::start_program(BLOCK_COMMAND, []);
69+
70+
assert!(process_exists(p.get_id()));
71+
72+
if force {
73+
p.force_destroy();
74+
} else {
75+
p.destroy();
76+
}
77+
78+
assert!(!process_exists(p.get_id()));
79+
}
80+
81+
#[test]
82+
fn test_unforced_destroy_actually_kills() {
83+
test_destroy_actually_kills(false);
84+
}
85+
86+
#[test]
87+
fn test_forced_destroy_actually_kills() {
88+
test_destroy_actually_kills(true);
89+
}

0 commit comments

Comments
 (0)