Skip to content

build: opt-in code-coverage targets (full report + patch/diff) - #30

Merged
rigazilla merged 4 commits into
infinispan:mainfrom
rigazilla:coverage-targets
Dec 4, 2026
Merged

rigazilla merged 4 commits into
infinispan:mainfrom
rigazilla:coverage-targets

Conversation

@rigazilla

@rigazilla rigazilla commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Closes #31.

Adds local code-coverage reporting to the build — a -DENABLE_COVERAGE=ON option plus three CMake targets. All off by default; normal and CI builds are unaffected. There is no coverage gate; these are developer reporting aids.

Targets

Target What
coverage Full gcovr report for src/ + include/hotrod/ — terminal summary, HTML (build/coverage/index.html), and Cobertura coverage.xml.
coverage-diff Patch coverage of only the lines changed vs COVERAGE_DIFF_BASE (default origin/main) via diff-cover; HTML at coverage/patch.html. -DCOVERAGE_DIFF_THRESHOLD=<pct> fails below a patch %.
coverage-reset Delete stale .gcda counters before a fresh run.

Tools (gcovr, diff-cover) are discovered with find_program, so a target is only created when its tool is present (with a helpful status message otherwise).

Usage

cmake -S . -B build-cov -DENABLE_COVERAGE=ON
cmake --build build-cov
ctest --test-dir build-cov                      # run the suites you want measured
cmake --build build-cov --target coverage       # full report
cmake --build build-cov --target coverage-diff  # patch coverage vs origin/main

Two gotchas handled (details in DECISIONS.md)

  • ENABLE_COVERAGE forces a Debug build. Coverage needs -O0, but under a non-Debug type the warnings block defines _FORTIFY_SOURCE=2, which errors at -O0 under -Werror; appending -U_FORTIFY_SOURCE doesn't help because CMake de-duplicates the repeated flag. Debug skips the define and gives -O0 -g.
  • gcovr is run from the source root with relative --filters (from the build dir with an absolute --root it matches 0 files); both targets pass the build dir as the .gcda search path.

Verified

  • coverage — produces summary + HTML + XML.
  • coverage-diff — runs clean (modern --format html: syntax, no deprecation warning); reports real per-file patch coverage against a ref with source changes, and correctly "no lines" for a docs-only diff.
  • A normal (non-coverage) configure is unchanged — no coverage targets, build type stays RelWithDebInfo.

Docs

STATUS (where-things-live row), DECISIONS (rationale + gotchas), README (a "Code coverage" section).

🤖 Generated with Claude Code

rigazilla and others added 4 commits December 3, 2026 16:59
Adds a -DENABLE_COVERAGE=ON configure option plus three custom targets, all
off by default so normal and CI builds are unaffected:

- coverage       full gcovr report for src/ + include/hotrod — terminal summary,
                 HTML (build/coverage/index.html), and Cobertura coverage.xml.
- coverage-diff  patch coverage of only the lines changed vs COVERAGE_DIFF_BASE
                 (default origin/main) via diff-cover; HTML at coverage/patch.html.
                 -DCOVERAGE_DIFF_THRESHOLD=<pct> fails below a patch percentage.
- coverage-reset delete stale .gcda counters before a fresh run.

Tools (gcovr, diff-cover) are discovered with find_program, so a target is only
created when its tool is present.

Notes on two gotchas (see DECISIONS.md):
- ENABLE_COVERAGE forces a Debug build. Coverage wants -O0, but under a non-Debug
  type the warnings block defines _FORTIFY_SOURCE=2, which errors at -O0 under
  -Werror; appending -U_FORTIFY_SOURCE does not help because CMake de-duplicates
  the repeated flag. Debug skips the define and yields -O0 -g.
- gcovr runs from the source root with relative --filters (from the build dir with
  an absolute --root it matches no files); both targets pass the build dir as the
  .gcda search path.

Docs: STATUS (where-things-live row), DECISIONS (rationale + gotchas), README
(Code coverage section).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
gcov can emit a negative branch hit count on some lines (e.g.
src/codec/HeaderCodec.cpp:48) with a non-trivial data set, which gcovr treats as
fatal and aborts the whole report. Pass gcovr's recommended
--gcov-ignore-parse-errors negative_hits.warn_once_per_file so the report still
generates (only the rare affected counts are unreliable). Applies to both the
coverage and coverage-diff targets via the shared gcovr args.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68080

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
On a large data set (full ctest -> many .gcda), gcovr's parallel gcov workers
race on the intermediate *.gcov.json.gz files written to the shared working dir,
surfacing as "Output file ... doesn't exist but no error from GCOV detected"
(a SanityCheckError, which is an AssertionError and therefore NOT catchable via
--gcov-ignore-errors). Pass -j 1 so gcov runs serially. Slower but reliable;
stacks with the existing negative-hits parse-error tolerance.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
diff-cover's --format html:.../coverage/patch.html does not create the parent
directory, so running `coverage-diff` without first running `coverage` (which does
the mkdir) failed with FileNotFoundError. Add an explicit make_directory step to
the coverage-diff target so it works standalone.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@rigazilla
rigazilla merged commit 8cb5bca into infinispan:main Dec 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev tooling: code-coverage CMake targets (full report + patch/diff)

1 participant