mirror of
https://github.com/samba-team/samba.git
synced 2025-01-12 09:18:10 +03:00
add more extensive test cases and verify that we are not losing any
memory inside the tree (This used to be ctdb commit 838376b52d65af509532a141d83b51975c7cc881)
This commit is contained in:
parent
9c216d0d76
commit
22e8064ae9
@ -28,6 +28,20 @@
|
||||
#include <time.h>
|
||||
#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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user