1 /* Copyright (c) 2007-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef SIMGRID_MC_LIVENESS_CHECKER_HPP
8 #define SIMGRID_MC_LIVENESS_CHECKER_HPP
17 #include <simgrid_config.h>
19 #include <xbt/automaton.h>
20 #include <xbt/memory.hpp>
21 #include "src/mc/mc_state.h"
22 #include "src/mc/Checker.hpp"
31 struct XBT_PRIVATE Pair {
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;
39 bool exploration_started = false;
41 Pair(unsigned long expanded_pairs);
44 Pair(Pair const&) = delete;
45 Pair& operator=(Pair const&) = delete;
48 struct XBT_PRIVATE VisitedPair {
50 int other_num = 0; /* Dot output for */
51 std::shared_ptr<simgrid::mc::State> graph_state = nullptr; /* System state included */
52 xbt_automaton_state_t automaton_state = nullptr;
53 std::shared_ptr<const std::vector<int>> atomic_propositions;
54 std::size_t heap_bytes_used = 0;
58 int pair_num, xbt_automaton_state_t automaton_state,
59 std::shared_ptr<const std::vector<int>> atomic_propositions,
60 std::shared_ptr<simgrid::mc::State> graph_state);
64 class XBT_PRIVATE LivenessChecker : public Checker {
66 LivenessChecker(Session& session);
69 RecordTrace getRecordTrace() override;
70 std::vector<std::string> getTextualTrace() override;
71 void logState() override;
75 int compare(simgrid::mc::VisitedPair* state1, simgrid::mc::VisitedPair* state2);
76 std::shared_ptr<const 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);
81 void removeAcceptancePair(int pair_num);
82 void purgeVisitedPairs();
84 std::shared_ptr<Pair> newPair(Pair* pair, xbt_automaton_state_t state, std::shared_ptr<const std::vector<int>> propositions);
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 unsigned long visitedPairsCount_ = 0;
91 unsigned long expandedPairsCount_ = 0;
92 unsigned long expandedStatesCount_ = 0;
93 int previousPair_ = 0;
94 std::string previousRequest_;