Skip to main content

colcon-lcov-result

An extension for colcon-core to provide aggregate coverage results using LCOV.

LCOV is a graphical front-end for GCC’s coverage testing tool gcov, producing the following coverage metrics:

  • Statement coverage

  • Function coverage

  • Branch coverage

For more information, see this paper and this Wikipedia page.

Usage

  1. Build your packages with coverage flags, using colcon:

    $ colcon build \
          --symlink-install \
          --cmake-args \
              -DCMAKE_CXX_FLAGS='-fprofile-arcs -ftest-coverage' \
              -DCMAKE_C_FLAGS='-fprofile-arcs -ftest-coverage'
  2. Create a baseline for zero coverage:

    $ colcon lcov-result --initial
    • This step is optional, but will help reveal any files that are untouched by tests

  3. Run tests:

    $ colcon test
  4. Gather the lcov results:

    $ colcon lcov-result
    Reading tracefile /home/user/workspace/my_cool_ws/lcov/total_coverage.info
    Summary coverage rate:
      lines......: 78.6% (44 of 56 lines)
      functions..: 94.4% (34 of 36 functions)
      branches...: 37.0% (34 of 92 branches)
  5. Browse the coverage report by opening lcov/index.html in a browser

  6. Zero the coverage counters and re-run tests:

    $ colcon lcov-result --zero-counters
    $ colcon lcov-result --initial
    $ colcon test
    $ colcon lcov-result
    Reading tracefile /home/user/workspace/my_cool_ws/lcov/total_coverage.info
    Summary coverage rate:
      lines......: 78.6% (44 of 56 lines)
      functions..: 94.4% (34 of 36 functions)
      branches...: 37.0% (34 of 92 branches)

Tips and Tricks

  • When running locally, use the --packages-select option to generate coverage information for relevant packages

    • This will also suppress warnings for packages that were either not built with coverage flags or for which tests did not run

  • The --verbose flag can be used to print the coverage summary of each individual package as the results are analyzed

Contributing

For non-trivial contributions, it is recommended to first create an issue to discuss your ideas.

The following is the recommended workflow for contributing:

  1. Install colcon and extensions in a virtual environment:

    $ cd <workspace>
    $ python3 -m venv colcon-env
    $ source colcon-env/bin/activate
    $ pip3 install colcon-common-extensions
  2. Install colcon-lcov-result in editable mode:

    $ cd <workspace>
    $ python3 -m venv colcon-env
    $ source colcon-env/bin/activate
    $ cd path/to/colcon-lcov-result
    $ pip3 install -e .
  3. As long as you are in the virtual environment, make changes to colcon-lcov-result run colcon lcov-result, and see the effect of the changes

  4. Commit changes and submit a PR:

Troubleshooting

  • The following warning when running colcon lcov-result --initial implies that the package was not built with the correct flags:

    --- stderr: my_pkg
    geninfo: WARNING: no .gcno files found in /home/user/workspace/build/my_pkg - skipping!
    ---
    • The package will not show up in the final results. Use --packages-skip to suppress the warning

  • The following warning when running colcon lcov-result implies that no tests ran for that package

    [0.576s] ERROR:colcon.colcon_lcov_result.task.lcov:lcov:
    ERROR: no valid records found in tracefile /home/user/workspace/build/my_pkg/coverage.info
    --- stderr: my_pkg
    geninfo: WARNING: no .gcda files found in /home/user/workspace/build/my_pkg - skipping!
    ---
    • The package will show up in the final results with 0% coverage. Use --packages-skip to suppress these packages from the total

Known Issues

  1. The final step of aggregating all the result files can be slow depending on the number of packages that were analyzed

Developing

See DEVELOPING.md.

Release files for colcon-lcov-result 0.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colcon-lcov-result 0.5.3
File Size Uploaded
colcon_lcov_result-0.5.3.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for colcon-lcov-result 0.5.3
File Interpreter ABI Platform
colcon_lcov_result-0.5.3-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / colcon_lcov_result-0.5.3.tar.gz

Download URL colcon_lcov_result-0.5.3.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4cbf83bbf0e1e82b22e95ce2d76b667fdaaca2cda6ecf77bd46a03dfc98c047d
BLAKE2b-256 checksum
How to use checksums
3192da94528d5c90e376744e14320eb2460b3c6356757ca7e00b64758d0074f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / colcon_lcov_result-0.5.3-py3-none-any.whl

Download URL colcon_lcov_result-0.5.3-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de643660ddf356fbbeae0eabefb6a9c70f30979ddb1759e638f2660581a34fb8
BLAKE2b-256 checksum
How to use checksums
5958329ca3d1591a21d570ce5926def9a7be4124b5648168ab50f6ec88339054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.5.3 This release

2 release files

0.5.2

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

1 release file

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page