28 |
28 |
29 #include <stdint.h> |
29 #include <stdint.h> |
30 |
30 |
31 #include "mpool_tests.h" |
31 #include "mpool_tests.h" |
32 |
32 |
33 UCX_TEST_IMPLEMENT(test_ucx_mempool_new) { |
33 UCX_TEST(test_ucx_mempool_new) { |
34 UcxMempool *pool = ucx_mempool_new(16); |
34 UcxMempool *pool = ucx_mempool_new(16); |
35 UCX_TEST_BEGIN |
35 UCX_TEST_BEGIN |
36 UCX_TEST_ASSERT(pool->size == 16, "wrong size"); |
36 UCX_TEST_ASSERT(pool->size == 16, "wrong size"); |
37 UCX_TEST_ASSERT(pool->ndata == 0, "uninitialized counter"); |
37 UCX_TEST_ASSERT(pool->ndata == 0, "uninitialized counter"); |
38 UCX_TEST_ASSERT(pool->data != NULL, "no memory addressed"); |
38 UCX_TEST_ASSERT(pool->data != NULL, "no memory addressed"); |
39 UCX_TEST_END |
39 UCX_TEST_END |
40 ucx_mempool_destroy(pool); |
40 ucx_mempool_destroy(pool); |
41 } |
41 } |
42 |
42 |
43 UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc) { |
43 UCX_TEST(test_ucx_mempool_malloc) { |
44 |
44 |
45 UcxMempool *pool = ucx_mempool_new(1); |
45 UcxMempool *pool = ucx_mempool_new(1); |
46 UCX_TEST_BEGIN |
46 UCX_TEST_BEGIN |
47 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); |
47 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); |
48 |
48 |
57 |
57 |
58 UCX_TEST_END |
58 UCX_TEST_END |
59 ucx_mempool_destroy(pool); |
59 ucx_mempool_destroy(pool); |
60 } |
60 } |
61 |
61 |
62 UCX_TEST_IMPLEMENT(test_ucx_mempool_malloc_with_chcap) { |
62 UCX_TEST(test_ucx_mempool_malloc_with_chcap) { |
63 |
63 |
64 UcxMempool *pool = ucx_mempool_new(1); |
64 UcxMempool *pool = ucx_mempool_new(1); |
65 UCX_TEST_BEGIN |
65 UCX_TEST_BEGIN |
66 ucx_mempool_malloc(pool, sizeof(int)); |
66 ucx_mempool_malloc(pool, sizeof(int)); |
67 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); |
67 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); |
77 |
77 |
78 UCX_TEST_END |
78 UCX_TEST_END |
79 ucx_mempool_destroy(pool); |
79 ucx_mempool_destroy(pool); |
80 } |
80 } |
81 |
81 |
82 UCX_TEST_IMPLEMENT(test_ucx_mempool_calloc) { |
82 UCX_TEST(test_ucx_mempool_calloc) { |
83 |
83 |
84 UcxMempool *pool = ucx_mempool_new(1); |
84 UcxMempool *pool = ucx_mempool_new(1); |
85 UCX_TEST_BEGIN |
85 UCX_TEST_BEGIN |
86 |
86 |
87 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); |
87 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); |
126 UCX_EXTERN void test_setdestr(void* elem) { |
126 UCX_EXTERN void test_setdestr(void* elem) { |
127 intptr_t *cb = (intptr_t*) ((intptr_t*) elem)[1]; |
127 intptr_t *cb = (intptr_t*) ((intptr_t*) elem)[1]; |
128 *cb = 42; |
128 *cb = 42; |
129 } |
129 } |
130 |
130 |
131 UCX_TEST_IMPLEMENT(test_ucx_mempool_set_destr) { |
131 UCX_TEST(test_ucx_mempool_set_destr) { |
132 |
132 |
133 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
133 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
134 UCX_TEST_BEGIN |
134 UCX_TEST_BEGIN |
135 UcxMempool *pool = ucx_mempool_new(2); |
135 UcxMempool *pool = ucx_mempool_new(2); |
136 |
136 |
155 UCX_TEST_END |
155 UCX_TEST_END |
156 if (cb != NULL) free(cb); |
156 if (cb != NULL) free(cb); |
157 } |
157 } |
158 |
158 |
159 |
159 |
160 UCX_TEST_IMPLEMENT(test_ucx_mempool_reg_destr) { |
160 UCX_TEST(test_ucx_mempool_reg_destr) { |
161 |
161 |
162 intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t)); |
162 intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t)); |
163 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
163 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
164 UCX_TEST_BEGIN |
164 UCX_TEST_BEGIN |
165 UcxMempool *pool = ucx_mempool_new(1); |
165 UcxMempool *pool = ucx_mempool_new(1); |
182 |
182 |
183 if (test != NULL) free(test); |
183 if (test != NULL) free(test); |
184 if (cb != NULL) free(cb); |
184 if (cb != NULL) free(cb); |
185 } |
185 } |
186 |
186 |
187 UCX_TEST_IMPLEMENT(test_ucx_mempool_realloc) { |
187 UCX_TEST(test_ucx_mempool_realloc) { |
188 |
188 |
189 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
189 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
190 UCX_TEST_BEGIN |
190 UCX_TEST_BEGIN |
191 UcxMempool *pool = ucx_mempool_new(2); |
191 UcxMempool *pool = ucx_mempool_new(2); |
192 |
192 |