THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%
CLAR_TEST_SUITES += u-ctype
+CLAR_TEST_SUITES += u-mem-pool
CLAR_TEST_SUITES += u-strvec
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
UNIT_TEST_PROGRAMS += t-example-decorate
UNIT_TEST_PROGRAMS += t-hash
UNIT_TEST_PROGRAMS += t-hashmap
-UNIT_TEST_PROGRAMS += t-mem-pool
UNIT_TEST_PROGRAMS += t-oid-array
UNIT_TEST_PROGRAMS += t-oidmap
UNIT_TEST_PROGRAMS += t-oidtree
clar_test_suites = [
'unit-tests/u-ctype.c',
+ 'unit-tests/u-mem-pool.c',
'unit-tests/u-strvec.c',
]
'unit-tests/t-example-decorate.c',
'unit-tests/t-hash.c',
'unit-tests/t-hashmap.c',
- 'unit-tests/t-mem-pool.c',
'unit-tests/t-oid-array.c',
'unit-tests/t-oidmap.c',
'unit-tests/t-oidtree.c',
+++ /dev/null
-#include "test-lib.h"
-#include "mem-pool.h"
-
-static void setup_static(void (*f)(struct mem_pool *), size_t block_alloc)
-{
- struct mem_pool pool = { .block_alloc = block_alloc };
- f(&pool);
- mem_pool_discard(&pool, 0);
-}
-
-static void t_calloc_100(struct mem_pool *pool)
-{
- size_t size = 100;
- char *buffer = mem_pool_calloc(pool, 1, size);
- for (size_t i = 0; i < size; i++)
- check_int(buffer[i], ==, 0);
- if (!check(pool->mp_block != NULL))
- return;
- check(pool->mp_block->next_free != NULL);
- check(pool->mp_block->end != NULL);
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- TEST(setup_static(t_calloc_100, 1024 * 1024),
- "mem_pool_calloc returns 100 zeroed bytes with big block");
- TEST(setup_static(t_calloc_100, 1),
- "mem_pool_calloc returns 100 zeroed bytes with tiny block");
-
- return test_done();
-}
--- /dev/null
+#include "unit-test.h"
+#include "mem-pool.h"
+
+static void test_many_pool_allocations(size_t block_alloc)
+{
+ struct mem_pool pool = { .block_alloc = block_alloc };
+ size_t size = 100;
+ char *buffer = mem_pool_calloc(&pool, 1, size);
+ for (size_t i = 0; i < size; i++)
+ cl_assert_equal_i(0, buffer[i]);
+ cl_assert(pool.mp_block != NULL);
+ cl_assert(pool.mp_block->next_free != NULL);
+ cl_assert(pool.mp_block->end != NULL);
+ mem_pool_discard(&pool, 0);
+}
+
+void test_mem_pool__big_block(void)
+{
+ test_many_pool_allocations(1024 * 1024);
+}
+
+void test_mem_pool__tiny_block(void)
+{
+ test_many_pool_allocations(1);
+}