Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make a global singleton of Exploration, to kill ModelChecker
[simgrid.git] / src / mc / api / RemoteApp.cpp
index 6d250ba..dd249a2 100644 (file)
@@ -125,11 +125,11 @@ RemoteApp::RemoteApp(const std::vector<char*>& args)
 
   xbt_assert(mc_model_checker == nullptr, "Did you manage to start the MC twice in this process?");
 
-  checker_side_  = std::make_unique<simgrid::mc::CheckerSide>(sockets[1]);
-  auto process   = std::make_unique<simgrid::mc::RemoteProcessMemory>(pid);
-  model_checker_ = std::make_unique<simgrid::mc::ModelChecker>(std::move(process));
-
+  auto memory      = std::make_unique<simgrid::mc::RemoteProcessMemory>(pid);
+  model_checker_   = std::make_unique<simgrid::mc::ModelChecker>(std::move(memory));
   mc_model_checker = model_checker_.get();
+  checker_side_    = std::make_unique<simgrid::mc::CheckerSide>(sockets[1], model_checker_.get());
+
   start();
 
   /* Take the initial snapshot */
@@ -149,37 +149,6 @@ RemoteApp::~RemoteApp()
 }
 void RemoteApp::start()
 {
-  checker_side_->start(
-      [](evutil_socket_t sig, short events, void* arg) {
-        auto checker = static_cast<simgrid::mc::CheckerSide*>(arg);
-        if (events == EV_READ) {
-          std::array<char, MC_MESSAGE_LENGTH> buffer;
-          ssize_t size = recv(checker->get_channel().get_socket(), buffer.data(), buffer.size(), MSG_DONTWAIT);
-          if (size == -1) {
-            XBT_ERROR("Channel::receive failure: %s", strerror(errno));
-            if (errno != EAGAIN)
-              throw simgrid::xbt::errno_error();
-          }
-
-          if (not mc_model_checker->handle_message(buffer.data(), size))
-            checker->break_loop();
-        } else {
-          xbt_die("Unexpected event");
-        }
-      },
-      [](evutil_socket_t sig, short events, void* arg) {
-        auto mc = static_cast<simgrid::mc::ModelChecker*>(arg);
-        if (events == EV_SIGNAL) {
-          if (sig == SIGCHLD)
-            mc->handle_waitpid();
-          else
-            xbt_die("Unexpected signal: %d", sig);
-        } else {
-          xbt_die("Unexpected event");
-        }
-      },
-      model_checker_.get());
-
   XBT_DEBUG("Waiting for the model-checked process");
   int status;
 
@@ -313,13 +282,14 @@ void RemoteApp::check_deadlock() const
              to_c_str(message.type), (int)message.type, (int)MessageType::DEADLOCK_CHECK_REPLY);
 
   if (message.value != 0) {
+    auto* explo = Exploration::get_instance();
     XBT_CINFO(mc_global, "Counter-example execution trace:");
-    for (auto const& frame : model_checker_->get_exploration()->get_textual_trace())
+    for (auto const& frame : explo->get_textual_trace())
       XBT_CINFO(mc_global, "  %s", frame.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'",
-             model_checker_->get_exploration()->get_record_trace().to_string().c_str());
-    model_checker_->get_exploration()->log_state();
+             explo->get_record_trace().to_string().c_str());
+    explo->log_state();
     throw DeadlockError();
   }
 }
@@ -332,7 +302,7 @@ void RemoteApp::wait_for_requests()
   get_remote_process_memory().clear_cache();
 
   if (this->get_remote_process_memory().running())
-    checker_side_->dispatch();
+    checker_side_->dispatch_events();
 }
 
 void RemoteApp::shutdown()
@@ -358,7 +328,7 @@ Transition* RemoteApp::handle_simcall(aid_t aid, int times_considered, bool new_
 
   get_remote_process_memory().clear_cache();
   if (this->get_remote_process_memory().running())
-    checker_side_->dispatch(); // The app may send messages while processing the transition
+    checker_side_->dispatch_events(); // The app may send messages while processing the transition
 
   s_mc_message_simcall_execute_answer_t answer;
   ssize_t s = checker_side_->get_channel().receive(answer);