Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot//simgrid/simgrid
authorMarion Guthmuller <marion.guthmuller@loria.fr>
Wed, 13 Jun 2012 13:33:05 +0000 (15:33 +0200)
committerMarion Guthmuller <marion.guthmuller@loria.fr>
Wed, 13 Jun 2012 13:33:05 +0000 (15:33 +0200)
include/xbt/mmalloc.h
src/mc/mc_liveness.c
src/mc/mc_private.h
src/xbt/mmalloc/mm_diff.c
src/xbt/mmalloc/mmprivate.h

index b530468..93ba1f5 100644 (file)
@@ -58,7 +58,7 @@ extern void mmalloc_display_info_heap(xbt_mheap_t h);
 void mmalloc_set_current_heap(xbt_mheap_t new_heap);
 xbt_mheap_t mmalloc_get_current_heap(void);
 
-int mmalloc_compare_heap(xbt_mheap_t mdp1, xbt_mheap_t mdp2, void* s_heap, void* r_heap);
+int mmalloc_compare_heap(xbt_mheap_t mdp1, xbt_mheap_t mdp2);
 
 void mmalloc_backtrace_display(xbt_mheap_t mdp, void *addr);
 
index 14e31b8..66e290f 100644 (file)
@@ -33,132 +33,39 @@ unsigned int hash_region(char *str, int str_len){
 
 }
 
-const char* get_memory_map_addr(void *addr){
-
-  FILE *fp;                     /* File pointer to process's proc maps file */
-  char *line = NULL;            /* Temporal storage for each line that is readed */
-  ssize_t read;                 /* Number of bytes readed */
-  size_t n = 0;                 /* Amount of bytes to read by getline */
-
-  fp = fopen("/proc/self/maps", "r");
-  
-  if(fp == NULL)
-    perror("fopen failed");
-
-  if(addr == NULL){
-    free(line);
-    fclose(fp);
-    return "nil";
-  }
-
-  xbt_dynar_t lfields = NULL;
-  xbt_dynar_t start_end  = NULL;
-  void *start_addr;
-  void *end_addr;
-
-  while ((read = getline(&line, &n, fp)) != -1) {
-
-    xbt_str_trim(line, NULL);
-    xbt_str_strip_spaces(line);
-    lfields = xbt_str_split(line,NULL);
-
-    start_end = xbt_str_split(xbt_dynar_get_as(lfields, 0, char*), "-");
-    start_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 0, char*), NULL, 16);
-    end_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 1, char*), NULL, 16);
-
-    if((addr > start_addr) && ( addr < end_addr)){
-      free(line);
-      fclose(fp);
-      if(start_addr == std_heap){
-       xbt_dynar_reset(lfields);
-       xbt_free(lfields);
-       xbt_dynar_reset(start_end);
-       xbt_free(start_end);
-       return "std_heap";
-      }
-      if(start_addr == raw_heap){
-       xbt_dynar_reset(lfields);
-       xbt_free(lfields);
-       xbt_dynar_reset(start_end);
-       xbt_free(start_end);
-       return "raw_heap";
-      }
-      if(xbt_dynar_length(lfields) == 6){
-       return xbt_dynar_get_as(lfields, xbt_dynar_length(lfields) - 1, char*);
-      }else{
-       xbt_dynar_reset(lfields);
-       xbt_free(lfields);
-       xbt_dynar_reset(start_end);
-       xbt_free(start_end);
-       return "Anonymous";
-      }
-    }
-
-  }
-
-  xbt_dynar_reset(lfields);
-  xbt_free(lfields);
-  xbt_dynar_reset(start_end);
-  xbt_free(start_end);
-  free(line);
-  fclose(fp);
-  return "Unknown area";
-
-}
-
 int data_program_region_compare(void *d1, void *d2, size_t size){
   int distance = 0;
-  int pointer_align;
   int i;
-  char *pointed_address1 = NULL, *pointed_address2 = NULL;
   
   for(i=0; i<size; i++){
     if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
       fprintf(stderr,"Different byte (offset=%d) (%p - %p) in data program region\n", i, (char *)d1 + i, (char *)d2 + i);
       distance++;
-      pointer_align = (i /sizeof(void *)) * sizeof(void *);
-      pointed_address1 = strdup(get_memory_map_addr(*((void **)((char *)d1 + pointer_align))));
-      pointed_address2 = strdup(get_memory_map_addr(*((void **)((char *)d2 + pointer_align))));
-      fprintf(stderr, "Pointed address : %p (in %s) - %p (in %s)\n", *((void **)((char *)d1 + pointer_align)), pointed_address1, *((void **)((char *)d2 + pointer_align)), pointed_address2);
-      /* FIXME : compare values in pointed address thanks to DWARF */
     }
   }
   
   fprintf(stderr, "Hamming distance between data program regions : %d\n", distance);
 
-  free(pointed_address1);
-  free(pointed_address2);
-
   return distance;
 }
 
 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size){
   int distance = 0;
-  int pointer_align;
   int i;
-  char *pointed_address1 = NULL, *pointed_address2 = NULL;
   
   for(i=0; i<size; i++){
     if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
       fprintf(stderr, "Different byte (offset=%d) (%p - %p) in data libsimgrid region\n", i, (char *)d1 + i, (char *)d2 + i);
       distance++;
-      pointer_align = (i /sizeof(void *)) * sizeof(void *);
-      pointed_address1 = strdup(get_memory_map_addr(*((void **)((char *)d1 + pointer_align))));
-      pointed_address2 = strdup(get_memory_map_addr(*((void **)((char *)d2 + pointer_align))));
-      fprintf(stderr, "Pointed address : %p (in %s) - %p (in %s)\n", *((void **)((char *)d1 + pointer_align)), pointed_address1, *((void **)((char *)d2 + pointer_align)), pointed_address2);
-      /* FIXME : compare values in pointed address thanks to DWARF */
     }
   }
   
   fprintf(stderr, "Hamming distance between data libsimgrid regions : %d\n", distance);
-
-  free(pointed_address1);
-  free(pointed_address2);
   
   return distance;
 }
 
-int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, void* s_heap, void* r_heap){
+int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
 
   
   if(s1->num_reg != s2->num_reg){
@@ -186,7 +93,7 @@ int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, void* s_heap, void* r_h
        XBT_INFO("Different start addr of heap (s1 = %p, s2 = %p)", s1->regions[i]->start_addr, s2->regions[i]->start_addr);
        errors++;
       }
-      if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data, s_heap, r_heap)){
+      if(mmalloc_compare_heap(s1->regions[i]->data, s2->regions[i]->data)){
        XBT_INFO("Different heap (mmalloc_compare)");
        errors++; 
       }
@@ -267,7 +174,7 @@ int reached(xbt_state_t st){
          //XBT_INFO("Rdv points size %d - %d", xbt_dict_length(pair_test->rdv_points), xbt_dict_length(current_rdv_points));
          //if(xbt_dict_length(pair_test->rdv_points) == xbt_dict_length(current_rdv_points)){
          //if(rdv_points_compare(pair_test->rdv_points, current_rdv_points) == 0){
-         if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
+         if(snapshot_compare(pair_test->system_state, sn) == 0){
           
            MC_free_snapshot(sn);
            xbt_dynar_reset(prop_ato);
@@ -666,7 +573,7 @@ int visited(xbt_state_t st, int sc){
       if(pair_test->search_cycle == sc) {
        if(automaton_state_compare(pair_test->automaton_state, st) == 0){
          if(propositional_symbols_compare_value(pair_test->prop_ato, prop_ato) == 0){
-           if(snapshot_compare(pair_test->system_state, sn, std_heap, raw_heap) == 0){
+           if(snapshot_compare(pair_test->system_state, sn) == 0){
            
              MC_free_snapshot(sn);
              xbt_dynar_reset(prop_ato);
@@ -1373,3 +1280,60 @@ void MC_ddfs(int search_cycle){
   
 
 }
+
+
+#ifdef SIMGRID_TEST
+
+XBT_TEST_SUITE("mc_liveness", "Model checking liveness properties");
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(mc_liveness);
+
+XBT_TEST_UNIT("snapshots_comparison", test_compare_snapshot, "Comparison of snapshots")
+{
+
+  MC_SET_RAW_MEM;
+
+  /* Save first snapshot */
+  mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
+  MC_take_snapshot_liveness(snapshot1);
+
+  /* Save second snapshot */
+  mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
+  MC_take_snapshot_liveness(snapshot2);
+
+  MC_UNSET_RAW_MEM;
+
+  xbt_test_assert(snapshot_compare(snapshot1, snapshot2) == 0, "Different consecutive snapshot");
+  
+
+}
+
+XBT_TEST_UNIT("snapshots_comparison2", test2_compare_snapshot, "Comparison of snapshots with modification between")
+{
+
+  MC_SET_RAW_MEM;
+
+  /* Save first snapshot */
+  mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
+  MC_take_snapshot_liveness(snapshot1);
+
+  MC_UNSET_RAW_MEM;
+
+  void *test = snapshot1;
+  test = (char*)test+1;
+  char* t= strdup("toto");
+  t=strdup("tat");
+
+  MC_SET_RAW_MEM;
+
+  /* Save second snapshot */
+  mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
+  MC_take_snapshot_liveness(snapshot2);
+
+  MC_UNSET_RAW_MEM;
+
+  xbt_test_assert(snapshot_compare(snapshot1, snapshot2) != 0, "Same snapshot with new allocations");
+  
+
+}
+
+#endif
index 1d24b20..a64ca64 100644 (file)
@@ -253,7 +253,7 @@ int reached(xbt_state_t st);
 void set_pair_reached(xbt_state_t st);
 int reached_hash(xbt_state_t st);
 void set_pair_reached_hash(xbt_state_t st);
-int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2, void* s_heap, void* r_heap);
+int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2);
 int data_program_region_compare(void *d1, void *d2, size_t size);
 int data_libsimgrid_region_compare(void *d1, void *d2, size_t size);
 void MC_pair_delete(mc_pair_t pair);
@@ -266,8 +266,6 @@ void set_pair_visited_hash(xbt_state_t st, int search_cycle);
 unsigned int hash_region(char *str, int str_len);
 int rdv_points_compare(xbt_dict_t d1, xbt_dict_t d2);
 
-const char* get_memory_map_addr(void *addr);
-
 /* **** Double-DFS stateless **** */
 
 typedef struct s_mc_pair_stateless{
index c7e56c1..6e54a5d 100644 (file)
@@ -112,20 +112,20 @@ void mmalloc_backtrace_fragment_display(xbt_mheap_t mdp, size_t block, size_t fr
   }
 }
 
-int mmalloc_compare_heap(xbt_mheap_t mdp1, xbt_mheap_t mdp2, void* s_heap, void* r_heap){
+int mmalloc_compare_heap(xbt_mheap_t mdp1, xbt_mheap_t mdp2){
 
   if(mdp1 == NULL && mdp2 == NULL){
     fprintf(stderr, "Malloc descriptors null\n");
     return 0;
   }
 
-  int errors = mmalloc_compare_mdesc(mdp1, mdp2, s_heap, r_heap);
+  int errors = mmalloc_compare_mdesc(mdp1, mdp2);
 
   return (errors > 0);
 
 }
 
-int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap, void* r_heap){
+int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){
 
   int errors = 0;
 
@@ -196,6 +196,8 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
 
   //void* heapbase1 = (char *)mdp1 + ((char *)mdp1->heapbase - (char *)s_heap);
   //void* heapbase2 = (char *)mdp2 + ((char *)mdp2->heapbase - (char *)s_heap);
+
+  xbt_mheap_t s_heap = mmalloc_get_current_heap();
     
   void *heapbase1 = (char *)mdp1 + BLOCKSIZE;
   void *heapbase2 = (char *)mdp2 + BLOCKSIZE;
@@ -209,6 +211,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
 
   int k;
   int distance = 0;
+  int total_distance = 0;
 
   void *end_heap = get_end_addr_heap(s_heap);
 
@@ -263,7 +266,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
          pointer_align = (k / sizeof(void*)) * sizeof(void*); 
          address_pointed1 = *((void **)((char *)addr_block1 + pointer_align));
          address_pointed2 = *((void **)((char *)addr_block2 + pointer_align));                            
-         if(((address_pointed1 > s_heap) && (address_pointed1 < end_heap)) && ((address_pointed2 > s_heap) && (address_pointed2 < end_heap))){
+         if(((address_pointed1 > (void *)s_heap) && (address_pointed1 < end_heap)) && ((address_pointed2 > (void *)s_heap) && (address_pointed2 < end_heap))){
            block_pointed1 = ((char*)address_pointed1 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
            block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
            //fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2);
@@ -334,6 +337,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
        mmalloc_backtrace_block_display(mdp1, i);
        mmalloc_backtrace_block_display(mdp2, i);
        errors++; 
+       total_distance += distance;
       }
     
       
@@ -384,7 +388,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
                pointer_align = (k / sizeof(void*)) * sizeof(void*);
                address_pointed1 = *((void **)((char *)addr_frag1 + pointer_align));
                address_pointed2 = *((void **)((char *)addr_frag2 + pointer_align));                               
-               if(((address_pointed1 > s_heap) && (address_pointed1 < end_heap)) && ((address_pointed2 > s_heap) && (address_pointed2 < end_heap))){
+               if(((address_pointed1 > (void *)s_heap) && (address_pointed1 < end_heap)) && ((address_pointed2 > (void *)s_heap) && (address_pointed2 < end_heap))){
                  block_pointed1 = ((char*)address_pointed1 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
                  block_pointed2 = ((char*)address_pointed2 - (char*)((struct mdesc*)s_heap)->heapbase) / BLOCKSIZE + 1;
                  //fprintf(stderr, "Blocks pointed : %d - %d\n", block_pointed1, block_pointed2);
@@ -450,6 +454,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
              mmalloc_backtrace_fragment_display(mdp1, i, j);
              mmalloc_backtrace_fragment_display(mdp2, i, j);
              errors++;
+             total_distance += distance;
              
            }
 
@@ -473,11 +478,13 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
   //free(pointed_address1);
   //free(pointed_address2);
 
+  fprintf(stderr, "Hamming distance between heap regions : %d\n", total_distance);
+
   return (errors);
 }
 
 
-void *get_end_addr_heap(void *s_heap){
+void *get_end_addr_heap(void *heap){
 
   FILE *fp;                     /* File pointer to process's proc maps file */
   char *line = NULL;            /* Temporal storage for each line that is readed */
@@ -505,7 +512,7 @@ void *get_end_addr_heap(void *s_heap){
     start_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 0, char*), NULL, 16);
     end_addr = (void *) strtoul(xbt_dynar_get_as(start_end, 1, char*), NULL, 16);
 
-    if(start_addr == s_heap){
+    if(start_addr == heap){
       free(line);
       fclose(fp);
       xbt_dynar_reset(lfields);
index 45d1a78..1e2d6aa 100644 (file)
@@ -224,7 +224,7 @@ struct mdesc {
 
 };
 
-int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap, void* r_heap);
+int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2);
 
 void mmalloc_display_info(void *h);