Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: rename remote/EventLoop into remote/CheckerSide
[simgrid.git] / src / mc / ModelChecker.hpp
1 /* Copyright (c) 2007-2020. 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
13 #include <memory>
14 #include <set>
15 #include <string>
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 event_loop_;
24   /** String pool for host names */
25   std::set<std::string> hostnames_;
26   // This is the parent snapshot of the current state:
27   PageStore page_store_{500};
28   std::unique_ptr<RemoteClient> process_;
29   Checker* checker_ = nullptr;
30
31 public:
32   ModelChecker(ModelChecker const&) = delete;
33   ModelChecker& operator=(ModelChecker const&) = delete;
34   explicit ModelChecker(std::unique_ptr<RemoteClient> process);
35
36   RemoteClient& process() { return *process_; }
37   PageStore& page_store()
38   {
39     return page_store_;
40   }
41
42   std::string const& get_host_name(std::string const& hostname)
43   {
44     return *this->hostnames_.insert(hostname).first;
45   }
46
47   void start();
48   void shutdown();
49   void resume(simgrid::mc::RemoteClient& process);
50   void handle_events(int fd, short events);
51   void wait_for_requests();
52   void handle_simcall(Transition const& transition);
53   XBT_ATTRIB_NORETURN void exit(int status);
54
55   bool checkDeadlock();
56
57   Checker* getChecker() const { return checker_; }
58   void setChecker(Checker* checker) { checker_ = checker; }
59
60 private:
61   void setup_ignore();
62   bool handle_message(const char* buffer, ssize_t size);
63   void handle_waitpid();
64   void on_signal(int signo);
65
66 public:
67   unsigned long visited_states = 0;
68   unsigned long executed_transitions = 0;
69 };
70
71 }
72 }
73
74 #endif