From: Gabor Greif Date: Thu, 20 Mar 2008 22:50:54 +0000 (+0000) Subject: Add ability to run clang tests under valgrind. Patch by Sam Bishop. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e2db03f3f782b201be5a4542cd6bad8d869f8c9;p=clang Add ability to run clang tests under valgrind. Patch by Sam Bishop. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48621 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Makefile b/test/Makefile index 8c8fe512c7..ec4d45e058 100644 --- a/test/Makefile +++ b/test/Makefile @@ -9,7 +9,7 @@ TESTDIRS += Rewriter endif all:: - PATH=$$PATH:$(ToolDir):$(LLVM_SRC_ROOT)/test/Scripts \ + PATH=$$PATH:$(ToolDir):$(LLVM_SRC_ROOT)/test/Scripts VG=$(VG) \ find $(TESTDIRS) \( -name '*.c' -or -name '*.cpp' -or -name '*.m' \) \ -print -exec ./TestRunner.sh {} \; diff --git a/test/Makefile.parallel b/test/Makefile.parallel index 2e47039b99..0a3ef843c7 100644 --- a/test/Makefile.parallel +++ b/test/Makefile.parallel @@ -22,7 +22,7 @@ TESTS := $(addprefix Output/, $(addsuffix .testresults, $(shell find $(TESTDIRS) Output/%.testresults: % @ $(PROGRESS) - @ PATH=$$PATH:$(ToolDir):$(LLVM_SRC_ROOT)/test/Scripts ./TestRunner.sh $< > $@ || $(REPORTFAIL) + @ PATH=$$PATH:$(ToolDir):$(LLVM_SRC_ROOT)/test/Scripts VG=$(VG) ./TestRunner.sh $< > $@ || $(REPORTFAIL) all:: @ mkdir -p $(addprefix Output/, $(TESTDIRS)) diff --git a/test/TestRunner.sh b/test/TestRunner.sh index bc09a99065..8a0d87d3d5 100755 --- a/test/TestRunner.sh +++ b/test/TestRunner.sh @@ -11,7 +11,7 @@ # %llvmgcc - llvm-gcc command # %llvmgxx - llvm-g++ command # %prcontext - prcontext.tcl script -# %t1 - temporary file name (derived from testcase name) +# %t - temporary file name (derived from testcase name) # FILENAME=$1 @@ -40,20 +40,50 @@ grep -q 'RUN:' $FILENAME || ( exit 1 ) +# Run under valgrind if the VG environment variable has been set. +CLANG="clang" +if [ -n "$VG" ]; then + rm -f $OUTPUT.vg.* + CLANG="valgrind --leak-check=full --quiet --log-file=$OUTPUT.vg $CLANG" +fi + SCRIPT=$OUTPUT.script TEMPOUTPUT=$OUTPUT.tmp -grep '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 +grep 'RUN:' $FILENAME | \ + sed -e "s|^.*RUN:\(.*\)$|\1|g" \ + -e "s|%s|$SUBST|g" \ + -e "s|%llvmgcc|llvm-gcc -emit-llvm|g" \ + -e "s|%llvmgxx|llvm-g++ -emit-llvm|g" \ + -e "s|%prcontext|prcontext.tcl|g" \ + -e "s|%t|$TEMPOUTPUT|g" \ + -e "s|clang|$CLANG|g" > $SCRIPT grep -q XFAIL $FILENAME && (printf "XFAILED '$TESTNAME': "; grep XFAIL $FILENAME) -/bin/sh $SCRIPT > $OUTPUT 2>&1 || ( +/bin/sh $SCRIPT > $OUTPUT 2>&1 +SCRIPT_STATUS=$? + +if [ -n "$VG" ]; then + VG_STATUS=`cat $OUTPUT.vg.* | wc -l` +else + VG_STATUS=0 +fi + +if [ $SCRIPT_STATUS -ne 0 -o $VG_STATUS -ne 0 ]; then echo "******************** TEST '$TESTNAME' FAILED! ********************" echo "Command: " cat $SCRIPT - echo "Output:" + if [ $SCRIPT_STATUS -eq 0 ]; then + echo "Output:" + else + echo "Incorrect Output:" + fi cat $OUTPUT - rm $OUTPUT + if [ $VG_STATUS -ne 0 ]; then + echo "Valgrind Output:" + cat $OUTPUT.vg.* + fi echo "******************** TEST '$TESTNAME' FAILED! ********************" exit 1 -) +fi