]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2012-2014 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 | ||
5bcae85e SL |
11 | // ignore-emscripten can't run commands |
12 | ||
e9174d1e | 13 | #![feature(libc)] |
c34b1796 | 14 | |
e9174d1e SL |
15 | extern crate libc; |
16 | ||
17 | use std::process::{Command, ExitStatus}; | |
85aaf69f | 18 | use std::env; |
1a4d82fc | 19 | |
7453a54e SL |
20 | #[link(name = "rust_test_helpers")] |
21 | extern { | |
22 | fn rust_get_null_ptr() -> *mut ::libc::c_char; | |
23 | } | |
24 | ||
25 | #[cfg(unix)] | |
26 | fn check_status(status: std::process::ExitStatus) | |
27 | { | |
28 | use libc; | |
29 | use std::os::unix::process::ExitStatusExt; | |
30 | ||
31 | assert!(status.signal() == Some(libc::SIGSEGV) | |
32 | || status.signal() == Some(libc::SIGBUS)); | |
33 | } | |
34 | ||
35 | #[cfg(not(unix))] | |
36 | fn check_status(status: std::process::ExitStatus) | |
37 | { | |
38 | assert!(!status.success()); | |
39 | } | |
40 | ||
1a4d82fc | 41 | fn main() { |
85aaf69f SL |
42 | let args: Vec<String> = env::args().collect(); |
43 | if args.len() > 1 && args[1] == "segfault" { | |
7453a54e | 44 | unsafe { *rust_get_null_ptr() = 1; }; // trigger a segfault |
1a4d82fc | 45 | } else { |
85aaf69f | 46 | let segfault = Command::new(&args[0]).arg("segfault").output().unwrap(); |
e9174d1e SL |
47 | let stderr = String::from_utf8_lossy(&segfault.stderr); |
48 | let stdout = String::from_utf8_lossy(&segfault.stdout); | |
49 | println!("stdout: {}", stdout); | |
50 | println!("stderr: {}", stderr); | |
51 | println!("status: {}", segfault.status); | |
7453a54e | 52 | check_status(segfault.status); |
e9174d1e | 53 | assert!(!stderr.contains("has overflowed its stack")); |
1a4d82fc JJ |
54 | } |
55 | } |