Hi,

It seems beneficial to run the testcases under valgrind to find some
memory issues. This patch adds a new configure option --enable-valgrind
that makes it so that all tests run under valgrind and fail if valgrind
finds an memory issue (it succeeds with my latest two patches).

It is disabled by default since running make check becomes too slow
for normal use. But I enabled it for the make distcheck case, which
seems a good time to double check all tests are clean.

Comments?

Mark
>From 226876b2259d714015d4bd47d9602cf7fcce5bc3 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <[email protected]>
Date: Mon, 24 Sep 2012 16:23:07 +0200
Subject: [PATCH] Add configure --enable-valgrind option to run all tests
 under valgrind.


Signed-off-by: Mark Wielaard <[email protected]>
---
 ChangeLog             |  5 +++++
 Makefile.am           |  2 ++
 configure.ac          | 11 +++++++++++
 tests/ChangeLog       | 10 ++++++++++
 tests/Makefile.am     |  8 +++++++-
 tests/test-subr.sh    |  6 +++---
 tests/test-wrapper.sh |  4 ++++
 7 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 208e425..99218c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-09-24  Mark Wielaard  <[email protected]>
+
+       * configure.ac: Add --enable-valgrind check.
+       * Makefile.am (DISTCHECK_CONFIGURE_FLAGS): Add --enable-valgrind.
+
 2012-08-27  Mark Wielaard  <[email protected]>
 
        * configure.ac: Set version to 0.155.
diff --git a/Makefile.am b/Makefile.am
index 305bbfc..e833989 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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:
diff --git a/configure.ac b/configure.ac
index adec1c1..52a2322 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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])
 
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 88a33b9..721580c 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,13 @@
+2012-09-24  Mark Wielaard  <[email protected]>
+
+       * valgrind-wrapper.sh: New file.
+       * Makefile.am (EXTRA_DIST): Add valgrind-wrapper.sh.
+       (TESTS_ENVIRONMENT): Add valgrind_wrapper if USE_VALGRIND.
+       * test-wrapper.sh: export VALGRIND_WRAPPER if available.
+       * test-subr.sh (built_testrun): Use VALGRIND_WRAPPER to invoke
+       test program.
+       (installed_testrun): Likewise.
+
 2012-09-18  Petr Machata  <[email protected]>
 
        * testfile61.bz2: New testfile.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bee4973..ee72455 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -178,16 +178,22 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
             run-test-archive64.sh testarchive64.a.bz2 \
             testfile60.bz2 testfile61.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:
diff --git a/tests/test-subr.sh b/tests/test-subr.sh
index ff29136..19a9836 100644
--- a/tests/test-subr.sh
+++ b/tests/test-subr.sh
@@ -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
 }
 
diff --git a/tests/test-wrapper.sh b/tests/test-wrapper.sh
index 96ddb74..09b4d49 100755
--- a/tests/test-wrapper.sh
+++ b/tests/test-wrapper.sh
@@ -58,4 +58,8 @@ case "$1" in
   ;;
 esac
 
+if [ "x$VALGRIND_CMD" != "x" ]; then
+  export VALGRIND_CMD
+fi
+
 exec "$@"
-- 
1.7.11.4

_______________________________________________
elfutils-devel mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/elfutils-devel

Reply via email to