From: Aki Tuomi Date: Thu, 14 Mar 2019 08:10:45 +0000 (+0200) Subject: lib: Add test for backtrace-string X-Git-Tag: 2.3.9~584 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c4282c2597b28be092e2a0609b43d8fa301153ee;p=thirdparty%2Fdovecot%2Fcore.git lib: Add test for backtrace-string --- diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 67edf9aec5..856cc82539 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -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 index 0000000000..dac38aceb4 --- /dev/null +++ b/src/lib/test-backtrace.c @@ -0,0 +1,31 @@ +#include "test-lib.h" +#include "backtrace-string.h" +#include +#include + +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(); +} diff --git a/src/lib/test-lib.inc b/src/lib/test-lib.inc index 94acc428b8..e72357c7ab 100644 --- a/src/lib/test-lib.inc +++ b/src/lib/test-lib.inc @@ -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)