Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update runtests.sh to properly handle SIGINT, cleanup for ShellCheck #627

Merged
merged 4 commits into from
Jan 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 50 additions & 29 deletions intTests/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -85,63 +105,64 @@ 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 " <testcase name=\"${i}\" time=\"${TEST_TIME}\" />" >> ${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 " <testcase name=\"${i}\" time=\"${TEST_TIME}\"><failure><![CDATA[" >> ${XML_TEMP}
sed -e 's/]]>/] ]>/' logs/$i.log >> ${XML_TEMP}
echo "]]></failure></testcase>" >> ${XML_TEMP}
{
echo " <testcase name=\"${i}\" time=\"${TEST_TIME}\"><failure><![CDATA["
sed -e 's/]]>/] ]>/' "logs/$i.log"
echo "]]></failure></testcase>"
} >> ${XML_TEMP}
fi
done

DONE=1

echo "<?xml version='1.0'?>" > $XML_FILE
echo "<testsuites errors=\"${FAILED_TESTS}\" tests=\"${NUM_TESTS}\" time=\"${TOTAL_TIME}\">" >> $XML_FILE
echo " <testsuite name=\"SAWScript Integration Tests\">" >> $XML_FILE
cat $XML_TEMP >> $XML_FILE
echo " </testsuite>" >> $XML_FILE
echo "</testsuites>" >> $XML_FILE
{
echo "<testsuites errors=\"${FAILED_TESTS}\" tests=\"${NUM_TESTS}\" time=\"${TOTAL_TIME}\">"
echo " <testsuite name=\"SAWScript Integration Tests\">"
cat $XML_TEMP
echo " </testsuite>"
echo "</testsuites>"
} >> $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;