]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add test for backtrace-string
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 14 Mar 2019 08:10:45 +0000 (10:10 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 25 Mar 2019 12:16:16 +0000 (14:16 +0200)
src/lib/Makefile.am
src/lib/test-backtrace.c [new file with mode: 0644]
src/lib/test-lib.inc

index 67edf9aec5bb40733d37c4ec383227479fd8f848..856cc82539cbfd7aa7a0167e2b1b3c35057d53b1 100644 (file)
@@ -335,6 +335,7 @@ test_lib_SOURCES = \
        test-lib.c \
        test-array.c \
        test-aqueue.c \
+       test-backtrace.c \
        test-base32.c \
        test-base64.c \
        test-bits.c \
diff --git a/src/lib/test-backtrace.c b/src/lib/test-backtrace.c
new file mode 100644 (file)
index 0000000..dac38ac
--- /dev/null
@@ -0,0 +1,31 @@
+#include "test-lib.h"
+#include "backtrace-string.h"
+#include <setjmp.h>
+#include <signal.h>
+
+static void test_backtrace_get(void)
+{
+       test_begin("backtrace_get");
+       const char *bt = NULL;
+#if (defined(HAVE_LIBUNWIND))
+        test_assert(backtrace_get(&bt) == 0);
+       /* check that this function is there */
+        test_assert(strstr(bt, "test_backtrace") != NULL);
+       /* make sure the backtrace_get is not */
+       test_assert(strstr(bt, " backtrace_get") == NULL);
+#elif (defined(HAVE_BACKTRACE_SYMBOLS) && defined(HAVE_EXECINFO_H)) || \
+      (defined(HAVE_WALKCONTEXT) && defined(HAVE_UCONTEXT_H))
+       test_assert(backtrace_get(&bt) == 0);
+       /* it should have some kind of main in it */
+       test_assert(strstr(bt, "main") != NULL);
+#else
+       /* should not work in this context */
+       test_assert(backtrace_get(&bt) == -1);
+#endif
+       test_end();
+}
+
+void test_backtrace(void)
+{
+       test_backtrace_get();
+}
index 94acc428b86c26f631856ced1eb63f49d6112011..e72357c7ab25725d830a477cd49349c3707e559f 100644 (file)
@@ -5,6 +5,7 @@
 TEST(test_aqueue)
 TEST(test_array)
 FATAL(fatal_array)
+TEST(test_backtrace)
 TEST(test_base32)
 TEST(test_base64)
 TEST(test_bits)