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