Skip to content

Commit 9949a8d

Browse files
jieyouxuJakob-Koschel
authored andcommitted
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.
1 parent e665843 commit 9949a8d

File tree

6 files changed

+77
-9
lines changed

6 files changed

+77
-9
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,11 @@ pub struct Config {
236236
/// Run ignored tests
237237
pub run_ignored: bool,
238238

239-
/// Whether to run tests with `ignore-debug` header
240-
pub with_debug_assertions: bool,
239+
/// Whether rustc was built with debug assertions.
240+
pub with_rustc_debug_assertions: bool,
241+
242+
/// Whether std was built with debug assertions.
243+
pub with_std_debug_assertions: bool,
241244

242245
/// Only run tests that match these filters
243246
pub filters: Vec<String>,

src/tools/compiletest/src/directive-list.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
4646
"ignore-coverage-map",
4747
"ignore-coverage-run",
4848
"ignore-cross-compile",
49-
"ignore-debug",
5049
"ignore-eabi",
5150
"ignore-emscripten",
5251
"ignore-endian-big",
@@ -82,13 +81,15 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
8281
"ignore-powerpc",
8382
"ignore-remote",
8483
"ignore-riscv64",
84+
"ignore-rustc-debug-assertions",
8585
"ignore-s390x",
8686
"ignore-sgx",
8787
"ignore-sparc64",
8888
"ignore-spirv",
8989
"ignore-stable",
9090
"ignore-stage1",
9191
"ignore-stage2",
92+
"ignore-std-debug-assertions",
9293
"ignore-test",
9394
"ignore-thumb",
9495
"ignore-thumbv8m.base-none-eabi",
@@ -135,6 +136,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
135136
"needs-relocation-model-pic",
136137
"needs-run-enabled",
137138
"needs-rust-lld",
139+
"needs-rustc-debug-assertions",
138140
"needs-sanitizer-address",
139141
"needs-sanitizer-cfi",
140142
"needs-sanitizer-dataflow",
@@ -147,6 +149,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
147149
"needs-sanitizer-shadow-call-stack",
148150
"needs-sanitizer-support",
149151
"needs-sanitizer-thread",
152+
"needs-std-debug-assertions",
150153
"needs-symlink",
151154
"needs-threads",
152155
"needs-unwind",

src/tools/compiletest/src/header/cfg.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,14 @@ pub(super) fn parse_cfg_name_directive<'a>(
202202
message: "when running tests remotely",
203203
}
204204
condition! {
205-
name: "debug",
206-
condition: config.with_debug_assertions,
207-
message: "when running tests with `ignore-debug` header",
205+
name: "rustc-debug-assertions",
206+
condition: config.with_rustc_debug_assertions,
207+
message: "when rustc is built with debug assertions",
208+
}
209+
condition! {
210+
name: "std-debug-assertions",
211+
condition: config.with_std_debug_assertions,
212+
message: "when std is built with debug assertions",
208213
}
209214
condition! {
210215
name: config.debugger.as_ref().map(|d| d.to_str()),

src/tools/compiletest/src/header/needs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ pub(super) fn handle_needs(
159159
condition: cache.llvm_zstd,
160160
ignore_reason: "ignored if LLVM wasn't build with zstd for ELF section compression",
161161
},
162+
Need {
163+
name: "needs-rustc-debug-assertions",
164+
condition: config.with_rustc_debug_assertions,
165+
ignore_reason: "ignored if rustc wasn't built with debug assertions",
166+
},
167+
Need {
168+
name: "needs-std-debug-assertions",
169+
condition: config.with_std_debug_assertions,
170+
ignore_reason: "ignored if std wasn't built with debug assertions",
171+
},
162172
];
163173

164174
let (name, comment) = match ln.split_once([':', ' ']) {

src/tools/compiletest/src/header/tests.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ struct ConfigBuilder {
7474
git_hash: bool,
7575
system_llvm: bool,
7676
profiler_runtime: bool,
77+
rustc_debug_assertions: bool,
78+
std_debug_assertions: bool,
7779
}
7880

7981
impl ConfigBuilder {
@@ -122,6 +124,16 @@ impl ConfigBuilder {
122124
self
123125
}
124126

127+
fn rustc_debug_assertions(&mut self, is_enabled: bool) -> &mut Self {
128+
self.rustc_debug_assertions = is_enabled;
129+
self
130+
}
131+
132+
fn std_debug_assertions(&mut self, is_enabled: bool) -> &mut Self {
133+
self.std_debug_assertions = is_enabled;
134+
self
135+
}
136+
125137
fn build(&mut self) -> Config {
126138
let args = &[
127139
"compiletest",
@@ -170,6 +182,12 @@ impl ConfigBuilder {
170182
if self.profiler_runtime {
171183
args.push("--profiler-runtime".to_owned());
172184
}
185+
if self.rustc_debug_assertions {
186+
args.push("--with-rustc-debug-assertions".to_owned());
187+
}
188+
if self.std_debug_assertions {
189+
args.push("--with-std-debug-assertions".to_owned());
190+
}
173191

174192
args.push("--rustc-path".to_string());
175193
// This is a subtle/fragile thing. On rust-lang CI, there is no global
@@ -314,6 +332,32 @@ fn only_target() {
314332
assert!(!check_ignore(&config, "//@ only-64bit"));
315333
}
316334

335+
#[test]
336+
fn rustc_debug_assertions() {
337+
let config: Config = cfg().rustc_debug_assertions(false).build();
338+
339+
assert!(check_ignore(&config, "//@ needs-rustc-debug-assertions"));
340+
assert!(!check_ignore(&config, "//@ ignore-rustc-debug-assertions"));
341+
342+
let config: Config = cfg().rustc_debug_assertions(true).build();
343+
344+
assert!(!check_ignore(&config, "//@ needs-rustc-debug-assertions"));
345+
assert!(check_ignore(&config, "//@ ignore-rustc-debug-assertions"));
346+
}
347+
348+
#[test]
349+
fn std_debug_assertions() {
350+
let config: Config = cfg().std_debug_assertions(false).build();
351+
352+
assert!(check_ignore(&config, "//@ needs-std-debug-assertions"));
353+
assert!(!check_ignore(&config, "//@ ignore-std-debug-assertions"));
354+
355+
let config: Config = cfg().std_debug_assertions(true).build();
356+
357+
assert!(!check_ignore(&config, "//@ needs-std-debug-assertions"));
358+
assert!(check_ignore(&config, "//@ ignore-std-debug-assertions"));
359+
}
360+
317361
#[test]
318362
fn stage() {
319363
let config: Config = cfg().stage_id("stage1-x86_64-unknown-linux-gnu").build();

src/tools/compiletest/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
8888
.optopt("", "run", "whether to execute run-* tests", "auto | always | never")
8989
.optflag("", "ignored", "run tests marked as ignored")
9090
.optflag("", "has-enzyme", "run tests that require enzyme")
91-
.optflag("", "with-debug-assertions", "whether to run tests with `ignore-debug` header")
91+
.optflag("", "with-rustc-debug-assertions", "whether rustc was built with debug assertions")
92+
.optflag("", "with-std-debug-assertions", "whether std was built with debug assertions")
9293
.optmulti(
9394
"",
9495
"skip",
@@ -235,7 +236,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
235236

236237
let src_base = opt_path(matches, "src-base");
237238
let run_ignored = matches.opt_present("ignored");
238-
let with_debug_assertions = matches.opt_present("with-debug-assertions");
239+
let with_rustc_debug_assertions = matches.opt_present("with-rustc-debug-assertions");
240+
let with_std_debug_assertions = matches.opt_present("with-std-debug-assertions");
239241
let mode = matches.opt_str("mode").unwrap().parse().expect("invalid mode");
240242
let has_html_tidy = if mode == Mode::Rustdoc {
241243
Command::new("tidy")
@@ -293,7 +295,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
293295
suite: matches.opt_str("suite").unwrap(),
294296
debugger: None,
295297
run_ignored,
296-
with_debug_assertions,
298+
with_rustc_debug_assertions,
299+
with_std_debug_assertions,
297300
filters,
298301
skip: matches.opt_strs("skip"),
299302
filter_exact: matches.opt_present("exact"),

0 commit comments

Comments
 (0)