Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
66e8f811ccc55e0d5ea5938547662da5a8b5c3f9
[simgrid.git] / src / mc / mc_global.c
1 /* Copyright (c) 2008-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <unistd.h>
8 #include <sys/types.h>
9 #include <sys/wait.h>
10 #include <sys/time.h>
11 #include <sys/mman.h>
12 #include <libgen.h>
13
14 #define UNW_LOCAL_ONLY
15 #include <libunwind.h>
16
17 #include "simgrid/sg_config.h"
18 #include "../surf/surf_private.h"
19 #include "../simix/smx_private.h"
20 #include "xbt/fifo.h"
21 #include "xbt/automaton.h"
22 #include "xbt/dict.h"
23
24 #ifdef HAVE_MC
25 #include "../xbt/mmalloc/mmprivate.h"
26 #include "mc_private.h"
27 #endif
28 #include "mc_record.h"
29
30 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc,
31                                 "Logging specific to MC (global)");
32
33 double *mc_time = NULL;
34
35 #ifdef HAVE_MC
36 int user_max_depth_reached = 0;
37
38 /* MC global data structures */
39 mc_state_t mc_current_state = NULL;
40 char mc_replay_mode = FALSE;
41
42 __thread mc_comparison_times_t mc_comp_times = NULL;
43 __thread double mc_snapshot_comparison_time;
44 mc_stats_t mc_stats = NULL;
45 mc_global_t initial_global_state = NULL;
46 xbt_fifo_t mc_stack = NULL;
47
48 /* Liveness */
49 xbt_automaton_t _mc_property_automaton = NULL;
50
51 /* Variables */
52 mc_object_info_t mc_libsimgrid_info = NULL;
53 mc_object_info_t mc_binary_info = NULL;
54
55 mc_object_info_t mc_object_infos[2] = { NULL, NULL };
56
57 size_t mc_object_infos_size = 2;
58
59 /* Dot output */
60 FILE *dot_output = NULL;
61 const char *colors[13];
62
63
64 /*******************************  Initialisation of MC *******************************/
65 /*********************************************************************************/
66
67 static void MC_init_dot_output()
68 {                               /* FIXME : more colors */
69
70   colors[0] = "blue";
71   colors[1] = "red";
72   colors[2] = "green3";
73   colors[3] = "goldenrod";
74   colors[4] = "brown";
75   colors[5] = "purple";
76   colors[6] = "magenta";
77   colors[7] = "turquoise4";
78   colors[8] = "gray25";
79   colors[9] = "forestgreen";
80   colors[10] = "hotpink";
81   colors[11] = "lightblue";
82   colors[12] = "tan";
83
84   dot_output = fopen(_sg_mc_dot_output_file, "w");
85
86   if (dot_output == NULL) {
87     perror("Error open dot output file");
88     xbt_abort();
89   }
90
91   fprintf(dot_output,
92           "digraph graphname{\n fixedsize=true; rankdir=TB; ranksep=.25; edge [fontsize=12]; node [fontsize=10, shape=circle,width=.5 ]; graph [resolution=20, fontsize=10];\n");
93
94 }
95
96 static void MC_init_debug_info(void)
97 {
98   XBT_INFO("Get debug information ...");
99
100   memory_map_t maps = MC_get_memory_map();
101
102   /* Get local variables for state equality detection */
103   mc_binary_info = MC_find_object_info(maps, xbt_binary_name, 1);
104   mc_object_infos[0] = mc_binary_info;
105
106   mc_libsimgrid_info = MC_find_object_info(maps, libsimgrid_path, 0);
107   mc_object_infos[1] = mc_libsimgrid_info;
108
109   // Use information of the other objects:
110   MC_post_process_object_info(mc_binary_info);
111   MC_post_process_object_info(mc_libsimgrid_info);
112
113   MC_free_memory_map(maps);
114   XBT_INFO("Get debug information done !");
115 }
116
117
118 mc_model_checker_t mc_model_checker = NULL;
119
120 mc_model_checker_t MC_model_checker_new()
121 {
122   mc_model_checker_t mc = xbt_new0(s_mc_model_checker_t, 1);
123   mc->pages = mc_pages_store_new();
124   mc->fd_clear_refs = -1;
125   mc->fd_pagemap = -1;
126   return mc;
127 }
128
129 void MC_model_checker_delete(mc_model_checker_t mc) {
130   mc_pages_store_delete(mc->pages);
131   if(mc->record)
132     xbt_dynar_free(&mc->record);
133 }
134
135 void MC_init()
136 {
137   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
138
139   mc_time = xbt_new0(double, simix_process_maxpid);
140
141   /* Initialize the data structures that must be persistent across every
142      iteration of the model-checker (in RAW memory) */
143
144   MC_SET_MC_HEAP;
145
146   mc_model_checker = MC_model_checker_new();
147
148   mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
149
150   /* Initialize statistics */
151   mc_stats = xbt_new0(s_mc_stats_t, 1);
152   mc_stats->state_size = 1;
153
154   MC_init_memory_map_info();
155   MC_init_debug_info();         /* FIXME : get debug information only if liveness verification or visited state reduction */
156
157   if ((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0] != '\0'))
158     MC_init_dot_output();
159
160   /* Init parmap */
161   //parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
162
163   MC_SET_STD_HEAP;
164
165   if (_sg_mc_visited > 0 || _sg_mc_liveness) {
166     /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
167     MC_ignore_local_variable("e", "*");
168     MC_ignore_local_variable("__ex_cleanup", "*");
169     MC_ignore_local_variable("__ex_mctx_en", "*");
170     MC_ignore_local_variable("__ex_mctx_me", "*");
171     MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
172     MC_ignore_local_variable("_log_ev", "*");
173     MC_ignore_local_variable("_throw_ctx", "*");
174     MC_ignore_local_variable("ctx", "*");
175
176     MC_ignore_local_variable("self", "simcall_BODY_mc_snapshot");
177     MC_ignore_local_variable("next_cont"
178       "ext", "smx_ctx_sysv_suspend_serial");
179     MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
180
181     /* Ignore local variable about time used for tracing */
182     MC_ignore_local_variable("start_time", "*");
183
184     MC_ignore_global_variable("mc_model_checker");
185
186     // Mot of those things could be moved into mc_model_checker:
187     MC_ignore_global_variable("compared_pointers");
188     MC_ignore_global_variable("mc_comp_times");
189     MC_ignore_global_variable("mc_snapshot_comparison_time");
190     MC_ignore_global_variable("mc_time");
191     MC_ignore_global_variable("smpi_current_rank");
192     MC_ignore_global_variable("counter");       /* Static variable used for tracing */
193     MC_ignore_global_variable("maestro_stack_start");
194     MC_ignore_global_variable("maestro_stack_end");
195     MC_ignore_global_variable("smx_total_comms");
196     MC_ignore_global_variable("communications_pattern");
197     MC_ignore_global_variable("initial_communications_pattern");
198     MC_ignore_global_variable("incomplete_communications_pattern");
199     MC_ignore_global_variable("mc_diff_info");
200
201     MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
202
203     smx_process_t process;
204     xbt_swag_foreach(process, simix_global->process_list) {
205       MC_ignore_heap(&(process->process_hookup),
206                      sizeof(process->process_hookup));
207                      }
208   }
209
210   if (raw_mem_set)
211     MC_SET_MC_HEAP;
212
213 }
214
215 /*******************************  Core of MC *******************************/
216 /**************************************************************************/
217
218 static void MC_modelcheck_comm_determinism_init(void)
219 {
220
221   int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
222
223   MC_init();
224
225   if (!mc_mem_set)
226     MC_SET_MC_HEAP;
227
228   /* Create exploration stack */
229   mc_stack = xbt_fifo_new();
230
231   MC_SET_STD_HEAP;
232
233   MC_pre_modelcheck_comm_determinism();
234
235   MC_SET_MC_HEAP;
236   initial_global_state = xbt_new0(s_mc_global_t, 1);
237   initial_global_state->snapshot = MC_take_snapshot(0);
238   initial_global_state->initial_communications_pattern_done = 0;
239   initial_global_state->comm_deterministic = 1;
240   initial_global_state->send_deterministic = 1;
241   MC_SET_STD_HEAP;
242
243   MC_modelcheck_comm_determinism();
244
245   if(mc_mem_set)
246     MC_SET_MC_HEAP;
247
248 }
249
250 static void MC_modelcheck_safety_init(void)
251 {
252   int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
253
254   _sg_mc_safety = 1;
255
256   MC_init();
257
258   if (!mc_mem_set)
259     MC_SET_MC_HEAP;
260
261   /* Create exploration stack */
262   mc_stack = xbt_fifo_new();
263
264   MC_SET_STD_HEAP;
265
266   MC_pre_modelcheck_safety();
267
268   MC_SET_MC_HEAP;
269   /* Save the initial state */
270   initial_global_state = xbt_new0(s_mc_global_t, 1);
271   initial_global_state->snapshot = MC_take_snapshot(0);
272   MC_SET_STD_HEAP;
273
274   MC_modelcheck_safety();
275
276   if (mc_mem_set)
277     MC_SET_MC_HEAP;
278
279   xbt_abort();
280   //MC_exit();
281 }
282
283 static void MC_modelcheck_liveness_init()
284 {
285
286   int mc_mem_set = (mmalloc_get_current_heap() == mc_heap);
287
288   _sg_mc_liveness = 1;
289
290   MC_init();
291
292   if (!mc_mem_set)
293     MC_SET_MC_HEAP;
294
295   /* Create exploration stack */
296   mc_stack = xbt_fifo_new();
297
298   /* Create the initial state */
299   initial_global_state = xbt_new0(s_mc_global_t, 1);
300
301   MC_SET_STD_HEAP;
302
303   MC_pre_modelcheck_liveness();
304
305   /* We're done */
306   MC_print_statistics(mc_stats);
307   xbt_free(mc_time);
308
309   if (mc_mem_set)
310     MC_SET_MC_HEAP;
311
312 }
313
314 void MC_do_the_modelcheck_for_real()
315 {
316
317   if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
318     XBT_INFO("Check communication determinism");
319     MC_modelcheck_comm_determinism_init();
320   } else if (!_sg_mc_property_file || _sg_mc_property_file[0] == '\0') {
321     if (mc_reduce_kind == e_mc_reduce_unset)
322       mc_reduce_kind = e_mc_reduce_dpor;
323     XBT_INFO("Check a safety property");
324     MC_modelcheck_safety_init();
325   } else {
326     if (mc_reduce_kind == e_mc_reduce_unset)
327       mc_reduce_kind = e_mc_reduce_none;
328     XBT_INFO("Check the liveness property %s", _sg_mc_property_file);
329     MC_automaton_load(_sg_mc_property_file);
330     MC_modelcheck_liveness_init();
331   }
332 }
333
334
335 void MC_exit(void)
336 {
337   xbt_free(mc_time);
338
339   MC_memory_exit();
340   //xbt_abort();
341 }
342
343 int MC_deadlock_check()
344 {
345   int deadlock = FALSE;
346   smx_process_t process;
347   if (xbt_swag_size(simix_global->process_list)) {
348     deadlock = TRUE;
349     xbt_swag_foreach(process, simix_global->process_list) {
350       if (MC_request_is_enabled(&process->simcall)) {
351         deadlock = FALSE;
352         break;
353       }
354     }
355   }
356   return deadlock;
357 }
358
359 void mc_update_comm_pattern(mc_call_type call_type, smx_simcall_t req, int value, xbt_dynar_t pattern) {
360   switch(call_type) {
361   case MC_CALL_TYPE_NONE:
362     break;
363   case MC_CALL_TYPE_SEND:
364   case MC_CALL_TYPE_RECV:
365     get_comm_pattern(pattern, req, call_type);
366     break;
367   case MC_CALL_TYPE_WAIT:
368     {
369       smx_synchro_t current_comm = NULL;
370       if (call_type == MC_CALL_TYPE_WAIT)
371         current_comm = simcall_comm_wait__get__comm(req);
372       else
373         current_comm = xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_synchro_t);
374       // First wait only must be considered:
375       if (current_comm->comm.refcount == 1)
376         complete_comm_pattern(pattern, current_comm);
377       break;
378     }
379   default:
380     xbt_die("Unexpected call type %i", (int)call_type);
381   }
382 }
383
384 /**
385  * \brief Re-executes from the state at position start all the transitions indicated by
386  *        a given model-checker stack.
387  * \param stack The stack with the transitions to execute.
388  * \param start Start index to begin the re-execution.
389  *
390  *  If start==-1, restore the initial state and replay the actions the
391  *  the transitions in the stack.
392  *
393  *  Otherwise, we only replay a part of the transitions of the stacks
394  *  without restoring the state: it is assumed that the current state
395  *  match with the transitions to execute.
396  */
397 void MC_replay(xbt_fifo_t stack, int start)
398 {
399   int raw_mem = (mmalloc_get_current_heap() == mc_heap);
400
401   int value, i = 1, count = 1, j;
402   char *req_str;
403   smx_simcall_t req = NULL, saved_req = NULL;
404   xbt_fifo_item_t item, start_item;
405   mc_state_t state;
406   smx_process_t process = NULL;
407
408   XBT_DEBUG("**** Begin Replay ****");
409
410   if (start == -1) {
411     /* Restore the initial state */
412     MC_restore_snapshot(initial_global_state->snapshot);
413     /* At the moment of taking the snapshot the raw heap was set, so restoring
414      * it will set it back again, we have to unset it to continue  */
415     MC_SET_STD_HEAP;
416   }
417
418   start_item = xbt_fifo_get_last_item(stack);
419   if (start != -1) {
420     while (i != start) {
421       start_item = xbt_fifo_get_prev_item(start_item);
422       i++;
423     }
424   }
425
426   MC_SET_MC_HEAP;
427
428   if (mc_reduce_kind == e_mc_reduce_dpor) {
429     xbt_dict_reset(first_enabled_state);
430     xbt_swag_foreach(process, simix_global->process_list) {
431       if (MC_process_is_enabled(process)) {
432         char *key = bprintf("%lu", process->pid);
433         char *data = bprintf("%d", count);
434         xbt_dict_set(first_enabled_state, key, data, NULL);
435         xbt_free(key);
436       }
437     }
438   }
439
440   if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
441     for (j=0; j<simix_process_maxpid; j++) {
442       xbt_dynar_reset((xbt_dynar_t)xbt_dynar_get_as(communications_pattern, j, xbt_dynar_t));
443     }
444     for (j=0; j<simix_process_maxpid; j++) {
445       xbt_dynar_reset((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, j, xbt_dynar_t));
446     }
447   }
448
449   MC_SET_STD_HEAP;
450
451   /* Traverse the stack from the state at position start and re-execute the transitions */
452   for (item = start_item;
453        item != xbt_fifo_get_first_item(stack);
454        item = xbt_fifo_get_prev_item(item)) {
455
456     state = (mc_state_t) xbt_fifo_get_item_content(item);
457     saved_req = MC_state_get_executed_request(state, &value);
458
459     if (mc_reduce_kind == e_mc_reduce_dpor) {
460       MC_SET_MC_HEAP;
461       char *key = bprintf("%lu", saved_req->issuer->pid);
462       if(xbt_dict_get_or_null(first_enabled_state, key))
463          xbt_dict_remove(first_enabled_state, key);
464       xbt_free(key);
465       MC_SET_STD_HEAP;
466     }
467
468     if (saved_req) {
469       /* because we got a copy of the executed request, we have to fetch the  
470          real one, pointed by the request field of the issuer process */
471       req = &saved_req->issuer->simcall;
472
473       /* Debug information */
474       if (XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)) {
475         req_str = MC_request_to_string(req, value);
476         XBT_DEBUG("Replay: %s (%p)", req_str, state);
477         xbt_free(req_str);
478       }
479
480       /* TODO : handle test and testany simcalls */
481       mc_call_type call = MC_CALL_TYPE_NONE;
482       if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
483         call = mc_get_call_type(req);
484       }
485
486       SIMIX_simcall_handle(req, value);
487
488       if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
489         MC_SET_MC_HEAP;
490         mc_update_comm_pattern(call, req, value, communications_pattern);
491         MC_SET_STD_HEAP;
492       }
493
494       MC_wait_for_requests();
495
496       count++;
497
498       if (mc_reduce_kind == e_mc_reduce_dpor) {
499         MC_SET_MC_HEAP;
500         /* Insert in dict all enabled processes */
501         xbt_swag_foreach(process, simix_global->process_list) {
502           if (MC_process_is_enabled(process) ) {
503             char *key = bprintf("%lu", process->pid);
504             if (xbt_dict_get_or_null(first_enabled_state, key) == NULL) {
505               char *data = bprintf("%d", count);
506               xbt_dict_set(first_enabled_state, key, data, NULL);
507             }
508             xbt_free(key);
509           }
510         }
511         MC_SET_STD_HEAP;
512       }
513     }
514
515     /* Update statistics */
516     mc_stats->visited_states++;
517     mc_stats->executed_transitions++;
518
519   }
520
521   XBT_DEBUG("**** End Replay ****");
522
523   if (raw_mem)
524     MC_SET_MC_HEAP;
525   else
526     MC_SET_STD_HEAP;
527
528
529 }
530
531 void MC_replay_liveness(xbt_fifo_t stack, int all_stack)
532 {
533
534   initial_global_state->raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
535
536   xbt_fifo_item_t item;
537   int depth = 1;
538
539   XBT_DEBUG("**** Begin Replay ****");
540
541   /* Restore the initial state */
542   MC_restore_snapshot(initial_global_state->snapshot);
543
544   /* At the moment of taking the snapshot the raw heap was set, so restoring
545    * it will set it back again, we have to unset it to continue  */
546   if (!initial_global_state->raw_mem_set)
547     MC_SET_STD_HEAP;
548
549     /* Traverse the stack from the initial state and re-execute the transitions */
550     for (item = xbt_fifo_get_last_item(stack);
551          all_stack ? depth <= xbt_fifo_size(stack) : item != xbt_fifo_get_first_item(stack);
552          item = xbt_fifo_get_prev_item(item)) {
553
554       mc_pair_t pair = (mc_pair_t) xbt_fifo_get_item_content(item);
555
556       mc_state_t state = (mc_state_t) pair->graph_state;
557       smx_simcall_t req = NULL, saved_req = NULL;
558       int value;
559       char *req_str;
560
561       if (pair->requests > 0) {
562
563         saved_req = MC_state_get_executed_request(state, &value);
564         //XBT_DEBUG("SavedReq->call %u", saved_req->call);
565
566         if (saved_req != NULL) {
567           /* because we got a copy of the executed request, we have to fetch the
568              real one, pointed by the request field of the issuer process */
569           req = &saved_req->issuer->simcall;
570           //XBT_DEBUG("Req->call %u", req->call);
571
572           /* Debug information */
573           if (XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)) {
574             req_str = MC_request_to_string(req, value);
575             XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
576             xbt_free(req_str);
577           }
578
579         }
580
581         SIMIX_simcall_handle(req, value);
582         MC_wait_for_requests();
583       }
584
585       /* Update statistics */
586       mc_stats->visited_pairs++;
587       mc_stats->executed_transitions++;
588
589       depth++;
590
591     }
592
593   XBT_DEBUG("**** End Replay ****");
594
595   if (initial_global_state->raw_mem_set)
596     MC_SET_MC_HEAP;
597   else
598     MC_SET_STD_HEAP;
599
600 }
601
602 /**
603  * \brief Dumps the contents of a model-checker's stack and shows the actual
604  *        execution trace
605  * \param stack The stack to dump
606  */
607 void MC_dump_stack_safety(xbt_fifo_t stack)
608 {
609
610   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
611
612   MC_show_stack_safety(stack);
613
614   if (!_sg_mc_checkpoint) {
615
616     mc_state_t state;
617
618     MC_SET_MC_HEAP;
619     while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
620       MC_state_delete(state);
621     MC_SET_STD_HEAP;
622
623   }
624
625   if (raw_mem_set)
626     MC_SET_MC_HEAP;
627   else
628     MC_SET_STD_HEAP;
629
630 }
631
632
633 void MC_show_stack_safety(xbt_fifo_t stack)
634 {
635
636   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
637
638   MC_SET_MC_HEAP;
639
640   int value;
641   mc_state_t state;
642   xbt_fifo_item_t item;
643   smx_simcall_t req;
644   char *req_str = NULL;
645
646   for (item = xbt_fifo_get_last_item(stack);
647        (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
648         : (NULL)); item = xbt_fifo_get_prev_item(item)) {
649     req = MC_state_get_executed_request(state, &value);
650     if (req) {
651       req_str = MC_request_to_string(req, value);
652       XBT_INFO("%s", req_str);
653       xbt_free(req_str);
654     }
655   }
656
657   if (!raw_mem_set)
658     MC_SET_STD_HEAP;
659 }
660
661 void MC_show_deadlock(smx_simcall_t req)
662 {
663   /*char *req_str = NULL; */
664   XBT_INFO("**************************");
665   XBT_INFO("*** DEAD-LOCK DETECTED ***");
666   XBT_INFO("**************************");
667   XBT_INFO("Locked request:");
668   /*req_str = MC_request_to_string(req);
669      XBT_INFO("%s", req_str);
670      xbt_free(req_str); */
671   XBT_INFO("Counter-example execution trace:");
672   MC_dump_stack_safety(mc_stack);
673   MC_print_statistics(mc_stats);
674 }
675
676
677 void MC_show_stack_liveness(xbt_fifo_t stack)
678 {
679   int value;
680   mc_pair_t pair;
681   xbt_fifo_item_t item;
682   smx_simcall_t req;
683   char *req_str = NULL;
684
685   for (item = xbt_fifo_get_last_item(stack);
686        (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item)))
687         : (NULL)); item = xbt_fifo_get_prev_item(item)) {
688     req = MC_state_get_executed_request(pair->graph_state, &value);
689     if (req) {
690       if (pair->requests > 0) {
691         req_str = MC_request_to_string(req, value);
692         XBT_INFO("%s", req_str);
693         xbt_free(req_str);
694       } else {
695         XBT_INFO("End of system requests but evolution in Büchi automaton");
696       }
697     }
698   }
699 }
700
701 void MC_dump_stack_liveness(xbt_fifo_t stack)
702 {
703
704   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
705
706   mc_pair_t pair;
707
708   MC_SET_MC_HEAP;
709   while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
710     MC_pair_delete(pair);
711   MC_SET_STD_HEAP;
712
713   if (raw_mem_set)
714     MC_SET_MC_HEAP;
715
716 }
717
718
719 void MC_print_statistics(mc_stats_t stats)
720 {
721   xbt_mheap_t previous_heap = mmalloc_get_current_heap();
722
723   if (stats->expanded_pairs == 0) {
724     XBT_INFO("Expanded states = %lu", stats->expanded_states);
725     XBT_INFO("Visited states = %lu", stats->visited_states);
726   } else {
727     XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
728     XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
729   }
730   XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
731   MC_SET_MC_HEAP;
732   if ((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0] != '\0')) {
733     fprintf(dot_output, "}\n");
734     fclose(dot_output);
735   }
736   if (initial_global_state != NULL) {
737     if (_sg_mc_comms_determinism)
738       XBT_INFO("Communication-deterministic : %s",
739                !initial_global_state->comm_deterministic ? "No" : "Yes");
740     if (_sg_mc_send_determinism)
741       XBT_INFO("Send-deterministic : %s",
742                !initial_global_state->send_deterministic ? "No" : "Yes");
743   }
744   mmalloc_set_current_heap(previous_heap);
745 }
746
747 void MC_assert(int prop)
748 {
749   if (MC_is_active() && !prop) {
750     XBT_INFO("**************************");
751     XBT_INFO("*** PROPERTY NOT VALID ***");
752     XBT_INFO("**************************");
753     XBT_INFO("Counter-example execution trace:");
754     MC_record_dump_path(mc_stack);
755     MC_dump_stack_safety(mc_stack);
756     MC_print_statistics(mc_stats);
757     xbt_abort();
758   }
759 }
760
761 void MC_cut(void)
762 {
763   user_max_depth_reached = 1;
764 }
765
766 void MC_automaton_load(const char *file)
767 {
768
769   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
770
771   MC_SET_MC_HEAP;
772
773   if (_mc_property_automaton == NULL)
774     _mc_property_automaton = xbt_automaton_new();
775
776   xbt_automaton_load(_mc_property_automaton, file);
777
778   MC_SET_STD_HEAP;
779
780   if (raw_mem_set)
781     MC_SET_MC_HEAP;
782
783 }
784
785 void MC_automaton_new_propositional_symbol(const char *id, void *fct)
786 {
787
788   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
789
790   MC_SET_MC_HEAP;
791
792   if (_mc_property_automaton == NULL)
793     _mc_property_automaton = xbt_automaton_new();
794
795   xbt_automaton_propositional_symbol_new(_mc_property_automaton, id, fct);
796
797   MC_SET_STD_HEAP;
798
799   if (raw_mem_set)
800     MC_SET_MC_HEAP;
801
802 }
803
804 void MC_dump_stacks(FILE* file)
805 {
806   int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
807   MC_SET_MC_HEAP;
808
809   int nstack = 0;
810   stack_region_t current_stack;
811   unsigned cursor;
812   xbt_dynar_foreach(stacks_areas, cursor, current_stack) {
813     unw_context_t * context = (unw_context_t *)current_stack->context;
814     fprintf(file, "Stack %i:\n", nstack);
815
816     int nframe = 0;
817     char buffer[100];
818     unw_cursor_t c;
819     unw_init_local (&c, context);
820     unw_word_t off;
821     do {
822       const char * name = !unw_get_proc_name(&c, buffer, 100, &off) ? buffer : "?";
823       fprintf(file, "  %i: %s\n", nframe, name);
824       ++nframe;
825     } while(unw_step(&c));
826
827     ++nstack;
828   }
829
830   if (raw_mem_set)
831     MC_SET_MC_HEAP;
832 }
833 #endif
834
835 double MC_process_clock_get(smx_process_t process)
836 {
837   if (mc_time) {
838     if (process != NULL)
839       return mc_time[process->pid];
840     else
841       return -1;
842   } else {
843     return 0;
844   }
845 }
846
847 void MC_process_clock_add(smx_process_t process, double amount)
848 {
849   mc_time[process->pid] += amount;
850 }