Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'pikachuyann/simgrid-xbt_random'
[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/sosp/PageStore.hpp"
10 #include "xbt/base.h"
11
12 #include <memory>
13 #include <set>
14 #include <string>
15
16 #include <event2/event.h>
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   struct event_base* base_    = nullptr;
25   struct event* socket_event_ = nullptr;
26   struct event* signal_event_ = nullptr;
27   /** String pool for host names */
28   std::set<std::string> hostnames_;
29   // This is the parent snapshot of the current state:
30   PageStore page_store_{500};
31   std::unique_ptr<RemoteClient> process_;
32   Checker* checker_ = nullptr;
33
34 public:
35   ModelChecker(ModelChecker const&) = delete;
36   ModelChecker& operator=(ModelChecker const&) = delete;
37   explicit ModelChecker(std::unique_ptr<RemoteClient> process);
38   ~ModelChecker();
39
40   RemoteClient& process() { return *process_; }
41   PageStore& page_store()
42   {
43     return page_store_;
44   }
45
46   std::string const& get_host_name(std::string const& hostname)
47   {
48     return *this->hostnames_.insert(hostname).first;
49   }
50
51   void start();
52   void shutdown();
53   void resume(simgrid::mc::RemoteClient& process);
54   void loop();
55   void handle_events(int fd, short events);
56   void wait_for_requests();
57   void handle_simcall(Transition const& transition);
58   XBT_ATTRIB_NORETURN void exit(int status);
59
60   bool checkDeadlock();
61
62   Checker* getChecker() const { return checker_; }
63   void setChecker(Checker* checker) { checker_ = checker; }
64
65 private:
66   void setup_ignore();
67   bool handle_message(const char* buffer, ssize_t size);
68   void handle_waitpid();
69   void on_signal(int signo);
70
71 public:
72   unsigned long visited_states = 0;
73   unsigned long executed_transitions = 0;
74 };
75
76 }
77 }
78
79 #endif