2007-07-11 21:01:13 +04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# TestRunner.sh - This script is used to run arbitrary unit tests. Unit
|
|
|
|
# tests must contain the command used to run them in the input file, starting
|
|
|
|
# immediately after a "RUN:" string.
|
|
|
|
#
|
|
|
|
# This runner recognizes and replaces the following strings in the command:
|
|
|
|
#
|
|
|
|
# %s - Replaced with the input name of the program, or the program to
|
|
|
|
# execute, as appropriate.
|
|
|
|
# %prcontext - prcontext.tcl script
|
2008-03-21 01:50:54 +03:00
|
|
|
# %t - temporary file name (derived from testcase name)
|
2007-07-11 21:01:13 +04:00
|
|
|
#
|
|
|
|
|
|
|
|
FILENAME=$1
|
|
|
|
TESTNAME=$1
|
|
|
|
SUBST=$1
|
2007-11-28 22:16:54 +03:00
|
|
|
|
|
|
|
OUTPUT=Output/$1.out
|
2007-07-11 21:01:13 +04:00
|
|
|
|
|
|
|
# create the output directory if it does not already exist
|
2007-11-28 22:16:54 +03:00
|
|
|
mkdir -p `dirname $OUTPUT` > /dev/null 2>&1
|
2007-07-11 21:01:13 +04:00
|
|
|
|
|
|
|
if test $# != 1; then
|
|
|
|
# If more than one parameter is passed in, there must be three parameters:
|
|
|
|
# The filename to read from (already processed), the command used to execute,
|
|
|
|
# and the file to output to.
|
|
|
|
SUBST=$2
|
|
|
|
OUTPUT=$3
|
|
|
|
TESTNAME=$3
|
|
|
|
fi
|
|
|
|
|
|
|
|
ulimit -t 40
|
|
|
|
|
2007-12-12 09:19:22 +03:00
|
|
|
# Verify the script contains a run line.
|
|
|
|
grep -q 'RUN:' $FILENAME || (
|
|
|
|
echo "******************** TEST '$TESTNAME' HAS NO RUN LINE! ********************"
|
|
|
|
exit 1
|
|
|
|
)
|
|
|
|
|
2008-03-21 01:50:54 +03:00
|
|
|
# Run under valgrind if the VG environment variable has been set.
|
2008-07-25 05:05:44 +04:00
|
|
|
CLANG=$CLANG
|
2008-07-27 09:05:07 +04:00
|
|
|
if [ ! -n "$CLANG" ]; then
|
2008-07-25 05:05:44 +04:00
|
|
|
CLANG="clang"
|
|
|
|
fi
|
2008-03-21 01:50:54 +03:00
|
|
|
if [ -n "$VG" ]; then
|
2008-09-04 22:33:57 +04:00
|
|
|
rm -f $OUTPUT.vg
|
|
|
|
CLANG="valgrind --leak-check=full --quiet --log-file=$OUTPUT.vg $CLANG"
|
2008-03-21 01:50:54 +03:00
|
|
|
fi
|
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
SCRIPT=$OUTPUT.script
|
2008-03-17 16:45:47 +03:00
|
|
|
TEMPOUTPUT=$OUTPUT.tmp
|
2008-03-21 01:50:54 +03:00
|
|
|
grep 'RUN:' $FILENAME | \
|
|
|
|
sed -e "s|^.*RUN:\(.*\)$|\1|g" \
|
2008-09-04 22:33:57 +04:00
|
|
|
-e "s|clang|$CLANG|g" \
|
2008-03-21 01:50:54 +03:00
|
|
|
-e "s|%s|$SUBST|g" \
|
|
|
|
-e "s|%prcontext|prcontext.tcl|g" \
|
2008-09-04 22:33:57 +04:00
|
|
|
-e "s|%t|$TEMPOUTPUT|g" > $SCRIPT
|
2007-07-11 21:01:13 +04:00
|
|
|
|
2008-09-04 04:30:11 +04:00
|
|
|
IS_XFAIL=0
|
|
|
|
if (grep -q XFAIL $FILENAME); then
|
|
|
|
IS_XFAIL=1
|
|
|
|
printf "XFAILED '$TESTNAME': "
|
|
|
|
grep XFAIL $FILENAME
|
|
|
|
fi
|
2007-07-11 21:01:13 +04:00
|
|
|
|
2008-03-21 01:50:54 +03:00
|
|
|
/bin/sh $SCRIPT > $OUTPUT 2>&1
|
|
|
|
SCRIPT_STATUS=$?
|
|
|
|
|
|
|
|
if [ -n "$VG" ]; then
|
2008-09-04 22:33:57 +04:00
|
|
|
[ ! -s $OUTPUT.vg ]
|
|
|
|
VG_STATUS=$?
|
2008-03-21 01:50:54 +03:00
|
|
|
else
|
|
|
|
VG_STATUS=0
|
|
|
|
fi
|
|
|
|
|
2008-09-04 04:30:11 +04:00
|
|
|
if [ $IS_XFAIL -ne 0 ]; then
|
|
|
|
if [ $SCRIPT_STATUS -ne 0 ]; then
|
|
|
|
SCRIPT_STATUS=0
|
|
|
|
else
|
|
|
|
SCRIPT_STATUS=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2008-03-21 01:50:54 +03:00
|
|
|
if [ $SCRIPT_STATUS -ne 0 -o $VG_STATUS -ne 0 ]; then
|
2007-07-11 21:01:13 +04:00
|
|
|
echo "******************** TEST '$TESTNAME' FAILED! ********************"
|
|
|
|
echo "Command: "
|
|
|
|
cat $SCRIPT
|
2008-03-21 01:50:54 +03:00
|
|
|
if [ $SCRIPT_STATUS -eq 0 ]; then
|
|
|
|
echo "Output:"
|
2008-09-04 04:30:11 +04:00
|
|
|
elif [ $IS_XFAIL -ne 0 ]; then
|
|
|
|
echo "Incorrect Output (Expected Failure):"
|
2008-03-21 01:50:54 +03:00
|
|
|
else
|
|
|
|
echo "Incorrect Output:"
|
|
|
|
fi
|
2007-07-11 21:01:13 +04:00
|
|
|
cat $OUTPUT
|
2008-03-21 01:50:54 +03:00
|
|
|
if [ $VG_STATUS -ne 0 ]; then
|
|
|
|
echo "Valgrind Output:"
|
2008-09-04 22:33:57 +04:00
|
|
|
cat $OUTPUT.vg
|
2008-03-21 01:50:54 +03:00
|
|
|
fi
|
2007-07-11 21:01:13 +04:00
|
|
|
echo "******************** TEST '$TESTNAME' FAILED! ********************"
|
2008-03-17 15:35:00 +03:00
|
|
|
exit 1
|
2008-03-21 01:50:54 +03:00
|
|
|
fi
|