Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
dbb5e5dc857bf07a24a2037122e902da7b456c9c
[simgrid.git] / src / mc / api / RemoteApp.hpp
1 /* Copyright (c) 2016-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_REMOTE_APP_HPP
7 #define SIMGRID_MC_REMOTE_APP_HPP
8
9 #include "simgrid/forward.h"
10 #include "src/mc/api/ActorState.hpp"
11 #include "src/mc/remote/CheckerSide.hpp"
12 #include "src/mc/remote/RemotePtr.hpp"
13 #include "src/mc/sosp/PageStore.hpp"
14
15 #include <functional>
16
17 namespace simgrid::mc {
18
19 /** High-level view of the verified application, from the model-checker POV
20  *
21  *  This is expected to become the interface used by model-checking algorithms to control the execution of
22  *  the application process during the exploration of the execution graph.
23  *
24  *  One day, this will allow parallel exploration, ie, the handling of several application processes (each encapsulated
25  * in a separate CheckerSide objects) that explore several parts of the exploration graph.
26  */
27 class XBT_PUBLIC RemoteApp {
28 private:
29 #if SIMGRID_HAVE_STATEFUL_MC
30   PageStore page_store_{500};
31   std::shared_ptr<simgrid::mc::Snapshot> initial_snapshot_;
32 #else
33   void* initial_snapshot_ = nullptr; // The code tests it to decide whether to use the refork exec path
34 #endif
35   std::unique_ptr<CheckerSide> checker_side_;
36   std::unique_ptr<CheckerSide> application_factory_; // when no meminfo, create checker_side_ by cloning this one
37   int master_socket_ = -1;
38
39   const std::vector<char*> app_args_;
40
41   // No copy:
42   RemoteApp(RemoteApp const&) = delete;
43   RemoteApp& operator=(RemoteApp const&) = delete;
44
45 public:
46   /** Create a new session by executing the provided code in a fork()
47    *
48    *  This sets up the environment for the model-checked process
49    *  (environment variables, sockets, etc.).
50    *
51    *  The code is expected to `exec` the model-checked application.
52    */
53   explicit RemoteApp(const std::vector<char*>& args, bool need_memory_introspection);
54
55   void restore_initial_state();
56   void wait_for_requests();
57
58   /** Ask to the application to check for a deadlock. If so, do an error message and throw a McError(DEADLOCK). */
59   void check_deadlock() const;
60
61   /** Ask the application to run post-mortem analysis, and maybe to stop ASAP */
62   void finalize_app(bool terminate_asap = false);
63
64   /** Retrieve the max PID of the running actors */
65   unsigned long get_maxpid() const;
66
67   /* Get the list of actors that are ready to run at that step. Usually shorter than maxpid */
68   void get_actors_status(std::map<aid_t, simgrid::mc::ActorState>& whereto) const;
69
70   /** Take a transition. A new Transition is created iff the last parameter is true */
71   Transition* handle_simcall(aid_t aid, int times_considered, bool new_transition);
72
73 #if SIMGRID_HAVE_STATEFUL_MC
74   /* Get the memory of the remote process */
75   RemoteProcessMemory* get_remote_process_memory() { return checker_side_->get_remote_memory(); }
76
77   PageStore& get_page_store() { return page_store_; }
78 #endif
79 };
80 } // namespace simgrid::mc
81
82 #endif