mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
dc2ffa4054
Test wasm32-wasip1 in CI, not wasm32-unknown-unknown This commit changes CI to no longer test the `wasm32-unknown-unknown` target and instead test the `wasm32-wasip1` target. There was some discussion of this in a [Zulip thread], and the motivations for this PR are: * Runtime failures on `wasm32-unknown-unknown` print nothing, meaning all you get is "something failed". In contrast `wasm32-wasip1` can print to stdout/stderr. * The unknown-unknown target is missing lots of pieces of libstd, and while `wasm32-wasip1` is also missing some pieces (e.g. threads) it's missing fewer pieces. This means that many more tests can be run. Overall my hope is to improve the debuggability of wasm failures on CI and ideally be a bit less of a maintenance burden. This commit specifically removes the testing of `wasm32-unknown-unknown` and replaces it with testing of `wasm32-wasip1`. Along the way there were a number of other archiectural changes made as well, including: * A new `target.*.runtool` option can now be specified in `config.toml` which is passed as `--runtool` to `compiletest`. This is used to reimplement execution of WebAssembly in a less-wasm-specific fashion. * The default value for `runtool` is an ambiently located WebAssembly runtime found on the system, if any. I've implemented logic for Wasmtime. * Existing testing support for `wasm32-unknown-unknown` and Emscripten has been removed. I'm not aware of Emscripten testing being run any time recently and otherwise `wasm32-wasip1` is in theory the focus now. * I've added a new `//@ needs-threads` directive for `compiletest` and classified a bunch of wasm-ignored tests as needing threads. In theory these tests can run on `wasm32-wasi-preview1-threads`, for example. * I've tried to audit all existing tests that are either `ignore-emscripten` or `ignore-wasm*`. Many now run on `wasm32-wasip1` due to being able to emit error messages, for example. Many are updated with comments as to why they can't run as well. * The `compiletest` output matching for `wasm32-wasip1` automatically uses "match a subset" mode implemented in `compiletest`. This is because WebAssembly runtimes often add extra information on failure, such as the `unreachable` instruction in `panic!`, which isn't able to be matched against the golden output from native platforms. * I've ported most existing `run-make` tests that use custom Node.js wrapper scripts to the new run-make-based-in-Rust infrastructure. To do this I added `wasmparser` as a dependency of `run-make-support` for the various wasm tests to use that parse wasm files. The one test that executed WebAssembly now uses `wasmtime`-the-CLI to execute the test instead. I have not ported over an exception-handling test as Wasmtime doesn't implement this yet. * I've updated the `test` crate to print out timing information for WASI targets as it can do that (gets a previously ignored test now passing). * The `test-various` image now builds a WASI sysroot for the WASI target and additionally downloads a fixed release of Wasmtime, currently the latest one at 18.0.2, and uses that for testing. [Zulip thread]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Have.20wasm.20tests.20ever.20caused.20problems.20on.20CI.3F/near/424317944
102 lines
2.4 KiB
Rust
102 lines
2.4 KiB
Rust
//@ run-pass
|
|
//@ revisions: current next
|
|
//@ ignore-compare-mode-next-solver (explicit revisions)
|
|
//@[next] compile-flags: -Znext-solver
|
|
|
|
#![allow(unused_must_use)]
|
|
#![feature(c_unwind)]
|
|
#![feature(panic_always_abort)]
|
|
// Since we mark some ABIs as "nounwind" to LLVM, we must make sure that
|
|
// we never unwind through them.
|
|
|
|
//@ ignore-wasm32 no processes
|
|
//@ ignore-sgx no processes
|
|
|
|
use std::io;
|
|
use std::io::prelude::*;
|
|
use std::process::{exit, Command, Stdio};
|
|
use std::sync::{Arc, Barrier};
|
|
use std::thread;
|
|
use std::{env, panic};
|
|
|
|
extern "C" fn panic_in_ffi() {
|
|
panic!("Test");
|
|
}
|
|
|
|
fn should_have_aborted() {
|
|
io::stdout().write(b"This should never be printed.\n");
|
|
let _ = io::stdout().flush();
|
|
}
|
|
|
|
fn bomb_out_but_not_abort(msg: &str) {
|
|
eprintln!("bombing out: {}", msg);
|
|
exit(1);
|
|
}
|
|
|
|
fn test() {
|
|
let _ = panic::catch_unwind(|| {
|
|
panic_in_ffi();
|
|
});
|
|
should_have_aborted();
|
|
}
|
|
|
|
fn test_always_abort() {
|
|
panic::always_abort();
|
|
let _ = panic::catch_unwind(|| {
|
|
panic!();
|
|
});
|
|
should_have_aborted();
|
|
}
|
|
|
|
fn test_always_abort_thread() {
|
|
let barrier = Arc::new(Barrier::new(2));
|
|
let thr = {
|
|
let barrier = barrier.clone();
|
|
thread::spawn(move || {
|
|
barrier.wait();
|
|
panic!("in thread");
|
|
})
|
|
};
|
|
panic::always_abort();
|
|
barrier.wait();
|
|
let _ = thr.join();
|
|
bomb_out_but_not_abort("joined - but we were supposed to panic!");
|
|
}
|
|
|
|
fn main() {
|
|
let tests: &[(_, fn())] = &[
|
|
("test", test),
|
|
("test_always_abort", test_always_abort),
|
|
("test_always_abort_thread", test_always_abort_thread),
|
|
];
|
|
|
|
let args: Vec<String> = env::args().collect();
|
|
if args.len() > 1 {
|
|
// This is inside the self-executed command.
|
|
for (a, f) in tests {
|
|
if &args[1] == a {
|
|
return f();
|
|
}
|
|
}
|
|
bomb_out_but_not_abort("bad test");
|
|
}
|
|
|
|
let execute_self_expecting_abort = |arg| {
|
|
let mut p = Command::new(&args[0])
|
|
.stdout(Stdio::piped())
|
|
.stdin(Stdio::piped())
|
|
.arg(arg)
|
|
.spawn()
|
|
.unwrap();
|
|
let status = p.wait().unwrap();
|
|
assert!(!status.success());
|
|
// Any reasonable platform can distinguish a process which
|
|
// called exit(1) from one which panicked.
|
|
assert_ne!(status.code(), Some(1));
|
|
};
|
|
|
|
for (a, _f) in tests {
|
|
execute_self_expecting_abort(a);
|
|
}
|
|
}
|