Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
codacy
[simgrid.git] / src / mc / compare.cpp
index cdf9d1b..e5a873b 100644 (file)
@@ -13,8 +13,8 @@
 #include <utility>
 #include <unordered_set>
 
-#include <xbt/sysdep.h>
-#include <xbt/dynar.h>
+#include "xbt/dynar.h"
+#include "xbt/sysdep.h"
 #include <xbt/mmalloc.h>
 
 #include <mc/mc.h>
 
 #if HAVE_SMPI
 #include "src/smpi/private.h"
+#include "src/smpi/private.hpp"
 #endif
 
 #include "src/mc/mc_forward.hpp"
-#include "src/mc/mc_safety.h"
 #include "src/mc/mc_private.h"
 #include "src/mc/mc_smx.h"
 #include "src/mc/mc_dwarf.hpp"
@@ -114,8 +114,7 @@ struct ProcessComparisonState {
   std::vector<simgrid::mc::Type*> types;
   std::size_t heapsize = 0;
 
-  void initHeapInformation(xbt_mheap_t heap,
-                          std::vector<simgrid::mc::IgnoredHeapRegion>* i);
+  void initHeapInformation(xbt_mheap_t heap, std::vector<simgrid::mc::IgnoredHeapRegion>* i);
 };
 
 namespace {
@@ -320,17 +319,22 @@ int mmalloc_compare_heap(
   simgrid::mc::Process* process = &mc_model_checker->process();
 
   /* Start comparison */
+  size_t i1;
+  size_t i2;
   size_t j1;
   size_t j2;
   size_t k;
+  void* addr_block1;
   void* addr_block2;
   void* addr_frag1;
   void* addr_frag2;
   int nb_diff1 = 0;
   int nb_diff2 = 0;
+  int equal;
+  int res_compare = 0;
 
   /* Check busy blocks */
-  size_t i1 = 1;
+  i1 = 1;
 
   malloc_info heapinfo_temp1;
   malloc_info heapinfo_temp2;
@@ -363,7 +367,7 @@ int mmalloc_compare_heap(
       abort();
     }
 
-    void* addr_block1 = ((void*)(((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase));
+    addr_block1 = ((void*)(((ADDR2UINT(i1)) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase));
 
     if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) {       /* Large block */
 
@@ -381,9 +385,9 @@ int mmalloc_compare_heap(
         continue;
       }
 
-      size_t i2       = 1;
-      int equal       = 0;
-      int res_compare = 0;
+      i2          = 1;
+      equal       = 0;
+      res_compare = 0;
 
       /* Try first to associate to same block in the other heap */
       if (heapinfo2->type == heapinfo1->type
@@ -401,7 +405,7 @@ int mmalloc_compare_heap(
         }
       }
 
-      while (i2 < state.heaplimit && !equal) {
+      while (i2 < state.heaplimit && not equal) {
 
         addr_block2 = (ADDR2UINT(i2) - 1) * BLOCKSIZE + (char*)state.std_heap_copy.heapbase;
 
@@ -438,7 +442,7 @@ int mmalloc_compare_heap(
         i2++;
       }
 
-      if (!equal) {
+      if (not equal) {
         XBT_DEBUG("Block %zu not found (size_used = %zu, addr = %p)", i1, heapinfo1->busy_block.busy_size, addr_block1);
         i1 = state.heaplimit + 1;
         nb_diff1++;
@@ -461,8 +465,7 @@ int mmalloc_compare_heap(
         equal = 0;
 
         /* Try first to associate to same fragment in the other heap */
-        if (heapinfo2->type == heapinfo1->type
-            && !state.equals_to2_(i1, j1).valid) {
+        if (heapinfo2->type == heapinfo1->type && not state.equals_to2_(i1, j1).valid) {
           addr_block2 = (ADDR2UINT(i1) - 1) * BLOCKSIZE +
                          (char *) state.std_heap_copy.heapbase;
           addr_frag2 =
@@ -474,7 +477,7 @@ int mmalloc_compare_heap(
             equal = 1;
         }
 
-        while (i2 < state.heaplimit && !equal) {
+        while (i2 < state.heaplimit && not equal) {
 
           const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(
             heap_region2, &heapinfo_temp2b, &heapinfos2[i2],
@@ -519,7 +522,7 @@ int mmalloc_compare_heap(
           i2++;
         }
 
-        if (!equal) {
+        if (not equal) {
           XBT_DEBUG("Block %zu, fragment %zu not found (size_used = %zd, address = %p)\n", i1, j1,
                     heapinfo1->busy_frag.frag_size[j1], addr_frag1);
           i2 = state.heaplimit + 1;
@@ -542,7 +545,7 @@ int mmalloc_compare_heap(
       heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info));
 
     if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED && i1 == state.heaplimit && heapinfo1->busy_block.busy_size > 0 &&
-        !state.equals_to1_(i, 0).valid) {
+        not state.equals_to1_(i, 0).valid) {
       XBT_DEBUG("Block %zu not found (size used = %zu)", i, heapinfo1->busy_block.busy_size);
       nb_diff1++;
     }
@@ -550,7 +553,7 @@ int mmalloc_compare_heap(
     if (heapinfo1->type <= 0)
       continue;
     for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo1->type); j++)
-      if (i1 == state.heaplimit && heapinfo1->busy_frag.frag_size[j] > 0 && !state.equals_to1_(i, j).valid) {
+      if (i1 == state.heaplimit && heapinfo1->busy_frag.frag_size[j] > 0 && not state.equals_to1_(i, j).valid) {
         XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)", i, j, heapinfo1->busy_frag.frag_size[j]);
         nb_diff1++;
       }
@@ -562,10 +565,8 @@ int mmalloc_compare_heap(
   for (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));
-    if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED
-        && i1 == state.heaplimit
-        && heapinfo2->busy_block.busy_size > 0
-        && !state.equals_to2_(i, 0).valid) {
+    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,
                 heapinfo2->busy_block.busy_size);
       nb_diff2++;
@@ -575,9 +576,7 @@ int mmalloc_compare_heap(
       continue;
 
     for (j = 0; j < (size_t) (BLOCKSIZE >> heapinfo2->type); j++)
-      if (i1 == state.heaplimit
-          && heapinfo2->busy_frag.frag_size[j] > 0
-          && !state.equals_to2_(i, j).valid) {
+      if (i1 == state.heaplimit && heapinfo2->busy_frag.frag_size[j] > 0 && not state.equals_to2_(i, j).valid) {
         XBT_DEBUG("Block %zu, Fragment %zu not found (size used = %zd)",
           i, j, heapinfo2->busy_frag.frag_size[j]);
         nb_diff2++;
@@ -733,7 +732,7 @@ top:
     return 1;
 
   case DW_TAG_base_type:
-    if (!type->name.empty() && type->name == "char") {        /* String, hence random (arbitrary ?) size */
+    if (not type->name.empty() && type->name == "char") { /* String, hence random (arbitrary ?) size */
       if (real_area1 == real_area2)
         return -1;
       else
@@ -1038,7 +1037,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index,
 
     // Find type_size:
     if (type->type == DW_TAG_pointer_type ||
-        (type->type == DW_TAG_base_type && !type->name.empty() && type->name == "char"))
+        (type->type == DW_TAG_base_type && not type->name.empty() && type->name == "char"))
       type_size = -1;
     else
       type_size = type->byte_size;
@@ -1090,7 +1089,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index,
     if (heapinfo1->busy_block.busy_size != heapinfo2->busy_block.busy_size)
       return 1;
 
-    if (!previous->insert(simgrid::mc::makeHeapLocationPair(block1, -1, block2, -1)).second) {
+    if (not previous->insert(simgrid::mc::makeHeapLocationPair(block1, -1, block2, -1)).second) {
       if (match_pairs)
         state.match_equals(previous);
       return 0;
@@ -1229,7 +1228,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index,
     }
 
     if (offset1 == 0 && offset2 == 0 &&
-        !previous->insert(simgrid::mc::makeHeapLocationPair(block1, frag1, block2, frag2)).second) {
+        not previous->insert(simgrid::mc::makeHeapLocationPair(block1, frag1, block2, frag2)).second) {
       if (match_pairs)
         state.match_equals(previous);
       return 0;
@@ -1353,8 +1352,7 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state,
       return 0;
     if (addr_pointed1 == nullptr || addr_pointed2 == nullptr)
       return 1;
-    if (!state.compared_pointers.insert(
-        std::make_pair(addr_pointed1, addr_pointed2)).second)
+    if (not state.compared_pointers.insert(std::make_pair(addr_pointed1, addr_pointed2)).second)
       return 0;
 
     pointer_level++;
@@ -1366,9 +1364,7 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state,
 
       if (addr_pointed1 > process->heap_address
           && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)) {
-        if (!
-            (addr_pointed2 > process->heap_address
-             && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)))
+        if (not(addr_pointed2 > process->heap_address && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)))
           return 1;
         // The pointers are both in the heap:
         return simgrid::mc::compare_heap_area(state,
@@ -1378,9 +1374,9 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state,
 
       // The pointers are both in the current object R/W segment:
       else if (region1->contain(simgrid::mc::remote(addr_pointed1))) {
-        if (!region2->contain(simgrid::mc::remote(addr_pointed2)))
+        if (not region2->contain(simgrid::mc::remote(addr_pointed2)))
           return 1;
-        if (!type->type_id)
+        if (not type->type_id)
           return (addr_pointed1 != addr_pointed2);
         else
           return compare_areas_with_type(state, process_index,
@@ -1646,7 +1642,6 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc:
       XBT_DEBUG("(%d - %d) Different local variables between stacks %d", num1,
                 num2, cursor + 1);
       errors++;
-      is_diff = 1;
 #else
 
 #ifdef MC_VERBOSE
@@ -1724,8 +1719,7 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc:
     // * There MUST not be any false negative.
 
     XBT_VERB("(%d - %d) State equality hash test is %s %s", num1, num2,
-             (hash_result != 0) == (errors != 0) ? "true" : "false",
-             !hash_result ? "positive" : "negative");
+             (hash_result != 0) == (errors != 0) ? "true" : "false", not hash_result ? "positive" : "negative");
   }
 #endif