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.
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.
11 // ignore-cloudabi can't run commands
12 // ignore-emscripten can't run commands
18 use std::process::{Command, ExitStatus};
21 #[link(name = "rust_test_helpers", kind = "static")]
23 fn rust_get_null_ptr() -> *mut ::libc::c_char;
27 fn check_status(status: std::process::ExitStatus)
30 use std::os::unix::process::ExitStatusExt;
32 assert!(status.signal() == Some(libc::SIGSEGV)
33 || status.signal() == Some(libc::SIGBUS));
37 fn check_status(status: std::process::ExitStatus)
39 assert!(!status.success());
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
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"));