t-rpool.c revision 266692
141227Sjdp/*
241227Sjdp * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
341227Sjdp *	All rights reserved.
441227Sjdp *
541227Sjdp * By using this file, you agree to the terms and conditions set
641227Sjdp * forth in the LICENSE file which can be found at the top level of
741227Sjdp * the sendmail distribution.
841227Sjdp */
941227Sjdp
1041227Sjdp#include <sm/gen.h>
1141227SjdpSM_IDSTR(id, "@(#)$Id: t-rpool.c,v 1.19 2013-11-22 20:51:43 ca Exp $")
1241227Sjdp
1341227Sjdp#include <sm/debug.h>
1441227Sjdp#include <sm/heap.h>
1541227Sjdp#include <sm/rpool.h>
1641227Sjdp#include <sm/io.h>
1741227Sjdp#include <sm/test.h>
1841227Sjdp
1941227Sjdpstatic void
2041227Sjdprfree __P((
2141227Sjdp	void *cx));
2241227Sjdp
2341227Sjdpstatic void
2441227Sjdprfree(cx)
2594372Sru	void *cx;
2641227Sjdp{
27112044Sobrien	(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "rfree freeing `%s'\n",
28112044Sobrien			     (char *) cx);
29112044Sobrien}
3041227Sjdp
31112044Sobrienint
32112044Sobrienmain(argc, argv)
3350017Sabial	int argc;
3442917Sjdp	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