Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further tidy the includes in MC
[simgrid.git] / src / mc / ModelChecker.hpp
1 /* Copyright (c) 2007-2019. 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_;
25   struct event* socket_event_;
26   struct event* signal_event_;
27   /** String pool for host names */
28   // TODO, use std::set with heterogeneous comparison lookup (C++14)?
29   std::set<std::string> hostnames_;
30   // This is the parent snapshot of the current state:
31   PageStore page_store_;
32   std::unique_ptr<RemoteClient> process_;
33   Checker* checker_ = nullptr;
34 public:
35   std::shared_ptr<simgrid::mc::Snapshot> parent_snapshot_;
36
37   ModelChecker(ModelChecker const&) = delete;
38   ModelChecker& operator=(ModelChecker const&) = delete;
39   explicit ModelChecker(std::unique_ptr<RemoteClient> process);
40   ~ModelChecker();
41
42   RemoteClient& process() { return *process_; }
43   PageStore& page_store()
44   {
45     return page_store_;
46   }
47
48   std::string const& get_host_name(const char* hostname)
49   {
50     return *this->hostnames_.insert(hostname).first;
51   }
52   std::string const& get_host_name(std::string const& hostname)
53   {
54     return *this->hostnames_.insert(hostname).first;
55   }
56
57   void start();
58   void shutdown();
59   void resume(simgrid::mc::RemoteClient& process);
60   void loop();
61   void handle_events(int fd, short events);
62   void wait_for_requests();
63   void handle_simcall(Transition const& transition);
64   XBT_ATTRIB_NORETURN void exit(int status);
65
66   bool checkDeadlock();
67
68   Checker* getChecker() const { return checker_; }
69   void setChecker(Checker* checker) { checker_ = checker; }
70
71 private:
72   void setup_ignore();
73   bool handle_message(char* buffer, ssize_t size);
74   void handle_waitpid();
75   void on_signal(int signo);
76
77 public:
78   unsigned long visited_states = 0;
79   unsigned long executed_transitions = 0;
80 };
81
82 }
83 }
84
85 #endif