xref: /freebsd/contrib/sendmail/libsm/t-rpool.c (revision ee7b0571c2c18bdec848ed2044223cc88db29bd8)
140266059SGregory Neil Shapiro /*
25dd76dd0SGregory Neil Shapiro  * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
340266059SGregory Neil Shapiro  *	All rights reserved.
440266059SGregory Neil Shapiro  *
540266059SGregory Neil Shapiro  * By using this file, you agree to the terms and conditions set
640266059SGregory Neil Shapiro  * forth in the LICENSE file which can be found at the top level of
740266059SGregory Neil Shapiro  * the sendmail distribution.
840266059SGregory Neil Shapiro  */
940266059SGregory Neil Shapiro 
1040266059SGregory Neil Shapiro #include <sm/gen.h>
11*4313cc83SGregory Neil Shapiro SM_IDSTR(id, "@(#)$Id: t-rpool.c,v 1.19 2013-11-22 20:51:43 ca Exp $")
1240266059SGregory Neil Shapiro 
1340266059SGregory Neil Shapiro #include <sm/debug.h>
1440266059SGregory Neil Shapiro #include <sm/heap.h>
1540266059SGregory Neil Shapiro #include <sm/rpool.h>
1640266059SGregory Neil Shapiro #include <sm/io.h>
1740266059SGregory Neil Shapiro #include <sm/test.h>
1840266059SGregory Neil Shapiro 
1940266059SGregory Neil Shapiro static void
2040266059SGregory Neil Shapiro rfree __P((
2140266059SGregory Neil Shapiro 	void *cx));
2240266059SGregory Neil Shapiro 
2340266059SGregory Neil Shapiro static void
rfree(cx)2440266059SGregory Neil Shapiro rfree(cx)
2540266059SGregory Neil Shapiro 	void *cx;
2640266059SGregory Neil Shapiro {
2740266059SGregory Neil Shapiro 	(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "rfree freeing `%s'\n",
2840266059SGregory Neil Shapiro 			     (char *) cx);
2940266059SGregory Neil Shapiro }
3040266059SGregory Neil Shapiro 
3140266059SGregory Neil Shapiro int
main(argc,argv)3240266059SGregory Neil Shapiro main(argc, argv)
3340266059SGregory Neil Shapiro 	int argc;
3440266059SGregory Neil Shapiro 	char *argv[];
3540266059SGregory Neil Shapiro {
3640266059SGregory Neil Shapiro 	SM_RPOOL_T *rpool;
3740266059SGregory Neil Shapiro 	char *a[26];
3840266059SGregory Neil Shapiro 	int i, j;
3940266059SGregory Neil Shapiro 	SM_RPOOL_ATTACH_T att;
4040266059SGregory Neil Shapiro 
4140266059SGregory Neil Shapiro 	sm_test_begin(argc, argv, "test rpool");
4240266059SGregory Neil Shapiro 	sm_debug_addsetting_x("sm_check_heap", 1);
4340266059SGregory Neil Shapiro 	rpool = sm_rpool_new_x(NULL);
4440266059SGregory Neil Shapiro 	SM_TEST(rpool != NULL);
4540266059SGregory Neil Shapiro 	att = sm_rpool_attach_x(rpool, rfree, "attachment #1");
4640266059SGregory Neil Shapiro 	SM_TEST(att != NULL);
4740266059SGregory Neil Shapiro 	for (i = 0; i < 26; ++i)
4840266059SGregory Neil Shapiro 	{
4940266059SGregory Neil Shapiro 		size_t sz = i * i * i;
5040266059SGregory Neil Shapiro 
5140266059SGregory Neil Shapiro 		a[i] = sm_rpool_malloc_x(rpool, sz);
5240266059SGregory Neil Shapiro 		for (j = 0; j < sz; ++j)
5340266059SGregory Neil Shapiro 			a[i][j] = 'a' + i;
5440266059SGregory Neil Shapiro 	}
5540266059SGregory Neil Shapiro 	att = sm_rpool_attach_x(rpool, rfree, "attachment #2");
5640266059SGregory Neil Shapiro 	(void) sm_rpool_attach_x(rpool, rfree, "attachment #3");
5740266059SGregory Neil Shapiro 	sm_rpool_detach(att);
5840266059SGregory Neil Shapiro 
5940266059SGregory Neil Shapiro 	/* XXX more tests? */
6040266059SGregory Neil Shapiro #if DEBUG
6140266059SGregory Neil Shapiro 	sm_dprintf("heap after filling up rpool:\n");
6240266059SGregory Neil Shapiro 	sm_heap_report(smioout, 3);
6340266059SGregory Neil Shapiro 	sm_dprintf("freeing rpool:\n");
6440266059SGregory Neil Shapiro 	sm_rpool_free(rpool);
6540266059SGregory Neil Shapiro 	sm_dprintf("heap after freeing rpool:\n");
6640266059SGregory Neil Shapiro 	sm_heap_report(smioout, 3);
6740266059SGregory Neil Shapiro #endif /* DEBUG */
6840266059SGregory Neil Shapiro 	return sm_test_end();
6940266059SGregory Neil Shapiro }
70