]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: move the logic to support /skipped into shared logic
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 23 Apr 2021 08:55:49 +0000 (10:55 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 23 Apr 2021 13:12:35 +0000 (15:12 +0200)
The logic to query test state was rather complex. I don't quite grok the point
of ret=$((ret+1))… But afaics, the precise result was always ignored by the
caller anyway.

test/TEST-02-UNITTESTS/test.sh
test/TEST-24-CRYPTSETUP/test.sh
test/TEST-55-OOMD/test.sh
test/test-functions

index 2bfe41a42b30fab27970dc834eefcd6577714ba0..f7545b7620cac10b868831907445ae4a61fd0e06 100755 (executable)
@@ -39,7 +39,7 @@ check_result_nspawn() {
     save_journal "$workspace/var/log/journal"
     _umount_dir "${initdir:?}"
 
-    [[ -n "${TIMED_OUT:=}" ]] && ret=$((ret + 1))
+    [[ -n "${TIMED_OUT:=}" ]] && ret=1
     return $ret
 }
 
@@ -67,7 +67,7 @@ check_result_qemu() {
     save_journal "$initdir/var/log/journal"
     _umount_dir "$initdir"
 
-    [[ -n "${TIMED_OUT:=}" ]] && ret=$((ret + 1))
+    [[ -n "${TIMED_OUT:=}" ]] && ret=1
     return $ret
 }
 
index e4d99d10b9e5d36fb26d311175ed43532624e4d9..109d403568c3d301c67528119d49158ff28ff2e3 100755 (executable)
@@ -26,7 +26,7 @@ check_result_qemu() {
     [[ -f "$TESTDIR/failed" ]] && cat "$TESTDIR/failed"
     echo "${JOURNAL_LIST:-No journals were saved}"
 
-    test -s "$TESTDIR/failed" && ret=$((ret + 1))
+    test -s "$TESTDIR/failed" && ret=1
     return $ret
 }
 
index 9f7a11aea46bbd2c9390c084694547bd360d2ea4..6f7e776c3c994062b85e7dc09e7442f226f44aa9 100755 (executable)
@@ -19,52 +19,4 @@ EOF
     )
 }
 
-check_result_nspawn() {
-    local workspace="${1:?}"
-    local ret=1
-    local journald_report=""
-    local pids=""
-
-    [[ -e "$workspace/testok" ]] && ret=0
-    if [[ -e "$workspace/skipped" ]]; then
-        echo "TEST-56-OOMD was skipped:"
-        cat "$workspace/skipped"
-        ret=0
-    fi
-
-    [[ -f "$workspace/failed" ]] && cp -a "$workspace/failed" "${TESTDIR:?}"
-    save_journal "$workspace/var/log/journal"
-    [[ -f "$TESTDIR/failed" ]] && cat "$TESTDIR/failed"
-    echo "${JOURNAL_LIST:-No journals were saved}"
-
-    test -s "$TESTDIR/failed" && ret=$((ret + 1))
-    [ -n "${TIMED_OUT:=}" ] && ret=$((ret + 1))
-    check_asan_reports "$workspace" || ret=$((ret + 1))
-    _umount_dir "${initdir:?}"
-    return $ret
-}
-
-check_result_qemu() {
-    local ret=1
-
-    mount_initdir
-    [[ -e "${initdir:?}/testok" ]] && ret=0
-    if [[ -e "$initdir/skipped" ]]; then
-        echo "TEST-56-OOMD was skipped:"
-        cat "$initdir/skipped"
-        ret=0
-    fi
-
-    [[ -f "$initdir/failed" ]] && cp -a "$initdir/failed" "${TESTDIR:?}"
-    save_journal "$initdir/var/log/journal"
-    check_asan_reports "$initdir" || ret=$((ret + 1))
-    _umount_dir "$initdir"
-    [[ -f "$TESTDIR/failed" ]] && cat "$TESTDIR/failed"
-    echo "${JOURNAL_LIST:-No journals were saved}"
-
-    test -s "$TESTDIR/failed" && ret=$((ret + 1))
-    [ -n "${TIMED_OUT:=}" ] && ret=$((ret + 1))
-    return $ret
-}
-
 do_test "$@" 55
index 6f11b2f1b279d025b2334f49dd7957c891b2171e..649d03b5afc0628b2b42db9f359f63b34bf89d34 100644 (file)
@@ -1118,42 +1118,66 @@ save_journal() {
     JOURNAL_LIST="$(ls -l "$dest"*)"
 }
 
-check_result_nspawn() {
+check_result_common() {
     local workspace="${1:?}"
-    local ret=1
-    local journald_report=""
-    local pids=""
-    [[ -e "$workspace/testok" ]] && ret=0
-    [[ -f "$workspace/failed" ]] && cp -a "$workspace/failed" "${TESTDIR:?}"
+    local ret
+
+    if [ -s "$workspace/failed" ]; then
+        # …/failed only counts if non-empty
+        ls -l "$workspace/failed"
+        cp -a "$workspace/failed" "${TESTDIR:?}/"
+        ret=1
+    elif [ -e "$workspace/testok" ]; then
+        # …/testok always counts (but with lower priority than …/failed)
+        ret=0
+    elif [ -e "$workspace/skipped" ]; then
+        # …/skipped always counts (a message is expected)
+        echo "${TESTNAME:?} was skipped:"
+        cat "$workspace/skipped"
+        ret=0
+    elif [ -n "$TIMED_OUT" ]; then
+        echo "${TESTNAME:?} timed out!"
+        ret=2
+    else
+        echo "${TESTNAME:?} did not report a result!"
+    fi
+
     save_journal "$workspace/var/log/journal"
-    [[ -f "$TESTDIR/failed" ]] && cat "$TESTDIR/failed"
-    echo "${JOURNAL_LIST:-"No journals were saved"}"
-    test -s "$TESTDIR/failed" && ret=$((ret+1))
-    [ -n "$TIMED_OUT" ] && ret=$((ret+1))
-    check_asan_reports "$workspace" || ret=$((ret+1))
+
+    check_asan_reports "$workspace" || ret=3
+
     if [ -d "${ARTIFACT_DIRECTORY}" ] && [ -f "$workspace/strace.out" ]; then
         cp "$workspace/strace.out" "${ARTIFACT_DIRECTORY}/"
     fi
+
+    [ -f "$TESTDIR/failed" ] && cat "$TESTDIR/failed"
+    echo "${JOURNAL_LIST:-"No journals were saved"}"
+
+    return $ret
+}
+
+check_result_nspawn() {
+    local workspace="${1:?}"
+    local ret
+
+    check_result_common "${workspace}"
+    ret=$?
+
     _umount_dir "${initdir:?}"
+
     return $ret
 }
 
 # can be overridden in specific test
 check_result_qemu() {
-    local ret=1
+    local ret
     mount_initdir
-    [[ -e "${initdir:?}/testok" ]] && ret=0
-    [[ -f "$initdir/failed" ]] && cp -a "$initdir/failed" "${TESTDIR:?}"
-    save_journal "$initdir/var/log/journal"
-    check_asan_reports "$initdir" || ret=$((ret+1))
-    if [ -d "${ARTIFACT_DIRECTORY}" ] && [ -f "$initdir/strace.out" ]; then
-        cp "$initdir/strace.out" "${ARTIFACT_DIRECTORY}/"
-    fi
-    _umount_dir "$initdir"
-    [[ -f "$TESTDIR/failed" ]] && cat "$TESTDIR/failed"
-    echo "${JOURNAL_LIST:-"No journals were saved"}"
-    test -s "$TESTDIR/failed" && ret=$((ret+1))
-    [ -n "$TIMED_OUT" ] && ret=$((ret+1))
+
+    check_result_common "${initdir:?}"
+    ret=$?
+
+    _umount_dir "${initdir:?}"
+
     return $ret
 }
 
@@ -2208,7 +2232,7 @@ instmods() {
                 ((ret+=$?))
                 ;;
         esac
-        return $ret
+        return "$ret"
     }
 
     local mod mpargs