Nostro/tests/coverage.sh

42 lines
1.8 KiB
Shell
Raw Normal View History

2026-11-01 18:35:23 +01:00
#!/bin/sh
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
# Runs the tests built with clang's source-based coverage and reports it for nostro's own sources, then lists every
# line no test ran. Needs crafter-build, llvm-profdata, llvm-cov and llvm-readelf on PATH. A toolchain without compiler-rt's profile
# runtime takes its libclang_rt.profile archive as the first argument. Leaves the profiles and the annotated sources in
# build/coverage/.
set -eu
cd "$(dirname "$0")/.."
out=build/coverage
rm -rf "$out"
mkdir -p "$out"
if [ $# -gt 0 ]; then
LLVM_PROFILE_FILE="$PWD/$out/%p.profraw" crafter-build test --banks=bunq --coverage "--profile-runtime=$1"
else
LLVM_PROFILE_FILE="$PWD/$out/%p.profraw" crafter-build test --banks=bunq --coverage
fi
llvm-profdata merge -sparse "$out"/*.profraw -o "$out/nostro.profdata"
# Each test's newest build with coverage mappings in it: a plain build can be newer, and a test whose sources did not
# change is not linked again.
set --
for test in tests/Should*/; do
name=$(basename "$test")
for binary in $(ls -t bin/"$name"-*/"$name"); do
if llvm-readelf -S "$binary" | grep -q __llvm_covfun; then
if [ $# -eq 0 ]; then
set -- "$binary"
else
set -- "$@" -object "$binary"
fi
break
fi
done
done
ignore='(lib/json\.hpp|/tests/|/Crafter\.|/app/|/usr/)'
llvm-cov report "$@" -instr-profile="$out/nostro.profdata" -ignore-filename-regex="$ignore"
llvm-cov show "$@" -instr-profile="$out/nostro.profdata" -ignore-filename-regex="$ignore" -format=text > "$out/sources.txt"
awk '/^\/.*:$/ { file = $0 } /^ *[0-9]+\| *0\|/ { split($0, part, "|"); gsub(/ /, "", part[1]); print "not run: " file part[1] }' "$out/sources.txt"