Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'issue105' into 'master'
[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 {
19 namespace mc {
20
21 /** State of the model-checker (global variables for the model checker)
22  */
23 class ModelChecker {
24   CheckerSide checker_side_;
25   /** String pool for host names */
26   std::set<xbt::string, std::less<>> hostnames_;
27   // This is the parent snapshot of the current state:
28   PageStore page_store_{500};
29   std::unique_ptr<RemoteProcess> remote_process_;
30   Exploration* exploration_ = nullptr;
31
32   unsigned long visited_states_ = 0;
33
34   // Expect MessageType::SIMCALL_TO_STRING or MessageType::SIMCALL_DOT_LABEL
35   std::string simcall_to_string(MessageType type, aid_t aid, int times_considered);
36
37 public:
38   ModelChecker(ModelChecker const&) = delete;
39   ModelChecker& operator=(ModelChecker const&) = delete;
40   explicit ModelChecker(std::unique_ptr<RemoteProcess> remote_simulation, int sockfd);
41
42   RemoteProcess& get_remote_process() { return *remote_process_; }
43   Channel& channel() { return checker_side_.get_channel(); }
44   PageStore& page_store() { return page_store_; }
45
46   xbt::string const& get_host_name(const char* hostname)
47   {
48     return *this->hostnames_.insert(xbt::string(hostname)).first;
49   }
50
51   void start();
52   void shutdown();
53   void resume();
54   void wait_for_requests();
55
56   /** Let the application take a transition. A new Transition is created iff the last parameter is true */
57   Transition* handle_simcall(aid_t aid, int times_considered, bool new_transition);
58
59   /* Interactions with the simcall observer */
60   XBT_ATTRIB_NORETURN void exit(int status);
61
62   void finalize_app(bool terminate_asap = false);
63
64   Exploration* get_exploration() const { return exploration_; }
65   void set_exploration(Exploration* exploration) { exploration_ = exploration; }
66
67   unsigned long get_visited_states() const { return visited_states_; }
68   void inc_visited_states() { visited_states_++; }
69
70 private:
71   void setup_ignore();
72   bool handle_message(const char* buffer, ssize_t size);
73   void handle_waitpid();
74 };
75
76 }
77 }
78
79 #endif