|
| 1 | +// libtest used to panic if it hit the thread limit. This often resulted in spurious test failures |
| 2 | +// (thread 'main' panicked at 'called Result::unwrap() on an Err value: Os |
| 3 | +// { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }' ... |
| 4 | +// error: test failed, to rerun pass '--lib'). |
| 5 | +// Since the fix in #81546, the test should continue to run synchronously |
| 6 | +// if it runs out of threads. Therefore, this test's final execution step |
| 7 | +// should succeed without an error. |
| 8 | +// See https://github.com/rust-lang/rust/pull/81546 |
| 9 | + |
| 10 | +//@ only-linux |
| 11 | +// Reason: thread limit modification |
| 12 | + |
| 13 | +use std::ffi::{self, CStr, CString}; |
| 14 | +use std::path::PathBuf; |
| 15 | + |
| 16 | +use run_make_support::{libc, run, rustc}; |
| 17 | + |
| 18 | +fn main() { |
| 19 | + rustc().input("test.rs").arg("--test").run(); |
| 20 | + |
| 21 | + let pid = unsafe { libc::fork() }; |
| 22 | + assert!(pid >= 0); |
| 23 | + |
| 24 | + if pid == 0 { |
| 25 | + let test = CString::new("test").unwrap(); |
| 26 | + // The argv array should be terminated with a NULL pointer. |
| 27 | + let argv = [test.as_ptr(), std::ptr::null()]; |
| 28 | + let rlimit = libc::rlimit { rlim_cur: 1, rlim_max: 1 }; |
| 29 | + let ret = unsafe { libc::setrlimit(libc::RLIMIT_NPROC, &rlimit as *const libc::rlimit) }; |
| 30 | + assert!(ret == 0); |
| 31 | + |
| 32 | + let ret = unsafe { libc::execv(test.as_ptr(), argv.as_ptr()) }; |
| 33 | + assert!(ret == 0); |
| 34 | + } else { |
| 35 | + // parent |
| 36 | + |
| 37 | + let mut child_exit_status: libc::c_int = 0; |
| 38 | + let ret = unsafe { libc::waitpid(pid, &mut child_exit_status as *mut libc::c_int, 0) }; |
| 39 | + assert!(ret == pid); |
| 40 | + assert!(child_exit_status == 0); |
| 41 | + } |
| 42 | +} |
0 commit comments