t-rpool.c revision 90792
1171169Smlaier/* 2171169Smlaier * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. 3171169Smlaier * All rights reserved. 4171169Smlaier * 5171169Smlaier * By using this file, you agree to the terms and conditions set 6171169Smlaier * forth in the LICENSE file which can be found at the top level of 7171169Smlaier * the sendmail distribution. 8171169Smlaier */ 9171169Smlaier 10171169Smlaier#include <sm/gen.h> 11171169SmlaierSM_IDSTR(id, "@(#)$Id: t-rpool.c,v 1.18 2001/09/11 04:04:49 gshapiro Exp $") 12171169Smlaier 13171169Smlaier#include <sm/debug.h> 14171169Smlaier#include <sm/heap.h> 15171169Smlaier#include <sm/rpool.h> 16171169Smlaier#include <sm/io.h> 17171169Smlaier#include <sm/test.h> 18171169Smlaier 19171169Smlaierstatic void 20171169Smlaierrfree __P(( 21171169Smlaier void *cx)); 22171169Smlaier 23171169Smlaierstatic void 24171169Smlaierrfree(cx) 25171169Smlaier void *cx; 26171169Smlaier{ 27171169Smlaier (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "rfree freeing `%s'\n", 28171169Smlaier (char *) cx); 29171169Smlaier} 30171169Smlaier 31171169Smlaierint 32171169Smlaiermain(argc, argv) 33171169Smlaier int argc; 34171169Smlaier char *argv[]; 35171169Smlaier{ 36171169Smlaier SM_RPOOL_T *rpool; 37171169Smlaier char *a[26]; 38171169Smlaier int i, j; 39171169Smlaier SM_RPOOL_ATTACH_T att; 40171169Smlaier 41171169Smlaier sm_test_begin(argc, argv, "test rpool"); 42171169Smlaier sm_debug_addsetting_x("sm_check_heap", 1); 43171169Smlaier rpool = sm_rpool_new_x(NULL); 44171169Smlaier SM_TEST(rpool != NULL); 45171169Smlaier att = sm_rpool_attach_x(rpool, rfree, "attachment #1"); 46171169Smlaier SM_TEST(att != NULL); 47171169Smlaier for (i = 0; i < 26; ++i) 48171169Smlaier { 49171169Smlaier size_t sz = i * i * i; 50171169Smlaier 51171169Smlaier a[i] = sm_rpool_malloc_x(rpool, sz); 52171169Smlaier for (j = 0; j < sz; ++j) 53171169Smlaier a[i][j] = 'a' + i; 54171169Smlaier } 55171169Smlaier att = sm_rpool_attach_x(rpool, rfree, "attachment #2"); 56171169Smlaier (void) sm_rpool_attach_x(rpool, rfree, "attachment #3"); 57171169Smlaier sm_rpool_detach(att); 58171169Smlaier 59171169Smlaier /* XXX more tests? */ 60171169Smlaier#if DEBUG 61171169Smlaier sm_dprintf("heap after filling up rpool:\n"); 62171169Smlaier sm_heap_report(smioout, 3); 63171169Smlaier sm_dprintf("freeing rpool:\n"); 64171169Smlaier sm_rpool_free(rpool); 65171169Smlaier sm_dprintf("heap after freeing rpool:\n"); 66171169Smlaier sm_heap_report(smioout, 3); 67171169Smlaier#endif /* DEBUG */ 68171169Smlaier return sm_test_end(); 69171169Smlaier} 70171169Smlaier