]>
Commit | Line | Data |
---|---|---|
1 | #define JEMALLOC_MANGLE | |
2 | #include "jemalloc_test.h" | |
3 | ||
4 | int | |
5 | main(void) | |
6 | { | |
7 | size_t pagesize; | |
8 | void *p, *q; | |
9 | size_t sz, tsz; | |
10 | int r; | |
11 | ||
12 | malloc_printf("Test begin\n"); | |
13 | ||
14 | /* Get page size. */ | |
15 | { | |
16 | #ifdef _WIN32 | |
17 | SYSTEM_INFO si; | |
18 | GetSystemInfo(&si); | |
19 | pagesize = (size_t)si.dwPageSize; | |
20 | #else | |
21 | long result = sysconf(_SC_PAGESIZE); | |
22 | assert(result != -1); | |
23 | pagesize = (size_t)result; | |
24 | #endif | |
25 | } | |
26 | ||
27 | r = allocm(&p, &sz, 42, 0); | |
28 | if (r != ALLOCM_SUCCESS) { | |
29 | malloc_printf("Unexpected allocm() error\n"); | |
30 | abort(); | |
31 | } | |
32 | ||
33 | q = p; | |
34 | r = rallocm(&q, &tsz, sz, 0, ALLOCM_NO_MOVE); | |
35 | if (r != ALLOCM_SUCCESS) | |
36 | malloc_printf("Unexpected rallocm() error\n"); | |
37 | if (q != p) | |
38 | malloc_printf("Unexpected object move\n"); | |
39 | if (tsz != sz) { | |
40 | malloc_printf("Unexpected size change: %zu --> %zu\n", | |
41 | sz, tsz); | |
42 | } | |
43 | ||
44 | q = p; | |
45 | r = rallocm(&q, &tsz, sz, 5, ALLOCM_NO_MOVE); | |
46 | if (r != ALLOCM_SUCCESS) | |
47 | malloc_printf("Unexpected rallocm() error\n"); | |
48 | if (q != p) | |
49 | malloc_printf("Unexpected object move\n"); | |
50 | if (tsz != sz) { | |
51 | malloc_printf("Unexpected size change: %zu --> %zu\n", | |
52 | sz, tsz); | |
53 | } | |
54 | ||
55 | q = p; | |
56 | r = rallocm(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE); | |
57 | if (r != ALLOCM_ERR_NOT_MOVED) | |
58 | malloc_printf("Unexpected rallocm() result\n"); | |
59 | if (q != p) | |
60 | malloc_printf("Unexpected object move\n"); | |
61 | if (tsz != sz) { | |
62 | malloc_printf("Unexpected size change: %zu --> %zu\n", | |
63 | sz, tsz); | |
64 | } | |
65 | ||
66 | q = p; | |
67 | r = rallocm(&q, &tsz, sz + 5, 0, 0); | |
68 | if (r != ALLOCM_SUCCESS) | |
69 | malloc_printf("Unexpected rallocm() error\n"); | |
70 | if (q == p) | |
71 | malloc_printf("Expected object move\n"); | |
72 | if (tsz == sz) { | |
73 | malloc_printf("Expected size change: %zu --> %zu\n", | |
74 | sz, tsz); | |
75 | } | |
76 | p = q; | |
77 | sz = tsz; | |
78 | ||
79 | r = rallocm(&q, &tsz, pagesize*2, 0, 0); | |
80 | if (r != ALLOCM_SUCCESS) | |
81 | malloc_printf("Unexpected rallocm() error\n"); | |
82 | if (q == p) | |
83 | malloc_printf("Expected object move\n"); | |
84 | if (tsz == sz) { | |
85 | malloc_printf("Expected size change: %zu --> %zu\n", | |
86 | sz, tsz); | |
87 | } | |
88 | p = q; | |
89 | sz = tsz; | |
90 | ||
91 | r = rallocm(&q, &tsz, pagesize*4, 0, 0); | |
92 | if (r != ALLOCM_SUCCESS) | |
93 | malloc_printf("Unexpected rallocm() error\n"); | |
94 | if (tsz == sz) { | |
95 | malloc_printf("Expected size change: %zu --> %zu\n", | |
96 | sz, tsz); | |
97 | } | |
98 | p = q; | |
99 | sz = tsz; | |
100 | ||
101 | r = rallocm(&q, &tsz, pagesize*2, 0, ALLOCM_NO_MOVE); | |
102 | if (r != ALLOCM_SUCCESS) | |
103 | malloc_printf("Unexpected rallocm() error\n"); | |
104 | if (q != p) | |
105 | malloc_printf("Unexpected object move\n"); | |
106 | if (tsz == sz) { | |
107 | malloc_printf("Expected size change: %zu --> %zu\n", | |
108 | sz, tsz); | |
109 | } | |
110 | sz = tsz; | |
111 | ||
112 | r = rallocm(&q, &tsz, pagesize*4, 0, ALLOCM_NO_MOVE); | |
113 | if (r != ALLOCM_SUCCESS) | |
114 | malloc_printf("Unexpected rallocm() error\n"); | |
115 | if (q != p) | |
116 | malloc_printf("Unexpected object move\n"); | |
117 | if (tsz == sz) { | |
118 | malloc_printf("Expected size change: %zu --> %zu\n", | |
119 | sz, tsz); | |
120 | } | |
121 | sz = tsz; | |
122 | ||
123 | dallocm(p, 0); | |
124 | ||
125 | malloc_printf("Test end\n"); | |
126 | return (0); | |
127 | } |