1 // Copyright 2017 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.
14 // ignore-cloudabi no processes
15 // ignore-emscripten no processes
16 // ignore-musl FIXME #31506
17 // min-system-llvm-version 5.0
20 use std::process::Command;
24 #[link(name = "rust_test_helpers", kind = "static")]
26 #[link_name = "rust_dbg_extern_identity_u64"]
31 let args = env::args().skip(1).collect::<Vec<_>>();
34 "main-thread" => recurse(&[]),
35 "child-thread" => thread::spawn(|| recurse(&[])).join().unwrap(),
41 let me = env::current_exe().unwrap();
43 // The linux kernel has some different behavior for the main thread because
44 // the main thread's stack can typically grow. We can't always guarantee
45 // that we report stack overflow on the main thread, see #43052 for some
47 if cfg!(not(target_os = "linux")) {
48 assert_overflow(Command::new(&me).arg("main-thread"));
50 assert_overflow(Command::new(&me).arg("child-thread"));
53 #[allow(unconditional_recursion)]
54 fn recurse(array: &[u64]) {
55 unsafe { black_box(array.as_ptr() as u64); }
56 let local: [_; 1024] = unsafe { mem::uninitialized() };
60 fn assert_overflow(cmd: &mut Command) {
61 let output = cmd.output().unwrap();
62 assert!(!output.status.success());
63 let stdout = String::from_utf8_lossy(&output.stdout);
64 let stderr = String::from_utf8_lossy(&output.stderr);
65 println!("status: {}", output.status);
66 println!("stdout: {}", stdout);
67 println!("stderr: {}", stderr);
68 assert!(stdout.is_empty());
69 assert!(stderr.contains("has overflowed its stack\n"));