blob: b649fab9cc9ebfaff25ab7399b66de121cbc4335 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +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
14#
15
16FILENAME=$1
17TESTNAME=$1
18SUBST=$1
Ted Kremenek5df51ba2007-11-28 19:16:54 +000019
20OUTPUT=Output/$1.out
Chris Lattner4b009652007-07-25 00:24:17 +000021
22# create the output directory if it does not already exist
Ted Kremenek5df51ba2007-11-28 19:16:54 +000023mkdir -p `dirname $OUTPUT` > /dev/null 2>&1
Chris Lattner4b009652007-07-25 00:24:17 +000024
25if 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
31 TESTNAME=$3
32fi
33
34ulimit -t 40
35
Chris Lattnerc8c6cec2007-12-12 06:19:22 +000036# Verify the script contains a run line.
37grep -q 'RUN:' $FILENAME || (
38 echo "******************** TEST '$TESTNAME' HAS NO RUN LINE! ********************"
39 exit 1
40)
41
Chris Lattner4b009652007-07-25 00:24:17 +000042SCRIPT=$OUTPUT.script
Chris Lattnerc8c6cec2007-12-12 06:19:22 +000043grep '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 Lattner4b009652007-07-25 00:24:17 +000044
45grep -q XFAIL $FILENAME && (printf "XFAILED '$TESTNAME': "; grep XFAIL $FILENAME)
46
47/bin/sh $SCRIPT > $OUTPUT 2>&1 || (
48 echo "******************** TEST '$TESTNAME' FAILED! ********************"
49 echo "Command: "
50 cat $SCRIPT
51 echo "Output:"
52 cat $OUTPUT
53 rm $OUTPUT
54 echo "******************** TEST '$TESTNAME' FAILED! ********************"
Gabor Greifc6668c02008-03-17 12:35:00 +000055 exit 1
Chris Lattner4b009652007-07-25 00:24:17 +000056)
57