Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2f7ce7ead09709f3b3356f1f098d986152931ca8
[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_snapshot_read_pointer_region(real_area1, region1);
175     void* addr_pointed2 = mc_snapshot_read_pointer_region(real_area2, region2);
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, snapshot1, process_index);
234       void *member2 =
235         mc_member_resolve(real_area2, type, member, 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(process->heap_address, s1, MC_NO_PROCESS_INDEX,
489     alloca(sizeof(struct mdesc)), sizeof(struct mdesc));
490   xbt_mheap_t heap2 = (xbt_mheap_t) mc_snapshot_read(process->heap_address, s2, MC_NO_PROCESS_INDEX,
491     alloca(sizeof(struct mdesc)), sizeof(struct mdesc));
492   res_init = init_heap_information(heap1, heap2, s1->to_ignore, s2->to_ignore);
493   if (res_init == -1) {
494 #ifdef MC_DEBUG
495     XBT_DEBUG("(%d - %d) Different heap information", num1, num2);
496     errors++;
497 #else
498 #ifdef MC_VERBOSE
499     XBT_TRACE3(mc, state_diff, num1, num2, "Different heap information");
500     XBT_VERB("(%d - %d) Different heap information", num1, num2);
501 #endif
502
503     xbt_os_walltimer_stop(global_timer);
504     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
505     xbt_os_timer_free(global_timer);
506
507     return 1;
508 #endif
509   }
510 #ifdef MC_DEBUG
511   xbt_os_walltimer_start(timer);
512 #endif
513
514   /* Stacks comparison */
515   cursor = 0;
516   int diff_local = 0;
517 #ifdef MC_DEBUG
518   is_diff = 0;
519 #endif
520   mc_snapshot_stack_t stack1, stack2;
521   while (cursor < xbt_dynar_length(s1->stacks)) {
522     stack1 =
523         (mc_snapshot_stack_t) xbt_dynar_get_as(s1->stacks, cursor,
524                                                mc_snapshot_stack_t);
525     stack2 =
526         (mc_snapshot_stack_t) xbt_dynar_get_as(s2->stacks, cursor,
527                                                mc_snapshot_stack_t);
528
529     if (stack1->process_index != stack2->process_index) {
530       diff_local = 1;
531       XBT_DEBUG("(%d - %d) Stacks with different process index (%i vs %i)", num1, num2,
532         stack1->process_index, stack2->process_index);
533     }
534     else diff_local =
535         compare_local_variables(stack1->process_index, s1, s2, stack1, stack2);
536     if (diff_local > 0) {
537       XBT_TRACE3(mc, state_diff, num1, num2, "Different local variables");
538 #ifdef MC_DEBUG
539       if (is_diff == 0) {
540         xbt_os_walltimer_stop(timer);
541         mc_comp_times->stacks_comparison_time = xbt_os_timer_elapsed(timer);
542       }
543       XBT_DEBUG("(%d - %d) Different local variables between stacks %d", num1,
544                 num2, cursor + 1);
545       errors++;
546       is_diff = 1;
547 #else
548
549 #ifdef MC_VERBOSE
550       XBT_VERB("(%d - %d) Different local variables between stacks %d", num1,
551                num2, cursor + 1);
552 #endif
553
554       reset_heap_information();
555       xbt_os_walltimer_stop(timer);
556       xbt_os_timer_free(timer);
557       xbt_os_walltimer_stop(global_timer);
558       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
559       xbt_os_timer_free(global_timer);
560
561       return 1;
562 #endif
563     }
564     cursor++;
565   }
566
567
568
569   const char *names[3] = { "?", "libsimgrid", "binary" };
570 #ifdef MC_DEBUG
571   double *times[3] = {
572     NULL,
573     &mc_comp_times->libsimgrid_global_variables_comparison_time,
574     &mc_comp_times->binary_global_variables_comparison_time
575   };
576 #endif
577
578   size_t regions_count = s1->snapshot_regions_count;
579   // TODO, raise a difference instead?
580   xbt_assert(regions_count == s2->snapshot_regions_count);
581
582   for (size_t k = 0; k != regions_count; ++k) {
583     mc_mem_region_t region1 = s1->snapshot_regions[k];
584     mc_mem_region_t region2 = s2->snapshot_regions[k];
585
586     // Preconditions:
587     if (region1->region_type != MC_REGION_TYPE_DATA)
588       continue;
589
590     xbt_assert(region1->region_type == region2->region_type);
591     xbt_assert(region1->object_info == region2->object_info);
592
593     xbt_assert(region1->object_info);
594 #ifdef MC_DEBUG
595     if (is_diff == 0)
596       xbt_os_walltimer_stop(timer);
597     xbt_os_walltimer_start(timer);
598 #endif
599
600     /* Compare global variables */
601     is_diff =
602       compare_global_variables(region1->object_info, MC_NO_PROCESS_INDEX,
603         region1, region2,
604         s1, s2);
605
606     if (is_diff != 0) {
607       XBT_TRACE3(mc, state_diff, num1, num2, "Different global variables");
608 #ifdef MC_DEBUG
609       xbt_os_walltimer_stop(timer);
610       *times[k] = xbt_os_timer_elapsed(timer);
611       XBT_DEBUG("(%d - %d) Different global variables in %s", num1, num2,
612                 names[k]);
613       errors++;
614 #else
615 #ifdef MC_VERBOSE
616       XBT_VERB("(%d - %d) Different global variables in %s", num1, num2,
617                names[k]);
618 #endif
619
620       reset_heap_information();
621       xbt_os_walltimer_stop(timer);
622       xbt_os_timer_free(timer);
623       xbt_os_walltimer_stop(global_timer);
624       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
625       xbt_os_timer_free(global_timer);
626
627       return 1;
628 #endif
629     }
630   }
631
632 #ifdef MC_DEBUG
633   xbt_os_walltimer_start(timer);
634 #endif
635
636   /* Compare heap */
637   if (mmalloc_compare_heap(s1, s2) > 0) {
638     XBT_TRACE3(mc, state_diff, num1, num2, "Different heap");
639
640 #ifdef MC_DEBUG
641     xbt_os_walltimer_stop(timer);
642     mc_comp_times->heap_comparison_time = xbt_os_timer_elapsed(timer);
643     XBT_DEBUG("(%d - %d) Different heap (mmalloc_compare)", num1, num2);
644     errors++;
645 #else
646
647 #ifdef MC_VERBOSE
648     XBT_VERB("(%d - %d) Different heap (mmalloc_compare)", num1, num2);
649 #endif
650
651     reset_heap_information();
652     xbt_os_walltimer_stop(timer);
653     xbt_os_timer_free(timer);
654     xbt_os_walltimer_stop(global_timer);
655     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
656     xbt_os_timer_free(global_timer);
657
658     return 1;
659 #endif
660   } else {
661 #ifdef MC_DEBUG
662     xbt_os_walltimer_stop(timer);
663 #endif
664   }
665
666   reset_heap_information();
667
668   xbt_os_walltimer_stop(timer);
669   xbt_os_timer_free(timer);
670
671 #ifdef MC_VERBOSE
672   xbt_os_walltimer_stop(global_timer);
673   mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
674 #endif
675
676   xbt_os_timer_free(global_timer);
677
678 #ifdef MC_DEBUG
679   print_comparison_times();
680 #endif
681
682 #ifdef MC_VERBOSE
683   if (errors || hash_result)
684     XBT_VERB("(%d - %d) Difference found", num1, num2);
685   else
686     XBT_VERB("(%d - %d) No difference found", num1, num2);
687 #endif
688
689 #if defined(MC_DEBUG) && defined(MC_VERBOSE)
690   if (_sg_mc_hash) {
691     // * false positive SHOULD be avoided.
692     // * There MUST not be any false negative.
693
694     XBT_VERB("(%d - %d) State equality hash test is %s %s", num1, num2,
695              (hash_result != 0) == (errors != 0) ? "true" : "false",
696              !hash_result ? "positive" : "negative");
697   }
698 #endif
699
700   return errors > 0 || hash_result;
701
702 }
703
704 /***************************** Statistics *****************************/
705 /*******************************************************************/
706
707 void print_comparison_times()
708 {
709   XBT_DEBUG("*** Comparison times ***");
710   XBT_DEBUG("- Nb processes : %f", mc_comp_times->nb_processes_comparison_time);
711   XBT_DEBUG("- Nb bytes used : %f", mc_comp_times->bytes_used_comparison_time);
712   XBT_DEBUG("- Stacks sizes : %f", mc_comp_times->stacks_sizes_comparison_time);
713   XBT_DEBUG("- Binary global variables : %f",
714             mc_comp_times->binary_global_variables_comparison_time);
715   XBT_DEBUG("- Libsimgrid global variables : %f",
716             mc_comp_times->libsimgrid_global_variables_comparison_time);
717   XBT_DEBUG("- Heap : %f", mc_comp_times->heap_comparison_time);
718   XBT_DEBUG("- Stacks : %f", mc_comp_times->stacks_comparison_time);
719 }
720
721 /**************************** MC snapshot compare simcall **************************/
722 /***********************************************************************************/
723
724 int simcall_HANDLER_mc_compare_snapshots(smx_simcall_t simcall,
725                                    mc_snapshot_t s1, mc_snapshot_t s2)
726 {
727   return snapshot_compare(s1, s2);
728 }
729
730 int MC_compare_snapshots(void *s1, void *s2)
731 {
732
733   return simcall_mc_compare_snapshots(s1, s2);
734
735 }
736
737 }