Introduction
Coverage report trends percentage of executed source code during the tests.
g++ flags
Generating coverage data requires specific g++
flags: -g -O0 --coverage
, set them only when running coverage tests, for this reason you can use separate CMAKE_BUILD_TYPE
:
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
endif()
Generate reports locally
-
Install
lcov
- Run cmake using correct
CMAKE_BUILD_TYPE
, compile code and run tests. This should output.gcda
files containing coverage data. - Use
lcov
to process the reports:lcov --directory . --capture --output-file coverage.info
- Remove particular coverage data that does not belong to package itself
lcov --remove coverage.info '/opt/*' '/usr/*' --output-file coverage.info
- Display coverage report
lcov --list coverage.info
Uploading reports to Codecov from aliBuild
…
Uploading reports to Codecov from Travis
Disclaimer: You can follow these instruction only if you’re able to supply all dependencies to the Travis build before it times out.
At first create an account in codecov
, generate security token: Account
> Access
> Create API token
and provide it to Travis.
Then, follow instruction from previous section, instead of displaying coverage report (Point 5) upload them to codecov:
- bash <(curl -s https://codecov.io/bash) || echo "No coverage reports"