Skip to content

Commit dd3747b

Browse files
authored
Rollup merge of #84500 - tmandry:compiletest-run-flag, r=Mark-Simulacrum
Add --run flag to compiletest This controls whether run-* tests actually get run. r? ```@Mark-Simulacrum```
2 parents b30e428 + 1e46b18 commit dd3747b

File tree

9 files changed

+93
-16
lines changed

9 files changed

+93
-16
lines changed

Diff for: src/bootstrap/builder/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ mod dist {
489489
compare_mode: None,
490490
rustfix_coverage: false,
491491
pass: None,
492+
run: None,
492493
};
493494

494495
let build = Build::new(config);
@@ -529,6 +530,7 @@ mod dist {
529530
compare_mode: None,
530531
rustfix_coverage: false,
531532
pass: None,
533+
run: None,
532534
};
533535

534536
let build = Build::new(config);
@@ -584,6 +586,7 @@ mod dist {
584586
compare_mode: None,
585587
rustfix_coverage: false,
586588
pass: None,
589+
run: None,
587590
};
588591
// Make sure rustfmt binary not being found isn't an error.
589592
config.channel = "beta".to_string();

Diff for: src/bootstrap/flags.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub enum Subcommand {
103103
bless: bool,
104104
compare_mode: Option<String>,
105105
pass: Option<String>,
106+
run: Option<String>,
106107
test_args: Vec<String>,
107108
rustc_args: Vec<String>,
108109
fail_fast: bool,
@@ -222,8 +223,8 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
222223
VALUE overrides the skip-rebuild option in config.toml.",
223224
"VALUE",
224225
);
225-
opts.optopt("", "rust-profile-generate", "rustc error format", "FORMAT");
226-
opts.optopt("", "rust-profile-use", "rustc error format", "FORMAT");
226+
opts.optopt("", "rust-profile-generate", "generate PGO profile with rustc build", "FORMAT");
227+
opts.optopt("", "rust-profile-use", "use PGO profile for rustc build", "FORMAT");
227228

228229
// We can't use getopt to parse the options until we have completed specifying which
229230
// options are valid, but under the current implementation, some options are conditional on
@@ -293,6 +294,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
293294
"force {check,build,run}-pass tests to this mode.",
294295
"check | build | run",
295296
);
297+
opts.optopt("", "run", "whether to execute run-* tests", "auto | always | never");
296298
opts.optflag(
297299
"",
298300
"rustfix-coverage",
@@ -556,6 +558,7 @@ Arguments:
556558
bless: matches.opt_present("bless"),
557559
compare_mode: matches.opt_str("compare-mode"),
558560
pass: matches.opt_str("pass"),
561+
run: matches.opt_str("run"),
559562
test_args: matches.opt_strs("test-args"),
560563
rustc_args: matches.opt_strs("rustc-args"),
561564
fail_fast: !matches.opt_present("no-fail-fast"),
@@ -742,6 +745,13 @@ impl Subcommand {
742745
}
743746
}
744747

748+
pub fn run(&self) -> Option<&str> {
749+
match *self {
750+
Subcommand::Test { ref run, .. } => run.as_ref().map(|s| &s[..]),
751+
_ => None,
752+
}
753+
}
754+
745755
pub fn open(&self) -> bool {
746756
match *self {
747757
Subcommand::Doc { open, .. } => open,

Diff for: src/bootstrap/test.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,11 @@ note: if you're sure you want to do this, please open an issue as to why. In the
12401240
cmd.arg(pass);
12411241
}
12421242

1243+
if let Some(ref run) = builder.config.cmd.run() {
1244+
cmd.arg("--run");
1245+
cmd.arg(run);
1246+
}
1247+
12431248
if let Some(ref nodejs) = builder.config.nodejs {
12441249
cmd.arg("--nodejs").arg(nodejs);
12451250
}

Diff for: src/test/debuginfo/should-fail.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// == Test [gdb|lldb]-[command|check] are parsed correctly ===
44
// should-fail
5+
// needs-run-enabled
56
// compile-flags:-g
67

78
// === GDB TESTS ===================================================================================

Diff for: src/test/ui/meta/revision-bad.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// run-fail
55
// revisions: foo bar
66
// should-fail
7+
// needs-run-enabled
78
//[foo] error-pattern:bar
89
//[bar] error-pattern:foo
910

Diff for: src/tools/compiletest/src/common.rs

+12
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ pub struct Config {
249249
/// Force the pass mode of a check/build/run-pass test to this mode.
250250
pub force_pass_mode: Option<PassMode>,
251251

252+
/// Explicitly enable or disable running.
253+
pub run: Option<bool>,
254+
252255
/// Write out a parseable log of tests that were run
253256
pub logfile: Option<PathBuf>,
254257

@@ -348,6 +351,15 @@ pub struct Config {
348351
pub npm: Option<String>,
349352
}
350353

354+
impl Config {
355+
pub fn run_enabled(&self) -> bool {
356+
self.run.unwrap_or_else(|| {
357+
// Auto-detect whether to run based on the platform.
358+
!self.target.ends_with("-fuchsia")
359+
})
360+
}
361+
}
362+
351363
#[derive(Debug, Clone)]
352364
pub struct TestPaths {
353365
pub file: PathBuf, // e.g., compile-test/foo/bar/baz.rs

Diff for: src/tools/compiletest/src/header.rs

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ impl EarlyProps {
8585
props.ignore = true;
8686
}
8787

88+
if !config.run_enabled() && config.parse_name_directive(ln, "needs-run-enabled") {
89+
props.ignore = true;
90+
}
91+
8892
if !rustc_has_sanitizer_support
8993
&& config.parse_name_directive(ln, "needs-sanitizer-support")
9094
{

Diff for: src/tools/compiletest/src/main.rs

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
8787
"force {check,build,run}-pass tests to this mode.",
8888
"check | build | run",
8989
)
90+
.optopt("", "run", "whether to execute run-* tests", "auto | always | never")
9091
.optflag("", "ignored", "run tests marked as ignored")
9192
.optflag("", "exact", "filters match exactly")
9293
.optopt(
@@ -234,6 +235,12 @@ pub fn parse_config(args: Vec<String>) -> Config {
234235
mode.parse::<PassMode>()
235236
.unwrap_or_else(|_| panic!("unknown `--pass` option `{}` given", mode))
236237
}),
238+
run: matches.opt_str("run").and_then(|mode| match mode.as_str() {
239+
"auto" => None,
240+
"always" => Some(true),
241+
"never" => Some(false),
242+
_ => panic!("unknown `--run` option `{}` given", mode),
243+
}),
237244
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
238245
runtool: matches.opt_str("runtool"),
239246
host_rustcflags: matches.opt_str("host-rustcflags"),

Diff for: src/tools/compiletest/src/runtest.rs

+48-14
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) {
259259
pub fn compute_stamp_hash(config: &Config) -> String {
260260
let mut hash = DefaultHasher::new();
261261
config.stage_id.hash(&mut hash);
262+
config.run.hash(&mut hash);
262263

263264
match config.debugger {
264265
Some(Debugger::Cdb) => {
@@ -317,6 +318,7 @@ enum TestOutput {
317318
enum WillExecute {
318319
Yes,
319320
No,
321+
Disabled,
320322
}
321323

322324
/// Should `--emit metadata` be used?
@@ -357,14 +359,17 @@ impl<'test> TestCx<'test> {
357359
}
358360

359361
fn should_run(&self, pm: Option<PassMode>) -> WillExecute {
360-
match self.config.mode {
361-
Ui if pm == Some(PassMode::Run) || self.props.fail_mode == Some(FailMode::Run) => {
362-
WillExecute::Yes
363-
}
364-
MirOpt if pm == Some(PassMode::Run) => WillExecute::Yes,
365-
Ui | MirOpt => WillExecute::No,
362+
let test_should_run = match self.config.mode {
363+
Ui if pm == Some(PassMode::Run) || self.props.fail_mode == Some(FailMode::Run) => true,
364+
MirOpt if pm == Some(PassMode::Run) => true,
365+
Ui | MirOpt => false,
366366
mode => panic!("unimplemented for mode {:?}", mode),
367-
}
367+
};
368+
if test_should_run { self.run_if_enabled() } else { WillExecute::No }
369+
}
370+
371+
fn run_if_enabled(&self) -> WillExecute {
372+
if self.config.run_enabled() { WillExecute::Yes } else { WillExecute::Disabled }
368373
}
369374

370375
fn should_run_successfully(&self, pm: Option<PassMode>) -> bool {
@@ -439,12 +444,17 @@ impl<'test> TestCx<'test> {
439444

440445
fn run_rfail_test(&self) {
441446
let pm = self.pass_mode();
442-
let proc_res = self.compile_test(WillExecute::Yes, self.should_emit_metadata(pm));
447+
let should_run = self.run_if_enabled();
448+
let proc_res = self.compile_test(should_run, self.should_emit_metadata(pm));
443449

444450
if !proc_res.status.success() {
445451
self.fatal_proc_rec("compilation failed!", &proc_res);
446452
}
447453

454+
if let WillExecute::Disabled = should_run {
455+
return;
456+
}
457+
448458
let proc_res = self.exec_compiled_test();
449459

450460
// The value our Makefile configures valgrind to return on failure
@@ -483,12 +493,17 @@ impl<'test> TestCx<'test> {
483493

484494
fn run_rpass_test(&self) {
485495
let emit_metadata = self.should_emit_metadata(self.pass_mode());
486-
let proc_res = self.compile_test(WillExecute::Yes, emit_metadata);
496+
let should_run = self.run_if_enabled();
497+
let proc_res = self.compile_test(should_run, emit_metadata);
487498

488499
if !proc_res.status.success() {
489500
self.fatal_proc_rec("compilation failed!", &proc_res);
490501
}
491502

503+
if let WillExecute::Disabled = should_run {
504+
return;
505+
}
506+
492507
// FIXME(#41968): Move this check to tidy?
493508
let expected_errors = errors::load_errors(&self.testpaths.file, self.revision);
494509
assert!(
@@ -510,12 +525,17 @@ impl<'test> TestCx<'test> {
510525
return self.run_rpass_test();
511526
}
512527

513-
let mut proc_res = self.compile_test(WillExecute::Yes, EmitMetadata::No);
528+
let should_run = self.run_if_enabled();
529+
let mut proc_res = self.compile_test(should_run, EmitMetadata::No);
514530

515531
if !proc_res.status.success() {
516532
self.fatal_proc_rec("compilation failed!", &proc_res);
517533
}
518534

535+
if let WillExecute::Disabled = should_run {
536+
return;
537+
}
538+
519539
let mut new_config = self.config.clone();
520540
new_config.runtool = new_config.valgrind_path.clone();
521541
let new_cx = TestCx { config: &new_config, ..*self };
@@ -732,10 +752,14 @@ impl<'test> TestCx<'test> {
732752

733753
fn run_debuginfo_cdb_test_no_opt(&self) {
734754
// compile test file (it should have 'compile-flags:-g' in the header)
735-
let compile_result = self.compile_test(WillExecute::Yes, EmitMetadata::No);
755+
let should_run = self.run_if_enabled();
756+
let compile_result = self.compile_test(should_run, EmitMetadata::No);
736757
if !compile_result.status.success() {
737758
self.fatal_proc_rec("compilation failed!", &compile_result);
738759
}
760+
if let WillExecute::Disabled = should_run {
761+
return;
762+
}
739763

740764
let exe_file = self.make_exe_name();
741765

@@ -826,10 +850,14 @@ impl<'test> TestCx<'test> {
826850
let mut cmds = commands.join("\n");
827851

828852
// compile test file (it should have 'compile-flags:-g' in the header)
829-
let compiler_run_result = self.compile_test(WillExecute::Yes, EmitMetadata::No);
853+
let should_run = self.run_if_enabled();
854+
let compiler_run_result = self.compile_test(should_run, EmitMetadata::No);
830855
if !compiler_run_result.status.success() {
831856
self.fatal_proc_rec("compilation failed!", &compiler_run_result);
832857
}
858+
if let WillExecute::Disabled = should_run {
859+
return;
860+
}
833861

834862
let exe_file = self.make_exe_name();
835863

@@ -1044,10 +1072,14 @@ impl<'test> TestCx<'test> {
10441072

10451073
fn run_debuginfo_lldb_test_no_opt(&self) {
10461074
// compile test file (it should have 'compile-flags:-g' in the header)
1047-
let compile_result = self.compile_test(WillExecute::Yes, EmitMetadata::No);
1075+
let should_run = self.run_if_enabled();
1076+
let compile_result = self.compile_test(should_run, EmitMetadata::No);
10481077
if !compile_result.status.success() {
10491078
self.fatal_proc_rec("compilation failed!", &compile_result);
10501079
}
1080+
if let WillExecute::Disabled = should_run {
1081+
return;
1082+
}
10511083

10521084
let exe_file = self.make_exe_name();
10531085

@@ -1531,7 +1563,9 @@ impl<'test> TestCx<'test> {
15311563
// Only use `make_exe_name` when the test ends up being executed.
15321564
let output_file = match will_execute {
15331565
WillExecute::Yes => TargetLocation::ThisFile(self.make_exe_name()),
1534-
WillExecute::No => TargetLocation::ThisDirectory(self.output_base_dir()),
1566+
WillExecute::No | WillExecute::Disabled => {
1567+
TargetLocation::ThisDirectory(self.output_base_dir())
1568+
}
15351569
};
15361570

15371571
let allow_unused = match self.config.mode {

0 commit comments

Comments
 (0)