dovecot-2.2: lib: test-data-stack - add realloc tests
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 28 13:54:29 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/5d290af2d1da
changeset: 17651:5d290af2d1da
user: Phil Carmody <phil at dovecot.fi>
date: Mon Jul 28 16:45:33 2014 +0300
description:
lib: test-data-stack - add realloc tests
These will fail noisily with a DEBUG build until the realloc/DEBUG
bug is fixed.
diffstat:
src/lib/test-data-stack.c | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diffs (51 lines):
diff -r 27ceef4cbd10 -r 5d290af2d1da src/lib/test-data-stack.c
--- a/src/lib/test-data-stack.c Mon Jul 28 16:45:33 2014 +0300
+++ b/src/lib/test-data-stack.c Mon Jul 28 16:45:33 2014 +0300
@@ -63,6 +63,31 @@
test_end();
}
+static void test_ds_realloc()
+{
+ test_begin("data-stack realloc");
+ T_BEGIN {
+ size_t i;
+ unsigned char *p;
+ size_t left = t_get_bytes_available();
+ while (left < 10000) {
+ t_malloc(left); /* force a new block */
+ left = t_get_bytes_available();
+ }
+ left -= 64; /* make room for the sentry if DEBUG */
+ p = t_malloc(1);
+ p[0] = 1;
+ for (i = 2; i <= left; i++) {
+ /* grow it */
+ test_assert_idx(t_try_realloc(p, i), i);
+ p[i-1] = i;
+ test_assert_idx(p[i-2] == (unsigned char)(i-1), i);
+ }
+ test_assert(t_get_bytes_available() < 64 + MEM_ALIGN(1));
+ } T_END;
+ test_end();
+}
+
static void test_ds_recurse(int depth, int number, size_t size)
{
int i;
@@ -86,6 +111,8 @@
memset(ps[i], tag[0], size);
ps[i][size-2] = 0;
}
+ /* Do not expect a high failure rate from t_try_realloc */
+ test_assert_idx(try_fails <= number / 20, depth);
/* Now recurse... */
if(depth>0)
@@ -115,5 +142,6 @@
void test_data_stack(void)
{
test_ds_buffers();
+ test_ds_realloc();
test_ds_recursive(20, 80);
}
More information about the dovecot-cvs
mailing list