diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-01-08 14:05:16 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-01-08 14:05:17 -0800 |
| commit | bdfa7a2445a672c9eaf4f103167d1022a70ea39b (patch) | |
| tree | f56251175bd665f97803be323849ba3e153b75c1 /t | |
| parent | Merge branch 'rs/fast-import-simplify-mempool-allocation' (diff) | |
| parent | mem-pool: simplify alignment calculation (diff) | |
| download | git-bdfa7a2445a672c9eaf4f103167d1022a70ea39b.tar.gz git-bdfa7a2445a672c9eaf4f103167d1022a70ea39b.zip | |
Merge branch 'rs/mem-pool-improvements'
MemPool allocator fixes.
* rs/mem-pool-improvements:
mem-pool: simplify alignment calculation
mem-pool: fix big allocations
Diffstat (limited to 't')
| -rw-r--r-- | t/unit-tests/t-mem-pool.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/t/unit-tests/t-mem-pool.c b/t/unit-tests/t-mem-pool.c new file mode 100644 index 0000000000..a0d57df761 --- /dev/null +++ b/t/unit-tests/t-mem-pool.c @@ -0,0 +1,31 @@ +#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, const char **argv) +{ + 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(); +} |
