Skip to content

Generate code coverage reports

leoisl edited this page Jun 25, 2019 · 6 revisions

Dependencies

You need to have lcov installed.

Additionally, these instructions will be focused on running tests from CLion. If you are running from command line it should be a very similar process.

Clear previous counter

The first thing you need to do each time is clear the output from the previous coverage counters.

cd /path/to/pandora
cd cmake-build-debug/test/CMakeFiles/pandora_test.dir
lcov --directory . --zerocounters

Run tests

Run the test suite from CLion.

Capture coverage information

lcov --directory . --capture \
  --exclude '/usr/local/include/boost/*' \
  --exclude '*_test.cpp' \
  --exclude '*.h' \
  --exclude '/usr/include/*' \
  --exclude  '*cmake-build-debug*' \
  --exclude  '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/*' \
  --output-file pandora_test.info

lcov on your system may or may not raise an error with the --exclude arguments as these may have different paths to your system. You can remove them if you want but keep in the mind the coverage report will contain a bunch of other files not related to pandora. For example, if using Linux, you wont need to exclude the Xcode directory.

Generate the report

genhtml --show-details --legend pandora_test.info
# mac
open index.html
# linux
google-chrome index.html
# or
firefox index.html

Alternative way to filter coverage information

With this, you can capture all the information one time, then filter it with what you want to filter and build the report on the filtered info.

Capture all information:

lcov --directory . --capture --output-file pandora_test.info

Create a filtered .info (change what you want to filter out):

lcov --remove pandora_test.info -o pandora_test.filtered.info '/usr/include/*' '/pandora/build_debug/include/*' '/pandora/build_debug/test/*' '*_main.cpp'

Generate report with the filtered .info:

genhtml --show-details --legend pandora_test.filtered.info --output-directory lcov_report

Output will be at lcov_report