Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
95543458ec6b83e1fca88aaa57962dc869bbe358
[simgrid.git] / src / mc / ModelChecker.hpp
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_MODEL_CHECKER_HPP
8 #define SIMGRID_MC_MODEL_CHECKER_HPP
9
10 #include <sys/types.h>
11
12 #include <memory>
13 #include <set>
14 #include <string>
15
16 #include <event2/event.h>
17
18 #include "xbt/base.h"
19 #include <sys/types.h>
20
21 #include "src/mc/PageStore.hpp"
22 #include "src/mc/Transition.hpp"
23 #include "src/mc/mc_forward.hpp"
24 #include "src/mc/remote/RemoteClient.hpp"
25 #include "src/mc/remote/mc_protocol.h"
26
27 namespace simgrid {
28 namespace mc {
29
30 /** State of the model-checker (global variables for the model checker)
31  */
32 class ModelChecker {
33   struct event_base *base_;
34   struct event* socket_event_;
35   struct event* signal_event_;
36   /** String pool for host names */
37   // TODO, use std::set with heterogeneous comparison lookup (C++14)?
38   std::set<std::string> hostnames_;
39   // This is the parent snapshot of the current state:
40   PageStore page_store_;
41   std::unique_ptr<RemoteClient> process_;
42   Checker* checker_ = nullptr;
43 public:
44   std::shared_ptr<simgrid::mc::Snapshot> parent_snapshot_;
45
46 public:
47   ModelChecker(ModelChecker const&) = delete;
48   ModelChecker& operator=(ModelChecker const&) = delete;
49   explicit ModelChecker(std::unique_ptr<RemoteClient> process);
50   ~ModelChecker();
51
52   RemoteClient& process() { return *process_; }
53   PageStore& page_store()
54   {
55     return page_store_;
56   }
57
58   std::string const& get_host_name(const char* hostname)
59   {
60     return *this->hostnames_.insert(hostname).first;
61   }
62   std::string const& get_host_name(std::string const& hostname)
63   {
64     return *this->hostnames_.insert(hostname).first;
65   }
66
67   void start();
68   void shutdown();
69   void resume(simgrid::mc::RemoteClient& process);
70   void loop();
71   void handle_events(int fd, short events);
72   void wait_client(simgrid::mc::RemoteClient& process);
73   void handle_simcall(Transition const& transition);
74   void wait_for_requests()
75   {
76     mc_model_checker->wait_client(mc_model_checker->process());
77   }
78   void exit(int status);
79
80   bool checkDeadlock();
81
82   Checker* getChecker() const { return checker_; }
83   void setChecker(Checker* checker) { checker_ = checker; }
84
85 private:
86   void setup_ignore();
87   bool handle_message(char* buffer, ssize_t size);
88   void handle_waitpid();
89   void on_signal(int signo);
90
91 public:
92   unsigned long visited_states = 0;
93   unsigned long executed_transitions = 0;
94 };
95
96 }
97 }
98
99 #endif