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 |
| 14 | # |
| 15 | |
| 16 | FILENAME=$1 |
| 17 | TESTNAME=$1 |
| 18 | SUBST=$1 |
Ted Kremenek | 5df51ba | 2007-11-28 19:16:54 +0000 | [diff] [blame] | 19 | |
| 20 | OUTPUT=Output/$1.out |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 21 | |
| 22 | # create the output directory if it does not already exist |
Ted Kremenek | 5df51ba | 2007-11-28 19:16:54 +0000 | [diff] [blame] | 23 | mkdir -p `dirname $OUTPUT` > /dev/null 2>&1 |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 24 | |
| 25 | if test $# != 1; then |
| 26 | # If more than one parameter is passed in, there must be three parameters: |
| 27 | # The filename to read from (already processed), the command used to execute, |
| 28 | # and the file to output to. |
| 29 | SUBST=$2 |
| 30 | OUTPUT=$3 |
| 31 | TESTNAME=$3 |
| 32 | fi |
| 33 | |
| 34 | ulimit -t 40 |
| 35 | |
Chris Lattner | c8c6cec | 2007-12-12 06:19:22 +0000 | [diff] [blame] | 36 | # Verify the script contains a run line. |
| 37 | grep -q 'RUN:' $FILENAME || ( |
| 38 | echo "******************** TEST '$TESTNAME' HAS NO RUN LINE! ********************" |
| 39 | exit 1 |
| 40 | ) |
| 41 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 42 | SCRIPT=$OUTPUT.script |
Chris Lattner | c8c6cec | 2007-12-12 06:19:22 +0000 | [diff] [blame] | 43 | grep 'RUN:' $FILENAME | sed "s|^.*RUN:\(.*\)$|\1|g;s|%s|$SUBST|g;s|%llvmgcc|llvm-gcc -emit-llvm|g;s|%llvmgxx|llvm-g++ -emit-llvm|g;s|%prcontext|prcontext.tcl|g" > $SCRIPT |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 44 | |
| 45 | grep -q XFAIL $FILENAME && (printf "XFAILED '$TESTNAME': "; grep XFAIL $FILENAME) |
| 46 | |
| 47 | /bin/sh $SCRIPT > $OUTPUT 2>&1 || ( |
| 48 | echo "******************** TEST '$TESTNAME' FAILED! ********************" |
| 49 | echo "Command: " |
| 50 | cat $SCRIPT |
| 51 | echo "Output:" |
| 52 | cat $OUTPUT |
| 53 | rm $OUTPUT |
| 54 | echo "******************** TEST '$TESTNAME' FAILED! ********************" |
Gabor Greif | c6668c0 | 2008-03-17 12:35:00 +0000 | [diff] [blame^] | 55 | exit 1 |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 56 | ) |
| 57 | |