Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove the stateful model-checking from the archive. It's not working anymore
[simgrid.git] / src / mc / explo / DFSExplorer.hpp
1 /* Copyright (c) 2008-2023. 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_SAFETY_CHECKER_HPP
7 #define SIMGRID_MC_SAFETY_CHECKER_HPP
8
9 #include "src/mc/api/ClockVector.hpp"
10 #include "src/mc/api/State.hpp"
11 #include "src/mc/explo/Exploration.hpp"
12 #include "src/mc/explo/odpor/Execution.hpp"
13 #include "src/mc/mc_config.hpp"
14
15 #include <deque>
16 #include <list>
17 #include <memory>
18 #include <set>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22
23 namespace simgrid::mc {
24
25 using stack_t = std::deque<std::shared_ptr<State>>;
26
27 class XBT_PRIVATE DFSExplorer : public Exploration {
28 private:
29   ReductionMode reduction_mode_;
30   unsigned long backtrack_count_      = 0; // for statistics
31   unsigned long visited_states_count_ = 0; // for statistics
32
33   static xbt::signal<void(RemoteApp&)> on_exploration_start_signal;
34   static xbt::signal<void(RemoteApp&)> on_backtracking_signal;
35
36   static xbt::signal<void(State*, RemoteApp&)> on_state_creation_signal;
37
38   static xbt::signal<void(State*, RemoteApp&)> on_restore_system_state_signal;
39   static xbt::signal<void(RemoteApp&)> on_restore_initial_state_signal;
40   static xbt::signal<void(Transition*, RemoteApp&)> on_transition_replay_signal;
41   static xbt::signal<void(Transition*, RemoteApp&)> on_transition_execute_signal;
42
43   static xbt::signal<void(RemoteApp&)> on_log_state_signal;
44
45 public:
46   explicit DFSExplorer(const std::vector<char*>& args, ReductionMode mode);
47   void run() override;
48   RecordTrace get_record_trace() override;
49   void log_state() override;
50
51   /** Called once when the exploration starts */
52   static void on_exploration_start(std::function<void(RemoteApp& remote_app)> const& f)
53   {
54     on_exploration_start_signal.connect(f);
55   }
56   /** Called each time that the exploration backtracks from a exploration end */
57   static void on_backtracking(std::function<void(RemoteApp& remote_app)> const& f)
58   {
59     on_backtracking_signal.connect(f);
60   }
61   /** Called each time that a new state is create */
62   static void on_state_creation(std::function<void(State*, RemoteApp& remote_app)> const& f)
63   {
64     on_state_creation_signal.connect(f);
65   }
66   /** Called when rollbacking directly onto a previously checkpointed state */
67   static void on_restore_system_state(std::function<void(State*, RemoteApp& remote_app)> const& f)
68   {
69     on_restore_system_state_signal.connect(f);
70   }
71   /** Called when the state to which we backtrack was not checkpointed state, forcing us to restore the initial state
72    * before replaying some transitions */
73   static void on_restore_initial_state(std::function<void(RemoteApp& remote_app)> const& f)
74   {
75     on_restore_initial_state_signal.connect(f);
76   }
77   /** Called when replaying a transition that was previously executed, to reach a backtracked state */
78   static void on_transition_replay(std::function<void(Transition*, RemoteApp& remote_app)> const& f)
79   {
80     on_transition_replay_signal.connect(f);
81   }
82   /** Called when executing a new transition */
83   static void on_transition_execute(std::function<void(Transition*, RemoteApp& remote_app)> const& f)
84   {
85     on_transition_execute_signal.connect(f);
86   }
87   /** Called when displaying the statistics at the end of the exploration */
88   static void on_log_state(std::function<void(RemoteApp&)> const& f) { on_log_state_signal.connect(f); }
89
90 private:
91   void backtrack();
92
93   /** Stack representing the position in the exploration graph */
94   stack_t stack_;
95
96   /**
97    * Provides additional metadata about the position in the exploration graph
98    * which is used by SDPOR and ODPOR
99    */
100   odpor::Execution execution_seq_;
101
102   /** Per-actor clock vectors used to compute the "happens-before" relation */
103   std::unordered_map<aid_t, ClockVector> per_actor_clocks_;
104
105   /** Opened states are states that still contains todo actors.
106    *  When backtracking, we pick a state from it*/
107   std::vector<std::shared_ptr<State>> opened_states_;
108   std::shared_ptr<State> best_opened_state();
109
110   /** If we're running ODPOR, picks the corresponding state in the stack
111    * (opened_states_ are ignored)
112    */
113   std::shared_ptr<State> next_odpor_state();
114
115   /** Change current stack_ value to correspond to the one we would have
116    *  had if we executed transition to get to state. This is required when
117    *  backtracking, and achieved thanks to the fact states save their parent.*/
118   void restore_stack(std::shared_ptr<State> state);
119
120   RecordTrace get_record_trace_of_stack(stack_t stack);
121 };
122
123 } // namespace simgrid::mc
124
125 #endif