aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 1 | #include "test/jemalloc_test.h" |
| 2 | |
Mike Hommey | 4a2a3c9 | 2015-08-28 13:45:51 +0900 | [diff] [blame] | 3 | #ifdef JEMALLOC_FILL |
| 4 | const char *malloc_conf = "junk:false"; |
| 5 | #endif |
| 6 | |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 7 | static chunk_hooks_t orig_hooks; |
| 8 | static chunk_hooks_t old_hooks; |
| 9 | |
| 10 | static bool do_dalloc = true; |
| 11 | static bool do_decommit; |
| 12 | |
| 13 | static bool did_alloc; |
| 14 | static bool did_dalloc; |
| 15 | static bool did_commit; |
| 16 | static bool did_decommit; |
| 17 | static bool did_purge; |
| 18 | static bool did_split; |
| 19 | static bool did_merge; |
| 20 | |
| 21 | #if 0 |
| 22 | # define TRACE_HOOK(fmt, ...) malloc_printf(fmt, __VA_ARGS__) |
| 23 | #else |
| 24 | # define TRACE_HOOK(fmt, ...) |
| 25 | #endif |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 26 | |
| 27 | void * |
Daniel Micay | a95018e | 2014-10-04 01:39:32 -0400 | [diff] [blame] | 28 | chunk_alloc(void *new_addr, size_t size, size_t alignment, bool *zero, |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 29 | bool *commit, unsigned arena_ind) |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 30 | { |
| 31 | |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 32 | TRACE_HOOK("%s(new_addr=%p, size=%zu, alignment=%zu, *zero=%s, " |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 33 | "*commit=%s, arena_ind=%u)\n", __func__, new_addr, size, alignment, |
| 34 | *zero ? "true" : "false", *commit ? "true" : "false", arena_ind); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 35 | did_alloc = true; |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 36 | return (old_hooks.alloc(new_addr, size, alignment, zero, commit, |
| 37 | arena_ind)); |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 40 | bool |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 41 | chunk_dalloc(void *chunk, size_t size, bool committed, unsigned arena_ind) |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 42 | { |
| 43 | |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 44 | TRACE_HOOK("%s(chunk=%p, size=%zu, committed=%s, arena_ind=%u)\n", |
| 45 | __func__, chunk, size, committed ? "true" : "false", arena_ind); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 46 | did_dalloc = true; |
| 47 | if (!do_dalloc) |
| 48 | return (true); |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 49 | return (old_hooks.dalloc(chunk, size, committed, arena_ind)); |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | bool |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 53 | chunk_commit(void *chunk, size_t size, size_t offset, size_t length, |
| 54 | unsigned arena_ind) |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 55 | { |
Jason Evans | 03bf5b6 | 2015-08-12 10:26:54 -0700 | [diff] [blame] | 56 | bool err; |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 57 | |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 58 | TRACE_HOOK("%s(chunk=%p, size=%zu, offset=%zu, length=%zu, " |
| 59 | "arena_ind=%u)\n", __func__, chunk, size, offset, length, |
| 60 | arena_ind); |
Jason Evans | 03bf5b6 | 2015-08-12 10:26:54 -0700 | [diff] [blame] | 61 | err = old_hooks.commit(chunk, size, offset, length, arena_ind); |
| 62 | did_commit = !err; |
| 63 | return (err); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | bool |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 67 | chunk_decommit(void *chunk, size_t size, size_t offset, size_t length, |
| 68 | unsigned arena_ind) |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 69 | { |
Jason Evans | 03bf5b6 | 2015-08-12 10:26:54 -0700 | [diff] [blame] | 70 | bool err; |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 71 | |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 72 | TRACE_HOOK("%s(chunk=%p, size=%zu, offset=%zu, length=%zu, " |
| 73 | "arena_ind=%u)\n", __func__, chunk, size, offset, length, |
| 74 | arena_ind); |
Jason Evans | 03bf5b6 | 2015-08-12 10:26:54 -0700 | [diff] [blame] | 75 | if (!do_decommit) |
| 76 | return (true); |
| 77 | err = old_hooks.decommit(chunk, size, offset, length, arena_ind); |
| 78 | did_decommit = !err; |
| 79 | return (err); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | bool |
| 83 | chunk_purge(void *chunk, size_t size, size_t offset, size_t length, |
| 84 | unsigned arena_ind) |
| 85 | { |
| 86 | |
| 87 | TRACE_HOOK("%s(chunk=%p, size=%zu, offset=%zu, length=%zu " |
| 88 | "arena_ind=%u)\n", __func__, chunk, size, offset, length, |
| 89 | arena_ind); |
| 90 | did_purge = true; |
| 91 | return (old_hooks.purge(chunk, size, offset, length, arena_ind)); |
| 92 | } |
| 93 | |
| 94 | bool |
| 95 | chunk_split(void *chunk, size_t size, size_t size_a, size_t size_b, |
| 96 | bool committed, unsigned arena_ind) |
| 97 | { |
| 98 | |
| 99 | TRACE_HOOK("%s(chunk=%p, size=%zu, size_a=%zu, size_b=%zu, " |
| 100 | "committed=%s, arena_ind=%u)\n", __func__, chunk, size, size_a, |
| 101 | size_b, committed ? "true" : "false", arena_ind); |
| 102 | did_split = true; |
| 103 | return (old_hooks.split(chunk, size, size_a, size_b, committed, |
| 104 | arena_ind)); |
| 105 | } |
| 106 | |
| 107 | bool |
| 108 | chunk_merge(void *chunk_a, size_t size_a, void *chunk_b, size_t size_b, |
| 109 | bool committed, unsigned arena_ind) |
| 110 | { |
| 111 | |
| 112 | TRACE_HOOK("%s(chunk_a=%p, size_a=%zu, chunk_b=%p size_b=%zu, " |
| 113 | "committed=%s, arena_ind=%u)\n", __func__, chunk_a, size_a, chunk_b, |
| 114 | size_b, committed ? "true" : "false", arena_ind); |
| 115 | did_merge = true; |
| 116 | return (old_hooks.merge(chunk_a, size_a, chunk_b, size_b, |
| 117 | committed, arena_ind)); |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 118 | } |
| 119 | |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 120 | TEST_BEGIN(test_chunk) |
| 121 | { |
| 122 | void *p; |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 123 | size_t old_size, new_size, large0, large1, huge0, huge1, huge2, sz; |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 124 | unsigned arena_ind; |
| 125 | int flags; |
| 126 | size_t hooks_mib[3], purge_mib[3]; |
| 127 | size_t hooks_miblen, purge_miblen; |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 128 | chunk_hooks_t new_hooks = { |
| 129 | chunk_alloc, |
| 130 | chunk_dalloc, |
| 131 | chunk_commit, |
| 132 | chunk_decommit, |
| 133 | chunk_purge, |
| 134 | chunk_split, |
| 135 | chunk_merge |
| 136 | }; |
Jason Evans | 828d919 | 2015-08-12 15:21:07 -0700 | [diff] [blame] | 137 | bool xallocx_success_a, xallocx_success_b, xallocx_success_c; |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 138 | |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 139 | sz = sizeof(unsigned); |
Jason Evans | 8f61fde | 2016-10-27 21:31:25 -0700 | [diff] [blame] | 140 | assert_d_eq(mallctl("arenas.extend", (void *)&arena_ind, &sz, NULL, 0), |
| 141 | 0, "Unexpected mallctl() failure"); |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 142 | flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE; |
| 143 | |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 144 | /* Install custom chunk hooks. */ |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 145 | hooks_miblen = sizeof(hooks_mib)/sizeof(size_t); |
| 146 | assert_d_eq(mallctlnametomib("arena.0.chunk_hooks", hooks_mib, |
| 147 | &hooks_miblen), 0, "Unexpected mallctlnametomib() failure"); |
| 148 | hooks_mib[1] = (size_t)arena_ind; |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 149 | old_size = sizeof(chunk_hooks_t); |
| 150 | new_size = sizeof(chunk_hooks_t); |
Jason Evans | 8f61fde | 2016-10-27 21:31:25 -0700 | [diff] [blame] | 151 | assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, (void *)&old_hooks, |
| 152 | &old_size, (void *)&new_hooks, new_size), 0, |
| 153 | "Unexpected chunk_hooks error"); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 154 | orig_hooks = old_hooks; |
| 155 | assert_ptr_ne(old_hooks.alloc, chunk_alloc, "Unexpected alloc error"); |
| 156 | assert_ptr_ne(old_hooks.dalloc, chunk_dalloc, |
| 157 | "Unexpected dalloc error"); |
| 158 | assert_ptr_ne(old_hooks.commit, chunk_commit, |
| 159 | "Unexpected commit error"); |
| 160 | assert_ptr_ne(old_hooks.decommit, chunk_decommit, |
| 161 | "Unexpected decommit error"); |
| 162 | assert_ptr_ne(old_hooks.purge, chunk_purge, "Unexpected purge error"); |
| 163 | assert_ptr_ne(old_hooks.split, chunk_split, "Unexpected split error"); |
| 164 | assert_ptr_ne(old_hooks.merge, chunk_merge, "Unexpected merge error"); |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 165 | |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 166 | /* Get large size classes. */ |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 167 | sz = sizeof(size_t); |
Jason Evans | 8f61fde | 2016-10-27 21:31:25 -0700 | [diff] [blame] | 168 | assert_d_eq(mallctl("arenas.lrun.0.size", (void *)&large0, &sz, NULL, |
| 169 | 0), 0, "Unexpected arenas.lrun.0.size failure"); |
| 170 | assert_d_eq(mallctl("arenas.lrun.1.size", (void *)&large1, &sz, NULL, |
| 171 | 0), 0, "Unexpected arenas.lrun.1.size failure"); |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 172 | |
| 173 | /* Get huge size classes. */ |
Jason Evans | 8f61fde | 2016-10-27 21:31:25 -0700 | [diff] [blame] | 174 | assert_d_eq(mallctl("arenas.hchunk.0.size", (void *)&huge0, &sz, NULL, |
| 175 | 0), 0, "Unexpected arenas.hchunk.0.size failure"); |
| 176 | assert_d_eq(mallctl("arenas.hchunk.1.size", (void *)&huge1, &sz, NULL, |
| 177 | 0), 0, "Unexpected arenas.hchunk.1.size failure"); |
| 178 | assert_d_eq(mallctl("arenas.hchunk.2.size", (void *)&huge2, &sz, NULL, |
| 179 | 0), 0, "Unexpected arenas.hchunk.2.size failure"); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 180 | |
| 181 | /* Test dalloc/decommit/purge cascade. */ |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 182 | purge_miblen = sizeof(purge_mib)/sizeof(size_t); |
| 183 | assert_d_eq(mallctlnametomib("arena.0.purge", purge_mib, &purge_miblen), |
| 184 | 0, "Unexpected mallctlnametomib() failure"); |
| 185 | purge_mib[1] = (size_t)arena_ind; |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 186 | do_dalloc = false; |
| 187 | do_decommit = false; |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 188 | p = mallocx(huge0 * 2, flags); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 189 | assert_ptr_not_null(p, "Unexpected mallocx() error"); |
| 190 | did_dalloc = false; |
| 191 | did_decommit = false; |
| 192 | did_purge = false; |
Jason Evans | 828d919 | 2015-08-12 15:21:07 -0700 | [diff] [blame] | 193 | did_split = false; |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 194 | xallocx_success_a = (xallocx(p, huge0, 0, flags) == huge0); |
| 195 | assert_d_eq(mallctlbymib(purge_mib, purge_miblen, NULL, NULL, NULL, 0), |
| 196 | 0, "Unexpected arena.%u.purge error", arena_ind); |
Jason Evans | 828d919 | 2015-08-12 15:21:07 -0700 | [diff] [blame] | 197 | if (xallocx_success_a) { |
| 198 | assert_true(did_dalloc, "Expected dalloc"); |
| 199 | assert_false(did_decommit, "Unexpected decommit"); |
| 200 | assert_true(did_purge, "Expected purge"); |
| 201 | } |
| 202 | assert_true(did_split, "Expected split"); |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 203 | dallocx(p, flags); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 204 | do_dalloc = true; |
| 205 | |
| 206 | /* Test decommit/commit and observe split/merge. */ |
| 207 | do_dalloc = false; |
| 208 | do_decommit = true; |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 209 | p = mallocx(huge0 * 2, flags); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 210 | assert_ptr_not_null(p, "Unexpected mallocx() error"); |
| 211 | did_decommit = false; |
| 212 | did_commit = false; |
| 213 | did_split = false; |
| 214 | did_merge = false; |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 215 | xallocx_success_b = (xallocx(p, huge0, 0, flags) == huge0); |
| 216 | assert_d_eq(mallctlbymib(purge_mib, purge_miblen, NULL, NULL, NULL, 0), |
| 217 | 0, "Unexpected arena.%u.purge error", arena_ind); |
Jason Evans | 828d919 | 2015-08-12 15:21:07 -0700 | [diff] [blame] | 218 | if (xallocx_success_b) |
| 219 | assert_true(did_split, "Expected split"); |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 220 | xallocx_success_c = (xallocx(p, huge0 * 2, 0, flags) == huge0 * 2); |
Jason Evans | 03bf5b6 | 2015-08-12 10:26:54 -0700 | [diff] [blame] | 221 | assert_b_eq(did_decommit, did_commit, "Expected decommit/commit match"); |
Jason Evans | 828d919 | 2015-08-12 15:21:07 -0700 | [diff] [blame] | 222 | if (xallocx_success_b && xallocx_success_c) |
| 223 | assert_true(did_merge, "Expected merge"); |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 224 | dallocx(p, flags); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 225 | do_dalloc = true; |
| 226 | do_decommit = false; |
| 227 | |
| 228 | /* Test purge for partial-chunk huge allocations. */ |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 229 | if (huge0 * 2 > huge2) { |
| 230 | /* |
Jason Evans | d059b9d | 2015-07-24 18:21:42 -0700 | [diff] [blame] | 231 | * There are at least four size classes per doubling, so a |
| 232 | * successful xallocx() from size=huge2 to size=huge1 is |
| 233 | * guaranteed to leave trailing purgeable memory. |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 234 | */ |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 235 | p = mallocx(huge2, flags); |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 236 | assert_ptr_not_null(p, "Unexpected mallocx() error"); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 237 | did_purge = false; |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 238 | assert_zu_eq(xallocx(p, huge1, 0, flags), huge1, |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 239 | "Unexpected xallocx() failure"); |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 240 | assert_true(did_purge, "Expected purge"); |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 241 | dallocx(p, flags); |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 244 | /* Test decommit for large allocations. */ |
| 245 | do_decommit = true; |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 246 | p = mallocx(large1, flags); |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 247 | assert_ptr_not_null(p, "Unexpected mallocx() error"); |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 248 | assert_d_eq(mallctlbymib(purge_mib, purge_miblen, NULL, NULL, NULL, 0), |
| 249 | 0, "Unexpected arena.%u.purge error", arena_ind); |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 250 | did_decommit = false; |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 251 | assert_zu_eq(xallocx(p, large0, 0, flags), large0, |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 252 | "Unexpected xallocx() failure"); |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 253 | assert_d_eq(mallctlbymib(purge_mib, purge_miblen, NULL, NULL, NULL, 0), |
| 254 | 0, "Unexpected arena.%u.purge error", arena_ind); |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 255 | did_commit = false; |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 256 | assert_zu_eq(xallocx(p, large1, 0, flags), large1, |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 257 | "Unexpected xallocx() failure"); |
Jason Evans | 03bf5b6 | 2015-08-12 10:26:54 -0700 | [diff] [blame] | 258 | assert_b_eq(did_decommit, did_commit, "Expected decommit/commit match"); |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 259 | dallocx(p, flags); |
Jason Evans | 8fadb1a | 2015-08-04 10:49:46 -0700 | [diff] [blame] | 260 | do_decommit = false; |
| 261 | |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 262 | /* Make sure non-huge allocation succeeds. */ |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 263 | p = mallocx(42, flags); |
Jason Evans | 8d6a3e8 | 2015-03-18 18:55:33 -0700 | [diff] [blame] | 264 | assert_ptr_not_null(p, "Unexpected mallocx() error"); |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 265 | dallocx(p, flags); |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 266 | |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 267 | /* Restore chunk hooks. */ |
Jason Evans | de35328 | 2016-04-25 20:26:03 -0700 | [diff] [blame] | 268 | assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, NULL, NULL, |
Jason Evans | 8f61fde | 2016-10-27 21:31:25 -0700 | [diff] [blame] | 269 | (void *)&old_hooks, new_size), 0, "Unexpected chunk_hooks error"); |
| 270 | assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, (void *)&old_hooks, |
| 271 | &old_size, NULL, 0), 0, "Unexpected chunk_hooks error"); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 272 | assert_ptr_eq(old_hooks.alloc, orig_hooks.alloc, |
| 273 | "Unexpected alloc error"); |
| 274 | assert_ptr_eq(old_hooks.dalloc, orig_hooks.dalloc, |
| 275 | "Unexpected dalloc error"); |
| 276 | assert_ptr_eq(old_hooks.commit, orig_hooks.commit, |
| 277 | "Unexpected commit error"); |
| 278 | assert_ptr_eq(old_hooks.decommit, orig_hooks.decommit, |
| 279 | "Unexpected decommit error"); |
| 280 | assert_ptr_eq(old_hooks.purge, orig_hooks.purge, |
| 281 | "Unexpected purge error"); |
| 282 | assert_ptr_eq(old_hooks.split, orig_hooks.split, |
| 283 | "Unexpected split error"); |
| 284 | assert_ptr_eq(old_hooks.merge, orig_hooks.merge, |
| 285 | "Unexpected merge error"); |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 286 | } |
| 287 | TEST_END |
| 288 | |
| 289 | int |
| 290 | main(void) |
| 291 | { |
| 292 | |
| 293 | return (test(test_chunk)); |
| 294 | } |