Logo AND Algorithmique Numérique Distribuée

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