Coverage is measured using GCC's built-in gcov instrumentation, with gcovr to
aggregate and render reports.
gcov— part of GCC; generates.gcno(compile-time) and.gcda(runtime) filesgcovr— Python tool that reads gcov data and outputs JSON, HTML, and text summaries in a single command; no root access required
gcovr is preferred over the traditional lcov/genhtml pipeline because it produces
a machine-readable JSON report (used for AI-assisted gap analysis) alongside the human
HTML report, and does so in one invocation.
pip install gcovr
gcovr --versionCoverage is opt-in: pass COVERAGE=1 to add the --coverage flags to PG_CFLAGS
and SHLIB_LINK. Default builds are never instrumented.
source docs/dev/env.sh
make clean
make COVERAGE=1
make install--coverage is a GCC shorthand:
- At compile time:
-fprofile-arcs -ftest-coverage(generates.gcnobeside each.o) - At link time:
-lgcov(links the gcov runtime into the shared library)
make clean is required when switching instrumentation on or off — the flags change
how every object file is compiled.
Before running tests, reset any leftover .gcda files from previous runs:
make coverage-cleanmake installcheck # SQL regression tests (test/sql/*.sql)
make prove_installcheck # Perl TAP tests (test/t/0*.pl)Background worker note: The Vamana BGW is a separate forked process. Its coverage data is written by
atexit()handlers when the process exits. Always stop the cluster cleanly withpg_ctl stopbefore collecting data —SIGKILLor a crash will lose BGW coverage.
One command produces all three outputs:
make coverageReports are written to coverage_reports/ (gitignored — never committed):
| File | Purpose |
|---|---|
coverage_reports/coverage.txt |
Per-file line summary (human-readable) |
coverage_reports/coverage.json |
gcovr JSON v0.14 — per-line hit counts and function names; AI-consumable |
coverage_reports/index.html |
Interactive HTML; red/green line highlighting |
Drop COVERAGE=1 and rebuild; no Makefile edit is needed:
make clean && make && make install- Run
make coverageto generatecoverage_reports/coverage.json. - Share
coverage_reports/coverage.jsonwith the AI assistant (or ask the assistant to read it directly from the workspace). - The assistant identifies uncovered lines and branches, cross-references against the source files, and writes targeted test cases.
- Re-run
make coverage-clean && make prove_installcheck && make coverageto verify improvement.
| Source file | What it exercises |
|---|---|
src/vamanabuild.c |
Batch build path |
src/vamanascan.c |
KNN query path |
src/vamanaworker.c |
BGW main loop, IPC handling |
src/vamanaworkerindex.c |
Index load/eviction in BGW cache |
src/vamanaworkersearch.c |
Batch search dispatch |
src/vamanaworkerwrite.c |
Insert/delete write path |
src/svs_wrapper.c |
SVS C API call sites |
src/vamanavacuum.c |
Vacuum/delete path (typically under-tested) |
src/vamana_undo.c |
Undo/abort path |
.gcdafiles are written to the same directory as the.ofiles (src/). The PostgreSQL server process must have write access to that directory. In a local dev build under$HOMEthis is automatic.- Each test run accumulates into the existing
.gcdafiles. Rungcovr --deleteto start fresh. - For the BGW, coverage accumulates across all index builds, searches, inserts, and
vacuums executed during the test run. The Perl TAP tests (
test/t/) exercise more BGW paths than the SQL regression tests alone.