20 |
20 |
21 UCX_TEST_BEGIN(test_ucx_mempool_malloc) { |
21 UCX_TEST_BEGIN(test_ucx_mempool_malloc) { |
22 |
22 |
23 UcxMempool *pool = ucx_mempool_new(1); |
23 UcxMempool *pool = ucx_mempool_new(1); |
24 |
24 |
25 int *test = (int*) ucx_mempool_malloc(pool, sizeof(int)); |
25 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); |
26 |
26 |
27 UCX_TEST_ASSERT(pool->ndata == 1, "counter not incremented") |
27 UCX_TEST_ASSERT(pool->ndata == 1, "counter not incremented") |
28 UCX_TEST_ASSERT(pool->size == 1, "chcap called") |
28 UCX_TEST_ASSERT(pool->size == 1, "chcap called") |
29 |
29 |
30 int *pooladdr = (int*)((char*)pool->data[0] + sizeof(ucx_destructor)); |
30 intptr_t *pooladdr = |
|
31 (intptr_t*)((char*)pool->data[0] + sizeof(ucx_destructor)); |
31 *pooladdr = 5; |
32 *pooladdr = 5; |
32 |
33 |
33 UCX_TEST_ASSERT(*test == 5, "wrong pointer") |
34 UCX_TEST_ASSERT(*test == 5, "wrong pointer") |
34 |
35 |
35 ucx_mempool_free(pool); |
36 ucx_mempool_free(pool); |
40 UCX_TEST_BEGIN(test_ucx_mempool_malloc_with_chcap) { |
41 UCX_TEST_BEGIN(test_ucx_mempool_malloc_with_chcap) { |
41 |
42 |
42 UcxMempool *pool = ucx_mempool_new(1); |
43 UcxMempool *pool = ucx_mempool_new(1); |
43 |
44 |
44 ucx_mempool_malloc(pool, sizeof(int)); |
45 ucx_mempool_malloc(pool, sizeof(int)); |
45 int *test = (int*) ucx_mempool_malloc(pool, sizeof(int)); |
46 intptr_t *test = (intptr_t*) ucx_mempool_malloc(pool, sizeof(intptr_t)); |
46 |
47 |
47 UCX_TEST_ASSERT(pool->ndata == 2, "counter not incremented") |
48 UCX_TEST_ASSERT(pool->ndata == 2, "counter not incremented") |
48 UCX_TEST_ASSERT(pool->size == 17, "chcap not called") |
49 UCX_TEST_ASSERT(pool->size == 17, "chcap not called") |
49 |
50 |
50 int *pooladdr = (int*)((char*)pool->data[1] + sizeof(ucx_destructor)); |
51 intptr_t *pooladdr = |
|
52 (intptr_t*)((char*)pool->data[1] + sizeof(ucx_destructor)); |
51 *pooladdr = 5; |
53 *pooladdr = 5; |
52 |
54 |
53 UCX_TEST_ASSERT(*test == 5, "wrong pointer") |
55 UCX_TEST_ASSERT(*test == 5, "wrong pointer") |
54 |
56 |
55 ucx_mempool_free(pool); |
57 ucx_mempool_free(pool); |
59 |
61 |
60 UCX_TEST_BEGIN(test_ucx_mempool_calloc) { |
62 UCX_TEST_BEGIN(test_ucx_mempool_calloc) { |
61 |
63 |
62 UcxMempool *pool = ucx_mempool_new(1); |
64 UcxMempool *pool = ucx_mempool_new(1); |
63 |
65 |
64 int *test = (int*) ucx_mempool_calloc(pool, 2, sizeof(int)); |
66 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); |
65 |
67 |
66 UCX_TEST_ASSERT(test != NULL, "no memory for test data") |
68 UCX_TEST_ASSERT(test != NULL, "no memory for test data") |
67 UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed") |
69 UCX_TEST_ASSERT(test[0] == 0 && test[1] == 0, "failed") |
68 |
70 |
69 ucx_mempool_free(pool); |
71 ucx_mempool_free(pool); |
78 |
80 |
79 UCX_TEST_BEGIN(test_ucx_mempool_set_destr) { |
81 UCX_TEST_BEGIN(test_ucx_mempool_set_destr) { |
80 |
82 |
81 UcxMempool *pool = ucx_mempool_new(2); |
83 UcxMempool *pool = ucx_mempool_new(2); |
82 |
84 |
83 ucx_mempool_malloc(pool, sizeof(int)); |
85 ucx_mempool_malloc(pool, sizeof(intptr_t)); |
84 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); |
86 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); |
85 |
87 |
86 int *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
88 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
87 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") |
89 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") |
88 |
90 |
89 test[0] = 5; test[1] = (intptr_t) cb; |
91 test[0] = 5; test[1] = (intptr_t) cb; |
90 *cb = 13; |
92 *cb = 13; |
91 |
93 |
136 |
138 |
137 UCX_TEST_BEGIN(test_ucx_mempool_realloc) { |
139 UCX_TEST_BEGIN(test_ucx_mempool_realloc) { |
138 |
140 |
139 UcxMempool *pool = ucx_mempool_new(2); |
141 UcxMempool *pool = ucx_mempool_new(2); |
140 |
142 |
141 ucx_mempool_malloc(pool, sizeof(int)); |
143 ucx_mempool_malloc(pool, sizeof(intptr_t)); |
142 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); |
144 intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); |
143 |
145 |
144 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
146 intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); |
145 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") |
147 UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") |
146 |
148 |