Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
16bfff72a830683e3cc09043c16bfdbe256aef4b
[simgrid.git] / src / mc / checker / LivenessChecker.hpp
1 /* Copyright (c) 2007-2015. 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 <cstddef>
11
12 #include <string>
13 #include <list>
14 #include <memory>
15 #include <vector>
16
17 #include <simgrid_config.h>
18 #include <xbt/base.h>
19 #include <xbt/automaton.h>
20 #include "src/mc/mc_state.h"
21 #include "src/mc/checker/Checker.hpp"
22
23 SG_BEGIN_DECL()
24
25 SG_END_DECL()
26
27 namespace simgrid {
28 namespace mc {
29
30 struct XBT_PRIVATE Pair {
31   int num = 0;
32   bool search_cycle = false;
33   std::shared_ptr<simgrid::mc::State> graph_state = nullptr; /* System state included */
34   xbt_automaton_state_t automaton_state = nullptr;
35   std::shared_ptr<const std::vector<int>> atomic_propositions;
36   int requests = 0;
37   int depth = 0;
38   bool exploration_started = false;
39
40   explicit Pair(unsigned long expanded_pairs);
41   ~Pair() = default;
42
43   Pair(Pair const&) = delete;
44   Pair& operator=(Pair const&) = delete;
45 };
46
47 struct XBT_PRIVATE VisitedPair {
48   int num;
49   int other_num = 0; /* Dot output for */
50   std::shared_ptr<simgrid::mc::State> graph_state = nullptr; /* System state included */
51   xbt_automaton_state_t automaton_state;
52   std::shared_ptr<const std::vector<int>> atomic_propositions;
53   std::size_t heap_bytes_used = 0;
54   int actors_count            = 0;
55
56   VisitedPair(
57     int pair_num, xbt_automaton_state_t automaton_state,
58     std::shared_ptr<const std::vector<int>> atomic_propositions,
59     std::shared_ptr<simgrid::mc::State> graph_state);
60   ~VisitedPair() = default;
61 };
62
63 class XBT_PRIVATE LivenessChecker : public Checker {
64 public:
65   explicit LivenessChecker(Session& session);
66   ~LivenessChecker() = default;
67   void run() override;
68   RecordTrace getRecordTrace() override;
69   std::vector<std::string> getTextualTrace() override;
70   void logState() override;
71 private:
72   int compare(simgrid::mc::VisitedPair* state1, simgrid::mc::VisitedPair* state2);
73   std::shared_ptr<const std::vector<int>> getPropositionValues();
74   std::shared_ptr<VisitedPair> insertAcceptancePair(simgrid::mc::Pair* pair);
75   int insertVisitedPair(std::shared_ptr<VisitedPair> visited_pair, simgrid::mc::Pair* pair);
76   void showAcceptanceCycle(std::size_t depth);
77   void replay();
78   void removeAcceptancePair(int pair_num);
79   void purgeVisitedPairs();
80   void backtrack();
81   std::shared_ptr<Pair> newPair(Pair* pair, xbt_automaton_state_t state, std::shared_ptr<const std::vector<int>> propositions);
82 private:
83   // A stack of (application_state, automaton_state) pairs for DFS exploration:
84   std::list<std::shared_ptr<Pair>> explorationStack_;
85   std::list<std::shared_ptr<VisitedPair>> acceptancePairs_;
86   std::list<std::shared_ptr<VisitedPair>> visitedPairs_;
87   unsigned long visitedPairsCount_ = 0;
88   unsigned long expandedPairsCount_ = 0;
89   unsigned long expandedStatesCount_ = 0;
90   int previousPair_ = 0;
91   std::string previousRequest_;
92 };
93
94 }
95 }
96
97 #endif