]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: optionally, only save test journal for failing tests
authorDan Streetman <ddstreet@canonical.com>
Fri, 2 Jul 2021 14:38:14 +0000 (10:38 -0400)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 3 Jul 2021 09:48:31 +0000 (10:48 +0100)
Saving the journal for passing tests creates a huge amount of unneeded
data stored for each full test run. Add a env var to allow saving the
journal only for failed tests.

test/test-functions

index 3451e16d9ade4fa32d2ff9ec0d7cac8b9d6efd0d..795f71564521a70bfa136e8625e8e19654e396bd 100644 (file)
@@ -1117,6 +1117,15 @@ check_asan_reports() {
 }
 
 save_journal() {
+    # Default to always saving journal
+    local save="yes"
+
+    if [ "${TEST_SAVE_JOURNAL}" = "no" ]; then
+        save="no"
+    elif [ "${TEST_SAVE_JOURNAL}" = "fail" ] && [ "$2" = "0" ]; then
+        save="no"
+    fi
+
     if [ -n "${ARTIFACT_DIRECTORY}" ]; then
         dest="${ARTIFACT_DIRECTORY}/${testname:?}.journal"
     else
@@ -1124,9 +1133,9 @@ save_journal() {
     fi
 
     for j in "${1:?}"/*; do
-        "$SYSTEMD_JOURNAL_REMOTE" \
-            -o "$dest" \
-            --getter="$JOURNALCTL -o export -D $j"
+        if [ "$save" = "yes" ]; then
+            "$SYSTEMD_JOURNAL_REMOTE" -o "$dest" --getter="$JOURNALCTL -o export -D $j"
+        fi
 
         if [ -n "${TEST_SHOW_JOURNAL}" ]; then
             echo "---- $j ----"
@@ -1136,6 +1145,10 @@ save_journal() {
         rm -r "$j"
     done
 
+    if [ "$save" != "yes" ]; then
+        return 0
+    fi
+
     if [ -n "${SUDO_USER}" ]; then
         setfacl -m "user:${SUDO_USER:?}:r-X" "$dest"*
     fi
@@ -1171,10 +1184,10 @@ check_result_common() {
         ret=3
     fi
 
-    save_journal "$workspace/var/log/journal"
-
     check_asan_reports "$workspace" || ret=4
 
+    save_journal "$workspace/var/log/journal" $ret
+
     if [ -d "${ARTIFACT_DIRECTORY}" ] && [ -f "$workspace/strace.out" ]; then
         cp "$workspace/strace.out" "${ARTIFACT_DIRECTORY}/"
     fi
@@ -1252,10 +1265,12 @@ check_result_nspawn_unittests() {
         fi
     fi
 
-    save_journal "$workspace/var/log/journal"
+    [[ -n "${TIMED_OUT:=}" ]] && ret=1
+
+    save_journal "$workspace/var/log/journal" $ret
+
     _umount_dir "${initdir:?}"
 
-    [[ -n "${TIMED_OUT:=}" ]] && ret=1
     return $ret
 }
 
@@ -1282,10 +1297,12 @@ check_result_qemu_unittests() {
         fi
     fi
 
-    save_journal "$initdir/var/log/journal"
+    [[ -n "${TIMED_OUT:=}" ]] && ret=1
+
+    save_journal "$initdir/var/log/journal" $ret
+
     _umount_dir "$initdir"
 
-    [[ -n "${TIMED_OUT:=}" ]] && ret=1
     return $ret
 }