Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e90523ca9d5d49aba77e0a4ffd5223da60aa8ef8
[simgrid.git] / src / mc / checker / LivenessChecker.hpp
1 /* Copyright (c) 2007-2019. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef SIMGRID_MC_LIVENESS_CHECKER_HPP
8 #define SIMGRID_MC_LIVENESS_CHECKER_HPP
9
10 #include "src/mc/checker/Checker.hpp"
11 #include "src/mc/mc_state.hpp"
12 #include "xbt/automaton.hpp"
13
14 #include <list>
15 #include <memory>
16 #include <vector>
17
18 namespace simgrid {
19 namespace mc {
20
21 class XBT_PRIVATE Pair {
22 public:
23   int num = 0;
24   bool search_cycle = false;
25   std::shared_ptr<simgrid::mc::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;
28   int requests = 0;
29   int depth = 0;
30   bool exploration_started = false;
31
32   explicit Pair(unsigned long expanded_pairs);
33   ~Pair() = default;
34
35   Pair(Pair const&) = delete;
36   Pair& operator=(Pair const&) = delete;
37 };
38
39 class XBT_PRIVATE VisitedPair {
40 public:
41   int num;
42   int other_num = 0; /* Dot output for */
43   std::shared_ptr<simgrid::mc::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;
47   int actors_count            = 0;
48
49   VisitedPair(
50     int pair_num, xbt_automaton_state_t automaton_state,
51     std::shared_ptr<const std::vector<int>> atomic_propositions,
52     std::shared_ptr<simgrid::mc::State> graph_state);
53   ~VisitedPair() = default;
54 };
55
56 class XBT_PRIVATE LivenessChecker : public Checker {
57 public:
58   explicit LivenessChecker(Session& session);
59   ~LivenessChecker() = default;
60   void run() override;
61   RecordTrace get_record_trace() override;
62   std::vector<std::string> get_textual_trace() override;
63   void log_state() override;
64
65 private:
66   int compare(simgrid::mc::VisitedPair* state1, simgrid::mc::VisitedPair* state2);
67   std::shared_ptr<const std::vector<int>> get_proposition_values();
68   std::shared_ptr<VisitedPair> insert_acceptance_pair(simgrid::mc::Pair* pair);
69   int insert_visited_pair(std::shared_ptr<VisitedPair> visited_pair, simgrid::mc::Pair* pair);
70   void show_acceptance_cycle(std::size_t depth);
71   void replay();
72   void remove_acceptance_pair(int pair_num);
73   void purge_visited_pairs();
74   void backtrack();
75   std::shared_ptr<Pair> create_pair(Pair* pair, xbt_automaton_state_t state,
76                                     std::shared_ptr<const std::vector<int>> propositions);
77
78   // A stack of (application_state, automaton_state) pairs for DFS exploration:
79   std::list<std::shared_ptr<Pair>> exploration_stack_;
80   std::list<std::shared_ptr<VisitedPair>> acceptance_pairs_;
81   std::list<std::shared_ptr<VisitedPair>> visited_pairs_;
82   unsigned long visited_pairs_count_   = 0;
83   unsigned long expanded_pairs_count_  = 0;
84   unsigned long expanded_states_count_ = 0;
85   int previous_pair_                   = 0;
86   std::string previous_request_;
87 };
88
89 }
90 }
91
92 #endif