Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
10f95d265aedbfc0ea43ef41c30e3872d6e5d12e
[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 <string.h>
8
9 #include "mc_base.h"
10
11 #ifndef _XBT_WIN32
12 #include <unistd.h>
13 #include <sys/wait.h>
14 #include <sys/time.h>
15 #endif
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 <libunwind.h>
26 #include <xbt/mmalloc.h>
27
28 #include "../xbt/mmalloc/mmprivate.h"
29 #include "mc_object_info.h"
30 #include "mc_comm_pattern.h"
31 #include "mc_request.h"
32 #include "mc_safety.h"
33 #include "mc_memory_map.h"
34 #include "mc_snapshot.h"
35 #include "mc_liveness.h"
36 #include "mc_private.h"
37 #include "mc_unw.h"
38 #include "mc_smx.h"
39 #endif
40 #include "mc_record.h"
41 #include "mc_protocol.h"
42 #include "mc_client.h"
43
44 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc,
45                                 "Logging specific to MC (global)");
46
47 e_mc_mode_t mc_mode;
48
49 double *mc_time = NULL;
50
51 #ifdef HAVE_MC
52 int user_max_depth_reached = 0;
53
54 /* MC global data structures */
55 mc_state_t mc_current_state = NULL;
56 char mc_replay_mode = FALSE;
57
58 __thread mc_comparison_times_t mc_comp_times = NULL;
59 __thread double mc_snapshot_comparison_time;
60 mc_stats_t mc_stats = NULL;
61 mc_global_t initial_global_state = NULL;
62 xbt_fifo_t mc_stack = NULL;
63
64 /* Liveness */
65 xbt_automaton_t _mc_property_automaton = NULL;
66
67 /* Dot output */
68 FILE *dot_output = NULL;
69 const char *colors[13];
70
71
72 /*******************************  Initialisation of MC *******************************/
73 /*********************************************************************************/
74
75 static void MC_init_dot_output()
76 {                               /* FIXME : more colors */
77
78   colors[0] = "blue";
79   colors[1] = "red";
80   colors[2] = "green3";
81   colors[3] = "goldenrod";
82   colors[4] = "brown";
83   colors[5] = "purple";
84   colors[6] = "magenta";
85   colors[7] = "turquoise4";
86   colors[8] = "gray25";
87   colors[9] = "forestgreen";
88   colors[10] = "hotpink";
89   colors[11] = "lightblue";
90   colors[12] = "tan";
91
92   dot_output = fopen(_sg_mc_dot_output_file, "w");
93
94   if (dot_output == NULL) {
95     perror("Error open dot output file");
96     xbt_abort();
97   }
98
99   fprintf(dot_output,
100           "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");
101
102 }
103
104 void MC_init()
105 {
106   MC_init_pid(getpid(), -1);
107 }
108
109 static void MC_init_mode(void)
110 {
111   if (mc_mode == MC_MODE_NONE) {
112     if (getenv(MC_ENV_SOCKET_FD)) {
113       mc_mode = MC_MODE_CLIENT;
114     } else {
115       mc_mode = MC_MODE_STANDALONE;
116     }
117   }
118 }
119
120 void MC_init_pid(pid_t pid, int socket)
121 {
122   /* Initialize the data structures that must be persistent across every
123      iteration of the model-checker (in RAW memory) */
124
125   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
126
127   mc_model_checker = MC_model_checker_new(pid, socket);
128   if (mc_mode == MC_MODE_SERVER) {
129     unsigned long maxpid;
130     MC_process_read_variable(&mc_model_checker->process, "simix_process_maxpid",
131       &maxpid, sizeof(maxpid));
132     simix_process_maxpid = maxpid;
133   }
134
135   mmalloc_set_current_heap(std_heap);
136   mc_time = xbt_new0(double, MC_smx_get_maxpid());
137   mmalloc_set_current_heap(mc_heap);
138
139   mc_comp_times = xbt_new0(s_mc_comparison_times_t, 1);
140
141   /* Initialize statistics */
142   mc_stats = xbt_new0(s_mc_stats_t, 1);
143   mc_stats->state_size = 1;
144
145   if ((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0] != '\0'))
146     MC_init_dot_output();
147
148   /* Init parmap */
149   //parmap = xbt_parmap_mc_new(xbt_os_get_numcores(), XBT_PARMAP_DEFAULT);
150
151   MC_SET_STD_HEAP;
152
153   if (_sg_mc_visited > 0 || _sg_mc_liveness  || _sg_mc_termination) {
154     /* Ignore some variables from xbt/ex.h used by exception e for stacks comparison */
155     MC_ignore_local_variable("e", "*");
156     MC_ignore_local_variable("__ex_cleanup", "*");
157     MC_ignore_local_variable("__ex_mctx_en", "*");
158     MC_ignore_local_variable("__ex_mctx_me", "*");
159     MC_ignore_local_variable("__xbt_ex_ctx_ptr", "*");
160     MC_ignore_local_variable("_log_ev", "*");
161     MC_ignore_local_variable("_throw_ctx", "*");
162     MC_ignore_local_variable("ctx", "*");
163
164     MC_ignore_local_variable("self", "simcall_BODY_mc_snapshot");
165     MC_ignore_local_variable("next_cont"
166       "ext", "smx_ctx_sysv_suspend_serial");
167     MC_ignore_local_variable("i", "smx_ctx_sysv_suspend_serial");
168
169     /* Ignore local variable about time used for tracing */
170     MC_ignore_local_variable("start_time", "*");
171
172     /* Main MC state: */
173     MC_ignore_global_variable("mc_model_checker");
174     MC_ignore_global_variable("initial_communications_pattern");
175     MC_ignore_global_variable("incomplete_communications_pattern");
176     MC_ignore_global_variable("nb_comm_pattern");
177
178     /* MC __thread variables: */
179     MC_ignore_global_variable("mc_diff_info");
180     MC_ignore_global_variable("mc_comp_times");
181     MC_ignore_global_variable("mc_snapshot_comparison_time");
182
183     /* This MC state is used in MC replay as well: */
184     MC_ignore_global_variable("mc_time");
185
186     /* Static variable used for tracing */
187     MC_ignore_global_variable("counter");
188
189     /* SIMIX */
190     MC_ignore_global_variable("smx_total_comms");
191
192     if (mc_mode == MC_MODE_STANDALONE || mc_mode == MC_MODE_CLIENT) {
193       /* Those requests are handled on the client side and propagated by message
194        * to the server: */
195
196       MC_ignore_heap(mc_time, MC_smx_get_maxpid() * sizeof(double));
197
198       smx_process_t process;
199       xbt_swag_foreach(process, simix_global->process_list) {
200         MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
201       }
202     }
203
204   }
205
206   mmalloc_set_current_heap(heap);
207 }
208
209 /*******************************  Core of MC *******************************/
210 /**************************************************************************/
211
212 static void MC_modelcheck_comm_determinism_init(void)
213 {
214   MC_init();
215   if (mc_mode == MC_MODE_CLIENT) {
216     // This will move somehwere else:
217     MC_client_handle_messages();
218   }
219
220   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
221
222   /* Create exploration stack */
223   mc_stack = xbt_fifo_new();
224
225   MC_SET_STD_HEAP;
226
227   MC_pre_modelcheck_comm_determinism();
228
229   MC_SET_MC_HEAP;
230   initial_global_state = xbt_new0(s_mc_global_t, 1);
231   initial_global_state->snapshot = MC_take_snapshot(0);
232   initial_global_state->initial_communications_pattern_done = 0;
233   initial_global_state->recv_deterministic = 1;
234   initial_global_state->send_deterministic = 1;
235   initial_global_state->recv_diff = NULL;
236   initial_global_state->send_diff = NULL;
237
238   MC_SET_STD_HEAP;
239
240   MC_modelcheck_comm_determinism();
241
242   mmalloc_set_current_heap(heap);
243 }
244
245 static void MC_modelcheck_liveness_init()
246 {
247   _sg_mc_liveness = 1;
248
249   MC_init();
250   if (mc_mode == MC_MODE_CLIENT) {
251     // This will move somehwere else:
252     MC_client_handle_messages();
253   }
254
255   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
256
257   /* Create exploration stack */
258   mc_stack = xbt_fifo_new();
259
260   /* Create the initial state */
261   initial_global_state = xbt_new0(s_mc_global_t, 1);
262
263   MC_SET_STD_HEAP;
264
265   MC_pre_modelcheck_liveness();
266
267   /* We're done */
268   MC_print_statistics(mc_stats);
269   xbt_free(mc_time);
270
271   mmalloc_set_current_heap(heap);
272
273 }
274
275 void MC_do_the_modelcheck_for_real()
276 {
277   MC_init_mode();
278
279   if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
280     XBT_INFO("Check communication determinism");
281     mc_reduce_kind = e_mc_reduce_none;
282     MC_modelcheck_comm_determinism_init();
283   }
284
285   else if (!_sg_mc_property_file || _sg_mc_property_file[0] == '\0') {
286     if(_sg_mc_termination){
287       XBT_INFO("Check non progressive cycles");
288       mc_reduce_kind = e_mc_reduce_none;
289     } else {
290       if (mc_reduce_kind == e_mc_reduce_unset)
291         mc_reduce_kind = e_mc_reduce_dpor;
292       else {
293         _sg_mc_safety = 1;
294         mc_reduce_kind = e_mc_reduce_dpor;
295         if (mc_mode == MC_MODE_SERVER || mc_mode == MC_MODE_STANDALONE) {
296           XBT_INFO("Check a safety property");
297           MC_modelcheck_safety();
298         }
299         else {
300           // Most of this is not needed:
301           MC_init();
302           // Main event loop:
303           MC_client_main_loop();
304         }
305       }
306     }
307   }
308
309   else {
310     if (mc_reduce_kind == e_mc_reduce_unset)
311       mc_reduce_kind = e_mc_reduce_none;
312     XBT_INFO("Check the liveness property %s", _sg_mc_property_file);
313     MC_automaton_load(_sg_mc_property_file);
314     MC_modelcheck_liveness_init();
315   }
316 }
317
318
319 void MC_exit(void)
320 {
321   xbt_free(mc_time);
322
323   MC_memory_exit();
324   //xbt_abort();
325 }
326
327 int MC_deadlock_check()
328 {
329   if (mc_mode == MC_MODE_SERVER) {
330     int res;
331     if ((res = MC_protocol_send_simple_message(mc_model_checker->process.socket,
332       MC_MESSAGE_DEADLOCK_CHECK)))
333       xbt_die("Could not check deadlock state");
334     s_mc_int_message_t message;
335     ssize_t s = MC_receive_message(mc_model_checker->process.socket, &message, sizeof(message), 0);
336     if (s == -1)
337       xbt_die("Could not receive message");
338     else if (s != sizeof(message) || message.type != MC_MESSAGE_DEADLOCK_CHECK_REPLY) {
339       xbt_die("%s received unexpected message %s (%i, size=%i) "
340         "expected MC_MESSAGE_DEADLOCK_CHECK_REPLY (%i, size=%i)",
341         MC_mode_name(mc_mode),
342         MC_message_type_name(message.type), (int) message.type, (int) s,
343         (int) MC_MESSAGE_DEADLOCK_CHECK_REPLY, (int) sizeof(message)
344         );
345     }
346     else
347       return message.value;
348   }
349
350   int deadlock = FALSE;
351   smx_process_t process;
352   if (xbt_swag_size(simix_global->process_list)) {
353     deadlock = TRUE;
354     MC_EACH_SIMIX_PROCESS(process,
355       if (MC_process_is_enabled(process)) {
356         deadlock = FALSE;
357         break;
358       }
359     );
360   }
361   return deadlock;
362 }
363
364 void MC_handle_comm_pattern(e_mc_call_type_t call_type, smx_simcall_t req, int value, xbt_dynar_t pattern, int backtracking) {
365
366   switch(call_type) {
367   case MC_CALL_TYPE_NONE:
368     break;
369   case MC_CALL_TYPE_SEND:
370   case MC_CALL_TYPE_RECV:
371     MC_get_comm_pattern(pattern, req, call_type, backtracking);
372     break;
373   case MC_CALL_TYPE_WAIT:
374   case MC_CALL_TYPE_WAITANY:
375     {
376       smx_synchro_t current_comm = NULL;
377       if (call_type == MC_CALL_TYPE_WAIT)
378         current_comm = simcall_comm_wait__get__comm(req);
379       else
380         current_comm = xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_synchro_t);
381       MC_complete_comm_pattern(pattern, current_comm, req->issuer->pid, backtracking);
382     }
383     break;
384   default:
385     xbt_die("Unexpected call type %i", (int)call_type);
386   }
387   
388 }
389
390 /**
391  * \brief Re-executes from the state at position start all the transitions indicated by
392  *        a given model-checker stack.
393  * \param stack The stack with the transitions to execute.
394  * \param start Start index to begin the re-execution.
395  */
396 void MC_replay(xbt_fifo_t stack)
397 {
398   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
399
400   int value, count = 1, j;
401   char *req_str;
402   smx_simcall_t req = NULL, saved_req = NULL;
403   xbt_fifo_item_t item, start_item;
404   mc_state_t state;
405   
406   XBT_DEBUG("**** Begin Replay ****");
407
408   /* Intermediate backtracking */
409   if(_sg_mc_checkpoint > 0 || _sg_mc_termination || _sg_mc_visited > 0) {
410     start_item = xbt_fifo_get_first_item(stack);
411     state = (mc_state_t)xbt_fifo_get_item_content(start_item);
412     if(state->system_state){
413       MC_restore_snapshot(state->system_state);
414       if(_sg_mc_comms_determinism || _sg_mc_send_determinism) 
415         MC_restore_communications_pattern(state);
416       MC_SET_STD_HEAP;
417       return;
418     }
419   }
420
421
422   /* Restore the initial state */
423   MC_restore_snapshot(initial_global_state->snapshot);
424   /* At the moment of taking the snapshot the raw heap was set, so restoring
425    * it will set it back again, we have to unset it to continue  */
426   MC_SET_STD_HEAP;
427
428   start_item = xbt_fifo_get_last_item(stack);
429   
430   MC_SET_MC_HEAP;
431
432   if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
433     for (j=0; j < simix_process_maxpid; j++) {
434       xbt_dynar_reset((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, j, xbt_dynar_t));
435       ((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, j, mc_list_comm_pattern_t))->index_comm = 0;
436     }
437   }
438
439   MC_SET_STD_HEAP;
440
441   /* Traverse the stack from the state at position start and re-execute the transitions */
442   for (item = start_item;
443        item != xbt_fifo_get_first_item(stack);
444        item = xbt_fifo_get_prev_item(item)) {
445
446     state = (mc_state_t) xbt_fifo_get_item_content(item);
447     saved_req = MC_state_get_executed_request(state, &value);
448     
449     if (saved_req) {
450       /* because we got a copy of the executed request, we have to fetch the  
451          real one, pointed by the request field of the issuer process */
452
453       const smx_process_t issuer = MC_smx_simcall_get_issuer(saved_req);
454       req = &issuer->simcall;
455
456       /* Debug information */
457       if (XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)) {
458         req_str = MC_request_to_string(req, value, MC_REQUEST_SIMIX);
459         XBT_DEBUG("Replay: %s (%p)", req_str, state);
460         xbt_free(req_str);
461       }
462
463       /* TODO : handle test and testany simcalls */
464       e_mc_call_type_t call = MC_CALL_TYPE_NONE;
465       if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
466         call = MC_get_call_type(req);
467
468       MC_simcall_handle(req, value);
469
470       MC_SET_MC_HEAP;
471       if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
472         MC_handle_comm_pattern(call, req, value, NULL, 1);
473       MC_SET_STD_HEAP;
474       
475       MC_wait_for_requests();
476
477       count++;
478     }
479
480     /* Update statistics */
481     mc_stats->visited_states++;
482     mc_stats->executed_transitions++;
483
484   }
485
486   XBT_DEBUG("**** End Replay ****");
487   mmalloc_set_current_heap(heap);
488 }
489
490 void MC_replay_liveness(xbt_fifo_t stack)
491 {
492
493   initial_global_state->raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
494
495   xbt_fifo_item_t item;
496   mc_pair_t pair = NULL;
497   mc_state_t state = NULL;
498   smx_simcall_t req = NULL, saved_req = NULL;
499   int value, depth = 1;
500   char *req_str;
501
502   XBT_DEBUG("**** Begin Replay ****");
503
504   /* Intermediate backtracking */
505   if(_sg_mc_checkpoint > 0) {
506     item = xbt_fifo_get_first_item(stack);
507     pair = (mc_pair_t) xbt_fifo_get_item_content(item);
508     if(pair->graph_state->system_state){
509       MC_restore_snapshot(pair->graph_state->system_state);
510       MC_SET_STD_HEAP;
511       return;
512     }
513   }
514
515   /* Restore the initial state */
516   MC_restore_snapshot(initial_global_state->snapshot);
517
518   /* At the moment of taking the snapshot the raw heap was set, so restoring
519    * it will set it back again, we have to unset it to continue  */
520   if (!initial_global_state->raw_mem_set)
521     MC_SET_STD_HEAP;
522
523     /* Traverse the stack from the initial state and re-execute the transitions */
524     for (item = xbt_fifo_get_last_item(stack);
525          item != xbt_fifo_get_first_item(stack);
526          item = xbt_fifo_get_prev_item(item)) {
527
528       pair = (mc_pair_t) xbt_fifo_get_item_content(item);
529
530       state = (mc_state_t) pair->graph_state;
531
532       if (pair->exploration_started) {
533
534         saved_req = MC_state_get_executed_request(state, &value);
535
536         if (saved_req != NULL) {
537           /* because we got a copy of the executed request, we have to fetch the
538              real one, pointed by the request field of the issuer process */
539           const smx_process_t issuer = MC_smx_simcall_get_issuer(saved_req);
540           req = &issuer->simcall;
541
542           /* Debug information */
543           if (XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)) {
544             req_str = MC_request_to_string(req, value, MC_REQUEST_SIMIX);
545             XBT_DEBUG("Replay (depth = %d) : %s (%p)", depth, req_str, state);
546             xbt_free(req_str);
547           }
548
549         }
550
551         MC_simcall_handle(req, value);
552         MC_wait_for_requests();
553       }
554
555       /* Update statistics */
556       mc_stats->visited_pairs++;
557       mc_stats->executed_transitions++;
558
559       depth++;
560       
561     }
562
563   XBT_DEBUG("**** End Replay ****");
564
565   if (initial_global_state->raw_mem_set)
566     MC_SET_MC_HEAP;
567   else
568     MC_SET_STD_HEAP;
569
570 }
571
572 /**
573  * \brief Dumps the contents of a model-checker's stack and shows the actual
574  *        execution trace
575  * \param stack The stack to dump
576  */
577 void MC_dump_stack_safety(xbt_fifo_t stack)
578 {
579   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
580
581   MC_show_stack_safety(stack);
582   
583   mc_state_t state;
584   
585   MC_SET_MC_HEAP;
586   while ((state = (mc_state_t) xbt_fifo_pop(stack)) != NULL)
587     MC_state_delete(state, !state->in_visited_states ? 1 : 0);
588   mmalloc_set_current_heap(heap);
589 }
590
591
592 void MC_show_stack_safety(xbt_fifo_t stack)
593 {
594   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
595
596   int value;
597   mc_state_t state;
598   xbt_fifo_item_t item;
599   smx_simcall_t req;
600   char *req_str = NULL;
601
602   for (item = xbt_fifo_get_last_item(stack);
603        (item ? (state = (mc_state_t) (xbt_fifo_get_item_content(item)))
604         : (NULL)); item = xbt_fifo_get_prev_item(item)) {
605     req = MC_state_get_executed_request(state, &value);
606     if (req) {
607       req_str = MC_request_to_string(req, value, MC_REQUEST_EXECUTED);
608       XBT_INFO("%s", req_str);
609       xbt_free(req_str);
610     }
611   }
612
613   mmalloc_set_current_heap(heap);
614 }
615
616 void MC_show_deadlock(smx_simcall_t req)
617 {
618   /*char *req_str = NULL; */
619   XBT_INFO("**************************");
620   XBT_INFO("*** DEAD-LOCK DETECTED ***");
621   XBT_INFO("**************************");
622   XBT_INFO("Locked request:");
623   /*req_str = MC_request_to_string(req);
624      XBT_INFO("%s", req_str);
625      xbt_free(req_str); */
626   XBT_INFO("Counter-example execution trace:");
627   MC_dump_stack_safety(mc_stack);
628   MC_print_statistics(mc_stats);
629 }
630
631 void MC_show_non_termination(void){
632   XBT_INFO("******************************************");
633   XBT_INFO("*** NON-PROGRESSIVE CYCLE DETECTED ***");
634   XBT_INFO("******************************************");
635   XBT_INFO("Counter-example execution trace:");
636   MC_dump_stack_safety(mc_stack);
637   MC_print_statistics(mc_stats);
638 }
639
640
641 void MC_show_stack_liveness(xbt_fifo_t stack)
642 {
643   int value;
644   mc_pair_t pair;
645   xbt_fifo_item_t item;
646   smx_simcall_t req;
647   char *req_str = NULL;
648
649   for (item = xbt_fifo_get_last_item(stack);
650        (item ? (pair = (mc_pair_t) (xbt_fifo_get_item_content(item))) : (NULL));
651        item = xbt_fifo_get_prev_item(item)) {
652     req = MC_state_get_executed_request(pair->graph_state, &value);
653     if (req && req->call != SIMCALL_NONE) {
654       req_str = MC_request_to_string(req, value, MC_REQUEST_EXECUTED);
655       XBT_INFO("%s", req_str);
656       xbt_free(req_str);
657     }
658   }
659 }
660
661
662 void MC_dump_stack_liveness(xbt_fifo_t stack)
663 {
664   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
665   mc_pair_t pair;
666   while ((pair = (mc_pair_t) xbt_fifo_pop(stack)) != NULL)
667     MC_pair_delete(pair);
668   mmalloc_set_current_heap(heap);
669 }
670
671 void MC_print_statistics(mc_stats_t stats)
672 {
673   if(_sg_mc_comms_determinism) {
674     if (!initial_global_state->recv_deterministic && initial_global_state->send_deterministic){
675       XBT_INFO("******************************************************");
676       XBT_INFO("**** Only-send-deterministic communication pattern ****");
677       XBT_INFO("******************************************************");
678       XBT_INFO("%s", initial_global_state->recv_diff);
679     }else if(!initial_global_state->send_deterministic && initial_global_state->recv_deterministic) {
680       XBT_INFO("******************************************************");
681       XBT_INFO("**** Only-recv-deterministic communication pattern ****");
682       XBT_INFO("******************************************************");
683       XBT_INFO("%s", initial_global_state->send_diff);
684     }
685   }
686
687   if (stats->expanded_pairs == 0) {
688     XBT_INFO("Expanded states = %lu", stats->expanded_states);
689     XBT_INFO("Visited states = %lu", stats->visited_states);
690   } else {
691     XBT_INFO("Expanded pairs = %lu", stats->expanded_pairs);
692     XBT_INFO("Visited pairs = %lu", stats->visited_pairs);
693   }
694   XBT_INFO("Executed transitions = %lu", stats->executed_transitions);
695   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
696   if ((_sg_mc_dot_output_file != NULL) && (_sg_mc_dot_output_file[0] != '\0')) {
697     fprintf(dot_output, "}\n");
698     fclose(dot_output);
699   }
700   if (initial_global_state != NULL && (_sg_mc_comms_determinism || _sg_mc_send_determinism)) {
701     XBT_INFO("Send-deterministic : %s", !initial_global_state->send_deterministic ? "No" : "Yes");
702     if (_sg_mc_comms_determinism)
703       XBT_INFO("Recv-deterministic : %s", !initial_global_state->recv_deterministic ? "No" : "Yes");
704   }
705   mmalloc_set_current_heap(heap);
706 }
707
708 void MC_automaton_load(const char *file)
709 {
710   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
711
712   if (_mc_property_automaton == NULL)
713     _mc_property_automaton = xbt_automaton_new();
714
715   xbt_automaton_load(_mc_property_automaton, file);
716   mmalloc_set_current_heap(heap);
717 }
718
719 static void register_symbol(xbt_automaton_propositional_symbol_t symbol)
720 {
721   if (mc_mode != MC_MODE_CLIENT)
722     return;
723   s_mc_register_symbol_message_t message;
724   message.type = MC_MESSAGE_REGISTER_SYMBOL;
725   const char* name = xbt_automaton_propositional_symbol_get_name(symbol);
726   if (strlen(name) + 1 > sizeof(message.name))
727     xbt_die("Symbol is too long");
728   strncpy(message.name, name, sizeof(message.name));
729   message.callback = xbt_automaton_propositional_symbol_get_callback(symbol);
730   message.data = xbt_automaton_propositional_symbol_get_data(symbol);
731   MC_client_send_message(&message, sizeof(message));
732 }
733
734 void MC_automaton_new_propositional_symbol(const char *id, int(*fct)(void))
735 {
736   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
737
738   if (_mc_property_automaton == NULL)
739     _mc_property_automaton = xbt_automaton_new();
740
741   xbt_automaton_propositional_symbol_t symbol = xbt_automaton_propositional_symbol_new(_mc_property_automaton, id, fct);
742   register_symbol(symbol);
743   mmalloc_set_current_heap(heap);
744 }
745
746 void MC_automaton_new_propositional_symbol_pointer(const char *id, int* value)
747 {
748   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
749   if (_mc_property_automaton == NULL)
750     _mc_property_automaton = xbt_automaton_new();
751   xbt_automaton_propositional_symbol_t symbol = xbt_automaton_propositional_symbol_new_pointer(_mc_property_automaton, id, value);
752   register_symbol(symbol);
753   mmalloc_set_current_heap(heap);
754 }
755
756 void MC_automaton_new_propositional_symbol_callback(const char* id,
757   xbt_automaton_propositional_symbol_callback_type callback,
758   void* data, xbt_automaton_propositional_symbol_free_function_type free_function)
759 {
760   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
761   if (_mc_property_automaton == NULL)
762     _mc_property_automaton = xbt_automaton_new();
763   xbt_automaton_propositional_symbol_t symbol = xbt_automaton_propositional_symbol_new_callback(
764     _mc_property_automaton, id, callback, data, free_function);
765   register_symbol(symbol);
766   mmalloc_set_current_heap(heap);
767 }
768
769 void MC_dump_stacks(FILE* file)
770 {
771   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
772
773   int nstack = 0;
774   stack_region_t current_stack;
775   unsigned cursor;
776   xbt_dynar_foreach(stacks_areas, cursor, current_stack) {
777     unw_context_t * context = (unw_context_t *)current_stack->context;
778     fprintf(file, "Stack %i:\n", nstack);
779
780     int nframe = 0;
781     char buffer[100];
782     unw_cursor_t c;
783     unw_init_local (&c, context);
784     unw_word_t off;
785     do {
786       const char * name = !unw_get_proc_name(&c, buffer, 100, &off) ? buffer : "?";
787       fprintf(file, "  %i: %s\n", nframe, name);
788       ++nframe;
789     } while(unw_step(&c));
790
791     ++nstack;
792   }
793   mmalloc_set_current_heap(heap);
794 }
795 #endif
796
797 double MC_process_clock_get(smx_process_t process)
798 {
799   if (mc_time) {
800     if (process != NULL)
801       return mc_time[process->pid];
802     else
803       return -1;
804   } else {
805     return 0;
806   }
807 }
808
809 void MC_process_clock_add(smx_process_t process, double amount)
810 {
811   mc_time[process->pid] += amount;
812 }
813
814 void MC_report_assertion_error(void)
815 {
816   XBT_INFO("**************************");
817   XBT_INFO("*** PROPERTY NOT VALID ***");
818   XBT_INFO("**************************");
819   XBT_INFO("Counter-example execution trace:");
820   MC_record_dump_path(mc_stack);
821   MC_dump_stack_safety(mc_stack);
822   MC_print_statistics(mc_stats);
823 }