summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-09-21 13:47:45 +0200
committerMark Wielaard <mark@klomp.org>2018-09-21 13:48:12 +0200
commit69d6e67eee30c483ba53a8e1da1b3568033e3dde (patch)
tree9ace88bb74721e594ee9e34aa770c37622cb65db
parent52b6b2f1f49e7385527e9f311f248092be0c0b61 (diff)
tests: backtrace-dwarf.c improve error handling in test framework.
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>
-rw-r--r--tests/ChangeLog7
-rw-r--r--tests/backtrace-dwarf.c38
2 files changed, 31 insertions, 14 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 4e8b8144..04eeb4ac 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 35f25ed6..dfbf1856 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__ */