Rollup merge of #122109 - alexcrichton:compiletests-needs-threads, r=workingjubilee

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:
Matthias Krüger 2024-03-07 00:57:43 +01:00 committed by GitHub
commit 5642b04186
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
77 changed files with 109 additions and 76 deletions

View File

@ -451,6 +451,15 @@ pub fn can_unwind(&self) -> bool {
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",

View File

@ -787,6 +787,7 @@ pub fn line_directive<'line>(
"needs-sanitizer-shadow-call-stack",
"needs-sanitizer-support",
"needs-sanitizer-thread",
"needs-threads",
"needs-unwind",
"needs-xray",
"no-prefer-dynamic",

View File

@ -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(),

View File

@ -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)
}
}

View File

@ -1,4 +1,4 @@
//@ ignore-wasm32-bare compiled with panic=abort by default
//@ needs-unwind
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
//

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
#![feature(rustc_private)]
extern crate libc;

View File

@ -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;

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
#![feature(rustc_private)]

View File

@ -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;

View File

@ -7,8 +7,7 @@
// optimisation.
//@ pretty-expanded FIXME #23616
//@ ignore-emscripten no threads support
//@ needs-threads
#![feature(intrinsics)]
use std::{mem, thread};

View File

@ -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

View File

@ -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)]

View File

@ -5,7 +5,7 @@
// that use capture clauses.
//@ pretty-expanded FIXME #23616
//@ ignore-emscripten no threads support
//@ needs-threads
extern crate cci_capture_clause;

View File

@ -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.

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_variables)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;
use std::mem;

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
// Regression test for unwrapping the result of `join`, issue #21291

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
pub fn main() {
let f = || || 0;

View File

@ -1,6 +1,6 @@
//@ edition:2018
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;
use std::time::Duration;

View File

@ -1,6 +1,6 @@
//@ run-pass
//@ ignore-windows
//@ ignore-emscripten no threads support
//@ needs-threads
use std::cell::Cell;
use std::fmt;

View File

@ -1,7 +1,7 @@
//@ run-pass
//@ compile-flags: -C lto
//@ no-prefer-dynamic
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -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};

View File

@ -1,7 +1,7 @@
//@ run-fail
//@ error-pattern:thread '<unnamed>' panicked
//@ error-pattern:test
//@ ignore-emscripten Needs threads
//@ needs-threads
use std::thread;

View File

@ -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;

View File

@ -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};

View File

@ -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};

View File

@ -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};

View File

@ -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() {}

View File

@ -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]

View File

@ -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)

View File

@ -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;

View File

@ -1,7 +1,7 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -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);

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no processes
//@ needs-threads
//@ ignore-sgx no processes
use std::cell::RefCell;

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads
//@ needs-threads
//@ ignore-sgx no processes
use std::thread;

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -1,4 +1,4 @@
//@ ignore-wasm32
//@ needs-threads
//@ dont-check-compiler-stderr
#![feature(cfg_target_thread_local, thread_local_internals)]

View File

@ -1,4 +1,4 @@
//@ ignore-wasm32
//@ needs-threads
#![feature(thread_local)]
#![feature(cfg_target_thread_local, thread_local_internals)]

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
use std::sync::mpsc::channel;
use std::thread;

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
use std::sync::mpsc::channel;
use std::thread;

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;
use std::sync::mpsc::{channel, Receiver};

View File

@ -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;

View File

@ -1,6 +1,6 @@
//@ run-pass
//@ compile-flags:--test
//@ ignore-emscripten
//@ needs-threads
use std::sync::mpsc::channel;
use std::sync::mpsc::TryRecvError;

View File

@ -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;

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -1,7 +1,7 @@
//@ run-pass
#![allow(non_camel_case_types)]
//@ ignore-emscripten no threads support
//@ needs-threads
/*
Make sure we can spawn tasks that take different types of

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -3,7 +3,7 @@
#![allow(unused_mut)]
//@ ignore-windows
//@ exec-env:RUST_LOG=debug
//@ ignore-emscripten no threads support
//@ needs-threads
// regression test for issue #10405, make sure we don't call println! too soon.

View File

@ -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};

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -1,7 +1,7 @@
//@ run-pass
#![allow(unused_must_use)]
#![allow(unused_mut)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;
use std::sync::mpsc::{channel, Sender};

View File

@ -1,7 +1,7 @@
//@ run-pass
#![allow(unused_must_use)]
//@ pretty-expanded FIXME #23616
//@ ignore-emscripten no threads support
//@ needs-threads
use std::sync::mpsc::{channel, Sender};
use std::thread;

View File

@ -1,7 +1,7 @@
//@ run-pass
#![allow(unused_must_use)]
#![allow(unused_mut)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_variables)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::sync::mpsc::{channel, Sender};
use std::thread;

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_parens)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::sync::mpsc::{channel, Sender};
use std::thread;

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
//@ pretty-expanded FIXME #23616
use std::sync::mpsc::{channel, Sender};

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
//@ pretty-expanded FIXME #23616
// Issue #922

View File

@ -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};

View File

@ -1,7 +1,7 @@
//@ run-pass
#![allow(unused_must_use)]
#![allow(unused_assignments)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::sync::mpsc::{channel, Sender};
use std::thread;

View File

@ -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};

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
//@ pretty-expanded FIXME #23616
use std::thread;

View File

@ -1,6 +1,6 @@
//@ run-fail
//@ error-pattern:Ensure that the child thread runs by panicking
//@ ignore-emscripten Needs threads.
//@ needs-threads
use std::thread;

View File

@ -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;

View File

@ -1,5 +1,5 @@
//@ run-pass
//@ ignore-emscripten no threads support
//@ needs-threads
//@ needs-unwind
#![feature(internal_output_capture)]

View File

@ -1,6 +1,6 @@
//@ run-pass
//@ ignore-android needs extra network permissions
//@ ignore-emscripten no threads or sockets support
//@ needs-threads
//@ ignore-netbsd system ulimit (Too many open files)
//@ ignore-openbsd system ulimit (Too many open files)

View File

@ -5,7 +5,7 @@
//@ error-pattern:should be a positive integer
//@ compile-flags: --test
//@ exec-env:RUST_TEST_THREADS=foo
//@ ignore-emscripten
//@ needs-threads
#[test]
fn do_nothing() {}

View File

@ -1,6 +1,6 @@
//@ run-pass
#![allow(unused_must_use)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -1,6 +1,6 @@
//@ run-pass
//@ no-prefer-dynamic
//@ ignore-emscripten no threads support
//@ needs-threads
static mut HIT: bool = false;

View File

@ -1,7 +1,7 @@
//@ run-pass
#![allow(stable_features)]
//@ ignore-emscripten no threads support
//@ needs-threads
#![feature(thread_local_try_with)]

View File

@ -1,7 +1,7 @@
//@ run-pass
#![allow(stable_features)]
//@ ignore-emscripten no threads support
//@ needs-threads
#![feature(thread_local_try_with)]

View File

@ -2,7 +2,7 @@
//@ needs-unwind
#![allow(non_camel_case_types)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::sync::mpsc::{channel, Sender};
use std::thread;

View File

@ -2,7 +2,7 @@
#![allow(unused_must_use)]
#![allow(unused_mut)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -2,7 +2,7 @@
#![allow(unused_must_use)]
#![allow(unused_mut)]
//@ ignore-emscripten no threads support
//@ needs-threads
use std::thread;

View File

@ -3,7 +3,7 @@
// Tests that a heterogeneous list of existential `dyn` types can be put inside an Arc
// and shared between threads as long as all types fulfill Send.
//@ ignore-emscripten no threads support
//@ needs-threads
use std::sync::Arc;
use std::sync::mpsc::channel;