1
0
mirror of https://github.com/containers/netavark.git synced 2026-02-05 06:45:56 +01:00
Files
netavark/docs/generate-code-coverage-report.md
Jake Correnti 1f75d87c3e Document how to generate a code coverage report for netavark
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>
2024-01-03 13:11:31 -05:00

1.1 KiB

Generating a code coverage report

Get set up

  • Enable nightly Rust:
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 grcov to 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 grcov in 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