Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Big bang in MC: app's observers are serialized, to become transitions in checker
[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   Checker* checker_ = nullptr;
31
32   // Expect MessageType::SIMCALL_TO_STRING or MessageType::SIMCALL_DOT_LABEL
33   std::string simcall_to_string(MessageType type, aid_t aid, int times_considered);
34
35 public:
36   ModelChecker(ModelChecker const&) = delete;
37   ModelChecker& operator=(ModelChecker const&) = delete;
38   explicit ModelChecker(std::unique_ptr<RemoteProcess> remote_simulation, int sockfd);
39
40   RemoteProcess& get_remote_process() { return *remote_process_; }
41   Channel& channel() { return checker_side_.get_channel(); }
42   PageStore& page_store() { return page_store_; }
43
44   xbt::string const& get_host_name(const char* hostname)
45   {
46     return *this->hostnames_.insert(xbt::string(hostname)).first;
47   }
48
49   void start();
50   void shutdown();
51   void resume();
52   void wait_for_requests();
53   Transition* handle_simcall(Transition const& transition, bool new_transition);
54
55   /* Interactions with the simcall observer */
56   bool simcall_is_visible(aid_t aid);
57   std::string simcall_dot_label(aid_t aid, int times_considered);
58
59   XBT_ATTRIB_NORETURN void exit(int status);
60
61   bool checkDeadlock();
62   void finalize_app(bool terminate_asap = false);
63
64   Checker* getChecker() const { return checker_; }
65   void setChecker(Checker* checker) { checker_ = checker; }
66
67 private:
68   void setup_ignore();
69   bool handle_message(const char* buffer, ssize_t size);
70   void handle_waitpid();
71
72 public:
73   unsigned long visited_states = 0;
74 };
75
76 }
77 }
78
79 #endif