Add configure --enable-valgrind option to run all tests under valgrind.
authorMark Wielaard <mjw@redhat.com>
Mon, 1 Oct 2012 14:14:12 +0000 (16:14 +0200)
committerMark Wielaard <mjw@redhat.com>
Mon, 1 Oct 2012 15:33:14 +0000 (17:33 +0200)
Signed-off-by: Mark Wielaard <mjw@redhat.com>
ChangeLog
Makefile.am
configure.ac
tests/ChangeLog
tests/Makefile.am
tests/test-subr.sh
tests/test-wrapper.sh

index 208e425..a05ebdf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-10-01  Mark Wielaard  <mjw@redhat.com>
+
+       * configure.ac: Add --enable-valgrind check.
+       * Makefile.am (DISTCHECK_CONFIGURE_FLAGS): Add --enable-valgrind.
+
 2012-08-27  Mark Wielaard  <mjw@redhat.com>
 
        * configure.ac: Set version to 0.155.
index 305bbfc..e833989 100644 (file)
@@ -32,8 +32,10 @@ EXTRA_DIST = elfutils.spec GPG-KEY NOTES CONTRIBUTING \
 # Make sure the test install uses lib64 when $LIB will yield lib64.
 # Make sure the test build uses the same compiler, which on e.g. ppc64
 # determines which platform we are actually testing.
+# Run all tests under valgrind.
 DISTCHECK_CONFIGURE_FLAGS = \
        --libdir=`echo $(libdir) | sed "s,^$(exec_prefix),$$dc_install_base,"`\
+       --enable-valgrind \
        CC="$(CC)"
 
 distcheck-hook:
index adec1c1..52a2322 100644 (file)
@@ -190,6 +190,17 @@ if test "$use_gcov" = yes; then
 fi
 AM_CONDITIONAL(GCOV, test "$use_gcov" = yes)
 
+AC_ARG_ENABLE([valgrind],
+AS_HELP_STRING([--enable-valgrind],[run all tests under valgrind]),
+[use_valgrind=$enableval], [use_valgrind=no])
+if test "$use_valgrind" = yes; then
+  AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
+  if test "$HAVE_VALGRIND" = "no"; then
+    AC_MSG_ERROR([valgrind not found])
+  fi
+fi
+AM_CONDITIONAL(USE_VALGRIND, test "$use_valgrind" = yes)
+
 AM_CONDITIONAL(BUILD_STATIC, [dnl
 test "$use_mudflap" = yes -o "$use_gprof" = yes -o "$use_gcov" = yes])
 
index 1b5271c..37e214e 100644 (file)
@@ -1,3 +1,10 @@
+2012-10-01  Mark Wielaard  <mjw@redhat.com>
+
+       * Makefile.am (TESTS_ENVIRONMENT): Define valgrind_cmd if USE_VALGRIND.
+       * test-wrapper.sh: Export VALGRIND_CMD if available.
+       * test-subr.sh (built_testrun): Use VALGRIND_CMD to invoke test prog.
+       (installed_testrun): Likewise.
+
 2012-09-24  Petr Machata  <pmachata@redhat.com>
 
        * testfile63.bz2: New testfile.
index 6cf098b..4775b37 100644 (file)
@@ -181,16 +181,22 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
             run-readelf-vmcoreinfo.sh testfile62.bz2 \
             run-readelf-mixed-corenote.sh testfile63.bz2
 
+if USE_VALGRIND
+valgrind_cmd="valgrind -q --trace-children=yes --error-exitcode=1"
+endif
+
 installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \
                              bindir=$(DESTDIR)$(bindir) \
                              LC_ALL=C LANG=C \
+                             VALGRIND_CMD=$(valgrind_cmd) \
                              $(srcdir)/test-wrapper.sh \
                              installed $(tests_rpath) \
                              $(program_transform_name)
 if STANDALONE
 TESTS_ENVIRONMENT = $(installed_TESTS_ENVIRONMENT)
 else !STANDALONE
-TESTS_ENVIRONMENT = LC_ALL=C LANG=C $(srcdir)/test-wrapper.sh \
+TESTS_ENVIRONMENT = LC_ALL=C LANG=C VALGRIND_CMD=$(valgrind_cmd) \
+                   $(srcdir)/test-wrapper.sh \
                    ../libdw:../backends:../libelf:../libasm
 
 installcheck-local:
index ff29136..19a9836 100644 (file)
@@ -72,7 +72,7 @@ testrun()
 built_testrun()
 {
   LD_LIBRARY_PATH="${built_library_path}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"\
-  "$@"
+  $VALGRIND_CMD "$@"
 }
 
 installed_testrun()
@@ -93,9 +93,9 @@ installed_testrun()
   if [ "${libdir}" != /usr/lib ] && [ "${libdir}" != /usr/lib64 ]; then
     LD_LIBRARY_PATH="${libdir}:${libdir}/elfutils\
 ${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" \
-    $program ${1+"$@"}
+    $VALGRIND_CMD $program ${1+"$@"}
   else
-    $program ${1+"$@"}
+    $VALGRIND_CMD $program ${1+"$@"}
   fi
 }
 
index 96ddb74..09b4d49 100755 (executable)
@@ -58,4 +58,8 @@ case "$1" in
   ;;
 esac
 
+if [ "x$VALGRIND_CMD" != "x" ]; then
+  export VALGRIND_CMD
+fi
+
 exec "$@"