Skip to content

Commit c143dfa

Browse files
Seyi007gitster
authored andcommitted
t/unit-tests: convert mem-pool test to use clar test framework
Adapt the mem-pool test script to use clar framework by using clar assertions where necessary.Test functions are created as a standalone to test different test cases. Mentored-by: Patrick Steinhardt <[email protected]> Signed-off-by: Seyi Kuforiji <[email protected]> Acked-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aae2b43 commit c143dfa

File tree

4 files changed

+27
-33
lines changed

4 files changed

+27
-33
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/%
13381338
THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/clar/%
13391339

13401340
CLAR_TEST_SUITES += u-ctype
1341+
CLAR_TEST_SUITES += u-mem-pool
13411342
CLAR_TEST_SUITES += u-strvec
13421343
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
13431344
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
@@ -1347,7 +1348,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
13471348
UNIT_TEST_PROGRAMS += t-example-decorate
13481349
UNIT_TEST_PROGRAMS += t-hash
13491350
UNIT_TEST_PROGRAMS += t-hashmap
1350-
UNIT_TEST_PROGRAMS += t-mem-pool
13511351
UNIT_TEST_PROGRAMS += t-oid-array
13521352
UNIT_TEST_PROGRAMS += t-oidmap
13531353
UNIT_TEST_PROGRAMS += t-oidtree

t/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
clar_test_suites = [
22
'unit-tests/u-ctype.c',
3+
'unit-tests/u-mem-pool.c',
34
'unit-tests/u-strvec.c',
45
]
56

@@ -43,7 +44,6 @@ unit_test_programs = [
4344
'unit-tests/t-example-decorate.c',
4445
'unit-tests/t-hash.c',
4546
'unit-tests/t-hashmap.c',
46-
'unit-tests/t-mem-pool.c',
4747
'unit-tests/t-oid-array.c',
4848
'unit-tests/t-oidmap.c',
4949
'unit-tests/t-oidtree.c',

t/unit-tests/t-mem-pool.c

Lines changed: 0 additions & 31 deletions
This file was deleted.

t/unit-tests/u-mem-pool.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "unit-test.h"
2+
#include "mem-pool.h"
3+
4+
static void test_many_pool_allocations(size_t block_alloc)
5+
{
6+
struct mem_pool pool = { .block_alloc = block_alloc };
7+
size_t size = 100;
8+
char *buffer = mem_pool_calloc(&pool, 1, size);
9+
for (size_t i = 0; i < size; i++)
10+
cl_assert_equal_i(0, buffer[i]);
11+
cl_assert(pool.mp_block != NULL);
12+
cl_assert(pool.mp_block->next_free != NULL);
13+
cl_assert(pool.mp_block->end != NULL);
14+
mem_pool_discard(&pool, 0);
15+
}
16+
17+
void test_mem_pool__big_block(void)
18+
{
19+
test_many_pool_allocations(1024 * 1024);
20+
}
21+
22+
void test_mem_pool__tiny_block(void)
23+
{
24+
test_many_pool_allocations(1);
25+
}

0 commit comments

Comments
 (0)