Logo AND Algorithmique Numérique Distribuée

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