Logo AND Algorithmique Numérique Distribuée

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