Logo AND Algorithmique Numérique Distribuée

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