1 /* Copyright (c) 2016-2023. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_MC_REMOTE_APP_HPP
7 #define SIMGRID_MC_REMOTE_APP_HPP
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"
16 namespace simgrid::mc {
18 /** High-level view of the verified application, from the model-checker POV
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.
26 class XBT_PUBLIC RemoteApp {
28 std::unique_ptr<CheckerSide> checker_side_;
29 std::unique_ptr<ModelChecker> model_checker_;
30 PageStore page_store_{500};
31 std::shared_ptr<simgrid::mc::Snapshot> initial_snapshot_;
34 RemoteApp(RemoteApp const&) = delete;
35 RemoteApp& operator=(RemoteApp const&) = delete;
38 /** Create a new session by executing the provided code in a fork()
40 * This sets up the environment for the model-checked process
41 * (environment variables, sockets, etc.).
43 * The code is expected to `exec` the model-checked application.
45 explicit RemoteApp(const std::vector<char*>& args);
50 void restore_initial_state() const;
51 void wait_for_requests();
53 /** Ask to the application to check for a deadlock. If so, do an error message and throw a DeadlockError. */
54 void check_deadlock() const;
56 /** Ask the application to run post-mortem analysis, and maybe to stop ASAP */
57 void finalize_app(bool terminate_asap = false);
58 /** Forcefully kill the application (after running post-mortem analysis)*/
61 /** Retrieve the max PID of the running actors */
62 unsigned long get_maxpid() const;
64 /* Get the list of actors that are ready to run at that step. Usually shorter than maxpid */
65 void get_actors_status(std::map<aid_t, simgrid::mc::ActorState>& whereto) const;
67 /** Take a transition. A new Transition is created iff the last parameter is true */
68 Transition* handle_simcall(aid_t aid, int times_considered, bool new_transition);
70 /* Get the memory of the remote process */
71 RemoteProcessMemory& get_remote_process_memory() { return model_checker_->get_remote_process_memory(); }
73 PageStore& get_page_store() { return page_store_; }
75 } // namespace simgrid::mc