Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3420b02989b3e8ec669a37df08611d1d96445763
[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 #include "mc_smx.h"
17
18 #ifdef HAVE_SMPI
19 #include "smpi/private.h"
20 #endif
21
22 #include "xbt/mmalloc.h"
23 #include "xbt/mmalloc/mmprivate.h"
24
25 #include <xbt/probes.h>
26
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, mc,
28                                 "Logging specific to mc_compare");
29
30 typedef struct s_pointers_pair {
31   void *p1;
32   void *p2;
33   bool operator==(s_pointers_pair const& x) const {
34     return this->p1 == x.p1 && this->p2 == x.p2;
35   }
36   bool operator<(s_pointers_pair const& x) const {
37     return this->p1 < x.p1 || (this->p1 == x.p1 && this->p2 < x.p2);
38   }
39 } s_pointers_pair_t, *pointers_pair_t;
40
41 namespace boost {
42   template<>
43   struct hash<s_pointers_pair> {
44     typedef uintptr_t result_type;
45     result_type operator()(s_pointers_pair const& x) const {
46       return (result_type) x.p1 ^
47         ((result_type) x.p2 << 8 | (result_type) x.p2 >> (8*sizeof(uintptr_t) - 8));
48     }
49   };
50 }
51
52 struct mc_compare_state {
53   boost::unordered_set<s_pointers_pair> compared_pointers;
54 };
55
56 extern "C" {
57
58 /************************** Free functions ****************************/
59 /********************************************************************/
60
61 static void stack_region_free(stack_region_t s)
62 {
63   if (s) {
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 = MC_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 if (_sg_mc_termination) { /* Non-progressive cycle MC */
399     s1 = ((mc_state_t) state1)->system_state;
400     s2 = ((mc_state_t) state2)->system_state;
401     num1 = ((mc_state_t) state1)->num;
402     num2 = ((mc_state_t) state2)->num;
403   } else {                      /* Safety or comm determinism MC */
404     s1 = ((mc_visited_state_t) state1)->system_state;
405     s2 = ((mc_visited_state_t) state2)->system_state;
406     num1 = ((mc_visited_state_t) state1)->num;
407     num2 = ((mc_visited_state_t) state2)->num;
408   }
409
410   int errors = 0;
411   int res_init;
412
413   xbt_os_timer_t global_timer = xbt_os_timer_new();
414   xbt_os_timer_t timer = xbt_os_timer_new();
415
416   xbt_os_walltimer_start(global_timer);
417
418 #ifdef MC_DEBUG
419   xbt_os_walltimer_start(timer);
420 #endif
421
422   int hash_result = 0;
423   if (_sg_mc_hash) {
424     hash_result = (s1->hash != s2->hash);
425     if (hash_result) {
426       XBT_TRACE2(mc, hash_diff, num1, num2);
427       XBT_VERB("(%d - %d) Different hash : 0x%" PRIx64 "--0x%" PRIx64, num1,
428                num2, s1->hash, s2->hash);
429 #ifndef MC_DEBUG
430       return 1;
431 #endif
432     } else {
433       XBT_VERB("(%d - %d) Same hash : 0x%" PRIx64, num1, num2, s1->hash);
434     }
435   }
436
437   /* Compare enabled processes */
438   unsigned int cursor;
439   int pid;
440   xbt_dynar_foreach(s1->enabled_processes, cursor, pid){
441     if(!xbt_dynar_member(s2->enabled_processes, &pid)) {
442       //XBT_TRACE3(mc, state_diff, num1, num2, "Different enabled processes");
443       XBT_VERB("(%d - %d) Different enabled processes", num1, num2);
444       // return 1; ??
445     }
446   }
447
448   unsigned long i = 0;
449   size_t size_used1, size_used2;
450   int is_diff = 0;
451
452   /* Compare size of stacks */
453   while (i < xbt_dynar_length(s1->stacks)) {
454     size_used1 = s1->stack_sizes[i];
455     size_used2 = s2->stack_sizes[i];
456     if (size_used1 != size_used2) {
457 #ifdef MC_DEBUG
458       if (is_diff == 0) {
459         xbt_os_walltimer_stop(timer);
460         mc_comp_times->stacks_sizes_comparison_time =
461             xbt_os_timer_elapsed(timer);
462       }
463       XBT_DEBUG("(%d - %d) Different size used in stacks : %zu - %zu", num1,
464                 num2, size_used1, size_used2);
465       errors++;
466       is_diff = 1;
467 #else
468 #ifdef MC_VERBOSE
469       XBT_VERB("(%d - %d) Different size used in stacks : %zu - %zu", num1,
470                num2, size_used1, size_used2);
471 #endif
472       XBT_TRACE3(mc, state_diff, num1, num2, "Different stack size");
473
474       xbt_os_walltimer_stop(timer);
475       xbt_os_timer_free(timer);
476       xbt_os_walltimer_stop(global_timer);
477       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
478       xbt_os_timer_free(global_timer);
479
480       return 1;
481 #endif
482     }
483     i++;
484   }
485
486 #ifdef MC_DEBUG
487   if (is_diff == 0)
488     xbt_os_walltimer_stop(timer);
489   xbt_os_walltimer_start(timer);
490 #endif
491
492   /* Init heap information used in heap comparison algorithm */
493   xbt_mheap_t heap1 = (xbt_mheap_t) MC_snapshot_read(
494     s1, MC_ADDRESS_SPACE_READ_FLAGS_LAZY,
495     alloca(sizeof(struct mdesc)), process->heap_address, sizeof(struct mdesc),
496     MC_PROCESS_INDEX_MISSING);
497   xbt_mheap_t heap2 = (xbt_mheap_t) MC_snapshot_read(
498     s2, MC_ADDRESS_SPACE_READ_FLAGS_LAZY,
499     alloca(sizeof(struct mdesc)), process->heap_address, sizeof(struct mdesc),
500     MC_PROCESS_INDEX_MISSING);
501   res_init = init_heap_information(heap1, heap2, s1->to_ignore, s2->to_ignore);
502   if (res_init == -1) {
503 #ifdef MC_DEBUG
504     XBT_DEBUG("(%d - %d) Different heap information", num1, num2);
505     errors++;
506 #else
507 #ifdef MC_VERBOSE
508     XBT_TRACE3(mc, state_diff, num1, num2, "Different heap information");
509     XBT_VERB("(%d - %d) Different heap information", num1, num2);
510 #endif
511
512     xbt_os_walltimer_stop(global_timer);
513     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
514     xbt_os_timer_free(global_timer);
515
516     return 1;
517 #endif
518   }
519 #ifdef MC_DEBUG
520   xbt_os_walltimer_start(timer);
521 #endif
522
523   /* Stacks comparison */
524   cursor = 0;
525   int diff_local = 0;
526 #ifdef MC_DEBUG
527   is_diff = 0;
528 #endif
529   mc_snapshot_stack_t stack1, stack2;
530   while (cursor < xbt_dynar_length(s1->stacks)) {
531     stack1 =
532         (mc_snapshot_stack_t) xbt_dynar_get_as(s1->stacks, cursor,
533                                                mc_snapshot_stack_t);
534     stack2 =
535         (mc_snapshot_stack_t) xbt_dynar_get_as(s2->stacks, cursor,
536                                                mc_snapshot_stack_t);
537
538     if (stack1->process_index != stack2->process_index) {
539       diff_local = 1;
540       XBT_DEBUG("(%d - %d) Stacks with different process index (%i vs %i)", num1, num2,
541         stack1->process_index, stack2->process_index);
542     }
543     else diff_local =
544         compare_local_variables(stack1->process_index, s1, s2, stack1, stack2);
545     if (diff_local > 0) {
546       XBT_TRACE3(mc, state_diff, num1, num2, "Different local variables");
547 #ifdef MC_DEBUG
548       if (is_diff == 0) {
549         xbt_os_walltimer_stop(timer);
550         mc_comp_times->stacks_comparison_time = xbt_os_timer_elapsed(timer);
551       }
552       XBT_DEBUG("(%d - %d) Different local variables between stacks %d", num1,
553                 num2, cursor + 1);
554       errors++;
555       is_diff = 1;
556 #else
557
558 #ifdef MC_VERBOSE
559       XBT_VERB("(%d - %d) Different local variables between stacks %d", num1,
560                num2, cursor + 1);
561 #endif
562
563       reset_heap_information();
564       xbt_os_walltimer_stop(timer);
565       xbt_os_timer_free(timer);
566       xbt_os_walltimer_stop(global_timer);
567       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
568       xbt_os_timer_free(global_timer);
569
570       return 1;
571 #endif
572     }
573     cursor++;
574   }
575
576   size_t regions_count = s1->snapshot_regions_count;
577   // TODO, raise a difference instead?
578   xbt_assert(regions_count == s2->snapshot_regions_count);
579
580   mc_comp_times->global_variables_comparison_time = 0;
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
595     const char* name = region1->object_info->file_name;
596
597 #ifdef MC_DEBUG
598     if (is_diff == 0)
599       xbt_os_walltimer_stop(timer);
600     xbt_os_walltimer_start(timer);
601 #endif
602
603     /* Compare global variables */
604     is_diff =
605       compare_global_variables(region1->object_info, MC_ADDRESS_SPACE_READ_FLAGS_NONE,
606         region1, region2,
607         s1, s2);
608
609     if (is_diff != 0) {
610       XBT_TRACE3(mc, state_diff, num1, num2, "Different global variables");
611 #ifdef MC_DEBUG
612       xbt_os_walltimer_stop(timer);
613       mc_comp_times->global_variables_comparison_time
614         += xbt_os_timer_elapsed(timer);
615       XBT_DEBUG("(%d - %d) Different global variables in %s", num1, num2,
616                 name);
617       errors++;
618 #else
619 #ifdef MC_VERBOSE
620       XBT_VERB("(%d - %d) Different global variables in %s", num1, num2,
621                name);
622 #endif
623
624       reset_heap_information();
625       xbt_os_walltimer_stop(timer);
626       xbt_os_timer_free(timer);
627       xbt_os_walltimer_stop(global_timer);
628       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
629       xbt_os_timer_free(global_timer);
630
631       return 1;
632 #endif
633     }
634   }
635
636 #ifdef MC_DEBUG
637   xbt_os_walltimer_start(timer);
638 #endif
639
640   /* Compare heap */
641   if (mmalloc_compare_heap(s1, s2) > 0) {
642     XBT_TRACE3(mc, state_diff, num1, num2, "Different heap");
643
644 #ifdef MC_DEBUG
645     xbt_os_walltimer_stop(timer);
646     mc_comp_times->heap_comparison_time = xbt_os_timer_elapsed(timer);
647     XBT_DEBUG("(%d - %d) Different heap (mmalloc_compare)", num1, num2);
648     errors++;
649 #else
650
651 #ifdef MC_VERBOSE
652     XBT_VERB("(%d - %d) Different heap (mmalloc_compare)", num1, num2);
653 #endif
654
655     reset_heap_information();
656     xbt_os_walltimer_stop(timer);
657     xbt_os_timer_free(timer);
658     xbt_os_walltimer_stop(global_timer);
659     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
660     xbt_os_timer_free(global_timer);
661
662     return 1;
663 #endif
664   } else {
665 #ifdef MC_DEBUG
666     xbt_os_walltimer_stop(timer);
667 #endif
668   }
669
670   reset_heap_information();
671
672   xbt_os_walltimer_stop(timer);
673   xbt_os_timer_free(timer);
674
675 #ifdef MC_VERBOSE
676   xbt_os_walltimer_stop(global_timer);
677   mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
678 #endif
679
680   xbt_os_timer_free(global_timer);
681
682 #ifdef MC_DEBUG
683   print_comparison_times();
684 #endif
685
686 #ifdef MC_VERBOSE
687   if (errors || hash_result)
688     XBT_VERB("(%d - %d) Difference found", num1, num2);
689   else
690     XBT_VERB("(%d - %d) No difference found", num1, num2);
691 #endif
692
693 #if defined(MC_DEBUG) && defined(MC_VERBOSE)
694   if (_sg_mc_hash) {
695     // * false positive SHOULD be avoided.
696     // * There MUST not be any false negative.
697
698     XBT_VERB("(%d - %d) State equality hash test is %s %s", num1, num2,
699              (hash_result != 0) == (errors != 0) ? "true" : "false",
700              !hash_result ? "positive" : "negative");
701   }
702 #endif
703
704   return errors > 0 || hash_result;
705
706 }
707
708 /***************************** Statistics *****************************/
709 /*******************************************************************/
710
711 void print_comparison_times()
712 {
713   XBT_DEBUG("*** Comparison times ***");
714   XBT_DEBUG("- Nb processes : %f", mc_comp_times->nb_processes_comparison_time);
715   XBT_DEBUG("- Nb bytes used : %f", mc_comp_times->bytes_used_comparison_time);
716   XBT_DEBUG("- Stacks sizes : %f", mc_comp_times->stacks_sizes_comparison_time);
717   XBT_DEBUG("- GLobal variables : %f", mc_comp_times->global_variables_comparison_time);
718   XBT_DEBUG("- Heap : %f", mc_comp_times->heap_comparison_time);
719   XBT_DEBUG("- Stacks : %f", mc_comp_times->stacks_comparison_time);
720 }
721
722 }