From 488d889685d4d718e37bf579bae0c98e1890ad95 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 4 Aug 2022 23:43:57 +0200 Subject: [PATCH] only 3 more functions to go in mc::api --- src/mc/api.cpp | 45 --------------------------------- src/mc/api.hpp | 5 ---- src/mc/explo/simgrid_mc.cpp | 50 +++++++++++++++++++++++++++++++------ 3 files changed, 43 insertions(+), 57 deletions(-) diff --git a/src/mc/api.cpp b/src/mc/api.cpp index ec477c9841..70f4c57cfd 100644 --- a/src/mc/api.cpp +++ b/src/mc/api.cpp @@ -29,51 +29,6 @@ XBT_LOG_EXTERNAL_CATEGORY(mc_global); namespace simgrid::mc { -simgrid::mc::Exploration* Api::initialize(char** argv, const std::unordered_map& env, - simgrid::mc::ExplorationAlgorithm algo) -{ - remote_app_ = std::make_unique([argv, &env] { - int i = 1; - while (argv[i] != nullptr && argv[i][0] == '-') - i++; - - for (auto const& [key, val] : env) { - XBT_INFO("setenv '%s'='%s'", key.c_str(), val.c_str()); - setenv(key.c_str(), val.c_str(), 1); - } - xbt_assert(argv[i] != nullptr, - "Unable to find a binary to exec on the command line. Did you only pass config flags?"); - execvp(argv[i], argv + i); - xbt_die("The model-checked process failed to exec(%s): %s", argv[i], strerror(errno)); - }); - - simgrid::mc::Exploration* explo; - switch (algo) { - case ExplorationAlgorithm::CommDeterminism: - explo = simgrid::mc::create_communication_determinism_checker(*(remote_app_.get())); - break; - - case ExplorationAlgorithm::UDPOR: - explo = simgrid::mc::create_udpor_checker(*(remote_app_.get())); - break; - - case ExplorationAlgorithm::Safety: - explo = simgrid::mc::create_dfs_exploration(*(remote_app_.get())); - break; - - case ExplorationAlgorithm::Liveness: - explo = simgrid::mc::create_liveness_checker(*(remote_app_.get())); - break; - - default: - THROW_IMPOSSIBLE; - } - - mc_model_checker->set_exploration(explo); - return explo; -} - - std::size_t Api::get_remote_heap_bytes() const { RemoteProcess& process = mc_model_checker->get_remote_process(); diff --git a/src/mc/api.hpp b/src/mc/api.hpp index 14ad74a941..7c084d69cf 100644 --- a/src/mc/api.hpp +++ b/src/mc/api.hpp @@ -40,8 +40,6 @@ private: } }; - std::unique_ptr remote_app_; - public: // No copy: Api(Api const&) = delete; @@ -53,9 +51,6 @@ public: return api; } - simgrid::mc::Exploration* initialize(char** argv, const std::unordered_map& env, - simgrid::mc::ExplorationAlgorithm algo); - // REMOTE APIs std::size_t get_remote_heap_bytes() const; diff --git a/src/mc/explo/simgrid_mc.cpp b/src/mc/explo/simgrid_mc.cpp index bcbe09c93f..6f55f3d398 100644 --- a/src/mc/explo/simgrid_mc.cpp +++ b/src/mc/explo/simgrid_mc.cpp @@ -18,6 +18,8 @@ #include #include +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(mc); + static simgrid::config::Flag _sg_mc_setenv{ "model-check/setenv", "Extra environment variables to pass to the child process (ex: 'AZE=aze;QWE=qwe').", "", [](std::string_view value) { @@ -67,19 +69,53 @@ int main(int argc, char** argv) token.c_str()); environment[kv[0]] = kv[1]; } + auto remote_app = std::make_unique([argv_copy, &environment] { + int i = 1; + while (argv_copy[i] != nullptr && argv_copy[i][0] == '-') + i++; + + for (auto const& [key, val] : environment) { + XBT_INFO("setenv '%s'='%s'", key.c_str(), val.c_str()); + setenv(key.c_str(), val.c_str(), 1); + } + xbt_assert(argv_copy[i] != nullptr, + "Unable to find a binary to exec on the command line. Did you only pass config flags?"); + execvp(argv_copy[i], argv_copy.data() + i); + xbt_die("The model-checked process failed to exec(%s): %s", argv_copy[i], strerror(errno)); + }); + + simgrid::mc::Exploration* explo; + switch (algo) { + case simgrid::mc::ExplorationAlgorithm::CommDeterminism: + explo = simgrid::mc::create_communication_determinism_checker(*remote_app.get()); + break; + + case simgrid::mc::ExplorationAlgorithm::UDPOR: + explo = simgrid::mc::create_udpor_checker(*remote_app.get()); + break; - int res = SIMGRID_MC_EXIT_SUCCESS; - std::unique_ptr checker{ - simgrid::mc::Api::get().initialize(argv_copy.data(), environment, algo)}; + case simgrid::mc::ExplorationAlgorithm::Safety: + explo = simgrid::mc::create_dfs_exploration(*remote_app.get()); + break; + + case simgrid::mc::ExplorationAlgorithm::Liveness: + explo = simgrid::mc::create_liveness_checker(*remote_app.get()); + break; + + default: + THROW_IMPOSSIBLE; + } + mc_model_checker->set_exploration(explo); + std::unique_ptr checker{explo}; try { checker->run(); } catch (const simgrid::mc::DeadlockError&) { - res = SIMGRID_MC_EXIT_DEADLOCK; + return SIMGRID_MC_EXIT_DEADLOCK; } catch (const simgrid::mc::TerminationError&) { - res = SIMGRID_MC_EXIT_NON_TERMINATION; + return SIMGRID_MC_EXIT_NON_TERMINATION; } catch (const simgrid::mc::LivenessError&) { - res = SIMGRID_MC_EXIT_LIVENESS; + return SIMGRID_MC_EXIT_LIVENESS; } - return res; + return SIMGRID_MC_EXIT_SUCCESS; } -- 2.20.1