Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: simplify initialization and kill api::set_checker()
[simgrid.git] / src / mc / api.hpp
1 #ifndef SIMGRID_MC_API_HPP
2 #define SIMGRID_MC_API_HPP
3
4 #include <memory>
5 #include <vector>
6
7 #include "simgrid/forward.h"
8 #include "src/mc/mc_forward.hpp"
9 #include "src/mc/mc_record.hpp"
10 #include "src/mc/mc_request.hpp"
11 #include "src/mc/mc_state.hpp"
12 #include "xbt/automaton.hpp"
13 #include "xbt/base.h"
14
15 namespace simgrid {
16 namespace mc {
17
18 XBT_DECLARE_ENUM_CLASS(CheckerAlgorithm, Safety, UDPOR, Liveness, CommDeterminism);
19
20 /**
21  * @brief Maintains the transition's information.
22  */
23 struct s_transition_detail {
24   simgrid::simix::Simcall call_ = simgrid::simix::Simcall::NONE;
25   long issuer_id                = -1;
26   RemotePtr<kernel::activity::MailboxImpl> mbox_remote_addr {}; // used to represent mailbox remote address for isend and ireceive transitions
27   RemotePtr<kernel::activity::ActivityImpl> comm_remote_addr {}; // the communication this transition concerns (to be used only for isend, ireceive, wait and test)
28 };
29
30 using transition_detail_t = std::unique_ptr<s_transition_detail>;
31
32 /*
33 ** This class aimes to implement FACADE APIs for simgrid. The FACADE layer sits between the CheckerSide
34 ** (Unfolding_Checker, DPOR, ...) layer and the
35 ** AppSide layer. The goal is to drill down into the entagled details in the CheckerSide layer and break down the
36 ** detailes in a way that the CheckerSide eventually
37 ** be capable to acquire the required information through the FACADE layer rather than the direct access to the AppSide.
38 */
39
40 class Api {
41 private:
42   Api() = default;
43
44   struct DerefAndCompareByActorsCountAndUsedHeap {
45     template <class X, class Y> bool operator()(X const& a, Y const& b) const
46     {
47       return std::make_pair(a->actors_count, a->heap_bytes_used) < std::make_pair(b->actors_count, b->heap_bytes_used);
48     }
49   };
50
51   simgrid::kernel::activity::CommImpl* get_comm_or_nullptr(smx_simcall_t const r) const;
52   bool request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2) const;
53   simgrid::mc::ActorInformation* actor_info_cast(smx_actor_t actor) const;
54   std::string get_actor_name(smx_actor_t actor) const;
55   std::string get_actor_string(smx_actor_t actor) const;
56   std::string get_actor_dot_label(smx_actor_t actor) const;
57
58 public:
59   // No copy:
60   Api(Api const&) = delete;
61   void operator=(Api const&) = delete;
62
63   static Api& get()
64   {
65     static Api api;
66     return api;
67   }
68
69   simgrid::mc::Checker* initialize(char** argv, simgrid::mc::CheckerAlgorithm algo) const;
70
71   // ACTOR APIs
72   std::vector<simgrid::mc::ActorInformation>& get_actors() const;
73   bool actor_is_enabled(aid_t pid) const;
74   unsigned long get_maxpid() const;
75   int get_actors_size() const;
76
77   // COMMUNICATION APIs
78   RemotePtr<kernel::activity::CommImpl> get_comm_isend_raw_addr(smx_simcall_t request) const;
79   RemotePtr<kernel::activity::CommImpl> get_comm_waitany_raw_addr(smx_simcall_t request, int value) const;
80   std::string get_pattern_comm_rdv(RemotePtr<kernel::activity::CommImpl> const& addr) const;
81   unsigned long get_pattern_comm_src_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const;
82   unsigned long get_pattern_comm_dst_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const;
83   std::vector<char> get_pattern_comm_data(RemotePtr<kernel::activity::CommImpl> const& addr) const;
84   xbt::string const& get_actor_host_name(smx_actor_t actor) const;
85 #if HAVE_SMPI
86   bool check_send_request_detached(smx_simcall_t const& simcall) const;
87 #endif
88   smx_actor_t get_src_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const;
89   smx_actor_t get_dst_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const;
90
91   // REMOTE APIs
92   std::size_t get_remote_heap_bytes() const;
93
94   // MODEL CHECKER APIs
95   void mc_inc_visited_states() const;
96   void mc_inc_executed_trans() const;
97   unsigned long mc_get_visited_states() const;
98   unsigned long mc_get_executed_trans() const;
99   void mc_check_deadlock() const;
100   bool mc_is_null() const;
101   Checker* mc_get_checker() const;
102   void handle_simcall(Transition const& transition) const;
103   void mc_wait_for_requests() const;
104   XBT_ATTRIB_NORETURN void mc_exit(int status) const;
105   void dump_record_path() const;
106   smx_simcall_t mc_state_choose_request(simgrid::mc::State* state) const;
107
108   // UDPOR APIs
109   std::list<transition_detail_t> get_enabled_transitions(simgrid::mc::State* state) const;
110
111   // SIMCALL APIs
112   std::string request_to_string(smx_simcall_t req, int value) const;
113   std::string request_get_dot_output(smx_simcall_t req, int value) const;
114   smx_actor_t simcall_get_issuer(s_smx_simcall const* req) const;
115   long simcall_get_actor_id(s_smx_simcall const* req) const;
116   RemotePtr<kernel::activity::MailboxImpl> get_mbox_remote_addr(smx_simcall_t const req) const;
117   RemotePtr<kernel::activity::ActivityImpl> get_comm_remote_addr(smx_simcall_t const req) const;
118   bool simcall_check_dependency(smx_simcall_t const req1, smx_simcall_t const req2) const;
119
120 #if HAVE_SMPI
121   int get_smpi_request_tag(smx_simcall_t const& simcall, simgrid::simix::Simcall type) const;
122 #endif
123
124   // STATE APIs
125   void restore_state(std::shared_ptr<simgrid::mc::Snapshot> system_state) const;
126   void log_state() const;
127   void restore_initial_state() const;
128
129   // SNAPSHOT APIs
130   bool snapshot_equal(const Snapshot* s1, const Snapshot* s2) const;
131   simgrid::mc::Snapshot* take_snapshot(int num_state) const;
132
133   // SESSION APIs
134   void session_initialize() const;
135   void s_close() const;
136   void execute(Transition& transition, smx_simcall_t simcall) const;
137
138 // AUTOMATION APIs
139 #if SIMGRID_HAVE_MC
140   void automaton_load(const char* file) const;
141 #endif
142   std::vector<int> automaton_propositional_symbol_evaluate() const;
143   std::vector<xbt_automaton_state_t> get_automaton_state() const;
144   int compare_automaton_exp_label(const xbt_automaton_exp_label* l) const;
145   void set_property_automaton(xbt_automaton_state_t const& automaton_state) const;
146   inline DerefAndCompareByActorsCountAndUsedHeap compare_pair() const
147   {
148     return DerefAndCompareByActorsCountAndUsedHeap();
149   }
150   inline int automaton_state_compare(const_xbt_automaton_state_t const& s1, const_xbt_automaton_state_t const& s2) const
151   {
152     return xbt_automaton_state_compare(s1, s2);
153   }
154   xbt_automaton_exp_label_t get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const;
155   xbt_automaton_state_t get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const;
156
157   // DYNAR APIs
158   inline unsigned long get_dynar_length(const_xbt_dynar_t const& dynar) const { return xbt_dynar_length(dynar); }
159 };
160
161 } // namespace mc
162 } // namespace simgrid
163
164 #endif