Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
argh, linkchecker needs --check-extern to be really useful
[simgrid.git] / src / mc / mc_client_api.cpp
1 /* Copyright (c) 2008-2019. 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/ModelChecker.hpp"
12 #include "src/mc/mc_ignore.hpp"
13 #include "src/mc/mc_private.hpp"
14 #include "src/mc/mc_record.hpp"
15 #include "src/mc/mc_replay.hpp"
16 #include "src/mc/remote/Client.hpp"
17 #include "src/mc/remote/mc_protocol.h"
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   xbt_assert(mc_model_checker == nullptr);
33   if (not prop) {
34     if (MC_is_active())
35       simgrid::mc::Client::get()->reportAssertionFailure();
36     if (MC_record_replay_is_active())
37       xbt_die("MC assertion failed");
38   }
39 }
40
41 void MC_cut()
42 {
43   xbt_assert(mc_model_checker == nullptr);
44   if (not MC_is_active())
45     return;
46   // FIXME, We want to do this in the model-checker:
47   xbt_die("MC_cut() not implemented");
48 }
49
50 void MC_ignore(void* addr, size_t size)
51 {
52   xbt_assert(mc_model_checker == nullptr);
53   if (not MC_is_active())
54     return;
55   simgrid::mc::Client::get()->ignoreMemory(addr, size);
56 }
57
58 void MC_automaton_new_propositional_symbol(const char* /*id*/, int (*/*fct*/)())
59 {
60   xbt_assert(mc_model_checker == nullptr);
61   if (not MC_is_active())
62     return;
63   xbt_die("Support for client-side function proposition is not implemented: "
64     "use MC_automaton_new_propositional_symbol_pointer instead.");
65 }
66
67 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
68 {
69   xbt_assert(mc_model_checker == nullptr);
70   if (not MC_is_active())
71     return;
72   simgrid::mc::Client::get()->declareSymbol(name, value);
73 }
74
75 /** @brief Register a stack in the model checker
76  *
77  *  The stacks are allocated in the heap. The MC handle them specifically
78  *  when we analyze/compare the content of the heap so it must be told where
79  *  they are with this function.
80  *
81  *  @param stack Where the stack is
82  *  @param actor Actor owning the stack
83  *  @param context The context associated to that stack
84  *  @param size    Size of the stack
85  */
86 void MC_register_stack_area(void* stack, smx_actor_t actor, ucontext_t* context, size_t size)
87 {
88   xbt_assert(mc_model_checker == nullptr);
89   if (not MC_is_active())
90     return;
91   simgrid::mc::Client::get()->declareStack(stack, size, actor, context);
92 }
93
94 void MC_ignore_global_variable(const char* /*name*/)
95 {
96   xbt_assert(mc_model_checker == nullptr);
97   if (not MC_is_active())
98     return;
99   // TODO, send a message to the model_checker
100   xbt_die("Unimplemented");
101 }
102
103 void MC_ignore_heap(void *address, size_t size)
104 {
105   xbt_assert(mc_model_checker == nullptr);
106   if (not MC_is_active())
107     return;
108   simgrid::mc::Client::get()->ignoreHeap(address, size);
109 }
110
111 void MC_unignore_heap(void* address, size_t size)
112 {
113   xbt_assert(mc_model_checker == nullptr);
114   if (not MC_is_active())
115     return;
116   simgrid::mc::Client::get()->unignoreHeap(address, size);
117 }