From 9f0fb75b8e121a93b0f63dd823fa86ffd44e8e5d Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Wed, 12 Jun 2024 11:08:39 +0100 Subject: libctf: suppress spurious failure of malloc-counting tests under valgrind The libctf-regression/open-error-free.c test works by interposing malloc and counting mallocs and frees across libctf operations. This only works under suitably-interposable mallocs on systems supporting dlsym (RTLD_NEXT, ...), so its operation is restricted to glibc systems for now, but also it interacts badly with valgrind, which interposes malloc itself. Detect a running valgrind and skip the test. Add new facilities allowing libctf lookup tests to declare themselves unsupported, by printing "UNSUPPORTED: " and then some meaningful message instead of their normal output. libctf/ * configure.ac: Check for . * config.h.in: Regenerate. * configure: Likewise. * testsuite/lib/ctf-lib.exp (run_lookup_test): Add support for UNSUPPORTED tests. * testsuite/libctf-regression/open-error-free.c: When running under valgrind, this test is unsupported. --- libctf/testsuite/lib/ctf-lib.exp | 5 +++++ libctf/testsuite/libctf-regression/open-error-free.c | 13 +++++++++++++ 2 files changed, 18 insertions(+) (limited to 'libctf/testsuite') diff --git a/libctf/testsuite/lib/ctf-lib.exp b/libctf/testsuite/lib/ctf-lib.exp index eb2b738..cfd36be 100644 --- a/libctf/testsuite/lib/ctf-lib.exp +++ b/libctf/testsuite/lib/ctf-lib.exp @@ -270,6 +270,11 @@ proc run_lookup_test { name } { set results [run_host_cmd "$opts(wrapper) tmpdir/lookup" $lookup_output] } + if { [regexp {^UNSUPPORTED: (.*)$} $results -> reason] } { + unsupported "$testname: $reason" + return 0 + } + set f [open "tmpdir/lookup.out" "w"] puts $f $results close $f diff --git a/libctf/testsuite/libctf-regression/open-error-free.c b/libctf/testsuite/libctf-regression/open-error-free.c index 5e48744..edc5f34 100644 --- a/libctf/testsuite/libctf-regression/open-error-free.c +++ b/libctf/testsuite/libctf-regression/open-error-free.c @@ -1,6 +1,7 @@ /* Make sure that, on error, an opened dict is properly freed. */ #define _GNU_SOURCE 1 +#include "config.h" #include #include #include @@ -8,6 +9,10 @@ #include #include +#ifdef HAVE_VALGRIND_VALGRIND_H +#include +#endif + static unsigned long long malloc_count; static unsigned long long free_count; @@ -111,6 +116,14 @@ int main (void) ctf_next_t *it = NULL; unsigned long long frozen_malloc_count, frozen_free_count; +#ifdef HAVE_VALGRIND_VALGRIND_H + if (RUNNING_ON_VALGRIND) + { + printf ("UNSUPPORTED: valgrind interferes with malloc counting\n"); + return 0; + } +#endif + if ((fp = ctf_create (&err)) == NULL) goto open_err; -- cgit v1.1