Logo AND Algorithmique Numérique Distribuée

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