From 78c8e828e82fd458a3bbac0e290b20d77e990c91 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 9 Apr 2020 18:50:08 +0200 Subject: [PATCH 1/7] Add a few echo statements to make the logs easier to follow Signed-off-by: Gilles Peskine --- tests/scripts/basic-build-test.sh | 39 +++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh index b8f624256a6a..003c03aabd8d 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -123,28 +123,43 @@ cd tests if [ ! -f "seedfile" ]; then dd if=/dev/urandom of="seedfile" bs=64 count=1 fi +echo # Step 2a - Unit Tests (keep going even if some tests fail) +echo '################ Unit tests ################' perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT +echo '^^^^^^^^^^^^^^^^ Unit tests ^^^^^^^^^^^^^^^^' echo # Step 2b - System Tests (keep going even if some tests fail) +echo +echo '################ ssl-opt.sh ################' sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT +echo '^^^^^^^^^^^^^^^^ ssl-opt.sh ^^^^^^^^^^^^^^^^' echo # Step 2c - Compatibility tests (keep going even if some tests fail) -sh compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' | \ - tee compat-test-$TEST_OUTPUT -OPENSSL_CMD="$OPENSSL_LEGACY" \ - sh compat.sh -m 'ssl3' |tee -a compat-test-$TEST_OUTPUT -OPENSSL_CMD="$OPENSSL_LEGACY" \ - GNUTLS_CLI="$GNUTLS_LEGACY_CLI" \ - GNUTLS_SERV="$GNUTLS_LEGACY_SERV" \ - sh compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' | \ - tee -a compat-test-$TEST_OUTPUT -OPENSSL_CMD="$OPENSSL_NEXT" \ - sh compat.sh -e '^$' -f 'ARIA\|CHACHA' | \ - tee -a compat-test-$TEST_OUTPUT +echo '################ compat.sh ################' +{ + echo '#### compat.sh: Default versions' + sh compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' + echo + + echo '#### compat.sh: legacy (SSLv3)' + OPENSSL_CMD="$OPENSSL_LEGACY" sh compat.sh -m 'ssl3' + echo + + echo '#### compat.sh: legacy (null, DES, RC4)' + OPENSSL_CMD="$OPENSSL_LEGACY" \ + GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" \ + sh compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' + echo + + echo '#### compat.sh: next (ARIA, ChaCha)' + OPENSSL_CMD="$OPENSSL_NEXT" sh compat.sh -e '^$' -f 'ARIA\|CHACHA' + echo +} | tee compat-test-$TEST_OUTPUT +echo '^^^^^^^^^^^^^^^^ compat.sh ^^^^^^^^^^^^^^^^' echo # Step 3 - Process the coverage report From bd7222d526ce3824097034d94c16b774ef3edb65 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 13 Jul 2021 23:23:23 +0200 Subject: [PATCH 2/7] Only run an unbridled parallel make (make -j) if MAKEFLAGS is unset Signed-off-by: Gilles Peskine --- tests/scripts/basic-build-test.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh index 003c03aabd8d..40efbd76ffa7 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -89,6 +89,11 @@ fi : ${SEED:=1} export SEED +# if MAKEFLAGS is not set add the -j option to speed up invocations of make +if [ -z "${MAKEFLAGS+set}" ]; then + export MAKEFLAGS="-j" +fi + # To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh # we just export the variables they require export OPENSSL_CMD="$OPENSSL" @@ -113,7 +118,7 @@ export CFLAGS=' --coverage -g3 -O0 ' make clean cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full -make -j +make # Step 2 - Execute the tests From 499abc90f8a3b3bbb851a5617dd13b9c3c811ec6 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 13 Jul 2021 23:26:00 +0200 Subject: [PATCH 3/7] Show the udp_proxy seed in the console log Signed-off-by: Gilles Peskine --- tests/scripts/basic-build-test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh index 40efbd76ffa7..d5766210181d 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -139,6 +139,7 @@ echo # Step 2b - System Tests (keep going even if some tests fail) echo echo '################ ssl-opt.sh ################' +echo "ssl-opt.sh will use SEED=$SEED for udp_proxy" sh ssl-opt.sh |tee sys-test-$TEST_OUTPUT echo '^^^^^^^^^^^^^^^^ ssl-opt.sh ^^^^^^^^^^^^^^^^' echo From d9437e6863e4b8903aa51a5e0850835807514654 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 13 Jul 2021 23:27:01 +0200 Subject: [PATCH 4/7] Save the coverage report to a file Save the "Test Report Summary" to a file. This can help both CI scripts and human readers who want the summary after the fact without having to copy the console output. Take care to exit with a nonzero status if there is a failure while generating the test report summary. Signed-off-by: Gilles Peskine --- .gitignore | 1 + tests/scripts/basic-build-test.sh | 198 ++++++++++++++++-------------- 2 files changed, 108 insertions(+), 91 deletions(-) diff --git a/.gitignore b/.gitignore index 5fb0bdebf8d8..4837ebb88b7b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ Testing Coverage *.gcno *.gcda +coverage-summary.txt # generated by scripts/memory.sh massif-* diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh index d5766210181d..c225315920bc 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -187,116 +187,125 @@ echo "=========================================================================" echo "Test Report Summary" echo -cd tests +{ -# Step 4a - Unit tests -echo "Unit tests - tests/scripts/run-test-suites.pl" + cd tests -PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') -SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') -TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') -FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') + # Step 4a - Unit tests + echo "Unit tests - tests/scripts/run-test-suites.pl" -echo "No test suites : $TOTAL_SUITES" -echo "Passed : $PASSED_TESTS" -echo "Failed : $FAILED_TESTS" -echo "Skipped : $SKIPPED_TESTS" -echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))" -echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))" -echo + PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') + SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') + TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') + FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') -TOTAL_PASS=$PASSED_TESTS -TOTAL_FAIL=$FAILED_TESTS -TOTAL_SKIP=$SKIPPED_TESTS -TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) -TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS)) - -# Step 4b - TLS Options tests -echo "TLS Options tests - tests/ssl-opt.sh" - -PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p') -SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p') -TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p') -FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS)) - -echo "Passed : $PASSED_TESTS" -echo "Failed : $FAILED_TESTS" -echo "Skipped : $SKIPPED_TESTS" -echo "Total exec'd tests : $TOTAL_TESTS" -echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))" -echo + echo "No test suites : $TOTAL_SUITES" + echo "Passed : $PASSED_TESTS" + echo "Failed : $FAILED_TESTS" + echo "Skipped : $SKIPPED_TESTS" + echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))" + echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))" + echo -TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) -TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) -TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) -TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS)) -TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS)) + TOTAL_PASS=$PASSED_TESTS + TOTAL_FAIL=$FAILED_TESTS + TOTAL_SKIP=$SKIPPED_TESTS + TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) + TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS)) + + # Step 4b - TLS Options tests + echo "TLS Options tests - tests/ssl-opt.sh" + + PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p') + SKIPPED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p') + TOTAL_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p') + FAILED_TESTS=$(($TOTAL_TESTS - $PASSED_TESTS)) + + echo "Passed : $PASSED_TESTS" + echo "Failed : $FAILED_TESTS" + echo "Skipped : $SKIPPED_TESTS" + echo "Total exec'd tests : $TOTAL_TESTS" + echo "Total avail tests : $(($TOTAL_TESTS + $SKIPPED_TESTS))" + echo + TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) + TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) + TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) + TOTAL_AVAIL=$(($TOTAL_AVAIL + $TOTAL_TESTS + $SKIPPED_TESTS)) + TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS)) -# Step 4c - System Compatibility tests -echo "System/Compatibility tests - tests/compat.sh" -PASSED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') -SKIPPED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') -EXED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') -FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS)) + # Step 4c - System Compatibility tests + echo "System/Compatibility tests - tests/compat.sh" -echo "Passed : $PASSED_TESTS" -echo "Failed : $FAILED_TESTS" -echo "Skipped : $SKIPPED_TESTS" -echo "Total exec'd tests : $EXED_TESTS" -echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))" -echo + PASSED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') + SKIPPED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* ([0-9]* \/ [0-9]* tests (\([0-9]*\) skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') + EXED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* ([0-9]* \/ \([0-9]*\) tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') + FAILED_TESTS=$(($EXED_TESTS - $PASSED_TESTS)) -TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) -TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) -TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) -TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS)) -TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS)) + echo "Passed : $PASSED_TESTS" + echo "Failed : $FAILED_TESTS" + echo "Skipped : $SKIPPED_TESTS" + echo "Total exec'd tests : $EXED_TESTS" + echo "Total avail tests : $(($EXED_TESTS + $SKIPPED_TESTS))" + echo + TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) + TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) + TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) + TOTAL_AVAIL=$(($TOTAL_AVAIL + $EXED_TESTS + $SKIPPED_TESTS)) + TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS)) -# Step 4d - Grand totals -echo "-------------------------------------------------------------------------" -echo "Total tests" -echo "Total Passed : $TOTAL_PASS" -echo "Total Failed : $TOTAL_FAIL" -echo "Total Skipped : $TOTAL_SKIP" -echo "Total exec'd tests : $TOTAL_EXED" -echo "Total avail tests : $TOTAL_AVAIL" -echo + # Step 4d - Grand totals + echo "-------------------------------------------------------------------------" + echo "Total tests" + echo "Total Passed : $TOTAL_PASS" + echo "Total Failed : $TOTAL_FAIL" + echo "Total Skipped : $TOTAL_SKIP" + echo "Total exec'd tests : $TOTAL_EXED" + echo "Total avail tests : $TOTAL_AVAIL" + echo -# Step 4e - Coverage -echo "Coverage" -LINES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p') -LINES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p') -FUNCS_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p') -FUNCS_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p') -BRANCHES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* branches)$/\1/p') -BRANCHES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) branches)$/\1/p') + # Step 4e - Coverage + echo "Coverage" -LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL)) -LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))" + LINES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* lines)/\1/p') + LINES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ lines......: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) lines)/\1/p') + FUNCS_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* functions)$/\1/p') + FUNCS_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ functions..: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) functions)$/\1/p') + BRANCHES_TESTED=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% (\([0-9]*\) of [0-9]* branches)$/\1/p') + BRANCHES_TOTAL=$(tail -n4 cov-$TEST_OUTPUT|sed -n -e 's/ branches...: [0-9]*.[0-9]% ([0-9]* of \([0-9]*\) branches)$/\1/p') -FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL)) -FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))" + LINES_PERCENT=$((1000*$LINES_TESTED/$LINES_TOTAL)) + LINES_PERCENT="$(($LINES_PERCENT/10)).$(($LINES_PERCENT-($LINES_PERCENT/10)*10))" -BRANCHES_PERCENT=$((1000*$BRANCHES_TESTED/$BRANCHES_TOTAL)) -BRANCHES_PERCENT="$(($BRANCHES_PERCENT/10)).$(($BRANCHES_PERCENT-($BRANCHES_PERCENT/10)*10))" + FUNCS_PERCENT=$((1000*$FUNCS_TESTED/$FUNCS_TOTAL)) + FUNCS_PERCENT="$(($FUNCS_PERCENT/10)).$(($FUNCS_PERCENT-($FUNCS_PERCENT/10)*10))" -echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%" -echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%" -echo "Branches Tested : $BRANCHES_TESTED of $BRANCHES_TOTAL $BRANCHES_PERCENT%" -echo + BRANCHES_PERCENT=$((1000*$BRANCHES_TESTED/$BRANCHES_TOTAL)) + BRANCHES_PERCENT="$(($BRANCHES_PERCENT/10)).$(($BRANCHES_PERCENT-($BRANCHES_PERCENT/10)*10))" -rm unit-test-$TEST_OUTPUT -rm sys-test-$TEST_OUTPUT -rm compat-test-$TEST_OUTPUT -rm cov-$TEST_OUTPUT + rm unit-test-$TEST_OUTPUT + rm sys-test-$TEST_OUTPUT + rm compat-test-$TEST_OUTPUT + rm cov-$TEST_OUTPUT -cd .. + echo "Lines Tested : $LINES_TESTED of $LINES_TOTAL $LINES_PERCENT%" + echo "Functions Tested : $FUNCS_TESTED of $FUNCS_TOTAL $FUNCS_PERCENT%" + 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 + +} | tee coverage-summary.txt make clean @@ -304,6 +313,13 @@ if [ -f "$CONFIG_BAK" ]; then mv "$CONFIG_BAK" "$CONFIG_H" fi -if [ $TOTAL_FAIL -ne 0 ]; then - exit 1 -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. +newline=' +' +case "$(tail -n2 coverage-summary.txt)" in + *"$newline"*) exit 1;; + "Branches Tested"*) :;; + *) exit 1;; +esac From 3a8d854d73c20da4d7012abb27da1902c555a3df Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 22 Jul 2021 10:56:39 +0200 Subject: [PATCH 5/7] Explain the final error checking Signed-off-by: Gilles Peskine --- tests/scripts/basic-build-test.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh index c225315920bc..aae25fe95820 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -316,10 +316,15 @@ 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;; - "Branches Tested"*) :;; - *) exit 1;; + *"$newline"*) exit 1;; # last line was not blank + "Branches Tested"*) :;; # looks good + *) exit 1;; # next-to-last line had unexpected content esac From a6b4582add4aa15ba11ba5a8240c052e805d58c1 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 22 Jul 2021 11:08:30 +0200 Subject: [PATCH 6/7] 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 aae25fe95820..b8267cefda16 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -187,6 +187,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 @@ -298,13 +303,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 @@ -313,18 +312,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" From 31bf22c06a706833535f0e45f9225fe265daad13 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 22 Jul 2021 12:29:27 +0200 Subject: [PATCH 7/7] Fix mixup about the directory containing the success indicator file Signed-off-by: Gilles Peskine --- tests/scripts/basic-build-test.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh index b8267cefda16..67812841f7b9 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -190,7 +190,7 @@ 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" +rm -f "tests/basic-build-test-$$.ok" { @@ -303,6 +303,8 @@ rm -f "basic-build-test-$$.ok" echo "Branches Tested : $BRANCHES_TESTED of $BRANCHES_TOTAL $BRANCHES_PERCENT%" echo + # Mark the report generation as having succeeded. This must be the + # last thing in the report generation. touch "basic-build-test-$$.ok" } | tee coverage-summary.txt @@ -315,4 +317,4 @@ fi # 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" +rm "tests/basic-build-test-$$.ok"