Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[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 <simgrid_config.h>
19 #include <xbt/base.h>
20 #include <sys/types.h>
21
22 #include "src/mc/PageStore.hpp"
23 #include "src/mc/Process.hpp"
24 #include "src/mc/Transition.hpp"
25 #include "src/mc/mc_forward.hpp"
26 #include "src/mc/remote/mc_protocol.h"
27
28 namespace simgrid {
29 namespace mc {
30
31 /** State of the model-checker (global variables for the model checker)
32  */
33 class ModelChecker {
34   struct event_base *base_;
35   struct event *socket_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<Process> 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   ModelChecker(std::unique_ptr<Process> process);
50   ~ModelChecker();
51
52   Process& process()
53   {
54     return *process_;
55   }
56   PageStore& page_store()
57   {
58     return page_store_;
59   }
60
61   std::string const& get_host_name(const char* hostname)
62   {
63     return *this->hostnames_.insert(hostname).first;
64   }
65   std::string const& get_host_name(std::string const& hostname)
66   {
67     return *this->hostnames_.insert(hostname).first;
68   }
69
70   void start();
71   void shutdown();
72   void resume(simgrid::mc::Process& process);
73   void loop();
74   void handle_events(int fd, short events);
75   void wait_client(simgrid::mc::Process& process);
76   void handle_simcall(Transition const& transition);
77   void wait_for_requests()
78   {
79     mc_model_checker->wait_client(mc_model_checker->process());
80   }
81   void exit(int status);
82
83   bool checkDeadlock();
84
85   Checker* getChecker() const { return checker_; }
86   void setChecker(Checker* checker) { checker_ = checker; }
87
88 private:
89   void setup_ignore();
90   bool handle_message(char* buffer, ssize_t size);
91   void handle_waitpid();
92   void on_signal(int signo);
93
94 public:
95   unsigned long visited_states = 0;
96   unsigned long executed_transitions = 0;
97 };
98
99 }
100 }
101
102 #endif