✓ Uses Rust 2018 edition
|new 0.5.12||Mar 26, 2020|
|0.5.9||Jan 9, 2020|
|0.5.7||Dec 23, 2019|
|0.5.5||Oct 7, 2019|
|0.3.0||Oct 9, 2018|
#12 in Testing
3,088 downloads per month
grcov collects and aggregates code coverage information for multiple source files. grcov processes .gcda files which can be generated from llvm/clang or gcc. Linux, OSX and Windows are supported.
This is a project initiated by Mozilla to gather code coverage results on Firefox.
- Build & Test
- Minimum requirements
USAGE: grcov [FLAGS] [OPTIONS] <paths>... FLAGS: --branch Enables parsing branch coverage information --guess-directory-when-missing -h, --help Prints help information --ignore-not-existing Ignore source files that can't be found on the disk --llvm Speeds-up parsing, when the code coverage information is exclusively coming from a llvm build -V, --version Prints version information OPTIONS: --commit-sha <COMMIT HASH> Sets the hash of the commit used to generate the code coverage data --filter <filter> Filters out covered/uncovered files. Use 'covered' to only return covered files, 'uncovered' to only return uncovered files [possible values: covered, uncovered] --ignore <PATH>... Ignore files/directories specified as globs --log <LOG> Set the file where to log (or stderr or stdout). Defaults to 'stderr' [default: stderr] -o, --output-file <FILE> Specifies the output file -t, --output-type <OUTPUT TYPE> Sets a custom output type [default: lcov] [possible values: ade, lcov, coveralls, coveralls+, files, covdir, html] --path-mapping <PATH>... -p, --prefix-dir <PATH> Specifies a prefix to remove from the paths (e.g. if grcov is run on a different machine than the one that generated the code coverage information) --service-job-id <SERVICE JOB ID> Sets the service job id [aliases: service-job-number] --service-name <SERVICE NAME> Sets the service name --service-number <SERVICE NUMBER> Sets the service number --service-pull-request <SERVICE PULL REQUEST> Sets the service pull request number -s, --source-dir <DIRECTORY> Specifies the root directory of the source files --threads <NUMBER> [default: 16] --token <TOKEN> Sets the repository token from Coveralls, required for the 'coveralls' and 'coveralls+' formats --vcs-branch <VCS BRANCH> Set the branch for coveralls report. Defaults to 'master' [default: master] ARGS: <paths>... Sets the input paths to use
Grcov can be downloaded from releases or, if you have Rust installed,
you can run
cargo install grcov.
gcc (or for older gcc versions pass
-fprofile-arcs options (see gcc docs).
- Ensure that the following environment variables are set up:
export CARGO_INCREMENTAL=0 export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
These will ensure that things like dead code elimination do not skew the coverage.
- Build your code:
If you look in
target/debug/deps dir you will see
.gcno files have appeared. These are the locations that could be covered.
- Run your tests:
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
Generate a html coverage report like this:
grcov ./target/debug/ -s . -t html --llvm --branch --ignore-not-existing -o ./target/debug/coverage/
You can see the report in
(or alterntatively with
-t lcov grcov will output a lcov compatible coverage report that you could then feed into lcov's
-t lcov you could generate an lcov.info file and pass it to genhtml:
genhtml -o ./target/debug/coverage/ --show-details --highlight --ignore-errors source --legend ./target/debug/lcov.info
Coverage can also be generated in coveralls format:
grcov ./target/debug -t coveralls -s . --token YOUR_COVERALLS_TOKEN > coveralls.json
Here is an example of .travis.yml file
language: rust before_install: - curl -L https://github.com/mozilla/grcov/releases/latest/download/grcov-linux-x86_64.tar.bz2 | tar jxf - matrix: include: - os: linux rust: nightly script: - export CARGO_INCREMENTAL=0 - export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads" - 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 provides the following output types:
|lcov (default)||lcov's INFO format that is compatible with the linux coverage project.|
|ade||ActiveData-ETL format. Only useful for Mozilla projects.|
|coveralls||Generates coverage in Coveralls format.|
|coveralls+||Like coveralls but with function level information.|
|files||Output a file list of covered or uncovered source files.|
|covdir||Provides coverage in a recursive JSON format.|
|html||Output a HTML coverage report.|
This project is using pre-commit. Please run
pre-commit install to install the git pre-commit hooks on your clone. Instructions on how to install pre-commit can be found here.
Every time you will try to commit, pre-commit will run checks on your files to make sure they follow our style standards and they aren't affected by some simple issues. If the checks fail, pre-commit won't let you commit.
To run unit tests:
cargo test --lib
To run integration tests, it is suggested to use the Docker image defined in tests/Dockerfile. Simply build the image to run them:
docker build -t marcocas/grcov -f tests/Dockerfile .
Otherwise, if you don't want to use Docker, the only prerequisite is to install GCC 7, setting the
GCC_CXX environment variable to
g++-7 and the
GCOV environment variable to
gcov-7. Then run the tests with:
- GCC 4.9 or higher is required (if parsing coverage artifacts generated by GCC).
Published under the MPL 2.0 license.