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