Detect panic strategy using rustc --print cfg

Instead of relying on a command line parameter, detect if a target
is able to unwind or not.
Ignore tests that require unwinding on targets that don't support it.
This commit is contained in:
Florian Bartels 2022-09-22 12:40:37 +02:00
parent 9279c547c7
commit 7bfbaa3881
3 changed files with 17 additions and 16 deletions

View file

@ -278,10 +278,6 @@ pub struct Config {
/// override this setting.
pub optimize_tests: bool,
/// 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,
@ -426,6 +422,10 @@ impl Config {
*&self.target_cfg().pointer_width
}
pub fn can_unwind(&self) -> bool {
self.target_cfg().panic == PanicStrategy::Unwind
}
pub fn has_asm_support(&self) -> bool {
static ASM_SUPPORTED_ARCHS: &[&str] = &[
"x86", "x86_64", "arm", "aarch64", "riscv32",
@ -446,6 +446,7 @@ pub struct TargetCfg {
families: Vec<String>,
pointer_width: u32,
endian: Endian,
panic: PanicStrategy,
}
#[derive(Eq, PartialEq, Clone, Debug)]
@ -481,6 +482,7 @@ impl TargetCfg {
let mut families = Vec::new();
let mut pointer_width = None;
let mut endian = None;
let mut panic = None;
for line in print_cfg.lines() {
if let Some((name, value)) = line.split_once('=') {
let value = value.trim_matches('"');
@ -498,6 +500,13 @@ impl TargetCfg {
s => panic!("unexpected {s}"),
})
}
"panic" => {
panic = match value {
"abort" => Some(PanicStrategy::Abort),
"unwind" => Some(PanicStrategy::Unwind),
s => panic!("unexpected {s}"),
}
}
_ => {}
}
}
@ -510,6 +519,7 @@ impl TargetCfg {
families,
pointer_width: pointer_width.unwrap(),
endian: endian.unwrap(),
panic: panic.unwrap(),
}
}
}

View file

@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
use tracing::*;
use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PanicStrategy, PassMode};
use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PassMode};
use crate::util;
use crate::{extract_cdb_version, extract_gdb_version};
@ -949,8 +949,7 @@ pub fn make_test_description<R: Read>(
ignore |= !has_memtag && config.parse_name_directive(ln, "needs-sanitizer-memtag");
ignore |= !has_shadow_call_stack
&& config.parse_name_directive(ln, "needs-sanitizer-shadow-call-stack");
ignore |= config.target_panic == PanicStrategy::Abort
&& config.parse_name_directive(ln, "needs-unwind");
ignore |= !config.can_unwind() && config.parse_name_directive(ln, "needs-unwind");
ignore |= config.target == "wasm32-unknown-unknown"
&& config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS);
ignore |= config.debugger == Some(Debugger::Cdb) && ignore_cdb(config, ln);

View file

@ -5,9 +5,7 @@
extern crate test;
use crate::common::{
expected_output_path, output_base_dir, output_relative_path, PanicStrategy, UI_EXTENSIONS,
};
use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
use crate::common::{CompareMode, Config, Debugger, Mode, PassMode, TestPaths};
use crate::util::logv;
use getopts::Options;
@ -105,7 +103,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
.optmulti("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
.optmulti("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
.optflag("", "optimize-tests", "run tests with optimizations enabled")
.optopt("", "target-panic", "what panic strategy the target supports", "unwind | abort")
.optflag("", "verbose", "run tests verbosely, showing all output")
.optflag(
"",
@ -258,11 +255,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
optimize_tests: matches.opt_present("optimize-tests"),
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,