From: Trond Norbye Date: Thu, 3 Dec 2009 15:22:16 +0000 (+0100) Subject: Fix the test_xxx macros, and generate coredump if the test fails X-Git-Tag: 0.37~82^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=c3c83ce7fbd1ff2b50a64fef95dd3449fc31e116;p=m6w6%2Flibmemcached Fix the test_xxx macros, and generate coredump if the test fails --- diff --git a/tests/test.c b/tests/test.c index 920ffe5f..aa850116 100644 --- a/tests/test.c +++ b/tests/test.c @@ -44,6 +44,14 @@ static const char *test_strerror(test_return_t code) } +void create_core(void) +{ + if (getenv("LIBMEMCACHED_NO_COREDUMP") == NULL && fork() == 0) + abort(); + + abort(); +} + int main(int argc, char *argv[]) { test_return_t failed; diff --git a/tests/test.h b/tests/test.h index e786e9ea..18da50f2 100644 --- a/tests/test.h +++ b/tests/test.h @@ -42,9 +42,38 @@ struct world_st { /* How we make all of this work :) */ void get_world(world_st *world); -#define test_truth(A) if (! (A)) {fprintf(stderr, "%d", __LINE__); return TEST_FAILURE;} -#define test_false(A) if ((A)) {fprintf(stderr, "%d", __LINE__); return TEST_FAILURE;} -#define test_strcmp(A,B) if (strcmp((A), (B))) {fprintf(stderr, "%d", __LINE__); return TEST_FAILURE;} +void create_core(void); + +#define test_truth(A) \ +do \ +{ \ + if (! (A)) { \ + fprintf(stderr, "Assertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + +#define test_false(A) \ +do \ +{ \ + if ((A)) { \ + fprintf(stderr, "Assertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + +#define test_strcmp(A,B) \ +do \ +{ \ + if (strcmp((A), (B))) \ + { \ + fprintf(stderr, "%d", __LINE__); \ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) #ifdef __cplusplus }