Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Separate NetworkModel from LinkImpl.
[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/Session.hpp"
14 #include "src/mc/api/State.hpp"
15 #include "src/mc/mc_forward.hpp"
16 #include "src/mc/mc_record.hpp"
17 #include "xbt/automaton.hpp"
18 #include "xbt/base.h"
19
20 namespace simgrid {
21 namespace mc {
22
23 XBT_DECLARE_ENUM_CLASS(ExplorationAlgorithm, Safety, UDPOR, Liveness, CommDeterminism);
24
25 /*
26 ** This class aimes to implement FACADE APIs for simgrid. The FACADE layer sits between the CheckerSide
27 ** (Unfolding_Checker, DPOR, ...) layer and the
28 ** AppSide layer. The goal is to drill down into the entagled details in the CheckerSide layer and break down the
29 ** detailes in a way that the CheckerSide eventually
30 ** be capable to acquire the required information through the FACADE layer rather than the direct access to the AppSide.
31 */
32
33 class Api {
34 private:
35   Api() = default;
36
37   struct DerefAndCompareByActorsCountAndUsedHeap {
38     template <class X, class Y> bool operator()(X const& a, Y const& b) const
39     {
40       return std::make_pair(a->actors_count, a->heap_bytes_used) < std::make_pair(b->actors_count, b->heap_bytes_used);
41     }
42   };
43
44   std::unique_ptr<simgrid::mc::Session> session_;
45
46 public:
47   // No copy:
48   Api(Api const&) = delete;
49   void operator=(Api const&) = delete;
50
51   static Api& get()
52   {
53     static Api api;
54     return api;
55   }
56
57   simgrid::mc::Exploration* initialize(char** argv, simgrid::mc::ExplorationAlgorithm algo);
58
59   // ACTOR APIs
60   std::vector<simgrid::mc::ActorInformation>& get_actors() const;
61   unsigned long get_maxpid() const;
62
63   // REMOTE APIs
64   std::size_t get_remote_heap_bytes() const;
65
66   // MODEL CHECKER APIs
67   void mc_inc_visited_states() const;
68   unsigned long mc_get_visited_states() const;
69   XBT_ATTRIB_NORETURN void mc_exit(int status) const;
70
71   // STATE APIs
72   void restore_state(const Snapshot* system_state) const;
73
74   // SNAPSHOT APIs
75   bool snapshot_equal(const Snapshot* s1, const Snapshot* s2) const;
76   simgrid::mc::Snapshot* take_snapshot(long num_state) const;
77
78   // SESSION APIs
79   simgrid::mc::Session const& get_session() const { return *session_; }
80   void s_close();
81
82   // AUTOMATION APIs
83   void automaton_load(const char* file) const;
84   std::vector<int> automaton_propositional_symbol_evaluate() const;
85   std::vector<xbt_automaton_state_t> get_automaton_state() const;
86   int compare_automaton_exp_label(const xbt_automaton_exp_label* l) const;
87   void set_property_automaton(xbt_automaton_state_t const& automaton_state) const;
88   inline DerefAndCompareByActorsCountAndUsedHeap compare_pair() const
89   {
90     return DerefAndCompareByActorsCountAndUsedHeap();
91   }
92   xbt_automaton_exp_label_t get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const;
93   xbt_automaton_state_t get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const;
94 };
95
96 } // namespace mc
97 } // namespace simgrid
98
99 #endif