@@ -6,8 +6,8 @@ use crate::common::{Assembly, Incremental, JsDocTest, MirOpt, RunMake, RustdocJs
6
6
use crate :: common:: { Codegen , CodegenUnits , DebugInfo , Debugger , Rustdoc } ;
7
7
use crate :: common:: { CompareMode , FailMode , PassMode } ;
8
8
use crate :: common:: { Config , TestPaths } ;
9
- use crate :: common:: { Pretty , RunCoverage , RunPassValgrind } ;
10
- use crate :: common:: { UI_COVERAGE , UI_RUN_STDERR , UI_RUN_STDOUT } ;
9
+ use crate :: common:: { CoverageMap , Pretty , RunCoverage , RunPassValgrind } ;
10
+ use crate :: common:: { UI_COVERAGE , UI_COVERAGE_MAP , UI_RUN_STDERR , UI_RUN_STDOUT } ;
11
11
use crate :: compute_diff:: { write_diff, write_filtered_diff} ;
12
12
use crate :: errors:: { self , Error , ErrorKind } ;
13
13
use crate :: header:: TestProps ;
@@ -254,6 +254,7 @@ impl<'test> TestCx<'test> {
254
254
MirOpt => self . run_mir_opt_test ( ) ,
255
255
Assembly => self . run_assembly_test ( ) ,
256
256
JsDocTest => self . run_js_doc_test ( ) ,
257
+ CoverageMap => self . run_coverage_map_test ( ) ,
257
258
RunCoverage => self . run_coverage_test ( ) ,
258
259
}
259
260
}
@@ -467,6 +468,46 @@ impl<'test> TestCx<'test> {
467
468
}
468
469
}
469
470
471
+ fn run_coverage_map_test ( & self ) {
472
+ let Some ( coverage_dump_path) = & self . config . coverage_dump_path else {
473
+ self . fatal ( "missing --coverage-dump" ) ;
474
+ } ;
475
+
476
+ let proc_res = self . compile_test_and_save_ir ( ) ;
477
+ if !proc_res. status . success ( ) {
478
+ self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
479
+ }
480
+ drop ( proc_res) ;
481
+
482
+ let llvm_ir_path = self . output_base_name ( ) . with_extension ( "ll" ) ;
483
+
484
+ let mut dump_command = Command :: new ( coverage_dump_path) ;
485
+ dump_command. arg ( llvm_ir_path) ;
486
+ let proc_res = self . run_command_to_procres ( & mut dump_command) ;
487
+ if !proc_res. status . success ( ) {
488
+ self . fatal_proc_rec ( "coverage-dump failed!" , & proc_res) ;
489
+ }
490
+
491
+ let kind = UI_COVERAGE_MAP ;
492
+
493
+ let expected_coverage_dump = self . load_expected_output ( kind) ;
494
+ let actual_coverage_dump = self . normalize_output ( & proc_res. stdout , & [ ] ) ;
495
+
496
+ let coverage_dump_errors = self . compare_output (
497
+ kind,
498
+ & actual_coverage_dump,
499
+ & expected_coverage_dump,
500
+ self . props . compare_output_lines_by_subset ,
501
+ ) ;
502
+
503
+ if coverage_dump_errors > 0 {
504
+ self . fatal_proc_rec (
505
+ & format ! ( "{coverage_dump_errors} errors occurred comparing coverage output." ) ,
506
+ & proc_res,
507
+ ) ;
508
+ }
509
+ }
510
+
470
511
fn run_coverage_test ( & self ) {
471
512
let should_run = self . run_if_enabled ( ) ;
472
513
let proc_res = self . compile_test ( should_run, Emit :: None ) ;
@@ -650,6 +691,10 @@ impl<'test> TestCx<'test> {
650
691
let mut cmd = Command :: new ( tool_path) ;
651
692
configure_cmd_fn ( & mut cmd) ;
652
693
694
+ self . run_command_to_procres ( & mut cmd)
695
+ }
696
+
697
+ fn run_command_to_procres ( & self , cmd : & mut Command ) -> ProcRes {
653
698
let output = cmd. output ( ) . unwrap_or_else ( |_| panic ! ( "failed to exec `{cmd:?}`" ) ) ;
654
699
655
700
let proc_res = ProcRes {
@@ -2321,9 +2366,11 @@ impl<'test> TestCx<'test> {
2321
2366
}
2322
2367
}
2323
2368
DebugInfo => { /* debuginfo tests must be unoptimized */ }
2324
- RunCoverage => {
2325
- // Coverage reports are affected by optimization level, and
2326
- // the current snapshots assume no optimization by default.
2369
+ CoverageMap | RunCoverage => {
2370
+ // Coverage mappings and coverage reports are affected by
2371
+ // optimization level, so they ignore the optimize-tests
2372
+ // setting and set an optimization level in their mode's
2373
+ // compile flags (below) or in per-test `compile-flags`.
2327
2374
}
2328
2375
_ => {
2329
2376
rustc. arg ( "-O" ) ;
@@ -2392,8 +2439,22 @@ impl<'test> TestCx<'test> {
2392
2439
2393
2440
rustc. arg ( dir_opt) ;
2394
2441
}
2442
+ CoverageMap => {
2443
+ rustc. arg ( "-Cinstrument-coverage" ) ;
2444
+ // These tests only compile to MIR, so they don't need the
2445
+ // profiler runtime to be present.
2446
+ rustc. arg ( "-Zno-profiler-runtime" ) ;
2447
+ // Coverage mappings are sensitive to MIR optimizations, and
2448
+ // the current snapshots assume `opt-level=2` unless overridden
2449
+ // by `compile-flags`.
2450
+ rustc. arg ( "-Copt-level=2" ) ;
2451
+ }
2395
2452
RunCoverage => {
2396
2453
rustc. arg ( "-Cinstrument-coverage" ) ;
2454
+ // Coverage reports are sometimes sensitive to optimizations,
2455
+ // and the current snapshots assume no optimization unless
2456
+ // overridden by `compile-flags`.
2457
+ rustc. arg ( "-Copt-level=0" ) ;
2397
2458
}
2398
2459
RunPassValgrind | Pretty | DebugInfo | Codegen | Rustdoc | RustdocJson | RunMake
2399
2460
| CodegenUnits | JsDocTest | Assembly => {
0 commit comments