]> git.saurik.com Git - redis.git/blame - deps/jemalloc/test/mremap.c
redis-check-dump now understands dumps produced by Redis 2.6
[redis.git] / deps / jemalloc / test / mremap.c
CommitLineData
a78e148b 1#define JEMALLOC_MANGLE
2#include "jemalloc_test.h"
3
4int
5main(void)
6{
7 int ret, err;
8 size_t sz, lg_chunk, chunksize, i;
9 char *p, *q;
10
ad4c0b41 11 malloc_printf("Test begin\n");
a78e148b 12
13 sz = sizeof(lg_chunk);
ad4c0b41 14 if ((err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0))) {
a78e148b 15 assert(err != ENOENT);
ad4c0b41 16 malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
a78e148b 17 strerror(err));
18 ret = 1;
ad4c0b41 19 goto label_return;
a78e148b 20 }
21 chunksize = ((size_t)1U) << lg_chunk;
22
23 p = (char *)malloc(chunksize);
24 if (p == NULL) {
ad4c0b41 25 malloc_printf("malloc(%zu) --> %p\n", chunksize, p);
a78e148b 26 ret = 1;
ad4c0b41 27 goto label_return;
a78e148b 28 }
29 memset(p, 'a', chunksize);
30
31 q = (char *)realloc(p, chunksize * 2);
32 if (q == NULL) {
ad4c0b41 33 malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize * 2,
a78e148b 34 q);
35 ret = 1;
ad4c0b41 36 goto label_return;
a78e148b 37 }
38 for (i = 0; i < chunksize; i++) {
39 assert(q[i] == 'a');
40 }
41
42 p = q;
43
44 q = (char *)realloc(p, chunksize);
45 if (q == NULL) {
ad4c0b41 46 malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize, q);
a78e148b 47 ret = 1;
ad4c0b41 48 goto label_return;
a78e148b 49 }
50 for (i = 0; i < chunksize; i++) {
51 assert(q[i] == 'a');
52 }
53
54 free(q);
55
56 ret = 0;
ad4c0b41 57label_return:
58 malloc_printf("Test end\n");
a78e148b 59 return (ret);
60}