Skip to content

Commit

Permalink
Add instruction for using grcov to help improve unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tanj authored and David-OConnor committed Jun 12, 2021
1 parent 51b4b53 commit ef6553a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ script.py
build/
dist/

# grcov
*.profraw
24 changes: 24 additions & 0 deletions GRCOV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Getting test coverage report with grcov #

Get [grcov](https://github.com/mozilla/grcov ) and install their requirements for your system.

To get a complete test report run the following commands with these env
variables set. (I found some flags they suggested broke with some of our packages.)

`.bashrc`
```shell
export LLVM_PROFILE_FILE="your_name-%p-%m.profraw"
export RUSTDOCFLAGS="-Cpanic=abort"
```

1. `RUSTFLAGS="-Zinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off -Zpanic_abort_tests" CARGO_INCREMENTAL=0 RUSTC_BOOTSTRAP=1 cargo build`
1. `RUSTFLAGS="-Zinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off -Zpanic_abort_tests" CARGO_INCREMENTAL=0 RUSTC_BOOTSTRAP=1 cargo test`
1. `grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/`


## Known issues ##

- If you run `grcov` on Windows you will need to run it as admin or it will fail
with an error related to symlinks. [Issue 561](https://github.com/mozilla/grcov/issues/561)
- `[ERROR] Execution count overflow detected.` can occur when running `grcov`
but is not fatal and a report will still be created. [Issue 613](https://github.com/mozilla/grcov/issues/613)

0 comments on commit ef6553a

Please sign in to comment.