Skip to content

Commit

Permalink
Rollup merge of #84734 - tmandry:compiletest-needs-unwind, r=Mark-Sim…
Browse files Browse the repository at this point in the history
…ulacrum

Add `needs-unwind` and beginning of support for testing `panic=abort` std to compiletest

For the Fuchsia platform we build libstd with `panic=abort` and would like a way to run tests with that enabled. This adds low-level support for this directly to compiletest.

In the future I'd like to add high-level support in rustbuild, e.g. having target-specific flags that allow configuring a panic strategy. (Side note: It would be nice if we could also build multiple configurations for the same target, but I'm getting ahead of myself.)

This plus #84500 have everything that's needed to get ui tests passing on fuchsia targets.

Part of #84766. Note that this change only includes the header on tests which need an unwinder to _build_, not those which need it to _run_.

r? ````@Mark-Simulacrum````
  • Loading branch information
Dylan-DPC committed May 6, 2021
2 parents 3a0d6be + 947ad58 commit 577f1d0
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/test/ui/cfg/cfg-panic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// build-pass
// compile-flags: -C panic=unwind
// needs-unwind
// ignore-emscripten no panic_unwind implementation
// ignore-wasm32 no panic_unwind implementation
// ignore-wasm64 no panic_unwind implementation
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/intrinsics/intrinsic-alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod rusti {
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-70093.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// run-pass
// compile-flags: -Zlink-native-libraries=no -Cdefault-linker-libraries=yes
// ignore-windows - this will probably only work on unixish systems
// ignore-fuchsia - missing __libc_start_main for some reason (#84733)

#[link(name = "some-random-non-existent-library", kind = "static")]
extern "C" {}
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/panic-handler/weak-lang-item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// aux-build:weak-lang-items.rs
// error-pattern: `#[panic_handler]` function required, but not found
// error-pattern: language item required, but not found: `eh_personality`
// needs-unwind since it affects the error output
// ignore-emscripten compiled with panic=abort, personality not required

#![no_std]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/panic-handler/weak-lang-item.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0259]: the name `core` is defined multiple times
--> $DIR/weak-lang-item.rs:8:1
--> $DIR/weak-lang-item.rs:9:1
|
LL | extern crate core;
| ^^^^^^^^^^^^^^^^^^ `core` reimported here
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/panic-runtime/abort-link-to-unwind-dylib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// build-fail
// compile-flags:-C panic=abort -C prefer-dynamic
// needs-unwind
// ignore-musl - no dylibs here
// ignore-emscripten
// ignore-sgx no dynamic lib support
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/panic-runtime/lto-unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(unused_variables)]

// compile-flags:-C lto -C panic=unwind
// needs-unwind
// no-prefer-dynamic
// ignore-emscripten no processes
// ignore-sgx no processes
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/panic-runtime/transitive-link-a-bunch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// build-fail
// needs-unwind
// aux-build:panic-runtime-unwind.rs
// aux-build:panic-runtime-abort.rs
// aux-build:wants-panic-runtime-unwind.rs
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/panic-runtime/want-unwind-got-abort.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// build-fail
// needs-unwind
// error-pattern:is incompatible with this crate's strategy of `unwind`
// aux-build:panic-runtime-abort.rs
// aux-build:panic-runtime-lang-items.rs
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/panic-runtime/want-unwind-got-abort2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// build-fail
// needs-unwind
// error-pattern:is incompatible with this crate's strategy of `unwind`
// aux-build:panic-runtime-abort.rs
// aux-build:wants-panic-runtime-abort.rs
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/structs-enums/rec-align-u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct Outer {
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/test-panic-abort-disabled.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// error-pattern:building tests with panic=abort is not supported
// no-prefer-dynamic
// compile-flags: --test -Cpanic=abort
// compile-flags: --test -Cpanic=abort -Zpanic-abort-tests=no
// run-flags: --test-threads=1

// ignore-wasm no panic or subprocess support
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/unwind-no-uwtable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-pass
// needs-unwind
// ignore-windows target requires uwtable
// ignore-wasm32-bare no proper panic=unwind support
// compile-flags: -C panic=unwind -C force-unwind-tables=n
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/x86stdcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn main() {
target_os = "dragonfly",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
Expand Down
10 changes: 10 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ impl fmt::Display for Debugger {
}
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum PanicStrategy {
Unwind,
Abort,
}

/// Configuration for compiletest
#[derive(Debug, Clone)]
pub struct Config {
Expand Down Expand Up @@ -265,6 +271,10 @@ pub struct Config {
/// Flags to pass to the compiler when building for the target
pub target_rustcflags: Option<String>,

/// What panic strategy the target is built with. Unwind supports Abort, but
/// not vice versa.
pub target_panic: PanicStrategy,

/// Target system to be tested
pub target: String,

Expand Down
8 changes: 7 additions & 1 deletion src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};

use tracing::*;

use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PassMode};
use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PanicStrategy, PassMode};
use crate::util;
use crate::{extract_cdb_version, extract_gdb_version};

Expand Down Expand Up @@ -115,6 +115,12 @@ impl EarlyProps {
props.ignore = true;
}

if config.target_panic == PanicStrategy::Abort
&& config.parse_name_directive(ln, "needs-unwind")
{
props.ignore = true;
}

if config.target == "wasm32-unknown-unknown" && config.parse_check_run_results(ln) {
props.ignore = true;
}
Expand Down
18 changes: 13 additions & 5 deletions src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

extern crate test;

use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
use crate::common::{
expected_output_path, output_base_dir, output_relative_path, PanicStrategy, UI_EXTENSIONS,
};
use crate::common::{CompareMode, Config, Debugger, Mode, PassMode, Pretty, TestPaths};
use crate::util::logv;
use getopts::Options;
Expand Down Expand Up @@ -97,8 +99,9 @@ pub fn parse_config(args: Vec<String>) -> Config {
(eg. emulator, valgrind)",
"PROGRAM",
)
.optopt("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
.optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
.optmulti("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
.optmulti("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
.optopt("", "target-panic", "what panic strategy the target supports", "unwind | abort")
.optflag("", "verbose", "run tests verbosely, showing all output")
.optflag(
"",
Expand Down Expand Up @@ -243,8 +246,13 @@ pub fn parse_config(args: Vec<String>) -> Config {
}),
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
runtool: matches.opt_str("runtool"),
host_rustcflags: matches.opt_str("host-rustcflags"),
target_rustcflags: matches.opt_str("target-rustcflags"),
host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
target_panic: match matches.opt_str("target-panic").as_deref() {
Some("unwind") | None => PanicStrategy::Unwind,
Some("abort") => PanicStrategy::Abort,
_ => panic!("unknown `--target-panic` option `{}` given", mode),
},
target,
host: opt_str2(matches.opt_str("host")),
cdb,
Expand Down

0 comments on commit 577f1d0

Please sign in to comment.