Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more informative message when java needs libcgraph
[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 <poll.h>
13 #include <memory>
14
15 #include <simgrid_config.h>
16 #include <xbt/dict.h>
17 #include <xbt/base.h>
18 #include <sys/types.h>
19
20 #include "src/mc/mc_forward.hpp"
21 #include "src/mc/Process.hpp"
22 #include "src/mc/PageStore.hpp"
23 #include "src/mc/mc_protocol.h"
24
25 namespace simgrid {
26 namespace mc {
27
28 /** State of the model-checker (global variables for the model checker)
29  */
30 class ModelChecker {
31   struct pollfd fds_[2];
32   /** String pool for host names */
33   // TODO, use std::set with heterogeneous comparison lookup (C++14)?
34   xbt_dict_t /* <hostname, nullptr> */ hostnames_;
35   // This is the parent snapshot of the current state:
36   PageStore page_store_;
37   std::unique_ptr<Process> process_;
38   Checker* checker_ = nullptr;
39 public:
40   std::shared_ptr<simgrid::mc::Snapshot> parent_snapshot_;
41
42 public:
43   ModelChecker(ModelChecker const&) = delete;
44   ModelChecker& operator=(ModelChecker const&) = delete;
45   ModelChecker(std::unique_ptr<Process> process);
46   ~ModelChecker();
47
48   Process& process()
49   {
50     return *process_;
51   }
52   PageStore& page_store()
53   {
54     return page_store_;
55   }
56   const char* get_host_name(const char* name);
57
58   void start();
59   void shutdown();
60   void resume(simgrid::mc::Process& process);
61   void loop();
62   bool handle_events();
63   void wait_client(simgrid::mc::Process& process);
64   void simcall_handle(simgrid::mc::Process& process, unsigned long pid, int value);
65   void wait_for_requests()
66   {
67     mc_model_checker->wait_client(mc_model_checker->process());
68   }
69   void exit(int status);
70
71   bool checkDeadlock();
72
73   Checker* getChecker() const { return checker_; }
74   void setChecker(Checker* checker) { checker_ = checker; }
75
76 private:
77   void setup_ignore();
78   bool handle_message(char* buffer, ssize_t size);
79   void handle_signals();
80   void handle_waitpid();
81   void on_signal(const struct signalfd_siginfo* info);
82
83 };
84
85 }
86 }
87
88 #endif