diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index e82b88eef79..070a014afa8 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -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, diff --git a/src/tools/compiletest/src/directive-list.rs b/src/tools/compiletest/src/directive-list.rs index 4d57907f26f..b7a171e02b5 100644 --- a/src/tools/compiletest/src/directive-list.rs +++ b/src/tools/compiletest/src/directive-list.rs @@ -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", diff --git a/src/tools/compiletest/src/header/cfg.rs b/src/tools/compiletest/src/header/cfg.rs index b9314f0abbb..3ab552903dc 100644 --- a/src/tools/compiletest/src/header/cfg.rs +++ b/src/tools/compiletest/src/header/cfg.rs @@ -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()), diff --git a/src/tools/compiletest/src/header/needs.rs b/src/tools/compiletest/src/header/needs.rs index a744fb61b9c..77570c58db5 100644 --- a/src/tools/compiletest/src/header/needs.rs +++ b/src/tools/compiletest/src/header/needs.rs @@ -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([':', ' ']) { diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 2e6effcab98..4b35bbee08b 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -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(); diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs index ccf8057bf5c..d171bf67a44 100644 --- a/src/tools/compiletest/src/lib.rs +++ b/src/tools/compiletest/src/lib.rs @@ -88,7 +88,8 @@ pub fn parse_config(args: Vec) -> 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) -> 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) -> 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"),