Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Better responsabilities splitup between CheckerSide and RemoteProcessMemory
[simgrid.git] / src / mc / explo / Exploration.cpp
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 #include "src/mc/explo/Exploration.hpp"
7 #include "src/mc/mc_config.hpp"
8 #include "src/mc/mc_exit.hpp"
9 #include "src/mc/mc_private.hpp"
10 #include "src/mc/sosp/RemoteProcessMemory.hpp"
11
12 #include <sys/wait.h>
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_explo, mc, "Generic exploration algorithm of the model-checker");
15
16 namespace simgrid::mc {
17
18 static simgrid::config::Flag<std::string> cfg_dot_output_file{
19     "model-check/dot-output", "Name of dot output file corresponding to graph state", ""};
20
21 Exploration* Exploration::instance_ = nullptr; // singleton instance
22
23 Exploration::Exploration(const std::vector<char*>& args) : remote_app_(std::make_unique<RemoteApp>(args))
24 {
25   xbt_assert(instance_ == nullptr, "Cannot have more than one exploration instance");
26   instance_ = this;
27
28   if (not cfg_dot_output_file.get().empty()) {
29     dot_output_ = fopen(cfg_dot_output_file.get().c_str(), "w");
30     xbt_assert(dot_output_ != nullptr, "Error open dot output file: %s", strerror(errno));
31
32     fprintf(dot_output_, "digraph graphname{\n fixedsize=true; rankdir=TB; ranksep=.25; edge [fontsize=12]; node "
33                          "[fontsize=10, shape=circle,width=.5 ]; graph [resolution=20, fontsize=10];\n");
34   }
35 }
36
37 Exploration::~Exploration()
38 {
39   if (dot_output_ != nullptr)
40     fclose(dot_output_);
41   instance_ = nullptr;
42 }
43
44 void Exploration::dot_output(const char* fmt, ...)
45 {
46   if (dot_output_ != nullptr) {
47     va_list ap;
48     va_start(ap, fmt);
49     vfprintf(dot_output_, fmt, ap);
50     va_end(ap);
51     fflush(dot_output_);
52   }
53 }
54
55 void Exploration::log_state()
56 {
57   if (not cfg_dot_output_file.get().empty()) {
58     dot_output("}\n");
59     fclose(dot_output_);
60   }
61   if (getenv("SIMGRID_MC_SYSTEM_STATISTICS")) {
62     int ret = system("free");
63     if (ret != 0)
64       XBT_WARN("Call to system(free) did not return 0, but %d", ret);
65   }
66 }
67
68 void Exploration::report_crash(int status)
69 {
70   XBT_INFO("**************************");
71   XBT_INFO("** CRASH IN THE PROGRAM **");
72   XBT_INFO("**************************");
73   if (WIFSIGNALED(status))
74     XBT_INFO("From signal: %s", strsignal(WTERMSIG(status)));
75   else if (WIFEXITED(status))
76     XBT_INFO("From exit: %i", WEXITSTATUS(status));
77   if (not xbt_log_no_loc)
78     XBT_INFO("%s core dump was generated by the system.", WCOREDUMP(status) ? "A" : "No");
79
80   XBT_INFO("Counter-example execution trace:");
81   for (auto const& s : get_textual_trace())
82     XBT_INFO("  %s", s.c_str());
83   XBT_INFO("You can debug the problem (and see the whole details) by rerunning out of simgrid-mc with "
84            "--cfg=model-check/replay:'%s'",
85            get_record_trace().to_string().c_str());
86   log_state();
87   if (xbt_log_no_loc) {
88     XBT_INFO("Stack trace not displayed because you passed --log=no_loc");
89   } else {
90     XBT_INFO("Stack trace:");
91     get_remote_app().get_remote_process_memory().dump_stack();
92   }
93
94   system_exit(SIMGRID_MC_EXIT_PROGRAM_CRASH);
95 }
96 void Exploration::report_assertion_failure()
97 {
98   XBT_INFO("**************************");
99   XBT_INFO("*** PROPERTY NOT VALID ***");
100   XBT_INFO("**************************");
101   XBT_INFO("Counter-example execution trace:");
102   for (auto const& s : get_textual_trace())
103     XBT_INFO("  %s", s.c_str());
104   XBT_INFO("You can debug the problem (and see the whole details) by rerunning out of simgrid-mc with "
105            "--cfg=model-check/replay:'%s'",
106            get_record_trace().to_string().c_str());
107   log_state();
108   system_exit(SIMGRID_MC_EXIT_SAFETY);
109 }
110
111 void Exploration::system_exit(int status)
112 {
113   get_remote_app().shutdown();
114   ::exit(status);
115 }
116
117 }; // namespace simgrid::mc