]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: Run valgrind also on binary tests.
authorMark Wielaard <mark@klomp.org>
Thu, 29 Oct 2020 15:43:14 +0000 (16:43 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 30 Oct 2020 23:49:42 +0000 (00:49 +0100)
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 <mark@klomp.org>
libasm/ChangeLog
libasm/asm_align.c
tests/ChangeLog
tests/dwfl-bug-fd-leak.c
tests/dwfl-proc-attach.c
tests/test-wrapper.sh
tests/vdsosyms.c

index 83a65492327061613bb6ac21ad0d50cff4bf3d25..d7ab8c428e628fd0090609e308c17c795442e7c9 100644 (file)
@@ -1,3 +1,8 @@
+2020-10-29  Mark Wielaard  <mark@klomp.org>
+
+       * asm_align.c (__libasm_ensure_section_space): Use calloc, not
+       malloc to allocate extra space.
+
 2020-07-19  Mark Wielaard  <mark@klomp.org>
 
        * libasmP.h: Include libebl.h after libasm.h.
index e59a070ea556388140c1ba10b868c1f74d5aaba8..c8c671b2dd549599f357ffe5224305f59ffe3cd0 100644 (file)
@@ -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;
 
index 13abf89ac5dd51f628947c28b500badc5b41b1ae..b84f2af0d3551000023c8a5f15e846bbfbcced9f 100644 (file)
@@ -1,3 +1,12 @@
+2020-10-29  Mark Wielaard  <mark@klomp.org>
+
+       * 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  <fche@redhat.com>
 
        PR26775
index ee3a916b26ca4218e6f368929f0faa07cfc9e837..b09133613515170a9347945f9942939b8131ed0d 100644 (file)
@@ -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");
 
index 102ba1811f3c10bbab60e2d6c1cc8011849e5fd4..b72cc8142a0e06005baa2df743fe8a20a5e8e86f 100644 (file)
@@ -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;
 }
 
index 09b4d49f624a3ed31698defde30d9f92aba560a8..db16c591a9d58c37373ad17a9aa7af1a3169bf87 100755 (executable)
@@ -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
index 7bfa738189b0b0d177e07e6d2d2a1518d6a3decd..83ab034fb93292d51b11394256194e410b2dfad5 100644 (file)
@@ -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;
 }