Cockatrice/gcovr.cfg
Lukas Brübach 2c249438d5 [CI] Publish a gcovr line-coverage report from the test run
Sanitizers tell us what a run did wrong; they say nothing about what it never
reached. This adds the other half: an instrumented build whose report says which
of our own lines no test executes.

Add an ENABLE_COVERAGE option that compiles with --coverage -O0 -g, mirroring the
ENABLE_SANITIZERS opt-in including the per-source carve-out that keeps vendored
trees out of the denominator. -O0 is deliberate: at higher optimisation levels GCC
merges and relocates lines, so the report would describe code that no longer exists
in that form. Only GCC is supported, since Clang's intermediate format needs
llvm-cov; asking for coverage under Clang is a hard error rather than a build that
silently produces unreadable .gcno files.

Keep the filters in a committed gcovr.cfg rather than in the invocation. The tests
themselves are excluded because they are compiled with the same instrumentation
and are only ever executed by the run doing the measuring, so leaving them in would
report a healthier project than we have. The process entry points and the client's
window chrome go too: each needs a display, an interactive terminal or a live
database before it does anything a headless test could observe, so they would
otherwise sit at 0% forever and bury real movement.

Give coverage its own matrix leg rather than a second flag on the sanitizer leg.
The two answer different questions, and combining them slows both down without
telling us more. The new variant key gives the leg its own Docker image and ccache
entry so the two legs cannot race on the same tag.

The leg publishes an HTML report with per-file pages, LCOV, Cobertura XML and a
JSON summary. gcovr is a report-time dependency rather than a build dependency, so
a missing one warns and skips instead of failing an otherwise green build.
2026-10-10 19:51:50 +02:00

63 lines
3 KiB
INI

# gcovr configuration for Cockatrice line coverage.
#
# Used by .ci/compile.sh --coverage and by hand:
#
# cmake -S . -B build/cover -DCMAKE_BUILD_TYPE=Debug -DWITH_SERVER=1 -DTEST=1 -DENABLE_COVERAGE=ON
# cmake --build build/cover -j 24
# ctest --test-dir build/cover -LE bench -j 24
# gcovr build/cover --root . --object-directory build/cover --txt --decisions
#
# The point of most of this file is subtraction. A raw report is dominated by code no test can
# reach: vendored third-party trees, build directories left over from earlier experiments, and
# the client's main() and window classes, which have no headless test. Those all dilute the one
# number worth watching, so they are filtered out here rather than in every invocation.
# root is deliberately not set here. This file is normally invoked from the build directory
# (compile.sh runs there, because it configures with `cmake ..`), so a `root` of `.` would
# resolve to the build tree and every filter below would exclude everything. compile.sh passes
# --root explicitly instead.
# Our own code only. This keeps generated Qt MOC output, protobuf output and anything CMake
# built under the source tree out of the report.
filter = ^cockatrice/
filter = ^libcockatrice_[^/]+/
filter = ^servatrice/
filter = ^oracle/
# The tests are the vehicle, not the subject. They are compiled with the same instrumentation,
# so leaving them in would add their near-perfect coverage to the numerator and quietly report a
# healthier project than we have: test code is only ever executed by the run that is measuring
# it. Helpers under tests/ are excluded on the same grounds.
exclude = ^tests/
# Vendored third-party code is not ours to cover and is never going to move the number.
exclude = ^vcpkg/
exclude = ^doc/doxygen/theme/
exclude = ^libcockatrice_rng/libcockatrice/rng/sfmt/
exclude = ^libcockatrice_utility/libcockatrice/utility/peglib\.h$
exclude = ^oracle/src/lzma/
exclude = ^oracle/src/qt-json/
exclude = ^oracle/src/zip/
exclude = ^servatrice/src/smtp/
# Qt's own moc/pch/uic output is generated into the build tree, not the source tree, so the
# filters above already keep it out. These cover CLion's directories, which sit in-tree and are
# picked up by the object-directory walk.
exclude = .*cmake-build-.*
exclude = .*\.cache/
# Process entry points and the client's window chrome. Each of these needs a display, an
# interactive terminal, or a live database before it does anything a test could observe, so no
# headless run will ever move them. Left in, they contribute thousands of lines at 0% and drag
# the total down by a fixed amount that hides movement in the code we can actually test. The
# window header is excluded with its .cpp because gcovr attributes its inline template code
# there, which is where most of its line count lives.
exclude = ^cockatrice/src/main\.cpp$
exclude = ^cockatrice/src/interface/window_main\.
exclude = ^oracle/src/main\.cpp$
exclude = ^servatrice/src/main\.cpp$
exclude-throw-branches = yes
exclude-function-lines = yes
print-summary = yes