summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2021-10-03 16:50:38 +0100
committerLuca Boccassi <luca.boccassi@gmail.com>2021-10-04 16:40:49 +0100
commitc82dc15b9fcc8fde17d48d3beaec650ecda5bbbf (patch)
treed245c91271e162d33e812ee7841d74583a793853 /test
parent9d0ad242b84ccf08a370aa019c638300429ad5eb (diff)
downloadsystemd-c82dc15b9fcc8fde17d48d3beaec650ecda5bbbf.tar.gz
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.
Diffstat (limited to 'test')
-rwxr-xr-xtest/run-integration-tests.sh13
-rw-r--r--test/test-functions36
2 files changed, 49 insertions, 0 deletions
diff --git a/test/run-integration-tests.sh b/test/run-integration-tests.sh
index 89058f4aca..6746d94ffe 100755
--- a/test/run-integration-tests.sh
+++ b/test/run-integration-tests.sh
@@ -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"
diff --git a/test/test-functions b/test/test-functions
index 31eb86f2bd..bb205cd31f 100644
--- a/test/test-functions
+++ b/test/test-functions
@@ -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