From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id 48A3F385482E for ; Thu, 29 Oct 2020 17:27:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 48A3F385482E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mark@klomp.org Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id D610030278CD; Thu, 29 Oct 2020 18:27:31 +0100 (CET) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 961D741E7E76; Thu, 29 Oct 2020 18:27:31 +0100 (CET) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] tests: Run valgrind also on binary tests. Date: Thu, 29 Oct 2020 18:27:24 +0100 Message-Id: <20201029172724.28643-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Oct 2020 17:27:35 -0000 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 --- libasm/ChangeLog | 5 +++++ libasm/asm_align.c | 4 ++-- tests/ChangeLog | 9 +++++++++ tests/dwfl-bug-fd-leak.c | 9 ++++++++- tests/dwfl-proc-attach.c | 7 +++++++ tests/test-wrapper.sh | 10 +++++++++- tests/vdsosyms.c | 2 ++ 7 files changed, 42 insertions(+), 4 deletions(-) diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 83a65492..d7ab8c42 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 e59a070e..c8c671b2 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 91aeadaf..95f09c38 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-28 Tom Tromey PR26773 diff --git a/tests/dwfl-bug-fd-leak.c b/tests/dwfl-bug-fd-leak.c index ee3a916b..b0913361 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 102ba181..b72cc814 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 09b4d49f..db16c591 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 7bfa7381..83ab034f 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; } -- 2.18.4