Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1134b94a3269f59fbf055ca7ded57f8debb2dd82
[simgrid.git] / src / mc / api.hpp
1 /* Copyright (c) 2020-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 #ifndef SIMGRID_MC_API_HPP
7 #define SIMGRID_MC_API_HPP
8
9 #include <memory>
10 #include <vector>
11
12 #include "simgrid/forward.h"
13 #include "src/mc/api/State.hpp"
14 #include "src/mc/mc_forward.hpp"
15 #include "src/mc/mc_record.hpp"
16 #include "xbt/automaton.hpp"
17 #include "xbt/base.h"
18
19 namespace simgrid {
20 namespace mc {
21
22 XBT_DECLARE_ENUM_CLASS(CheckerAlgorithm, Safety, UDPOR, Liveness, CommDeterminism);
23
24 /**
25  * @brief Maintains the transition's information.
26  */
27 struct s_transition_detail {
28   simgrid::simix::Simcall call_ = simgrid::simix::Simcall::NONE;
29   long issuer_id                = -1;
30   RemotePtr<kernel::activity::MailboxImpl> mbox_remote_addr {}; // used to represent mailbox remote address for isend and ireceive transitions
31   RemotePtr<kernel::activity::ActivityImpl> comm_remote_addr {}; // the communication this transition concerns (to be used only for isend, ireceive, wait and test)
32 };
33
34 using transition_detail_t = std::unique_ptr<s_transition_detail>;
35
36 /*
37 ** This class aimes to implement FACADE APIs for simgrid. The FACADE layer sits between the CheckerSide
38 ** (Unfolding_Checker, DPOR, ...) layer and the
39 ** AppSide layer. The goal is to drill down into the entagled details in the CheckerSide layer and break down the
40 ** detailes in a way that the CheckerSide eventually
41 ** be capable to acquire the required information through the FACADE layer rather than the direct access to the AppSide.
42 */
43
44 class Api {
45 private:
46   Api() = default;
47
48   struct DerefAndCompareByActorsCountAndUsedHeap {
49     template <class X, class Y> bool operator()(X const& a, Y const& b) const
50     {
51       return std::make_pair(a->actors_count, a->heap_bytes_used) < std::make_pair(b->actors_count, b->heap_bytes_used);
52     }
53   };
54
55 public:
56   // No copy:
57   Api(Api const&) = delete;
58   void operator=(Api const&) = delete;
59
60   static Api& get()
61   {
62     static Api api;
63     return api;
64   }
65
66   simgrid::mc::Checker* initialize(char** argv, simgrid::mc::CheckerAlgorithm algo) const;
67
68   // ACTOR APIs
69   std::vector<simgrid::mc::ActorInformation>& get_actors() const;
70   unsigned long get_maxpid() const;
71
72   // COMMUNICATION APIs
73   xbt::string const& get_actor_name(smx_actor_t actor) const;
74   xbt::string const& get_actor_host_name(smx_actor_t actor) const;
75
76   // REMOTE APIs
77   std::size_t get_remote_heap_bytes() const;
78
79   // MODEL CHECKER APIs
80   void mc_inc_visited_states() const;
81   unsigned long mc_get_visited_states() const;
82   XBT_ATTRIB_NORETURN void mc_exit(int status) const;
83
84   // STATE APIs
85   void restore_state(std::shared_ptr<simgrid::mc::Snapshot> system_state) const;
86
87   // SNAPSHOT APIs
88   bool snapshot_equal(const Snapshot* s1, const Snapshot* s2) const;
89   simgrid::mc::Snapshot* take_snapshot(long num_state) const;
90
91   // SESSION APIs
92   void s_close() const;
93
94 // AUTOMATION APIs
95 #if SIMGRID_HAVE_MC
96   void automaton_load(const char* file) const;
97 #endif
98   std::vector<int> automaton_propositional_symbol_evaluate() const;
99   std::vector<xbt_automaton_state_t> get_automaton_state() const;
100   int compare_automaton_exp_label(const xbt_automaton_exp_label* l) const;
101   void set_property_automaton(xbt_automaton_state_t const& automaton_state) const;
102   inline DerefAndCompareByActorsCountAndUsedHeap compare_pair() const
103   {
104     return DerefAndCompareByActorsCountAndUsedHeap();
105   }
106   inline int automaton_state_compare(const_xbt_automaton_state_t const& s1, const_xbt_automaton_state_t const& s2) const
107   {
108     return xbt_automaton_state_compare(s1, s2);
109   }
110   xbt_automaton_exp_label_t get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const;
111   xbt_automaton_state_t get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const;
112 };
113
114 } // namespace mc
115 } // namespace simgrid
116
117 #endif