]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: create and merge code coverage reports in integration tests
authorLuca Boccassi <luca.boccassi@microsoft.com>
Sun, 3 Oct 2021 15:50:38 +0000 (16:50 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 4 Oct 2021 15:40:49 +0000 (16:40 +0100)
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.

test/run-integration-tests.sh
test/test-functions

index 89058f4aca68f2a362241dbecee4d3abd1c43a12..6746d94ffef21771d74787c84b098dd9149e3c33 100755 (executable)
@@ -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"
index 31eb86f2bd3b7564a13ee0c42bc4e0dd3f2322ec..bb205cd31feda44b40588db29651d2ccff2240dc 100644 (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