Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / mc / explo / Exploration.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_CHECKER_HPP
7 #define SIMGRID_MC_CHECKER_HPP
8
9 #include "simgrid/forward.h"
10 #include "src/mc/api/RemoteApp.hpp"
11 #include "src/mc/mc_record.hpp"
12 #include <xbt/Extendable.hpp>
13
14 #include <memory>
15
16 namespace simgrid::mc {
17
18 /** A model-checking exploration algorithm
19  *
20  *  This is an abstract base class used to group the data, state, configuration
21  *  of a model-checking algorithm.
22  *
23  *  Implementing this interface will probably not be really mandatory,
24  *  you might be able to write your model-checking algorithm as plain
25  *  imperative code instead.
26  *
27  *  It is expected to interact with the model-checked application through the
28  * `RemoteApp` interface (that is currently not perfectly sufficient to that extend). */
29 // abstract
30 class Exploration : public xbt::Extendable<Exploration> {
31   std::unique_ptr<RemoteApp> remote_app_;
32   static Exploration* instance_;
33
34   FILE* dot_output_ = nullptr;
35
36 public:
37   explicit Exploration(const std::vector<char*>& args);
38   virtual ~Exploration();
39
40   static Exploration* get_instance() { return instance_; }
41   // No copy:
42   Exploration(Exploration const&) = delete;
43   Exploration& operator=(Exploration const&) = delete;
44
45   /** Main function of this algorithm */
46   virtual void run() = 0;
47
48   /** Produce an error message indicating that the application crashed (status was produced by waitpid) */
49   void report_crash(int status);
50   /** Produce an error message indicating that a property was violated */
51   void report_assertion_failure();
52
53   /** Kill the application and the model-checker (which exits with `status`)*/
54   XBT_ATTRIB_NORETURN void system_exit(int status);
55
56   /* These methods are callbacks called by the model-checking engine
57    * to get and display information about the current state of the
58    * model-checking algorithm: */
59
60   /** Show the current trace/stack
61    *
62    *  Could this be handled in the Session/ModelChecker instead? */
63   virtual RecordTrace get_record_trace() = 0;
64
65   /** Generate a textual execution trace of the simulated application */
66   virtual std::vector<std::string> get_textual_trace() = 0;
67
68   /** Log additional information about the state of the model-checker */
69   virtual void log_state();
70
71   RemoteApp& get_remote_app() { return *remote_app_.get(); }
72
73   /** Print something to the dot output file*/
74   void dot_output(const char* fmt, ...) XBT_ATTRIB_PRINTF(2, 3);
75 };
76
77 // External constructors so that the types (and the types of their content) remain hidden
78 XBT_PUBLIC Exploration* create_liveness_checker(const std::vector<char*>& args);
79 XBT_PUBLIC Exploration* create_dfs_exploration(const std::vector<char*>& args, bool with_dpor);
80 XBT_PUBLIC Exploration* create_communication_determinism_checker(const std::vector<char*>& args, bool with_dpor);
81 XBT_PUBLIC Exploration* create_udpor_checker(const std::vector<char*>& args);
82
83 } // namespace simgrid::mc
84
85 #endif