Hello,
I made some enhancements to the valgrind-tests.m4 file which I find
quite handy and wanted to put tem into discussion.
The main changes are:
Memory leaks can be treated as errors
(--enable-valgrind-memleaks-are-errors)
Possibility for overriding the default arguments for valgrind via
VALGRIND_MEMLEAK_OPTS environment variable.
It also occurred to me that the original file did not work properly for
enabling/disabling valgrind tests on my machines so I tried to fix that.
(check for --enable-valgrind-tests option)
Currently it is not perfect. I still have to add 4 macros to the
configure.ac file:
gl_VALGRIND_TESTS
gl_VALGRIND_MEMLEAKS_ARE_ERRORS
gl_VALGRIND_CONSISTENCY
gl_VALGRIND_SUMMARY
additionally the valgrind summary can be printed by adding the
follwowing to AC_MSG_NOTICE:
Valgrind: ${opt_valgrind_tests}
${valgrind_options}
What do you think?
Bernd
Here is the diff:
*** m4/valgrind-tests.m4 2010-08-22 21:39:47.000000000 +0200
--- ../protfw/m4/valgrind_tests.m4 2010-08-30 23:43:11.000000000 +0200
***************
*** 6,11 ****
--- 6,75 ----
dnl From Simon Josefsson
+ AC_ARG_VAR([VALGRIND_MEMLEAK_OPTS],
+ [use this variable to override command line options of
valgrind for memory leak checking. Run 'valgrind --help' or 'man
valgrind' for valid options])
+
+ # gl_VALGRIND_TREAT_LEAKS_AS_ERRORS()
+ # -----------------------------------
+ # Configuration parameter to treat memory leaks as errors if they
+ # occur in a module test
+ AC_DEFUN([gl_VALGRIND_MEMLEAKS_ARE_ERRORS],
+ [
+ AC_ARG_ENABLE(valgrind-memleaks-are-errors,
+ AS_HELP_STRING([--enable-valgrind-memleaks-are-errors],
+ [treat module tests with memory leaks as errors]),
+ [opt_valgrind_memleaks_are_errors=$enableval],
+ [opt_valgrind_memleaks_are_errors=no])
+
+ if test -z "$VALGRIND_MEMLEAK_OPTS"; then
+ if test "$opt_valgrind_memleaks_are_errors" = "yes"; then
+ opt_valgrind_memleaks_are_errors=yes
+ VALGRIND_MEMLEAK_OPTS="-q --error-exitcode=1 --leak-check=full"
+ else
+ opt_valgrind_memleaks_are_errors=no
+ VALGRIND_MEMLEAK_OPTS="-q"
+ fi
+ else
+ opt_valgrind_memleaks_are_errors="$VALGRIND_MEMLEAK_OPTS"
+ fi
+
+ AC_SUBST([VALGRIND_MEMLEAK_OPTS],[$VALGRIND_MEMLEAK_OPTS])
+ AC_MSG_CHECKING([whether valgrind treats memory leaks as errors])
+ AC_MSG_RESULT($opt_valgrind_memleaks_are_errors)
+ ])
+
+
+ AC_DEFUN([gl_VALGRIND_CONSISTENCY],
+ [
+ if test "$opt_valgrind_tests" = "no" && test
"$opt_valgrind_memleaks_are_errors" != "no"; then
+ AC_MSG_WARN(
+ [
+ *******************************************************************
+ *** ***
+ *** Memory leak checking with Valgrind is disabled. ***
+ *** ***
+ *** Ignoring: --enable-valgrind-tests ***
+ *** Ignoring: settings in \$VALGRIND_MEMLEAK_OPTS ***
+ *** ***
+ *******************************************************************
+ ])
+ fi
+ ])
+
+ AC_DEFUN([gl_VALGRIND_SUMMARY],
+ [
+ valgrind_options=""
+ if test "$opt_valgrind_tests" = "yes"; then
+ if test "$opt_valgrind_memleaks_are_errors" = "yes" ||
+ test "$opt_valgrind_memleaks_are_errors" = "no";
+ then
+ valgrind_options="Memleaks are errors:
${opt_valgrind_memleaks_are_errors}"
+ else
+ valgrind_options="Valgrind options:
${opt_valgrind_memleaks_are_errors}"
+ fi
+ fi
+ ])
+
# gl_VALGRIND_TESTS()
# -------------------
# Check if valgrind is available, and set VALGRIND to it if available.
***************
*** 14,29 ****
AC_ARG_ENABLE(valgrind-tests,
AS_HELP_STRING([--enable-valgrind-tests],
[run self tests under valgrind]),
! [opt_valgrind_tests=$enableval], [opt_valgrind_tests=yes])
# Run self-tests under valgrind?
if test "$opt_valgrind_tests" = "yes" && test "$cross_compiling" =
no; then
AC_CHECK_PROGS(VALGRIND, valgrind)
fi
! if test -n "$VALGRIND" && $VALGRIND -q true > /dev/null 2>&1; then
opt_valgrind_tests=yes
! VALGRIND="$VALGRIND -q"
else
opt_valgrind_tests=no
VALGRIND=
--- 78,93 ----
AC_ARG_ENABLE(valgrind-tests,
AS_HELP_STRING([--enable-valgrind-tests],
[run self tests under valgrind]),
! [opt_valgrind_tests=$enableval], [opt_valgrind_tests=no])
# Run self-tests under valgrind?
if test "$opt_valgrind_tests" = "yes" && test "$cross_compiling" =
no; then
AC_CHECK_PROGS(VALGRIND, valgrind)
fi
! if test -n "$VALGRIND" && $VALGRIND true > /dev/null 2>&1; then
opt_valgrind_tests=yes
! VALGRIND="libtool --mode=execute $VALGRIND \$(VALGRIND_MEMLEAK_OPTS)"
else
opt_valgrind_tests=no
VALGRIND=