Logo AND Algorithmique Numérique Distribuée

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