test: properly catch tests error with no /testok or empty /failed

When editing this function in 7bf20e48bd, 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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-04-29 09:13:12 +02:00
parent 3796bdc55d
commit c0d4409219

View 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() {