t_mem.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 1999-2001, 2004, 2007, 2009, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: t_mem.c,v 1.15 2009/01/22 23:47:54 tbox Exp $ */
#include <config.h>
/*
* Adapted from the original mempool_test.c program.
*/
#define MP1_FREEMAX 10
#define MP1_FILLCNT 10
#define MP1_MAXALLOC 30
#define MP2_FREEMAX 25
#define MP2_FILLCNT 25
static int
memtest(void) {
int nfails;
void *items1[50];
void *items2[50];
void *tmp;
unsigned int i, j;
int rval;
nfails = 0;
if (isc_result != ISC_R_SUCCESS) {
t_info("isc_mem_create failed %s\n",
++nfails;
return(nfails);
}
if (isc_result != ISC_R_SUCCESS) {
t_info("isc_mempool_create failed %s\n",
++nfails;
return(nfails);
}
if (isc_result != ISC_R_SUCCESS) {
t_info("isc_mempool_create failed %s\n",
++nfails;
return(nfails);
}
if (T_debug)
/*
* Allocate MP1_MAXALLOC items from the pool. This is our max.
*/
for (i = 0; i < MP1_MAXALLOC; i++) {
t_info("isc_mempool_get unexpectedly failed\n");
++nfails;
}
}
/*
* Try to allocate one more. This should fail.
*/
t_info("isc_mempool_get unexpectedly succeeded\n");
++nfails;
}
/*
* Free the first 11 items. Verify that there are 10 free items on
* the free list (which is our max).
*/
for (i = 0; i < 11; i++) {
}
if (rval != 10) {
t_info("isc_mempool_getfreecount returned %d, expected %d\n",
rval, MP1_FREEMAX);
++nfails;
}
if (rval != 19) {
t_info("isc_mempool_getallocated returned %d, expected %d\n",
++nfails;
}
if (T_debug)
/*
* Now, beat up on mp2 for a while. Allocate 50 items, then free
* them, then allocate 50 more, etc.
*/
t_info("exercising the memory pool\n");
for (j = 0; j < 500000; j++) {
for (i = 0; i < 50; i++) {
t_info("items2[%d] is unexpectedly null\n", i);
++nfails;
}
}
for (i = 0; i < 50; i++) {
}
if (j % 50000 == 0)
t_info("...\n");
}
/*
* Free all the other items and blow away this pool.
*/
for (i = 11; i < MP1_MAXALLOC; i++) {
}
if (T_debug)
if (T_debug)
return(0);
}
static const char *a1 =
"the memory module supports the creation of memory contexts "
"and the management of memory pools.";
static void
t1(void) {
int rval;
int result;
if (rval == 0)
else
}
testspec_t T_testlist[] = {
};
#ifdef WIN32
int
}
#endif