Logo AND Algorithmique Numérique Distribuée

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