rust/tests/coverage
Michael Goulet bacddd3e5d
Rollup merge of #119208 - Zalathar:hoist, r=WaffleLapkin,Swatinem
coverage: Hoist some complex code out of the main span refinement loop

The span refinement loop in `spans.rs` takes the spans that have been extracted from MIR, and modifies them to produce more helpful output in coverage reports.

It is also one of the most complicated pieces of code in the coverage instrumentor. It has an abundance of moving pieces that make it difficult to understand, and most attempts to modify it end up accidentally changing its behaviour in unacceptable ways.

This PR nevertheless tries to make a dent in it by hoisting two pieces of special-case logic out of the main loop, and into separate preprocessing passes. Coverage tests show that the resulting mappings are *almost* identical, with all known differences being unimportant.

This should hopefully unlock further simplifications to the refinement loop, since it now has fewer edge cases to worry about.
2024-01-05 23:41:41 -05:00
..
auxiliary coverage: Regression test for #117788 2023-11-13 12:31:44 +11:00
abort.cov-map
abort.coverage
abort.rs
assert_not.cov-map coverage: Regression test for assert!(!false) 2023-12-16 20:58:04 +11:00
assert_not.coverage coverage: Regression test for assert!(!false) 2023-12-16 20:58:04 +11:00
assert_not.rs coverage: Regression test for assert!(!false) 2023-12-16 20:58:04 +11:00
assert.cov-map
assert.coverage
assert.rs
async2.cov-map Enable GVN by default. 2023-12-24 20:08:57 +00:00
async2.coverage coverage: Use Waker::noop in async tests 2023-12-15 17:17:20 +11:00
async2.rs coverage: Use Waker::noop in async tests 2023-12-15 17:17:20 +11:00
async_block.cov-map coverage: Add a test for async blocks 2023-12-20 18:48:04 +11:00
async_block.coverage coverage: Add a test for async blocks 2023-12-20 18:48:04 +11:00
async_block.rs coverage: Add a test for async blocks 2023-12-20 18:48:04 +11:00
async.cov-map coverage: Use Waker::noop in async tests 2023-12-15 17:17:20 +11:00
async.coverage coverage: Use Waker::noop in async tests 2023-12-15 17:17:20 +11:00
async.rs coverage: Use Waker::noop in async tests 2023-12-15 17:17:20 +11:00
bad_counter_ids.cov-map
bad_counter_ids.coverage
bad_counter_ids.rs
closure_bug.cov-map
closure_bug.coverage
closure_bug.rs
closure_macro_async.cov-map coverage: Use Waker::noop in async tests 2023-12-15 17:17:20 +11:00
closure_macro_async.coverage coverage: Use Waker::noop in async tests 2023-12-15 17:17:20 +11:00
closure_macro_async.rs coverage: Use Waker::noop in async tests 2023-12-15 17:17:20 +11:00
closure_macro.cov-map
closure_macro.coverage
closure_macro.rs
closure.cov-map coverage: Hoist the splitting of visible macro invocations 2024-01-05 12:53:23 +11:00
closure.coverage
closure.rs
color.coverage Allow coverage tests to enable llvm-cov --use-color 2024-01-05 13:42:54 +11:00
color.rs Allow coverage tests to enable llvm-cov --use-color 2024-01-05 13:42:54 +11:00
conditions.cov-map coverage: Simplify building coverage expressions based on sums 2023-11-25 12:29:20 +11:00
conditions.coverage
conditions.rs
continue.cov-map coverage: Simplify building coverage expressions based on sums 2023-11-25 12:29:20 +11:00
continue.coverage
continue.rs
coroutine.cov-map coverage: Simplify building coverage expressions based on sums 2023-11-25 12:29:20 +11:00
coroutine.coverage
coroutine.rs
dead_code.cov-map
dead_code.coverage
dead_code.rs
drop_trait.cov-map
drop_trait.coverage
drop_trait.rs
fn_sig_into_try.cov-map
fn_sig_into_try.coverage
fn_sig_into_try.rs
generics.cov-map
generics.coverage
generics.rs
if_else.cov-map
if_else.coverage
if_else.rs
if_not.cov-map coverage: Use SpanMarker to mark the full condition of if ! 2023-12-08 22:40:49 +11:00
if_not.coverage coverage: Use SpanMarker to mark the full condition of if ! 2023-12-08 22:40:49 +11:00
if_not.rs coverage: Add a dedicated test for coverage of if ! 2023-12-08 22:40:49 +11:00
if.cov-map
if.coverage
if.rs
ignore_map.coverage Allow tests to ignore individual test modes 2024-01-05 13:42:54 +11:00
ignore_map.rs Allow tests to ignore individual test modes 2024-01-05 13:42:54 +11:00
ignore_run.cov-map Allow tests to ignore individual test modes 2024-01-05 13:42:54 +11:00
ignore_run.rs Allow tests to ignore individual test modes 2024-01-05 13:42:54 +11:00
inline-dead.cov-map coverage: Overhaul how "visible macros" are determined 2024-01-05 12:53:23 +11:00
inline-dead.coverage coverage: Overhaul how "visible macros" are determined 2024-01-05 12:53:23 +11:00
inline-dead.rs
inline.cov-map coverage: Skip spans that can't be un-expanded back to the function body 2023-12-03 12:35:33 +11:00
inline.coverage coverage: Skip spans that can't be un-expanded back to the function body 2023-12-03 12:35:33 +11:00
inline.rs
inner_items.cov-map
inner_items.coverage
inner_items.rs
issue-83601.cov-map
issue-83601.coverage
issue-83601.rs
issue-84561.cov-map
issue-84561.coverage
issue-84561.rs
issue-85461.cov-map
issue-85461.coverage
issue-85461.rs
issue-93054.cov-map
issue-93054.coverage
issue-93054.rs
lazy_boolean.cov-map coverage: Use SpanMarker to mark the full condition of if ! 2023-12-08 22:40:49 +11:00
lazy_boolean.coverage coverage: Use SpanMarker to mark the full condition of if ! 2023-12-08 22:40:49 +11:00
lazy_boolean.rs
long_and_wide.cov-map
long_and_wide.coverage
long_and_wide.rs
loop_break_value.cov-map
loop_break_value.coverage
loop_break_value.rs
loops_branches.cov-map coverage: Simplify building coverage expressions based on sums 2023-11-25 12:29:20 +11:00
loops_branches.coverage
loops_branches.rs
macro_name_span.cov-map macro_rules: Less hacky heuristic for using tt metavariable spans 2024-01-04 03:53:56 +03:00
macro_name_span.coverage macro_rules: Less hacky heuristic for using tt metavariable spans 2024-01-04 03:53:56 +03:00
macro_name_span.rs coverage: Regression test for #117788 2023-11-13 12:31:44 +11:00
match_or_pattern.cov-map
match_or_pattern.coverage
match_or_pattern.rs
nested_loops.cov-map
nested_loops.coverage
nested_loops.rs
no_cov_crate.cov-map
no_cov_crate.coverage
no_cov_crate.rs
no_spans_if_not.cov-map coverage: Regression test for markers in a function with no spans 2023-12-16 11:10:11 +11:00
no_spans_if_not.coverage coverage: Regression test for markers in a function with no spans 2023-12-16 11:10:11 +11:00
no_spans_if_not.rs coverage: Regression test for markers in a function with no spans 2023-12-16 11:10:11 +11:00
no_spans.cov-map coverage: Regression test for unwrapping prev when there are no spans 2023-12-08 22:49:12 +11:00
no_spans.coverage coverage: Regression test for unwrapping prev when there are no spans 2023-12-08 22:49:12 +11:00
no_spans.rs coverage: Regression test for unwrapping prev when there are no spans 2023-12-08 22:49:12 +11:00
overflow.cov-map
overflow.coverage
overflow.rs
panic_unwind.cov-map
panic_unwind.coverage
panic_unwind.rs
partial_eq.cov-map Enable GVN by default. 2023-12-24 20:08:57 +00:00
partial_eq.coverage
partial_eq.rs
README.md coverage: Rename the run-coverage test mode to coverage-run 2023-11-08 16:41:24 +11:00
simple_loop.cov-map
simple_loop.coverage
simple_loop.rs
simple_match.cov-map
simple_match.coverage
simple_match.rs
sort_groups.cov-map
sort_groups.coverage
sort_groups.rs
test_harness.cov-map
test_harness.coverage
test_harness.rs
thin-lto.cov-map Add thinlto support to codegen, assembly and coverage tests 2023-11-30 18:48:03 +08:00
thin-lto.coverage Add thinlto support to codegen, assembly and coverage tests 2023-11-30 18:48:03 +08:00
thin-lto.rs Add thinlto support to codegen, assembly and coverage tests 2023-11-30 18:48:03 +08:00
tight_inf_loop.cov-map
tight_inf_loop.coverage
tight_inf_loop.rs
trivial.cov-map
trivial.coverage
trivial.rs
try_error_result.cov-map coverage: Simplify building coverage expressions based on sums 2023-11-25 12:29:20 +11:00
try_error_result.coverage
try_error_result.rs
unreachable.cov-map coverage: Skip spans that can't be un-expanded back to the function body 2023-12-03 12:35:33 +11:00
unreachable.coverage coverage: Skip spans that can't be un-expanded back to the function body 2023-12-03 12:35:33 +11:00
unreachable.rs
unused_mod.cov-map
unused_mod.coverage
unused_mod.rs
unused.cov-map
unused.coverage
unused.rs
uses_crate.cov-map
uses_crate.coverage
uses_crate.rs
uses_inline_crate.cov-map
uses_inline_crate.coverage
uses_inline_crate.rs
while_early_ret.cov-map
while_early_ret.coverage
while_early_ret.rs
while.cov-map
while.coverage
while.rs
yield.cov-map
yield.coverage
yield.rs

The tests in this directory are shared by two different test modes, and can be run in multiple different ways:

  • ./x.py test coverage-map (compiles to LLVM IR and checks coverage mappings)
  • ./x.py test coverage-run (runs a test binary and checks its coverage report)
  • ./x.py test coverage (runs both coverage-map and coverage-run)

Maintenance note

These tests can be sensitive to small changes in MIR spans or MIR control flow, especially in HIR-to-MIR lowering or MIR optimizations.

If you haven't touched the coverage code directly, and the tests still pass in coverage-run mode, then it should usually be OK to just re-bless the mappings as necessary with ./x.py test coverage-map --bless, without worrying too much about the exact changes.