X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Frbtree%2Ftest%2Frun-many.c;fp=ccan%2Frbtree%2Ftest%2Frun-many.c;h=9ab96c820ba8da0677f93649825ec01a25289ca0;hp=75d2d01e5904edc0d0ec64db913a1d9ec36153b8;hb=c0ea2922129a17724930f1c3b535985d7576d63e;hpb=8d20b53ecd76773591e95db3bdfcbbd5129efb9e diff --git a/ccan/rbtree/test/run-many.c b/ccan/rbtree/test/run-many.c index 75d2d01e..9ab96c82 100644 --- a/ccan/rbtree/test/run-many.c +++ b/ccan/rbtree/test/run-many.c @@ -3,8 +3,25 @@ #include #include #include +#include +#include +#define NUM_ELEMS 100 -#define NUM_ELEMS 10000 +/* We want to test talloc failure paths. */ +static void *my_malloc(size_t size) +{ + return malloc(size); +} + +static void my_free(void *ptr) +{ + free(ptr); +} + +static void *my_realloc(void *ptr, size_t size) +{ + return realloc(ptr, size); +} static bool lookup_all(trbt_tree_t *rb, bool exist) { @@ -26,15 +43,25 @@ static bool lookup_all(trbt_tree_t *rb, bool exist) static bool add_one(trbt_tree_t *rb, bool exist, unsigned int i) { - int *p = trbt_insert32(rb, i, talloc_memdup(rb, &i, sizeof(i))); + int *new = talloc_memdup(rb, &i, sizeof(i)); + int *p; + + if (!new) + return false; + + p = trbt_insert32(rb, i, new); if (p) { if (!exist) return false; if (*p != i) return false; - } else + } else { if (exist) return false; + else + if (!trbt_lookup32(rb, i)) + return false; + } return true; } @@ -63,13 +90,27 @@ static void delete_all(trbt_tree_t *rb) } } -int main(void) +static void *ctx; +static trbt_tree_t *rb; + +static void exit_test(void) { - trbt_tree_t *rb; - void *ctx = talloc_strdup(NULL, "toplevel"); + talloc_free(rb); + ok1(talloc_total_blocks(ctx) == 1); + talloc_free(ctx); + failtest_exit(exit_status()); +} +int main(int argc, char *argv[]) +{ + failtest_init(argc, argv); + tap_fail_callback = exit_test; plan_tests(8); + ctx = talloc_strdup(NULL, "toplevel"); + + talloc_set_allocator(my_malloc, my_free, my_realloc); + rb = trbt_create(ctx, 0); ok1(rb); @@ -100,5 +141,5 @@ int main(void) talloc_free(ctx); /* This exits depending on whether all tests passed */ - return exit_status(); + failtest_exit(exit_status()); }