xref: /titanic_44/usr/src/cmd/sendmail/libsm/t-rpool.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate #include <sm/gen.h>
13*7c478bd9Sstevel@tonic-gate SM_IDSTR(id, "@(#)$Id: t-rpool.c,v 1.16 2001/03/04 18:38:47 ca Exp $")
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #include <sm/debug.h>
16*7c478bd9Sstevel@tonic-gate #include <sm/heap.h>
17*7c478bd9Sstevel@tonic-gate #include <sm/rpool.h>
18*7c478bd9Sstevel@tonic-gate #include <sm/io.h>
19*7c478bd9Sstevel@tonic-gate #include <sm/test.h>
20*7c478bd9Sstevel@tonic-gate 
21*7c478bd9Sstevel@tonic-gate static void
22*7c478bd9Sstevel@tonic-gate rfree __P((
23*7c478bd9Sstevel@tonic-gate 	void *cx));
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate static void
rfree(cx)26*7c478bd9Sstevel@tonic-gate rfree(cx)
27*7c478bd9Sstevel@tonic-gate 	void *cx;
28*7c478bd9Sstevel@tonic-gate {
29*7c478bd9Sstevel@tonic-gate 	(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "rfree freeing `%s'\n",
30*7c478bd9Sstevel@tonic-gate 			     (char *) cx);
31*7c478bd9Sstevel@tonic-gate }
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate int
main(argc,argv)34*7c478bd9Sstevel@tonic-gate main(argc, argv)
35*7c478bd9Sstevel@tonic-gate 	int argc;
36*7c478bd9Sstevel@tonic-gate 	char *argv[];
37*7c478bd9Sstevel@tonic-gate {
38*7c478bd9Sstevel@tonic-gate 	SM_RPOOL_T *rpool;
39*7c478bd9Sstevel@tonic-gate 	char *a[26];
40*7c478bd9Sstevel@tonic-gate 	int i, j;
41*7c478bd9Sstevel@tonic-gate 	SM_RPOOL_ATTACH_T att;
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate 	sm_test_begin(argc, argv, "test rpool");
44*7c478bd9Sstevel@tonic-gate 	sm_debug_addsetting_x("sm_check_heap", 1);
45*7c478bd9Sstevel@tonic-gate 	rpool = sm_rpool_new_x(NULL);
46*7c478bd9Sstevel@tonic-gate 	SM_TEST(rpool != NULL);
47*7c478bd9Sstevel@tonic-gate 	att = sm_rpool_attach_x(rpool, rfree, "attachment #1");
48*7c478bd9Sstevel@tonic-gate 	SM_TEST(att != NULL);
49*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 26; ++i)
50*7c478bd9Sstevel@tonic-gate 	{
51*7c478bd9Sstevel@tonic-gate 		size_t sz = i * i * i;
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate 		a[i] = sm_rpool_malloc_x(rpool, sz);
54*7c478bd9Sstevel@tonic-gate 		for (j = 0; j < sz; ++j)
55*7c478bd9Sstevel@tonic-gate 			a[i][j] = 'a' + i;
56*7c478bd9Sstevel@tonic-gate 	}
57*7c478bd9Sstevel@tonic-gate 	att = sm_rpool_attach_x(rpool, rfree, "attachment #2");
58*7c478bd9Sstevel@tonic-gate 	(void) sm_rpool_attach_x(rpool, rfree, "attachment #3");
59*7c478bd9Sstevel@tonic-gate 	sm_rpool_detach(att);
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 	/* XXX more tests? */
62*7c478bd9Sstevel@tonic-gate #if DEBUG
63*7c478bd9Sstevel@tonic-gate 	sm_dprintf("heap after filling up rpool:\n");
64*7c478bd9Sstevel@tonic-gate 	sm_heap_report(smioout, 3);
65*7c478bd9Sstevel@tonic-gate 	sm_dprintf("freeing rpool:\n");
66*7c478bd9Sstevel@tonic-gate 	sm_rpool_free(rpool);
67*7c478bd9Sstevel@tonic-gate 	sm_dprintf("heap after freeing rpool:\n");
68*7c478bd9Sstevel@tonic-gate 	sm_heap_report(smioout, 3);
69*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
70*7c478bd9Sstevel@tonic-gate 	return sm_test_end();
71*7c478bd9Sstevel@tonic-gate }
72