compiletest: Add a //@ needs-threads directive
This commit is extracted from #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.
This commit is contained in:
parent
bfe762e0ed
commit
75fa9f6dec
77 changed files with 109 additions and 76 deletions
|
|
@ -451,6 +451,15 @@ impl Config {
|
|||
self.target_cfg().panic == PanicStrategy::Unwind
|
||||
}
|
||||
|
||||
pub fn has_threads(&self) -> bool {
|
||||
// Wasm targets don't have threads unless `-threads` is in the target
|
||||
// name, such as `wasm32-wasip1-threads`.
|
||||
if self.target.starts_with("wasm") {
|
||||
return self.target.contains("threads");
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn has_asm_support(&self) -> bool {
|
||||
static ASM_SUPPORTED_ARCHS: &[&str] = &[
|
||||
"x86", "x86_64", "arm", "aarch64", "riscv32",
|
||||
|
|
|
|||
|
|
@ -787,6 +787,7 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
|
|||
"needs-sanitizer-shadow-call-stack",
|
||||
"needs-sanitizer-support",
|
||||
"needs-sanitizer-thread",
|
||||
"needs-threads",
|
||||
"needs-unwind",
|
||||
"needs-xray",
|
||||
"no-prefer-dynamic",
|
||||
|
|
|
|||
|
|
@ -84,6 +84,11 @@ pub(super) fn handle_needs(
|
|||
condition: config.run_enabled(),
|
||||
ignore_reason: "ignored when running the resulting test binaries is disabled",
|
||||
},
|
||||
Need {
|
||||
name: "needs-threads",
|
||||
condition: config.has_threads(),
|
||||
ignore_reason: "ignored on targets without threading support",
|
||||
},
|
||||
Need {
|
||||
name: "needs-unwind",
|
||||
condition: config.can_unwind(),
|
||||
|
|
|
|||
|
|
@ -592,3 +592,23 @@ fn ignore_mode() {
|
|||
assert!(!check_ignore(&config, &format!("//@ ignore-mode-{other}")));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn threads_support() {
|
||||
let threads = [
|
||||
("x86_64-unknown-linux-gnu", true),
|
||||
("aarch64-apple-darwin", true),
|
||||
("wasm32-unknown-unknown", false),
|
||||
("wasm64-unknown-unknown", false),
|
||||
#[cfg(not(bootstrap))]
|
||||
("wasm32-wasip1", false),
|
||||
#[cfg(not(bootstrap))]
|
||||
("wasm32-wasip1-threads", true),
|
||||
("wasm32-wasi-preview1-threads", true),
|
||||
];
|
||||
for (target, has_threads) in threads {
|
||||
let config = cfg().target(target).build();
|
||||
assert_eq!(config.has_threads(), has_threads);
|
||||
assert_eq!(check_ignore(&config, "//@ needs-threads"), !has_threads)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue