1 /* Copyright (c) 2007-2020. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_MC_LIVENESS_CHECKER_HPP
8 #define SIMGRID_MC_LIVENESS_CHECKER_HPP
10 #include "src/mc/checker/Checker.hpp"
11 #include "src/mc/mc_state.hpp"
12 #include "xbt/automaton.hpp"
21 class XBT_PRIVATE Pair {
24 bool search_cycle = false;
25 std::shared_ptr<State> graph_state = nullptr; /* System state included */
26 xbt_automaton_state_t automaton_state = nullptr;
27 std::shared_ptr<const std::vector<int>> atomic_propositions;
30 bool exploration_started = false;
32 explicit Pair(unsigned long expanded_pairs);
35 Pair(Pair const&) = delete;
36 Pair& operator=(Pair const&) = delete;
39 class XBT_PRIVATE VisitedPair {
42 int other_num = 0; /* Dot output for */
43 std::shared_ptr<State> graph_state = nullptr; /* System state included */
44 xbt_automaton_state_t automaton_state;
45 std::shared_ptr<const std::vector<int>> atomic_propositions;
46 std::size_t heap_bytes_used = 0;
49 VisitedPair(int pair_num, xbt_automaton_state_t automaton_state,
50 std::shared_ptr<const std::vector<int>> atomic_propositions, std::shared_ptr<State> graph_state);
51 ~VisitedPair() = default;
54 class XBT_PRIVATE LivenessChecker : public Checker {
56 explicit LivenessChecker(Session& session);
57 ~LivenessChecker() override = default;
59 RecordTrace get_record_trace() override;
60 std::vector<std::string> get_textual_trace() override;
61 void log_state() override;
64 std::shared_ptr<const std::vector<int>> get_proposition_values() const;
65 std::shared_ptr<VisitedPair> insert_acceptance_pair(Pair* pair);
66 int insert_visited_pair(std::shared_ptr<VisitedPair> visited_pair, Pair* pair);
67 void show_acceptance_cycle(std::size_t depth);
69 void remove_acceptance_pair(int pair_num);
70 void purge_visited_pairs();
72 std::shared_ptr<Pair> create_pair(const Pair* pair, xbt_automaton_state_t state,
73 std::shared_ptr<const std::vector<int>> propositions);
75 // A stack of (application_state, automaton_state) pairs for DFS exploration:
76 std::list<std::shared_ptr<Pair>> exploration_stack_;
77 std::list<std::shared_ptr<VisitedPair>> acceptance_pairs_;
78 std::list<std::shared_ptr<VisitedPair>> visited_pairs_;
79 unsigned long visited_pairs_count_ = 0;
80 unsigned long expanded_pairs_count_ = 0;
81 unsigned long expanded_states_count_ = 0;
82 int previous_pair_ = 0;
83 std::string previous_request_;
87 } // namespace simgrid