3 /* multidict_crash - A crash test for multi-level dictionnaries */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
8 /* This program is free software; you can redistribute it and/or modify it
9 under the terms of the license (GNU LGPL) which comes with this package. */
16 #define NB_ELM 10/*00*/
17 #define MULTICACHE_DEPTH 5
18 #define KEY_SIZE 12 /*512*/
22 static xbt_error_t test1();
24 static xbt_error_t test1() {
26 xbt_dict_t *head=NULL;
32 printf("\nGeneric multicache: CRASH test:\n");
33 printf(" Fill the struct and frees it %d times, using %d elements, depth of multicache=%d\n",NB_TEST,NB_ELM,MULTICACHE_DEPTH);
34 printf(" with %d chars long randomized keys. (a point is a test)\n",KEY_SIZE);
36 for (i=0;i<NB_TEST;i++) {
37 if (i%10) printf("."); else printf("%d",i/10); fflush(stdout);
38 if (!(key=malloc(sizeof(char*)*MULTICACHE_DEPTH)))
40 if (!(val=malloc(sizeof(char*)*MULTICACHE_DEPTH)))
42 for (l=0 ; l<MULTICACHE_DEPTH ; l++)
43 if (!(val[l]=malloc(sizeof(char)*KEY_SIZE)))
46 for (j=0;j<NB_ELM;j++) {
47 if (verbose) printf ("Add ");
48 for (l=0 ; l<MULTICACHE_DEPTH ; l++){
49 for (k=0;k<KEY_SIZE-1;k++) {
50 val[l][k]=rand() % ('z' - 'a') + 'a';
53 if (verbose) printf("%s ; ",val[l]);
54 key[l]=val[l];/* NOWADAYS, no need to strdup the key. */
56 if (verbose) printf("in multitree %p.\n",head);
57 TRYFAIL(xbt_multidict_set(&head,MULTICACHE_DEPTH,key,
58 strdup(val[0]),&free));
60 TRYFAIL(xbt_multidict_get(head,
61 MULTICACHE_DEPTH,(const char **)val,
63 if (!data || strcmp((char*)data,val[0])) {
64 fprintf(stderr,"Retrieved value (%s) does not match the entrered one (%s)\n",
69 xbt_dict_dump(head,&xbt_dict_print);
72 for (l=0 ; l<MULTICACHE_DEPTH ; l++)
73 if (val[l]) free(val[l]);
83 int main(int argc, char *argv[]) {
86 xbt_init(argc,argv,"root.thresh=debug"));