1 /* Copyright (c) 2008-2022. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_MC_SAFETY_CHECKER_HPP
7 #define SIMGRID_MC_SAFETY_CHECKER_HPP
9 #include "src/mc/VisitedState.hpp"
10 #include "src/mc/explo/Exploration.hpp"
11 #include "src/mc/mc_safety.hpp"
21 class XBT_PRIVATE DFSExplorer : public Exploration {
22 ReductionMode reductionMode_ = ReductionMode::unset;
23 long backtrack_count_ = 0;
25 static xbt::signal<void()> on_exploration_start_signal;
26 static xbt::signal<void()> on_backtracking_signal;
28 static xbt::signal<void(State*)> on_state_creation_signal;
30 static xbt::signal<void(State*)> on_restore_system_state_signal;
31 static xbt::signal<void()> on_restore_initial_state_signal;
32 static xbt::signal<void(Transition*)> on_transition_replay_signal;
33 static xbt::signal<void(Transition*)> on_transition_execute_signal;
35 static xbt::signal<void()> on_log_state_signal;
38 explicit DFSExplorer(Session* session);
40 RecordTrace get_record_trace() override;
41 std::vector<std::string> get_textual_trace() override;
42 void log_state() override;
44 /** Called once when the exploration starts */
45 static void on_exploration_start(std::function<void()> const& f) { on_exploration_start_signal.connect(f); }
46 /** Called each time that the exploration backtracks from a exploration end */
47 static void on_backtracking(std::function<void()> const& f) { on_backtracking_signal.connect(f); }
48 /** Called each time that a new state is create */
49 static void on_state_creation(std::function<void(State*)> const& f) { on_state_creation_signal.connect(f); }
50 /** Called when rollbacking directly onto a previously checkpointed state */
51 static void on_restore_system_state(std::function<void(State*)> const& f)
53 on_restore_system_state_signal.connect(f);
55 /** Called when the state to which we backtrack was not checkpointed state, forcing us to restore the initial state
56 * before replaying some transitions */
57 static void on_restore_initial_state(std::function<void()> const& f) { on_restore_initial_state_signal.connect(f); }
58 /** Called when replaying a transition that was previously executed, to reach a backtracked state */
59 static void on_transition_replay(std::function<void(Transition*)> const& f)
61 on_transition_replay_signal.connect(f);
63 /** Called when executing a new transition */
64 static void on_transition_execute(std::function<void(Transition*)> const& f)
66 on_transition_execute_signal.connect(f);
68 /** Called when displaying the statistics at the end of the exploration */
69 static void on_log_state(std::function<void()> const& f) { on_log_state_signal.connect(f); }
72 void check_non_termination(const State* current_state);
76 /** Stack representing the position in the exploration graph */
77 std::list<std::unique_ptr<State>> stack_;
78 VisitedStates visited_states_;
79 std::unique_ptr<VisitedState> visited_state_;
83 } // namespace simgrid