Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
only 3 more functions to go in mc::api
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 4 Aug 2022 21:43:57 +0000 (23:43 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 4 Aug 2022 21:49:53 +0000 (23:49 +0200)
src/mc/api.cpp
src/mc/api.hpp
src/mc/explo/simgrid_mc.cpp

index ec477c9..70f4c57 100644 (file)
@@ -29,51 +29,6 @@ XBT_LOG_EXTERNAL_CATEGORY(mc_global);
 
 namespace simgrid::mc {
 
-simgrid::mc::Exploration* Api::initialize(char** argv, const std::unordered_map<std::string, std::string>& env,
-                                          simgrid::mc::ExplorationAlgorithm algo)
-{
-  remote_app_ = std::make_unique<simgrid::mc::RemoteApp>([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();
index 14ad74a..7c084d6 100644 (file)
@@ -40,8 +40,6 @@ private:
     }
   };
 
-  std::unique_ptr<simgrid::mc::RemoteApp> 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<std::string, std::string>& env,
-                                       simgrid::mc::ExplorationAlgorithm algo);
-
   // REMOTE APIs
   std::size_t get_remote_heap_bytes() const;
 
index bcbe09c..6f55f3d 100644 (file)
@@ -18,6 +18,8 @@
 #include <memory>
 #include <unistd.h>
 
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(mc);
+
 static simgrid::config::Flag<std::string> _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<simgrid::mc::RemoteApp>([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<simgrid::mc::Exploration> 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<simgrid::mc::Exploration> 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;
 }