Skip to content

Commit 7ccc842

Browse files
committed
rewrite libtest-thread-limit to rmake
1 parent 8c082dd commit 7ccc842

File tree

8 files changed

+52
-10
lines changed

8 files changed

+52
-10
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3147,6 +3147,7 @@ dependencies = [
31473147
"bstr",
31483148
"build_helper",
31493149
"gimli 0.31.0",
3150+
"libc",
31503151
"object 0.36.2",
31513152
"regex",
31523153
"similar",

src/tools/run-make-support/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ wasmparser = { version = "0.214", default-features = false, features = ["std"] }
1111
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
1212
gimli = "0.31.0"
1313
build_helper = { path = "../build_helper" }
14+
libc = "0.2"

src/tools/run-make-support/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub mod rfs {
3636
// Re-exports of third-party library crates.
3737
pub use bstr;
3838
pub use gimli;
39+
pub use libc;
3940
pub use object;
4041
pub use regex;
4142
pub use wasmparser;

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ run-make/jobserver-error/Makefile
1111
run-make/libs-through-symlinks/Makefile
1212
run-make/libtest-json/Makefile
1313
run-make/libtest-junit/Makefile
14-
run-make/libtest-thread-limit/Makefile
1514
run-make/min-global-align/Makefile
1615
run-make/native-link-modifier-bundle/Makefile
1716
run-make/no-alloc-shim/Makefile

tests/run-make/libtest-thread-limit/Makefile

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

tests/run-make/libtest-thread-limit/test.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ fn spawn_thread_would_block() {
1010
THREAD_ID.set(thread::current().id()).unwrap();
1111
}
1212

13+
// HACK(Oneirical): Tests are run in alphabetical order, and the second test is dependent on the
14+
// first to set THREAD_ID. Do not rename the tests in such a way that `test_run_in_same_thread`
15+
// would run before `spawn_thread_would_block`.
16+
1317
#[test]
14-
fn run_in_same_thread() {
18+
fn test_run_in_same_thread() {
1519
assert_eq!(*THREAD_ID.get().unwrap(), thread::current().id());
1620
}

tests/run-make/macos-deployment-target/rmake.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// See https://github.com/rust-lang/rust/pull/105123
55

66
//@ only-macos
7+
// Reason: this test exercises an OSX-specific issue
78

89
use run_make_support::{cmd, rustc};
910

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

0 commit comments

Comments
 (0)