We were using mismatched compiler and gcov, which led to either segfaults or errors like "GCOV_TAG_COUNTER_ARCS mismatch". Add some cmake code that tries to find the gcov that matches the compiler. This should hopefully fix some of the mysterious missing coverage problems that we've been experiencing for a while.
Code coverage for TimescaleDB
Code coverage can be enabled for TimescaleDB builds by setting the
option -DCODECOVEAGE=ON
when running CMake (it is off by
default). This enables the necessary compiler option (--coverage
) to
generate code coverage statistics and should be enough for CI build
reports using, e.g., codecov.io
. In addition, local code coverage
reports can be generated with the lcov
tool, when this tool is
installed on the build system.
Generating local code coverage data files
A code coverage report is generated in three steps using lcov
:
- A pre test baseline run to learn what zero coverage looks like (the
coverage_base
target). - A post test run to learn the test coverage (the
coverage_test
target). - A final run to combine the pre test and post test output files into
a final data file (the
coverage_final
target).
Each of these steps can be run manually using the mentioned targets, but should happen automatically as part of regular build and test steps. Optionally, this process can be extended with a filtering step to ignore certain paths that shouldn't be included in the final report.
Producing a HTML-based code coverage report
Once the complete test suite has run (installcheck
target), it is
possible to produce a HTML-based code coverage report that can be
viewed in a web browser. This is automated by the coverage
target.
Thus, the complete steps to produce a code coverage report are:
cmake --build
cmake --build --target installcheck
cmake --build --target coverage