public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] tests: Try to use coredumpctl to extract core files.
@ 2017-12-23 22:31 Mark Wielaard
  2017-12-24 15:10 ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2017-12-23 22:31 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

If systemd-coredump is installed we have to use coredumpctl to extract
the core file to test. Unfortunately systemd-coredump/coredumpctl seem
to be somewhat fragile if multiple core dumps are generated/extracted
at the same time. So use a lock file to only run one core dump test at
a time (under make -j).

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tests/ChangeLog         |  5 +++++
 tests/backtrace-subr.sh | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index e16a3d04..c70d7abd 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2017-12-23  Mark Wielaard  <mark@klomp.org>
+
+	* backtrace-subr.sh (check_native_core): Use a lock file and try
+	to extract core using coredumpctl.
+
 2017-12-11  Dima Kogan  <dima@secretsauce.net>
 
         * run-aggregate-size.sh: Added check for multi-dimensional arrays.
diff --git a/tests/backtrace-subr.sh b/tests/backtrace-subr.sh
index c1f31569..e04a7ea6 100644
--- a/tests/backtrace-subr.sh
+++ b/tests/backtrace-subr.sh
@@ -137,19 +137,46 @@ check_native()
 # Backtrace core file.
 check_native_core()
 {
+# systemd-coredump/coredumpctl doesn't seem to like concurrent core dumps
+# use a lock file (fd 200) tests/core-dump-backtrace.lock
+(
   child=$1
 
   # Disable valgrind while dumping core.
   SAVED_VALGRIND_CMD="$VALGRIND_CMD"
   unset VALGRIND_CMD
 
+  # Wait for lock for 10 seconds or skip.
+  flock -x -w 10 200 || exit 77;
+
   # Skip the test if we cannot adjust core ulimit.
-  core="core.`ulimit -c unlimited || exit 77; set +ex; testrun ${abs_builddir}/$child --gencore; true`"
+  pid="`ulimit -c unlimited || exit 77; set +ex; testrun ${abs_builddir}/$child --gencore; true`"
+  core="core.$pid"
   # see if /proc/sys/kernel/core_uses_pid is set to 0
   if [ -f core ]; then
     mv core "$core"
   fi
-  if [ ! -f "$core" ]; then echo "No $core file generated"; exit 77; fi
+  type -P coredumpctl && have_coredumpctl=1 || have_coredumpctl=0
+  if [ ! -f "$core" -a $have_coredumpctl -eq 1 ]; then
+    # Maybe systemd-coredump took it. But give it some time to dump first...
+    sleep 1
+    coredumpctl --output="$core" dump $pid || rm -f $core
+
+    # Try a couple of times after waiting some more if something went wrong...
+    if [ ! -f "$core" ]; then
+      sleep 2
+      coredumpctl --output="$core" dump $pid || rm -f $core
+    fi
+
+    if [ ! -f "$core" ]; then
+      sleep 3
+      coredumpctl --output="$core" dump $pid || rm -f $core
+    fi
+  fi
+  if [ ! -f "$core" ]; then
+    echo "No $core file generated";
+    exit 77;
+  fi
 
   if [ "x$SAVED_VALGRIND_CMD" != "x" ]; then
     VALGRIND_CMD="$SAVED_VALGRIND_CMD"
@@ -163,4 +190,6 @@ check_native_core()
   cat $core.{bt,err}
   check_native_unsupported $core.err $child-$core
   check_all $core.{bt,err} $child-$core
+  rm $core{,.{bt,err}}
+) 200>${abs_builddir}/core-dump-backtrace.lock
 }
-- 
2.14.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tests: Try to use coredumpctl to extract core files.
  2017-12-23 22:31 [PATCH] tests: Try to use coredumpctl to extract core files Mark Wielaard
@ 2017-12-24 15:10 ` Mark Wielaard
  2017-12-29  0:01   ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2017-12-24 15:10 UTC (permalink / raw)
  To: elfutils-devel

On Sat, Dec 23, 2017 at 11:31:42PM +0100, Mark Wielaard wrote:
> If systemd-coredump is installed we have to use coredumpctl to extract
> the core file to test. Unfortunately systemd-coredump/coredumpctl seem
> to be somewhat fragile if multiple core dumps are generated/extracted
> at the same time. So use a lock file to only run one core dump test at
> a time (under make -j).

One small addition to appease make distcheck. We have to clean up the
lock file. We don't want to make it a tempfile because we want the file
to exist globally during all test runs.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index fca00727..a9aa8bd4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -515,6 +515,9 @@ dwarf_default_lower_bound_LDADD = $(libdw)
 system_elf_libelf_test_CPPFLAGS =
 system_elf_libelf_test_LDADD = $(libelf)
 
+# A lock file used to make sure only one test dumps core at a time
+CLEANFILES = core-dump-backtrace.lock
+
 if GCOV
 check: check-am coverage
 .PHONY: coverage

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tests: Try to use coredumpctl to extract core files.
  2017-12-24 15:10 ` Mark Wielaard
@ 2017-12-29  0:01   ` Mark Wielaard
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2017-12-29  0:01 UTC (permalink / raw)
  To: elfutils-devel

On Sun, Dec 24, 2017 at 04:10:45PM +0100, Mark Wielaard wrote:
> On Sat, Dec 23, 2017 at 11:31:42PM +0100, Mark Wielaard wrote:
> > If systemd-coredump is installed we have to use coredumpctl to extract
> > the core file to test. Unfortunately systemd-coredump/coredumpctl seem
> > to be somewhat fragile if multiple core dumps are generated/extracted
> > at the same time. So use a lock file to only run one core dump test at
> > a time (under make -j).
> 
> One small addition to appease make distcheck. We have to clean up the
> lock file. We don't want to make it a tempfile because we want the file
> to exist globally during all test runs.

I pushed this variant to master.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-29  0:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-23 22:31 [PATCH] tests: Try to use coredumpctl to extract core files Mark Wielaard
2017-12-24 15:10 ` Mark Wielaard
2017-12-29  0:01   ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).