Skip to content

Commit e05bc97

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 ed82e19 commit e05bc97

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

+9
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,15 @@ impl Config {
453453
self.target_cfg().panic == PanicStrategy::Unwind
454454
}
455455

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

src/tools/compiletest/src/header.rs

+1
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

+5
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

+20
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-2
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};

tests/ui/codegen/issue-28950.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-pass
2-
//@ ignore-emscripten no threads
2+
//@ needs-threads
33
//@ compile-flags: -O
44

55
// Tests that the `vec!` macro does not overflow the stack when it is

tests/ui/coroutine/smoke.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ revisions: default nomiropt
44
//@[nomiropt]compile-flags: -Z mir-opt-level=0
55

6-
//@ ignore-emscripten no threads support
6+
//@ needs-threads
77
//@ compile-flags: --test
88

99
#![feature(coroutines, coroutine_trait)]

tests/ui/cross-crate/cci_capture_clause.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// that use capture clauses.
66

77
//@ pretty-expanded FIXME #23616
8-
//@ ignore-emscripten no threads support
8+
//@ needs-threads
99

1010
extern crate cci_capture_clause;
1111

tests/ui/hashmap/hashmap-memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![allow(non_camel_case_types)]
55
#![allow(dead_code)]
66
#![allow(unused_mut)]
7-
//@ ignore-emscripten No support for threads
7+
//@ needs-threads
88

99
/**
1010
A somewhat reduced test case to expose some Valgrind issues.

tests/ui/issues/issue-16560.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-pass
22
#![allow(unused_variables)]
3-
//@ ignore-emscripten no threads support
3+
//@ needs-threads
44

55
use std::thread;
66
use std::mem;

tests/ui/issues/issue-21291.rs

+1-1
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
// Regression test for unwrapping the result of `join`, issue #21291
55

tests/ui/issues/issue-22864-2.rs

+1-1
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
pub fn main() {
55
let f = || || 0;

tests/ui/issues/issue-59020.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ edition:2018
22
//@ run-pass
3-
//@ ignore-emscripten no threads support
3+
//@ needs-threads
44

55
use std::thread;
66
use std::time::Duration;

tests/ui/logging-only-prints-once.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-pass
22
//@ ignore-windows
3-
//@ ignore-emscripten no threads support
3+
//@ needs-threads
44

55
use std::cell::Cell;
66
use std::fmt;

tests/ui/lto/lto-still-runs-thread-dtors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-pass
22
//@ compile-flags: -C lto
33
//@ no-prefer-dynamic
4-
//@ ignore-emscripten no threads support
4+
//@ needs-threads
55

66
use std::thread;
77

tests/ui/macros/macro-with-braces-in-expr-position.rs

+1-1
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::thread;
66

tests/ui/moves/moves-based-on-type-capture-clause.rs

+1-1
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::thread;
66

tests/ui/panics/panic-handler-chain.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//@ run-pass
22
//@ needs-unwind
3+
//@ needs-threads
34
#![allow(stable_features)]
45

5-
//@ ignore-emscripten no threads support
6-
76
#![feature(std_panic)]
87

98
use std::sync::atomic::{AtomicUsize, Ordering};

tests/ui/panics/panic-task-name-none.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-fail
22
//@ error-pattern:thread '<unnamed>' panicked
33
//@ error-pattern:test
4-
//@ ignore-emscripten Needs threads
4+
//@ needs-threads
55

66
use std::thread;
77

tests/ui/panics/panic-task-name-owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-fail
22
//@ error-pattern:thread 'owned name' panicked
33
//@ error-pattern:test
4-
//@ ignore-emscripten Needs threads.
4+
//@ needs-threads
55

66
use std::thread::Builder;
77

tests/ui/process-termination/process-termination-blocking-io.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// https://github.com/fortanix/rust-sgx/issues/109
33

44
//@ run-pass
5-
//@ ignore-emscripten no threads support
5+
//@ needs-threads
66

77
use std::{net::TcpListener, sync::mpsc, thread};
88

tests/ui/process-termination/process-termination-simple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// program should terminate when std::process::exit is called from any thread
22

33
//@ run-pass
4-
//@ ignore-emscripten no threads support
4+
//@ needs-threads
55

66
use std::{process, thread};
77

tests/ui/structs-enums/ivec-tag.rs

+1-1
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::thread;
66
use std::sync::mpsc::{channel, Sender};

tests/ui/test-attrs/test-filter-multiple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ run-flags: --test-threads=1 test1 test2
44
//@ check-run-results
55
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
6-
//@ ignore-emscripten no threads support
6+
//@ needs-threads
77

88
#[test]
99
fn test1() {}

tests/ui/test-attrs/test-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ run-flags: --test-threads=1
33
//@ check-run-results
44
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
5-
//@ ignore-emscripten no threads support
5+
//@ needs-threads
66
//@ run-pass
77

88
#[test]

tests/ui/thread-local/tls.rs

+1-1
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
//@ compile-flags: -O
44
//@ ignore-nto Doesn't work without emulated TLS enabled (in LLVM)
55

tests/ui/threads-sendsync/child-outlives-parent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Reported as issue #126, child leaks the string.
33

44
//@ pretty-expanded FIXME #23616
5-
//@ ignore-emscripten no threads support
5+
//@ needs-threads
66

77
use std::thread;
88

tests/ui/threads-sendsync/clone-with-exterior.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-pass
22

33
#![allow(unused_must_use)]
4-
//@ ignore-emscripten no threads support
4+
//@ needs-threads
55

66
use std::thread;
77

tests/ui/threads-sendsync/comm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//@ run-pass
22
#![allow(unused_must_use)]
3-
//@ ignore-emscripten no threads support
3+
//@ needs-threads
44

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

88
pub fn main() {
99
let (tx, rx) = channel();
10-
let t = thread::spawn(move|| { child(&tx) });
10+
let t = thread::spawn(move || { child(&tx) });
1111
let y = rx.recv().unwrap();
1212
println!("received");
1313
println!("{}", y);

tests/ui/threads-sendsync/eprint-on-tls-drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-pass
2-
//@ ignore-emscripten no processes
2+
//@ needs-threads
33
//@ ignore-sgx no processes
44

55
use std::cell::RefCell;

tests/ui/threads-sendsync/issue-24313.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-pass
2-
//@ ignore-emscripten no threads
2+
//@ needs-threads
33
//@ ignore-sgx no processes
44

55
use std::thread;

tests/ui/threads-sendsync/issue-29488.rs

+1-1
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
use std::thread;
55

tests/ui/threads-sendsync/issue-43733-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ ignore-wasm32
1+
//@ needs-threads
22
//@ dont-check-compiler-stderr
33
#![feature(cfg_target_thread_local, thread_local_internals)]
44

tests/ui/threads-sendsync/issue-43733.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ ignore-wasm32
1+
//@ needs-threads
22
#![feature(thread_local)]
33
#![feature(cfg_target_thread_local, thread_local_internals)]
44

tests/ui/threads-sendsync/issue-4446.rs

+1-1
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
use std::sync::mpsc::channel;
55
use std::thread;

tests/ui/threads-sendsync/issue-4448.rs

+1-1
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
use std::sync::mpsc::channel;
55
use std::thread;

tests/ui/threads-sendsync/issue-8827.rs

+1-1
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
use std::thread;
55
use std::sync::mpsc::{channel, Receiver};

tests/ui/threads-sendsync/issue-9396.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-pass
22
#![allow(unused_must_use)]
33
#![allow(deprecated)]
4-
//@ ignore-emscripten no threads support
4+
//@ needs-threads
55

66
use std::sync::mpsc::{TryRecvError, channel};
77
use std::thread;

tests/ui/threads-sendsync/mpsc_stress.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-pass
22
//@ compile-flags:--test
3-
//@ ignore-emscripten
3+
//@ needs-threads
44

55
use std::sync::mpsc::channel;
66
use std::sync::mpsc::TryRecvError;

tests/ui/threads-sendsync/send-resource.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![allow(non_camel_case_types)]
55

66
//@ pretty-expanded FIXME #23616
7-
//@ ignore-emscripten no threads support
7+
//@ needs-threads
88

99
use std::thread;
1010
use std::sync::mpsc::channel;

0 commit comments

Comments
 (0)