]> git.saurik.com Git - redis.git/blame - deps/jemalloc/test/mremap.c
Jemalloc updated to 3.0.0.
[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
4934f93d 11 malloc_printf("Test begin\n");
a78e148b 12
13 sz = sizeof(lg_chunk);
4934f93d 14 if ((err = mallctl("opt.lg_chunk", &lg_chunk, &sz, NULL, 0))) {
a78e148b 15 assert(err != ENOENT);
4934f93d 16 malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
a78e148b 17 strerror(err));
18 ret = 1;
4934f93d 19 goto label_return;
a78e148b 20 }
21 chunksize = ((size_t)1U) << lg_chunk;
22
23 p = (char *)malloc(chunksize);
24 if (p == NULL) {
4934f93d 25 malloc_printf("malloc(%zu) --> %p\n", chunksize, p);
a78e148b 26 ret = 1;
4934f93d 27 goto label_return;
a78e148b 28 }
29 memset(p, 'a', chunksize);
30
31 q = (char *)realloc(p, chunksize * 2);
32 if (q == NULL) {
4934f93d 33 malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize * 2,
a78e148b 34 q);
35 ret = 1;
4934f93d 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) {
4934f93d 46 malloc_printf("realloc(%p, %zu) --> %p\n", p, chunksize, q);
a78e148b 47 ret = 1;
4934f93d 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;
4934f93d 57label_return:
58 malloc_printf("Test end\n");
a78e148b 59 return (ret);
60}