Skip to content

Commit 012c7eb

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 93742bd commit 012c7eb

File tree

6 files changed

+77
-9
lines changed

6 files changed

+77
-9
lines changed

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

+4-1
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/common.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,11 @@ pub struct Config {
235235
/// Run ignored tests
236236
pub run_ignored: bool,
237237

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

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

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

+8-3
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

+10
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

+44
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ struct ConfigBuilder {
7070
git_hash: bool,
7171
system_llvm: bool,
7272
profiler_runtime: bool,
73+
rustc_debug_assertions: bool,
74+
std_debug_assertions: bool,
7375
}
7476

7577
impl ConfigBuilder {
@@ -118,6 +120,16 @@ impl ConfigBuilder {
118120
self
119121
}
120122

123+
fn rustc_debug_assertions(&mut self, is_enabled: bool) -> &mut Self {
124+
self.rustc_debug_assertions = is_enabled;
125+
self
126+
}
127+
128+
fn std_debug_assertions(&mut self, is_enabled: bool) -> &mut Self {
129+
self.std_debug_assertions = is_enabled;
130+
self
131+
}
132+
121133
fn build(&mut self) -> Config {
122134
let args = &[
123135
"compiletest",
@@ -165,6 +177,12 @@ impl ConfigBuilder {
165177
if self.profiler_runtime {
166178
args.push("--profiler-runtime".to_owned());
167179
}
180+
if self.rustc_debug_assertions {
181+
args.push("--with-rustc-debug-assertions".to_owned());
182+
}
183+
if self.std_debug_assertions {
184+
args.push("--with-std-debug-assertions".to_owned());
185+
}
168186

169187
args.push("--rustc-path".to_string());
170188
// This is a subtle/fragile thing. On rust-lang CI, there is no global
@@ -309,6 +327,32 @@ fn only_target() {
309327
assert!(!check_ignore(&config, "//@ only-64bit"));
310328
}
311329

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

src/tools/compiletest/src/lib.rs

+6-3
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",
@@ -228,7 +229,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
228229

229230
let src_base = opt_path(matches, "src-base");
230231
let run_ignored = matches.opt_present("ignored");
231-
let with_debug_assertions = matches.opt_present("with-debug-assertions");
232+
let with_rustc_debug_assertions = matches.opt_present("with-rustc-debug-assertions");
233+
let with_std_debug_assertions = matches.opt_present("with-std-debug-assertions");
232234
let mode = matches.opt_str("mode").unwrap().parse().expect("invalid mode");
233235
let has_html_tidy = if mode == Mode::Rustdoc {
234236
Command::new("tidy")
@@ -286,7 +288,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
286288
suite: matches.opt_str("suite").unwrap(),
287289
debugger: None,
288290
run_ignored,
289-
with_debug_assertions,
291+
with_rustc_debug_assertions,
292+
with_std_debug_assertions,
290293
filters,
291294
skip: matches.opt_strs("skip"),
292295
filter_exact: matches.opt_present("exact"),

0 commit comments

Comments
 (0)