Skip to content

Commit 65b986b

Browse files
committed
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 4d296ea commit 65b986b

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
@@ -45,7 +45,6 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
4545
"ignore-coverage-map",
4646
"ignore-coverage-run",
4747
"ignore-cross-compile",
48-
"ignore-debug",
4948
"ignore-eabi",
5049
"ignore-emscripten",
5150
"ignore-endian-big",
@@ -81,13 +80,15 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
8180
"ignore-powerpc",
8281
"ignore-remote",
8382
"ignore-riscv64",
83+
"ignore-rustc-debug-assertions",
8484
"ignore-s390x",
8585
"ignore-sgx",
8686
"ignore-sparc64",
8787
"ignore-spirv",
8888
"ignore-stable",
8989
"ignore-stage1",
9090
"ignore-stage2",
91+
"ignore-std-debug-assertions",
9192
"ignore-test",
9293
"ignore-thumb",
9394
"ignore-thumbv8m.base-none-eabi",
@@ -134,6 +135,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
134135
"needs-relocation-model-pic",
135136
"needs-run-enabled",
136137
"needs-rust-lld",
138+
"needs-rustc-debug-assertions",
137139
"needs-sanitizer-address",
138140
"needs-sanitizer-cfi",
139141
"needs-sanitizer-dataflow",
@@ -146,6 +148,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
146148
"needs-sanitizer-shadow-call-stack",
147149
"needs-sanitizer-support",
148150
"needs-sanitizer-thread",
151+
"needs-std-debug-assertions",
149152
"needs-symlink",
150153
"needs-threads",
151154
"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",
@@ -169,6 +181,12 @@ impl ConfigBuilder {
169181
if self.profiler_runtime {
170182
args.push("--profiler-runtime".to_owned());
171183
}
184+
if self.rustc_debug_assertions {
185+
args.push("--with-rustc-debug-assertions".to_owned());
186+
}
187+
if self.std_debug_assertions {
188+
args.push("--with-std-debug-assertions".to_owned());
189+
}
172190

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

334+
#[test]
335+
fn rustc_debug_assertions() {
336+
let config: Config = cfg().rustc_debug_assertions(false).build();
337+
338+
assert!(check_ignore(&config, "//@ needs-rustc-debug-assertions"));
339+
assert!(!check_ignore(&config, "//@ ignore-rustc-debug-assertions"));
340+
341+
let config: Config = cfg().rustc_debug_assertions(true).build();
342+
343+
assert!(!check_ignore(&config, "//@ needs-rustc-debug-assertions"));
344+
assert!(check_ignore(&config, "//@ ignore-rustc-debug-assertions"));
345+
}
346+
347+
#[test]
348+
fn std_debug_assertions() {
349+
let config: Config = cfg().std_debug_assertions(false).build();
350+
351+
assert!(check_ignore(&config, "//@ needs-std-debug-assertions"));
352+
assert!(!check_ignore(&config, "//@ ignore-std-debug-assertions"));
353+
354+
let config: Config = cfg().std_debug_assertions(true).build();
355+
356+
assert!(!check_ignore(&config, "//@ needs-std-debug-assertions"));
357+
assert!(check_ignore(&config, "//@ ignore-std-debug-assertions"));
358+
}
359+
316360
#[test]
317361
fn stage() {
318362
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",
@@ -234,7 +235,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
234235

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

0 commit comments

Comments
 (0)