]> git.saurik.com Git - redis.git/blame_incremental - deps/jemalloc/test/allocated.c
redis-check-dump now understands dumps produced by Redis 2.6
[redis.git] / deps / jemalloc / test / allocated.c
... / ...
CommitLineData
1#define JEMALLOC_MANGLE
2#include "jemalloc_test.h"
3
4void *
5je_thread_start(void *arg)
6{
7 int err;
8 void *p;
9 uint64_t a0, a1, d0, d1;
10 uint64_t *ap0, *ap1, *dp0, *dp1;
11 size_t sz, usize;
12
13 sz = sizeof(a0);
14 if ((err = mallctl("thread.allocated", &a0, &sz, NULL, 0))) {
15 if (err == ENOENT) {
16#ifdef JEMALLOC_STATS
17 assert(false);
18#endif
19 goto label_return;
20 }
21 malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
22 strerror(err));
23 exit(1);
24 }
25 sz = sizeof(ap0);
26 if ((err = mallctl("thread.allocatedp", &ap0, &sz, NULL, 0))) {
27 if (err == ENOENT) {
28#ifdef JEMALLOC_STATS
29 assert(false);
30#endif
31 goto label_return;
32 }
33 malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
34 strerror(err));
35 exit(1);
36 }
37 assert(*ap0 == a0);
38
39 sz = sizeof(d0);
40 if ((err = mallctl("thread.deallocated", &d0, &sz, NULL, 0))) {
41 if (err == ENOENT) {
42#ifdef JEMALLOC_STATS
43 assert(false);
44#endif
45 goto label_return;
46 }
47 malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
48 strerror(err));
49 exit(1);
50 }
51 sz = sizeof(dp0);
52 if ((err = mallctl("thread.deallocatedp", &dp0, &sz, NULL, 0))) {
53 if (err == ENOENT) {
54#ifdef JEMALLOC_STATS
55 assert(false);
56#endif
57 goto label_return;
58 }
59 malloc_printf("%s(): Error in mallctl(): %s\n", __func__,
60 strerror(err));
61 exit(1);
62 }
63 assert(*dp0 == d0);
64
65 p = malloc(1);
66 if (p == NULL) {
67 malloc_printf("%s(): Error in malloc()\n", __func__);
68 exit(1);
69 }
70
71 sz = sizeof(a1);
72 mallctl("thread.allocated", &a1, &sz, NULL, 0);
73 sz = sizeof(ap1);
74 mallctl("thread.allocatedp", &ap1, &sz, NULL, 0);
75 assert(*ap1 == a1);
76 assert(ap0 == ap1);
77
78 usize = malloc_usable_size(p);
79 assert(a0 + usize <= a1);
80
81 free(p);
82
83 sz = sizeof(d1);
84 mallctl("thread.deallocated", &d1, &sz, NULL, 0);
85 sz = sizeof(dp1);
86 mallctl("thread.deallocatedp", &dp1, &sz, NULL, 0);
87 assert(*dp1 == d1);
88 assert(dp0 == dp1);
89
90 assert(d0 + usize <= d1);
91
92label_return:
93 return (NULL);
94}
95
96int
97main(void)
98{
99 int ret = 0;
100 je_thread_t thread;
101
102 malloc_printf("Test begin\n");
103
104 je_thread_start(NULL);
105
106 je_thread_create(&thread, je_thread_start, NULL);
107 je_thread_join(thread, (void *)&ret);
108
109 je_thread_start(NULL);
110
111 je_thread_create(&thread, je_thread_start, NULL);
112 je_thread_join(thread, (void *)&ret);
113
114 je_thread_start(NULL);
115
116 malloc_printf("Test end\n");
117 return (ret);
118}