blob: 58d8cc52242606358ca23142d5a3fe6ecc5b0536 [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 Lattnerec26d4d2003-05-14 18:44:22 +000016OUTPUT=Output/$FILENAME.out
Chris Lattnerdec2d792003-05-14 18:39:57 +000017
Chris Lattner53643602004-04-10 06:03:22 +000018# create the output directory if it does not already exist
19mkdir Output > /dev/null 2>&1
20
Chris Lattnerdec2d792003-05-14 18:39:57 +000021if 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 Lattner1b2bde92003-05-14 19:54:07 +000027 TESTNAME=$3
Chris Lattnerdec2d792003-05-14 18:39:57 +000028fi
29
Chris Lattner1b2bde92003-05-14 19:54:07 +000030ulimit -t 40
31
Chris Lattnerec26d4d2003-05-14 18:44:22 +000032SCRIPT=$OUTPUT.script
Chris Lattner7f9b4e92005-08-05 19:48:29 +000033grep '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 Lattner9a3c2b52002-02-01 04:24:47 +000034
Chris Lattnerd24d4af2002-02-11 23:32:43 +000035
Chris Lattnerdec2d792003-05-14 18:39:57 +000036/bin/sh $SCRIPT > $OUTPUT 2>&1 || (
Chris Lattner1b2bde92003-05-14 19:54:07 +000037 echo "******************** TEST '$TESTNAME' FAILED! ********************"
Chris Lattnerd24d4af2002-02-11 23:32:43 +000038 echo "Command: "
Chris Lattnerdec2d792003-05-14 18:39:57 +000039 cat $SCRIPT
Chris Lattner9a3c2b52002-02-01 04:24:47 +000040 echo "Output:"
41 cat $OUTPUT
42 rm $OUTPUT
Chris Lattner1b2bde92003-05-14 19:54:07 +000043 echo "******************** TEST '$TESTNAME' FAILED! ********************"
Chris Lattner9a3c2b52002-02-01 04:24:47 +000044)
45