X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/bf3ddeb867d4053ee01ee6d070d0839a9f61b6ab..86a552c797938ffe6db296e12b7043c3c7fdf14f:/src/mc/explo/Exploration.cpp diff --git a/src/mc/explo/Exploration.cpp b/src/mc/explo/Exploration.cpp index 3fc6127081..8bf01108a3 100644 --- a/src/mc/explo/Exploration.cpp +++ b/src/mc/explo/Exploration.cpp @@ -5,9 +5,14 @@ #include "src/mc/explo/Exploration.hpp" #include "src/mc/mc_config.hpp" +#include "src/mc/mc_environ.h" #include "src/mc/mc_exit.hpp" #include "src/mc/mc_private.hpp" +#include "xbt/string.hpp" + +#if SIMGRID_HAVE_STATEFUL_MC #include "src/mc/sosp/RemoteProcessMemory.hpp" +#endif #include @@ -18,9 +23,13 @@ namespace simgrid::mc { static simgrid::config::Flag cfg_dot_output_file{ "model-check/dot-output", "Name of dot output file corresponding to graph state", ""}; -Exploration::Exploration(const std::vector& args) : remote_app_(std::make_unique(args)) +Exploration* Exploration::instance_ = nullptr; // singleton instance + +Exploration::Exploration(const std::vector& args, bool need_memory_introspection) + : remote_app_(std::make_unique(args, need_memory_introspection)) { - mc_model_checker->set_exploration(this); + xbt_assert(instance_ == nullptr, "Cannot have more than one exploration instance"); + instance_ = this; if (not cfg_dot_output_file.get().empty()) { dot_output_ = fopen(cfg_dot_output_file.get().c_str(), "w"); @@ -35,6 +44,7 @@ Exploration::~Exploration() { if (dot_output_ != nullptr) fclose(dot_output_); + instance_ = nullptr; } void Exploration::dot_output(const char* fmt, ...) @@ -54,20 +64,40 @@ void Exploration::log_state() dot_output("}\n"); fclose(dot_output_); } - if (getenv("SIMGRID_MC_SYSTEM_STATISTICS")) { + if (getenv(MC_ENV_SYSTEM_STATISTICS)) { int ret = system("free"); if (ret != 0) XBT_WARN("Call to system(free) did not return 0, but %d", ret); } } +// Make our tests fully reproducible despite the subtle differences of strsignal() across archs +static const char* signal_name(int status) +{ + switch (WTERMSIG(status)) { + case SIGABRT: // FreeBSD uses "Abort trap" as a strsignal for SIGABRT + return "Aborted"; + case SIGSEGV: // MacOSX uses "Segmentation fault: 11" for SIGKILL + return "Segmentation fault"; + default: + return strsignal(WTERMSIG(status)); + } +} -void Exploration::report_crash(int status) +std::vector Exploration::get_textual_trace() +{ + std::vector trace; + for (auto const& transition : get_record_trace()) + trace.push_back(xbt::string_printf("%ld: %s", transition->aid_, transition->to_string().c_str())); + return trace; +} + +XBT_ATTRIB_NORETURN void Exploration::report_crash(int status) { XBT_INFO("**************************"); XBT_INFO("** CRASH IN THE PROGRAM **"); XBT_INFO("**************************"); if (WIFSIGNALED(status)) - XBT_INFO("From signal: %s", strsignal(WTERMSIG(status))); + XBT_INFO("From signal: %s", signal_name(status)); else if (WIFEXITED(status)) XBT_INFO("From exit: %i", WEXITSTATUS(status)); if (not xbt_log_no_loc) @@ -83,18 +113,31 @@ void Exploration::report_crash(int status) if (xbt_log_no_loc) { XBT_INFO("Stack trace not displayed because you passed --log=no_loc"); } else { - XBT_INFO("Stack trace:"); - get_remote_app().get_remote_process_memory().dump_stack(); +#if SIMGRID_HAVE_STATEFUL_MC + const auto* memory = get_remote_app().get_remote_process_memory(); + if (memory) { + XBT_INFO("Stack trace:"); + memory->dump_stack(); + } else +#endif + XBT_INFO("Stack trace not shown because there is no memory introspection."); } - get_remote_app().get_remote_process_memory().terminate(); - system_exit(SIMGRID_MC_EXIT_PROGRAM_CRASH); + throw McError(ExitStatus::PROGRAM_CRASH); } - -void Exploration::system_exit(int status) +XBT_ATTRIB_NORETURN void Exploration::report_assertion_failure() { - get_remote_app().shutdown(); - ::exit(status); + XBT_INFO("**************************"); + XBT_INFO("*** PROPERTY NOT VALID ***"); + XBT_INFO("**************************"); + XBT_INFO("Counter-example execution trace:"); + for (auto const& s : get_textual_trace()) + XBT_INFO(" %s", s.c_str()); + XBT_INFO("You can debug the problem (and see the whole details) by rerunning out of simgrid-mc with " + "--cfg=model-check/replay:'%s'", + get_record_trace().to_string().c_str()); + log_state(); + throw McError(ExitStatus::SAFETY); } }; // namespace simgrid::mc