]> git.proxmox.com Git - rustc.git/blob - src/vendor/rayon/tests/run-pass/stack_overflow_crash.rs
New upstream version 1.25.0+dfsg1
[rustc.git] / src / vendor / rayon / tests / run-pass / stack_overflow_crash.rs
1 extern crate rayon;
2
3 use rayon::*;
4
5 use std::process::{self, Command};
6 use std::env;
7
8 #[cfg(target_os = "linux")]
9 use std::os::unix::process::ExitStatusExt;
10
11
12
13 fn force_stack_overflow(depth: u32) {
14 let buffer = [0u8; 1024*1024];
15 if depth > 0 {
16 force_stack_overflow(depth - 1);
17 }
18 }
19
20 fn main() {
21 if env::args().len() == 1 {
22 // first check that the recursivecall actually causes a stack overflow, and does not get optimized away
23 {
24 let status = Command::new(env::current_exe().unwrap())
25 .arg("8")
26 .status()
27 .unwrap();
28
29 #[cfg(windows)]
30 assert_eq!(status.code(), Some(0xc00000fd /*STATUS_STACK_OVERFLOW*/));
31
32 #[cfg(unix)]
33 assert_eq!(status.code(), None);
34
35 #[cfg(target_os = "linux")]
36 assert!(status.signal() == Some(11 /*SIGABRT*/) ||
37 status.signal() == Some(6 /*SIGSEGV*/));
38 }
39
40
41 // now run with a larger stack and verify correct operation
42 {
43 let status = Command::new(env::current_exe().unwrap())
44 .arg("48")
45 .status()
46 .unwrap();
47 assert_eq!(status.code(), Some(0));
48 #[cfg(target_os = "linux")]
49 assert_eq!(status.signal(), None);
50 }
51 } else {
52 let stack_size_in_mb: usize = env::args().nth(1).unwrap().parse().unwrap();
53 let pool = ThreadPoolBuilder::new().stack_size(stack_size_in_mb * 1024 * 1024).build().unwrap();
54 let index = pool.install(|| {
55 force_stack_overflow(32);
56 });
57 }
58 }