From c0d440921922ca5f10b1feb196cf5d2f90143b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 29 Apr 2021 09:13:12 +0200 Subject: [PATCH] test: properly catch tests error with no /testok or empty /failed 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 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/test-functions b/test/test-functions index 8bae7a9911e..eb0a3e33271 100644 --- a/test/test-functions +++ b/test/test-functions @@ -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() {