Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename mc::RemoteSimulation into mc::RemoteProcess
[simgrid.git] / src / mc / ModelChecker.hpp
1 /* Copyright (c) 2007-2021. 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/sosp/PageStore.hpp"
11 #include "xbt/base.h"
12 #include "xbt/string.hpp"
13
14 #include <memory>
15 #include <set>
16
17 namespace simgrid {
18 namespace 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   Checker* checker_ = nullptr;
30
31   // Expect MessageType::SIMCALL_TO_STRING or MessageType::SIMCALL_DOT_LABEL
32   std::string simcall_to_string(MessageType type, int aid, int times_considered);
33
34 public:
35   ModelChecker(ModelChecker const&) = delete;
36   ModelChecker& operator=(ModelChecker const&) = delete;
37   explicit ModelChecker(std::unique_ptr<RemoteProcess> remote_simulation, int sockfd);
38
39   RemoteProcess& get_remote_simulation() { return *remote_process_; }
40   Channel& channel() { return checker_side_.get_channel(); }
41   PageStore& page_store()
42   {
43     return page_store_;
44   }
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(simgrid::mc::RemoteProcess& get_remote_simulation);
54   void wait_for_requests();
55   void handle_simcall(Transition const& transition);
56
57   /* Interactions with the simcall observer */
58   bool simcall_is_visible(int aid);
59   std::string simcall_to_string(int aid, int times_considered);
60   std::string simcall_dot_label(int aid, int times_considered);
61
62   XBT_ATTRIB_NORETURN void exit(int status);
63
64   bool checkDeadlock();
65
66   Checker* getChecker() const { return checker_; }
67   void setChecker(Checker* checker) { checker_ = checker; }
68
69 private:
70   void setup_ignore();
71   bool handle_message(const char* buffer, ssize_t size);
72   void handle_waitpid();
73
74 public:
75   unsigned long visited_states = 0;
76   unsigned long executed_transitions = 0;
77 };
78
79 }
80 }
81
82 #endif