mirror of
https://github.com/containers/netavark.git
synced 2026-02-05 06:45:56 +01:00
I documented how to generate a code coverage report using coverage-profiling in the Rust compiler and the `grcov` tool created by Mozilla. It generates an html version of the report that you can open in the browser and navigate. Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
1.1 KiB
1.1 KiB
Generating a code coverage report
Get set up
- Enable
nightlyRust:
rustup override set nightly
- Build the demangler:
cargo install rustfilt
- Install Grcov
cargo install grcov
Generate the report
- Build the program with coverage profiling enabled in the Rust compiler:
RUSTFLAGS="-C instrument-coverage" make
- Run all of the tests:
make test
#or
cargo test
sudo bats test/
sudo bats test-dhcp/
- Use
grcovto generate a report:
grcov . -s . --binary-path ./targets/release/ -t html --branch --ignore-not-existing --ignore '../*' --ignore '/*' -o target/coverage/
Access the report
- To view the code coverage report, you can open the html file generated by
grcovin your browser:
firefox target/coverage/index.html
- You will now have a large collection of raw profiling data in the form of default_*.profraw files. Now that the report has been created, you can delete these files.
Additional Resources
- Instrumentation-based Code Coverage: https://doc.rust-lang.org/rustc/instrument-coverage.html#-c-instrument-coverageoptions