Skip to content

Commit

Permalink
Rollup merge of rust-lang#122109 - alexcrichton:compiletests-needs-th…
Browse files Browse the repository at this point in the history
…reads, r=workingjubilee

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.
  • Loading branch information
matthiaskrgr authored Mar 6, 2024
2 parents 1d4360a + 75fa9f6 commit 5642b04
Show file tree
Hide file tree
Showing 77 changed files with 109 additions and 76 deletions.
9 changes: 9 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/tools/compiletest/src/header/needs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
20 changes: 20 additions & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion tests/codegen/cffi/c-variadic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ ignore-wasm32-bare compiled with panic=abort by default
//@ needs-unwind
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
//

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/abi/extern/extern-call-deep2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
#![feature(rustc_private)]

extern crate libc;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/abi/extern/extern-call-scrub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// make sure the stack pointers are maintained properly in both
// directions

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

extern crate libc;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/abi/foreign/foreign-call-no-runtime.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

#![feature(rustc_private)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/box/unit/unique-send-2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads

use std::sync::mpsc::{channel, Sender};
use std::thread;
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/codegen/init-large-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// optimisation.

//@ pretty-expanded FIXME #23616
//@ ignore-emscripten no threads support

//@ needs-threads
#![feature(intrinsics)]

use std::{mem, thread};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/codegen/issue-28950.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads
//@ needs-threads
//@ compile-flags: -O

// Tests that the `vec!` macro does not overflow the stack when it is
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/coroutine/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ revisions: default nomiropt
//@[nomiropt]compile-flags: -Z mir-opt-level=0

//@ ignore-emscripten no threads support
//@ needs-threads
//@ compile-flags: --test

#![feature(coroutines, coroutine_trait)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cross-crate/cci_capture_clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// that use capture clauses.

//@ pretty-expanded FIXME #23616
//@ ignore-emscripten no threads support
//@ needs-threads

extern crate cci_capture_clause;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/hashmap/hashmap-memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(non_camel_case_types)]
#![allow(dead_code)]
#![allow(unused_mut)]
//@ ignore-emscripten No support for threads
//@ needs-threads

/**
A somewhat reduced test case to expose some Valgrind issues.
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-16560.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_variables)]
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;
use std::mem;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-21291.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

// Regression test for unwrapping the result of `join`, issue #21291

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-22864-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

pub fn main() {
let f = || || 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-59020.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ edition:2018
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;
use std::time::Duration;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/logging-only-prints-once.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
//@ ignore-windows
//@ ignore-emscripten no threads support
//@ needs-threads

use std::cell::Cell;
use std::fmt;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lto/lto-still-runs-thread-dtors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ run-pass
//@ compile-flags: -C lto
//@ no-prefer-dynamic
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/macro-with-braces-in-expr-position.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/moves/moves-based-on-type-capture-clause.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;

Expand Down
3 changes: 1 addition & 2 deletions tests/ui/panics/panic-handler-chain.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//@ run-pass
//@ needs-unwind
//@ needs-threads
#![allow(stable_features)]

//@ ignore-emscripten no threads support

#![feature(std_panic)]

use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/panics/panic-task-name-none.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ run-fail
//@ error-pattern:thread '<unnamed>' panicked
//@ error-pattern:test
//@ ignore-emscripten Needs threads
//@ needs-threads

use std::thread;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/panics/panic-task-name-owned.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ run-fail
//@ error-pattern:thread 'owned name' panicked
//@ error-pattern:test
//@ ignore-emscripten Needs threads.
//@ needs-threads

use std::thread::Builder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/fortanix/rust-sgx/issues/109

//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

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

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/process-termination/process-termination-simple.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// program should terminate when std::process::exit is called from any thread

//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

use std::{process, thread};

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/structs-enums/ivec-tag.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;
use std::sync::mpsc::{channel, Sender};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test-attrs/test-filter-multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ run-flags: --test-threads=1 test1 test2
//@ check-run-results
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ ignore-emscripten no threads support
//@ needs-threads

#[test]
fn test1() {}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test-attrs/test-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ run-flags: --test-threads=1
//@ check-run-results
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ ignore-emscripten no threads support
//@ needs-threads
//@ run-pass

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/thread-local/tls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
//@ compile-flags: -O
//@ ignore-nto Doesn't work without emulated TLS enabled (in LLVM)

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/child-outlives-parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Reported as issue #126, child leaks the string.

//@ pretty-expanded FIXME #23616
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/clone-with-exterior.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ run-pass

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

use std::thread;

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/threads-sendsync/comm.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads

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

pub fn main() {
let (tx, rx) = channel();
let t = thread::spawn(move|| { child(&tx) });
let t = thread::spawn(move || { child(&tx) });
let y = rx.recv().unwrap();
println!("received");
println!("{}", y);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/eprint-on-tls-drop.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no processes
//@ needs-threads
//@ ignore-sgx no processes

use std::cell::RefCell;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/issue-24313.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads
//@ needs-threads
//@ ignore-sgx no processes

use std::thread;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/issue-29488.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/issue-43733-2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ ignore-wasm32
//@ needs-threads
//@ dont-check-compiler-stderr
#![feature(cfg_target_thread_local, thread_local_internals)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/issue-43733.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ ignore-wasm32
//@ needs-threads
#![feature(thread_local)]
#![feature(cfg_target_thread_local, thread_local_internals)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/issue-4446.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

use std::sync::mpsc::channel;
use std::thread;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/issue-4448.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

use std::sync::mpsc::channel;
use std::thread;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/issue-8827.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;
use std::sync::mpsc::{channel, Receiver};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/issue-9396.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ run-pass
#![allow(unused_must_use)]
#![allow(deprecated)]
//@ ignore-emscripten no threads support
//@ needs-threads

use std::sync::mpsc::{TryRecvError, channel};
use std::thread;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/mpsc_stress.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ run-pass
//@ compile-flags:--test
//@ ignore-emscripten
//@ needs-threads

use std::sync::mpsc::channel;
use std::sync::mpsc::TryRecvError;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/send-resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(non_camel_case_types)]

//@ pretty-expanded FIXME #23616
//@ ignore-emscripten no threads support
//@ needs-threads

use std::thread;
use std::sync::mpsc::channel;
Expand Down
Loading

0 comments on commit 5642b04

Please sign in to comment.