From 78ba5de2dc4c74f772b9e40cd673476dac6d7a1a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 19 Nov 2012 10:58:25 +1030 Subject: [PATCH 1/1] tal: add test for group growth. Rusty forgets a git add. Signed-off-by: Rusty Russell --- ccan/tal/test/run-groups-grow.c | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ccan/tal/test/run-groups-grow.c diff --git a/ccan/tal/test/run-groups-grow.c b/ccan/tal/test/run-groups-grow.c new file mode 100644 index 00000000..e8e382db --- /dev/null +++ b/ccan/tal/test/run-groups-grow.c @@ -0,0 +1,46 @@ +#define CCAN_TAL_DEBUG +#include +#include +#include + +static size_t num_allocated; + +static void *alloc_account(size_t len) +{ + num_allocated++; + return malloc(len); +} + +static void free_account(void *p) +{ + num_allocated--; + return free(p); +} + +#define NUM_ALLOCS 1000 + +int main(void) +{ + void *p, *c[NUM_ALLOCS]; + int i; + size_t allocated_after_first; + + plan_tests(1); + + tal_set_backend(alloc_account, NULL, free_account, NULL); + + p = tal(NULL, char); + c[0] = tal(p, char); + + allocated_after_first = num_allocated; + for (i = 1; i < NUM_ALLOCS; i++) + c[i] = tal(p, char); + + /* Now free them all. */ + for (i = 0; i < NUM_ALLOCS; i++) + tal_free(c[i]); + + /* We can expect some residue from having any child, but limited! */ + ok1(num_allocated <= allocated_after_first); + return exit_status(); +} -- 2.39.2