Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ad79c59ee69017e766d8b116d96064d1e1e00db2
[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/VisitedState.hpp"
10 #include "src/mc/explo/Exploration.hpp"
11
12 #include <list>
13 #include <memory>
14 #include <string>
15 #include <vector>
16
17 namespace simgrid::mc {
18
19 class XBT_PRIVATE DFSExplorer : public Exploration {
20   XBT_DECLARE_ENUM_CLASS(ReductionMode, none, dpor);
21
22   ReductionMode reduction_mode_;
23   long backtrack_count_        = 0;
24
25   static xbt::signal<void(RemoteApp&)> on_exploration_start_signal;
26   static xbt::signal<void(RemoteApp&)> on_backtracking_signal;
27
28   static xbt::signal<void(State*, RemoteApp&)> on_state_creation_signal;
29
30   static xbt::signal<void(State*, RemoteApp&)> on_restore_system_state_signal;
31   static xbt::signal<void(RemoteApp&)> on_restore_initial_state_signal;
32   static xbt::signal<void(Transition*, RemoteApp&)> on_transition_replay_signal;
33   static xbt::signal<void(Transition*, RemoteApp&)> on_transition_execute_signal;
34
35   static xbt::signal<void(RemoteApp&)> on_log_state_signal;
36
37 public:
38   explicit DFSExplorer(const std::vector<char*>& args, bool with_dpor);
39   void run() override;
40   RecordTrace get_record_trace() override;
41   std::vector<std::string> get_textual_trace() override;
42   void log_state() override;
43
44   /** Called once when the exploration starts */
45   static void on_exploration_start(std::function<void(RemoteApp& remote_app)> const& f)
46   {
47     on_exploration_start_signal.connect(f);
48   }
49   /** Called each time that the exploration backtracks from a exploration end */
50   static void on_backtracking(std::function<void(RemoteApp& remote_app)> const& f)
51   {
52     on_backtracking_signal.connect(f);
53   }
54   /** Called each time that a new state is create */
55   static void on_state_creation(std::function<void(State*, RemoteApp& remote_app)> const& f)
56   {
57     on_state_creation_signal.connect(f);
58   }
59   /** Called when rollbacking directly onto a previously checkpointed state */
60   static void on_restore_system_state(std::function<void(State*, RemoteApp& remote_app)> const& f)
61   {
62     on_restore_system_state_signal.connect(f);
63   }
64   /** Called when the state to which we backtrack was not checkpointed state, forcing us to restore the initial state
65    * before replaying some transitions */
66   static void on_restore_initial_state(std::function<void(RemoteApp& remote_app)> const& f)
67   {
68     on_restore_initial_state_signal.connect(f);
69   }
70   /** Called when replaying a transition that was previously executed, to reach a backtracked state */
71   static void on_transition_replay(std::function<void(Transition*, RemoteApp& remote_app)> const& f)
72   {
73     on_transition_replay_signal.connect(f);
74   }
75   /** Called when executing a new transition */
76   static void on_transition_execute(std::function<void(Transition*, RemoteApp& remote_app)> const& f)
77   {
78     on_transition_execute_signal.connect(f);
79   }
80   /** Called when displaying the statistics at the end of the exploration */
81   static void on_log_state(std::function<void(RemoteApp&)> const& f) { on_log_state_signal.connect(f); }
82
83 private:
84   void check_non_termination(const State* current_state);
85   void backtrack();
86   bool sleep_set_reduction_;
87
88   /** Stack representing the position in the exploration graph */
89   std::list<std::unique_ptr<State>> stack_;
90   VisitedStates visited_states_;
91   std::unique_ptr<VisitedState> visited_state_;
92 };
93
94 } // namespace simgrid::mc
95
96 #endif