From 48885161c24cb13afc051e1961e80bbfb62cafee Mon Sep 17 00:00:00 2001 From: Samuel Breese Date: Mon, 13 Jan 2020 12:52:18 -0500 Subject: [PATCH 1/2] Update runtests.sh to properly handle SIGINT, cleanup for shellcheck --- intTests/runtests.sh | 84 +++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/intTests/runtests.sh b/intTests/runtests.sh index 82e5736a45..227029bb9d 100755 --- a/intTests/runtests.sh +++ b/intTests/runtests.sh @@ -3,9 +3,29 @@ ################################################################ # Setup environment. +trap "finish" SIGINT + +finish() { + echo "tests passed: ${PASSED_TESTS} / ${NUM_TESTS}" + if [ "${PASSED_TESTS}" == "${NUM_TESTS}" ]; then + echo "all tests passed" + exit 0 + else + if [ "${FAILED_TESTS}" != 0 ]; then + echo "${FAILED_TEST_DETAILS}" + fi + if [ -z "$DONE" ]; then + echo "interrupted: $i" + fi + exit 1 + fi +} + if [ -z "$TESTBASE" ]; then - export TESTBASE=`pwd` + TESTBASE=$(pwd) + export TESTBASE fi + JSS_BASE=$TESTBASE/../deps/jvm-verifier # define the BIN variable, if not already defined @@ -52,7 +72,7 @@ export SAW="eval saw -j '$CP'" export JSS="eval jss -j '$CP' -c ." # Figure out what tests to run -if [[ -z "$@" ]]; then +if [[ -z "$*" ]]; then if [ -z "$DISABLED_TESTS" ]; then # File listing tests disabled by default. DISABLED_TESTS=disabled_tests.txt @@ -61,13 +81,13 @@ if [[ -z "$@" ]]; then TESTS="" for t in test*; do if ! grep -q "^$t\$" $DISABLED_TESTS; then - TESTS="$TESTS $t" + TESTS="$TESTS $t" fi done else # Default disabled tests are ignored when specific tests are # specified on the command line. - TESTS=$@ + TESTS=$* fi if [ -z "${TEST_TIMEOUT}" ]; then @@ -85,63 +105,69 @@ XML_TEMP="${XML_FILE}.tmp" mkdir -p logs rm -f logs/* -NUM_TESTS=0 +NUM_TESTS=$(echo "$TESTS" | wc -w) +PASSED_TESTS=0 FAILED_TESTS=0 FAILED_TEST_DETAILS="failed:" export TIMEFORMAT="%R" TOTAL_TIME=0 for i in $TESTS; do - NUM_TESTS=$(( $NUM_TESTS + 1 )) - # Some nasty bash hacking here to catpure the amount of time taken by the test # See http://mywiki.wooledge.org/BashFAQ/032 START_TIME=$SECONDS if [ "${OS}" == "Windows_NT" ]; then # ulimit is useless on cygwin :-( Use the 'timeout' utility instead - (cd $i; (/usr/bin/timeout -k 15 ${TEST_TIMEOUT} sh -vx test.sh > ../logs/$i.log 2>&1) 2>&1 ) + ( cd "$i" || exit 1; (/usr/bin/timeout -k 15 ${TEST_TIMEOUT} sh -vx test.sh > "../logs/$i.log" 2>&1) 2>&1 ) RES=$? else - (ulimit -t ${TEST_TIMEOUT}; cd $i; (sh -vx test.sh > ../logs/$i.log 2>&1) 2>&1 ) + ( ulimit -t ${TEST_TIMEOUT}; cd "$i" || exit 1; (sh -vx test.sh > "../logs/$i.log" 2>&1) 2>&1 ) RES=$? fi END_TIME=$SECONDS - TEST_TIME=$(expr $END_TIME - $START_TIME) + TEST_TIME=$((END_TIME - START_TIME)) - if [ $(expr $TEST_TIME ">=" $TEST_TIMEOUT) == 1 ]; then + if [ $((TEST_TIME >= TEST_TIMEOUT)) == 1 ]; then TIMED_OUT=" TIMEOUT" else TIMED_OUT="" fi - TOTAL_TIME=$(expr ${TOTAL_TIME} + ${TEST_TIME}) + TOTAL_TIME=$((TOTAL_TIME + TEST_TIME)) if [ $RES == 0 ]; then + PASSED_TESTS=$(( PASSED_TESTS + 1 )) echo "$i: OK (${TEST_TIME}s)" echo " " >> ${XML_TEMP} else + FAILED_TESTS=$(( FAILED_TESTS + 1 )) echo "$i: FAIL (${TEST_TIME}s${TIMED_OUT})" - if [ ! -z "$LOUD" ]; then cat logs/$i.log; fi - FAILED_TESTS=$(( $FAILED_TESTS + 1 )) + if [ -n "$LOUD" ]; then cat "logs/$i.log"; fi FAILED_TEST_DETAILS+=" $i" - echo " > ${XML_TEMP} - sed -e 's/]]>/] ]>/' logs/$i.log >> ${XML_TEMP} - echo "]]>" >> ${XML_TEMP} + { + echo " /] ]>/' "logs/$i.log" + echo "]]>" + } >> ${XML_TEMP} fi done +DONE=1 + echo "" > $XML_FILE -echo "" >> $XML_FILE -echo " " >> $XML_FILE -cat $XML_TEMP >> $XML_FILE -echo " " >> $XML_FILE -echo "" >> $XML_FILE +{ + echo "" + echo " " + cat $XML_TEMP + echo " " + echo "" +} >> $XML_FILE + rm $XML_TEMP -PASSED_TESTS=$(expr $NUM_TESTS - $FAILED_TESTS) -echo "tests passed: ${PASSED_TESTS} / ${NUM_TESTS}" -if [ "${FAILED_TESTS}" == 0 ]; then - echo "all tests passed" -else - echo "${FAILED_TEST_DETAILS}" -fi +finish; + +# Local Variables: +# sh-basic-offset: 2 +# indent-tabs-mode: nil +# End: From 40d25288b741a401071cbe7d917fe6ca9c952768 Mon Sep 17 00:00:00 2001 From: Samuel Breese Date: Mon, 13 Jan 2020 13:06:01 -0500 Subject: [PATCH 2/2] Remove Emacs file-local variables --- intTests/runtests.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/intTests/runtests.sh b/intTests/runtests.sh index 227029bb9d..69fac26e24 100755 --- a/intTests/runtests.sh +++ b/intTests/runtests.sh @@ -166,8 +166,3 @@ echo "" > $XML_FILE rm $XML_TEMP finish; - -# Local Variables: -# sh-basic-offset: 2 -# indent-tabs-mode: nil -# End: