Logo AND Algorithmique Numérique Distribuée

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