Logo AND Algorithmique Numérique Distribuée

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