Logo AND Algorithmique Numérique Distribuée

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