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