test: create and merge code coverage reports in integration tests

If -Db_coverage=true is used at build time, then ARTIFACT_DIRECTORY/TEST-XX-FOO.coverage-info
files are created with code coverage data, and run-integration-test.sh also
merges them into ARTIFACT_DIRECTORY/merged.coverage-info since the coveralls.io
helpers accept only a single file.
This commit is contained in:
Luca Boccassi 2021-10-03 16:50:38 +01:00 committed by Luca Boccassi
parent 9d0ad242b8
commit c82dc15b9f
2 changed files with 49 additions and 0 deletions

View file

@ -116,4 +116,17 @@ else
echo -e "\nTOTAL FAILURES: $FAILURES OF $COUNT"
fi
# If we have coverage files, merge them into a single report for upload
if [ -n "${ARTIFACT_DIRECTORY}" ]; then
lcov_args=()
while read -r info_file; do
lcov_args+=(--add-tracefile "${info_file}")
done < <(find "${ARTIFACT_DIRECTORY}" -maxdepth 1 -name "*.coverage-info")
if [ ${#lcov_args[@]} -gt 1 ]; then
lcov "${lcov_args[@]}" --output-file "${ARTIFACT_DIRECTORY}/merged.coverage-info"
fi
fi
exit "$FAILURES"

View file

@ -1012,6 +1012,13 @@ install_compiled_systemd() {
exit 1
fi
(set -x; DESTDIR="$initdir" "$ninja_bin" -C "$BUILD_DIR" install)
# If we are doing coverage runs, copy over the binary notes files, as lcov expects to
# find them in the same directory as the runtime data counts
if meson configure "${BUILD_DIR:?}" | grep 'b_coverage' | awk '{ print $2 }' | grep -q 'true'; then
mkdir -p "${initdir}/${BUILD_DIR:?}/"
rsync -am --include='*/' --include='*.gcno' --exclude='*' "${BUILD_DIR:?}/" "${initdir}/${BUILD_DIR:?}/"
fi
}
install_debian_systemd() {
@ -1170,6 +1177,9 @@ create_empty_image() {
if meson configure "${BUILD_DIR:?}" | grep 'link-.*-shared' | awk '{ print $2 }' | grep -q 'false'; then
size=$((size+=200))
fi
if meson configure "${BUILD_DIR:?}" | grep 'b_coverage' | awk '{ print $2 }' | grep -q 'true'; then
size=$((size+=250))
fi
fi
if ! get_bool "$STRIP_BINARIES"; then
size=$((4 * size))
@ -1272,6 +1282,30 @@ check_asan_reports() {
return $ret
}
check_coverage_reports() {
local root="${1:?}"
if get_bool "$NO_BUILD"; then
return 0
fi
if meson configure "${BUILD_DIR:?}" | grep 'b_coverage' | awk '{ print $2 }' | grep -q 'false'; then
return 0
fi
if [ -n "${ARTIFACT_DIRECTORY}" ]; then
dest="${ARTIFACT_DIRECTORY}/${testname:?}.coverage-info"
else
dest="${TESTDIR:?}/coverage-info"
fi
# Create a coverage report that will later be uploaded. Remove info about
# system libraries/headers, as we don't really care about them.
lcov --directory "${root}/${BUILD_DIR:?}" --capture --output-file "${dest}"
lcov --remove "${dest}" -o "${dest}" '/usr/include/*' '/usr/lib/*'
return 0
}
save_journal() {
# Default to always saving journal
local save="yes"
@ -1342,6 +1376,8 @@ check_result_common() {
check_asan_reports "$workspace" || ret=4
check_coverage_reports "$workspace" || ret=5
save_journal "$workspace/var/log/journal" $ret
if [ -d "${ARTIFACT_DIRECTORY}" ] && [ -f "$workspace/strace.out" ]; then