2019-07-26 21:54:25 +00:00
|
|
|
//@ run-pass
|
2024-03-06 20:44:54 +00:00
|
|
|
//@ ignore-wasm32 can't run commands
|
2019-04-24 16:26:33 +00:00
|
|
|
//@ ignore-sgx no processes
|
2022-09-19 21:02:42 +00:00
|
|
|
//@ ignore-fuchsia must translate zircon signal to SIGSEGV/SIGBUS, FIXME (#58590)
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2024-04-16 03:46:27 +00:00
|
|
|
#![feature(rustc_private)]
|
2015-07-27 20:41:35 +00:00
|
|
|
|
2015-02-16 14:04:02 +00:00
|
|
|
use std::env;
|
2024-04-16 03:46:27 +00:00
|
|
|
use std::ffi::c_char;
|
2020-09-01 21:12:52 +00:00
|
|
|
use std::process::{Command, ExitStatus};
|
2014-10-23 05:29:41 +00:00
|
|
|
|
2016-11-24 00:09:51 +00:00
|
|
|
#[link(name = "rust_test_helpers", kind = "static")]
|
2020-09-01 21:12:52 +00:00
|
|
|
extern "C" {
|
2024-04-16 03:46:27 +00:00
|
|
|
fn rust_get_null_ptr() -> *mut c_char;
|
2016-01-31 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
2024-04-16 03:46:27 +00:00
|
|
|
fn check_status(status: ExitStatus) {
|
|
|
|
extern crate libc;
|
2016-01-31 23:30:32 +00:00
|
|
|
use std::os::unix::process::ExitStatusExt;
|
|
|
|
|
2020-09-01 21:12:52 +00:00
|
|
|
assert!(status.signal() == Some(libc::SIGSEGV) || status.signal() == Some(libc::SIGBUS));
|
2016-01-31 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(unix))]
|
2024-04-16 03:46:27 +00:00
|
|
|
fn check_status(status: ExitStatus) {
|
2016-01-31 23:30:32 +00:00
|
|
|
assert!(!status.success());
|
|
|
|
}
|
|
|
|
|
2014-10-23 05:29:41 +00:00
|
|
|
fn main() {
|
2015-02-16 14:04:02 +00:00
|
|
|
let args: Vec<String> = env::args().collect();
|
2015-02-02 02:53:25 +00:00
|
|
|
if args.len() > 1 && args[1] == "segfault" {
|
2020-09-01 21:12:52 +00:00
|
|
|
unsafe {
|
|
|
|
*rust_get_null_ptr() = 1;
|
|
|
|
}; // trigger a segfault
|
2014-10-23 05:29:41 +00:00
|
|
|
} else {
|
2015-02-02 02:53:25 +00:00
|
|
|
let segfault = Command::new(&args[0]).arg("segfault").output().unwrap();
|
2015-07-27 20:41:35 +00:00
|
|
|
let stderr = String::from_utf8_lossy(&segfault.stderr);
|
|
|
|
let stdout = String::from_utf8_lossy(&segfault.stdout);
|
|
|
|
println!("stdout: {}", stdout);
|
|
|
|
println!("stderr: {}", stderr);
|
|
|
|
println!("status: {}", segfault.status);
|
2016-01-31 23:30:32 +00:00
|
|
|
check_status(segfault.status);
|
2015-07-27 20:41:35 +00:00
|
|
|
assert!(!stderr.contains("has overflowed its stack"));
|
2014-10-23 05:29:41 +00:00
|
|
|
}
|
|
|
|
}
|