bin+lib grcov

Rust tool to collect and aggregate code coverage data for multiple source files

5 releases (3 breaking)

✓ Uses Rust 2018 edition

0.5.0 May 14, 2019
0.4.3 Mar 29, 2019
0.4.1 Jan 21, 2019
0.3.0 Oct 9, 2018
0.2.3 Oct 5, 2018

#29 in Testing

Download history 14/week @ 2019-01-29 46/week @ 2019-02-05 114/week @ 2019-02-12 210/week @ 2019-02-19 226/week @ 2019-02-26 180/week @ 2019-03-05 191/week @ 2019-03-12 177/week @ 2019-03-19 99/week @ 2019-03-26 50/week @ 2019-04-02 46/week @ 2019-04-09 31/week @ 2019-04-16 50/week @ 2019-04-23 216/week @ 2019-04-30 50/week @ 2019-05-07

542 downloads per month

MPL-2.0 license



Build Status Build status codecov

grcov collects and aggregates code coverage information for multiple source files.

This is a project initiated by Mozilla to gather code coverage results on Firefox.


  1. Download grcov from https://github.com/mozilla/grcov/releases or run cargo install grcov
  2. Run grcov:
    grcov [FLAGS] [OPTIONS] <paths>...

            Enables parsing branch coverage information

    -h, --help
            Prints help information

            Ignore source files that can't be found on the disk

            Speeds-up parsing, when the code coverage information is exclusively coming from a llvm build

    -V, --version
            Prints version information

        --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-dir <PATH>...
            Ignore files/directories specified as globs

    -o, --output-file <FILE>
            Specifies the output file

    -t, --output-type <OUTPUT TYPE>
            Sets a custom output type:
            - *lcov* for the lcov INFO format;
            - *coveralls* for the Coveralls specific format;
            - *coveralls+* for the Coveralls specific format with function information;
            - *ade* for the ActiveData-ETL specific format;
            - *files* to only return a list of files.
             [default: lcov]  [possible values: ade, lcov, coveralls, coveralls+, files]
        --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-number <SERVICE JOB NUMBER>
            Sets the service job number

        --service-name <SERVICE NAME>
            Sets the service name

        --service-number <SERVICE NUMBER>
            Sets the service number

    -s, --source-dir <DIRECTORY>
            Specifies the root directory of the source files

        --threads <NUMBER>
             [default: 24]

        --token <TOKEN>
            Sets the repository token from Coveralls, required for the 'coveralls' and 'coveralls+' formats

            Sets the input paths to use

Let's see a few examples, assuming the source directory is ~/Documents/mozilla-central and the build directory is ~/Documents/mozilla-central/build.

LCOV output

grcov ~/Documents/mozilla-central/build -t lcov > lcov.info

As the LCOV output is compatible with lcov, genhtml can be used to generate a HTML summary of the code coverage:

genhtml -o report/ --show-details --highlight --ignore-errors source --legend lcov.info

Coveralls/Codecov output

grcov ~/Documents/FD/mozilla-central/build -t coveralls -s ~/Documents/FD/mozilla-central --token YOUR_COVERALLS_TOKEN > coveralls.json

grcov with Travis

Here is an example of .travis.yml file

language: rust

  - curl -L https://github.com/mozilla/grcov/releases/download/v0.4.1/grcov-linux-x86_64.tar.bz2 | tar jxf -

    - os: linux
      rust: nightly

    - 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-dir "/*" -o lcov.info;
      bash <(curl -s https://codecov.io/bash) -f lcov.info;

Build & Test

In order to build, either LLVM 7 or LLVM 8 libraries and headers are required. If one of these versions is sucessfully installed, build with:

cargo build

To run tests:

cargo test

Minimum requirements

  • GCC 4.9 or higher is required (if parsing coverage artifacts generated by GCC).


Published under the MPL 2.0 license.


~150K SLoC