summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-04-23 10:55:49 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-04-23 15:12:35 +0200
commit7bf20e48bd7d641a39a14a7feb749b7e8b0fc0f6 (patch)
tree692aeb6cc46e1e433ecdea951402eb47a16516a1 /test
parent7b87fe4c30c3a5492ba409ebb13b1a5505c00a86 (diff)
downloadsystemd-7bf20e48bd7d641a39a14a7feb749b7e8b0fc0f6.tar.gz
test: move the logic to support /skipped into shared logic
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.
Diffstat (limited to 'test')
-rwxr-xr-xtest/TEST-02-UNITTESTS/test.sh4
-rwxr-xr-xtest/TEST-24-CRYPTSETUP/test.sh2
-rwxr-xr-xtest/TEST-55-OOMD/test.sh48
-rw-r--r--test/test-functions74
4 files changed, 52 insertions, 76 deletions
diff --git a/test/TEST-02-UNITTESTS/test.sh b/test/TEST-02-UNITTESTS/test.sh
index 2bfe41a42b..f7545b7620 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 e4d99d10b9..109d403568 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 9f7a11aea4..6f7e776c3c 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 6f11b2f1b2..649d03b5af 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