From: Bruno Haible Date: Sun, 3 Jan 2021 01:14:16 +0000 (+0100) Subject: valgrind-tests: Disable valgrind if it would cause all tests to fail. X-Git-Tag: v1.0~3228 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=f22259966f1f52efbf5f03d274298a6417b4595c;p=gnulib.git valgrind-tests: Disable valgrind if it would cause all tests to fail. Suggested by Simon Josefsson in . * 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. --- diff --git a/ChangeLog b/ChangeLog index 9d9c280324..840208f5ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2021-01-02 Bruno Haible + + valgrind-tests: Disable valgrind if it would cause all tests to fail. + Suggested by Simon Josefsson in + . + * 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 valgrind-tests: Really enable the valgrind options test. diff --git a/m4/valgrind-tests.m4 b/m4/valgrind-tests.m4 index 499759dd55..50d90e1456 100644 --- a/m4/valgrind-tests.m4 +++ b/m4/valgrind-tests.m4 @@ -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