From 6ee3b7ed1ff74c4d529d6eaabb237fe24810f4fa Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 22 Jul 2021 11:08:30 +0200 Subject: [PATCH] More robust failure detection for the coverage report generation The previous implementation was hard to understand and could in principle fail to notice if there was a test case failure and the writing of the line "Note: $TOTAL_FAIL failures." failed. KISS. Signed-off-by: Gilles Peskine --- tests/scripts/basic-build-test.sh | 32 ++++++++++--------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh index 96f9c47ad..2be62b43d 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -156,6 +156,11 @@ echo "=========================================================================" echo "Test Report Summary" echo +# A failure of the left-hand side of a pipe is ignored (this is a limitation +# of sh). We'll use the presence of this file as a marker that the generation +# of the report succeeded. +rm -f "basic-build-test-$$.ok" + { cd tests @@ -267,13 +272,7 @@ echo echo "Branches Tested : $BRANCHES_TESTED of $BRANCHES_TOTAL $BRANCHES_PERCENT%" echo - # If there was a failure, remind the reader here. This also ensures that - # the coverage summary ends with a distinctive mark so that this script - # knows to exit with a failure status. - if [ $TOTAL_FAIL -ne 0 ]; then - echo "Note: $TOTAL_FAIL failures." - fi - + touch "basic-build-test-$$.ok" } | tee coverage-summary.txt make clean @@ -282,18 +281,7 @@ if [ -f "$CONFIG_BAK" ]; then mv "$CONFIG_BAK" "$CONFIG_H" fi -# If the coverage summary doesn't end with the expected last two lines -# ("Branches Tested" and a blank line), either there was an error while -# creating the coverage summary or the coverage summary reported failures. -# The script runs under `set -e`, so most failures cause it to abort, -# but failures on the left-hand side of a pipe are not detected (this is -# a limitation of sh), so we check that the left-hand side of the pipe -# succeeded by checking that it took the last action that it was expected -# to take. -newline=' -' -case "$(tail -n2 coverage-summary.txt)" in - *"$newline"*) exit 1;; # last line was not blank - "Branches Tested"*) :;; # looks good - *) exit 1;; # next-to-last line had unexpected content -esac +# The file must exist, otherwise it means something went wrong while generating +# the coverage report. If something did go wrong, rm will complain so this +# script will exit with a failure status. +rm "basic-build-test-$$.ok"