Logo AND Algorithmique Numérique Distribuée

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