]> git.saurik.com Git - redis.git/blob - deps/jemalloc/test/rallocm.c
Better installation info inside README file.
[redis.git] / deps / jemalloc / test / rallocm.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #define JEMALLOC_MANGLE
6 #include "jemalloc_test.h"
7
8 int
9 main(void)
10 {
11 void *p, *q;
12 size_t sz, tsz;
13 int r;
14
15 fprintf(stderr, "Test begin\n");
16
17 r = JEMALLOC_P(allocm)(&p, &sz, 42, 0);
18 if (r != ALLOCM_SUCCESS) {
19 fprintf(stderr, "Unexpected allocm() error\n");
20 abort();
21 }
22
23 q = p;
24 r = JEMALLOC_P(rallocm)(&q, &tsz, sz, 0, ALLOCM_NO_MOVE);
25 if (r != ALLOCM_SUCCESS)
26 fprintf(stderr, "Unexpected rallocm() error\n");
27 if (q != p)
28 fprintf(stderr, "Unexpected object move\n");
29 if (tsz != sz) {
30 fprintf(stderr, "Unexpected size change: %zu --> %zu\n",
31 sz, tsz);
32 }
33
34 q = p;
35 r = JEMALLOC_P(rallocm)(&q, &tsz, sz, 5, ALLOCM_NO_MOVE);
36 if (r != ALLOCM_SUCCESS)
37 fprintf(stderr, "Unexpected rallocm() error\n");
38 if (q != p)
39 fprintf(stderr, "Unexpected object move\n");
40 if (tsz != sz) {
41 fprintf(stderr, "Unexpected size change: %zu --> %zu\n",
42 sz, tsz);
43 }
44
45 q = p;
46 r = JEMALLOC_P(rallocm)(&q, &tsz, sz + 5, 0, ALLOCM_NO_MOVE);
47 if (r != ALLOCM_ERR_NOT_MOVED)
48 fprintf(stderr, "Unexpected rallocm() result\n");
49 if (q != p)
50 fprintf(stderr, "Unexpected object move\n");
51 if (tsz != sz) {
52 fprintf(stderr, "Unexpected size change: %zu --> %zu\n",
53 sz, tsz);
54 }
55
56 q = p;
57 r = JEMALLOC_P(rallocm)(&q, &tsz, sz + 5, 0, 0);
58 if (r != ALLOCM_SUCCESS)
59 fprintf(stderr, "Unexpected rallocm() error\n");
60 if (q == p)
61 fprintf(stderr, "Expected object move\n");
62 if (tsz == sz) {
63 fprintf(stderr, "Expected size change: %zu --> %zu\n",
64 sz, tsz);
65 }
66 p = q;
67 sz = tsz;
68
69 r = JEMALLOC_P(rallocm)(&q, &tsz, 8192, 0, 0);
70 if (r != ALLOCM_SUCCESS)
71 fprintf(stderr, "Unexpected rallocm() error\n");
72 if (q == p)
73 fprintf(stderr, "Expected object move\n");
74 if (tsz == sz) {
75 fprintf(stderr, "Expected size change: %zu --> %zu\n",
76 sz, tsz);
77 }
78 p = q;
79 sz = tsz;
80
81 r = JEMALLOC_P(rallocm)(&q, &tsz, 16384, 0, 0);
82 if (r != ALLOCM_SUCCESS)
83 fprintf(stderr, "Unexpected rallocm() error\n");
84 if (tsz == sz) {
85 fprintf(stderr, "Expected size change: %zu --> %zu\n",
86 sz, tsz);
87 }
88 p = q;
89 sz = tsz;
90
91 r = JEMALLOC_P(rallocm)(&q, &tsz, 8192, 0, ALLOCM_NO_MOVE);
92 if (r != ALLOCM_SUCCESS)
93 fprintf(stderr, "Unexpected rallocm() error\n");
94 if (q != p)
95 fprintf(stderr, "Unexpected object move\n");
96 if (tsz == sz) {
97 fprintf(stderr, "Expected size change: %zu --> %zu\n",
98 sz, tsz);
99 }
100 sz = tsz;
101
102 r = JEMALLOC_P(rallocm)(&q, &tsz, 16384, 0, ALLOCM_NO_MOVE);
103 if (r != ALLOCM_SUCCESS)
104 fprintf(stderr, "Unexpected rallocm() error\n");
105 if (q != p)
106 fprintf(stderr, "Unexpected object move\n");
107 if (tsz == sz) {
108 fprintf(stderr, "Expected size change: %zu --> %zu\n",
109 sz, tsz);
110 }
111 sz = tsz;
112
113 JEMALLOC_P(dallocm)(p, 0);
114
115 fprintf(stderr, "Test end\n");
116 return (0);
117 }