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