git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/4] t/unit-tests: convert mem-pool test to use clar test framework

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 16, 2025, 13:12 UTC
Message-ID
<Z4kF1zR9TA8ff2bl@pks.im>
In-Reply-To
<20250116104911.77405-3-kuforiji98@gmail.com>
On Thu, Jan 16, 2025 at 11:49:09AM +0100, Seyi Kuforiji wrote:
> Adapt the mem-pool test script to use clar framework by using clar
> assertions where necessary. Following the consensus to convert the
> unit-tests scripts found in the t/unit-tests folder to clar driven by
> Patrick Steinhardt.

I think it's a minor detail that isn't really worth mentioning that I was the one introducing the clar, so I'd leave my name out of it. This also applies to subsequent commit messages.

Show 37 quoted lines
> diff --git a/t/unit-tests/t-mem-pool.c b/t/unit-tests/t-mem-pool.c
> deleted file mode 100644
> index fe500c704b..0000000000
> --- a/t/unit-tests/t-mem-pool.c
> +++ /dev/null
> @@ -1,31 +0,0 @@
> -#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();
> -}
Mh, too bad that Git doesn't render it as a 
Show 10 quoted lines
> diff --git a/t/unit-tests/u-mem-pool.c b/t/unit-tests/u-mem-pool.c
> new file mode 100644
> index 0000000000..36e31a3201
> --- /dev/null
> +++ b/t/unit-tests/u-mem-pool.c
> @@ -0,0 +1,26 @@
> +#include "unit-test.h"
> +#include "mem-pool.h"
> +
> +static void t_calloc_100(size_t block_alloc)

Can we maybe give this a more descriptive name? Something like `test_many_pool_allocations()` maybe?

Show 16 quoted lines
> +{
> +	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)
> +{
> +	t_calloc_100(1024 * 1024);
> +
There is a needless empty line here.
Other than that the changes look good to me.
Patrick
Previous: Seyi KuforijiNext: Junio C Hamano
Message 5 of 24 in “t/unit-tests: convert unit-tests to use clar”
  1. 0/4 t/unit-tests: convert unit-tests to use clarSeyi Kuforiji, Jan 16, 2025
  2. 1/4 t/unit-tests: handle dashes in test suite filenamesSeyi Kuforiji, Jan 16, 2025
  3. Patrick SteinhardtJan 16, 2025
  4. 2/4 t/unit-tests: convert mem-pool test to use clar test frameworkSeyi Kuforiji, Jan 16, 2025
  5. Patrick SteinhardtJan 16, 2025
  6. Junio C HamanoJan 16, 2025
  7. 3/4 t/unit-tests: adapt priority queue test to use clar test frameworkSeyi Kuforiji, Jan 16, 2025
  8. Patrick SteinhardtJan 16, 2025
  9. 4/4 t/unit-tests: convert reftable tree test to use clar test frameworkSeyi Kuforiji, Jan 16, 2025
  10. 0/4 t/unit-tests: convert unit-tests to use clarSeyi Kuforiji, Jan 16, 2025
  11. 1/4 t/unit-tests: handle dashes in test suite filenamesSeyi Kuforiji, Jan 16, 2025
  12. Patrick SteinhardtJan 17, 2025
  13. 2/4 t/unit-tests: convert mem-pool test to use clar test frameworkSeyi Kuforiji, Jan 16, 2025
  14. 3/4 t/unit-tests: adapt priority queue test to use clar test frameworkSeyi Kuforiji, Jan 16, 2025
  15. 4/4 t/unit-tests: convert reftable tree test to use clar test frameworkSeyi Kuforiji, Jan 16, 2025
  16. Patrick SteinhardtJan 17, 2025
  17. t/unit-tests: convert unit-tests to use clarSeyi Kuforiji, Jan 17, 2025
  18. 1/4 t/unit-tests: handle dashes in test suite filenamesSeyi Kuforiji, Jan 17, 2025
  19. 2/4 t/unit-tests: convert mem-pool test to use clar test frameworkSeyi Kuforiji, Jan 17, 2025
  20. Karthik NayakJan 20, 2025
  21. 3/4 t/unit-tests: adapt priority queue test to use clar test frameworkSeyi Kuforiji, Jan 17, 2025
  22. Karthik NayakJan 20, 2025
  23. 4/4 t/unit-tests: convert reftable tree test to use clar test frameworkSeyi Kuforiji, Jan 17, 2025
  24. Patrick SteinhardtJan 17, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.