]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/segfault-no-out-of-stack.rs
Ignore new test on Windows
[rust.git] / src / test / run-pass / segfault-no-out-of-stack.rs
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
11 // ignore-cloudabi can't run commands
12 // ignore-emscripten can't run commands
13
14 #![feature(libc)]
15
16 extern crate libc;
17
18 use std::process::{Command, ExitStatus};
19 use std::env;
20
21 #[link(name = "rust_test_helpers", kind = "static")]
22 extern {
23     fn rust_get_null_ptr() -> *mut ::libc::c_char;
24 }
25
26 #[cfg(unix)]
27 fn check_status(status: std::process::ExitStatus)
28 {
29     use libc;
30     use std::os::unix::process::ExitStatusExt;
31
32     assert!(status.signal() == Some(libc::SIGSEGV)
33             || status.signal() == Some(libc::SIGBUS));
34 }
35
36 #[cfg(not(unix))]
37 fn check_status(status: std::process::ExitStatus)
38 {
39     assert!(!status.success());
40 }
41
42 fn main() {
43     let args: Vec<String> = env::args().collect();
44     if args.len() > 1 && args[1] == "segfault" {
45         unsafe { *rust_get_null_ptr() = 1; }; // trigger a segfault
46     } else {
47         let segfault = Command::new(&args[0]).arg("segfault").output().unwrap();
48         let stderr = String::from_utf8_lossy(&segfault.stderr);
49         let stdout = String::from_utf8_lossy(&segfault.stdout);
50         println!("stdout: {}", stdout);
51         println!("stderr: {}", stderr);
52         println!("status: {}", segfault.status);
53         check_status(segfault.status);
54         assert!(!stderr.contains("has overflowed its stack"));
55     }
56 }