test-mempool-alloconly.c revision c8d80ba718487eff6b69b1adcf576b5265d2cf82
/* 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)
return FALSE;
}
return TRUE;
}
void test_mempool_alloconly(void)
{
#define SENTRY_SIZE 32
#define SENTRY_CHAR 0xDE
#define PMALLOC_MAX_COUNT 128
unsigned int i, j, k;
char *sentry;
test_begin("mempool_alloconly");
for (i = 0; i < 64; i++) {
for (j = 1; j <= 128; j++) {
/* make sure p_malloc() doesn't overwrite unallocated
data in data stack. parts of the code relies on
this. */
for (k = 1; k <= PMALLOC_MAX_COUNT; k++) {
}
for (k = 1; k <= PMALLOC_MAX_COUNT; k++)
pool_unref(&pool);
}
}
test_end();
}
{
return FATAL_TEST_FAILURE;
switch(stage) {
case 0: /* forbidden size */
test_begin("fatal_mempool_alloconly");
test_expect_fatal_string("Trying to allocate 0 bytes");
return FATAL_TEST_FAILURE;
case 1: /* logically impossible size */
test_expect_fatal_string("Trying to allocate");
return FATAL_TEST_FAILURE;
case 2: /* physically impossible size */
test_expect_fatal_string("Out of memory");
return FATAL_TEST_FAILURE;
#endif
/* 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;
}