1 #include "test/jemalloc_test.h"
2 
TEST_BEGIN(test_same_size)3 TEST_BEGIN(test_same_size)
4 {
5 	void *p;
6 	size_t sz, tsz;
7 
8 	p = mallocx(42, 0);
9 	assert_ptr_not_null(p, "Unexpected mallocx() error");
10 	sz = sallocx(p, 0);
11 
12 	tsz = xallocx(p, sz, 0, 0);
13 	assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
14 
15 	dallocx(p, 0);
16 }
17 TEST_END
18 
TEST_BEGIN(test_extra_no_move)19 TEST_BEGIN(test_extra_no_move)
20 {
21 	void *p;
22 	size_t sz, tsz;
23 
24 	p = mallocx(42, 0);
25 	assert_ptr_not_null(p, "Unexpected mallocx() error");
26 	sz = sallocx(p, 0);
27 
28 	tsz = xallocx(p, sz, sz-42, 0);
29 	assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
30 
31 	dallocx(p, 0);
32 }
33 TEST_END
34 
TEST_BEGIN(test_no_move_fail)35 TEST_BEGIN(test_no_move_fail)
36 {
37 	void *p;
38 	size_t sz, tsz;
39 
40 	p = mallocx(42, 0);
41 	assert_ptr_not_null(p, "Unexpected mallocx() error");
42 	sz = sallocx(p, 0);
43 
44 	tsz = xallocx(p, sz + 5, 0, 0);
45 	assert_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
46 
47 	dallocx(p, 0);
48 }
49 TEST_END
50 
51 int
main(void)52 main(void)
53 {
54 
55 	return (test(
56 	    test_same_size,
57 	    test_extra_no_move,
58 	    test_no_move_fail));
59 }
60