Logo AND Algorithmique Numérique Distribuée

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