Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
97a6f85853ff9fb2e82969ed9112a4b66330b1c9
[simgrid.git] / src / mc / mc_client_api.cpp
1 /* Copyright (c) 2008-2020. 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 "src/mc/ModelChecker.hpp"
8 #include "src/mc/mc_ignore.hpp"
9 #include "src/mc/mc_private.hpp"
10 #include "src/mc/mc_record.hpp"
11 #include "src/mc/mc_replay.hpp"
12 #include "src/mc/remote/Client.hpp"
13 #include "xbt/asserts.h"
14
15 /** @file mc_client_api.cpp
16  *
17  *  This is the implementation of the API used by the user simulated program to
18  *  communicate with the MC (declared in modelchecker.h).
19  */
20
21 // MC_random() is in mc_base.cpp
22
23 void MC_assert(int prop)
24 {
25   xbt_assert(mc_model_checker == nullptr);
26   if (not prop) {
27     if (MC_is_active())
28       simgrid::mc::Client::get()->report_assertion_failure();
29     if (MC_record_replay_is_active())
30       xbt_die("MC assertion failed");
31   }
32 }
33
34 void MC_cut()
35 {
36   xbt_assert(mc_model_checker == nullptr);
37   if (not MC_is_active())
38     return;
39   // FIXME, We want to do this in the model-checker:
40   xbt_die("MC_cut() not implemented");
41 }
42
43 void MC_ignore(void* addr, size_t size)
44 {
45   xbt_assert(mc_model_checker == nullptr);
46   if (not MC_is_active())
47     return;
48   simgrid::mc::Client::get()->ignore_memory(addr, size);
49 }
50
51 void MC_automaton_new_propositional_symbol(const char* /*id*/, int (*/*fct*/)())
52 {
53   xbt_assert(mc_model_checker == nullptr);
54   if (not MC_is_active())
55     return;
56   xbt_die("Support for client-side function proposition is not implemented: "
57     "use MC_automaton_new_propositional_symbol_pointer instead.");
58 }
59
60 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
61 {
62   xbt_assert(mc_model_checker == nullptr);
63   if (not MC_is_active())
64     return;
65   simgrid::mc::Client::get()->declare_symbol(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 specifically
71  *  when we analyze/compare the content of the heap so it must be told where
72  *  they are with this function.
73  *
74  *  @param stack Where the stack is
75  *  @param actor Actor owning the stack
76  *  @param context The context associated to that stack
77  *  @param size    Size of the stack
78  */
79 void MC_register_stack_area(void* stack, ucontext_t* context, size_t size)
80 {
81   xbt_assert(mc_model_checker == nullptr);
82   if (not MC_is_active())
83     return;
84   simgrid::mc::Client::get()->declare_stack(stack, size, context);
85 }
86
87 void MC_ignore_global_variable(const char* /*name*/)
88 {
89   xbt_assert(mc_model_checker == nullptr);
90   if (not MC_is_active())
91     return;
92   // TODO, send a message to the model_checker
93   xbt_die("Unimplemented");
94 }
95
96 void MC_ignore_heap(void *address, size_t size)
97 {
98   xbt_assert(mc_model_checker == nullptr);
99   if (not MC_is_active())
100     return;
101   simgrid::mc::Client::get()->ignore_heap(address, size);
102 }
103
104 void MC_unignore_heap(void* address, size_t size)
105 {
106   xbt_assert(mc_model_checker == nullptr);
107   if (not MC_is_active())
108     return;
109   simgrid::mc::Client::get()->unignore_heap(address, size);
110 }