Skip to content

Commit 08c3545

Browse files
committed
Auto merge of rust-lang#117484 - Zalathar:tests, r=Mark-Simulacrum
coverage: Unify `tests/coverage-map` and `tests/run-coverage` into `tests/coverage` Ever since the introduction of the `coverage-map` suite, it's been awkward to have to manage two separate coverage test directories containing dozens of mostly-identical files. However, those two suites were separate for good reasons. They have very different requirements (since only one of them requires actually running the test program), running only one suite is noticeably faster than running both, and having separate suites allows them to be blessed separately if desired. So while unifying them was an obvious idea, actually doing so was non-trivial. --- Nevertheless, this PR finds a way to merge the two suites into one directory while retaining almost all of the developer-experience benefits of having two suites. This required non-trivial implementations of `Step`, but the end result works very smoothly. --- The first 5 commits are a copy of rust-lang#117340, which is a necessary prerequisite, though they can be reviewed directly as part of this PR if desired.
2 parents f81d6f0 + 523997b commit 08c3545

File tree

206 files changed

+436
-2386
lines changed

Some content is hidden

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

206 files changed

+436
-2386
lines changed

src/bootstrap/src/core/build_steps/test.rs

+100-6
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,47 @@ macro_rules! test_definitions {
13051305
};
13061306
}
13071307

1308+
/// Declares an alias for running the [`Coverage`] tests in only one mode.
1309+
/// Adapted from [`test_definitions`].
1310+
macro_rules! coverage_test_alias {
1311+
($name:ident {
1312+
alias_and_mode: $alias_and_mode:expr,
1313+
default: $default:expr,
1314+
only_hosts: $only_hosts:expr $(,)?
1315+
}) => {
1316+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1317+
pub struct $name {
1318+
pub compiler: Compiler,
1319+
pub target: TargetSelection,
1320+
}
1321+
1322+
impl $name {
1323+
const MODE: &'static str = $alias_and_mode;
1324+
}
1325+
1326+
impl Step for $name {
1327+
type Output = ();
1328+
const DEFAULT: bool = $default;
1329+
const ONLY_HOSTS: bool = $only_hosts;
1330+
1331+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1332+
run.alias($alias_and_mode)
1333+
}
1334+
1335+
fn make_run(run: RunConfig<'_>) {
1336+
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1337+
1338+
run.builder.ensure($name { compiler, target: run.target });
1339+
}
1340+
1341+
fn run(self, builder: &Builder<'_>) {
1342+
Coverage { compiler: self.compiler, target: self.target }
1343+
.run_unified_suite(builder, Self::MODE)
1344+
}
1345+
}
1346+
};
1347+
}
1348+
13081349
default_test!(Ui { path: "tests/ui", mode: "ui", suite: "ui" });
13091350

13101351
default_test!(RunPassValgrind {
@@ -1349,13 +1390,66 @@ host_test!(RunMakeFullDeps {
13491390

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

1352-
default_test!(CoverageMap {
1353-
path: "tests/coverage-map",
1354-
mode: "coverage-map",
1355-
suite: "coverage-map"
1393+
/// Custom test step that is responsible for running the coverage tests
1394+
/// in multiple different modes.
1395+
///
1396+
/// Each individual mode also has its own alias that will run the tests in
1397+
/// just that mode.
1398+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1399+
pub struct Coverage {
1400+
pub compiler: Compiler,
1401+
pub target: TargetSelection,
1402+
}
1403+
1404+
impl Coverage {
1405+
const PATH: &'static str = "tests/coverage";
1406+
const SUITE: &'static str = "coverage";
1407+
1408+
fn run_unified_suite(&self, builder: &Builder<'_>, mode: &'static str) {
1409+
builder.ensure(Compiletest {
1410+
compiler: self.compiler,
1411+
target: self.target,
1412+
mode,
1413+
suite: Self::SUITE,
1414+
path: Self::PATH,
1415+
compare_mode: None,
1416+
})
1417+
}
1418+
}
1419+
1420+
impl Step for Coverage {
1421+
type Output = ();
1422+
const DEFAULT: bool = false;
1423+
const ONLY_HOSTS: bool = false;
1424+
1425+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1426+
run.suite_path(Self::PATH)
1427+
}
1428+
1429+
fn make_run(run: RunConfig<'_>) {
1430+
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1431+
1432+
run.builder.ensure(Coverage { compiler, target: run.target });
1433+
}
1434+
1435+
fn run(self, builder: &Builder<'_>) {
1436+
self.run_unified_suite(builder, CoverageMap::MODE);
1437+
self.run_unified_suite(builder, RunCoverage::MODE);
1438+
}
1439+
}
1440+
1441+
// Aliases for running the coverage tests in only one mode.
1442+
coverage_test_alias!(CoverageMap {
1443+
alias_and_mode: "coverage-map",
1444+
default: true,
1445+
only_hosts: false,
1446+
});
1447+
coverage_test_alias!(RunCoverage {
1448+
alias_and_mode: "run-coverage",
1449+
default: true,
1450+
only_hosts: true,
13561451
});
13571452

1358-
host_test!(RunCoverage { path: "tests/run-coverage", mode: "run-coverage", suite: "run-coverage" });
13591453
host_test!(RunCoverageRustdoc {
13601454
path: "tests/run-coverage-rustdoc",
13611455
mode: "run-coverage",
@@ -1581,7 +1675,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
15811675
cmd.arg("--rust-demangler-path").arg(rust_demangler);
15821676
}
15831677

1584-
cmd.arg("--src-base").arg(builder.src.join("tests").join(suite));
1678+
cmd.arg("--src-base").arg(builder.src.join(suite_path));
15851679
cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
15861680

15871681
// When top stage is 0, that means that we're testing an externally provided compiler.

src/bootstrap/src/core/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ impl<'a> Builder<'a> {
727727
test::Tidy,
728728
test::Ui,
729729
test::RunPassValgrind,
730+
test::Coverage,
730731
test::CoverageMap,
731732
test::RunCoverage,
732733
test::MirOpt,

src/tools/compiletest/src/common.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,23 @@ impl Default for Mode {
7878
}
7979

8080
impl Mode {
81-
pub fn disambiguator(self) -> &'static str {
81+
pub fn aux_dir_disambiguator(self) -> &'static str {
8282
// Pretty-printing tests could run concurrently, and if they do,
8383
// they need to keep their output segregated.
8484
match self {
8585
Pretty => ".pretty",
8686
_ => "",
8787
}
8888
}
89+
90+
pub fn output_dir_disambiguator(self) -> &'static str {
91+
// Coverage tests use the same test files for multiple test modes,
92+
// so each mode should have a separate output directory.
93+
match self {
94+
CoverageMap | RunCoverage => self.to_str(),
95+
_ => "",
96+
}
97+
}
8998
}
9099

91100
string_enum! {
@@ -699,6 +708,7 @@ pub fn output_testname_unique(
699708
let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
700709
let debugger = config.debugger.as_ref().map_or("", |m| m.to_str());
701710
PathBuf::from(&testpaths.file.file_stem().unwrap())
711+
.with_extra_extension(config.mode.output_dir_disambiguator())
702712
.with_extra_extension(revision.unwrap_or(""))
703713
.with_extra_extension(mode)
704714
.with_extra_extension(debugger)

src/tools/compiletest/src/runtest.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ impl<'test> TestCx<'test> {
21932193
|| self.is_vxworks_pure_static()
21942194
|| self.config.target.contains("bpf")
21952195
|| !self.config.target_cfg().dynamic_linking
2196-
|| self.config.mode == RunCoverage
2196+
|| matches!(self.config.mode, CoverageMap | RunCoverage)
21972197
{
21982198
// We primarily compile all auxiliary libraries as dynamic libraries
21992199
// to avoid code size bloat and large binaries as much as possible
@@ -2481,9 +2481,9 @@ impl<'test> TestCx<'test> {
24812481
RunCoverage => {
24822482
rustc.arg("-Cinstrument-coverage");
24832483
// Coverage reports are sometimes sensitive to optimizations,
2484-
// and the current snapshots assume no optimization unless
2484+
// and the current snapshots assume `opt-level=2` unless
24852485
// overridden by `compile-flags`.
2486-
rustc.arg("-Copt-level=0");
2486+
rustc.arg("-Copt-level=2");
24872487
}
24882488
RunPassValgrind | Pretty | DebugInfo | Codegen | Rustdoc | RustdocJson | RunMake
24892489
| CodegenUnits | JsDocTest | Assembly => {
@@ -2720,7 +2720,7 @@ impl<'test> TestCx<'test> {
27202720
fn aux_output_dir_name(&self) -> PathBuf {
27212721
self.output_base_dir()
27222722
.join("auxiliary")
2723-
.with_extra_extension(self.config.mode.disambiguator())
2723+
.with_extra_extension(self.config.mode.aux_dir_disambiguator())
27242724
}
27252725

27262726
/// Generates a unique name for the test, such as `testname.revision.mode`.

tests/coverage-map/README.md

-13
This file was deleted.

tests/coverage-map/if.cov-map

-15
This file was deleted.

tests/coverage-map/if.rs

-9
This file was deleted.

tests/coverage-map/status-quo/overflow.rs

-63
This file was deleted.

tests/coverage-map/status-quo/sort_groups.rs

-23
This file was deleted.

tests/coverage/README.md

+16
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/coverage/issue-85461.cov-map

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Function name: issue_85461::main
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 08, 01, 03, 02]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 0
6+
Number of file 0 mappings: 1
7+
- Code(Counter(0)) at (prev + 8, 1) to (start + 3, 2)
8+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)