Logo AND Algorithmique Numérique Distribuée

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