Skip to content

Commit 75fa9f6

Browse files
committed
compiletest: Add a //@ needs-threads directive
This commit is extracted from rust-lang#122036 and adds a new directive to the `compiletest` test runner, `//@ needs-threads`. This is intended to capture the need that a target must implement threading to execute a specific test, typically one that uses `std::thread`. This is primarily done for WebAssembly targets which currently do not have threads by default. This enables transitioning a lot of `//@ ignore-wasm*`-style ignores into a more self-documenting `//@ needs-threads` directive. Additionally the `wasm32-wasi-preview1-threads` target, for example, does actually have threads, but isn't tested in CI at this time. This change enables running these tests for that target, but not other wasm targets.
1 parent bfe762e commit 75fa9f6

File tree

77 files changed

+109
-76
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+109
-76
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,15 @@ impl Config {
451451
self.target_cfg().panic == PanicStrategy::Unwind
452452
}
453453

454+
pub fn has_threads(&self) -> bool {
455+
// Wasm targets don't have threads unless `-threads` is in the target
456+
// name, such as `wasm32-wasip1-threads`.
457+
if self.target.starts_with("wasm") {
458+
return self.target.contains("threads");
459+
}
460+
true
461+
}
462+
454463
pub fn has_asm_support(&self) -> bool {
455464
static ASM_SUPPORTED_ARCHS: &[&str] = &[
456465
"x86", "x86_64", "arm", "aarch64", "riscv32",

src/tools/compiletest/src/header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
787787
"needs-sanitizer-shadow-call-stack",
788788
"needs-sanitizer-support",
789789
"needs-sanitizer-thread",
790+
"needs-threads",
790791
"needs-unwind",
791792
"needs-xray",
792793
"no-prefer-dynamic",

src/tools/compiletest/src/header/needs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ pub(super) fn handle_needs(
8484
condition: config.run_enabled(),
8585
ignore_reason: "ignored when running the resulting test binaries is disabled",
8686
},
87+
Need {
88+
name: "needs-threads",
89+
condition: config.has_threads(),
90+
ignore_reason: "ignored on targets without threading support",
91+
},
8792
Need {
8893
name: "needs-unwind",
8994
condition: config.can_unwind(),

src/tools/compiletest/src/header/tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,23 @@ fn ignore_mode() {
592592
assert!(!check_ignore(&config, &format!("//@ ignore-mode-{other}")));
593593
}
594594
}
595+
596+
#[test]
597+
fn threads_support() {
598+
let threads = [
599+
("x86_64-unknown-linux-gnu", true),
600+
("aarch64-apple-darwin", true),
601+
("wasm32-unknown-unknown", false),
602+
("wasm64-unknown-unknown", false),
603+
#[cfg(not(bootstrap))]
604+
("wasm32-wasip1", false),
605+
#[cfg(not(bootstrap))]
606+
("wasm32-wasip1-threads", true),
607+
("wasm32-wasi-preview1-threads", true),
608+
];
609+
for (target, has_threads) in threads {
610+
let config = cfg().target(target).build();
611+
assert_eq!(config.has_threads(), has_threads);
612+
assert_eq!(check_ignore(&config, "//@ needs-threads"), !has_threads)
613+
}
614+
}

tests/codegen/cffi/c-variadic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ ignore-wasm32-bare compiled with panic=abort by default
1+
//@ needs-unwind
22
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
33
//
44

tests/ui/abi/extern/extern-call-deep2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-pass
22
#![allow(unused_must_use)]
3-
//@ ignore-emscripten no threads support
3+
//@ needs-threads
44
#![feature(rustc_private)]
55

66
extern crate libc;

tests/ui/abi/extern/extern-call-scrub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// make sure the stack pointers are maintained properly in both
55
// directions
66

7-
//@ ignore-emscripten no threads support
7+
//@ needs-threads
88
#![feature(rustc_private)]
99

1010
extern crate libc;

tests/ui/abi/foreign/foreign-call-no-runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-pass
2-
//@ ignore-emscripten no threads support
2+
//@ needs-threads
33

44
#![feature(rustc_private)]
55

tests/ui/box/unit/unique-send-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-pass
22
#![allow(unused_must_use)]
3-
//@ ignore-emscripten no threads support
3+
//@ needs-threads
44

55
use std::sync::mpsc::{channel, Sender};
66
use std::thread;

tests/ui/codegen/init-large-type.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// optimisation.
88

99
//@ pretty-expanded FIXME #23616
10-
//@ ignore-emscripten no threads support
11-
10+
//@ needs-threads
1211
#![feature(intrinsics)]
1312

1413
use std::{mem, thread};

0 commit comments

Comments
 (0)