-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite libtest-thread-limit to rmake
- Loading branch information
Showing
8 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// libtest used to panic if it hit the thread limit. This often resulted in spurious test failures | ||
// (thread 'main' panicked at 'called Result::unwrap() on an Err value: Os | ||
// { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }' ... | ||
// error: test failed, to rerun pass '--lib'). | ||
// Since the fix in #81546, the test should continue to run synchronously | ||
// if it runs out of threads. Therefore, this test's final execution step | ||
// should succeed without an error. | ||
// See https://github.com/rust-lang/rust/pull/81546 | ||
|
||
//@ only-linux | ||
// Reason: thread limit modification | ||
|
||
use std::ffi::{self, CStr, CString}; | ||
use std::path::PathBuf; | ||
|
||
use run_make_support::{libc, run, rustc}; | ||
|
||
fn main() { | ||
rustc().input("test.rs").arg("--test").run(); | ||
|
||
let pid = unsafe { libc::fork() }; | ||
assert!(pid >= 0); | ||
|
||
if pid == 0 { | ||
let test = CString::new("test").unwrap(); | ||
// The argv array should be terminated with a NULL pointer. | ||
let argv = [test.as_ptr(), std::ptr::null()]; | ||
let rlimit = libc::rlimit { rlim_cur: 1, rlim_max: 1 }; | ||
let ret = unsafe { libc::setrlimit(libc::RLIMIT_NPROC, &rlimit as *const libc::rlimit) }; | ||
assert!(ret == 0); | ||
|
||
let ret = unsafe { libc::execv(test.as_ptr(), argv.as_ptr()) }; | ||
assert!(ret == 0); | ||
} else { | ||
// parent | ||
|
||
let mut child_exit_status: libc::c_int = 0; | ||
let ret = unsafe { libc::waitpid(pid, &mut child_exit_status as *mut libc::c_int, 0) }; | ||
assert!(ret == pid); | ||
assert!(child_exit_status == 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters