From: Timo Sirainen Date: Mon, 12 Dec 2016 13:21:13 +0000 (+0200) Subject: lib-test: Change test_fatal_func_t to take unsigned int stage as parameter. X-Git-Tag: 2.3.0.rc1~2434 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=957d34edbe3599fbb4e7c0bcf3785bd7fd4862c4;p=thirdparty%2Fdovecot%2Fcore.git lib-test: Change test_fatal_func_t to take unsigned int stage as parameter. It could never be -1, so this makes it clearer. It also removes annoying casts when comparing stage to e.g. N_ELEMENTS(). --- diff --git a/src/lib-test/test-common.c b/src/lib-test/test-common.c index 1c677a7356..51acaa7555 100644 --- a/src/lib-test/test-common.c +++ b/src/lib-test/test-common.c @@ -250,7 +250,7 @@ static void test_run_named_funcs(struct named_test tests[], const char *match) static void run_one_fatal(test_fatal_func_t *fatal_function) { - static int index = 0; + static unsigned int index = 0; for (;;) { volatile int jumped = setjmp(fatal_jmpbuf); if (jumped == 0) { diff --git a/src/lib-test/test-common.h b/src/lib-test/test-common.h index 057f7e287a..5746707d91 100644 --- a/src/lib-test/test-common.h +++ b/src/lib-test/test-common.h @@ -72,7 +72,7 @@ enum fatal_test_state { is increased by 1. The idea is that each stage would be running an individual test that is supposed to crash. The function is called until FATAL_TEST_FINISHED or FATAL_TEST_ABORT is returned. */ -typedef enum fatal_test_state test_fatal_func_t(int stage); +typedef enum fatal_test_state test_fatal_func_t(unsigned int stage); struct named_fatal { const char *name; @@ -83,7 +83,7 @@ int test_run_with_fatals(void (*test_functions[])(void), int test_run_named_with_fatals(const char *match, struct named_test tests[], struct named_fatal fatals[]); -#define FATAL_DECL(x) enum fatal_test_state x(int); +#define FATAL_DECL(x) enum fatal_test_state x(unsigned int); #define FATAL_NAMELESS(x) x, /* Were you to want to use the X trick but not name the tests */ #define FATAL_NAMED(x) { .name = #x , .func = x }, diff --git a/src/lib/test-array.c b/src/lib/test-array.c index 05751c30c7..d399c42ae0 100644 --- a/src/lib/test-array.c +++ b/src/lib/test-array.c @@ -292,7 +292,7 @@ void test_array(void) test_array_swap(); } -enum fatal_test_state fatal_array(int stage) +enum fatal_test_state fatal_array(unsigned int stage) { double tmpd[2] = { 42., -42. }; short tmps[8] = {1,2,3,4,5,6,7,8}; @@ -330,7 +330,7 @@ enum fatal_test_state fatal_array(int stage) test_end(); /* Forces the compiler to check the value of useless_ptr, so that it must call array_idx (which is marked as pure, and gcc was desperate - to optimise out. Of course, gcc is unaware stage is never -1.*/ - return (useless_ptr != NULL && stage == -1) + to optimise out. Of course, gcc is unaware stage is never UINT_MAX.*/ + return (useless_ptr != NULL && stage == UINT_MAX) ? FATAL_TEST_FAILURE : FATAL_TEST_FINISHED; } diff --git a/src/lib/test-data-stack.c b/src/lib/test-data-stack.c index 4f063ce351..94996b5ff6 100644 --- a/src/lib/test-data-stack.c +++ b/src/lib/test-data-stack.c @@ -145,7 +145,7 @@ void test_data_stack(void) test_ds_recursive(20, 80); } -enum fatal_test_state fatal_data_stack(int stage) +enum fatal_test_state fatal_data_stack(unsigned int stage) { #ifdef DEBUG #define NONEXISTENT_STACK_FRAME_ID (data_stack_frame_t)999999999 diff --git a/src/lib/test-mempool-alloconly.c b/src/lib/test-mempool-alloconly.c index 5658e202b5..3fa122e9a5 100644 --- a/src/lib/test-mempool-alloconly.c +++ b/src/lib/test-mempool-alloconly.c @@ -53,7 +53,7 @@ void test_mempool_alloconly(void) test_end(); } -enum fatal_test_state fatal_mempool(int stage) +enum fatal_test_state fatal_mempool(unsigned int stage) { static pool_t pool; diff --git a/src/lib/test-printf-format-fix.c b/src/lib/test-printf-format-fix.c index 2dc685d1b9..26fb5b7eb2 100644 --- a/src/lib/test-printf-format-fix.c +++ b/src/lib/test-printf-format-fix.c @@ -95,7 +95,7 @@ void test_printf_format_fix() } /* Want to test the panics too? go for it! */ -enum fatal_test_state fatal_printf_format_fix(int stage) +enum fatal_test_state fatal_printf_format_fix(unsigned int stage) { static const char *fatals[] = { "no no no %n's", @@ -104,7 +104,7 @@ enum fatal_test_state fatal_printf_format_fix(int stage) "definitely can't have a tailing %", }; - if((unsigned int)stage >= N_ELEMENTS(fatals)) { + if(stage >= N_ELEMENTS(fatals)) { test_end(); return FATAL_TEST_FINISHED; }