Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
49ca9778e3a2599f960c137a62cd8ca41ca8fc8f
[simgrid.git] / src / mc / mc_compare.cpp
1 /* Copyright (c) 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #define __STDC_FORMAT_MACROS
8 #include <cinttypes>
9 #include <boost/unordered_set.hpp>
10
11 #include <xbt/sysdep.h>
12
13 #include "internal_config.h"
14 #include "mc_object_info.h"
15 #include "mc_safety.h"
16 #include "mc_liveness.h"
17 #include "mc_private.h"
18 #include "mc_smx.h"
19 #include "mc_dwarf.hpp"
20
21 #include "mc/Frame.hpp"
22 #include "mc/ObjectInformation.hpp"
23 #include "mc/Variable.hpp"
24
25 #ifdef HAVE_SMPI
26 #include "smpi/private.h"
27 #endif
28
29 #include "xbt/mmalloc.h"
30 #include "xbt/mmalloc/mmprivate.h"
31
32 #include <xbt/probes.h>
33
34 using simgrid::mc::remote;
35
36 typedef struct s_pointers_pair {
37   void *p1;
38   void *p2;
39   bool operator==(s_pointers_pair const& x) const {
40     return this->p1 == x.p1 && this->p2 == x.p2;
41   }
42   bool operator<(s_pointers_pair const& x) const {
43     return this->p1 < x.p1 || (this->p1 == x.p1 && this->p2 < x.p2);
44   }
45 } s_pointers_pair_t, *pointers_pair_t;
46
47 namespace boost {
48   template<>
49   struct hash<s_pointers_pair> {
50     typedef uintptr_t result_type;
51     result_type operator()(s_pointers_pair const& x) const {
52       return (result_type) x.p1 ^
53         ((result_type) x.p2 << 8 | (result_type) x.p2 >> (8*sizeof(uintptr_t) - 8));
54     }
55   };
56 }
57
58 struct mc_compare_state {
59   boost::unordered_set<s_pointers_pair> compared_pointers;
60 };
61
62 extern "C" {
63
64 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, xbt,
65                                 "Logging specific to mc_compare in mc");
66
67 /************************** Free functions ****************************/
68 /********************************************************************/
69
70 static void stack_region_free(stack_region_t s)
71 {
72   if (s) {
73     xbt_free(s);
74   }
75 }
76
77 static void stack_region_free_voidp(void *s)
78 {
79   stack_region_free((stack_region_t) * (void **) s);
80 }
81
82 static void pointers_pair_free(pointers_pair_t p)
83 {
84   xbt_free(p);
85 }
86
87 static void pointers_pair_free_voidp(void *p)
88 {
89   pointers_pair_free((pointers_pair_t) * (void **) p);
90 }
91
92 /************************** Snapshot comparison *******************************/
93 /******************************************************************************/
94
95 /** \brief Try to add a pair a compared pointers to the set of compared pointers
96  *
97  *  \result !=0 if the pointers were added (they were not in the set),
98  *      0 otherwise (they were already in the set)
99  */
100 static int add_compared_pointers(mc_compare_state& state, void *p1, void *p2)
101 {
102   s_pointers_pair_t new_pair;
103   new_pair.p1 = p1;
104   new_pair.p2 = p2;
105   return state.compared_pointers.insert(new_pair).second ? 1 : 0;
106 }
107
108 static int compare_areas_with_type(struct mc_compare_state& state,
109                                    int process_index,
110                                    void* real_area1, mc_snapshot_t snapshot1, mc_mem_region_t region1,
111                                    void* real_area2, mc_snapshot_t snapshot2, mc_mem_region_t region2,
112                                    simgrid::mc::Type* type, int pointer_level)
113 {
114   simgrid::mc::Process* process = &mc_model_checker->process();
115
116   simgrid::mc::Type* subtype;
117   simgrid::mc::Type* subsubtype;
118   int elm_size, i, res;
119
120   top:
121   switch (type->type) {
122   case DW_TAG_unspecified_type:
123     return 1;
124
125   case DW_TAG_base_type:
126   case DW_TAG_enumeration_type:
127   case DW_TAG_union_type:
128   {
129     return MC_snapshot_region_memcmp(
130       real_area1, region1, real_area2, region2,
131       type->byte_size) != 0;
132   }
133   case DW_TAG_typedef:
134   case DW_TAG_volatile_type:
135   case DW_TAG_const_type:
136     // Poor man's TCO:
137     type = type->subtype;
138     goto top;
139   case DW_TAG_array_type:
140     subtype = type->subtype;
141     switch (subtype->type) {
142     case DW_TAG_unspecified_type:
143       return 1;
144
145     case DW_TAG_base_type:
146     case DW_TAG_enumeration_type:
147     case DW_TAG_pointer_type:
148     case DW_TAG_reference_type:
149     case DW_TAG_rvalue_reference_type:
150     case DW_TAG_structure_type:
151     case DW_TAG_class_type:
152     case DW_TAG_union_type:
153       if (subtype->full_type)
154         subtype = subtype->full_type;
155       elm_size = subtype->byte_size;
156       break;
157     case DW_TAG_const_type:
158     case DW_TAG_typedef:
159     case DW_TAG_volatile_type:
160       subsubtype = subtype->subtype;
161       if (subsubtype->full_type)
162         subsubtype = subsubtype->full_type;
163       elm_size = subsubtype->byte_size;
164       break;
165     default:
166       return 0;
167       break;
168     }
169     for (i = 0; i < type->element_count; i++) {
170       size_t off = i * elm_size;
171       res = compare_areas_with_type(state, process_index,
172             (char*) real_area1 + off, snapshot1, region1,
173             (char*) real_area2 + off, snapshot2, region2,
174             type->subtype, pointer_level);
175       if (res == 1)
176         return res;
177     }
178     break;
179   case DW_TAG_pointer_type:
180   case DW_TAG_reference_type:
181   case DW_TAG_rvalue_reference_type:
182   {
183     void* addr_pointed1 = MC_region_read_pointer(region1, real_area1);
184     void* addr_pointed2 = MC_region_read_pointer(region2, real_area2);
185
186     if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
187       return (addr_pointed1 != addr_pointed2);
188     } else {
189
190       if (addr_pointed1 == NULL && addr_pointed2 == NULL)
191         return 0;
192       if (addr_pointed1 == NULL || addr_pointed2 == NULL)
193         return 1;
194       if (!add_compared_pointers(state, addr_pointed1, addr_pointed2))
195         return 0;
196
197       pointer_level++;
198
199       // Some cases are not handled here:
200       // * the pointers lead to different areas (one to the heap, the other to the RW segment ...);
201       // * a pointer leads to the read-only segment of the current object;
202       // * a pointer lead to a different ELF object.
203
204       if (addr_pointed1 > process->heap_address
205           && addr_pointed1 < mc_snapshot_get_heap_end(snapshot1)) {
206         if (!
207             (addr_pointed2 > process->heap_address
208              && addr_pointed2 < mc_snapshot_get_heap_end(snapshot2)))
209           return 1;
210         // The pointers are both in the heap:
211         return compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
212                                  snapshot2, NULL, type->subtype, pointer_level);
213       }
214
215       // The pointers are both in the current object R/W segment:
216       else if (region1->contain(simgrid::mc::remote(addr_pointed1))) {
217         if (!region2->contain(simgrid::mc::remote(addr_pointed2)))
218           return 1;
219         if (!type->type_id)
220           return (addr_pointed1 != addr_pointed2);
221         else {
222           return compare_areas_with_type(state, process_index,
223                                          addr_pointed1, snapshot1, region1,
224                                          addr_pointed2, snapshot2, region2,
225                                          type->subtype, pointer_level);
226         }
227       }
228
229       // TODO, We do not handle very well the case where
230       // it belongs to a different (non-heap) region from the current one.
231
232       else {
233         return (addr_pointed1 != addr_pointed2);
234       }
235     }
236     break;
237   }
238   case DW_TAG_structure_type:
239   case DW_TAG_class_type:
240     for(simgrid::mc::Member& member : type->members) {
241       void *member1 =
242         mc_member_resolve(real_area1, type, &member, snapshot1, process_index);
243       void *member2 =
244         mc_member_resolve(real_area2, type, &member, snapshot2, process_index);
245       mc_mem_region_t subregion1 = mc_get_region_hinted(member1, snapshot1, process_index, region1);
246       mc_mem_region_t subregion2 = mc_get_region_hinted(member2, snapshot2, process_index, region2);
247       res =
248           compare_areas_with_type(state, process_index,
249                                   member1, snapshot1, subregion1,
250                                   member2, snapshot2, subregion2,
251                                   member.type, pointer_level);
252       if (res == 1)
253         return res;
254     }
255     break;
256   case DW_TAG_subroutine_type:
257     return -1;
258     break;
259   default:
260     XBT_VERB("Unknown case : %d", type->type);
261     break;
262   }
263
264   return 0;
265 }
266
267 static int compare_global_variables(simgrid::mc::ObjectInformation* object_info,
268                                     int process_index,
269                                     mc_mem_region_t r1,
270                                     mc_mem_region_t r2, mc_snapshot_t snapshot1,
271                                     mc_snapshot_t snapshot2)
272 {
273   xbt_assert(r1 && r2, "Missing region.");
274
275 #ifdef HAVE_SMPI
276   if (r1->storage_type() == simgrid::mc::StorageType::Privatized) {
277     xbt_assert(process_index >= 0);
278     if (r2->storage_type() != simgrid::mc::StorageType::Privatized) {
279       return 1;
280     }
281
282     size_t process_count = MC_smpi_process_count();
283     xbt_assert(process_count == r1->privatized_data().size()
284       && process_count == r2->privatized_data().size());
285
286     // Compare the global variables separately for each simulates process:
287     for (size_t process_index = 0; process_index < process_count; process_index++) {
288       int is_diff = compare_global_variables(object_info, process_index,
289         &r1->privatized_data()[process_index],
290         &r2->privatized_data()[process_index],
291         snapshot1, snapshot2);
292       if (is_diff) return 1;
293     }
294     return 0;
295   }
296 #else
297   xbt_assert(r1->storage_type() != simgrid::mc::StorageType::Privatized);
298 #endif
299   xbt_assert(r2->storage_type() != simgrid::mc::StorageType::Privatized);
300
301   struct mc_compare_state state;
302
303   std::vector<simgrid::mc::Variable>& variables = object_info->global_variables;
304
305   for (simgrid::mc::Variable& current_var : variables) {
306
307     // If the variable is not in this object, skip it:
308     // We do not expect to find a pointer to something which is not reachable
309     // by the global variables.
310     if ((char *) current_var.address < (char *) object_info->start_rw
311         || (char *) current_var.address > (char *) object_info->end_rw)
312       continue;
313
314     simgrid::mc::Type* bvariable_type = current_var.type;
315     int res =
316         compare_areas_with_type(state, process_index,
317                                 (char *) current_var.address, snapshot1, r1,
318                                 (char *) current_var.address, snapshot2, r2,
319                                 bvariable_type, 0);
320     if (res == 1) {
321       XBT_TRACE3(mc, global_diff, -1, -1, current_var->name);
322       XBT_VERB("Global variable %s (%p) is different between snapshots",
323                current_var.name.c_str(),
324                (char *) current_var.address);
325       return 1;
326     }
327
328   }
329
330   return 0;
331
332 }
333
334 static int compare_local_variables(int process_index,
335                                    mc_snapshot_t snapshot1,
336                                    mc_snapshot_t snapshot2,
337                                    mc_snapshot_stack_t stack1,
338                                    mc_snapshot_stack_t stack2)
339 {
340   struct mc_compare_state state;
341
342   if (stack1->local_variables.size() != stack2->local_variables.size()) {
343     XBT_VERB("Different number of local variables");
344     return 1;
345   } else {
346     unsigned int cursor = 0;
347     local_variable_t current_var1, current_var2;
348     int res;
349     while (cursor < stack1->local_variables.size()) {
350       current_var1 = &stack1->local_variables[cursor];
351       current_var2 = &stack1->local_variables[cursor];
352       if (current_var1->name != current_var2->name
353           || current_var1->subprogram != current_var1->subprogram
354           || current_var1->ip != current_var2->ip) {
355         // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
356         XBT_VERB
357             ("Different name of variable (%s - %s) "
358              "or frame (%s - %s) or ip (%lu - %lu)",
359              current_var1->name.c_str(),
360              current_var2->name.c_str(),
361              current_var1->subprogram->name.c_str(),
362              current_var2->subprogram->name.c_str(),
363              current_var1->ip, current_var2->ip);
364         return 1;
365       }
366       // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
367
368         simgrid::mc::Type* subtype = current_var1->type;
369         res =
370             compare_areas_with_type(state, process_index,
371                                     current_var1->address, snapshot1, mc_get_snapshot_region(current_var1->address, snapshot1, process_index),
372                                     current_var2->address, snapshot2, mc_get_snapshot_region(current_var2->address, snapshot2, process_index),
373                                     subtype, 0);
374
375       if (res == 1) {
376         // TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
377         XBT_TRACE3(mc, local_diff, -1, -1, current_var1->name);
378         XBT_VERB
379             ("Local variable %s (%p - %p) in frame %s "
380              "is different between snapshots",
381              current_var1->name.c_str(),
382              current_var1->address,
383              current_var2->address,
384              current_var1->subprogram->name.c_str());
385         return res;
386       }
387       cursor++;
388     }
389     return 0;
390   }
391 }
392
393 int snapshot_compare(void *state1, void *state2)
394 {
395   simgrid::mc::Process* process = &mc_model_checker->process();
396
397   mc_snapshot_t s1, s2;
398   int num1, num2;
399
400   if (_sg_mc_liveness) {        /* Liveness MC */
401     s1 = ((mc_visited_pair_t) state1)->graph_state->system_state;
402     s2 = ((mc_visited_pair_t) state2)->graph_state->system_state;
403     num1 = ((mc_visited_pair_t) state1)->num;
404     num2 = ((mc_visited_pair_t) state2)->num;
405   }else if (_sg_mc_termination) { /* Non-progressive cycle MC */
406     s1 = ((mc_state_t) state1)->system_state;
407     s2 = ((mc_state_t) state2)->system_state;
408     num1 = ((mc_state_t) state1)->num;
409     num2 = ((mc_state_t) state2)->num;
410   } else {                      /* Safety or comm determinism MC */
411     s1 = ((mc_visited_state_t) state1)->system_state;
412     s2 = ((mc_visited_state_t) state2)->system_state;
413     num1 = ((mc_visited_state_t) state1)->num;
414     num2 = ((mc_visited_state_t) state2)->num;
415   }
416
417   int errors = 0;
418   int res_init;
419
420   xbt_os_timer_t global_timer = xbt_os_timer_new();
421   xbt_os_timer_t timer = xbt_os_timer_new();
422
423   xbt_os_walltimer_start(global_timer);
424
425 #ifdef MC_DEBUG
426   xbt_os_walltimer_start(timer);
427 #endif
428
429   int hash_result = 0;
430   if (_sg_mc_hash) {
431     hash_result = (s1->hash != s2->hash);
432     if (hash_result) {
433       XBT_TRACE2(mc, hash_diff, num1, num2);
434       XBT_VERB("(%d - %d) Different hash : 0x%" PRIx64 "--0x%" PRIx64, num1,
435                num2, s1->hash, s2->hash);
436 #ifndef MC_DEBUG
437       return 1;
438 #endif
439     } else {
440       XBT_VERB("(%d - %d) Same hash : 0x%" PRIx64, num1, num2, s1->hash);
441     }
442   }
443
444   /* Compare enabled processes */
445   if (s1->enabled_processes != s2->enabled_processes) {
446       //XBT_TRACE3(mc, state_diff, num1, num2, "Different enabled processes");
447       XBT_VERB("(%d - %d) Different enabled processes", num1, num2);
448       // return 1; ??
449   }
450
451   unsigned long i = 0;
452   size_t size_used1, size_used2;
453   int is_diff = 0;
454
455   /* Compare size of stacks */
456   while (i < s1->stacks.size()) {
457     size_used1 = s1->stack_sizes[i];
458     size_used2 = s2->stack_sizes[i];
459     if (size_used1 != size_used2) {
460 #ifdef MC_DEBUG
461       if (is_diff == 0) {
462         xbt_os_walltimer_stop(timer);
463         mc_comp_times->stacks_sizes_comparison_time =
464             xbt_os_timer_elapsed(timer);
465       }
466       XBT_DEBUG("(%d - %d) Different size used in stacks : %zu - %zu", num1,
467                 num2, size_used1, size_used2);
468       errors++;
469       is_diff = 1;
470 #else
471 #ifdef MC_VERBOSE
472       XBT_VERB("(%d - %d) Different size used in stacks : %zu - %zu", num1,
473                num2, size_used1, size_used2);
474 #endif
475       XBT_TRACE3(mc, state_diff, num1, num2, "Different stack size");
476
477       xbt_os_walltimer_stop(timer);
478       xbt_os_timer_free(timer);
479       xbt_os_walltimer_stop(global_timer);
480       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
481       xbt_os_timer_free(global_timer);
482
483       return 1;
484 #endif
485     }
486     i++;
487   }
488
489 #ifdef MC_DEBUG
490   if (is_diff == 0)
491     xbt_os_walltimer_stop(timer);
492   xbt_os_walltimer_start(timer);
493 #endif
494
495   /* Init heap information used in heap comparison algorithm */
496   xbt_mheap_t heap1 = (xbt_mheap_t)s1->read_bytes(
497     alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
498     remote(process->heap_address),
499     simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy);
500   xbt_mheap_t heap2 = (xbt_mheap_t)s2->read_bytes(
501     alloca(sizeof(struct mdesc)), sizeof(struct mdesc),
502     remote(process->heap_address),
503     simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy);
504   res_init = init_heap_information(heap1, heap2, &s1->to_ignore, &s2->to_ignore);
505   if (res_init == -1) {
506 #ifdef MC_DEBUG
507     XBT_DEBUG("(%d - %d) Different heap information", num1, num2);
508     errors++;
509 #else
510 #ifdef MC_VERBOSE
511     XBT_TRACE3(mc, state_diff, num1, num2, "Different heap information");
512     XBT_VERB("(%d - %d) Different heap information", num1, num2);
513 #endif
514
515     xbt_os_walltimer_stop(global_timer);
516     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
517     xbt_os_timer_free(global_timer);
518
519     return 1;
520 #endif
521   }
522 #ifdef MC_DEBUG
523   xbt_os_walltimer_start(timer);
524 #endif
525
526   /* Stacks comparison */
527   unsigned cursor = 0;
528   int diff_local = 0;
529 #ifdef MC_DEBUG
530   is_diff = 0;
531 #endif
532   mc_snapshot_stack_t stack1, stack2;
533   while (cursor < s1->stacks.size()) {
534     stack1 = &s1->stacks[cursor];
535     stack2 = &s1->stacks[cursor];
536
537     if (stack1->process_index != stack2->process_index) {
538       diff_local = 1;
539       XBT_DEBUG("(%d - %d) Stacks with different process index (%i vs %i)", num1, num2,
540         stack1->process_index, stack2->process_index);
541     }
542     else diff_local =
543         compare_local_variables(stack1->process_index, s1, s2, stack1, stack2);
544     if (diff_local > 0) {
545       XBT_TRACE3(mc, state_diff, num1, num2, "Different local variables");
546 #ifdef MC_DEBUG
547       if (is_diff == 0) {
548         xbt_os_walltimer_stop(timer);
549         mc_comp_times->stacks_comparison_time = xbt_os_timer_elapsed(timer);
550       }
551       XBT_DEBUG("(%d - %d) Different local variables between stacks %d", num1,
552                 num2, cursor + 1);
553       errors++;
554       is_diff = 1;
555 #else
556
557 #ifdef MC_VERBOSE
558       XBT_VERB("(%d - %d) Different local variables between stacks %d", num1,
559                num2, cursor + 1);
560 #endif
561
562       reset_heap_information();
563       xbt_os_walltimer_stop(timer);
564       xbt_os_timer_free(timer);
565       xbt_os_walltimer_stop(global_timer);
566       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
567       xbt_os_timer_free(global_timer);
568
569       return 1;
570 #endif
571     }
572     cursor++;
573   }
574
575   size_t regions_count = s1->snapshot_regions.size();
576   // TODO, raise a difference instead?
577   xbt_assert(regions_count == s2->snapshot_regions.size());
578
579   mc_comp_times->global_variables_comparison_time = 0;
580
581   for (size_t k = 0; k != regions_count; ++k) {
582     mc_mem_region_t region1 = s1->snapshot_regions[k].get();
583     mc_mem_region_t region2 = s2->snapshot_regions[k].get();
584
585     // Preconditions:
586     if (region1->region_type() != simgrid::mc::RegionType::Data)
587       continue;
588
589     xbt_assert(region1->region_type() == region2->region_type());
590     xbt_assert(region1->object_info() == region2->object_info());
591     xbt_assert(region1->object_info());
592
593     std::string const& name = region1->object_info()->file_name;
594
595 #ifdef MC_DEBUG
596     if (is_diff == 0)
597       xbt_os_walltimer_stop(timer);
598     xbt_os_walltimer_start(timer);
599 #endif
600
601     /* Compare global variables */
602     is_diff =
603       compare_global_variables(region1->object_info(  ), simgrid::mc::AddressSpace::Normal,
604         region1, region2,
605         s1, s2);
606
607     if (is_diff != 0) {
608       XBT_TRACE3(mc, state_diff, num1, num2, "Different global variables");
609 #ifdef MC_DEBUG
610       xbt_os_walltimer_stop(timer);
611       mc_comp_times->global_variables_comparison_time
612         += xbt_os_timer_elapsed(timer);
613       XBT_DEBUG("(%d - %d) Different global variables in %s",
614         num1, num2, name.c_str());
615       errors++;
616 #else
617 #ifdef MC_VERBOSE
618       XBT_VERB("(%d - %d) Different global variables in %s",
619         num1, num2, name.c_str());
620 #endif
621
622       reset_heap_information();
623       xbt_os_walltimer_stop(timer);
624       xbt_os_timer_free(timer);
625       xbt_os_walltimer_stop(global_timer);
626       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
627       xbt_os_timer_free(global_timer);
628
629       return 1;
630 #endif
631     }
632   }
633
634 #ifdef MC_DEBUG
635   xbt_os_walltimer_start(timer);
636 #endif
637
638   /* Compare heap */
639   if (mmalloc_compare_heap(s1, s2) > 0) {
640     XBT_TRACE3(mc, state_diff, num1, num2, "Different heap");
641
642 #ifdef MC_DEBUG
643     xbt_os_walltimer_stop(timer);
644     mc_comp_times->heap_comparison_time = xbt_os_timer_elapsed(timer);
645     XBT_DEBUG("(%d - %d) Different heap (mmalloc_compare)", num1, num2);
646     errors++;
647 #else
648
649 #ifdef MC_VERBOSE
650     XBT_VERB("(%d - %d) Different heap (mmalloc_compare)", num1, num2);
651 #endif
652
653     reset_heap_information();
654     xbt_os_walltimer_stop(timer);
655     xbt_os_timer_free(timer);
656     xbt_os_walltimer_stop(global_timer);
657     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
658     xbt_os_timer_free(global_timer);
659
660     return 1;
661 #endif
662   } else {
663 #ifdef MC_DEBUG
664     xbt_os_walltimer_stop(timer);
665 #endif
666   }
667
668   reset_heap_information();
669
670   xbt_os_walltimer_stop(timer);
671   xbt_os_timer_free(timer);
672
673 #ifdef MC_VERBOSE
674   xbt_os_walltimer_stop(global_timer);
675   mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
676 #endif
677
678   xbt_os_timer_free(global_timer);
679
680 #ifdef MC_DEBUG
681   print_comparison_times();
682 #endif
683
684 #ifdef MC_VERBOSE
685   if (errors || hash_result)
686     XBT_VERB("(%d - %d) Difference found", num1, num2);
687   else
688     XBT_VERB("(%d - %d) No difference found", num1, num2);
689 #endif
690
691 #if defined(MC_DEBUG) && defined(MC_VERBOSE)
692   if (_sg_mc_hash) {
693     // * false positive SHOULD be avoided.
694     // * There MUST not be any false negative.
695
696     XBT_VERB("(%d - %d) State equality hash test is %s %s", num1, num2,
697              (hash_result != 0) == (errors != 0) ? "true" : "false",
698              !hash_result ? "positive" : "negative");
699   }
700 #endif
701
702   return errors > 0 || hash_result;
703
704 }
705
706 /***************************** Statistics *****************************/
707 /*******************************************************************/
708
709 void print_comparison_times()
710 {
711   XBT_DEBUG("*** Comparison times ***");
712   XBT_DEBUG("- Nb processes : %f", mc_comp_times->nb_processes_comparison_time);
713   XBT_DEBUG("- Nb bytes used : %f", mc_comp_times->bytes_used_comparison_time);
714   XBT_DEBUG("- Stacks sizes : %f", mc_comp_times->stacks_sizes_comparison_time);
715   XBT_DEBUG("- GLobal variables : %f", mc_comp_times->global_variables_comparison_time);
716   XBT_DEBUG("- Heap : %f", mc_comp_times->heap_comparison_time);
717   XBT_DEBUG("- Stacks : %f", mc_comp_times->stacks_comparison_time);
718 }
719
720 }