Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Only compile stateless MC when libevent is found
[simgrid.git] / src / mc / mc_client_api.cpp
1 /* Copyright (c) 2008-2023. 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   xbt_assert(simgrid::mc::model_checking_mode != simgrid::mc::ModelCheckingMode::CHECKER_SIDE,
21              "This should be called from the client side");
22
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   // Cannot used xbt_assert here, or it would be an infinite recursion.
34   xbt_assert(simgrid::mc::model_checking_mode != simgrid::mc::ModelCheckingMode::CHECKER_SIDE,
35              "This should be called from the client side");
36 #if SIMGRID_HAVE_MC
37   if (not prop) {
38     if (MC_is_active())
39       simgrid::mc::AppSide::get()->report_assertion_failure();
40     if (MC_record_replay_is_active())
41       xbt_die("MC assertion failed");
42   }
43 #else
44   if (not prop)
45     xbt_die("Safety property violation detected without the model-checker");
46 #endif
47 }
48
49 int MC_is_active()
50 {
51   return simgrid::mc::model_checking_mode == simgrid::mc::ModelCheckingMode::APP_SIDE ||
52          simgrid::mc::model_checking_mode == simgrid::mc::ModelCheckingMode::CHECKER_SIDE;
53 }
54
55 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
56 {
57 #if SIMGRID_HAVE_MC
58   xbt_assert(simgrid::mc::model_checking_mode != simgrid::mc::ModelCheckingMode::CHECKER_SIDE,
59              "This should be called from the client side");
60   simgrid::mc::AppSide::get()->declare_symbol(name, value);
61 #endif
62 }
63
64 void MC_ignore(void* addr, size_t size)
65 {
66 #if SIMGRID_HAVE_MC
67   xbt_assert(simgrid::mc::model_checking_mode != simgrid::mc::ModelCheckingMode::CHECKER_SIDE,
68              "This should be called from the client side");
69   simgrid::mc::AppSide::get()->ignore_memory(addr, size);
70 #endif
71 }
72
73 void MC_ignore_heap(void *address, size_t size)
74 {
75 #if SIMGRID_HAVE_MC
76   xbt_assert(simgrid::mc::model_checking_mode != simgrid::mc::ModelCheckingMode::CHECKER_SIDE,
77              "This should be called from the client side");
78   simgrid::mc::AppSide::get()->ignore_heap(address, size);
79 #endif
80 }
81
82 void MC_unignore_heap(void* address, size_t size)
83 {
84 #if SIMGRID_HAVE_MC
85   xbt_assert(simgrid::mc::model_checking_mode != simgrid::mc::ModelCheckingMode::CHECKER_SIDE,
86              "This should be called from the client side");
87   simgrid::mc::AppSide::get()->unignore_heap(address, size);
88 #endif
89 }