Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Do not use a dangerous guess-the-type logic in snapshot_compare()
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 22 Mar 2016 14:31:10 +0000 (15:31 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Wed, 23 Mar 2016 10:19:04 +0000 (11:19 +0100)
src/mc/mc_compare.cpp
src/mc/mc_liveness.h
src/mc/mc_private.h
src/mc/mc_safety.h
src/mc/mc_state.h

index 22dbfaf..825113f 100644 (file)
@@ -64,8 +64,6 @@ struct ComparisonState {
 
 using simgrid::mc::ComparisonState;
 
-extern "C" {
-
 /************************** Snapshot comparison *******************************/
 /******************************************************************************/
 
@@ -348,31 +346,14 @@ static int compare_local_variables(int process_index,
     return 0;
 }
 
-int snapshot_compare(void *state1, void *state2)
+namespace simgrid {
+namespace mc {
+
+static
+int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc::Snapshot* s2)
 {
   simgrid::mc::Process* process = &mc_model_checker->process();
 
-  simgrid::mc::Snapshot* s1;
-  simgrid::mc::Snapshot* s2;
-  int num1, num2;
-
-  if (_sg_mc_liveness) {        /* Liveness MC */
-    s1 = ((simgrid::mc::VisitedPair*) state1)->graph_state->system_state;
-    s2 = ((simgrid::mc::VisitedPair*) state2)->graph_state->system_state;
-    num1 = ((simgrid::mc::VisitedPair*) state1)->num;
-    num2 = ((simgrid::mc::VisitedPair*) state2)->num;
-  }else if (_sg_mc_termination) { /* Non-progressive cycle MC */
-    s1 = ((mc_state_t) state1)->system_state;
-    s2 = ((mc_state_t) state2)->system_state;
-    num1 = ((mc_state_t) state1)->num;
-    num2 = ((mc_state_t) state2)->num;
-  } else {                      /* Safety or comm determinism MC */
-    s1 = ((simgrid::mc::VisitedState*) state1)->system_state;
-    s2 = ((simgrid::mc::VisitedState*) state2)->system_state;
-    num1 = ((simgrid::mc::VisitedState*) state1)->num;
-    num2 = ((simgrid::mc::VisitedState*) state2)->num;
-  }
-
   int errors = 0;
   int res_init;
 
@@ -560,7 +541,34 @@ int snapshot_compare(void *state1, void *state2)
 #endif
 
   return errors > 0 || hash_result;
+}
 
+int snapshot_compare(simgrid::mc::VisitedPair* state1, simgrid::mc::VisitedPair* state2)
+{
+  simgrid::mc::Snapshot* s1 = state1->graph_state->system_state;
+  simgrid::mc::Snapshot* s2 = state2->graph_state->system_state;
+  int num1 = state1->num;
+  int num2 = state2->num;
+  return snapshot_compare(num1, s1, num2, s2);
 }
 
+int snapshot_compare(mc_state_t state1, mc_state_t state2)
+{
+  simgrid::mc::Snapshot* s1 = state1->system_state;
+  simgrid::mc::Snapshot* s2 = state2->system_state;
+  int num1 = state1->num;
+  int num2 = state2->num;
+  return snapshot_compare(num1, s1, num2, s2);
+}
+
+int snapshot_compare(simgrid::mc::VisitedState* state1, simgrid::mc::VisitedState* state2)
+{
+  simgrid::mc::Snapshot* s1 = state1->system_state;
+  simgrid::mc::Snapshot* s2 = state2->system_state;
+  int num1 = state1->num;
+  int num2 = state2->num;
+  return snapshot_compare(num1, s1, num2, s2);
+}
+
+}
 }
index b8fbd01..0b5b2da 100644 (file)
@@ -67,6 +67,8 @@ XBT_PRIVATE void dump_stack_liveness(xbt_fifo_t stack);
 XBT_PRIVATE extern xbt_dynar_t visited_pairs;
 XBT_PRIVATE int is_visited_pair(simgrid::mc::VisitedPair* visited_pair, simgrid::mc::Pair* pair);
 
+XBT_PRIVATE int snapshot_compare(simgrid::mc::VisitedPair* state1, simgrid::mc::VisitedPair* state2);
+
 }
 }
 
index 28f1178..23c17b0 100644 (file)
@@ -80,8 +80,6 @@ XBT_PRIVATE void MC_print_statistics(mc_stats_t stats);
 
 /********************************** Snapshot comparison **********************************/
 
-XBT_PRIVATE int snapshot_compare(void *state1, void *state2);
-
 //#define MC_DEBUG 1
 #define MC_VERBOSE 1
 
index 8e7503f..0bbe379 100644 (file)
@@ -44,6 +44,7 @@ struct XBT_PRIVATE VisitedState {
 
 extern XBT_PRIVATE std::vector<std::unique_ptr<simgrid::mc::VisitedState>> visited_states;
 XBT_PRIVATE std::unique_ptr<simgrid::mc::VisitedState> is_visited_state(mc_state_t graph_state);
+XBT_PRIVATE int snapshot_compare(simgrid::mc::VisitedState* state1, simgrid::mc::VisitedState* state2);
 
 }
 }
index 292d15c..93b350f 100644 (file)
@@ -68,4 +68,12 @@ XBT_PRIVATE void MC_state_remove_interleave_process(mc_state_t state, smx_proces
 
 SG_END_DECL()
 
+namespace simgrid {
+namespace mc {
+
+XBT_PRIVATE int snapshot_compare(mc_state_t state1, mc_state_t state2);
+
+}
+}
+
 #endif