Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move MC_report() functions as static functions where they're used
[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 #include "src/mc/Transition.hpp"
25
26 namespace simgrid {
27 namespace mc {
28
29 /** State of the model-checker (global variables for the model checker)
30  */
31 class ModelChecker {
32   struct pollfd fds_[2];
33   /** String pool for host names */
34   // TODO, use std::set with heterogeneous comparison lookup (C++14)?
35   xbt_dict_t /* <hostname, nullptr> */ hostnames_;
36   // This is the parent snapshot of the current state:
37   PageStore page_store_;
38   std::unique_ptr<Process> process_;
39   Checker* checker_ = nullptr;
40 public:
41   std::shared_ptr<simgrid::mc::Snapshot> parent_snapshot_;
42
43 public:
44   ModelChecker(ModelChecker const&) = delete;
45   ModelChecker& operator=(ModelChecker const&) = delete;
46   ModelChecker(std::unique_ptr<Process> process);
47   ~ModelChecker();
48
49   Process& process()
50   {
51     return *process_;
52   }
53   PageStore& page_store()
54   {
55     return page_store_;
56   }
57   const char* get_host_name(const char* name);
58
59   void start();
60   void shutdown();
61   void resume(simgrid::mc::Process& process);
62   void loop();
63   bool handle_events();
64   void wait_client(simgrid::mc::Process& process);
65   void handle_simcall(Transition const& transition);
66   void wait_for_requests()
67   {
68     mc_model_checker->wait_client(mc_model_checker->process());
69   }
70   void exit(int status);
71
72   bool checkDeadlock();
73
74   Checker* getChecker() const { return checker_; }
75   void setChecker(Checker* checker) { checker_ = checker; }
76
77 private:
78   void setup_ignore();
79   bool handle_message(char* buffer, ssize_t size);
80   void handle_signals();
81   void handle_waitpid();
82   void on_signal(const struct signalfd_siginfo* info);
83
84 public:
85   unsigned long visited_states = 0;
86   unsigned long executed_transitions = 0;
87 };
88
89 }
90 }
91
92 #endif