]> Savannah Git Hosting - gnulib.git/commitdiff
valgrind-tests: Disable valgrind if it would cause all tests to fail.
authorBruno Haible <bruno@clisp.org>
Sun, 3 Jan 2021 01:14:16 +0000 (02:14 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 3 Jan 2021 01:14:16 +0000 (02:14 +0100)
Suggested by Simon Josefsson <simon@josefsson.org> in
<https://lists.gnu.org/archive/html/help-gsasl/2021-01/msg00004.html>.

* m4/valgrind-tests.m4 (gl_VALGRIND_TESTS): Test $VALGRIND on an
executable produced by the current compiler. Set VALGRIND to empty if it
does not work. Don't set VALGRIND to empty if it merely does not accept
the --error-exitcode=1 --leak-check=full options.

ChangeLog
m4/valgrind-tests.m4

index 9d9c280324b55255b166207f9d4607d9039a2f6d..840208f5ff568e33ebf53691ed20f3c7b0f06842 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2021-01-02  Bruno Haible  <bruno@clisp.org>
+
+       valgrind-tests: Disable valgrind if it would cause all tests to fail.
+       Suggested by Simon Josefsson <simon@josefsson.org> in
+       <https://lists.gnu.org/archive/html/help-gsasl/2021-01/msg00004.html>.
+       * m4/valgrind-tests.m4 (gl_VALGRIND_TESTS): Test $VALGRIND on an
+       executable produced by the current compiler. Set VALGRIND to empty if it
+       does not work. Don't set VALGRIND to empty if it merely does not accept
+       the --error-exitcode=1 --leak-check=full options.
+
 2021-01-02  Bruno Haible  <bruno@clisp.org>
 
        valgrind-tests: Really enable the valgrind options test.
index 499759dd55ee52270dec5056314b4bdb365786d4..50d90e1456112a52675db6df8e1dfdf572bee26d 100644 (file)
@@ -1,4 +1,4 @@
-# valgrind-tests.m4 serial 5
+# valgrind-tests.m4 serial 6
 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,
@@ -20,7 +20,29 @@ AC_DEFUN([gl_VALGRIND_TESTS],
   if test "$opt_valgrind_tests" = "yes" && test "$cross_compiling" = no; then
     AC_CHECK_PROGS([VALGRIND], [valgrind])
 
-    if test "$VALGRIND"; then
+    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
+      dnl executables (with exit code 126).
+      AC_CACHE_CHECK([whether valgrind works on executables produced by the compiler],
+        [gl_cv_prog_valgrind_works],
+        [AC_RUN_IFELSE(
+           [AC_LANG_SOURCE([[int main () { return 0; }]])],
+           [$VALGRIND ./conftest$ac_exeext 2>/dev/null
+            if test $? = 0; then
+              gl_cv_prog_valgrind_works=yes
+            else
+              gl_cv_prog_valgrind_works=no
+            fi
+           ],
+           [gl_cv_prog_valgrind_works=no])
+        ])
+      if test $gl_cv_prog_valgrind_works != yes; then
+        VALGRIND=
+      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'
@@ -32,8 +54,6 @@ AC_DEFUN([gl_VALGRIND_TESTS],
         ])
       if test "$gl_cv_opt_valgrind_tests" != no; then
         VALGRIND="$VALGRIND $gl_cv_opt_valgrind_tests"
-      else
-        VALGRIND=
       fi
     fi
   fi