mempool_test.c revision dafcb997e390efa4423883dafd100c975c4095d6
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (C) 1999-2001 Internet Software Consortium.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Permission to use, copy, modify, and distribute this software for any
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * purpose with or without fee is hereby granted, provided that the above
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * copyright notice and this permission notice appear in all copies.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * PERFORMANCE OF THIS SOFTWARE.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/* $Id: mempool_test.c,v 1.15 2004/03/05 04:58:39 marka Exp $ */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster unsigned int i, j;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RUNTIME_CHECK(isc_mutex_init(&lock) == ISC_R_SUCCESS);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RUNTIME_CHECK(isc_mempool_create(mctx, 24, &mp1) == ISC_R_SUCCESS);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RUNTIME_CHECK(isc_mempool_create(mctx, 31, &mp2) == ISC_R_SUCCESS);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Allocate 30 items from the pool. This is our max.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for (i = 0; i < 30; i++) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Try to allocate one more. This should fail.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Free the first 11 items. Verify that there are 10 free items on
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the free list (which is our max).
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for (i = 0; i < 11; i++) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RUNTIME_CHECK(isc_mempool_getfreecount(mp1) == 10);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster RUNTIME_CHECK(isc_mempool_getallocated(mp1) == 19);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Now, beat up on mp2 for a while. Allocate 50 items, then free
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * them, then allocate 50 more, etc.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for (j = 0; j < 5000; j++) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for (i = 0; i < 50; i++) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for (i = 0; i < 50; i++) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Free all the other items and blow away this pool.