blob: 68091c2188b85bba3177393b8cbaf1de1d7acb15 [file] [log] [blame]
Chris Lattner9a3c2b52002-02-01 04:24:47 +00001#!/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 Lattnerdec2d792003-05-14 18:39:57 +00008#
9# %s - Replaced with the input name of the program, or the program to
10# execute, as appropriate.
Chris Lattner9a3c2b52002-02-01 04:24:47 +000011#
12
Chris Lattnerdec2d792003-05-14 18:39:57 +000013FILENAME=$1
Chris Lattner1b2bde92003-05-14 19:54:07 +000014TESTNAME=$1
Chris Lattnerdec2d792003-05-14 18:39:57 +000015SUBST=$1
Chris Lattnerdfc03752006-06-17 08:06:33 +000016FILENAME_ONLY=`basename $1`
17OUTPUT=Output/$FILENAME_ONLY.out
Chris Lattnerdec2d792003-05-14 18:39:57 +000018
Chris Lattner53643602004-04-10 06:03:22 +000019# create the output directory if it does not already exist
20mkdir Output > /dev/null 2>&1
21
Chris Lattnerdec2d792003-05-14 18:39:57 +000022if test $# != 1; then
23 # If more than one parameter is passed in, there must be three parameters:
24 # The filename to read from (already processed), the command used to execute,
25 # and the file to output to.
26 SUBST=$2
27 OUTPUT=$3
Chris Lattner1b2bde92003-05-14 19:54:07 +000028 TESTNAME=$3
Chris Lattnerdec2d792003-05-14 18:39:57 +000029fi
30
Chris Lattner1b2bde92003-05-14 19:54:07 +000031ulimit -t 40
32
Chris Lattnerec26d4d2003-05-14 18:44:22 +000033SCRIPT=$OUTPUT.script
Chris Lattnere25f5bb2006-03-08 22:28:19 +000034grep '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 Lattner9a3c2b52002-02-01 04:24:47 +000035
Chris Lattnerd24d4af2002-02-11 23:32:43 +000036
Chris Lattnerdec2d792003-05-14 18:39:57 +000037/bin/sh $SCRIPT > $OUTPUT 2>&1 || (
Chris Lattner1b2bde92003-05-14 19:54:07 +000038 echo "******************** TEST '$TESTNAME' FAILED! ********************"
Chris Lattnerd24d4af2002-02-11 23:32:43 +000039 echo "Command: "
Chris Lattnerdec2d792003-05-14 18:39:57 +000040 cat $SCRIPT
Chris Lattner9a3c2b52002-02-01 04:24:47 +000041 echo "Output:"
42 cat $OUTPUT
43 rm $OUTPUT
Chris Lattner1b2bde92003-05-14 19:54:07 +000044 echo "******************** TEST '$TESTNAME' FAILED! ********************"
Chris Lattner9a3c2b52002-02-01 04:24:47 +000045)
46