Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC further cleanups (let it compile, this time)
[simgrid.git] / src / mc / Session.hpp
1 /* Copyright (c) 2016-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_SESSION_HPP
7 #define SIMGRID_MC_SESSION_HPP
8
9 #include "simgrid/forward.h"
10 #include "src/mc/ModelChecker.hpp"
11 #include "src/mc/api/ActorState.hpp"
12 #include "src/mc/remote/RemotePtr.hpp"
13
14 #include <functional>
15
16 namespace simgrid::mc {
17
18 /** A model-checking session
19  *
20  *  This is expected to become the interface used by model-checking
21  *  algorithms to control the execution of the model-checked process
22  *  and the exploration of the execution graph. Model-checking
23  *  algorithms should be able to be written in high-level languages
24  *  (e.g. Python) using bindings on this interface.
25  */
26 class XBT_PUBLIC Session {
27 private:
28   std::unique_ptr<ModelChecker> model_checker_;
29   std::shared_ptr<simgrid::mc::Snapshot> initial_snapshot_;
30
31   // No copy:
32   Session(Session const&) = delete;
33   Session& operator=(Session const&) = delete;
34
35 public:
36   /** Create a new session by executing the provided code in a fork()
37    *
38    *  This sets up the environment for the model-checked process
39    *  (environment variables, sockets, etc.).
40    *
41    *  The code is expected to `exec` the model-checked application.
42    */
43   explicit Session(const std::function<void()>& code);
44
45   ~Session();
46   void close();
47
48   void take_initial_snapshot();
49   void restore_initial_state() const;
50
51   /** Ask to the application to check for a deadlock. If so, do an error message and throw a DeadlockError. */
52   void check_deadlock() const;
53
54   void log_state() const;
55
56   void get_actors_status(std::map<aid_t, ActorState>& whereto);
57 };
58 } // namespace simgrid::mc
59
60 #endif