From 7bf20e48bd7d641a39a14a7feb749b7e8b0fc0f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 23 Apr 2021 10:55:49 +0200 Subject: [PATCH] test: move the logic to support /skipped into shared logic MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 4 +- test/TEST-24-CRYPTSETUP/test.sh | 2 +- test/TEST-55-OOMD/test.sh | 48 --------------------- test/test-functions | 74 ++++++++++++++++++++++----------- 4 files changed, 52 insertions(+), 76 deletions(-) diff --git a/test/TEST-02-UNITTESTS/test.sh b/test/TEST-02-UNITTESTS/test.sh index 2bfe41a42b3..f7545b7620c 100755 --- a/test/TEST-02-UNITTESTS/test.sh +++ b/test/TEST-02-UNITTESTS/test.sh @@ -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 } diff --git a/test/TEST-24-CRYPTSETUP/test.sh b/test/TEST-24-CRYPTSETUP/test.sh index e4d99d10b9e..109d403568c 100755 --- a/test/TEST-24-CRYPTSETUP/test.sh +++ b/test/TEST-24-CRYPTSETUP/test.sh @@ -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 } diff --git a/test/TEST-55-OOMD/test.sh b/test/TEST-55-OOMD/test.sh index 9f7a11aea46..6f7e776c3c9 100755 --- a/test/TEST-55-OOMD/test.sh +++ b/test/TEST-55-OOMD/test.sh @@ -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 diff --git a/test/test-functions b/test/test-functions index 6f11b2f1b27..649d03b5afc 100644 --- a/test/test-functions +++ b/test/test-functions @@ -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 -- 2.39.2