test-mempool-allocfree.c revision a7d1bd5be687bbb125ccfb5c685491414280ddac
/* Copyright (c) 2007-2017 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
{
unsigned int i;
for (i = 0; i < size; i++) {
if (bytes[i] != b) {
i_debug("bytes[%u] != %u", i, b);
return FALSE;
}
}
return TRUE;
}
void test_mempool_allocfree(void)
{
unsigned int i;
size_t last_alloc = 0;
test_begin("mempool_allocfree");
for(i = 0; i <= 1000; i++) {
/* release previous allocation */
if ((i % 3) == 0) {
used -= last_alloc;
count--;
}
last_alloc = 0;
/* grow previous allocation */
} else if ((i % 5) == 0) {
used -= last_alloc;
else
count++;
if (last_alloc > 0)
last_alloc = i*2;
used += i*2;
/* shrink previous allocation */
} else if ((i % 7) == 0) {
used -= last_alloc;
else
count++;
if (last_alloc > 0)
last_alloc = i-2;
used += i-2;
/* allocate some memory */
} else {
/* fill it with sense marker */
used += i;
count++;
last_alloc = i;
}
}
pool_unref(&pool);
/* make sure realloc works correctly */
for(i = 1; i < 1000; i++) {
}
pool_unref(&pool);
test_end();
}
{
return FATAL_TEST_FAILURE;
switch(stage) {
case 0: /* forbidden size */
test_begin("fatal_mempool_allocfree");
return FATAL_TEST_FAILURE;
case 1: /* logically impossible size */
return FATAL_TEST_FAILURE;
case 2: /* physically impossible size */
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;
}