compiletest: add {ignore,needs}-{rustc,std}-debug-assertions directive support

And retire the old `only-debug` directive which was ambiguous and only
for std debug assertions.
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-10-19 10:13:13 +08:00
parent 4d296eabe4
commit 65b986b94d
6 changed files with 77 additions and 9 deletions

View File

@ -236,8 +236,11 @@ pub struct Config {
/// Run ignored tests
pub run_ignored: bool,
/// Whether to run tests with `ignore-debug` header
pub with_debug_assertions: bool,
/// Whether rustc was built with debug assertions.
pub with_rustc_debug_assertions: bool,
/// Whether std was built with debug assertions.
pub with_std_debug_assertions: bool,
/// Only run tests that match these filters
pub filters: Vec<String>,

View File

@ -45,7 +45,6 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"ignore-coverage-map",
"ignore-coverage-run",
"ignore-cross-compile",
"ignore-debug",
"ignore-eabi",
"ignore-emscripten",
"ignore-endian-big",
@ -81,6 +80,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"ignore-powerpc",
"ignore-remote",
"ignore-riscv64",
"ignore-rustc-debug-assertions",
"ignore-s390x",
"ignore-sgx",
"ignore-sparc64",
@ -88,6 +88,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"ignore-stable",
"ignore-stage1",
"ignore-stage2",
"ignore-std-debug-assertions",
"ignore-test",
"ignore-thumb",
"ignore-thumbv8m.base-none-eabi",
@ -134,6 +135,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"needs-relocation-model-pic",
"needs-run-enabled",
"needs-rust-lld",
"needs-rustc-debug-assertions",
"needs-sanitizer-address",
"needs-sanitizer-cfi",
"needs-sanitizer-dataflow",
@ -146,6 +148,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"needs-sanitizer-shadow-call-stack",
"needs-sanitizer-support",
"needs-sanitizer-thread",
"needs-std-debug-assertions",
"needs-symlink",
"needs-threads",
"needs-unwind",

View File

@ -202,9 +202,14 @@ pub(super) fn parse_cfg_name_directive<'a>(
message: "when running tests remotely",
}
condition! {
name: "debug",
condition: config.with_debug_assertions,
message: "when running tests with `ignore-debug` header",
name: "rustc-debug-assertions",
condition: config.with_rustc_debug_assertions,
message: "when rustc is built with debug assertions",
}
condition! {
name: "std-debug-assertions",
condition: config.with_std_debug_assertions,
message: "when std is built with debug assertions",
}
condition! {
name: config.debugger.as_ref().map(|d| d.to_str()),

View File

@ -159,6 +159,16 @@ pub(super) fn handle_needs(
condition: cache.llvm_zstd,
ignore_reason: "ignored if LLVM wasn't build with zstd for ELF section compression",
},
Need {
name: "needs-rustc-debug-assertions",
condition: config.with_rustc_debug_assertions,
ignore_reason: "ignored if rustc wasn't built with debug assertions",
},
Need {
name: "needs-std-debug-assertions",
condition: config.with_std_debug_assertions,
ignore_reason: "ignored if std wasn't built with debug assertions",
},
];
let (name, comment) = match ln.split_once([':', ' ']) {

View File

@ -74,6 +74,8 @@ struct ConfigBuilder {
git_hash: bool,
system_llvm: bool,
profiler_runtime: bool,
rustc_debug_assertions: bool,
std_debug_assertions: bool,
}
impl ConfigBuilder {
@ -122,6 +124,16 @@ impl ConfigBuilder {
self
}
fn rustc_debug_assertions(&mut self, is_enabled: bool) -> &mut Self {
self.rustc_debug_assertions = is_enabled;
self
}
fn std_debug_assertions(&mut self, is_enabled: bool) -> &mut Self {
self.std_debug_assertions = is_enabled;
self
}
fn build(&mut self) -> Config {
let args = &[
"compiletest",
@ -169,6 +181,12 @@ impl ConfigBuilder {
if self.profiler_runtime {
args.push("--profiler-runtime".to_owned());
}
if self.rustc_debug_assertions {
args.push("--with-rustc-debug-assertions".to_owned());
}
if self.std_debug_assertions {
args.push("--with-std-debug-assertions".to_owned());
}
args.push("--rustc-path".to_string());
// This is a subtle/fragile thing. On rust-lang CI, there is no global
@ -313,6 +331,32 @@ fn only_target() {
assert!(!check_ignore(&config, "//@ only-64bit"));
}
#[test]
fn rustc_debug_assertions() {
let config: Config = cfg().rustc_debug_assertions(false).build();
assert!(check_ignore(&config, "//@ needs-rustc-debug-assertions"));
assert!(!check_ignore(&config, "//@ ignore-rustc-debug-assertions"));
let config: Config = cfg().rustc_debug_assertions(true).build();
assert!(!check_ignore(&config, "//@ needs-rustc-debug-assertions"));
assert!(check_ignore(&config, "//@ ignore-rustc-debug-assertions"));
}
#[test]
fn std_debug_assertions() {
let config: Config = cfg().std_debug_assertions(false).build();
assert!(check_ignore(&config, "//@ needs-std-debug-assertions"));
assert!(!check_ignore(&config, "//@ ignore-std-debug-assertions"));
let config: Config = cfg().std_debug_assertions(true).build();
assert!(!check_ignore(&config, "//@ needs-std-debug-assertions"));
assert!(check_ignore(&config, "//@ ignore-std-debug-assertions"));
}
#[test]
fn stage() {
let config: Config = cfg().stage_id("stage1-x86_64-unknown-linux-gnu").build();

View File

@ -88,7 +88,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
.optopt("", "run", "whether to execute run-* tests", "auto | always | never")
.optflag("", "ignored", "run tests marked as ignored")
.optflag("", "has-enzyme", "run tests that require enzyme")
.optflag("", "with-debug-assertions", "whether to run tests with `ignore-debug` header")
.optflag("", "with-rustc-debug-assertions", "whether rustc was built with debug assertions")
.optflag("", "with-std-debug-assertions", "whether std was built with debug assertions")
.optmulti(
"",
"skip",
@ -234,7 +235,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
let src_base = opt_path(matches, "src-base");
let run_ignored = matches.opt_present("ignored");
let with_debug_assertions = matches.opt_present("with-debug-assertions");
let with_rustc_debug_assertions = matches.opt_present("with-rustc-debug-assertions");
let with_std_debug_assertions = matches.opt_present("with-std-debug-assertions");
let mode = matches.opt_str("mode").unwrap().parse().expect("invalid mode");
let has_html_tidy = if mode == Mode::Rustdoc {
Command::new("tidy")
@ -292,7 +294,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
suite: matches.opt_str("suite").unwrap(),
debugger: None,
run_ignored,
with_debug_assertions,
with_rustc_debug_assertions,
with_std_debug_assertions,
filters,
skip: matches.opt_strs("skip"),
filter_exact: matches.opt_present("exact"),