2019-07-26 21:54:25 +00:00
|
|
|
//@ run-pass
|
2023-07-08 05:10:24 +00:00
|
|
|
//@ revisions: current next
|
2024-03-11 01:18:41 +00:00
|
|
|
//@ ignore-compare-mode-next-solver (explicit revisions)
|
2023-12-14 12:11:28 +00:00
|
|
|
//@[next] compile-flags: -Znext-solver
|
2019-07-26 21:54:25 +00:00
|
|
|
|
2018-09-14 10:20:28 +00:00
|
|
|
#![allow(unused_must_use)]
|
2021-04-22 14:06:53 +00:00
|
|
|
#![feature(panic_always_abort)]
|
2017-12-19 00:59:29 +00:00
|
|
|
// Since we mark some ABIs as "nounwind" to LLVM, we must make sure that
|
|
|
|
// we never unwind through them.
|
|
|
|
|
2024-03-06 20:44:54 +00:00
|
|
|
//@ ignore-wasm32 no processes
|
2019-04-24 16:26:33 +00:00
|
|
|
//@ ignore-sgx no processes
|
2017-12-19 00:59:29 +00:00
|
|
|
|
|
|
|
use std::io;
|
2021-06-08 18:23:58 +00:00
|
|
|
use std::io::prelude::*;
|
2021-04-22 14:06:53 +00:00
|
|
|
use std::process::{exit, Command, Stdio};
|
|
|
|
use std::sync::{Arc, Barrier};
|
|
|
|
use std::thread;
|
2021-06-08 18:23:58 +00:00
|
|
|
use std::{env, panic};
|
2017-12-19 00:59:29 +00:00
|
|
|
|
|
|
|
extern "C" fn panic_in_ffi() {
|
|
|
|
panic!("Test");
|
|
|
|
}
|
|
|
|
|
2021-02-07 12:16:11 +00:00
|
|
|
fn should_have_aborted() {
|
2017-12-19 00:59:29 +00:00
|
|
|
io::stdout().write(b"This should never be printed.\n");
|
|
|
|
let _ = io::stdout().flush();
|
|
|
|
}
|
|
|
|
|
2021-04-22 14:05:23 +00:00
|
|
|
fn bomb_out_but_not_abort(msg: &str) {
|
|
|
|
eprintln!("bombing out: {}", msg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2021-02-07 12:16:11 +00:00
|
|
|
fn test() {
|
2021-06-08 18:23:58 +00:00
|
|
|
let _ = panic::catch_unwind(|| {
|
|
|
|
panic_in_ffi();
|
|
|
|
});
|
2021-02-07 12:16:11 +00:00
|
|
|
should_have_aborted();
|
2019-10-12 19:02:38 +00:00
|
|
|
}
|
|
|
|
|
2021-04-22 13:22:42 +00:00
|
|
|
fn test_always_abort() {
|
|
|
|
panic::always_abort();
|
2021-06-08 18:23:58 +00:00
|
|
|
let _ = panic::catch_unwind(|| {
|
|
|
|
panic!();
|
|
|
|
});
|
2021-04-22 13:22:42 +00:00
|
|
|
should_have_aborted();
|
|
|
|
}
|
|
|
|
|
2021-04-22 14:06:53 +00:00
|
|
|
fn test_always_abort_thread() {
|
|
|
|
let barrier = Arc::new(Barrier::new(2));
|
|
|
|
let thr = {
|
|
|
|
let barrier = barrier.clone();
|
2021-06-08 18:23:58 +00:00
|
|
|
thread::spawn(move || {
|
2021-04-22 14:06:53 +00:00
|
|
|
barrier.wait();
|
|
|
|
panic!("in thread");
|
|
|
|
})
|
|
|
|
};
|
|
|
|
panic::always_abort();
|
|
|
|
barrier.wait();
|
|
|
|
let _ = thr.join();
|
|
|
|
bomb_out_but_not_abort("joined - but we were supposed to panic!");
|
|
|
|
}
|
|
|
|
|
2017-12-19 00:59:29 +00:00
|
|
|
fn main() {
|
2021-02-07 12:16:11 +00:00
|
|
|
let tests: &[(_, fn())] = &[
|
|
|
|
("test", test),
|
2021-04-22 13:22:42 +00:00
|
|
|
("test_always_abort", test_always_abort),
|
2021-04-22 14:06:53 +00:00
|
|
|
("test_always_abort_thread", test_always_abort_thread),
|
2021-02-07 12:16:11 +00:00
|
|
|
];
|
|
|
|
|
2017-12-19 00:59:29 +00:00
|
|
|
let args: Vec<String> = env::args().collect();
|
2019-10-12 19:02:38 +00:00
|
|
|
if args.len() > 1 {
|
|
|
|
// This is inside the self-executed command.
|
2021-06-08 18:23:58 +00:00
|
|
|
for (a, f) in tests {
|
|
|
|
if &args[1] == a {
|
|
|
|
return f();
|
|
|
|
}
|
2019-10-12 19:02:38 +00:00
|
|
|
}
|
2021-04-22 14:05:23 +00:00
|
|
|
bomb_out_but_not_abort("bad test");
|
2017-12-19 00:59:29 +00:00
|
|
|
}
|
|
|
|
|
2021-02-07 12:16:11 +00:00
|
|
|
let execute_self_expecting_abort = |arg| {
|
|
|
|
let mut p = Command::new(&args[0])
|
2021-06-08 18:23:58 +00:00
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
.arg(arg)
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
2021-04-22 14:05:23 +00:00
|
|
|
let status = p.wait().unwrap();
|
|
|
|
assert!(!status.success());
|
|
|
|
// Any reasonable platform can distinguish a process which
|
|
|
|
// called exit(1) from one which panicked.
|
|
|
|
assert_ne!(status.code(), Some(1));
|
2021-02-07 12:16:11 +00:00
|
|
|
};
|
|
|
|
|
2021-06-08 18:23:58 +00:00
|
|
|
for (a, _f) in tests {
|
2021-02-07 12:16:11 +00:00
|
|
|
execute_self_expecting_abort(a);
|
|
|
|
}
|
2017-12-19 00:59:29 +00:00
|
|
|
}
|