Logo AND Algorithmique Numérique Distribuée

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