From: Josef 'Jeff' Sipek Date: Thu, 28 Jun 2018 17:07:48 +0000 (-0400) Subject: lib: mempool - Reduce test code duplication X-Git-Tag: 2.3.9~1631 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=298d488965758a0b73827c6082c167644672e85c;p=thirdparty%2Fdovecot%2Fcore.git lib: mempool - Reduce test code duplication The 32 and 64 bit versions of the tests were identical. --- diff --git a/src/lib/test-mempool.c b/src/lib/test-mempool.c index e3d2d7fdd9..ca245ab315 100644 --- a/src/lib/test-mempool.c +++ b/src/lib/test-mempool.c @@ -23,25 +23,7 @@ extern struct pool test_pool; static void test_mempool_overflow(void) { test_begin("mempool overflow"); -#if SIZEOF_VOID_P == 8 - const size_t max_num_u32 = BIG_MAX / sizeof(uint32_t); - uint32max_array_t *m1 = p_new(&test_pool, uint32max_array_t, LITTLE_MAX + 2); - test_assert(m1 == POINTER_CAST(BIG_MAX)); - char *m2 = p_new(&test_pool, char, BIG_MAX); - test_assert(m2 == POINTER_CAST(BIG_MAX)); - uint32_t *m3 = p_new(&test_pool, uint32_t, max_num_u32); - test_assert(m3 == POINTER_CAST(BIG_MAX - 3)); - - /* grow */ - test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, LITTLE_MAX + 1, LITTLE_MAX + 2) == POINTER_CAST(BIG_MAX)); - test_assert(p_realloc_type(&test_pool, m2, char, BIG_MAX - 1, BIG_MAX) == POINTER_CAST(BIG_MAX)); - test_assert(p_realloc_type(&test_pool, m3, uint32_t, max_num_u32 - 1, max_num_u32) == POINTER_CAST(BIG_MAX - 3)); - /* shrink */ - test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, LITTLE_MAX + 2, LITTLE_MAX + 1) == POINTER_CAST(BIG_MAX - LITTLE_MAX)); - test_assert(p_realloc_type(&test_pool, m2, char, BIG_MAX, BIG_MAX - 1) == POINTER_CAST(BIG_MAX - 1)); - test_assert(p_realloc_type(&test_pool, m3, uint32_t, max_num_u32, max_num_u32 - 1) == POINTER_CAST(BIG_MAX - 2 * sizeof(uint32_t) + 1)); -#elif SIZEOF_VOID_P == 4 const size_t max_num_u32 = BIG_MAX / sizeof(uint32_t); uint32max_array_t *m1 = p_new(&test_pool, uint32max_array_t, LITTLE_MAX + 2); test_assert(m1 == POINTER_CAST(BIG_MAX)); @@ -59,9 +41,7 @@ static void test_mempool_overflow(void) test_assert(p_realloc_type(&test_pool, m1, uint32max_array_t, LITTLE_MAX + 2, LITTLE_MAX + 1) == POINTER_CAST(BIG_MAX - LITTLE_MAX)); test_assert(p_realloc_type(&test_pool, m2, char, BIG_MAX, BIG_MAX - 1) == POINTER_CAST(BIG_MAX - 1)); test_assert(p_realloc_type(&test_pool, m3, uint32_t, max_num_u32, max_num_u32 - 1) == POINTER_CAST(BIG_MAX - 2 * sizeof(uint32_t) + 1)); -#else -# error unsupported pointer size -#endif + test_end(); } @@ -71,35 +51,6 @@ enum fatal_test_state fatal_mempool(unsigned int stage) static uint32_t *m2; test_expect_fatal_string("memory allocation overflow"); -#if SIZEOF_VOID_P == 8 - switch(stage) { - case 0: - test_begin("fatal mempool overflow"); - m1 = p_new(&test_pool, uint32max_array_t, LITTLE_MAX + 3); - return FATAL_TEST_FAILURE; - case 1: - m2 = p_new(&test_pool, uint32_t, BIG_MAX / sizeof(uint32_t) + 1); - return FATAL_TEST_FAILURE; - case 2: /* grow */ - m1 = p_realloc_type(&test_pool, m1, uint32max_array_t, - LITTLE_MAX + 2, LITTLE_MAX + 3); - return FATAL_TEST_FAILURE; - case 3: - m2 = p_realloc_type(&test_pool, m2, uint32_t, - BIG_MAX / sizeof(uint32_t), - BIG_MAX / sizeof(uint32_t) + 1); - return FATAL_TEST_FAILURE; - case 4: /* shrink */ - m1 = p_realloc_type(&test_pool, m1, uint32max_array_t, - LITTLE_MAX + 3, LITTLE_MAX + 2); - return FATAL_TEST_FAILURE; - case 5: - m2 = p_realloc_type(&test_pool, m2, uint32_t, - BIG_MAX / sizeof(uint32_t) + 1, - BIG_MAX / sizeof(uint32_t)); - return FATAL_TEST_FAILURE; - } -#elif SIZEOF_VOID_P == 4 switch(stage) { case 0: test_begin("fatal mempool overflow"); @@ -127,9 +78,6 @@ enum fatal_test_state fatal_mempool(unsigned int stage) BIG_MAX / sizeof(uint32_t)); return FATAL_TEST_FAILURE; } -#else -# error unsupported pointer size -#endif test_expect_fatal_string(NULL); test_end(); return FATAL_TEST_FINISHED;