3 /* multidict_crash - A crash test for multi-level dictionnaries */
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
14 #define NB_ELM 10/*00*/
15 #define MULTICACHE_DEPTH 5
16 #define KEY_SIZE 12 /*512*/
20 static xbt_error_t test1();
22 static xbt_error_t test1() {
24 xbt_dict_t *head=NULL;
30 printf("\nGeneric multicache: CRASH test:\n");
31 printf(" Fill the struct and frees it %d times, using %d elements, depth of multicache=%d\n",NB_TEST,NB_ELM,MULTICACHE_DEPTH);
32 printf(" with %d chars long randomized keys. (a point is a test)\n",KEY_SIZE);
34 for (i=0;i<NB_TEST;i++) {
35 if (i%10) printf("."); else printf("%d",i/10); fflush(stdout);
36 if (!(key=malloc(sizeof(char*)*MULTICACHE_DEPTH)))
38 if (!(val=malloc(sizeof(char*)*MULTICACHE_DEPTH)))
40 for (l=0 ; l<MULTICACHE_DEPTH ; l++)
41 if (!(val[l]=malloc(sizeof(char)*KEY_SIZE)))
44 for (j=0;j<NB_ELM;j++) {
45 if (verbose) printf ("Add ");
46 for (l=0 ; l<MULTICACHE_DEPTH ; l++){
47 for (k=0;k<KEY_SIZE-1;k++) {
48 val[l][k]=rand() % ('z' - 'a') + 'a';
51 if (verbose) printf("%s ; ",val[l]);
52 key[l]=val[l];/* NOWADAYS, no need to strdup the key. */
54 if (verbose) printf("in multitree %p.\n",head);
55 TRYFAIL(xbt_multidict_set(&head,MULTICACHE_DEPTH,key,
56 strdup(val[0]),&free));
58 TRYFAIL(xbt_multidict_get(head,
59 MULTICACHE_DEPTH,(const char **)val,
61 if (!data || strcmp((char*)data,val[0])) {
62 fprintf(stderr,"Retrieved value (%s) does not match the entrered one (%s)\n",
67 xbt_dict_dump(head,&xbt_dict_print);
70 for (l=0 ; l<MULTICACHE_DEPTH ; l++)
71 if (val[l]) free(val[l]);
81 int main(int argc, char *argv[]) {
84 xbt_init(argc,argv,"root.thresh=debug"));