Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update now that multidicts are reimplemented
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 27 Jun 2005 22:03:20 +0000 (22:03 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 27 Jun 2005 22:03:20 +0000 (22:03 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1423 48e7efb5-ca39-0410-a469-dd3cf9ba447f

testsuite/xbt/multidict_crash.c

index 0663563..720cbf7 100644 (file)
@@ -2,88 +2,83 @@
 
 /* multidict_crash - A crash test for multi-level dictionnaries             */
 
 
 /* multidict_crash - A crash test for multi-level dictionnaries             */
 
-/* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
+/* Copyright (c) 2003-2005 Martin Quinson. All rights reserved.             */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <stdio.h>
 
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <stdio.h>
 
-#include "gras.h"
+#include "xbt.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(Test,"this test");
 
 #define NB_ELM 10/*00*/
 
 #define NB_ELM 10/*00*/
-#define MULTICACHE_DEPTH 5
-#define KEY_SIZE 12 /*512*/
+#define DEPTH 5
+#define KEY_SIZE 6 /*512*/
 #define NB_TEST 20
 #define NB_TEST 20
-int verbose=0;
+int verbose=1;
 
 
-static xbt_error_t test1();
+static void str_free(void *s) {
+  char *c=*(char**)s;
+  free(c);
+}
 
 
-static xbt_error_t test1() {
+int main(int argc, char *argv[]) {
   xbt_error_t errcode;
   xbt_error_t errcode;
-  xbt_dict_t *head=NULL;
+  xbt_dict_t mdict=xbt_dict_new();
   int i,j,k,l;
   int i,j,k,l;
-  char **key = NULL;
-  char **val = NULL;
+  xbt_dynar_t keys = xbt_dynar_new(sizeof(char*),str_free);
   void *data;
   void *data;
+  char *key;
+
+  xbt_init(&argc,argv);
 
   printf("\nGeneric multicache: CRASH test:\n");
 
   printf("\nGeneric multicache: CRASH test:\n");
-  printf(" Fill the struct and frees it %d times, using %d elements, depth of multicache=%d\n",NB_TEST,NB_ELM,MULTICACHE_DEPTH);
+  printf(" Fill the struct and frees it %d times, using %d elements, depth of multicache=%d\n",NB_TEST,NB_ELM,DEPTH);
   printf(" with %d chars long randomized keys. (a point is a test)\n",KEY_SIZE);
 
   for (i=0;i<NB_TEST;i++) {
   printf(" with %d chars long randomized keys. (a point is a test)\n",KEY_SIZE);
 
   for (i=0;i<NB_TEST;i++) {
-    if (i%10) printf("."); else printf("%d",i/10); fflush(stdout);
-    if (!(key=malloc(sizeof(char*)*MULTICACHE_DEPTH)))
-      RAISE_MALLOC;
-    if (!(val=malloc(sizeof(char*)*MULTICACHE_DEPTH)))
-      RAISE_MALLOC;
-    for (l=0 ; l<MULTICACHE_DEPTH ; l++)
-      if (!(val[l]=malloc(sizeof(char)*KEY_SIZE)))
-       RAISE_MALLOC;
-
+    if (verbose) {
+      printf("Test %d\n",i);
+    } else {
+      if (i%10) printf("."); else printf("%d",i/10);
+    }
+    fflush(stdout);
+    
     for (j=0;j<NB_ELM;j++) {
     for (j=0;j<NB_ELM;j++) {
-      if (verbose) printf ("Add ");
-      for (l=0 ; l<MULTICACHE_DEPTH ; l++){
-       for (k=0;k<KEY_SIZE-1;k++) {
-         val[l][k]=rand() % ('z' - 'a') + 'a';
-       }
-       val[l][k]='\0';
-       if (verbose) printf("%s ; ",val[l]);
-       key[l]=val[l];/*  NOWADAYS, no need to strdup the key. */
-      }
-      if (verbose) printf("in multitree %p.\n",head);
-      TRYFAIL(xbt_multidict_set(&head,MULTICACHE_DEPTH,key,
-                                strdup(val[0]),&free));
-
-      TRYFAIL(xbt_multidict_get(head,
-                                MULTICACHE_DEPTH,(const char **)val,
-                                &data));
-      if (!data || strcmp((char*)data,val[0])) {
-       fprintf(stderr,"Retrieved value (%s) does not match the entrered one (%s)\n",
-               (char*)data,val[0]);
-       abort();
+      if (verbose) printf ("  Add {");
+      
+      for (l=0 ; l<DEPTH ; l++) {
+        key=xbt_malloc(KEY_SIZE);
+        
+       for (k=0;k<KEY_SIZE-1;k++) 
+         key[k]=rand() % ('z' - 'a') + 'a';
+         
+       key[k]='\0';
+       
+       if (verbose) printf("%p=%s %s ",key, key,(l<DEPTH-1?";":"}"));
+       xbt_dynar_push(keys,&key);
       }
       }
-    }
-    xbt_dict_dump(head,&xbt_dict_print);
-    xbt_dict_free(&head);
+      if (verbose) printf("in multitree %p.\n",mdict);
+                                                        
+      TRYFAIL(xbt_multidict_set(mdict,keys,xbt_strdup(key),&str_free));
 
 
-    for (l=0 ; l<MULTICACHE_DEPTH ; l++)
-      if (val[l]) free(val[l]);
-    free(val);
-    free(key);
+      TRYFAIL(xbt_multidict_get(mdict,keys,&data));
 
 
+      xbt_assert2(data && !strcmp((char*)data,key),
+                 "Retrieved value (%s) does not match the entrered one (%s)\n",
+                 (char*)data,key);
+    }
   }
 
   }
 
+/*  if (verbose)
+    xbt_dict_dump(mdict,&xbt_dict_print);*/
+    
+  xbt_dict_free(&mdict);
+  xbt_dynar_free(&keys);
   printf("\n");
   printf("\n");
-  return no_error;
-}
-
-int main(int argc, char *argv[]) {
-  xbt_error_t errcode;
 
 
-  xbt_init(argc,argv,"root.thresh=debug"));
-  TRYFAIL(test1());
-   
   xbt_exit();
   return 0;
 }
   xbt_exit();
   return 0;
 }