Add valgrind support to testsuite.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 22 Mar 2011 04:22:54 +0000 (21:22 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 22 Mar 2011 04:22:54 +0000 (21:22 -0700)
tests/automake.mk
tests/valgrind-wrapper.in [new file with mode: 0755]

index 484ef0e11c67647e08b5bab59edf4dccdad667b1..a6d8de3a236d834f6a06c81c34ac9f364ac13dd9 100644 (file)
@@ -384,6 +384,7 @@ TESTSUITE_AT = \
 
 TESTSUITE = $(srcdir)/tests/testsuite
 DISTCLEANFILES += tests/atconfig tests/atlocal $(TESTSUITE)
+AUTOTEST_PATH = tests/data:tests/language/lexer:tests/libpspp:tests/output:src/ui/terminal
 
 $(srcdir)/tests/testsuite.at: tests/testsuite.in tests/automake.mk
        cp $< $@
@@ -394,7 +395,7 @@ EXTRA_DIST += tests/testsuite.at
 
 CHECK_LOCAL += tests_check
 tests_check: tests/atconfig tests/atlocal $(TESTSUITE) $(check_PROGRAMS)
-       $(SHELL) '$(TESTSUITE)' -C tests AUTOTEST_PATH=tests/data:tests/language/lexer:tests/libpspp:tests/output:src/ui/terminal $(TESTSUITEFLAGS)
+       $(SHELL) '$(TESTSUITE)' -C tests AUTOTEST_PATH=$(AUTOTEST_PATH) $(TESTSUITEFLAGS)
 
 CLEAN_LOCAL += tests_clean
 tests_clean:
@@ -417,3 +418,27 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
          echo 'm4_define([AT_PACKAGE_BUGREPORT], [$(PACKAGE_BUGREPORT)])' && \
          echo 'm4_define([AT_PACKAGE_URL],       [$(PACKAGE_URL)])'; \
        } >'$(srcdir)/package.m4'
+\f
+# valgrind support for Autotest testsuite
+
+valgrind_wrappers = \
+       tests/valgrind/pspp \
+       tests/valgrind/render-test
+
+$(valgrind_wrappers): tests/valgrind-wrapper.in
+       @test -d tests/valgrind || mkdir tests/valgrind
+       sed -e 's,[@]wrap_program[@],$@,' \
+               $(top_srcdir)/tests/valgrind-wrapper.in > $@.tmp
+       chmod +x $@.tmp
+       mv $@.tmp $@
+CLEANFILES += $(valgrind_wrappers)
+EXTRA_DIST += tests/valgrind-wrapper.in
+
+VALGRIND = $(SHELL) $(abs_top_builddir)/libtool --mode=execute valgrind --log-file=valgrind.%p --leak-check=full --num-callers=20
+check-valgrind: all tests/atconfig tests/atlocal $(TESTSUITE) $(valgrind_wrappers)
+       $(SHELL) '$(TESTSUITE)' -C tests VALGRIND='$(VALGRIND)' AUTOTEST_PATH='tests/valgrind:$(AUTOTEST_PATH)' -d $(TESTSUITEFLAGS)
+       @echo
+       @echo '--------------------------------'
+       @echo 'Valgrind output is in:'
+       @echo 'tests/testsuite.dir/*/valgrind.*'
+       @echo '--------------------------------'
diff --git a/tests/valgrind-wrapper.in b/tests/valgrind-wrapper.in
new file mode 100755 (executable)
index 0000000..a60cd9e
--- /dev/null
@@ -0,0 +1,38 @@
+#! /bin/sh
+
+program=`basename "$0"`
+
+new_PATH=
+save_IFS=$IFS
+IFS=:
+found=no
+for dir in $PATH; do
+    IFS=$save_IFS
+    if test "X$dir" = X; then
+       dir=.
+    fi
+    if test -x "$dir/$program"; then
+       if test $found = no; then
+           found=yes
+           continue
+       else
+           if test "X$next_program" = X; then
+               next_program=$dir/$program
+           fi
+       fi
+    fi
+done
+IFS=$save_IFS
+
+if test $found = no; then
+    echo "$0: $program not found in PATH ($PATH)" >&2
+    exit 1
+elif test "X$next_program" = X; then
+    echo "$0: $program found only once in PATH ($PATH)" >&2
+    exit 1
+fi
+
+: ${VALGRIND:=libtool --mode=execute valgrind --log-file=valgrind.%p --leak-check=full --num-callers=20}
+exec $VALGRIND $next_program "$@"
+echo "$0: $VALGRIND $wrap_program $* failed" >&2
+exit 1