t-rpool.c revision 98121
1243730Srwatson/*
2243730Srwatson * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3243730Srwatson *	All rights reserved.
4243730Srwatson *
5243730Srwatson * By using this file, you agree to the terms and conditions set
6243730Srwatson * forth in the LICENSE file which can be found at the top level of
7243730Srwatson * the sendmail distribution.
8243730Srwatson */
9243730Srwatson
10243730Srwatson#include <sm/gen.h>
11243730SrwatsonSM_IDSTR(id, "@(#)$Id: t-rpool.c,v 1.18 2001/09/11 04:04:49 gshapiro Exp $")
12243730Srwatson
13243730Srwatson#include <sm/debug.h>
14243730Srwatson#include <sm/heap.h>
15243730Srwatson#include <sm/rpool.h>
16243730Srwatson#include <sm/io.h>
17243730Srwatson#include <sm/test.h>
18243730Srwatson
19243730Srwatsonstatic void
20243730Srwatsonrfree __P((
21243730Srwatson	void *cx));
22243730Srwatson
23243730Srwatsonstatic void
24243730Srwatsonrfree(cx)
25243730Srwatson	void *cx;
26243730Srwatson{
27243730Srwatson	(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "rfree freeing `%s'\n",
28243730Srwatson			     (char *) cx);
29243730Srwatson}
30243730Srwatson
31243730Srwatsonint
32243730Srwatsonmain(argc, argv)
33243730Srwatson	int argc;
34243730Srwatson	char *argv[];
35243730Srwatson{
36243730Srwatson	SM_RPOOL_T *rpool;
37243730Srwatson	char *a[26];
38243730Srwatson	int i, j;
39243730Srwatson	SM_RPOOL_ATTACH_T att;
40243730Srwatson
41243730Srwatson	sm_test_begin(argc, argv, "test rpool");
42243730Srwatson	sm_debug_addsetting_x("sm_check_heap", 1);
43243730Srwatson	rpool = sm_rpool_new_x(NULL);
44243730Srwatson	SM_TEST(rpool != NULL);
45243730Srwatson	att = sm_rpool_attach_x(rpool, rfree, "attachment #1");
46243730Srwatson	SM_TEST(att != NULL);
47243730Srwatson	for (i = 0; i < 26; ++i)
48243730Srwatson	{
49243730Srwatson		size_t sz = i * i * i;
50243730Srwatson
51243730Srwatson		a[i] = sm_rpool_malloc_x(rpool, sz);
52243730Srwatson		for (j = 0; j < sz; ++j)
53243730Srwatson			a[i][j] = 'a' + i;
54243730Srwatson	}
55243730Srwatson	att = sm_rpool_attach_x(rpool, rfree, "attachment #2");
56243730Srwatson	(void) sm_rpool_attach_x(rpool, rfree, "attachment #3");
57243730Srwatson	sm_rpool_detach(att);
58243730Srwatson
59243730Srwatson	/* XXX more tests? */
60243730Srwatson#if DEBUG
61243730Srwatson	sm_dprintf("heap after filling up rpool:\n");
62243730Srwatson	sm_heap_report(smioout, 3);
63243730Srwatson	sm_dprintf("freeing rpool:\n");
64243730Srwatson	sm_rpool_free(rpool);
65243730Srwatson	sm_dprintf("heap after freeing rpool:\n");
66243730Srwatson	sm_heap_report(smioout, 3);
67243730Srwatson#endif /* DEBUG */
68243730Srwatson	return sm_test_end();
69243730Srwatson}
70243730Srwatson