Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : get hash of local and global variables which are not pointers
[simgrid.git] / src / mc / mc_compare.c
1 /* Copyright (c) 2008-2012 Da SimGrid Team. All rights reserved.            */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "mc_private.h"
7
8 #include "xbt/mmalloc.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, mc,
11                                 "Logging specific to mc_compare");
12
13 static int heap_region_compare(void *d1, void *d2, size_t size);
14
15 static int is_heap_equality(xbt_dynar_t equals, void *a1, void *a2);
16 static size_t heap_ignore_size(void *address);
17
18 static void stack_region_free(stack_region_t s);
19 static void heap_equality_free(heap_equality_t e);
20
21 static int is_stack_ignore_variable(char *frame, char *var_name);
22 static int compare_local_variables(char *s1, char *s2);
23 static int compare_global_variables(int region_type, void *d1, void *d2);
24
25 static size_t heap_ignore_size(void *address){
26   unsigned int cursor = 0;
27   int start = 0;
28   int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
29   mc_heap_ignore_region_t region;
30
31   while(start <= end){
32     cursor = (start + end) / 2;
33     region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
34     if(region->address == address)
35       return region->size;
36     if(region->address < address)
37       start = cursor + 1;
38     if(region->address > address)
39       end = cursor - 1;   
40   }
41
42   return 0;
43 }
44
45 static int compare_global_variables(int region_type, void *d1, void *d2){
46
47   unsigned int cursor = 0;
48   size_t offset; 
49   int i = 0;
50   global_variable_t current_var; 
51   int pointer_align; 
52   void *addr_pointed1 = NULL, *addr_pointed2 = NULL;
53   int res_compare = 0;
54
55   if(region_type == 1){ /* libsimgrid */
56     xbt_dynar_foreach(mc_global_variables, cursor, current_var){
57       if(current_var->address < start_data_libsimgrid)
58         continue;
59       offset = (char *)current_var->address - (char *)start_data_libsimgrid;
60       i = 0;
61       while(i < current_var->size){
62         if(memcmp((char*)d1 + offset + i, (char*)d2 + offset + i, 1) != 0){
63           pointer_align = (i / sizeof(void*)) * sizeof(void*); 
64           addr_pointed1 = *((void **)((char *)d1 + offset + pointer_align));
65           addr_pointed2 = *((void **)((char *)d2 + offset + pointer_align));
66           if((addr_pointed1 > start_plt_libsimgrid && addr_pointed1 < end_plt_libsimgrid) 
67              || (addr_pointed2 > start_plt_libsimgrid && addr_pointed2 < end_plt_libsimgrid)){
68             i = current_var->size;
69             continue;
70           }else{
71             if((addr_pointed1 > std_heap) && ((char *)addr_pointed1 < (char *)std_heap + STD_HEAP_SIZE) 
72                && (addr_pointed2 > std_heap) && ((char *)addr_pointed2 < (char *)std_heap + STD_HEAP_SIZE)){
73               res_compare = compare_area(addr_pointed1, addr_pointed2, NULL);
74               if(res_compare == 1){
75                 #ifdef MC_VERBOSE
76                   XBT_VERB("Different global variable in libsimgrid : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
77                 #endif
78                 return 1;
79               }
80             }else{
81               #ifdef MC_VERBOSE
82                 XBT_VERB("Different global variable in libsimgrid : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
83               #endif
84               return 1;
85             }
86            
87           }
88         } 
89         i++;
90       }
91     }
92   }else{ /* binary */
93     xbt_dynar_foreach(mc_global_variables, cursor, current_var){
94       if(current_var->address > start_data_libsimgrid)
95         break;
96       offset = (char *)current_var->address - (char *)start_data_binary;
97       i = 0;
98       while(i < current_var->size){
99         if(memcmp((char*)d1 + offset + i, (char*)d2 + offset + i, 1) != 0){
100           pointer_align = (i / sizeof(void*)) * sizeof(void*); 
101           addr_pointed1 = *((void **)((char *)d1 + offset + pointer_align));
102           addr_pointed2 = *((void **)((char *)d2 + offset + pointer_align));
103           if((addr_pointed1 > start_plt_binary && addr_pointed1 < end_plt_binary) || (addr_pointed2 > start_plt_binary && addr_pointed2 < end_plt_binary)){
104             i = current_var->size;
105             continue;
106           }else{
107             if((addr_pointed1 > std_heap) && ((char *)addr_pointed1 < (char *)std_heap + STD_HEAP_SIZE) && (addr_pointed2 > std_heap) && ((char *)addr_pointed2 < (char *)std_heap + STD_HEAP_SIZE)){
108               res_compare = compare_area(addr_pointed1, addr_pointed2, NULL);
109               if(res_compare == 1){
110                 #ifdef MC_VERBOSE
111                   XBT_VERB("Different global variable in binary : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
112                 #endif
113                 return 1;
114               }
115             }else{
116               #ifdef MC_VERBOSE
117                 XBT_VERB("Different global variable in binary : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
118               #endif
119               return 1;
120             }
121           }
122         } 
123         i++;
124       }
125       
126     }
127   }
128
129   return 0;
130 }
131
132 static int heap_region_compare(void *d1, void *d2, size_t size){
133   
134   size_t i = 0;
135   
136   for(i=0; i<size; i++){
137     if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
138       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose)){
139         XBT_VERB("Different byte (offset=%zu) (%p - %p) in heap region", i, (char *)d1 + i, (char *)d2 + i);
140       }
141       return 1;
142     }
143   }
144   
145   return 0;
146 }
147
148 static void stack_region_free(stack_region_t s){
149   if(s){
150     xbt_free(s->process_name);
151     xbt_free(s);
152   }
153 }
154
155 void stack_region_free_voidp(void *s){
156   stack_region_free((stack_region_t) * (void **) s);
157 }
158
159 static void heap_equality_free(heap_equality_t e){
160   xbt_free(e);
161 }
162
163 void heap_equality_free_voidp(void *e){
164   heap_equality_free((heap_equality_t) * (void **) e);
165 }
166
167 int SIMIX_pre_mc_compare_snapshots(smx_simcall_t simcall,
168                                    mc_snapshot_t s1, mc_snapshot_t s2){
169   return snapshot_compare(s1, s2);
170 }
171
172 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
173
174   int raw_mem = (mmalloc_get_current_heap() == raw_heap);
175   
176   MC_SET_RAW_MEM;
177      
178   int errors = 0;
179
180   xbt_os_timer_t global_timer = xbt_os_timer_new();
181   xbt_os_timer_t timer = xbt_os_timer_new();
182
183   xbt_os_timer_start(global_timer);
184
185   #ifdef MC_DEBUG
186     xbt_os_timer_start(timer);
187   #endif
188
189   /* Compare number of processes */
190   if(s1->nb_processes != s2->nb_processes){
191     #ifdef MC_DEBUG
192       xbt_os_timer_stop(timer);
193       mc_comp_times->nb_processes_comparison_time =  xbt_os_timer_elapsed(timer);
194       XBT_DEBUG("Different number of processes : %d - %d", s1->nb_processes, s2->nb_processes);
195       errors++;
196     #else
197       #ifdef MC_VERBOSE
198         XBT_VERB("Different number of processes : %d - %d", s1->nb_processes, s2->nb_processes);
199       #endif
200      
201       xbt_os_timer_free(timer);
202       xbt_os_timer_stop(global_timer);
203       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
204       xbt_os_timer_free(global_timer);
205
206       if(!raw_mem)
207         MC_UNSET_RAW_MEM;
208
209       return 1;
210     #endif
211   }
212
213   #ifdef MC_DEBUG
214     xbt_os_timer_start(timer);
215   #endif
216
217   /* Compare number of bytes used in each heap */
218   if(s1->heap_bytes_used != s2->heap_bytes_used){
219     #ifdef MC_DEBUG
220       xbt_os_timer_stop(timer);
221       mc_comp_times->bytes_used_comparison_time = xbt_os_timer_elapsed(timer);
222       XBT_DEBUG("Different number of bytes used in each heap : %zu - %zu", s1->heap_bytes_used, s2->heap_bytes_used);
223       errors++;
224     #else
225       #ifdef MC_VERBOSE
226         XBT_VERB("Different number of bytes used in each heap : %zu - %zu", s1->heap_bytes_used, s2->heap_bytes_used);
227       #endif
228
229       xbt_os_timer_free(timer);
230       xbt_os_timer_stop(global_timer);
231       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
232       xbt_os_timer_free(global_timer);
233
234       if(!raw_mem)
235         MC_UNSET_RAW_MEM;
236
237       return 1;
238     #endif
239   }else{
240     #ifdef MC_DEBUG
241       xbt_os_timer_stop(timer);
242     #endif
243   }
244   
245   #ifdef MC_DEBUG
246     xbt_os_timer_start(timer);
247   #endif
248   
249   /* Compare size of stacks */
250   int i = 0;
251   size_t size_used1, size_used2;
252   int is_diff = 0;
253   while(i < xbt_dynar_length(s1->stacks)){
254     size_used1 = s1->stack_sizes[i];
255     size_used2 = s2->stack_sizes[i];
256     if(size_used1 != size_used2){
257     #ifdef MC_DEBUG
258       if(is_diff == 0){
259         xbt_os_timer_stop(timer);
260         mc_comp_times->stacks_sizes_comparison_time = xbt_os_timer_elapsed(timer);
261       }
262       XBT_DEBUG("Different size used in stacks : %zu - %zu", size_used1, size_used2);
263       errors++;
264       is_diff = 1;
265     #else
266       #ifdef MC_VERBOSE
267         XBT_VERB("Different size used in stacks : %zu - %zu", size_used1, size_used2);
268       #endif
269  
270       xbt_os_timer_free(timer);
271       xbt_os_timer_stop(global_timer);
272       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
273       xbt_os_timer_free(global_timer);
274
275       if(!raw_mem)
276         MC_UNSET_RAW_MEM;
277
278       return 1;
279     #endif  
280     }
281     i++;
282   }
283
284   #ifdef MC_DEBUG
285     if(is_diff == 0)
286       xbt_os_timer_stop(timer);
287     xbt_os_timer_start(timer);
288   #endif
289
290   /* Compare hash of global variables */
291   if(s1->hash_global != NULL && s2->hash_global != NULL){
292     if(strcmp(s1->hash_global, s2->hash_global) != 0){
293       #ifdef MC_DEBUG
294         xbt_os_timer_stop(timer);
295         mc_comp_times->hash_global_variables_comparison_time = xbt_os_timer_elapsed(timer);
296         XBT_DEBUG("Different hash of global variables : %s - %s", s1->hash_global, s2->hash_global); 
297         errors++; 
298       #else
299         #ifdef MC_VERBOSE
300           XBT_VERB("Different hash of global variables : %s - %s", s1->hash_global, s2->hash_global); 
301         #endif
302     
303         xbt_os_timer_free(timer);
304         xbt_os_timer_stop(global_timer);
305         mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
306         xbt_os_timer_free(global_timer);
307     
308         if(!raw_mem)
309           MC_UNSET_RAW_MEM;
310
311         return 1;
312       #endif
313     }
314   }
315
316   #ifdef MC_DEBUG
317     xbt_os_timer_start(timer);
318   #endif
319
320   /* Compare hash of local variables */
321   if(s1->hash_local != NULL && s2->hash_local != NULL){
322     if(strcmp(s1->hash_local, s2->hash_local) != 0){
323       #ifdef MC_DEBUG
324         xbt_os_timer_stop(timer);
325         mc_comp_times->hash_local_variables_comparison_time = xbt_os_timer_elapsed(timer);
326         XBT_DEBUG("Different hash of local variables : %s - %s", s1->hash_local, s2->hash_local); 
327         errors++; 
328       #else
329         #ifdef MC_VERBOSE
330           XBT_VERB("Different hash of local variables : %s - %s", s1->hash_local, s2->hash_local); 
331         #endif
332     
333         xbt_os_timer_free(timer);
334         xbt_os_timer_stop(global_timer);
335         mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
336         xbt_os_timer_free(global_timer);
337         
338         if(!raw_mem)
339           MC_UNSET_RAW_MEM;
340         
341         return 1;
342       #endif
343     }
344   }
345
346   #ifdef MC_DEBUG
347     xbt_os_timer_start(timer);
348   #endif
349
350   /* Init heap information used in heap comparison algorithm */
351   init_heap_information((xbt_mheap_t)s1->regions[0]->data, (xbt_mheap_t)s2->regions[0]->data, s1->to_ignore, s2->to_ignore);
352
353   /* Compare binary global variables */
354   is_diff = compare_global_variables(2, s1->regions[2]->data, s2->regions[2]->data);
355   if(is_diff != 0){
356     #ifdef MC_DEBUG
357       xbt_os_timer_stop(timer);
358       mc_comp_times->binary_global_variables_comparison_time = xbt_os_timer_elapsed(timer);
359       XBT_DEBUG("Different global variables in binary"); 
360       errors++; 
361     #else
362       #ifdef MC_VERBOSE
363         XBT_VERB("Different global variables in binary"); 
364       #endif
365     
366       reset_heap_information();
367       xbt_os_timer_free(timer);
368       xbt_os_timer_stop(global_timer);
369       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
370       xbt_os_timer_free(global_timer);
371     
372       if(!raw_mem)
373         MC_UNSET_RAW_MEM;
374
375       return 1;
376     #endif
377   }
378
379   #ifdef MC_DEBUG
380     if(is_diff == 0)
381       xbt_os_timer_stop(timer);
382     xbt_os_timer_start(timer);
383   #endif
384
385   /* Compare libsimgrid global variables */
386   is_diff = compare_global_variables(1, s1->regions[1]->data, s2->regions[1]->data);
387   if(is_diff != 0){
388     #ifdef MC_DEBUG
389       xbt_os_timer_stop(timer);
390       mc_comp_times->libsimgrid_global_variables_comparison_time = xbt_os_timer_elapsed(timer); 
391       XBT_DEBUG("Different global variables in libsimgrid"); 
392       errors++; 
393     #else
394       #ifdef MC_VERBOSE
395         XBT_VERB("Different global variables in libsimgrid"); 
396       #endif
397         
398       reset_heap_information();
399       xbt_os_timer_free(timer);
400       xbt_os_timer_stop(global_timer);
401       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
402       xbt_os_timer_free(global_timer);
403     
404       if(!raw_mem)
405         MC_UNSET_RAW_MEM;
406
407       return 1;
408     #endif
409   }  
410
411   #ifdef MC_DEBUG
412     if(is_diff == 0)
413       xbt_os_timer_stop(timer);
414     xbt_os_timer_start(timer);
415   #endif
416
417     /* Stacks comparison */
418     unsigned int  cursor = 0;
419     int diff_local = 0;
420     is_diff = 0;
421     
422     while(cursor < xbt_dynar_length(s1->stacks)){
423       diff_local = compare_local_variables(((mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t))->local_variables->data, ((mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t))->local_variables->data);
424       if(diff_local > 0){
425         #ifdef MC_DEBUG
426           if(is_diff == 0){
427             xbt_os_timer_stop(timer);
428             mc_comp_times->stacks_comparison_time = xbt_os_timer_elapsed(timer); 
429           }
430           XBT_DEBUG("Different local variables between stacks %d", cursor + 1);
431           errors++;
432           is_diff = 1;
433         #else
434         
435           #ifdef MC_VERBOSE
436             XBT_VERB("Different local variables between stacks %d", cursor + 1);
437           #endif
438           
439             reset_heap_information();
440             xbt_os_timer_free(timer);
441             xbt_os_timer_stop(global_timer);
442             mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
443             xbt_os_timer_free(global_timer);
444             
445             if(!raw_mem)
446               MC_UNSET_RAW_MEM;
447             
448             return 1;
449         #endif
450       }
451       cursor++;
452     }
453     
454     #ifdef MC_DEBUG
455       xbt_os_timer_start(timer);
456     #endif
457
458   /* Compare heap */
459  
460   if(mmalloc_compare_heap((xbt_mheap_t)s1->regions[0]->data, (xbt_mheap_t)s2->regions[0]->data)){
461
462     #ifdef MC_DEBUG
463       xbt_os_timer_stop(timer);
464       mc_comp_times->heap_comparison_time = xbt_os_timer_elapsed(timer); 
465       XBT_DEBUG("Different heap (mmalloc_compare)");
466       errors++;
467     #else
468
469       xbt_os_timer_free(timer);
470  
471       #ifdef MC_VERBOSE
472         XBT_VERB("Different heap (mmalloc_compare)");
473       #endif
474        
475       reset_heap_information();
476       xbt_os_timer_stop(global_timer);
477       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
478       xbt_os_timer_free(global_timer);
479
480       if(!raw_mem)
481         MC_UNSET_RAW_MEM;
482
483       return 1;
484     #endif
485   }else{
486     #ifdef MC_DEBUG
487       xbt_os_timer_stop(timer);
488     #endif
489   }
490
491   reset_heap_information();
492    
493   xbt_os_timer_free(timer);
494
495   #ifdef MC_VERBOSE
496     xbt_os_timer_stop(global_timer);
497     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
498   #endif
499
500   xbt_os_timer_free(global_timer);
501
502   #ifdef MC_DEBUG
503     print_comparison_times();
504   #endif
505
506   if(!raw_mem)
507     MC_UNSET_RAW_MEM;
508
509   return errors > 0;
510   
511 }
512
513 static int is_stack_ignore_variable(char *frame, char *var_name){
514
515   unsigned int cursor = 0;
516   int start = 0;
517   int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
518   mc_stack_ignore_variable_t current_var;
519
520   while(start <= end){
521     cursor = (start + end) / 2;
522     current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
523     if(strcmp(current_var->frame, frame) == 0 || strcmp(current_var->frame, "*") == 0){
524       if(strcmp(current_var->var_name, var_name) == 0)
525         return 1;
526       if(strcmp(current_var->var_name, var_name) < 0)
527         start = cursor + 1;
528       if(strcmp(current_var->var_name, var_name) > 0)
529         end = cursor - 1;
530     }else if(strcmp(current_var->frame, frame) < 0){
531       start = cursor + 1;
532     }else if(strcmp(current_var->frame, frame) > 0){
533       end = cursor - 1; 
534     }
535   }
536
537   return 0;
538 }
539
540 static int compare_local_variables(char *s1, char *s2){
541   
542   xbt_dynar_t tokens1 = xbt_str_split(s1, NULL);
543   xbt_dynar_t tokens2 = xbt_str_split(s2, NULL);
544
545   xbt_dynar_t s_tokens1, s_tokens2;
546   unsigned int cursor = 0;
547   void *addr1, *addr2;
548   char *frame_name1 = NULL, *frame_name2 = NULL;
549   int res_compare = 0;
550
551   #ifdef MC_VERBOSE
552     char *var_name;
553   #endif
554
555   while(cursor < xbt_dynar_length(tokens1)){
556     s_tokens1 = xbt_str_split(xbt_dynar_get_as(tokens1, cursor, char *), "=");
557     s_tokens2 = xbt_str_split(xbt_dynar_get_as(tokens2, cursor, char *), "=");
558     if(xbt_dynar_length(s_tokens1) > 1 && xbt_dynar_length(s_tokens2) > 1){
559       #ifdef MC_VERBOSE
560         var_name = xbt_dynar_get_as(s_tokens1, 0, char *);
561       #endif
562       if((strcmp(xbt_dynar_get_as(s_tokens1, 0, char *), "frame_name") == 0) && (strcmp(xbt_dynar_get_as(s_tokens2, 0, char *), "frame_name") == 0)){
563         xbt_free(frame_name1);
564         xbt_free(frame_name2);
565         frame_name1 = strdup(xbt_dynar_get_as(s_tokens1, 1, char *));
566         frame_name2 = strdup(xbt_dynar_get_as(s_tokens2, 1, char *));
567       }
568       addr1 = (void *) strtoul(xbt_dynar_get_as(s_tokens1, 1, char *), NULL, 16);
569       addr2 = (void *) strtoul(xbt_dynar_get_as(s_tokens2, 1, char *), NULL, 16);
570       if(addr1 > std_heap && (char *)addr1 <= (char *)std_heap + STD_HEAP_SIZE && addr2 > std_heap && (char *)addr2 <= (char *)std_heap + STD_HEAP_SIZE){
571         res_compare = compare_area(addr1, addr2, NULL);
572         if(res_compare == 1){
573           if(is_stack_ignore_variable(frame_name1, xbt_dynar_get_as(s_tokens1, 0, char *)) && is_stack_ignore_variable(frame_name2, xbt_dynar_get_as(s_tokens2, 0, char *))){
574             xbt_dynar_free(&s_tokens1);
575             xbt_dynar_free(&s_tokens2);
576             cursor++;
577             continue;
578           }else {
579             #ifdef MC_VERBOSE
580               XBT_VERB("Different local variable : %s at addresses %p - %p", var_name, addr1, addr2);
581             #endif
582             xbt_dynar_free(&s_tokens1);
583             xbt_dynar_free(&s_tokens2);
584             xbt_dynar_free(&tokens1);
585             xbt_dynar_free(&tokens2);
586             xbt_free(frame_name1);
587             xbt_free(frame_name2);
588             return 1;
589           }
590         }
591       }else{
592         if(strcmp(xbt_dynar_get_as(s_tokens1, 1, char *), xbt_dynar_get_as(s_tokens2, 1, char *)) != 0){
593           if(is_stack_ignore_variable(frame_name1, xbt_dynar_get_as(s_tokens1, 0, char *)) && is_stack_ignore_variable(frame_name2, xbt_dynar_get_as(s_tokens2, 0, char *))){
594             xbt_dynar_free(&s_tokens1);
595             xbt_dynar_free(&s_tokens2);
596             cursor++;
597             continue;
598           }else {
599             #ifdef MC_VERBOSE
600               XBT_VERB("Different local variable : %s (%s - %s)", var_name, xbt_dynar_get_as(s_tokens1, 1, char *), xbt_dynar_get_as(s_tokens2, 1, char *));
601             #endif
602             xbt_dynar_free(&s_tokens1);
603             xbt_dynar_free(&s_tokens2);
604             xbt_dynar_free(&tokens1);
605             xbt_dynar_free(&tokens2);
606             xbt_free(frame_name1);
607             xbt_free(frame_name2);
608             return 1;
609           }
610         }
611       }
612     }
613     xbt_dynar_free(&s_tokens1);
614     xbt_dynar_free(&s_tokens2);
615          
616     cursor++;
617   }
618
619   xbt_free(frame_name1);
620   xbt_free(frame_name2);
621   xbt_dynar_free(&tokens1);
622   xbt_dynar_free(&tokens2);
623   return 0;
624   
625 }
626
627 static int is_heap_equality(xbt_dynar_t equals, void *a1, void *a2){
628
629   unsigned int cursor = 0;
630   int start = 0;
631   int end = xbt_dynar_length(equals) - 1;
632   heap_equality_t current_equality;
633
634   while(start <= end){
635     cursor = (start + end) / 2;
636     current_equality = (heap_equality_t)xbt_dynar_get_as(equals, cursor, heap_equality_t);
637     if(current_equality->address1 == a1){
638       if(current_equality->address2 == a2)
639         return 1;
640       if(current_equality->address2 < a2)
641         start = cursor + 1;
642       if(current_equality->address2 > a2)
643         end = cursor - 1;
644     }
645     if(current_equality->address1 < a1)
646       start = cursor + 1;
647     if(current_equality->address1 > a1)
648       end = cursor - 1; 
649   }
650
651   return 0;
652
653 }
654
655 int MC_compare_snapshots(void *s1, void *s2){
656   
657   MC_ignore_stack("self", "simcall_BODY_mc_snapshot");
658
659   return simcall_mc_compare_snapshots(s1, s2);
660
661 }
662
663 void print_comparison_times(){
664   XBT_DEBUG("*** Comparison times ***");
665   XBT_DEBUG("- Nb processes : %f", mc_comp_times->nb_processes_comparison_time);
666   XBT_DEBUG("- Nb bytes used : %f", mc_comp_times->bytes_used_comparison_time);
667   XBT_DEBUG("- Stacks sizes : %f", mc_comp_times->stacks_sizes_comparison_time);
668   XBT_DEBUG("- Binary global variables : %f", mc_comp_times->binary_global_variables_comparison_time);
669   XBT_DEBUG("- Libsimgrid global variables : %f", mc_comp_times->libsimgrid_global_variables_comparison_time);
670   XBT_DEBUG("- Heap : %f", mc_comp_times->heap_comparison_time);
671   XBT_DEBUG("- Stacks : %f", mc_comp_times->stacks_comparison_time);
672 }