]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: test-lib - add a real fatal test for mempool-alloconly
authorPhil Carmody <phil@dovecot.fi>
Wed, 30 Jul 2014 12:01:29 +0000 (15:01 +0300)
committerPhil Carmody <phil@dovecot.fi>
Wed, 30 Jul 2014 12:01:29 +0000 (15:01 +0300)
Crazily huge memory allocation must fail.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib/test-lib.c
src/lib/test-lib.h
src/lib/test-mempool-alloconly.c

index 2a66fb51230178b8d6088ede64f3147886cea691..98e419077d57d9a33c6746affe0203bbbadea2ae 100644 (file)
@@ -47,5 +47,9 @@ int main(void)
                test_var_expand,
                NULL
        };
-       return test_run(test_functions);
+       static enum fatal_test_state (*fatal_functions[])(int) = {
+               fatal_mempool,
+               NULL
+       };
+       return test_run_with_fatals(test_functions, fatal_functions);
 }
index 8a919669db21f6d38fd67b60bc210eb515082cb1..07549078fccb79c8ea9a97555ff6f89c7e94de36 100644 (file)
@@ -27,6 +27,7 @@ void test_istream_tee(void);
 void test_json_parser(void);
 void test_llist(void);
 void test_mempool_alloconly(void);
+enum fatal_test_state fatal_mempool(int);
 void test_network(void);
 void test_numpack(void);
 void test_ostream_file(void);
index 2e4b0710f502611ed1b6873c3993b18f1181a497..f34dcac2368aaec1507cb3c9fa817b76750351dc 100644 (file)
@@ -44,3 +44,35 @@ void test_mempool_alloconly(void)
        }
        test_out("mempool_alloconly", success);
 }
+
+enum fatal_test_state fatal_mempool(int stage)
+{
+       static pool_t pool;
+
+       switch(stage) {
+       case 0: /* forbidden size */
+               test_begin("fatal_mempool");
+               pool = pool_alloconly_create(MEMPOOL_GROWING"fatal", 1);
+               (void)p_malloc(pool, 0);
+               return FATAL_TEST_FAILURE;
+
+       case 1: /* logically impossible size */
+               (void)p_malloc(pool, SSIZE_T_MAX + 1ULL);
+               return FATAL_TEST_FAILURE;
+
+       case 2: /* physically impossible size */
+               (void)p_malloc(pool, SSIZE_T_MAX - (size_t)MEM_ALIGN(1));
+               return FATAL_TEST_FAILURE;
+
+       /* Continue with other tests as follows:
+       case 3:
+               something_fatal();
+               return FATAL_TEST_FAILURE;
+       */
+       }
+
+       /* Either our tests have finished, or the test suite has got confused. */
+       pool_unref(&pool);
+       test_end();
+       return FATAL_TEST_FINISHED;
+}