timescaledb/codecov/README.md
Erik Nordström e1b9e02e12 Cleanup code coverage and make it work locally
The code coverage options for CMake have been cleaned up and fixed
where they were broken. Build targets for local coverage reports now
work. The option to enable code coverage has been changed to
`-DCODECOVERAGE=ON` and local HTML-based reports can be generated
using the `lcov` program through the following steps:

1. `make install`
2. `make installcheck`
3. `make coverage`

The previous CMake options and targets didn't properly work, and often
included redundant and confusing options.

For instance, the only compiler option needed for code coverage is
`--coverage` as this is an alias for `-fprofile-arcs
-ftest-coverage`. Previously, however, these options were added
multiple times in various places, often all of them, but sometimes
only a subset for no apparent reason. They were also added using the
wrong CMake commands, for instance `add_definitions`, which is
deprecated and reserved for preprocessor definitions and not compiler
options.

The `lcov` program is used to generate local HTML-based code coverage
reports. Although CMake was setup to look for `lcov`, it didn't check
for failure cases in case it wasn't found and further had incomplete
target configurations that really didn't do much. No additional
documentation was provided on how to generate local coverage
reports. All of this has been fixed, including documentation in
`codecov/README.md`.
2020-05-19 22:08:23 +02:00

1.5 KiB

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:

  1. A pre test baseline run to learn what zero coverage looks like (the coverage_base target).
  2. A post test run to learn the test coverage (the coverage_test target).
  3. 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:

  1. cmake --build
  2. cmake --build --target installcheck
  3. cmake --build --target coverage