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)
19 FILEDIR
=`dirname $TESTNAME`
23 # create the output directory if it does not already exist
24 mkdir
-p `dirname $OUTPUT` > /dev
/null
2>&1
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.
37 # Verify the script contains a run line.
38 grep -q 'RUN:' $FILENAME ||
(
39 echo "******************** TEST '$TESTNAME' HAS NO RUN LINE! ********************"
43 # Run under valgrind if the VG environment variable has been set.
45 if [ ! -n "$CLANG" ]; then
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"
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'.
65 if [ ! -n "$CLANGCC" ]; then
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"
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" \
87 -e "s|%S|$FILEDIR|g" \
88 -e "s|%prcontext|prcontext.tcl|g" \
89 -e "s|%t|$TEMPOUTPUT|g" > $SCRIPT
92 if (grep -q XFAIL
$FILENAME); then
94 printf "XFAILED '$TESTNAME': "
98 /bin
/sh
$SCRIPT > $OUTPUT 2>&1
101 if [ -n "$VG" ]; then
108 if [ $IS_XFAIL -ne 0 ]; then
109 if [ $SCRIPT_STATUS -ne 0 ]; then
116 if [ $SCRIPT_STATUS -ne 0 -o $VG_STATUS -ne 0 ]; then
117 echo "******************** TEST '$TESTNAME' FAILED! ********************"
120 if [ $SCRIPT_STATUS -eq 0 ]; then
122 elif [ $IS_XFAIL -ne 0 ]; then
123 echo "Incorrect Output (Expected Failure):"
125 echo "Incorrect Output:"
128 if [ $VG_STATUS -ne 0 ]; then
129 echo "Valgrind Output:"
132 echo "******************** TEST '$TESTNAME' FAILED! ********************"