Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
283366cda808ab5e22cf1f9fe375b62b3f5bd5df
[simgrid.git] / src / mc / Session.hpp
1 /* Copyright (c) 2016-2019. 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 "src/mc/ModelChecker.hpp"
10
11 #include <functional>
12
13 namespace simgrid {
14 namespace mc {
15
16 /** A model-checking session
17  *
18  *  This is expected to become the interface used by model-checking
19  *  algorithms to control the execution of the model-checked process
20  *  and the exploration of the execution graph. Model-checking
21  *  algorithms should be able to be written in high-level languages
22  *  (e.g. Python) using bindings on this interface.
23  */
24 class Session {
25 private:
26   std::unique_ptr<ModelChecker> model_checker_;
27   std::shared_ptr<simgrid::mc::Snapshot> initial_snapshot_;
28
29   Session(pid_t pid, int socket);
30
31   // No copy:
32   Session(Session const&) = delete;
33   Session& operator=(Session const&) = delete;
34
35 public:
36   ~Session();
37   void close();
38
39   void initialize();
40   void execute(Transition const& transition);
41   void log_state();
42
43   void restore_initial_state();
44
45   // static constructors
46
47   /** Create a new session by forking
48    *
49    *  This sets up the environment for the model-checked process
50    *  (environment variables, sockets, etc.).
51    *
52    *  The code is expected to `exec` the model-checker program.
53    */
54   static Session* fork(const std::function<void()>& code);
55
56   /** Spawn a model-checked process
57    *
58    *  @param path full path of the executable
59    *  @param argv arguments for the model-checked process (NULL-terminated)
60    */
61   static Session* spawnv(const char *path, char *const argv[]);
62
63   /** Spawn a model-checked process (using PATH)
64    *
65    *  @param file file name of the executable (found using `PATH`)
66    *  @param argv arguments for the model-checked process (NULL-terminated)
67    */
68   static Session* spawnvp(const char *file, char *const argv[]);
69 };
70
71 // Temporary :)
72 extern simgrid::mc::Session* session;
73
74 }
75 }
76
77 #endif