Logo AND Algorithmique Numérique Distribuée

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