Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix non-MC builds that don't have libevent-dev installed
[simgrid.git] / src / mc / mc_client_api.cpp
1 /* Copyright (c) 2008-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/simix.hpp"
7 #include "src/kernel/actor/ActorImpl.hpp"
8 #include "src/mc/mc_config.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/AppSide.hpp"
13 #include "xbt/asserts.h"
14 #include "xbt/random.hpp"
15
16 /* Implementation of the user API from the App to the Checker (see modelchecker.h)  */
17
18 int MC_random(int min, int max)
19 {
20 #if SIMGRID_HAVE_MC
21   xbt_assert(mc_model_checker == nullptr);
22 #endif
23   if (not MC_is_active() && not MC_record_replay_is_active()) { // no need to do a simcall in this case
24     static simgrid::xbt::random::XbtRandom prng;
25     return prng.uniform_int(min, max);
26   }
27   simgrid::kernel::actor::RandomSimcall observer{simgrid::kernel::actor::ActorImpl::self(), min, max};
28   return simgrid::kernel::actor::simcall_answered([&observer] { return observer.get_value(); }, &observer);
29 }
30
31 void MC_assert(int prop)
32 {
33 #if SIMGRID_HAVE_MC
34   xbt_assert(mc_model_checker == nullptr);
35   if (not prop) {
36     if (MC_is_active())
37       simgrid::mc::AppSide::get()->report_assertion_failure();
38     if (MC_record_replay_is_active())
39       xbt_die("MC assertion failed");
40   }
41 #else
42   xbt_assert(prop, "Safety property violation detected without the model-checker");
43 #endif
44 }
45
46 int MC_is_active()
47 {
48   return simgrid::mc::cfg_do_model_check;
49 }
50
51 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
52 {
53 #if SIMGRID_HAVE_MC
54   xbt_assert(mc_model_checker == nullptr);
55   simgrid::mc::AppSide::get()->declare_symbol(name, value);
56 #endif
57 }
58
59 void MC_ignore(void* addr, size_t size)
60 {
61 #if SIMGRID_HAVE_MC
62   xbt_assert(mc_model_checker == nullptr);
63   simgrid::mc::AppSide::get()->ignore_memory(addr, size);
64 #endif
65 }
66
67 void MC_ignore_heap(void *address, size_t size)
68 {
69 #if SIMGRID_HAVE_MC
70   xbt_assert(mc_model_checker == nullptr);
71   simgrid::mc::AppSide::get()->ignore_heap(address, size);
72 #endif
73 }
74
75 void MC_unignore_heap(void* address, size_t size)
76 {
77 #if SIMGRID_HAVE_MC
78   xbt_assert(mc_model_checker == nullptr);
79   simgrid::mc::AppSide::get()->unignore_heap(address, size);
80 #endif
81 }