Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mc/compare: kill dead code
[simgrid.git] / src / mc / compare.cpp
index d91e7fc..aad1013 100644 (file)
@@ -268,7 +268,7 @@ int StateComparator::initHeapInformation(xbt_mheap_t heap1, xbt_mheap_t heap2,
 }
 
 // TODO, have a robust way to find it in O(1)
-static inline RegionSnapshot* MC_get_heap_region(Snapshot* snapshot)
+static inline Region* MC_get_heap_region(Snapshot* snapshot)
 {
   for (auto const& region : snapshot->snapshot_regions_)
     if (region->region_type() == simgrid::mc::RegionType::Heap)
@@ -294,8 +294,8 @@ int mmalloc_compare_heap(
   malloc_info heapinfo_temp2;
   malloc_info heapinfo_temp2b;
 
-  simgrid::mc::RegionSnapshot* heap_region1 = MC_get_heap_region(snapshot1);
-  simgrid::mc::RegionSnapshot* heap_region2 = MC_get_heap_region(snapshot2);
+  simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
+  simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
 
   // This is the address of std_heap->heapinfo in the application process:
   void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo;
@@ -308,8 +308,10 @@ int mmalloc_compare_heap(
 
   while (i1 < state.heaplimit) {
 
-    const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
-    const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
+    const malloc_info* heapinfo1 =
+        (const malloc_info*)heap_region1->read(&heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info));
+    const malloc_info* heapinfo2 =
+        (const malloc_info*)heap_region2->read(&heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info));
 
     if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) {      /* Free block */
       i1 ++;
@@ -365,7 +367,8 @@ int mmalloc_compare_heap(
           continue;
         }
 
-        const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
+        const malloc_info* heapinfo2b =
+            (const malloc_info*)heap_region2->read(&heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
 
         if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) {
           i2++;
@@ -423,9 +426,8 @@ int mmalloc_compare_heap(
 
         while (i2 < state.heaplimit && not equal) {
 
-          const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(
-            heap_region2, &heapinfo_temp2b, &heapinfos2[i2],
-            sizeof(malloc_info));
+          const malloc_info* heapinfo2b =
+              (const malloc_info*)heap_region2->read(&heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info));
 
           if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) {
             i2 ++;
@@ -480,8 +482,8 @@ int mmalloc_compare_heap(
 
   /* All blocks/fragments are equal to another block/fragment_ ? */
   for (size_t i = 1; i < state.heaplimit; i++) {
-    const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
-      heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
+    const malloc_info* heapinfo1 =
+        (const malloc_info*)heap_region1->read(&heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
 
     if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo1->busy_block.busy_size > 0 &&
         not state.equals_to1_(i, 0).valid_) {
@@ -502,8 +504,8 @@ int mmalloc_compare_heap(
     XBT_DEBUG("Number of blocks/fragments not found in heap1: %d", nb_diff1);
 
   for (size_t i = 1; i < state.heaplimit; i++) {
-    const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
-      heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
+    const malloc_info* heapinfo2 =
+        (const malloc_info*)heap_region2->read(&heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info));
     if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo2->busy_block.busy_size > 0 &&
         not state.equals_to2_(i, 0).valid_) {
       XBT_DEBUG("Block %zu not found (size used = %zu)", i,
@@ -546,8 +548,8 @@ static int compare_heap_area_without_type(simgrid::mc::StateComparator& state, c
                                           int check_ignore)
 {
   simgrid::mc::RemoteClient* process = &mc_model_checker->process();
-  simgrid::mc::RegionSnapshot* heap_region1 = MC_get_heap_region(snapshot1);
-  simgrid::mc::RegionSnapshot* heap_region2 = MC_get_heap_region(snapshot2);
+  simgrid::mc::Region* heap_region1  = MC_get_heap_region(snapshot1);
+  simgrid::mc::Region* heap_region2  = MC_get_heap_region(snapshot2);
 
   for (int i = 0; i < size; ) {
 
@@ -649,8 +651,8 @@ static int compare_heap_area_with_type(simgrid::mc::StateComparator& state, cons
     const void* addr_pointed1;
     const void* addr_pointed2;
 
-    simgrid::mc::RegionSnapshot* heap_region1 = MC_get_heap_region(snapshot1);
-    simgrid::mc::RegionSnapshot* heap_region2 = MC_get_heap_region(snapshot2);
+    simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
+    simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
 
     switch (type->type) {
       case DW_TAG_unspecified_type:
@@ -935,13 +937,13 @@ static int compare_heap_area(simgrid::mc::StateComparator& state, const void* ar
 
   }
 
-  simgrid::mc::RegionSnapshot* heap_region1 = MC_get_heap_region(snapshot1);
-  simgrid::mc::RegionSnapshot* heap_region2 = MC_get_heap_region(snapshot2);
+  simgrid::mc::Region* heap_region1 = MC_get_heap_region(snapshot1);
+  simgrid::mc::Region* heap_region2 = MC_get_heap_region(snapshot2);
 
-  const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(
-    heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
-  const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(
-    heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
+  const malloc_info* heapinfo1 =
+      (const malloc_info*)heap_region1->read(&heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info));
+  const malloc_info* heapinfo2 =
+      (const malloc_info*)heap_region2->read(&heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info));
 
   if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO)
     && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) {
@@ -1148,9 +1150,9 @@ static int compare_heap_area(simgrid::mc::StateComparator& state, const void* ar
 /******************************************************************************/
 
 static int compare_areas_with_type(simgrid::mc::StateComparator& state, void* real_area1,
-                                   simgrid::mc::Snapshot* snapshot1, simgrid::mc::RegionSnapshot* region1,
-                                   void* real_area2, simgrid::mc::Snapshot* snapshot2,
-                                   simgrid::mc::RegionSnapshot* region2, simgrid::mc::Type* type, int pointer_level)
+                                   simgrid::mc::Snapshot* snapshot1, simgrid::mc::Region* region1, void* real_area2,
+                                   simgrid::mc::Snapshot* snapshot2, simgrid::mc::Region* region2,
+                                   simgrid::mc::Type* type, int pointer_level)
 {
   simgrid::mc::RemoteClient* process = &mc_model_checker->process();
 
@@ -1264,8 +1266,8 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state, void* re
         for (simgrid::mc::Member& member : type->members) {
           void* member1 = simgrid::dwarf::resolve_member(real_area1, type, &member, snapshot1);
           void* member2 = simgrid::dwarf::resolve_member(real_area2, type, &member, snapshot2);
-          simgrid::mc::RegionSnapshot* subregion1 = snapshot1->get_region(member1, region1); // region1 is hinted
-          simgrid::mc::RegionSnapshot* subregion2 = snapshot2->get_region(member2, region2); // region2 is hinted
+          simgrid::mc::Region* subregion1 = snapshot1->get_region(member1, region1); // region1 is hinted
+          simgrid::mc::Region* subregion2 = snapshot2->get_region(member2, region2); // region2 is hinted
           res = compare_areas_with_type(state, member1, snapshot1, subregion1, member2, snapshot2, subregion2,
                                         member.type, pointer_level);
           if (res == 1)
@@ -1284,8 +1286,8 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state, void* re
 }
 
 static int compare_global_variables(simgrid::mc::StateComparator& state, simgrid::mc::ObjectInformation* object_info,
-                                    simgrid::mc::RegionSnapshot* r1, simgrid::mc::RegionSnapshot* r2,
-                                    simgrid::mc::Snapshot* snapshot1, simgrid::mc::Snapshot* snapshot2)
+                                    simgrid::mc::Region* r1, simgrid::mc::Region* r2, simgrid::mc::Snapshot* snapshot1,
+                                    simgrid::mc::Snapshot* snapshot2)
 {
   xbt_assert(r1 && r2, "Missing region.");
 
@@ -1380,17 +1382,11 @@ int snapshot_compare(Snapshot* s1, Snapshot* s2)
 
   RemoteClient* process = &mc_model_checker->process();
 
-  int errors = 0;
-
-  int hash_result = 0;
   if (_sg_mc_hash) {
-    hash_result = (s1->hash_ != s2->hash_);
-    if (hash_result) {
+    if (s1->hash_ != s2->hash_) {
       XBT_VERB("(%d - %d) Different hash: 0x%" PRIx64 "--0x%" PRIx64, s1->num_state_, s2->num_state_, s1->hash_,
                s2->hash_);
-#ifndef MC_DEBUG
       return 1;
-#endif
     } else
       XBT_VERB("(%d - %d) Same hash: 0x%" PRIx64, s1->num_state_, s2->num_state_, s1->hash_);
   }
@@ -1407,18 +1403,9 @@ int snapshot_compare(Snapshot* s1, Snapshot* s2)
     size_t size_used1 = s1->stack_sizes_[i];
     size_t size_used2 = s2->stack_sizes_[i];
     if (size_used1 != size_used2) {
-#ifdef MC_DEBUG
-      XBT_DEBUG("(%d - %d) Different size used in stacks: %zu - %zu", s1->num_state, s2->num_state, size_used1,
-                size_used2);
-      errors++;
-      is_diff = 1;
-#else
-#ifdef MC_VERBOSE
       XBT_VERB("(%d - %d) Different size used in stacks: %zu - %zu", s1->num_state_, s2->num_state_, size_used1,
                size_used2);
-#endif
       return 1;
-#endif
     }
   }
   if (is_diff) // do not proceed if there is any stacks that don't match
@@ -1432,16 +1419,8 @@ int snapshot_compare(Snapshot* s1, Snapshot* s2)
   int res_init = state_comparator->initHeapInformation(heap1, heap2, &s1->to_ignore_, &s2->to_ignore_);
 
   if (res_init == -1) {
-#ifdef MC_DEBUG
-    XBT_DEBUG("(%d - %d) Different heap information", num1, nus1->num_state, s2->num_statem2);
-    errors++;
-#else
-#ifdef MC_VERBOSE
     XBT_VERB("(%d - %d) Different heap information", s1->num_state_, s2->num_state_);
-#endif
-
     return 1;
-#endif
   }
 
   /* Stacks comparison */
@@ -1451,18 +1430,8 @@ int snapshot_compare(Snapshot* s1, Snapshot* s2)
     mc_snapshot_stack_t stack2 = &s2->stacks_[cursor];
 
     if (compare_local_variables(*state_comparator, s1, s2, stack1, stack2) > 0) {
-#ifdef MC_DEBUG
-      XBT_DEBUG("(%d - %d) Different local variables between stacks %d", num1,
-                num2, cursor + 1);
-      errors++;
-#else
-
-#ifdef MC_VERBOSE
       XBT_VERB("(%d - %d) Different local variables between stacks %u", s1->num_state_, s2->num_state_, cursor + 1);
-#endif
-
       return 1;
-#endif
     }
   }
 
@@ -1471,8 +1440,8 @@ int snapshot_compare(Snapshot* s1, Snapshot* s2)
   xbt_assert(regions_count == s2->snapshot_regions_.size());
 
   for (size_t k = 0; k != regions_count; ++k) {
-    RegionSnapshot* region1 = s1->snapshot_regions_[k].get();
-    RegionSnapshot* region2 = s2->snapshot_regions_[k].get();
+    Region* region1 = s1->snapshot_regions_[k].get();
+    Region* region2 = s2->snapshot_regions_[k].get();
 
     // Preconditions:
     if (region1->region_type() != RegionType::Data)
@@ -1484,55 +1453,21 @@ int snapshot_compare(Snapshot* s1, Snapshot* s2)
 
     /* Compare global variables */
     if (compare_global_variables(*state_comparator, region1->object_info(), region1, region2, s1, s2)) {
-
-#ifdef MC_DEBUG
-      std::string const& name = region1->object_info()->file_name;
-      XBT_DEBUG("(%d - %d) Different global variables in %s", s1->num_state, s2->num_state, name.c_str());
-      errors++;
-#else
-#ifdef MC_VERBOSE
       std::string const& name = region1->object_info()->file_name;
       XBT_VERB("(%d - %d) Different global variables in %s", s1->num_state_, s2->num_state_, name.c_str());
-#endif
-
       return 1;
-#endif
     }
   }
 
   /* Compare heap */
   if (mmalloc_compare_heap(*state_comparator, s1, s2) > 0) {
-
-#ifdef MC_DEBUG
-    XBT_DEBUG("(%d - %d) Different heap (mmalloc_compare)", s1->num_state, s2->num_state);
-    errors++;
-#else
-
-#ifdef MC_VERBOSE
     XBT_VERB("(%d - %d) Different heap (mmalloc_compare)", s1->num_state_, s2->num_state_);
-#endif
     return 1;
-#endif
   }
 
-#ifdef MC_VERBOSE
-  if (errors || hash_result)
-    XBT_VERB("(%d - %d) Difference found", s1->num_state_, s2->num_state_);
-  else
     XBT_VERB("(%d - %d) No difference found", s1->num_state_, s2->num_state_);
-#endif
-
-#if defined(MC_DEBUG) && defined(MC_VERBOSE)
-  if (_sg_mc_hash) {
-    // * false positive SHOULD be avoided.
-    // * There MUST not be any false negative.
 
-    XBT_VERB("(%d - %d) State equality hash test is %s %s", s1->num_state, s2->num_state,
-             (hash_result != 0) == (errors != 0) ? "true" : "false", not hash_result ? "positive" : "negative");
-  }
-#endif
-
-  return errors > 0 || hash_result;
+    return 0;
 }
 
 }