kick/coverage.sh

46 lines
1.9 KiB
Bash
Executable file

#!/bin/sh
# Line coverage of kick.c unioned across the test suite (gcc/gcov route).
#
# ./coverage.sh # always the full suite (default + flaky), no args:
# # partial runs give a misleading union, and -n/pytest-xdist
# # shares .gcda files across workers (read-merge-write race),
# # so parallel coverage is not supported.
#
# Builds build-cov/ instrumented (--coverage + KICK_COVERAGE flush hook for
# the SIGTERM/_exit teardown path), zeroes counters, runs pytest against
# build-cov/kick via KICK_BIN, then reports kick.c line coverage (gcda
# counters merge automatically across the many kick invocations).
set -e
cd "$(dirname "$0")"
if [ $# -ne 0 ]; then
echo "usage: $0 (no arguments; always the full suite)" >&2
exit 2
fi
if [ ! -f build-cov/build.ninja ]; then
meson setup build-cov -Db_coverage=true "-Dc_args=-DKICK_COVERAGE"
else
meson setup build-cov --reconfigure -Db_coverage=true "-Dc_args=-DKICK_COVERAGE"
fi
meson compile -C build-cov kick wltest xdeco
find build-cov -name '*.gcda' -delete
# Both passes run even if the first fails (test failures must not cost us
# the report); the script still exits non-zero when either pass fails.
RC=0
KICK_BIN="$PWD/build-cov/kick" pytest || RC=$?
KICK_BIN="$PWD/build-cov/kick" pytest -m flaky || RC=$((RC || $?))
# crash_handler and handle_pending_tag_toplevel_destroy are unreachable by
# design (crash-only; synchronous claim) and carry GCOVR_EXCL markers for
# their lines; --exclude-function drops them from the function totals too.
echo "--- kick.c line coverage (union of all runs above) ---"
gcovr -r . --filter 'kick\.c$' \
--exclude-function 'crash_handler|handle_pending_tag_toplevel_destroy' \
--txt
gcovr -r . --filter 'kick\.c$' \
--exclude-function 'crash_handler|handle_pending_tag_toplevel_destroy' \
--html-details -o build-cov/cov-kick.html
echo "HTML: build-cov/cov-kick.html"
exit $RC