From 22e8064ae9634ff07c7634b17ce7732515796ff1 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 8 Aug 2007 17:26:40 +1000 Subject: [PATCH] add more extensive test cases and verify that we are not losing any memory inside the tree (This used to be ctdb commit 838376b52d65af509532a141d83b51975c7cc881) --- ctdb/tests/rb_test.c | 70 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/ctdb/tests/rb_test.c b/ctdb/tests/rb_test.c index 693a3f344e8..553517d12b5 100644 --- a/ctdb/tests/rb_test.c +++ b/ctdb/tests/rb_test.c @@ -28,6 +28,20 @@ #include #include "common/rb_tree.h" +static struct timeval tp1,tp2; + +static void start_timer(void) +{ + gettimeofday(&tp1,NULL); +} + +static double end_timer(void) +{ + gettimeofday(&tp2,NULL); + return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) - + (tp1.tv_sec + (tp1.tv_usec*1.0e-6)); +} + int num_records; void *callback(void *param, void *d) @@ -43,12 +57,25 @@ void *callback(void *param, void *d) return data; } -void traverse(void *param, void *d) +void *random_add(void *p, void *d) +{ + if(d){ + talloc_free(d); + } + return p; +} + +void traverse(void *p, void *d) { uint32_t *data = (uint32_t *)d; printf("traverse data:%d\n",*data); } + +void random_traverse(void *p, void *d) +{ + printf("%s ",(char *)d); +} /* @@ -67,9 +94,10 @@ int main(int argc, const char *argv[]) int extra_argc = 0; poptContext pc; struct event_context *ev; - int i; + int i,j,k; trbt_tree_t *tree; uint32_t *data; + uint32_t key[3]; uint32_t key1[3] = {0,10,20}; uint32_t key2[3] = {0,10,21}; uint32_t key3[3] = {0,11,20}; @@ -181,5 +209,43 @@ int main(int argc, const char *argv[]) trbt_traversearray32(tree, 3, traverse, NULL); + printf("\nrun random insert and delete for 60 seconds\n"); + tree = trbt_create(NULL); + i=0; + start_timer(); + while(end_timer() < 10.0){ + char *str; + + i++; + key[0]=random()%10; + key[1]=random()%10; + key[2]=random()%10; + if (random()%2) { + str=talloc_asprintf(tree, "%d.%d.%d", key[0],key[1],key[2]); + trbt_insertarray32_callback(tree, 3, key, random_add, str); + } else { + trbt_deletearray32(tree, 3, key); + } + if(i%1000==999)printf(".");fflush(stdout); + } + printf("\n"); + trbt_traversearray32(tree, 3, random_traverse, NULL); + printf("\n"); + + printf("\ndeleting all entries\n"); + for(i=0;i<10;i++){ + for(j=0;j<10;j++){ + for(k=0;k<10;k++){ + key[0]=i; + key[1]=j; + key[2]=k; + trbt_deletearray32(tree, 3, key); + } + } + } + trbt_traversearray32(tree, 3, random_traverse, NULL); + printf("\n"); + talloc_report_full(tree, stdout); + return 0; }