Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill redundent sanity checks
[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 /* Implementation of the user API from the App to the Checker (see modelchecker.h)  */
7
8 #include "src/mc/ModelChecker.hpp"
9 #include "src/mc/mc_config.hpp"
10 #include "src/mc/mc_private.hpp"
11 #include "src/mc/mc_record.hpp"
12 #include "src/mc/mc_replay.hpp"
13 #include "src/mc/remote/AppSide.hpp"
14 #include "xbt/asserts.h"
15 #include "xbt/random.hpp"
16
17 int MC_random(int min, int max)
18 {
19 #if SIMGRID_HAVE_MC
20   xbt_assert(mc_model_checker == nullptr);
21 #endif
22   if (not MC_is_active() && not MC_record_replay_is_active()) { // no need to do a simcall in this case
23     static simgrid::xbt::random::XbtRandom prng;
24     return prng.uniform_int(min, max);
25   }
26   simgrid::kernel::actor::RandomSimcall observer{simgrid::kernel::actor::ActorImpl::self(), min, max};
27   return simgrid::kernel::actor::simcall_answered([&observer] { return observer.get_value(); }, &observer);
28 }
29
30 void MC_assert(int prop)
31 {
32 #if SIMGRID_HAVE_MC
33   xbt_assert(mc_model_checker == nullptr);
34   if (not prop) {
35     if (MC_is_active())
36       simgrid::mc::AppSide::get()->report_assertion_failure();
37     if (MC_record_replay_is_active())
38       xbt_die("MC assertion failed");
39   }
40 #else
41   xbt_assert(prop, "Safety property violation detected without the model-checker");
42 #endif
43 }
44
45 int MC_is_active()
46 {
47   return simgrid::mc::cfg_do_model_check;
48 }
49
50 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
51 {
52 #if SIMGRID_HAVE_MC
53   xbt_assert(mc_model_checker == nullptr);
54   simgrid::mc::AppSide::get()->declare_symbol(name, value);
55 #endif
56 }
57
58 void MC_ignore(void* addr, size_t size)
59 {
60 #if SIMGRID_HAVE_MC
61   xbt_assert(mc_model_checker == nullptr);
62   simgrid::mc::AppSide::get()->ignore_memory(addr, size);
63 #endif
64 }
65
66 void MC_ignore_heap(void *address, size_t size)
67 {
68 #if SIMGRID_HAVE_MC
69   xbt_assert(mc_model_checker == nullptr);
70   simgrid::mc::AppSide::get()->ignore_heap(address, size);
71 #endif
72 }
73
74 void MC_unignore_heap(void* address, size_t size)
75 {
76 #if SIMGRID_HAVE_MC
77   xbt_assert(mc_model_checker == nullptr);
78   simgrid::mc::AppSide::get()->unignore_heap(address, size);
79 #endif
80 }