]> git.saurik.com Git - redis.git/blob - deps/jemalloc/test/mremap.c
Better installation info inside README file.
[redis.git] / deps / jemalloc / test / mremap.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
4 #include <errno.h>
5 #include <string.h>
6
7 #define JEMALLOC_MANGLE
8 #include "jemalloc_test.h"
9
10 int
11 main(void)
12 {
13 int ret, err;
14 size_t sz, lg_chunk, chunksize, i;
15 char *p, *q;
16
17 fprintf(stderr, "Test begin\n");
18
19 sz = sizeof(lg_chunk);
20 if ((err = JEMALLOC_P(mallctl)("opt.lg_chunk", &lg_chunk, &sz, NULL,
21 0))) {
22 assert(err != ENOENT);
23 fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
24 strerror(err));
25 ret = 1;
26 goto RETURN;
27 }
28 chunksize = ((size_t)1U) << lg_chunk;
29
30 p = (char *)malloc(chunksize);
31 if (p == NULL) {
32 fprintf(stderr, "malloc(%zu) --> %p\n", chunksize, p);
33 ret = 1;
34 goto RETURN;
35 }
36 memset(p, 'a', chunksize);
37
38 q = (char *)realloc(p, chunksize * 2);
39 if (q == NULL) {
40 fprintf(stderr, "realloc(%p, %zu) --> %p\n", p, chunksize * 2,
41 q);
42 ret = 1;
43 goto RETURN;
44 }
45 for (i = 0; i < chunksize; i++) {
46 assert(q[i] == 'a');
47 }
48
49 p = q;
50
51 q = (char *)realloc(p, chunksize);
52 if (q == NULL) {
53 fprintf(stderr, "realloc(%p, %zu) --> %p\n", p, chunksize, q);
54 ret = 1;
55 goto RETURN;
56 }
57 for (i = 0; i < chunksize; i++) {
58 assert(q[i] == 'a');
59 }
60
61 free(q);
62
63 ret = 0;
64 RETURN:
65 fprintf(stderr, "Test end\n");
66 return (ret);
67 }