Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[project-description] Fix extraction of the ns-3 version.
[simgrid.git] / src / mc / ModelChecker.hpp
1 /* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_MC_MODEL_CHECKER_HPP
7 #define SIMGRID_MC_MODEL_CHECKER_HPP
8
9 #include "src/mc/remote/CheckerSide.hpp"
10 #include "src/mc/remote/RemotePtr.hpp"
11 #include "src/mc/sosp/PageStore.hpp"
12 #include "xbt/base.h"
13 #include "xbt/string.hpp"
14
15 #include <memory>
16 #include <set>
17
18 namespace simgrid::mc {
19
20 /** State of the model-checker (global variables for the model checker)
21  */
22 class ModelChecker {
23   CheckerSide checker_side_;
24   /** String pool for host names */
25   std::set<xbt::string, std::less<>> hostnames_;
26   // This is the parent snapshot of the current state:
27   PageStore page_store_{500};
28   std::unique_ptr<RemoteProcess> remote_process_;
29   Exploration* exploration_ = nullptr;
30
31   unsigned long visited_states_ = 0;
32
33   // Expect MessageType::SIMCALL_TO_STRING or MessageType::SIMCALL_DOT_LABEL
34   std::string simcall_to_string(MessageType type, aid_t aid, int times_considered);
35
36 public:
37   ModelChecker(ModelChecker const&) = delete;
38   ModelChecker& operator=(ModelChecker const&) = delete;
39   explicit ModelChecker(std::unique_ptr<RemoteProcess> remote_simulation, int sockfd);
40
41   RemoteProcess& get_remote_process() { return *remote_process_; }
42   Channel& channel() { return checker_side_.get_channel(); }
43   PageStore& page_store() { return page_store_; }
44
45   xbt::string const& get_host_name(const char* hostname)
46   {
47     return *this->hostnames_.insert(xbt::string(hostname)).first;
48   }
49
50   void start();
51   void shutdown();
52   void resume();
53   void wait_for_requests();
54
55   /** Let the application take a transition. A new Transition is created iff the last parameter is true */
56   Transition* handle_simcall(aid_t aid, int times_considered, bool new_transition);
57
58   /* Interactions with the simcall observer */
59   XBT_ATTRIB_NORETURN void exit(int status);
60
61   void finalize_app(bool terminate_asap = false);
62
63   Exploration* get_exploration() const { return exploration_; }
64   void set_exploration(Exploration* exploration) { exploration_ = exploration; }
65
66   unsigned long get_visited_states() const { return visited_states_; }
67   void inc_visited_states() { visited_states_++; }
68
69 private:
70   void setup_ignore();
71   bool handle_message(const char* buffer, ssize_t size);
72   void handle_waitpid();
73 };
74
75 } // namespace simgrid::mc
76
77 #endif