test/mpool_tests.c

Thu, 31 May 2012 09:18:26 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 31 May 2012 09:18:26 +0200
changeset 32
c7af4ec56e19
parent 30
23bb65cbf7a4
child 33
9c219a62070d
permissions
-rw-r--r--

consequently used intptr_t in mpool tests

13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 *
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 */
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
5 #include <inttypes.h>
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
6
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 #include "mpool_tests.h"
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
9 UCX_TEST_BEGIN(test_ucx_mempool_new) {
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
10 UcxMempool *pool = ucx_mempool_new(16);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
11
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
12 UCX_TEST_ASSERT(pool->size == 16, "wrong size")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
13 UCX_TEST_ASSERT(pool->ndata == 0, "uninitialized counter")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
14 UCX_TEST_ASSERT(pool->data != NULL, "no memory addressed")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
15
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
16 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
17
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
18 UCX_TEST_END
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
19 }
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
21 UCX_TEST_BEGIN(test_ucx_mempool_malloc) {
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
22
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
23 UcxMempool *pool = ucx_mempool_new(1);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
24
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
25 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
26
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
27 UCX_TEST_ASSERT(pool->ndata == 1, "counter not incremented")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
28 UCX_TEST_ASSERT(pool->size == 1, "chcap called")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
29
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
30 intptr_t *pooladdr =
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
31 (intptr_t*)((char*)pool->data[0] + sizeof(ucx_destructor));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
32 *pooladdr = 5;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
33
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
34 UCX_TEST_ASSERT(*test == 5, "wrong pointer")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
35
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
36 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
37
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
38 UCX_TEST_END
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 }
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
41 UCX_TEST_BEGIN(test_ucx_mempool_malloc_with_chcap) {
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
42
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
43 UcxMempool *pool = ucx_mempool_new(1);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
44
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
45 ucx_mempool_malloc(pool, sizeof(int));
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
46 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
47
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
48 UCX_TEST_ASSERT(pool->ndata == 2, "counter not incremented")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
49 UCX_TEST_ASSERT(pool->size == 17, "chcap not called")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
50
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
51 intptr_t *pooladdr =
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
52 (intptr_t*)((char*)pool->data[1] + sizeof(ucx_destructor));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
53 *pooladdr = 5;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
54
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
55 UCX_TEST_ASSERT(*test == 5, "wrong pointer")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
56
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
57 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
58
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
59 UCX_TEST_END
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
60 }
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
61
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
62 UCX_TEST_BEGIN(test_ucx_mempool_calloc) {
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
63
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
64 UcxMempool *pool = ucx_mempool_new(1);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
65
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
66 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
67
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
68 UCX_TEST_ASSERT(test != NULL, "no memory for test data")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
69 UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
70
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
71 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
72
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
73 UCX_TEST_END
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
74 }
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
75
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
76 void test_setdestr(void* elem) {
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
77 intptr_t *cb = (intptr_t*) ((intptr_t*) elem)[1];
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
78 *cb = 42;
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 }
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
81 UCX_TEST_BEGIN(test_ucx_mempool_set_destr) {
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
82
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
83 UcxMempool *pool = ucx_mempool_new(2);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
84
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
85 ucx_mempool_malloc(pool, sizeof(intptr_t));
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
86 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
87
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
88 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
89 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
90
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
91 test[0] = 5; test[1] = (intptr_t) cb;
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
92 *cb = 13;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
93
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
94 ucx_mempool_set_destr(test, test_setdestr);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
95 UCX_TEST_ASSERT(
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
96 *(ucx_destructor*)(pool->data[1]) == test_setdestr, "failed")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
97 UCX_TEST_ASSERT(
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
98 test[0] == 5 && test[1] == (intptr_t) cb, "setdestr destroyed data")
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
99
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
100 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
101
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
102 UCX_TEST_ASSERT(*cb == 42, "destructor not called")
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
104 free(cb);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
105
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
106 UCX_TEST_END
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
107 }
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
110 UCX_TEST_BEGIN(test_ucx_mempool_reg_destr) {
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
111
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
112 UcxMempool *pool = ucx_mempool_new(1);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
113
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
114 intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
115
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
116 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
117 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
118
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
119 test[0] = 5; test[1] = (intptr_t) cb;
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
120 *cb = 13;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
121
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
122 ucx_mempool_reg_destr(pool, test, test_setdestr);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
123
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
124 ucx_destructor *pooladdr = (ucx_destructor*)
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
125 ((char*)pool->data[0] + sizeof(ucx_destructor));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
126
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
127 UCX_TEST_ASSERT(*pooladdr == test_setdestr, "failed")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
128
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
129 ucx_mempool_free(pool);
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
130 free(test);
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
131
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
132 UCX_TEST_ASSERT(*cb == 42, "destructor not called")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
133
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
134 free(cb);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
135
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
136 UCX_TEST_END
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
137 }
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
139 UCX_TEST_BEGIN(test_ucx_mempool_realloc) {
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
140
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
141 UcxMempool *pool = ucx_mempool_new(2);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
142
32
c7af4ec56e19 consequently used intptr_t in mpool tests
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
143 ucx_mempool_malloc(pool, sizeof(intptr_t));
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
144 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
145
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
146 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
147 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
148
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
149 test[0] = 5; test[1] = (intptr_t) cb;
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
150 *cb = 13;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
151
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
152 ucx_mempool_set_destr(test, test_setdestr);
14
b78e174b6814 Fixed realloc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 13
diff changeset
153
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
154 int *rtest, n = 2;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
155 do {
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
156 n *= 2;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
157 UCX_TEST_ASSERT(n < 65536, "test corrupt - no movement for realloc")
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
158 rtest = ucx_mempool_realloc(pool, test, n*sizeof(intptr_t));
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
159 } while (rtest == test);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
160 test = rtest;
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
161
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
162 UCX_TEST_ASSERT(*(ucx_destructor*)(pool->data[1]) == test_setdestr,
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
163 "realloc killed destructor")
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
164 UCX_TEST_ASSERT(
30
23bb65cbf7a4 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 28
diff changeset
165 test[0] == 5 && test[1] == (intptr_t) cb, "realloc destroyed data")
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
166
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
167 ucx_mempool_free(pool);
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
168
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
169 UCX_TEST_ASSERT(*cb == 42, "destructor not called")
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
171 free(cb);
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172
28
1666cbeb1db8 new mempool tests
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
173 UCX_TEST_END
13
98ac89e3aa37 Added mempool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 }

mercurial