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 <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2021-07-22 11:08:30 +02:00
parent a2df615e21
commit 5cf753ae02

View file

@ -160,6 +160,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
@ -271,13 +276,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
@ -286,18 +285,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"