Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
504f6826cfb204d8bfa3b2829db6908d3aae4a04
[simgrid.git] / src / mc / ModelChecker.hpp
1 /* Copyright (c) 2007-2022. 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/remote/CheckerSide.hpp"
10 #include "src/mc/remote/RemotePtr.hpp"
11 #include "src/mc/sosp/PageStore.hpp"
12 #include "xbt/base.h"
13
14 #include <memory>
15 #include <set>
16
17 namespace simgrid::mc {
18
19 /** State of the model-checker (global variables for the model checker)
20  */
21 class ModelChecker {
22   CheckerSide checker_side_;
23   /** String pool for host names */
24   std::set<std::string, std::less<>> hostnames_;
25   // This is the parent snapshot of the current state:
26   PageStore page_store_{500};
27   std::unique_ptr<RemoteProcess> remote_process_;
28   Exploration* exploration_ = nullptr;
29
30   FILE* dot_output_ = nullptr;
31
32   unsigned long visited_states_ = 0;
33
34 public:
35   ModelChecker(ModelChecker const&) = delete;
36   ModelChecker& operator=(ModelChecker const&) = delete;
37   explicit ModelChecker(std::unique_ptr<RemoteProcess> remote_simulation, int sockfd);
38
39   RemoteProcess& get_remote_process() { return *remote_process_; }
40   Channel& channel() { return checker_side_.get_channel(); }
41   PageStore& page_store() { return page_store_; }
42
43   std::string const& get_host_name(const char* hostname) { return *this->hostnames_.insert(hostname).first; }
44
45   void start();
46   void shutdown();
47   void resume();
48   void wait_for_requests();
49
50   /** Let the application take a transition. A new Transition is created iff the last parameter is true */
51   Transition* handle_simcall(aid_t aid, int times_considered, bool new_transition);
52
53   /* Interactions with the simcall observer */
54   XBT_ATTRIB_NORETURN void exit(int status);
55
56   void finalize_app(bool terminate_asap = false);
57
58   Exploration* get_exploration() const { return exploration_; }
59   void set_exploration(Exploration* exploration) { exploration_ = exploration; }
60
61   unsigned long get_visited_states() const { return visited_states_; }
62   void inc_visited_states() { visited_states_++; }
63
64   void dot_output(const char* fmt, ...) XBT_ATTRIB_PRINTF(2, 3);
65   void dot_output_flush()
66   {
67     if (dot_output_ != nullptr)
68       fflush(dot_output_);
69   }
70   void dot_output_close()
71   {
72     if (dot_output_ != nullptr)
73       fclose(dot_output_);
74   }
75
76 private:
77   void setup_ignore();
78   bool handle_message(const char* buffer, ssize_t size);
79   void handle_waitpid();
80 };
81
82 } // namespace simgrid::mc
83
84 #endif