Skip to content

Commit

Permalink
rewrite libtest-thread-limit to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Aug 14, 2024
1 parent 8c082dd commit 7ccc842
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3147,6 +3147,7 @@ dependencies = [
"bstr",
"build_helper",
"gimli 0.31.0",
"libc",
"object 0.36.2",
"regex",
"similar",
Expand Down
1 change: 1 addition & 0 deletions src/tools/run-make-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ wasmparser = { version = "0.214", default-features = false, features = ["std"] }
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
gimli = "0.31.0"
build_helper = { path = "../build_helper" }
libc = "0.2"
1 change: 1 addition & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod rfs {
// Re-exports of third-party library crates.
pub use bstr;
pub use gimli;
pub use libc;
pub use object;
pub use regex;
pub use wasmparser;
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ run-make/jobserver-error/Makefile
run-make/libs-through-symlinks/Makefile
run-make/libtest-json/Makefile
run-make/libtest-junit/Makefile
run-make/libtest-thread-limit/Makefile
run-make/min-global-align/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/no-alloc-shim/Makefile
Expand Down
7 changes: 0 additions & 7 deletions tests/run-make/libtest-thread-limit/Makefile

This file was deleted.

42 changes: 42 additions & 0 deletions tests/run-make/libtest-thread-limit/rmake.rs
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);
}
}
6 changes: 5 additions & 1 deletion tests/run-make/libtest-thread-limit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ fn spawn_thread_would_block() {
THREAD_ID.set(thread::current().id()).unwrap();
}

// HACK(Oneirical): Tests are run in alphabetical order, and the second test is dependent on the
// first to set THREAD_ID. Do not rename the tests in such a way that `test_run_in_same_thread`
// would run before `spawn_thread_would_block`.

#[test]
fn run_in_same_thread() {
fn test_run_in_same_thread() {
assert_eq!(*THREAD_ID.get().unwrap(), thread::current().id());
}
3 changes: 2 additions & 1 deletion tests/run-make/macos-deployment-target/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// See https://github.com/rust-lang/rust/pull/105123

//@ only-macos
// Reason: this test exercises an OSX-specific issue

use run_make_support::{cmd, rustc};

Expand All @@ -18,7 +19,7 @@ fn main() {
} else {
"version 10.13"
};
// XXX: The check is for either the x86_64 minimum OR the aarch64 minimum
// NOTE: The check is for either the x86_64 minimum OR the aarch64 minimum
// (M1 starts at macOS 11). They also use different load commands, so we let that change with
// each too. The aarch64 check isn't as robust as the x86 one, but testing both seems unneeded.
cmd("vtool")
Expand Down

0 comments on commit 7ccc842

Please sign in to comment.