Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make sure that the dtor of CheckerSide actually kills the application and waits for it
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 21 Mar 2023 20:48:55 +0000 (21:48 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 21 Mar 2023 20:48:55 +0000 (21:48 +0100)
src/mc/api/RemoteApp.cpp
src/mc/api/RemoteApp.hpp
src/mc/explo/Exploration.cpp
src/mc/remote/CheckerSide.cpp
src/mc/remote/CheckerSide.hpp

index 535da89..114c7e4 100644 (file)
@@ -43,13 +43,12 @@ RemoteApp::RemoteApp(const std::vector<char*>& args, bool need_memory_introspect
 RemoteApp::~RemoteApp()
 {
   initial_snapshot_ = nullptr;
-  shutdown();
+  checker_side_     = nullptr;
 }
 
 void RemoteApp::restore_initial_state()
 {
   if (initial_snapshot_ == nullptr) { // No memory introspection
-    shutdown();
     // We need to destroy the existing CheckerSide before creating the new one, or libevent gets crazy
     checker_side_.reset(nullptr);
     checker_side_.reset(new simgrid::mc::CheckerSide(app_args_, true));
@@ -178,18 +177,6 @@ void RemoteApp::wait_for_requests()
   checker_side_->wait_for_requests();
 }
 
-void RemoteApp::shutdown()
-{
-  XBT_DEBUG("Shutting down model-checker");
-
-  if (checker_side_->running()) {
-    XBT_DEBUG("Killing process");
-    finalize_app(true);
-    kill(checker_side_->get_pid(), SIGKILL);
-    checker_side_->terminate();
-  }
-}
-
 Transition* RemoteApp::handle_simcall(aid_t aid, int times_considered, bool new_transition)
 {
   s_mc_message_simcall_execute_t m = {};
@@ -221,18 +208,7 @@ Transition* RemoteApp::handle_simcall(aid_t aid, int times_considered, bool new_
 
 void RemoteApp::finalize_app(bool terminate_asap)
 {
-  s_mc_message_int_t m = {};
-  m.type               = MessageType::FINALIZE;
-  m.value              = terminate_asap;
-  xbt_assert(checker_side_->get_channel().send(m) == 0, "Could not ask the app to finalize on need");
-
-  s_mc_message_t answer;
-  ssize_t s = checker_side_->get_channel().receive(answer);
-  xbt_assert(s != -1, "Could not receive answer to FINALIZE");
-  xbt_assert(s == sizeof answer, "Broken message (size=%zd; expected %zu)", s, sizeof answer);
-  xbt_assert(answer.type == MessageType::FINALIZE_REPLY,
-             "Received unexpected message %s (%i); expected MessageType::FINALIZE_REPLY (%i)", to_c_str(answer.type),
-             (int)answer.type, (int)MessageType::FINALIZE_REPLY);
+  checker_side_->finalize(terminate_asap);
 }
 
 } // namespace simgrid::mc
index 6f4b700..0c9c00d 100644 (file)
@@ -56,8 +56,6 @@ public:
 
   /** Ask the application to run post-mortem analysis, and maybe to stop ASAP */
   void finalize_app(bool terminate_asap = false);
-  /** Forcefully kill the application (after running post-mortem analysis)*/
-  void shutdown();
 
   /** Retrieve the max PID of the running actors */
   unsigned long get_maxpid() const;
index bafc79d..6be979e 100644 (file)
@@ -116,7 +116,6 @@ void Exploration::report_assertion_failure()
 
 void Exploration::system_exit(int status)
 {
-  get_remote_app().shutdown();
   ::exit(status);
 }
 
index a6ce4dc..b680284 100644 (file)
@@ -217,6 +217,30 @@ CheckerSide::~CheckerSide()
   event_free(socket_event_);
   event_del(signal_event_);
   event_free(signal_event_);
+
+  if (running()) {
+    XBT_DEBUG("Killing process");
+    finalize(true);
+    kill(get_pid(), SIGKILL);
+    terminate();
+    handle_waitpid();
+  }
+}
+
+void CheckerSide::finalize(bool terminate_asap)
+{
+  s_mc_message_int_t m = {};
+  m.type               = MessageType::FINALIZE;
+  m.value              = terminate_asap;
+  xbt_assert(get_channel().send(m) == 0, "Could not ask the app to finalize on need");
+
+  s_mc_message_t answer;
+  ssize_t s = get_channel().receive(answer);
+  xbt_assert(s != -1, "Could not receive answer to FINALIZE");
+  xbt_assert(s == sizeof answer, "Broken message (size=%zd; expected %zu)", s, sizeof answer);
+  xbt_assert(answer.type == MessageType::FINALIZE_REPLY,
+             "Received unexpected message %s (%i); expected MessageType::FINALIZE_REPLY (%i)", to_c_str(answer.type),
+             (int)answer.type, (int)MessageType::FINALIZE_REPLY);
 }
 
 void CheckerSide::dispatch_events() const
index 3608441..17fb33c 100644 (file)
@@ -49,6 +49,9 @@ public:
   void break_loop() const;
   void wait_for_requests();
 
+  /** Ask the application to run post-mortem analysis, and maybe to stop ASAP */
+  void finalize(bool terminate_asap = false);
+
   /* Interacting with the application process */
   pid_t get_pid() const { return pid_; }
   bool running() const { return running_; }