From: Frantisek Sumsal Date: Tue, 12 Mar 2024 12:11:16 +0000 (+0100) Subject: test: split logs from each test into separate files if requested X-Git-Tag: v256-rc1~561^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F31735%2Fhead;p=thirdparty%2Fsystemd.git test: split logs from each test into separate files if requested If both $ARTIFACT_DIRECTORY and $SPLIT_TEST_LOGS are set, split the output from each test into a separate log file, so we don't have to load one ginormous log file when checking the results. --- diff --git a/test/run-integration-tests.sh b/test/run-integration-tests.sh index 7587e826a80..833f6093aae 100755 --- a/test/run-integration-tests.sh +++ b/test/run-integration-tests.sh @@ -27,6 +27,25 @@ pass_deny_list() { return 0 } +test_run() { + local test_name="${1:?}" + shift + + if [[ $# -eq 0 ]]; then + echo >&2 "test_run: missing arguments" + exit 1 + fi + + # Note: let's be very explicit in reporting the return code of the test command here, i.e don't rely on + # `set -e` or the return code of the last statement in the function, since reporting false positive + # would be very bad in this case. + if [[ "${SPLIT_TEST_LOGS:-0}" -ne 0 && -n "${ARTIFACT_DIRECTORY:-}" ]]; then + (set -x; "$@") &>>"$ARTIFACT_DIRECTORY/$test_name.log" || return $? + else + (set -x; "$@") || return $? + fi +} + ARGS=(setup run clean-again) CLEAN=0 CLEAN_AGAIN=0 @@ -77,7 +96,7 @@ SELECTED_TESTS="${SELECTED_TESTS:-TEST-??-*}" # cache. if [[ $CLEAN -eq 1 ]]; then for test in $SELECTED_TESTS; do - (set -x; make -C "$test" clean) + test_run "$test" make -C "$test" clean done fi @@ -91,7 +110,7 @@ if [[ ${#ARGS[@]} -ne 0 ]]; then echo -e "\n[$(date +%R:%S)] --x-- Running $test --x--" set +e - (set -x; make -C "$test" "${ARGS[@]}") + test_run "$test" make -C "$test" "${ARGS[@]}" result=$? set -e echo "[$(date +%R:%S)] --x-- Result of $test: $result --x--" @@ -106,7 +125,7 @@ fi # Run clean-again, if requested, and if no tests failed if [[ $FAILURES -eq 0 && $CLEAN_AGAIN -eq 1 ]]; then for test in "${!RESULTS[@]}"; do - (set -x; make -C "$test" clean-again) + test_run "$test" make -C "$test" clean-again done fi