Files
conflict-range/cpp/run-coverage.sh
T
andrew 73e371fb40 Remove dead branches from the fast translation
Drop predicate operands and unreachable arms that dispatch and readable invariants fix, and extend the exhaustive sweep to cover every branch side. Gate coverage on branch coverage as well.
2026-11-17 19:26:09 -05:00

53 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build with Clang source-based coverage and require 100% line and branch
# coverage of the summarised implementation (`src/fast.cpp`). `exhaustive_test`
# enumerates small readable instances deterministically and is sufficient on its
# own.
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
build="${1:-$here/build-coverage}"
cxx="${CXX:-clang++-21}"
profdata="${LLVM_PROFDATA:-$(command -v llvm-profdata-21 || command -v llvm-profdata || true)}"
cov="${LLVM_COV:-$(command -v llvm-cov-21 || command -v llvm-cov || true)}"
if [[ -z "$profdata" || -z "$cov" ]]; then
echo "llvm-profdata and llvm-cov are required" >&2
exit 2
fi
cmake -S "$here" -B "$build" -G Ninja \
-DCMAKE_CXX_COMPILER="$cxx" \
-DCMAKE_BUILD_TYPE=Debug \
-DCR_BUILD_FUZZERS=OFF \
-DCR_BUILD_BENCH=OFF \
-DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping" \
-DCMAKE_EXE_LINKER_FLAGS="-fprofile-instr-generate"
cmake --build "$build" --target exhaustive_test
profdir="$build/prof"
rm -rf "$profdir"
mkdir -p "$profdir"
cd "$here"
LLVM_PROFILE_FILE="$profdir/exhaustive-%p.profraw" "$build/exhaustive_test"
"$profdata" merge -sparse "$profdir"/*.profraw -o "$profdir/cov.profdata"
report() {
"$cov" report "$build/exhaustive_test" \
-instr-profile="$profdir/cov.profdata" src/fast.cpp
}
output="$(report)"
printf '%s\n' "$output"
line_cover="$(printf '%s\n' "$output" | awk '/fast\.cpp/ { print $10 }')"
branch_cover="$(printf '%s\n' "$output" | awk '/fast\.cpp/ { print $13 }')"
if [[ "$line_cover" != "100.00%" ]]; then
echo "fast.cpp line coverage is $line_cover, expected 100.00%" >&2
exit 1
fi
if [[ "$branch_cover" != "100.00%" ]]; then
echo "fast.cpp branch coverage is $branch_cover, expected 100.00%" >&2
exit 1
fi
echo "fast.cpp: 100.00% line and branch coverage"