Logo AND Algorithmique Numérique Distribuée

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