Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f94a9e171b06fb93f93926e7d9a12640dc64910f
[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 extern XBT_PRIVATE xbt_automaton_t property_automaton;
33
34 struct XBT_PRIVATE Pair {
35   int num = 0;
36   bool search_cycle = false;
37   std::shared_ptr<simgrid::mc::State> graph_state = nullptr; /* System state included */
38   xbt_automaton_state_t automaton_state = nullptr;
39   std::vector<int> atomic_propositions;
40   int requests = 0;
41   int depth = 0;
42   bool exploration_started = false;
43
44   Pair();
45   ~Pair();
46
47   Pair(Pair const&) = delete;
48   Pair& operator=(Pair const&) = delete;
49 };
50
51 struct XBT_PRIVATE VisitedPair {
52   int num = 0;
53   int other_num = 0; /* Dot output for */
54   std::shared_ptr<simgrid::mc::State> graph_state = nullptr; /* System state included */
55   xbt_automaton_state_t automaton_state = nullptr;
56   std::vector<int> atomic_propositions;
57   std::size_t heap_bytes_used = 0;
58   int nb_processes = 0;
59
60   VisitedPair(
61     int pair_num, xbt_automaton_state_t automaton_state,
62     std::vector<int> const& atomic_propositions,
63     std::shared_ptr<simgrid::mc::State> graph_state);
64   ~VisitedPair();
65 };
66
67 class XBT_PRIVATE LivenessChecker : public Checker {
68 public:
69   LivenessChecker(Session& session);
70   ~LivenessChecker();
71   int run() override;
72   RecordTrace getRecordTrace() override;
73   std::vector<std::string> getTextualTrace() override;
74 private:
75   int main();
76   void prepare();
77   int compare(simgrid::mc::VisitedPair* state1, simgrid::mc::VisitedPair* state2);
78   std::vector<int> getPropositionValues();
79   std::shared_ptr<VisitedPair> insertAcceptancePair(simgrid::mc::Pair* pair);
80   int insertVisitedPair(std::shared_ptr<VisitedPair> visited_pair, simgrid::mc::Pair* pair);
81   void showAcceptanceCycle(std::size_t depth);
82   void replay();
83   void removeAcceptancePair(int pair_num);
84   void purgeVisitedPairs();
85 public:
86   std::list<std::shared_ptr<VisitedPair>> acceptancePairs_;
87   std::list<std::shared_ptr<Pair>> livenessStack_;
88   std::list<std::shared_ptr<VisitedPair>> visitedPairs_;
89 };
90
91 }
92 }
93
94 #endif