bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH] valgrind-tests: Better option handling.
@ 2021-05-14 12:27 Simon Josefsson via Gnulib discussion list
  2021-05-14 13:07 ` Simon Josefsson via Gnulib discussion list
  2021-05-14 13:47 ` Bruno Haible
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Josefsson via Gnulib discussion list @ 2021-05-14 12:27 UTC (permalink / raw)
  To: bug-gnulib


[-- Attachment #1.1: Type: text/plain, Size: 732 bytes --]

Hi.  I have pushed the attached patch.  It should be completely
backwards compatible, or there is a bug, so please test this.  It adds
two new variables to allow both developers and users to influence the
valgrind options used.  You may want to re-read the manual, I updated it
to assume people use the parallel automake test harness today.

Developers may want to use 'LOG_COMPILER=$(LOG_VALGRIND)' instead of
'LOG_COMPILER=$(VALGRIND)' in your Makefile.am, to make it easier for
end-users to modify the options passed to valgrind.  The old style still
works fine, and in the same way as before.  The reason for the change is
to enable end-users to be able to change VALGRINDFLAGS during a 'make
check' phase if they want.

/Simon

[-- Attachment #1.2: 0001-valgrind-tests-Better-option-handling.patch --]
[-- Type: text/x-diff, Size: 10722 bytes --]

From e0a1ea5e1d20918f6850a2ab8cb86c691cd8b46c Mon Sep 17 00:00:00 2001
From: Simon Josefsson <simon@josefsson.org>
Date: Fri, 14 May 2021 14:17:20 +0200
Subject: [PATCH] valgrind-tests: Better option handling.

* m4/valgrind-tests.m4: Support new variables VALGRINDFLAGS and
DEFAULT_VALGRINDFLAGS.
* doc/valgrind-tests.texi (Running self-tests under valgrind): Improve.
---
 ChangeLog               |   8 +++
 doc/valgrind-tests.texi | 105 +++++++++++++++++++++++++++++++++++-----
 m4/valgrind-tests.m4    |  67 +++++++++++++++++--------
 3 files changed, 148 insertions(+), 32 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4716f78a8..daeb44ab4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-05-14  Simon Josefsson  <simon@josefsson.org>
+
+	valgrind-tests: Better option handling.
+	* m4/valgrind-tests.m4: Support new variables VALGRINDFLAGS and
+	DEFAULT_VALGRINDFLAGS.
+	* doc/valgrind-tests.texi (Running self-tests under valgrind):
+	Improve.
+
 2021-05-14  Markus Mützel  <markus.muetzel@gmx.de>  (tiny change)
 
 	windows-spawn: Don't assume that UNICODE is not defined.
diff --git a/doc/valgrind-tests.texi b/doc/valgrind-tests.texi
index fef910edf..9f3b30968 100644
--- a/doc/valgrind-tests.texi
+++ b/doc/valgrind-tests.texi
@@ -11,6 +11,7 @@ at the discretion of the developer.
 
 @menu
 * Using valgrind automatically::
+* Valgrind options::
 * Using valgrind manually::
 * Valgrind and shell scripts::
 @end menu
@@ -19,19 +20,93 @@ at the discretion of the developer.
 @subsection Using valgrind without developer intervention
 
 The @code{valgrind-tests} module searches for Valgrind at configure time
-and declares the @code{VALGRIND} automake variable for use with automake's
-@code{TESTS_ENVIRONMENT}.
+and declares the @code{LOG_VALGRIND} automake variable for use with
+automake's @code{LOG_COMPILER}.
 
 After importing the @code{valgrind-tests} module to your project, you
 use it by adding the following to the @code{Makefile.am} that runs the
 self-tests:
 
 @smallexample
-TESTS_ENVIRONMENT = $(VALGRIND)
+LOG_COMPILER = $(LOG_VALGRIND)
 @end smallexample
 
 This will run all self-checks under valgrind.
 
+Replace @code{LOG_COMPILER} with @code{TESTS_ENVIRONMENT} if you are
+using the old serial test harness.
+
+If you desire a project-wide decision that valgrind is not enabled by
+default, but still allow users to enable it with
+@code{--enable-valgrind-tests} you may put the following in configure.ac
+before gl_INIT.
+
+@smallexample
+gl_VALGRIND_TESTS_DEFAULT_NO
+@end smallexample
+
+@node Valgrind options
+@subsection Valgrind options
+
+The @code{VALGRIND} variable holds the name of the valgrind binary and
+some options passed to valgrind.  You may provide additional options
+that are passed to valgrind using the @samp{VALGRINDFLAGS} variable, for
+example:
+
+@smallexample
+./configure VALGRINDFLAGS="--suppressions=/your/local/valgrind/suppressions/file.txt"
+@end smallexample
+
+Alternatively during build phase:
+
+@smallexample
+make check VALGRINDFLAGS="--suppressions=/your/local/valgrind/suppressions/file.txt"
+@end smallexample
+
+This is useful if you have a valgrind suppression files that are needed
+to avoid triggering errors for known errors, typically in system
+libraries.
+
+The @code{VALGRIND} variable include options that are useful when
+valgrind is run non-interactively through the test harness.  The default
+parameters are @code{-q} to silence the output,
+@code{--error-exitcode=1} to cause valgrind errors to be treated as
+fatal errors, and @code{--leak-check=full} to check for memory leaks.
+
+These options can be controlled through the @code{DEFAULT_VALGRINDFLAGS}
+variable.  For example, when configuring the package:
+
+@smallexample
+./configure DEFAULT_VALGRINDFLAGS="--quiet"
+@end smallexample
+
+Alternatively, during the build phase:
+
+@smallexample
+make check DEFAULT_VALGRINDFLAGS="--quiet"
+@end smallexample
+
+That would have the effect of removing @code{--error-exitcode=1} and
+@code{--leak-check=full} from the default options, thus causing any
+valgrind errors to be silently ignored, instead of causing fatal test
+failures.
+
+As a developer you may use the variables in @code{configure.ac} before
+calling @code{gl_INIT}, like this if your program has deeply-nested call
+chains:
+
+@smallexample
+gl_EARLY
+...
+VALGRINDFLAGS="$VALGRINDFLAGS --num-callers=42"
+...
+gl_INIT
+@end smallexample
+
+Note that any user-supplied @code{VALGRINDFLAGS} value is preserved,
+which is usually what you want.
+
+
 @node Using valgrind manually
 @subsection Using valgrind at the developer's discretion
 
@@ -58,24 +133,28 @@ There are two ways to avoid this:
 
 @itemize @bullet
 @item
-You can make use of the @code{build-aux/run-test} script from Gnulib.
-Add these lines to your @code{Makefile.am}:
+Using the Automake parallel-tests feature, you can use the following instead:
 
 @smallexample
-# This must be the last thing that gets added to TESTS_ENVIRONMENT.
-TESTS_ENVIRONMENT += $(SHELL) $(top_srcdir)/build-aux/run-test '$(VALGRIND)'
+TEST_EXTENSIONS = .pl .sh
+LOG_COMPILER = $(LOG_VALGRIND)
 @end smallexample
 
+Then valgrind will only be used for the non-.sh and non-.pl tests.
+
+For old automake, you will need @code{AUTOMAKE_OPTIONS = parallel-tests}
+to enable the parallel test harness.
+
 @item
-Using the Automake parallel-tests feature, you can use the following instead:
+You can make use of the @code{build-aux/run-test} script from Gnulib.
+Add these lines to your @code{Makefile.am}:
 
 @smallexample
-AUTOMAKE_OPTIONS = parallel-tests
-TEST_EXTENSIONS = .pl .sh
-LOG_COMPILER = $(VALGRIND)
+LOG_COMPILER += $(SHELL) $(top_srcdir)/build-aux/run-test '$(LOG_VALGRIND)'
 @end smallexample
 
-Then valgrind will only be used for the non-.sh and non-.pl tests.
+Replace @code{LOG_COMPILER} with @code{TESTS_ENVIRONMENT} if you use the
+old serial test harness.
 @end itemize
 
 However, with this measure in place, binaries invoked through scripts will
@@ -84,7 +163,7 @@ variables in the @code{TESTS_ENVIRONMENT} variable that are then used by the
 shell scripts.  For example, add the following:
 
 @smallexample
-TESTS_ENVIRONMENT = VALGRIND='$(VALGRIND)'
+TESTS_ENVIRONMENT = VALGRIND='$(LOG_VALGRIND)'
 @end smallexample
 
 And then modify the shell scripts to invoke the binary prefixed with
diff --git a/m4/valgrind-tests.m4 b/m4/valgrind-tests.m4
index 50d90e145..9fc9d5b37 100644
--- a/m4/valgrind-tests.m4
+++ b/m4/valgrind-tests.m4
@@ -1,4 +1,4 @@
-# valgrind-tests.m4 serial 6
+# valgrind-tests.m4 serial 7
 dnl Copyright (C) 2008-2021 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,18 +8,60 @@ dnl From Simon Josefsson
 
 # gl_VALGRIND_TESTS()
 # -------------------
-# Check if valgrind is available, and set VALGRIND to it if available.
-AC_DEFUN([gl_VALGRIND_TESTS],
+# Check if valgrind is available.
+
+# Sets VALGRIND to command line (including options) to invoke valgrind
+# with, may be used directly in autoconf, makefiles or shell scripts.
+
+# Sets LOG_VALGRIND, suitable for use with LOG_COMPILER, that in a
+# makefile will expand to command line to invoke self-tests with,
+# i.e., LOG_VALGRIND = $(VALGRIND) $(DEFAULT_VALGRINDFLAGS)
+# $(VALGRINDFLAGS).
+
+# Whether to look for valgrind and set the variables can be influenced
+# by calling gl_VALGRIND_TESTS_DEFAULT_NO in configure.ac.
+# Regardless, the user can change the choice through the options
+# --enable-valgrind-tests or --disable-valgrind-tests.
+
+# You may modify the VALGRIND, DEFAULT_VALGRINDFLAGS and VALGRINDFLAGS
+# variables before calling this function to override defaults.  Either
+# as developer from configure.ac or user on the ./configure command
+# line.
+
+AC_DEFUN([gl_VALGRIND_TESTS_DEFAULT_NO],
+[
+  gl_valgrind_tests_default=no
+])
+
+AC_DEFUN_ONCE([gl_VALGRIND_TESTS],
 [
   AC_ARG_ENABLE([valgrind-tests],
     AS_HELP_STRING([--disable-valgrind-tests],
                    [don't try to run self tests under valgrind]),
-    [opt_valgrind_tests=$enableval], [opt_valgrind_tests=yes])
+    [opt_valgrind_tests=$enableval], [opt_valgrind_tests=${gl_valgrind_tests_default:-yes}])
 
   # Run self-tests under valgrind?
   if test "$opt_valgrind_tests" = "yes" && test "$cross_compiling" = no; then
     AC_CHECK_PROGS([VALGRIND], [valgrind])
 
+    AC_SUBST([DEFAULT_VALGRINDFLAGS])
+    if test -z "$DEFAULT_VALGRINDFLAGS"; then
+      DEFAULT_VALGRINDFLAGS="-q --error-exitcode=1 --leak-check=full"
+    fi
+    AC_ARG_VAR([VALGRINDFLAGS], [Additional flags for Valgrind])
+
+    if test -n "$VALGRIND"; then
+      AC_CACHE_CHECK([for valgrind options for tests],
+        [gl_cv_opt_valgrind_tests],
+        [AS_IF([$VALGRIND $DEFAULT_VALGRINDFLAGS $VALGRINDFLAGS true],
+               [gl_cv_opt_valgrind_tests="$DEFAULT_VALGRINDFLAGS $VALGRINDFLAGS"],
+               [gl_cv_opt_valgrind_tests=no])
+        ])
+      if test "$gl_cv_opt_valgrind_tests" != no; then
+        VALGRIND="$VALGRIND $gl_cv_opt_valgrind_tests"
+      fi
+    fi
+
     if test -n "$VALGRIND"; then
       dnl On Ubuntu 16.04, /usr/bin/valgrind works only on 64-bit executables
       dnl but fails on 32-bit executables (with exit code 1) and on x86_64-x32
@@ -28,7 +70,7 @@ AC_DEFUN([gl_VALGRIND_TESTS],
         [gl_cv_prog_valgrind_works],
         [AC_RUN_IFELSE(
            [AC_LANG_SOURCE([[int main () { return 0; }]])],
-           [$VALGRIND ./conftest$ac_exeext 2>/dev/null
+           [$VALGRIND $gl_cv_opt_valgrind_tests ./conftest$ac_exeext 2>/dev/null
             if test $? = 0; then
               gl_cv_prog_valgrind_works=yes
             else
@@ -42,19 +84,6 @@ AC_DEFUN([gl_VALGRIND_TESTS],
       fi
     fi
 
-    if test -n "$VALGRIND"; then
-      AC_CACHE_CHECK([for valgrind options for tests],
-        [gl_cv_opt_valgrind_tests],
-        [gl_valgrind_opts='-q --error-exitcode=1 --leak-check=full'
-         if $VALGRIND $gl_valgrind_opts ls > /dev/null 2>&1; then
-           gl_cv_opt_valgrind_tests="$gl_valgrind_opts"
-         else
-           gl_cv_opt_valgrind_tests=no
-         fi
-        ])
-      if test "$gl_cv_opt_valgrind_tests" != no; then
-        VALGRIND="$VALGRIND $gl_cv_opt_valgrind_tests"
-      fi
-    fi
+   AC_SUBST([LOG_VALGRIND], ["\$(VALGRIND) \$(DEFAULT_VALGRINDFLAGS) \$(VALGRINDFLAGS)"])
   fi
 ])
-- 
2.20.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] valgrind-tests: Better option handling.
  2021-05-14 12:27 [PATCH] valgrind-tests: Better option handling Simon Josefsson via Gnulib discussion list
@ 2021-05-14 13:07 ` Simon Josefsson via Gnulib discussion list
  2021-05-14 13:47 ` Bruno Haible
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Josefsson via Gnulib discussion list @ 2021-05-14 13:07 UTC (permalink / raw)
  To: Simon Josefsson via Gnulib discussion list


[-- Attachment #1.1: Type: text/plain, Size: 59 bytes --]

Further testing quickly found a small bug, pushed.

/Simon

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-valgrind-tests-Fix-LOG_VALGRIND-when-valgrind-is-mis.patch --]
[-- Type: text/x-diff, Size: 1718 bytes --]

From 784fdea59920d69998b59ab326c11a8a2a93ef88 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <simon@josefsson.org>
Date: Fri, 14 May 2021 15:03:25 +0200
Subject: [PATCH] valgrind-tests: Fix LOG_VALGRIND when valgrind is missing.

* m4/valgrind-tests.m4: Clear all variables when missing.
---
 ChangeLog            |  5 +++++
 m4/valgrind-tests.m4 | 11 +++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index daeb44ab4..8ab1a4b2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-05-14  Simon Josefsson  <simon@josefsson.org>
+
+	valgrind-tests: Fix LOG_VALGRIND when valgrind is missing.
+	* m4/valgrind-tests.m4: Clear all variables when missing.
+
 2021-05-14  Simon Josefsson  <simon@josefsson.org>
 
 	valgrind-tests: Better option handling.
diff --git a/m4/valgrind-tests.m4 b/m4/valgrind-tests.m4
index 9fc9d5b37..6453430e9 100644
--- a/m4/valgrind-tests.m4
+++ b/m4/valgrind-tests.m4
@@ -1,4 +1,4 @@
-# valgrind-tests.m4 serial 7
+# valgrind-tests.m4 serial 8
 dnl Copyright (C) 2008-2021 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -79,9 +79,12 @@ AC_DEFUN_ONCE([gl_VALGRIND_TESTS],
            ],
            [gl_cv_prog_valgrind_works=no])
         ])
-      if test $gl_cv_prog_valgrind_works != yes; then
-        VALGRIND=
-      fi
+    fi
+
+    if test $gl_cv_prog_valgrind_works != yes; then
+      VALGRIND=
+      VALGRINDFLAGS=
+      DEFAULT_VALGRINDFLAGS=
     fi
 
    AC_SUBST([LOG_VALGRIND], ["\$(VALGRIND) \$(DEFAULT_VALGRINDFLAGS) \$(VALGRINDFLAGS)"])
-- 
2.20.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] valgrind-tests: Better option handling.
  2021-05-14 12:27 [PATCH] valgrind-tests: Better option handling Simon Josefsson via Gnulib discussion list
  2021-05-14 13:07 ` Simon Josefsson via Gnulib discussion list
@ 2021-05-14 13:47 ` Bruno Haible
  2021-05-14 17:38   ` Simon Josefsson via Gnulib discussion list
  1 sibling, 1 reply; 5+ messages in thread
From: Bruno Haible @ 2021-05-14 13:47 UTC (permalink / raw)
  To: bug-gnulib, Simon Josefsson

Hi Simon,

> +Replace @code{LOG_COMPILER} with @code{TESTS_ENVIRONMENT} if you are
> +using the old serial test harness.

Assuming I am a GNU package maintainer and I read this paragraph. How do
I know whether my package uses the "old serial test harness"? Can I
determine this by looking at configure.ac? Or at the main Makefile.am?

Bruno



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] valgrind-tests: Better option handling.
  2021-05-14 13:47 ` Bruno Haible
@ 2021-05-14 17:38   ` Simon Josefsson via Gnulib discussion list
  2021-05-14 20:01     ` Bruno Haible
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Josefsson via Gnulib discussion list @ 2021-05-14 17:38 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib


[-- Attachment #1.1: Type: text/plain, Size: 1057 bytes --]

Bruno Haible <bruno@clisp.org> writes:

> Hi Simon,
>
>> +Replace @code{LOG_COMPILER} with @code{TESTS_ENVIRONMENT} if you are
>> +using the old serial test harness.
>
> Assuming I am a GNU package maintainer and I read this paragraph. How do
> I know whether my package uses the "old serial test harness"? Can I
> determine this by looking at configure.ac? Or at the main Makefile.am?

I suspect almost everyone is using the parallel test harness now since
it is the default since automake 1.11.3, however I clarified the manual,
does it look okay? I fixed some more things to make it actual work too.

Another read through the manual section would be welcome to make sure it
is now correct and complete.  Review of the recent changes to
valgrind-tests.m4 is also appreciated - I didn't want to break backwards
compatibility for the VALGRIND variable so it became a bit complicated.
Also I'm not sure what the best names to use for variables are.  If we
want to fix anything, let's do it relatively soon before people start to
use the new version.

/Simon

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-valgrind-tests-Doc-fix-and-introduce-AM_VALGRINDFLAG.patch --]
[-- Type: text/x-diff, Size: 6276 bytes --]

From 93be8dd0d91d7e547a83ab3a8c498b2a61a17b75 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <simon@josefsson.org>
Date: Fri, 14 May 2021 19:23:23 +0200
Subject: [PATCH] valgrind-tests: Doc fix and introduce AM_VALGRINDFLAGS.

* doc/valgrind-tests.texi (Using valgrind automatically): Clarify
when the parallel vs serial test harness is used, suggested by
Bruno Haible <bruno@clisp.org>.
* m4/valgrind-tests.m4: Add VALGRIND_PROGRAM and AM_VALGRINDFLAGS.
---
 ChangeLog               |  8 ++++++++
 doc/valgrind-tests.texi | 22 +++++++++++++++++-----
 m4/valgrind-tests.m4    | 25 ++++++++++++++++++-------
 3 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 191f4549e..136445e8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-05-14  Simon Josefsson  <simon@josefsson.org>
+
+	valgrind-tests: Doc fix and introduce AM_VALGRINDFLAGS.
+	* doc/valgrind-tests.texi (Using valgrind automatically): Clarify
+	when the parallel vs serial test harness is used, suggested by
+	Bruno Haible <bruno@clisp.org>.
+	* m4/valgrind-tests.m4: Add VALGRIND_PROGRAM and AM_VALGRINDFLAGS.
+
 2021-05-14  Bruno Haible  <bruno@clisp.org>
 
 	malloc-gnu, realloc-gnu, calloc-gnu: Ensure errno gets set to ENOMEM.
diff --git a/doc/valgrind-tests.texi b/doc/valgrind-tests.texi
index 9f3b30968..96a6bbbee 100644
--- a/doc/valgrind-tests.texi
+++ b/doc/valgrind-tests.texi
@@ -34,7 +34,11 @@ LOG_COMPILER = $(LOG_VALGRIND)
 This will run all self-checks under valgrind.
 
 Replace @code{LOG_COMPILER} with @code{TESTS_ENVIRONMENT} if you are
-using the old serial test harness.
+using the old serial test harness.  The parallel test harness has been
+the default in automake since version 1.11.3, but if you are using an
+older automake, or put @samp{serial-tests} in
+@samp{AM_INIT_AUTOMAKE}/@samp{AUTOMAKE_OPTIONS} you would still be using
+the serial test harness.
 
 If you desire a project-wide decision that valgrind is not enabled by
 default, but still allow users to enable it with
@@ -54,13 +58,13 @@ that are passed to valgrind using the @samp{VALGRINDFLAGS} variable, for
 example:
 
 @smallexample
-./configure VALGRINDFLAGS="--suppressions=/your/local/valgrind/suppressions/file.txt"
+./configure VALGRINDFLAGS="--suppressions=~/local.supp"
 @end smallexample
 
 Alternatively during build phase:
 
 @smallexample
-make check VALGRINDFLAGS="--suppressions=/your/local/valgrind/suppressions/file.txt"
+make check VALGRINDFLAGS="--suppressions=~/local.supp"
 @end smallexample
 
 This is useful if you have a valgrind suppression files that are needed
@@ -106,6 +110,14 @@ gl_INIT
 Note that any user-supplied @code{VALGRINDFLAGS} value is preserved,
 which is usually what you want.
 
+Finally, as a developer you may want to provide additional per-directory
+options to valgrind and the @code{AM_VALGRINDFLAGS} variable can be used
+for this.  For example:
+
+@smallexample
+AM_VALGRINDFLAGS = --suppressions=$(srcdir)/local-valgrind.supp
+LOG_COMPILER = $(LOG_VALGRIND)
+@end smallexample
 
 @node Using valgrind manually
 @subsection Using valgrind at the developer's discretion
@@ -142,8 +154,8 @@ LOG_COMPILER = $(LOG_VALGRIND)
 
 Then valgrind will only be used for the non-.sh and non-.pl tests.
 
-For old automake, you will need @code{AUTOMAKE_OPTIONS = parallel-tests}
-to enable the parallel test harness.
+For old automake (before 1.11.3), you will need @code{AUTOMAKE_OPTIONS =
+parallel-tests} to enable the parallel test harness.
 
 @item
 You can make use of the @code{build-aux/run-test} script from Gnulib.
diff --git a/m4/valgrind-tests.m4 b/m4/valgrind-tests.m4
index b6b46a496..772737266 100644
--- a/m4/valgrind-tests.m4
+++ b/m4/valgrind-tests.m4
@@ -13,10 +13,10 @@ dnl From Simon Josefsson
 # Sets VALGRIND to command line (including options) to invoke valgrind
 # with, may be used directly in autoconf, makefiles or shell scripts.
 
-# Sets LOG_VALGRIND, suitable for use with LOG_COMPILER, that in a
-# makefile will expand to command line to invoke self-tests with,
+# Sets LOG_VALGRIND, suitable for use with LOG_COMPILER, that in
+# Makefile will expand to command line to invoke self-tests with,
 # i.e., LOG_VALGRIND = $(VALGRIND) $(DEFAULT_VALGRINDFLAGS)
-# $(VALGRINDFLAGS).
+# $(VALGRINDFLAGS) $(AM_VALGRINDFLAGS).
 
 # Whether to look for valgrind and set the variables can be influenced
 # by calling gl_VALGRIND_TESTS_DEFAULT_NO in configure.ac.
@@ -26,7 +26,8 @@ dnl From Simon Josefsson
 # You may modify the VALGRIND, DEFAULT_VALGRINDFLAGS and VALGRINDFLAGS
 # variables before calling this function to override defaults.  Either
 # as developer from configure.ac or user on the ./configure command
-# line.
+# line.  You may set the AM_VALGRINDFLAGS in Makefile.am to provide a
+# per-directory additional flag.
 
 AC_DEFUN([gl_VALGRIND_TESTS_DEFAULT_NO],
 [
@@ -44,6 +45,13 @@ AC_DEFUN_ONCE([gl_VALGRIND_TESTS],
   if test "$opt_valgrind_tests" = "yes" && test "$cross_compiling" = no; then
     AC_CHECK_PROGS([VALGRIND], [valgrind])
 
+    # VALGRIND_PROGRAM contains the tool found by AC_CHECK_PROGS.  For
+    # backwards compatibility, the VALGRIND variable is later modified
+    # to also include all enabled options.  However the new variable
+    # LOG_VALGRIND needs to be able to refer to the valgrind tool
+    # without options, hence it uses this variable.
+    AC_SUBST([VALGRIND_PROGRAM], [$VALGRIND])
+
     AC_SUBST([DEFAULT_VALGRINDFLAGS])
     if test -z "$DEFAULT_VALGRINDFLAGS"; then
       DEFAULT_VALGRINDFLAGS="-q --error-exitcode=1 --leak-check=full"
@@ -81,12 +89,15 @@ AC_DEFUN_ONCE([gl_VALGRIND_TESTS],
         ])
     fi
 
+    AC_SUBST([AM_VALGRINDFLAGS])
+    AC_SUBST([LOG_VALGRIND], ["\$(VALGRIND_PROGRAM) \$(DEFAULT_VALGRINDFLAGS) \$(VALGRINDFLAGS) \$(AM_VALGRINDFLAGS)"])
+
     if test "$gl_cv_prog_valgrind_works" != yes; then
+      DEFAULT_VALGRINDFLAGS=
+      LOG_VALGRIND=
       VALGRIND=
       VALGRINDFLAGS=
-      DEFAULT_VALGRINDFLAGS=
+      VALGRIND_PROGRAM=
     fi
-
-   AC_SUBST([LOG_VALGRIND], ["\$(VALGRIND) \$(DEFAULT_VALGRINDFLAGS) \$(VALGRINDFLAGS)"])
   fi
 ])
-- 
2.20.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] valgrind-tests: Better option handling.
  2021-05-14 17:38   ` Simon Josefsson via Gnulib discussion list
@ 2021-05-14 20:01     ` Bruno Haible
  0 siblings, 0 replies; 5+ messages in thread
From: Bruno Haible @ 2021-05-14 20:01 UTC (permalink / raw)
  To: Simon Josefsson; +Cc: bug-gnulib

Hi Simon,

> > Assuming I am a GNU package maintainer and I read this paragraph. How do
> > I know whether my package uses the "old serial test harness"? Can I
> > determine this by looking at configure.ac? Or at the main Makefile.am?
> 
> I suspect almost everyone is using the parallel test harness now since
> it is the default since automake 1.11.3, however I clarified the manual,
> does it look okay?

Yes, this is clear now. Everyone can now see which test harness their package
is using. Mine are indeed using the new (parallel) one :-)

Thanks.

Bruno



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-14 20:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 12:27 [PATCH] valgrind-tests: Better option handling Simon Josefsson via Gnulib discussion list
2021-05-14 13:07 ` Simon Josefsson via Gnulib discussion list
2021-05-14 13:47 ` Bruno Haible
2021-05-14 17:38   ` Simon Josefsson via Gnulib discussion list
2021-05-14 20:01     ` Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).