blob: bc09a99065f0c4302f955345465d4e6e6de6064f [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +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:
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
Gabor Greif0f233032008-03-17 13:45:47 +000014# %t1 - temporary file name (derived from testcase name)
Reid Spencer5f016e22007-07-11 17:01:13 +000015#
16
17FILENAME=$1
18TESTNAME=$1
19SUBST=$1
Ted Kremenek6a18c762007-11-28 19:16:54 +000020
21OUTPUT=Output/$1.out
Reid Spencer5f016e22007-07-11 17:01:13 +000022
23# create the output directory if it does not already exist
Ted Kremenek6a18c762007-11-28 19:16:54 +000024mkdir -p `dirname $OUTPUT` > /dev/null 2>&1
Reid Spencer5f016e22007-07-11 17:01:13 +000025
26if test $# != 1; then
27 # If more than one parameter is passed in, there must be three parameters:
28 # The filename to read from (already processed), the command used to execute,
29 # and the file to output to.
30 SUBST=$2
31 OUTPUT=$3
32 TESTNAME=$3
33fi
34
35ulimit -t 40
36
Chris Lattner32a39992007-12-12 06:19:22 +000037# Verify the script contains a run line.
38grep -q 'RUN:' $FILENAME || (
39 echo "******************** TEST '$TESTNAME' HAS NO RUN LINE! ********************"
40 exit 1
41)
42
Reid Spencer5f016e22007-07-11 17:01:13 +000043SCRIPT=$OUTPUT.script
Gabor Greif0f233032008-03-17 13:45:47 +000044TEMPOUTPUT=$OUTPUT.tmp
Gabor Greifcf20b482008-03-18 06:42:43 +000045grep '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;s|%t|$TEMPOUTPUT|g" > $SCRIPT
Reid Spencer5f016e22007-07-11 17:01:13 +000046
47grep -q XFAIL $FILENAME && (printf "XFAILED '$TESTNAME': "; grep XFAIL $FILENAME)
48
49/bin/sh $SCRIPT > $OUTPUT 2>&1 || (
50 echo "******************** TEST '$TESTNAME' FAILED! ********************"
51 echo "Command: "
52 cat $SCRIPT
53 echo "Output:"
54 cat $OUTPUT
55 rm $OUTPUT
56 echo "******************** TEST '$TESTNAME' FAILED! ********************"
Gabor Greif5ca1b5a2008-03-17 12:35:00 +000057 exit 1
Reid Spencer5f016e22007-07-11 17:01:13 +000058)
59