]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: properly catch tests error with no /testok or empty /failed
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 29 Apr 2021 07:13:12 +0000 (09:13 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 4 May 2021 11:36:05 +0000 (13:36 +0200)
When editing this function in 7bf20e48bd7d641a39a14a7feb749b7e8, I couldn't
decide whether to initialize ret at the top and only reset it on success, or
whether to assign a value in each branch. In the end I did neither ;( So if the
test finished without creating any of the result files, we would echo a
message, but return "success".

But there was bigger confusion with /failed: some tests create it empty, some
don't. I think we may want to do away pre-creation of /failed completely, and
assume the test failed unless /testok is found. But I'm leaving that for later
rework. For now let's just make sure we report return success only if /testok
or /skipped is found.

test/test-functions

index 8bae7a9911e3dd1d4a89466cc7a28c8e6b96ad9d..eb0a3e332711823c9b9aef7bd7d49305928b98ce 100644 (file)
@@ -1134,8 +1134,7 @@ check_result_common() {
     local ret
 
     if [ -s "$workspace/failed" ]; then
-        # …/failed only counts if non-empty
-        ls -l "$workspace/failed"
+        # Non-empty …/failed has highest priority
         cp -a "$workspace/failed" "${TESTDIR:?}/"
         ret=1
     elif [ -e "$workspace/testok" ]; then
@@ -1147,24 +1146,28 @@ check_result_common() {
         cat "$workspace/skipped"
         ret=0
     elif [ -n "$TIMED_OUT" ]; then
-        echo "${TESTNAME:?} timed out!"
+        echo "(timeout)" >"${TESTDIR:?}/failed"
         ret=2
     else
-        echo "${TESTNAME:?} did not report a result!"
+        echo "(failed; see logs)" >"${TESTDIR:?}/failed"
+        ret=3
     fi
 
     save_journal "$workspace/var/log/journal"
 
-    check_asan_reports "$workspace" || ret=3
+    check_asan_reports "$workspace" || ret=4
 
     if [ -d "${ARTIFACT_DIRECTORY}" ] && [ -f "$workspace/strace.out" ]; then
         cp "$workspace/strace.out" "${ARTIFACT_DIRECTORY}/"
     fi
 
-    [ -f "$TESTDIR/failed" ] && cat "$TESTDIR/failed"
+    if [ ${ret:?} != 0 ] && [ -f "$TESTDIR/failed" ]; then
+        echo -n "${TESTNAME:?}: "
+        cat "$TESTDIR/failed"
+    fi
     echo "${JOURNAL_LIST:-"No journals were saved"}"
 
-    return $ret
+    return ${ret:?}
 }
 
 check_result_nspawn() {