Skip to content

Commit

Permalink
Revise the docs for coverage instrumentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar authored and tshepang committed Sep 11, 2023
1 parent 2eb01f9 commit aafa886
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/llvm-coverage-instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,32 +274,42 @@ since it will not be called), and adds a new `FunctionCoverage`, with

## Testing LLVM Coverage

[(See also the compiletest documentation for the `tests/coverage-map` and
`tests/run-coverage` test suites.)](./tests/compiletest.md#coverage-tests)

Coverage instrumentation in the MIR is validated by a `mir-opt` test:
[`instrument-coverage`][mir-opt-test].
[`tests/mir-opt/instrument_coverage.rs`].

Coverage instrumentation in LLVM IR is validated by the [`tests/coverage-map`]
test suite. These tests compile a test program to LLVM IR assembly, and then
use the [`src/tools/coverage-dump`] tool to extract and pretty-print the
coverage mappings that would be embedded in the final binary.

More complete testing of end-to-end coverage instrumentation and reports are
done in the `run-make-fulldeps` tests, with sample Rust programs (to be
instrumented) in the [`tests/run-coverage`] directory,
together with the actual tests and expected results.
End-to-end testing of coverage instrumentation and coverage reporting is
performed by the [`tests/run-coverage`] and [`tests/run-coverage-rustdoc`]
test suites. These tests compile and run a test program with coverage
instrumentation, then use LLVM tools to convert the coverage data into a
human-readable coverage report.

Finally, the [`coverage-llvmir`] test compiles a simple Rust program
with `-C instrument-coverage` and compares the compiled program's LLVM IR to
expected LLVM IR instructions and structured data for a coverage-enabled
program, including various checks for Coverage Map-related metadata and the LLVM
intrinsic calls to increment the runtime counters.

Expected results for both the `mir-opt` tests and the `coverage*` tests
can be refreshed by running:
Expected results for the `coverage-map`, `run-coverage`, `run-coverage-rustdoc`,
and `mir-opt` tests can be refreshed by running:

```shell
./x test tests/*coverage* --bless
./x test tests/mir-opt --bless
./x test tests/run-coverage --bless
./x test tests/run-coverage-rustdoc --bless
```

[mir-opt-test]: https://github.com/rust-lang/rust/blob/master/tests/mir-opt/instrument_coverage.rs
[`tests/mir-opt/instrument_coverage.rs`]: https://github.com/rust-lang/rust/blob/master/tests/mir-opt/instrument_coverage.rs
[`tests/coverage-map`]: https://github.com/rust-lang/rust/tree/master/tests/coverage-map
[`src/tools/coverage-dump`]: https://github.com/rust-lang/rust/tree/master/src/tools/coverage-dump
[`tests/run-coverage`]: https://github.com/rust-lang/rust/tree/master/tests/run-coverage
[spanview-debugging]: compiler-debugging.md#viewing-spanview-output
[`tests/run-coverage-rustdoc`]: https://github.com/rust-lang/rust/tree/master/tests/run-coverage-rustdoc
[`coverage-llvmir`]: https://github.com/rust-lang/rust/tree/master/tests/run-make/coverage-llvmir

## Implementation Details of the `InstrumentCoverage` MIR Pass
Expand Down

0 comments on commit aafa886

Please sign in to comment.