Skip to content

Commit

Permalink
t/unit-tests: convert mem-pool test to use clar test framework
Browse files Browse the repository at this point in the history
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 <ps@pks.im>
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Seyi007 authored and gitster committed Jan 16, 2025
1 parent ed2916a commit b5f6277
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ THIRD_PARTY_SOURCES += $(UNIT_TEST_DIR)/clar/%
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))
Expand All @@ -1347,7 +1348,6 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
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
Expand Down
2 changes: 1 addition & 1 deletion t/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
clar_test_suites = [
'unit-tests/u-ctype.c',
'unit-tests/u-mem-pool.c',
'unit-tests/u-strvec.c',
]

Expand Down Expand Up @@ -43,7 +44,6 @@ unit_test_programs = [
'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',
Expand Down
31 changes: 0 additions & 31 deletions t/unit-tests/t-mem-pool.c

This file was deleted.

25 changes: 25 additions & 0 deletions t/unit-tests/u-mem-pool.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#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);
}

0 comments on commit b5f6277

Please sign in to comment.