dovecot-2.2: lib: test-lib - add a real fatal test for mempool-a...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jul 30 12:04:02 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/16761cdb2537
changeset: 17670:16761cdb2537
user: Phil Carmody <phil at dovecot.fi>
date: Wed Jul 30 15:01:29 2014 +0300
description:
lib: test-lib - add a real fatal test for mempool-alloconly
Crazily huge memory allocation must fail.
Signed-off-by: Phil Carmody <phil at dovecot.fi>
diffstat:
src/lib/test-lib.c | 6 +++++-
src/lib/test-lib.h | 1 +
src/lib/test-mempool-alloconly.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 1 deletions(-)
diffs (64 lines):
diff -r aeb6520c0ae9 -r 16761cdb2537 src/lib/test-lib.c
--- a/src/lib/test-lib.c Wed Jul 30 15:01:29 2014 +0300
+++ b/src/lib/test-lib.c Wed Jul 30 15:01:29 2014 +0300
@@ -47,5 +47,9 @@
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);
}
diff -r aeb6520c0ae9 -r 16761cdb2537 src/lib/test-lib.h
--- a/src/lib/test-lib.h Wed Jul 30 15:01:29 2014 +0300
+++ b/src/lib/test-lib.h Wed Jul 30 15:01:29 2014 +0300
@@ -27,6 +27,7 @@
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);
diff -r aeb6520c0ae9 -r 16761cdb2537 src/lib/test-mempool-alloconly.c
--- a/src/lib/test-mempool-alloconly.c Wed Jul 30 15:01:29 2014 +0300
+++ b/src/lib/test-mempool-alloconly.c Wed Jul 30 15:01:29 2014 +0300
@@ -44,3 +44,35 @@
}
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;
+}
More information about the dovecot-cvs
mailing list