Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # TestRunner.sh - This script is used to run arbitrary unit tests. Unit |
| 4 | # tests must contain the command used to run them in the input file, starting |
| 5 | # immediately after a "RUN:" string. |
| 6 | # |
| 7 | # This runner recognizes and replaces the following strings in the command: |
| 8 | # |
| 9 | # %s - Replaced with the input name of the program, or the program to |
| 10 | # execute, as appropriate. |
| 11 | # %llvmgcc - llvm-gcc command |
| 12 | # %llvmgxx - llvm-g++ command |
| 13 | # %prcontext - prcontext.tcl script |
Gabor Greif | a1b615d | 2008-03-20 22:50:54 +0000 | [diff] [blame] | 14 | # %t - temporary file name (derived from testcase name) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 15 | # |
| 16 | |
| 17 | FILENAME=$1 |
| 18 | TESTNAME=$1 |
| 19 | SUBST=$1 |
Ted Kremenek | 5df51ba | 2007-11-28 19:16:54 +0000 | [diff] [blame] | 20 | |
| 21 | OUTPUT=Output/$1.out |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 22 | |
| 23 | # create the output directory if it does not already exist |
Ted Kremenek | 5df51ba | 2007-11-28 19:16:54 +0000 | [diff] [blame] | 24 | mkdir -p `dirname $OUTPUT` > /dev/null 2>&1 |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 25 | |
| 26 | if test $# != 1; then |
| 27 | # If more than one parameter is passed in, there must be three parameters: |
| 28 | # The filename to read from (already processed), the command used to execute, |
| 29 | # and the file to output to. |
| 30 | SUBST=$2 |
| 31 | OUTPUT=$3 |
| 32 | TESTNAME=$3 |
| 33 | fi |
| 34 | |
| 35 | ulimit -t 40 |
| 36 | |
Chris Lattner | c8c6cec | 2007-12-12 06:19:22 +0000 | [diff] [blame] | 37 | # Verify the script contains a run line. |
| 38 | grep -q 'RUN:' $FILENAME || ( |
| 39 | echo "******************** TEST '$TESTNAME' HAS NO RUN LINE! ********************" |
| 40 | exit 1 |
| 41 | ) |
| 42 | |
Gabor Greif | a1b615d | 2008-03-20 22:50:54 +0000 | [diff] [blame] | 43 | # Run under valgrind if the VG environment variable has been set. |
| 44 | CLANG="clang" |
| 45 | if [ -n "$VG" ]; then |
| 46 | rm -f $OUTPUT.vg.* |
Sam Bishop | 6fe1317 | 2008-03-23 03:42:18 +0000 | [diff] [blame] | 47 | CLANG="valgrind --leak-check=full --quiet --log-file=$OUTPUT.vg.%p $CLANG" |
Gabor Greif | a1b615d | 2008-03-20 22:50:54 +0000 | [diff] [blame] | 48 | fi |
| 49 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 50 | SCRIPT=$OUTPUT.script |
Gabor Greif | 4ca525f | 2008-03-17 13:45:47 +0000 | [diff] [blame] | 51 | TEMPOUTPUT=$OUTPUT.tmp |
Gabor Greif | a1b615d | 2008-03-20 22:50:54 +0000 | [diff] [blame] | 52 | grep 'RUN:' $FILENAME | \ |
| 53 | sed -e "s|^.*RUN:\(.*\)$|\1|g" \ |
| 54 | -e "s|%s|$SUBST|g" \ |
| 55 | -e "s|%llvmgcc|llvm-gcc -emit-llvm|g" \ |
| 56 | -e "s|%llvmgxx|llvm-g++ -emit-llvm|g" \ |
| 57 | -e "s|%prcontext|prcontext.tcl|g" \ |
| 58 | -e "s|%t|$TEMPOUTPUT|g" \ |
| 59 | -e "s|clang|$CLANG|g" > $SCRIPT |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 60 | |
| 61 | grep -q XFAIL $FILENAME && (printf "XFAILED '$TESTNAME': "; grep XFAIL $FILENAME) |
| 62 | |
Gabor Greif | a1b615d | 2008-03-20 22:50:54 +0000 | [diff] [blame] | 63 | /bin/sh $SCRIPT > $OUTPUT 2>&1 |
| 64 | SCRIPT_STATUS=$? |
| 65 | |
| 66 | if [ -n "$VG" ]; then |
| 67 | VG_STATUS=`cat $OUTPUT.vg.* | wc -l` |
| 68 | else |
| 69 | VG_STATUS=0 |
| 70 | fi |
| 71 | |
| 72 | if [ $SCRIPT_STATUS -ne 0 -o $VG_STATUS -ne 0 ]; then |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 73 | echo "******************** TEST '$TESTNAME' FAILED! ********************" |
| 74 | echo "Command: " |
| 75 | cat $SCRIPT |
Gabor Greif | a1b615d | 2008-03-20 22:50:54 +0000 | [diff] [blame] | 76 | if [ $SCRIPT_STATUS -eq 0 ]; then |
| 77 | echo "Output:" |
| 78 | else |
| 79 | echo "Incorrect Output:" |
| 80 | fi |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 81 | cat $OUTPUT |
Gabor Greif | a1b615d | 2008-03-20 22:50:54 +0000 | [diff] [blame] | 82 | if [ $VG_STATUS -ne 0 ]; then |
| 83 | echo "Valgrind Output:" |
| 84 | cat $OUTPUT.vg.* |
| 85 | fi |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 86 | echo "******************** TEST '$TESTNAME' FAILED! ********************" |
Gabor Greif | c6668c0 | 2008-03-17 12:35:00 +0000 | [diff] [blame] | 87 | exit 1 |
Gabor Greif | a1b615d | 2008-03-20 22:50:54 +0000 | [diff] [blame] | 88 | fi |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 89 | |