Logo AND Algorithmique Numérique Distribuée

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