190792Sgshapiro/* 2261363Sgshapiro * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers. 390792Sgshapiro * All rights reserved. 490792Sgshapiro * 590792Sgshapiro * By using this file, you agree to the terms and conditions set 690792Sgshapiro * forth in the LICENSE file which can be found at the top level of 790792Sgshapiro * the sendmail distribution. 890792Sgshapiro */ 990792Sgshapiro 1090792Sgshapiro#include <sm/gen.h> 11266692SgshapiroSM_IDSTR(id, "@(#)$Id: t-rpool.c,v 1.19 2013-11-22 20:51:43 ca Exp $") 1290792Sgshapiro 1390792Sgshapiro#include <sm/debug.h> 1490792Sgshapiro#include <sm/heap.h> 1590792Sgshapiro#include <sm/rpool.h> 1690792Sgshapiro#include <sm/io.h> 1790792Sgshapiro#include <sm/test.h> 1890792Sgshapiro 1990792Sgshapirostatic void 2090792Sgshapirorfree __P(( 2190792Sgshapiro void *cx)); 2290792Sgshapiro 2390792Sgshapirostatic void 2490792Sgshapirorfree(cx) 2590792Sgshapiro void *cx; 2690792Sgshapiro{ 2790792Sgshapiro (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "rfree freeing `%s'\n", 2890792Sgshapiro (char *) cx); 2990792Sgshapiro} 3090792Sgshapiro 3190792Sgshapiroint 3290792Sgshapiromain(argc, argv) 3390792Sgshapiro int argc; 3490792Sgshapiro char *argv[]; 3590792Sgshapiro{ 3690792Sgshapiro SM_RPOOL_T *rpool; 3790792Sgshapiro char *a[26]; 3890792Sgshapiro int i, j; 3990792Sgshapiro SM_RPOOL_ATTACH_T att; 4090792Sgshapiro 4190792Sgshapiro sm_test_begin(argc, argv, "test rpool"); 4290792Sgshapiro sm_debug_addsetting_x("sm_check_heap", 1); 4390792Sgshapiro rpool = sm_rpool_new_x(NULL); 4490792Sgshapiro SM_TEST(rpool != NULL); 4590792Sgshapiro att = sm_rpool_attach_x(rpool, rfree, "attachment #1"); 4690792Sgshapiro SM_TEST(att != NULL); 4790792Sgshapiro for (i = 0; i < 26; ++i) 4890792Sgshapiro { 4990792Sgshapiro size_t sz = i * i * i; 5090792Sgshapiro 5190792Sgshapiro a[i] = sm_rpool_malloc_x(rpool, sz); 5290792Sgshapiro for (j = 0; j < sz; ++j) 5390792Sgshapiro a[i][j] = 'a' + i; 5490792Sgshapiro } 5590792Sgshapiro att = sm_rpool_attach_x(rpool, rfree, "attachment #2"); 5690792Sgshapiro (void) sm_rpool_attach_x(rpool, rfree, "attachment #3"); 5790792Sgshapiro sm_rpool_detach(att); 5890792Sgshapiro 5990792Sgshapiro /* XXX more tests? */ 6090792Sgshapiro#if DEBUG 6190792Sgshapiro sm_dprintf("heap after filling up rpool:\n"); 6290792Sgshapiro sm_heap_report(smioout, 3); 6390792Sgshapiro sm_dprintf("freeing rpool:\n"); 6490792Sgshapiro sm_rpool_free(rpool); 6590792Sgshapiro sm_dprintf("heap after freeing rpool:\n"); 6690792Sgshapiro sm_heap_report(smioout, 3); 6790792Sgshapiro#endif /* DEBUG */ 6890792Sgshapiro return sm_test_end(); 6990792Sgshapiro} 70