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