1 /* 2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * 5 * By using this file, you agree to the terms and conditions set 6 * forth in the LICENSE file which can be found at the top level of 7 * the sendmail distribution. 8 */ 9 10 #include <sm/gen.h> 11 SM_IDSTR(id, "@(#)$Id: t-rpool.c,v 1.16 2001/03/04 18:38:47 ca Exp $") 12 13 #include <sm/debug.h> 14 #include <sm/heap.h> 15 #include <sm/rpool.h> 16 #include <sm/io.h> 17 #include <sm/test.h> 18 19 static void 20 rfree __P(( 21 void *cx)); 22 23 static void 24 rfree(cx) 25 void *cx; 26 { 27 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "rfree freeing `%s'\n", 28 (char *) cx); 29 } 30 31 int 32 main(argc, argv) 33 int argc; 34 char *argv[]; 35 { 36 SM_RPOOL_T *rpool; 37 char *a[26]; 38 int i, j; 39 SM_RPOOL_ATTACH_T att; 40 41 sm_test_begin(argc, argv, "test rpool"); 42 sm_debug_addsetting_x("sm_check_heap", 1); 43 rpool = sm_rpool_new_x(NULL); 44 SM_TEST(rpool != NULL); 45 att = sm_rpool_attach_x(rpool, rfree, "attachment #1"); 46 SM_TEST(att != NULL); 47 for (i = 0; i < 26; ++i) 48 { 49 size_t sz = i * i * i; 50 51 a[i] = sm_rpool_malloc_x(rpool, sz); 52 for (j = 0; j < sz; ++j) 53 a[i][j] = 'a' + i; 54 } 55 att = sm_rpool_attach_x(rpool, rfree, "attachment #2"); 56 (void) sm_rpool_attach_x(rpool, rfree, "attachment #3"); 57 sm_rpool_detach(att); 58 59 /* XXX more tests? */ 60 #if DEBUG 61 sm_dprintf("heap after filling up rpool:\n"); 62 sm_heap_report(smioout, 3); 63 sm_dprintf("freeing rpool:\n"); 64 sm_rpool_free(rpool); 65 sm_dprintf("heap after freeing rpool:\n"); 66 sm_heap_report(smioout, 3); 67 #endif /* DEBUG */ 68 return sm_test_end(); 69 } 70