]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: split logs from each test into separate files if requested 31735/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 12 Mar 2024 12:11:16 +0000 (13:11 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 12 Mar 2024 16:34:55 +0000 (17:34 +0100)
If both $ARTIFACT_DIRECTORY and $SPLIT_TEST_LOGS are set, split the
output from each test into a separate log file, so we don't have to load
one ginormous log file when checking the results.

test/run-integration-tests.sh

index 7587e826a807ada976eae56d10bc13519b9b8c2d..833f6093aae832090e1406352ac877718286037e 100755 (executable)
@@ -27,6 +27,25 @@ pass_deny_list() {
     return 0
 }
 
+test_run() {
+    local test_name="${1:?}"
+    shift
+
+    if [[ $# -eq 0 ]]; then
+        echo >&2 "test_run: missing arguments"
+        exit 1
+    fi
+
+    # Note: let's be very explicit in reporting the return code of the test command here, i.e don't rely on
+    #       `set -e` or the return code of the last statement in the function, since reporting false positive
+    #       would be very bad in this case.
+    if [[ "${SPLIT_TEST_LOGS:-0}" -ne 0 && -n "${ARTIFACT_DIRECTORY:-}" ]]; then
+        (set -x; "$@") &>>"$ARTIFACT_DIRECTORY/$test_name.log" || return $?
+    else
+        (set -x; "$@") || return $?
+    fi
+}
+
 ARGS=(setup run clean-again)
 CLEAN=0
 CLEAN_AGAIN=0
@@ -77,7 +96,7 @@ SELECTED_TESTS="${SELECTED_TESTS:-TEST-??-*}"
 # cache.
 if [[ $CLEAN -eq 1 ]]; then
     for test in $SELECTED_TESTS; do
-        (set -x; make -C "$test" clean)
+        test_run "$test" make -C "$test" clean
     done
 fi
 
@@ -91,7 +110,7 @@ if [[ ${#ARGS[@]} -ne 0 ]]; then
 
         echo -e "\n[$(date +%R:%S)] --x-- Running $test --x--"
         set +e
-        (set -x; make -C "$test" "${ARGS[@]}")
+        test_run "$test" make -C "$test" "${ARGS[@]}"
         result=$?
         set -e
         echo "[$(date +%R:%S)] --x-- Result of $test: $result --x--"
@@ -106,7 +125,7 @@ fi
 # Run clean-again, if requested, and if no tests failed
 if [[ $FAILURES -eq 0 && $CLEAN_AGAIN -eq 1 ]]; then
     for test in "${!RESULTS[@]}"; do
-        (set -x; make -C "$test" clean-again)
+        test_run "$test" make -C "$test" clean-again
     done
 fi