• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "test/jemalloc_test.h"
2 
3 #define MAXALIGN (((size_t)1) << 22)
4 #define NITER 3
5 
TEST_BEGIN(test_basic)6 TEST_BEGIN(test_basic) {
7 	void *ptr = mallocx(64, 0);
8 	sdallocx(ptr, 64, 0);
9 }
10 TEST_END
11 
TEST_BEGIN(test_alignment_and_size)12 TEST_BEGIN(test_alignment_and_size) {
13 	size_t nsz, sz, alignment, total;
14 	unsigned i;
15 	void *ps[NITER];
16 
17 	for (i = 0; i < NITER; i++) {
18 		ps[i] = NULL;
19 	}
20 
21 	for (alignment = 8;
22 	    alignment <= MAXALIGN;
23 	    alignment <<= 1) {
24 		total = 0;
25 		for (sz = 1;
26 		    sz < 3 * alignment && sz < (1U << 31);
27 		    sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
28 			for (i = 0; i < NITER; i++) {
29 				nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
30 				    MALLOCX_ZERO);
31 				ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
32 				    MALLOCX_ZERO);
33 				total += nsz;
34 				if (total >= (MAXALIGN << 1)) {
35 					break;
36 				}
37 			}
38 			for (i = 0; i < NITER; i++) {
39 				if (ps[i] != NULL) {
40 					sdallocx(ps[i], sz,
41 					    MALLOCX_ALIGN(alignment));
42 					ps[i] = NULL;
43 				}
44 			}
45 		}
46 	}
47 }
48 TEST_END
49 
50 int
main(void)51 main(void) {
52 	return test_no_reentrancy(
53 	    test_basic,
54 	    test_alignment_and_size);
55 }
56