Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 2 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ This is a project initiated by Mozilla to gather code coverage results on Firefo
- [Usage](#usage)
- [Example: How to generate source-based coverage for a Rust project](#example-how-to-generate-source-based-coverage-for-a-rust-project)
- [Example: How to generate .gcda files for C/C++](#example-how-to-generate-gcda-files-for-cc)
- [Example: How to generate .gcda files for a Rust project](#example-how-to-generate-gcda-files-for-a-rust-project)
- [Generate a coverage report from coverage artifacts](#generate-a-coverage-report-from-coverage-artifacts)
- [LCOV output](#lcov-output)
- [Coveralls output](#coveralls-output)
Expand Down Expand Up @@ -223,37 +222,12 @@ you can run `cargo install grcov`.

In the CWD, you will see a `.profraw` file has been generated. This contains the profiling information that grcov will parse, alongside with your binaries.

Note that gcov coverage using the `-Zprofile` flag is no longer supported in Rust (details [here](https://github.com/rust-lang/rust/pull/131829)). Use source based coverage and the `-Cinstrument-coverage` flag instead.

### Example: How to generate .gcda files for C/C++

Pass `--coverage` to `clang` or `gcc` (or for older gcc versions pass `-ftest-coverage` and `-fprofile-arcs` options (see [gcc docs](https://gcc.gnu.org/onlinedocs/gcc/Gcov-Data-Files.html)).

### Example: How to generate .gcda files for a Rust project

**Nightly Rust is required** to use grcov for Rust gcov-based coverage. Alternatively, you can `export
RUSTC_BOOTSTRAP=1`, which basically turns your stable rustc into a Nightly one.

1. Ensure that the following environment variables are set up:

```sh
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
export RUSTDOCFLAGS="-Cpanic=abort"
```

These will ensure that things like dead code elimination do not skew the coverage.

2. Build your code:

`cargo build`

If you look in `target/debug/deps` dir you will see `.gcno` files have appeared. These are the locations that could be covered.

3. Run your tests:

`cargo test`

In the `target/debug/deps/` dir you will now also see `.gcda` files. These contain the hit counts on which of those locations have been reached. Both sets of files are used as inputs to `grcov`.

### Generate a coverage report from coverage artifacts

Generate a html coverage report like this:
Expand Down Expand Up @@ -310,31 +284,6 @@ script:
- bash <(curl -s https://codecov.io/bash) -f lcov.info
```

Here is an example of .travis.yml file:

```yaml
language: rust

before_install:
- curl -L https://github.com/mozilla/grcov/releases/latest/download/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf -

matrix:
include:
- os: linux
rust: stable

script:
- export CARGO_INCREMENTAL=0
- export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
- export RUSTDOCFLAGS="-Cpanic=abort"
- cargo build --verbose $CARGO_OPTIONS
- cargo test --verbose $CARGO_OPTIONS
- |
zip -0 ccov.zip `find . \( -name "YOUR_PROJECT_NAME*.gc*" \) -print`;
./grcov ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing --ignore "/*" -o lcov.info;
bash <(curl -s https://codecov.io/bash) -f lcov.info;
```

#### grcov with Gitlab

Here is an example `.gitlab-ci.yml` which will build your project, then collect coverage data in a format that Gitlab understands. It is assumed that you'll use an image which already has relevant tools installed, if that's not the case put the appropriate commands at the beginning of the `script` stanza.
Expand Down
Loading