Simon Josefsson wrote in <https://lists.gnu.org/archive/html/help-gsasl/2021-01/msg00004.html>: > > On Ubuntu 16.04 x86_64, in 32-bit mode (CC="gcc -m32"), configure, > > make, > > and "make install" work fine, but "make -k check" fails several > > tests: > > Right. It would be nice if gnulib's valgrind m4 test was a bit > smarter, maybe it should try to build a small program printing > something to stdout and see if valgrind is able to run it and that it > prints the magic string to stdout. If that doesn't work, disable > valgrind.
Implemented as follows. Hope I didn't break anything. 2021-01-02 Bruno Haible <br...@clisp.org> valgrind-tests: Disable valgrind if it would cause all tests to fail. Suggested by Simon Josefsson <si...@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. diff --git a/m4/valgrind-tests.m4 b/m4/valgrind-tests.m4 index 499759d..50d90e1 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