blob: e84f56bd00c0167297717064240fa99be8956d3b [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.
Reid Spencer97be1332006-11-02 03:37:39 +000011# %llvmgcc - llvm-gcc command
12# %llvmgxx - llvm-g++ command
13# %prcontext - prcontext.tcl script
Chris Lattner9a3c2b52002-02-01 04:24:47 +000014#
15
Chris Lattnerdec2d792003-05-14 18:39:57 +000016FILENAME=$1
Chris Lattner1b2bde92003-05-14 19:54:07 +000017TESTNAME=$1
Chris Lattnerdec2d792003-05-14 18:39:57 +000018SUBST=$1
Chris Lattnerdfc03752006-06-17 08:06:33 +000019FILENAME_ONLY=`basename $1`
20OUTPUT=Output/$FILENAME_ONLY.out
Chris Lattnerdec2d792003-05-14 18:39:57 +000021
Chris Lattner53643602004-04-10 06:03:22 +000022# create the output directory if it does not already exist
23mkdir Output > /dev/null 2>&1
24
Chris Lattnerdec2d792003-05-14 18:39:57 +000025if 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
Chris Lattner1b2bde92003-05-14 19:54:07 +000031 TESTNAME=$3
Chris Lattnerdec2d792003-05-14 18:39:57 +000032fi
33
Chris Lattner1b2bde92003-05-14 19:54:07 +000034ulimit -t 40
35
Chris Lattnerec26d4d2003-05-14 18:44:22 +000036SCRIPT=$OUTPUT.script
Chris Lattnere25f5bb2006-03-08 22:28:19 +000037grep '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 +000038
Chris Lattnerd24d4af2002-02-11 23:32:43 +000039
Chris Lattnerdec2d792003-05-14 18:39:57 +000040/bin/sh $SCRIPT > $OUTPUT 2>&1 || (
Chris Lattner1b2bde92003-05-14 19:54:07 +000041 echo "******************** TEST '$TESTNAME' FAILED! ********************"
Chris Lattnerd24d4af2002-02-11 23:32:43 +000042 echo "Command: "
Chris Lattnerdec2d792003-05-14 18:39:57 +000043 cat $SCRIPT
Chris Lattner9a3c2b52002-02-01 04:24:47 +000044 echo "Output:"
45 cat $OUTPUT
46 rm $OUTPUT
Chris Lattner1b2bde92003-05-14 19:54:07 +000047 echo "******************** TEST '$TESTNAME' FAILED! ********************"
Chris Lattner9a3c2b52002-02-01 04:24:47 +000048)
49