From: Mark Wielaard Date: Thu, 29 Oct 2020 15:43:14 +0000 (+0100) Subject: tests: Run valgrind also on binary tests. X-Git-Tag: elfutils-0.182~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=70717f8c1fdef3ba5e83508bd3956b2479536534;p=thirdparty%2Felfutils.git tests: Run valgrind also on binary tests. When configuring with --enable-valgrind we were only running valgrind on tests with a shell wrapper script. This patch makes sure to also run valgrind on "pure" binary tests. This found one small issue in libasm where we could be writing some uninitialized padding to an ELF file. And there were a couple tests that didn't clean up all the resources they used. Both issues are also fixed with this patch. Signed-off-by: Mark Wielaard --- diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 83a654923..d7ab8c428 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,8 @@ +2020-10-29 Mark Wielaard + + * asm_align.c (__libasm_ensure_section_space): Use calloc, not + malloc to allocate extra space. + 2020-07-19 Mark Wielaard * libasmP.h: Include libebl.h after libasm.h. diff --git a/libasm/asm_align.c b/libasm/asm_align.c index e59a070ea..c8c671b2d 100644 --- a/libasm/asm_align.c +++ b/libasm/asm_align.c @@ -143,7 +143,7 @@ __libasm_ensure_section_space (AsmScn_t *asmscn, size_t len) /* This is the first block. */ size = MAX (2 * len, 960); - asmscn->content = (struct AsmData *) malloc (sizeof (struct AsmData) + asmscn->content = (struct AsmData *) calloc (1, sizeof (struct AsmData) + size); if (asmscn->content == NULL) return -1; @@ -160,7 +160,7 @@ __libasm_ensure_section_space (AsmScn_t *asmscn, size_t len) size = MAX (2 *len, MIN (32768, 2 * asmscn->offset)); - newp = (struct AsmData *) malloc (sizeof (struct AsmData) + size); + newp = (struct AsmData *) calloc (1, sizeof (struct AsmData) + size); if (newp == NULL) return -1; diff --git a/tests/ChangeLog b/tests/ChangeLog index 13abf89ac..b84f2af0d 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2020-10-29 Mark Wielaard + + * test-wrapper.sh: Determine whether the test is a script or not + and run binaries directly under valgrind. + * dwfl-bug-fd-leak.c (main): Call getrlimit before calling setrlimit. + * dwfl-proc-attach.c (main): Call dwfl_end, pthread_cancel and + pthread_join. + * vdsosyms.c (main): Call dwfl_end. + 2020-10-30 Frank Ch. Eigler PR26775 diff --git a/tests/dwfl-bug-fd-leak.c b/tests/dwfl-bug-fd-leak.c index ee3a916b2..b09133613 100644 --- a/tests/dwfl-bug-fd-leak.c +++ b/tests/dwfl-bug-fd-leak.c @@ -101,7 +101,14 @@ main (void) /* Set locale. */ (void) setlocale (LC_ALL, ""); - struct rlimit fd_limit = { .rlim_cur = 32, .rlim_max = 32 }; + /* Get both the soft and hard limits first. The soft limit is what + will be enforced against the process. The hard limit is the max + that can be set for the soft limit. We don't want to lower it + because we might not be able to (under valgrind). */ + struct rlimit fd_limit; + if (getrlimit (RLIMIT_NOFILE, &fd_limit) < 0) + error (2, errno, "getrlimit"); + fd_limit.rlim_cur = 32; if (setrlimit (RLIMIT_NOFILE, &fd_limit) < 0) error (2, errno, "setrlimit"); diff --git a/tests/dwfl-proc-attach.c b/tests/dwfl-proc-attach.c index 102ba1811..b72cc8142 100644 --- a/tests/dwfl-proc-attach.c +++ b/tests/dwfl-proc-attach.c @@ -97,6 +97,13 @@ main (int argc __attribute__ ((unused)), if (dwfl_getthreads (dwfl, thread_callback, &threads) != DWARF_CB_OK) error (-1, 0, "dwfl_getthreads failed: %s", dwfl_errmsg (-1)); + dwfl_end (dwfl); + + pthread_cancel (thread1); + pthread_cancel (thread2); + pthread_join (thread1, NULL); + pthread_join (thread2, NULL); + return (threads == 3) ? 0 : -1; } diff --git a/tests/test-wrapper.sh b/tests/test-wrapper.sh index 09b4d49f6..db16c591a 100755 --- a/tests/test-wrapper.sh +++ b/tests/test-wrapper.sh @@ -44,6 +44,7 @@ case "$1" in *.sh) export built_library_path program_transform_name elfutils_testrun export elfutils_tests_rpath + is_shell_script="yes" ;; *) if [ $elfutils_testrun = built ]; then @@ -55,6 +56,7 @@ case "$1" in LD_LIBRARY_PATH="${libdir}:${libdir}/elfutils$old_path" fi export LD_LIBRARY_PATH + is_shell_script="no" ;; esac @@ -62,4 +64,10 @@ if [ "x$VALGRIND_CMD" != "x" ]; then export VALGRIND_CMD fi -exec "$@" +# When it is a run-*.sh script the VALGRIND_CMD will be passed on +# otherwise we'll need to run the binary explicitly under valgrind. +if [ "x$is_shell_script" == "xyes" ]; then + exec "$@" +else + exec $VALGRIND_CMD "$@" +fi diff --git a/tests/vdsosyms.c b/tests/vdsosyms.c index 7bfa73818..83ab034fb 100644 --- a/tests/vdsosyms.c +++ b/tests/vdsosyms.c @@ -103,6 +103,8 @@ main (int argc __attribute__ ((unused)), char **argv __attribute__ ((unused))) if (dwfl_getmodules (dwfl, module_callback, NULL, 0) != 0) error (1, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1)); + dwfl_end (dwfl); + /* No symbols is ok, then we haven't seen the vdso at all on this arch. */ return vdso_syms >= 0 ? 0 : -1; }