[COMMITTED] tests: backtrace-dwarf.c improve error handling in test framework.

Mark Wielaard mark@klomp.org
Fri Sep 21 11:51:00 GMT 2018


To debug https://sourceware.org/bugzilla/show_bug.cgi?id=23673
clean up the test framework so we know what exactly failed.

Suggested-by: Dmitry V. Levin <ldv@sourceware.org>
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tests/ChangeLog         |  7 +++++++
 tests/backtrace-dwarf.c | 38 ++++++++++++++++++++++++--------------
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 4e8b814..04eeb4a 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2018-09-18  Mark Wielaard  <mark@klomp.org>
+
+	* backtrace-dwarf.c (thread_callback): Only error when
+	dwfl_thread_getframes returns an error.
+	(main): Don't call abort or assert but print an error when
+	something unexpected happens.
+
 2018-09-13  Mark Wielaard  <mark@klomp.org>
 
 	* run-strip-test-many.sh: New test.
diff --git a/tests/backtrace-dwarf.c b/tests/backtrace-dwarf.c
index 35f25ed..dfbf185 100644
--- a/tests/backtrace-dwarf.c
+++ b/tests/backtrace-dwarf.c
@@ -1,5 +1,5 @@
 /* Test program for unwinding of complicated DWARF expressions.
-   Copyright (C) 2013, 2015 Red Hat, Inc.
+   Copyright (C) 2013, 2015, 2018 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -16,7 +16,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
-#include <assert.h>
 #include <inttypes.h>
 #include <stdio_ext.h>
 #include <locale.h>
@@ -117,9 +116,11 @@ frame_callback (Dwfl_Frame *state, void *frame_arg)
 static int
 thread_callback (Dwfl_Thread *thread, void *thread_arg)
 {
-  dwfl_thread_getframes (thread, frame_callback, NULL);
+  if (dwfl_thread_getframes (thread, frame_callback, NULL) == -1)
+    error (1, 0, "dwfl_thread_getframes: %s", dwfl_errmsg (-1));
+
   /* frame_callback shall exit (0) on success.  */
-  error (1, 0, "dwfl_thread_getframes: %s", dwfl_errmsg (-1));
+  printf ("dwfl_thread_getframes returned, main not found\n");
   return DWARF_CB_ABORT;
 }
 
@@ -141,13 +142,18 @@ main (int argc __attribute__ ((unused)), char **argv)
   switch (pid)
   {
     case -1:
-      abort ();
+      perror ("fork failed");
+      exit (-1);
     case 0:;
       long l = ptrace (PTRACE_TRACEME, 0, NULL, NULL);
-      assert (errno == 0);
-      assert (l == 0);
+      if (l != 0)
+	{
+	  perror ("PTRACE_TRACEME failed");
+	  exit (-1);
+	}
       cleanup_13_main ();
-      abort ();
+      printf ("cleanup_13_main returned, impossible...\n");
+      exit (-1);
     default:
       break;
   }
@@ -155,16 +161,20 @@ main (int argc __attribute__ ((unused)), char **argv)
   errno = 0;
   int status;
   pid_t got = waitpid (pid, &status, 0);
-  assert (errno == 0);
-  assert (got == pid);
-  assert (WIFSTOPPED (status));
-  assert (WSTOPSIG (status) == SIGABRT);
+  if (got != pid)
+    error (1, errno, "waitpid returned %d", got);
+  if (!WIFSTOPPED (status))
+    error (1, 0, "unexpected wait status %u", status);
+  if (WSTOPSIG (status) != SIGABRT)
+    error (1, 0, "unexpected signal %u", WSTOPSIG (status));
 
   Dwfl *dwfl = pid_to_dwfl (pid);
-  dwfl_getthreads (dwfl, thread_callback, NULL);
+  if (dwfl_getthreads (dwfl, thread_callback, NULL) == -1)
+    error (1, 0, "dwfl_getthreads: %s", dwfl_errmsg (-1));
 
   /* There is an exit (0) call if we find the "main" frame,  */
-  error (1, 0, "dwfl_getthreads: %s", dwfl_errmsg (-1));
+  printf ("dwfl_getthreads returned, main not found\n");
+  exit (-1);
 }
 
 #endif /* ! __linux__ */
-- 
1.8.3.1



More information about the Elfutils-devel mailing list