Add LLVM runtime checks to build path
[clang/acc.git] / test / TestRunner.sh
blobbb20728578c1caca44d2ad1db4afd69ff92f8c2f
1 #!/bin/sh
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.
7 # This runner recognizes and replaces the following strings in the command:
9 # %s - Replaced with the input name of the program, or the program to
10 # execute, as appropriate.
11 # %S - Replaced with the directory where the input file resides
12 # %prcontext - prcontext.tcl script
13 # %t - temporary file name (derived from testcase name)
16 FILENAME=$1
17 TESTNAME=$1
18 SUBST=$1
19 FILEDIR=`dirname $TESTNAME`
21 OUTPUT=Output/$1.out
23 # create the output directory if it does not already exist
24 mkdir -p `dirname $OUTPUT` > /dev/null 2>&1
26 if 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
35 ulimit -t 40
37 # Verify the script contains a run line.
38 grep -q 'RUN:' $FILENAME || (
39 echo "******************** TEST '$TESTNAME' HAS NO RUN LINE! ********************"
40 exit 1
43 # Run under valgrind if the VG environment variable has been set.
44 CLANG=$CLANG
45 if [ ! -n "$CLANG" ]; then
46 CLANG="clang"
49 # Resolve the path, and Make sure $CLANG actually exists; otherwise
50 # ensuing failures are non-obvious.
51 CLANG=$(which "$CLANG")
52 if [ -z $CLANG ]; then
53 echo "Couldn't find 'clang' program, try setting CLANG in your environment"
54 exit 1
57 if [ -n "$VG" ]; then
58 rm -f $OUTPUT.vg
59 CLANG="valgrind --leak-check=full --quiet --log-file=$OUTPUT.vg $CLANG"
62 # Assuming $CLANG is correct, use it to derive clang-cc. We expect to
63 # be looking in a build directory, so just add '-cc'.
64 CLANGCC=$CLANGCC
65 if [ ! -n "$CLANGCC" ]; then
66 CLANGCC="$CLANG-cc"
69 # Try to sanity check $CLANGCC too
70 CLANGCC=$(which "$CLANGCC")
71 # If that failed, ask clang.
72 if [ -z "$CLANGCC" ]; then
73 CLANGCC=$($CLANG -print-prog-name=clang-cc)
75 if [ -z "$CLANGCC" ]; then
76 echo "Couldn't find 'clang-cc' program, make sure clang is found in your build directory"
77 exit 1
80 SCRIPT=$OUTPUT.script
81 TEMPOUTPUT=$OUTPUT.tmp
82 grep 'RUN:' $FILENAME | \
83 sed -e "s|^.*RUN:\(.*\)$|\1|g" \
84 -e "s| clang | $CLANG |g" \
85 -e "s| clang-cc | $CLANGCC |g" \
86 -e "s|%s|$SUBST|g" \
87 -e "s|%S|$FILEDIR|g" \
88 -e "s|%prcontext|prcontext.tcl|g" \
89 -e "s|%t|$TEMPOUTPUT|g" > $SCRIPT
91 IS_XFAIL=0
92 if (grep -q XFAIL $FILENAME); then
93 IS_XFAIL=1
94 printf "XFAILED '$TESTNAME': "
95 grep XFAIL $FILENAME
98 /bin/sh $SCRIPT > $OUTPUT 2>&1
99 SCRIPT_STATUS=$?
101 if [ -n "$VG" ]; then
102 [ ! -s $OUTPUT.vg ]
103 VG_STATUS=$?
104 else
105 VG_STATUS=0
108 if [ $IS_XFAIL -ne 0 ]; then
109 if [ $SCRIPT_STATUS -ne 0 ]; then
110 SCRIPT_STATUS=0
111 else
112 SCRIPT_STATUS=1
116 if [ $SCRIPT_STATUS -ne 0 -o $VG_STATUS -ne 0 ]; then
117 echo "******************** TEST '$TESTNAME' FAILED! ********************"
118 echo "Command: "
119 cat $SCRIPT
120 if [ $SCRIPT_STATUS -eq 0 ]; then
121 echo "Output:"
122 elif [ $IS_XFAIL -ne 0 ]; then
123 echo "Incorrect Output (Expected Failure):"
124 else
125 echo "Incorrect Output:"
127 cat $OUTPUT
128 if [ $VG_STATUS -ne 0 ]; then
129 echo "Valgrind Output:"
130 cat $OUTPUT.vg
132 echo "******************** TEST '$TESTNAME' FAILED! ********************"
133 exit 1