Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
12390fbfe3822c731484f608e420ce00c9e81e50
[simgrid.git] / src / mc / mc_compare.c
1 /* Copyright (c) 2012-2013. 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 #include "mc_private.h"
8
9 #include "xbt/mmalloc.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, mc,
12                                 "Logging specific to mc_compare");
13
14 typedef struct s_pointers_pair{
15   void *p1;
16   void *p2;
17 }s_pointers_pair_t, *pointers_pair_t;
18
19 __thread xbt_dynar_t compared_pointers;
20
21 /************************** Free functions ****************************/
22 /********************************************************************/
23
24 static void stack_region_free(stack_region_t s){
25   if(s){
26     xbt_free(s->process_name);
27     xbt_free(s);
28   }
29 }
30
31 static void stack_region_free_voidp(void *s){
32   stack_region_free((stack_region_t) * (void **) s);
33 }
34
35 static void pointers_pair_free(pointers_pair_t p){
36   xbt_free(p);
37 }
38
39 static void pointers_pair_free_voidp(void *p){
40   pointers_pair_free((pointers_pair_t) * (void **)p);
41 }
42
43 /************************** Snapshot comparison *******************************/
44 /******************************************************************************/
45
46 static int already_compared_pointers(void *p1, void *p2){
47
48   if(xbt_dynar_is_empty(compared_pointers))
49     return -1;
50
51   unsigned int cursor = 0;
52   int start = 0;
53   int end = xbt_dynar_length(compared_pointers) - 1;
54   pointers_pair_t pair;
55
56   while(start <= end){
57     cursor = (start + end) / 2;
58     pair = (pointers_pair_t)xbt_dynar_get_as(compared_pointers, cursor, pointers_pair_t);
59     if(pair->p1 == p1){
60       if(pair->p2 == p2)
61         return 0;
62       else if(pair->p2 < p2)
63         start = cursor + 1;
64       else
65         end = cursor - 1;
66     }else if(pair->p1 < p1){
67       start = cursor + 1;
68     }else{
69       end = cursor - 1 ;
70     }
71   }
72
73   return -1;
74
75 }
76
77 static void add_compared_pointers(void *p1, void *p2){
78
79   pointers_pair_t new_pair = xbt_new0(s_pointers_pair_t, 1);
80   new_pair->p1 = p1;
81   new_pair->p2 = p2;
82   
83   if(xbt_dynar_is_empty(compared_pointers)){
84     xbt_dynar_push(compared_pointers, &new_pair);
85     return;
86   }
87
88   unsigned int cursor = 0;
89   int start = 0;
90   int end = xbt_dynar_length(compared_pointers) - 1;
91   pointers_pair_t pair = NULL;
92
93   while(start <= end){
94     cursor = (start + end) / 2;
95     pair = (pointers_pair_t)xbt_dynar_get_as(compared_pointers, cursor, pointers_pair_t);
96     if(pair->p1 == p1){
97       if(pair->p2 == p2){
98         pointers_pair_free(new_pair);
99         return;
100       }else if(pair->p2 < p2)
101         start = cursor + 1;
102       else
103         end = cursor - 1;
104     }else if(pair->p1 < p1){
105       start = cursor + 1;
106     }else{
107       end = cursor - 1 ;
108     }
109   }
110
111   if(pair->p1 == p1){
112     if(pair->p2 < p2)
113       xbt_dynar_insert_at(compared_pointers, cursor + 1, &new_pair);
114     else
115       xbt_dynar_insert_at(compared_pointers, cursor, &new_pair); 
116   }else{
117     if(pair->p1 < p1)
118       xbt_dynar_insert_at(compared_pointers, cursor + 1, &new_pair);
119     else
120       xbt_dynar_insert_at(compared_pointers, cursor, &new_pair);   
121   }
122
123 }
124
125 static int compare_areas_with_type(void *area1, void *area2, xbt_dict_t types, xbt_dict_t other_types, char *type_id, int region_size, int region_type, void *start_data, int pointer_level){
126
127   dw_type_t type = xbt_dict_get_or_null(types, type_id);;
128   unsigned int cursor = 0;
129   dw_type_t member, subtype, subsubtype;
130   int elm_size, i, res, switch_types = 0;
131   void *addr_pointed1, *addr_pointed2;
132
133   switch(type->type){
134   case DW_TAG_base_type:
135   case DW_TAG_enumeration_type:
136   case DW_TAG_union_type:
137     return (memcmp(area1, area2, type->byte_size) != 0);
138     break;
139   case DW_TAG_typedef:
140   case DW_TAG_volatile_type:
141   case DW_TAG_const_type:
142     return compare_areas_with_type(area1, area2, types, other_types, type->dw_type_id, region_size, region_type, start_data, pointer_level);
143     break;
144   case DW_TAG_array_type:
145     subtype = xbt_dict_get_or_null(types, type->dw_type_id);
146     switch(subtype->type){
147     case DW_TAG_base_type:
148     case DW_TAG_enumeration_type:
149     case DW_TAG_pointer_type:
150     case DW_TAG_structure_type:
151     case DW_TAG_union_type:
152       if(subtype->byte_size == 0){ /*declaration of the type, need the complete description */
153         subtype = xbt_dict_get_or_null(types, get_type_description(types, subtype->name));
154         if(subtype == NULL){
155           subtype = xbt_dict_get_or_null(other_types, get_type_description(other_types, subtype->name));
156           switch_types = 1;
157         }
158       }
159       elm_size = subtype->byte_size;
160       break;
161     case DW_TAG_const_type:
162     case DW_TAG_typedef:
163     case DW_TAG_volatile_type:
164       subsubtype = xbt_dict_get_or_null(types, subtype->dw_type_id);
165       if(subsubtype->byte_size == 0){ /*declaration of the type, need the complete description */
166         subsubtype = xbt_dict_get_or_null(types, get_type_description(types, subsubtype->name));
167         if(subsubtype == NULL){
168           subsubtype = xbt_dict_get_or_null(other_types, get_type_description(other_types, subsubtype->name));
169           switch_types = 1;
170         }
171       }
172       elm_size = subsubtype->byte_size;
173       break;
174     default : 
175       return 0;
176       break;
177     }
178     for(i=0; i<type->element_count; i++){
179       if(switch_types)
180         res = compare_areas_with_type((char *)area1 + (i*elm_size), (char *)area2 + (i*elm_size), other_types, types, type->dw_type_id, region_size, region_type, start_data, pointer_level);
181       else
182         res = compare_areas_with_type((char *)area1 + (i*elm_size), (char *)area2 + (i*elm_size), types, other_types, type->dw_type_id, region_size, region_type, start_data, pointer_level);
183       if(res == 1)
184         return res;
185     }
186     break;
187   case DW_TAG_pointer_type:
188     if(type->dw_type_id && ((dw_type_t)xbt_dict_get_or_null(types, type->dw_type_id))->type == DW_TAG_subroutine_type){
189       addr_pointed1 = *((void **)(area1)); 
190       addr_pointed2 = *((void **)(area2));
191       return (addr_pointed1 != addr_pointed2);
192     }else{
193       addr_pointed1 = *((void **)(area1)); 
194       addr_pointed2 = *((void **)(area2));
195       
196       if(addr_pointed1 == NULL && addr_pointed2 == NULL)
197         return 0;
198       if(already_compared_pointers(addr_pointed1, addr_pointed2) != -1)
199         return 0;
200       add_compared_pointers(addr_pointed1, addr_pointed2);
201
202       pointer_level++;
203       
204       // Some cases are not handled here:
205       // * the pointers lead to different areas (one to the heap, the other to the RW segment ...);
206       // * a pointer leads to the read-only segment of the current object;
207       // * a pointer lead to a different ELF object.
208
209       // The pointers are both in the heap:
210       if(addr_pointed1 > std_heap && (char *)addr_pointed1 < (char*) std_heap + STD_HEAP_SIZE
211         && addr_pointed2 > std_heap && (char *)addr_pointed2 < (char*) std_heap + STD_HEAP_SIZE){
212         return compare_heap_area(addr_pointed1, addr_pointed2, NULL, types, other_types, type->dw_type_id, pointer_level); 
213       }
214
215       // The pointers are both in the current object R/W segment:
216       else if(addr_pointed1 > start_data && (char*)addr_pointed1 <= (char *)start_data + region_size
217         && addr_pointed2 > start_data && (char*)addr_pointed2 <= (char *)start_data + region_size){
218         if(type->dw_type_id == NULL)
219           return  (addr_pointed1 != addr_pointed2);
220         else
221           return  compare_areas_with_type(addr_pointed1, addr_pointed2, types, other_types, type->dw_type_id, region_size, region_type, start_data, pointer_level); 
222       }
223
224       else{
225         return (addr_pointed1 != addr_pointed2);
226       }
227     }
228     break;
229   case DW_TAG_structure_type:
230     xbt_dynar_foreach(type->members, cursor, member){
231       res = compare_areas_with_type((char *)area1 + member->offset, (char *)area2 + member->offset, types, other_types, member->dw_type_id, region_size, region_type, start_data, pointer_level);
232       if(res == 1)
233         return res;
234     }
235     break;
236   case DW_TAG_subroutine_type:
237     return -1;
238     break;
239   default:
240     XBT_VERB("Unknown case : %d", type->type);
241     break;
242   }
243   
244   return 0;
245 }
246
247 static int compare_global_variables(int region_type, mc_mem_region_t r1, mc_mem_region_t r2){
248
249   if(!compared_pointers){
250     compared_pointers = xbt_dynar_new(sizeof(pointers_pair_t), pointers_pair_free_voidp);
251     MC_ignore_global_variable("compared_pointers");
252   }else{
253     xbt_dynar_reset(compared_pointers);
254   }
255
256   xbt_dynar_t variables;
257   xbt_dict_t types, other_types;
258   int res;
259   unsigned int cursor = 0;
260   dw_variable_t current_var;
261   size_t offset;
262   void *start_data;
263   void* start_data_binary = mc_binary_info->start_rw;
264   void* start_data_libsimgrid = mc_libsimgrid_info->start_rw;
265
266   mc_object_info_t object_info = NULL;
267   mc_object_info_t other_object_info = NULL;
268   if(region_type == 2){
269     object_info = mc_binary_info;
270     other_object_info = mc_libsimgrid_info;
271     start_data = start_data_binary;
272   }else{
273     object_info = mc_libsimgrid_info;
274     other_object_info = mc_binary_info;
275     start_data = start_data_libsimgrid;
276   }
277   variables = object_info->global_variables;
278   types = object_info->types;
279   other_types = other_object_info->types;
280
281   xbt_dynar_foreach(variables, cursor, current_var){
282
283     // If the variable is not in this object, skip it:
284     // We do not expect to find a pointer to something which is not reachable
285     // by the global variables.
286     if((char*) current_var->address.address < (char*) object_info->start_rw
287       || (char*) current_var->address.address > (char*) object_info->end_rw)
288        continue;
289
290     offset = (char *)current_var->address.address - (char *)object_info->start_rw;
291
292     res = compare_areas_with_type((char *)r1->data + offset, (char *)r2->data + offset, types, other_types, current_var->type_origin, r1->size, region_type, start_data, 0);
293     if(res == 1){
294       XBT_VERB("Global variable %s (%p - %p) is different between snapshots", current_var->name, (char *)r1->data + offset, (char *)r2->data + offset);
295       xbt_dynar_free(&compared_pointers);
296       compared_pointers = NULL;
297       return 1;
298     }
299
300   }
301
302   xbt_dynar_free(&compared_pointers);
303   compared_pointers = NULL;
304
305   return 0;
306
307 }
308
309 static int compare_local_variables(mc_snapshot_stack_t stack1, mc_snapshot_stack_t stack2, void *heap1, void *heap2){
310   void* start_data_binary = mc_binary_info->start_rw;
311   void* start_data_libsimgrid = mc_libsimgrid_info->start_rw;
312
313   if(!compared_pointers){
314     compared_pointers = xbt_dynar_new(sizeof(pointers_pair_t), pointers_pair_free_voidp);
315     MC_ignore_global_variable("compared_pointers");
316   }else{
317     xbt_dynar_reset(compared_pointers);
318   }
319
320   if(xbt_dynar_length(stack1->local_variables) != xbt_dynar_length(stack2->local_variables)){
321     XBT_VERB("Different number of local variables");
322     xbt_dynar_free(&compared_pointers);
323     compared_pointers = NULL;
324     return 1;
325   }else{
326     unsigned int cursor = 0;
327     local_variable_t current_var1, current_var2;
328     int offset1, offset2, res;
329     while(cursor < xbt_dynar_length(stack1->local_variables)){
330       current_var1 = (local_variable_t)xbt_dynar_get_as(stack1->local_variables, cursor, local_variable_t);
331       current_var2 = (local_variable_t)xbt_dynar_get_as(stack2->local_variables, cursor, local_variable_t);
332       if(strcmp(current_var1->name, current_var2->name) != 0 || strcmp(current_var1->frame, current_var2->frame) != 0 || current_var1->ip != current_var2->ip){
333         xbt_dynar_free(&compared_pointers);
334         XBT_VERB("Different name of variable (%s - %s) or frame (%s - %s) or ip (%lu - %lu)", current_var1->name, current_var2->name, current_var1->frame, current_var2->frame, current_var1->ip, current_var2->ip);
335         return 1;
336       }
337       offset1 = (char *)current_var1->address - (char *)std_heap;
338       offset2 = (char *)current_var2->address - (char *)std_heap;
339       if(current_var1->region == 1)
340         res = compare_areas_with_type( (char *)heap1 + offset1, (char *)heap2 + offset2, mc_libsimgrid_info->types, mc_binary_info->types, current_var1->type, 0, 1, start_data_libsimgrid, 0);
341       else
342         res = compare_areas_with_type( (char *)heap1 + offset1, (char *)heap2 + offset2, mc_binary_info->types, mc_libsimgrid_info->types, current_var1->type, 0, 2, start_data_binary, 0);
343       if(res == 1){
344         XBT_VERB("Local variable %s (%p - %p) in frame %s  is different between snapshots", current_var1->name,(char *)heap1 + offset1, (char *)heap2 + offset2, current_var1->frame);
345         xbt_dynar_free(&compared_pointers);
346         compared_pointers = NULL;
347         return res;
348       }
349       cursor++;
350     }
351     xbt_dynar_free(&compared_pointers);
352     compared_pointers = NULL;
353     return 0;
354   }
355 }
356
357 int snapshot_compare(void *state1, void *state2){
358
359   mc_snapshot_t s1, s2;
360   int num1, num2;
361   
362   if(_sg_mc_property_file && _sg_mc_property_file[0] != '\0'){ /* Liveness MC */
363     s1 = ((mc_visited_pair_t)state1)->graph_state->system_state;
364     s2 = ((mc_visited_pair_t)state2)->graph_state->system_state;
365     num1 = ((mc_visited_pair_t)state1)->num;
366     num2 =  ((mc_visited_pair_t)state2)->num;
367     /* Firstly compare automaton state */
368     /*if(xbt_automaton_state_compare(((mc_pair_t)state1)->automaton_state, ((mc_pair_t)state2)->automaton_state) != 0)
369       return 1;
370     if(xbt_automaton_propositional_symbols_compare_value(((mc_pair_t)state1)->atomic_propositions, ((mc_pair_t)state2)->atomic_propositions) != 0)
371     return 1;*/
372   }else{ /* Safety MC */
373     s1 = ((mc_visited_state_t)state1)->system_state;
374     s2 = ((mc_visited_state_t)state2)->system_state;
375     num1 = ((mc_visited_state_t)state1)->num;
376     num2 = ((mc_visited_state_t)state2)->num;
377   }
378
379   int errors = 0;
380   int res_init;
381
382   xbt_os_timer_t global_timer = xbt_os_timer_new();
383   xbt_os_timer_t timer = xbt_os_timer_new();
384
385   xbt_os_walltimer_start(global_timer);
386
387   #ifdef MC_DEBUG
388     xbt_os_walltimer_start(timer);
389   #endif
390
391   /* Compare size of stacks */
392   int i = 0;
393   size_t size_used1, size_used2;
394   int is_diff = 0;
395   while(i < xbt_dynar_length(s1->stacks)){
396     size_used1 = s1->stack_sizes[i];
397     size_used2 = s2->stack_sizes[i];
398     if(size_used1 != size_used2){
399     #ifdef MC_DEBUG
400       if(is_diff == 0){
401         xbt_os_walltimer_stop(timer);
402         mc_comp_times->stacks_sizes_comparison_time = xbt_os_timer_elapsed(timer);
403       }
404       XBT_DEBUG("(%d - %d) Different size used in stacks : %zu - %zu", num1, num2, size_used1, size_used2);
405       errors++;
406       is_diff = 1;
407     #else
408       #ifdef MC_VERBOSE
409       XBT_VERB("(%d - %d) Different size used in stacks : %zu - %zu", num1, num2, size_used1, size_used2);
410       #endif
411
412       xbt_os_walltimer_stop(timer);
413       xbt_os_timer_free(timer);
414       xbt_os_walltimer_stop(global_timer);
415       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
416       xbt_os_timer_free(global_timer);
417
418       return 1;
419     #endif  
420     }
421     i++;
422   }
423
424   #ifdef MC_DEBUG
425     if(is_diff == 0)
426       xbt_os_walltimer_stop(timer);
427     xbt_os_walltimer_start(timer);
428   #endif
429
430   /* Compare hash of global variables */
431   if(s1->hash_global != NULL && s2->hash_global != NULL){
432     if(strcmp(s1->hash_global, s2->hash_global) != 0){
433       #ifdef MC_DEBUG
434         xbt_os_walltimer_stop(timer);
435         mc_comp_times->hash_global_variables_comparison_time = xbt_os_timer_elapsed(timer);
436         XBT_DEBUG("Different hash of global variables : %s - %s", s1->hash_global, s2->hash_global); 
437         errors++; 
438       #else
439         #ifdef MC_VERBOSE
440           XBT_VERB("Different hash of global variables : %s - %s", s1->hash_global, s2->hash_global); 
441         #endif
442
443         xbt_os_walltimer_stop(timer);
444         xbt_os_timer_free(timer);
445         xbt_os_walltimer_stop(global_timer);
446         mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
447         xbt_os_timer_free(global_timer);
448
449         return 1;
450       #endif
451     }
452   }
453
454   #ifdef MC_DEBUG
455     xbt_os_walltimer_start(timer);
456   #endif
457
458   /* Compare hash of local variables */
459   if(s1->hash_local != NULL && s2->hash_local != NULL){
460     if(strcmp(s1->hash_local, s2->hash_local) != 0){
461       #ifdef MC_DEBUG
462         xbt_os_walltimer_stop(timer);
463         mc_comp_times->hash_local_variables_comparison_time = xbt_os_timer_elapsed(timer);
464         XBT_DEBUG("Different hash of local variables : %s - %s", s1->hash_local, s2->hash_local); 
465         errors++; 
466       #else
467         #ifdef MC_VERBOSE
468           XBT_VERB("Different hash of local variables : %s - %s", s1->hash_local, s2->hash_local); 
469         #endif
470
471         xbt_os_walltimer_stop(timer);
472         xbt_os_timer_free(timer);
473         xbt_os_walltimer_stop(global_timer);
474         mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
475         xbt_os_timer_free(global_timer);
476
477         return 1;
478       #endif
479     }
480   }
481
482   #ifdef MC_DEBUG
483     xbt_os_walltimer_start(timer);
484   #endif
485
486   /* Init heap information used in heap comparison algorithm */
487   res_init = init_heap_information((xbt_mheap_t)s1->regions[0]->data, (xbt_mheap_t)s2->regions[0]->data, s1->to_ignore, s2->to_ignore);
488   if(res_init == -1){
489      #ifdef MC_DEBUG
490     XBT_DEBUG("(%d - %d) Different heap information", num1, num2); 
491         errors++; 
492       #else
493         #ifdef MC_VERBOSE
494         XBT_VERB("(%d - %d) Different heap information", num1, num2); 
495         #endif
496
497         xbt_os_walltimer_stop(global_timer);
498         mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
499         xbt_os_timer_free(global_timer);
500
501         return 1;
502       #endif
503   }
504
505   #ifdef MC_DEBUG
506     xbt_os_walltimer_start(timer);
507   #endif
508
509   /* Stacks comparison */
510   unsigned int  cursor = 0;
511   int diff_local = 0;
512   is_diff = 0;
513   mc_snapshot_stack_t stack1, stack2;
514     
515   while(cursor < xbt_dynar_length(s1->stacks)){
516     stack1 = (mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t);
517     stack2 = (mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t);
518     diff_local = compare_local_variables(stack1, stack2, s1->regions[0]->data, s2->regions[0]->data);
519     if(diff_local > 0){
520       #ifdef MC_DEBUG
521         if(is_diff == 0){
522           xbt_os_walltimer_stop(timer);
523           mc_comp_times->stacks_comparison_time = xbt_os_timer_elapsed(timer);
524         }
525         XBT_DEBUG("(%d - %d) Different local variables between stacks %d", num1, num2, cursor + 1);
526         errors++;
527         is_diff = 1;
528       #else
529         
530         #ifdef MC_VERBOSE
531         XBT_VERB("(%d - %d) Different local variables between stacks %d", num1, num2, cursor + 1);
532         #endif
533           
534         reset_heap_information();
535         xbt_os_walltimer_stop(timer);
536         xbt_os_timer_free(timer);
537         xbt_os_walltimer_stop(global_timer);
538         mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
539         xbt_os_timer_free(global_timer);
540  
541         return 1;
542       #endif
543     }
544     cursor++;
545   }
546
547
548
549  const char* names[3] = { "?", "libsimgrid", "binary" };
550 #ifdef MC_DEBUG
551  double *times[3] = {
552    NULL,
553    &mc_comp_times->libsimgrid_global_variables_comparison_time,
554    &mc_comp_times->binary_global_variables_comparison_time
555  };
556 #endif
557
558  int k=0;
559  for(k=2; k!=0; --k) {
560     #ifdef MC_DEBUG
561       if(is_diff == 0)
562         xbt_os_walltimer_stop(timer);
563       xbt_os_walltimer_start(timer);
564     #endif
565
566   /* Compare global variables */
567   is_diff = compare_global_variables(k, s1->regions[k], s2->regions[k]);
568   if(is_diff != 0){
569     #ifdef MC_DEBUG
570       xbt_os_walltimer_stop(timer);
571       *times[k] = xbt_os_timer_elapsed(timer);
572       XBT_DEBUG("(%d - %d) Different global variables in %s", num1, num2, names[k]);
573       errors++;
574     #else
575       #ifdef MC_VERBOSE
576       XBT_VERB("(%d - %d) Different global variables in %s", num1, num2, names[k]);
577       #endif
578
579       reset_heap_information();
580       xbt_os_walltimer_stop(timer);
581       xbt_os_timer_free(timer);
582       xbt_os_walltimer_stop(global_timer);
583       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
584       xbt_os_timer_free(global_timer);
585
586       return 1;
587     #endif
588   }
589  }
590
591   #ifdef MC_DEBUG
592     xbt_os_walltimer_start(timer);
593   #endif
594
595   /* Compare heap */
596     if(mmalloc_compare_heap((xbt_mheap_t)s1->regions[0]->data,
597                             (xbt_mheap_t)s2->regions[0]->data,
598                             mc_libsimgrid_info->types,
599                             mc_binary_info->types) > 0){
600
601     #ifdef MC_DEBUG
602       xbt_os_walltimer_stop(timer);
603       mc_comp_times->heap_comparison_time = xbt_os_timer_elapsed(timer); 
604       XBT_DEBUG("(%d - %d) Different heap (mmalloc_compare)", num1, num2);
605       errors++;
606     #else
607  
608       #ifdef MC_VERBOSE
609       XBT_VERB("(%d - %d) Different heap (mmalloc_compare)", num1, num2);
610       #endif
611        
612       reset_heap_information();
613       xbt_os_walltimer_stop(timer);
614       xbt_os_timer_free(timer);
615       xbt_os_walltimer_stop(global_timer);
616       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
617       xbt_os_timer_free(global_timer);
618
619       return 1;
620     #endif
621   }else{
622     #ifdef MC_DEBUG
623       xbt_os_walltimer_stop(timer);
624     #endif
625   }
626
627   reset_heap_information();
628   
629   xbt_os_walltimer_stop(timer);
630   xbt_os_timer_free(timer);
631
632   #ifdef MC_VERBOSE
633     xbt_os_walltimer_stop(global_timer);
634     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
635   #endif
636
637   xbt_os_timer_free(global_timer);
638
639   #ifdef MC_DEBUG
640     print_comparison_times();
641   #endif
642
643   return errors > 0;
644   
645 }
646
647 /***************************** Statistics *****************************/
648 /*******************************************************************/
649
650 void print_comparison_times(){
651   XBT_DEBUG("*** Comparison times ***");
652   XBT_DEBUG("- Nb processes : %f", mc_comp_times->nb_processes_comparison_time);
653   XBT_DEBUG("- Nb bytes used : %f", mc_comp_times->bytes_used_comparison_time);
654   XBT_DEBUG("- Stacks sizes : %f", mc_comp_times->stacks_sizes_comparison_time);
655   XBT_DEBUG("- Binary global variables : %f", mc_comp_times->binary_global_variables_comparison_time);
656   XBT_DEBUG("- Libsimgrid global variables : %f", mc_comp_times->libsimgrid_global_variables_comparison_time);
657   XBT_DEBUG("- Heap : %f", mc_comp_times->heap_comparison_time);
658   XBT_DEBUG("- Stacks : %f", mc_comp_times->stacks_comparison_time);
659 }
660
661 /**************************** MC snapshot compare simcall **************************/
662 /***********************************************************************************/
663
664 int SIMIX_pre_mc_compare_snapshots(smx_simcall_t simcall,
665                                    mc_snapshot_t s1, mc_snapshot_t s2){
666   return snapshot_compare(s1, s2);
667 }
668
669 int MC_compare_snapshots(void *s1, void *s2){
670   
671   MC_ignore_local_variable("self", "simcall_BODY_mc_snapshot");
672   return simcall_mc_compare_snapshots(s1, s2);
673
674 }