Chris Lattner | 9a3c2b5 | 2002-02-01 04:24:47 +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: |
Chris Lattner | dec2d79 | 2003-05-14 18:39:57 +0000 | [diff] [blame] | 8 | # |
| 9 | # %s - Replaced with the input name of the program, or the program to |
| 10 | # execute, as appropriate. |
Chris Lattner | 9a3c2b5 | 2002-02-01 04:24:47 +0000 | [diff] [blame] | 11 | # |
| 12 | |
Chris Lattner | dec2d79 | 2003-05-14 18:39:57 +0000 | [diff] [blame] | 13 | FILENAME=$1 |
Chris Lattner | 1b2bde9 | 2003-05-14 19:54:07 +0000 | [diff] [blame] | 14 | TESTNAME=$1 |
Chris Lattner | dec2d79 | 2003-05-14 18:39:57 +0000 | [diff] [blame] | 15 | SUBST=$1 |
Chris Lattner | ec26d4d | 2003-05-14 18:44:22 +0000 | [diff] [blame] | 16 | OUTPUT=Output/$FILENAME.out |
Chris Lattner | dec2d79 | 2003-05-14 18:39:57 +0000 | [diff] [blame] | 17 | |
Chris Lattner | 5364360 | 2004-04-10 06:03:22 +0000 | [diff] [blame] | 18 | # create the output directory if it does not already exist |
| 19 | mkdir Output > /dev/null 2>&1 |
| 20 | |
Chris Lattner | dec2d79 | 2003-05-14 18:39:57 +0000 | [diff] [blame] | 21 | if test $# != 1; then |
| 22 | # If more than one parameter is passed in, there must be three parameters: |
| 23 | # The filename to read from (already processed), the command used to execute, |
| 24 | # and the file to output to. |
| 25 | SUBST=$2 |
| 26 | OUTPUT=$3 |
Chris Lattner | 1b2bde9 | 2003-05-14 19:54:07 +0000 | [diff] [blame] | 27 | TESTNAME=$3 |
Chris Lattner | dec2d79 | 2003-05-14 18:39:57 +0000 | [diff] [blame] | 28 | fi |
| 29 | |
Chris Lattner | 1b2bde9 | 2003-05-14 19:54:07 +0000 | [diff] [blame] | 30 | ulimit -t 40 |
| 31 | |
Chris Lattner | ec26d4d | 2003-05-14 18:44:22 +0000 | [diff] [blame] | 32 | SCRIPT=$OUTPUT.script |
Chris Lattner | 7f9b4e9 | 2005-08-05 19:48:29 +0000 | [diff] [blame] | 33 | grep 'RUN:' $FILENAME | sed "s|^.*RUN:\(.*\)$|\1|g;s|%s|$SUBST|g;s|%llvmgcc|llvm-gcc|g;s|%llvmgxx|llvm-g++|g;s|%prcontext|prcontext.tcl|g" > $SCRIPT |
Chris Lattner | 9a3c2b5 | 2002-02-01 04:24:47 +0000 | [diff] [blame] | 34 | |
Chris Lattner | d24d4af | 2002-02-11 23:32:43 +0000 | [diff] [blame] | 35 | |
Chris Lattner | dec2d79 | 2003-05-14 18:39:57 +0000 | [diff] [blame] | 36 | /bin/sh $SCRIPT > $OUTPUT 2>&1 || ( |
Chris Lattner | 1b2bde9 | 2003-05-14 19:54:07 +0000 | [diff] [blame] | 37 | echo "******************** TEST '$TESTNAME' FAILED! ********************" |
Chris Lattner | d24d4af | 2002-02-11 23:32:43 +0000 | [diff] [blame] | 38 | echo "Command: " |
Chris Lattner | dec2d79 | 2003-05-14 18:39:57 +0000 | [diff] [blame] | 39 | cat $SCRIPT |
Chris Lattner | 9a3c2b5 | 2002-02-01 04:24:47 +0000 | [diff] [blame] | 40 | echo "Output:" |
| 41 | cat $OUTPUT |
| 42 | rm $OUTPUT |
Chris Lattner | 1b2bde9 | 2003-05-14 19:54:07 +0000 | [diff] [blame] | 43 | echo "******************** TEST '$TESTNAME' FAILED! ********************" |
Chris Lattner | 9a3c2b5 | 2002-02-01 04:24:47 +0000 | [diff] [blame] | 44 | ) |
| 45 | |