Skip to content

Commit 33a0812

Browse files
Rollup merge of rust-lang#112300 - Zalathar:run-coverage, r=wesleywiser
Convert `run-make/coverage-reports` tests to use a custom compiletest mode I was frustrated by the fact that most of the coverage tests are glued together with makefiles and shell scripts, so I tried my hand at converting most of them over to a newly-implemented `run-coverage` mode/suite in compiletest. This ~~*mostly*~~ resolves rust-lang#85009, ~~though I've left a small number of the existing tests as-is because they would require more work to fix/support~~. --- I had time to go back and add support for the more troublesome tests that I had initially skipped over, so this PR now manages to completely get rid of `run-make/coverage-reports`. --- The patches are arranged as follows: - Declare the new mode/suite in bootstrap - Small changes to compiletest that will be used by the new mode - Implement the new mode in compiletest - Migrate most of the tests over - Add more code to bootstrap and compiletest to support the remaining tests - Migrate the remaining tests (with some temporary hacks to avoid re-blessing them) - Remove the temporary hacks and re-bless the migrated tests - Remove the unused remnants of `run-make/coverage-reports`
2 parents 12d4f08 + 7b4e75b commit 33a0812

File tree

109 files changed

+523
-356
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+523
-356
lines changed

src/bootstrap/builder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ impl<'a> Builder<'a> {
686686
test::Tidy,
687687
test::Ui,
688688
test::RunPassValgrind,
689+
test::RunCoverage,
689690
test::MirOpt,
690691
test::Codegen,
691692
test::CodegenUnits,
@@ -694,6 +695,7 @@ impl<'a> Builder<'a> {
694695
test::Debuginfo,
695696
test::UiFullDeps,
696697
test::Rustdoc,
698+
test::RunCoverageRustdoc,
697699
test::Pretty,
698700
test::Crate,
699701
test::CrateLibrustc,

src/bootstrap/test.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,13 @@ host_test!(RunMakeFullDeps {
13191319

13201320
default_test!(Assembly { path: "tests/assembly", mode: "assembly", suite: "assembly" });
13211321

1322+
host_test!(RunCoverage { path: "tests/run-coverage", mode: "run-coverage", suite: "run-coverage" });
1323+
host_test!(RunCoverageRustdoc {
1324+
path: "tests/run-coverage-rustdoc",
1325+
mode: "run-coverage",
1326+
suite: "run-coverage-rustdoc"
1327+
});
1328+
13221329
// For the mir-opt suite we do not use macros, as we need custom behavior when blessing.
13231330
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
13241331
pub struct MirOpt {
@@ -1503,6 +1510,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
15031510
|| (mode == "ui" && is_rustdoc)
15041511
|| mode == "js-doc-test"
15051512
|| mode == "rustdoc-json"
1513+
|| suite == "run-coverage-rustdoc"
15061514
{
15071515
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
15081516
}
@@ -1516,7 +1524,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
15161524
.arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
15171525
}
15181526

1519-
if mode == "run-make" {
1527+
if mode == "run-make" || mode == "run-coverage" {
15201528
let rust_demangler = builder
15211529
.ensure(tool::RustDemangler {
15221530
compiler,
@@ -1703,17 +1711,21 @@ note: if you're sure you want to do this, please open an issue as to why. In the
17031711
add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
17041712
}
17051713

1706-
// Only pass correct values for these flags for the `run-make` suite as it
1707-
// requires that a C++ compiler was configured which isn't always the case.
1708-
if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
1714+
if !builder.config.dry_run()
1715+
&& (matches!(suite, "run-make" | "run-make-fulldeps") || mode == "run-coverage")
1716+
{
17091717
// The llvm/bin directory contains many useful cross-platform
17101718
// tools. Pass the path to run-make tests so they can use them.
1719+
// (The run-coverage tests also need these tools to process
1720+
// coverage reports.)
17111721
let llvm_bin_path = llvm_config
17121722
.parent()
17131723
.expect("Expected llvm-config to be contained in directory");
17141724
assert!(llvm_bin_path.is_dir());
17151725
cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1726+
}
17161727

1728+
if !builder.config.dry_run() && matches!(suite, "run-make" | "run-make-fulldeps") {
17171729
// If LLD is available, add it to the PATH
17181730
if builder.config.lld_enabled {
17191731
let lld_install_root =

src/tools/compiletest/src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ string_enum! {
6666
JsDocTest => "js-doc-test",
6767
MirOpt => "mir-opt",
6868
Assembly => "assembly",
69+
RunCoverage => "run-coverage",
6970
}
7071
}
7172

@@ -626,6 +627,7 @@ pub const UI_EXTENSIONS: &[&str] = &[
626627
UI_STDERR_64,
627628
UI_STDERR_32,
628629
UI_STDERR_16,
630+
UI_COVERAGE,
629631
];
630632
pub const UI_STDERR: &str = "stderr";
631633
pub const UI_STDOUT: &str = "stdout";
@@ -635,6 +637,7 @@ pub const UI_RUN_STDOUT: &str = "run.stdout";
635637
pub const UI_STDERR_64: &str = "64bit.stderr";
636638
pub const UI_STDERR_32: &str = "32bit.stderr";
637639
pub const UI_STDERR_16: &str = "16bit.stderr";
640+
pub const UI_COVERAGE: &str = "coverage";
638641

639642
/// Absolute path to the directory where all output for all tests in the given
640643
/// `relative_dir` group should reside. Example:

src/tools/compiletest/src/header.rs

+40-8
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub struct TestProps {
161161
// customized normalization rules
162162
pub normalize_stdout: Vec<(String, String)>,
163163
pub normalize_stderr: Vec<(String, String)>,
164-
pub failure_status: i32,
164+
pub failure_status: Option<i32>,
165165
// For UI tests, allows compiler to exit with arbitrary failure status
166166
pub dont_check_failure_status: bool,
167167
// Whether or not `rustfix` should apply the `CodeSuggestion`s of this test and compile the
@@ -257,7 +257,7 @@ impl TestProps {
257257
check_test_line_numbers_match: false,
258258
normalize_stdout: vec![],
259259
normalize_stderr: vec![],
260-
failure_status: -1,
260+
failure_status: None,
261261
dont_check_failure_status: false,
262262
run_rustfix: false,
263263
rustfix_only_machine_applicable: false,
@@ -428,7 +428,7 @@ impl TestProps {
428428
.parse_name_value_directive(ln, FAILURE_STATUS)
429429
.and_then(|code| code.trim().parse::<i32>().ok())
430430
{
431-
self.failure_status = code;
431+
self.failure_status = Some(code);
432432
}
433433

434434
config.set_name_directive(
@@ -491,11 +491,8 @@ impl TestProps {
491491
});
492492
}
493493

494-
if self.failure_status == -1 {
495-
self.failure_status = 1;
496-
}
497494
if self.should_ice {
498-
self.failure_status = 101;
495+
self.failure_status = Some(101);
499496
}
500497

501498
if config.mode == Mode::Incremental {
@@ -615,10 +612,25 @@ pub fn line_directive<'line>(
615612
}
616613

617614
fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>, &str, usize)) {
615+
iter_header_extra(testfile, rdr, &[], it)
616+
}
617+
618+
fn iter_header_extra(
619+
testfile: &Path,
620+
rdr: impl Read,
621+
extra_directives: &[&str],
622+
it: &mut dyn FnMut(Option<&str>, &str, usize),
623+
) {
618624
if testfile.is_dir() {
619625
return;
620626
}
621627

628+
// Process any extra directives supplied by the caller (e.g. because they
629+
// are implied by the test mode), with a dummy line number of 0.
630+
for directive in extra_directives {
631+
it(None, directive, 0);
632+
}
633+
622634
let comment = if testfile.extension().map(|e| e == "rs") == Some(true) { "//" } else { "#" };
623635

624636
let mut rdr = BufReader::new(rdr);
@@ -897,7 +909,27 @@ pub fn make_test_description<R: Read>(
897909
let mut ignore_message = None;
898910
let mut should_fail = false;
899911

900-
iter_header(path, src, &mut |revision, ln, line_number| {
912+
let extra_directives: &[&str] = match config.mode {
913+
// The run-coverage tests are treated as having these extra directives,
914+
// without needing to specify them manually in every test file.
915+
// (Some of the comments below have been copied over from
916+
// `tests/run-make/coverage-reports/Makefile`, which no longer exists.)
917+
Mode::RunCoverage => {
918+
&[
919+
"needs-profiler-support",
920+
// FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works
921+
// properly. Since we only have GCC on the CI ignore the test for now.
922+
"ignore-windows-gnu",
923+
// FIXME(pietroalbini): this test currently does not work on cross-compiled
924+
// targets because remote-test is not capable of sending back the *.profraw
925+
// files generated by the LLVM instrumentation.
926+
"ignore-cross-compile",
927+
]
928+
}
929+
_ => &[],
930+
};
931+
932+
iter_header_extra(path, src, extra_directives, &mut |revision, ln, line_number| {
901933
if revision.is_some() && revision != cfg {
902934
return;
903935
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(super) fn handle_needs(
8787
},
8888
Need {
8989
name: "needs-profiler-support",
90-
condition: std::env::var_os("RUSTC_PROFILER_SUPPORT").is_some(),
90+
condition: cache.profiler_support,
9191
ignore_reason: "ignored when profiler support is disabled",
9292
},
9393
Need {
@@ -195,6 +195,7 @@ pub(super) struct CachedNeedsConditions {
195195
sanitizer_memtag: bool,
196196
sanitizer_shadow_call_stack: bool,
197197
sanitizer_safestack: bool,
198+
profiler_support: bool,
198199
xray: bool,
199200
rust_lld: bool,
200201
i686_dlltool: bool,
@@ -232,6 +233,7 @@ impl CachedNeedsConditions {
232233
sanitizer_memtag: util::MEMTAG_SUPPORTED_TARGETS.contains(target),
233234
sanitizer_shadow_call_stack: util::SHADOWCALLSTACK_SUPPORTED_TARGETS.contains(target),
234235
sanitizer_safestack: util::SAFESTACK_SUPPORTED_TARGETS.contains(target),
236+
profiler_support: std::env::var_os("RUSTC_PROFILER_SUPPORT").is_some(),
235237
xray: util::XRAY_SUPPORTED_TARGETS.contains(target),
236238

237239
// For tests using the `needs-rust-lld` directive (e.g. for `-Zgcc-ld=lld`), we need to find

0 commit comments

Comments
 (0)