Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move initial state into Session
[simgrid.git] / src / mc / mc_client_api.cpp
1 /* Copyright (c) 2008-2015. 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 <xbt/log.h>
8 #include <xbt/sysdep.h>
9 #include <simgrid/modelchecker.h>
10
11 #include "src/mc/mc_record.h"
12 #include "src/mc/mc_private.h"
13 #include "src/mc/mc_ignore.h"
14 #include "src/mc/mc_protocol.h"
15 #include "src/mc/Client.hpp"
16 #include "src/mc/ModelChecker.hpp"
17
18 /** \file mc_client_api.cpp
19  *
20  *  This is the implementation of the API used by the user simulated program to
21  *  communicate with the MC (declared in modelchecker.h).
22  */
23
24 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client_api, mc,
25   "Public API for the model-checked application");
26
27 // MC_random() is in mc_base.cpp
28
29 void MC_assert(int prop)
30 {
31   if (MC_is_active() && !prop)
32     simgrid::mc::Client::get()->reportAssertionFailure();
33 }
34
35 void MC_cut(void)
36 {
37   // FIXME, We want to do this in the model-checker:
38   xbt_die("MC_cut() not implemented");
39 }
40
41 void MC_ignore(void* addr, size_t size)
42 {
43   xbt_assert(mc_mode != MC_MODE_SERVER);
44   if (mc_mode != MC_MODE_CLIENT)
45     return;
46   simgrid::mc::Client::get()->ignoreMemory(addr, size);
47 }
48
49 void MC_automaton_new_propositional_symbol(const char *id, int(*fct)(void))
50 {
51   xbt_assert(mc_mode != MC_MODE_SERVER);
52   if (mc_mode != MC_MODE_CLIENT)
53     return;
54
55   xbt_die("Support for client-side function proposition is not implemented: "
56     "use MC_automaton_new_propositional_symbol_pointer instead."
57   );
58 }
59
60 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
61 {
62   xbt_assert(mc_mode != MC_MODE_SERVER);
63   if (mc_mode != MC_MODE_CLIENT)
64     return;
65   simgrid::mc::Client::get()->declareSymbol(name, value);
66 }
67
68 /** @brief Register a stack in the model checker
69  *
70  *  The stacks are allocated in the heap. The MC handle them especially
71  *  when we analyse/compare the content of the heap so it must be told where
72  *  they are with this function.
73  *
74  *  @param stack
75  *  @param process Process owning the stack
76  *  @param context
77  *  @param size    Size of the stack
78  */
79 void MC_register_stack_area(void *stack, smx_process_t process, ucontext_t* context, size_t size)
80 {
81   if (mc_mode != MC_MODE_CLIENT)
82     return;
83   simgrid::mc::Client::get()->declareStack(stack, size, process, context);
84 }
85
86 void MC_ignore_global_variable(const char *name)
87 {
88   // TODO, send a message to the model_checker
89   xbt_die("Unimplemented");
90 }
91
92 void MC_ignore_heap(void *address, size_t size)
93 {
94   if (mc_mode != MC_MODE_CLIENT)
95     return;
96   simgrid::mc::Client::get()->ignoreHeap(address, size);
97 }
98
99 void MC_remove_ignore_heap(void *address, size_t size)
100 {
101   if (mc_mode != MC_MODE_CLIENT)
102     return;
103   simgrid::mc::Client::get()->unignoreHeap(address, size);
104 }