aboutsummaryrefslogtreecommitdiff
path: root/mempool/test
diff options
context:
space:
mode:
Diffstat (limited to 'mempool/test')
-rw-r--r--mempool/test/mempool_test.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/mempool/test/mempool_test.c b/mempool/test/mempool_test.c
index d257922..e6c24a4 100644
--- a/mempool/test/mempool_test.c
+++ b/mempool/test/mempool_test.c
@@ -18,12 +18,20 @@ static int sum(test_pool* pool) {
18 return sum; 18 return sum;
19} 19}
20 20
21// Create a pool. 21// Create a statically-backed pool.
22TEST_CASE(mempool_create) { 22TEST_CASE(mempool_create) {
23 test_pool pool; 23 test_pool pool;
24 mempool_make(&pool); 24 mempool_make(&pool);
25} 25}
26 26
27// Create a dynamically-backed pool.
28TEST_CASE(mem_create_dyn) {
29 DEF_MEMPOOL_DYN(dyn_pool, int);
30
31 dyn_pool pool;
32 mempool_make_dyn(&pool, NUM_BLOCKS, sizeof(int));
33}
34
27// Allocate all N blocks. 35// Allocate all N blocks.
28TEST_CASE(mempool_allocate_until_full) { 36TEST_CASE(mempool_allocate_until_full) {
29 test_pool pool; 37 test_pool pool;
@@ -154,4 +162,27 @@ TEST_CASE(mempool_get_block) {
154 } 162 }
155} 163}
156 164
165// Clear and re-use an allocator.
166TEST_CASE(mem_clear_then_reuse) {
167 test_pool mem;
168 mempool_make(&mem);
169
170 // Allocate chunks, contents not important.
171 for (int i = 0; i < NUM_BLOCKS; ++i) {
172 int* chunk = mempool_alloc(&mem);
173 TEST_TRUE(chunk != 0);
174 }
175
176 mempool_clear(&mem);
177
178 // Allocate chunks and assign values 0..N.
179 for (int i = 0; i < NUM_BLOCKS; ++i) {
180 int* chunk = mempool_alloc(&mem);
181 TEST_TRUE(chunk != 0);
182 *chunk = i + 1;
183 }
184
185 TEST_EQUAL(sum(&mem), NUM_BLOCKS * (NUM_BLOCKS + 1) / 2);
186}
187
157int main() { return 0; } 188int main() { return 0; }