Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Start moving classes into the mc/api directory
[simgrid.git] / src / mc / ModelChecker.cpp
index f44ed02..a7f0a6d 100644 (file)
@@ -1,11 +1,12 @@
-/* Copyright (c) 2008-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2008-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/mc/ModelChecker.hpp"
 #include "src/mc/Session.hpp"
-#include "src/mc/Transition.hpp"
+#include "src/mc/api/Transition.hpp"
+#include "src/mc/api/TransitionComm.hpp"
 #include "src/mc/checker/Checker.hpp"
 #include "src/mc/mc_config.hpp"
 #include "src/mc/mc_exit.hpp"
@@ -15,6 +16,7 @@
 #include "xbt/system_error.hpp"
 
 #include <array>
+#include <csignal>
 #include <sys/ptrace.h>
 #include <sys/wait.h>
 
@@ -307,17 +309,32 @@ void ModelChecker::wait_for_requests()
     checker_side_.dispatch();
 }
 
-void ModelChecker::handle_simcall(Transition const& transition)
+Transition* ModelChecker::handle_simcall(Transition const& transition, bool new_transition)
 {
-  s_mc_message_simcall_handle_t m;
+  s_mc_message_simcall_execute_t m;
   memset(&m, 0, sizeof(m));
-  m.type  = MessageType::SIMCALL_HANDLE;
+  m.type              = MessageType::SIMCALL_EXECUTE;
   m.aid_              = transition.aid_;
   m.times_considered_ = transition.times_considered_;
   checker_side_.get_channel().send(m);
+
+  s_mc_message_simcall_execute_answer_t answer;
+  ssize_t s = checker_side_.get_channel().receive(answer);
+  xbt_assert(s != -1, "Could not receive message");
+  xbt_assert(s == sizeof(answer) && answer.type == MessageType::SIMCALL_EXECUTE_ANSWER,
+             "Received unexpected message %s (%i, size=%i) "
+             "expected MessageType::SIMCALL_EXECUTE_ANSWER (%i, size=%i)",
+             to_c_str(answer.type), (int)answer.type, (int)s, (int)MessageType::SIMCALL_EXECUTE_ANSWER,
+             (int)sizeof(answer));
+
   this->remote_process_->clear_cache();
   if (this->remote_process_->running())
-    checker_side_.dispatch();
+    checker_side_.dispatch(); // The app may send messages while processing the transition
+
+  if (new_transition)
+    return recv_transition(transition.aid_, transition.times_considered_, answer.simcall, answer.buffer);
+  else
+    return nullptr;
 }
 bool ModelChecker::simcall_is_visible(aid_t aid)
 {
@@ -344,13 +361,13 @@ bool ModelChecker::simcall_is_visible(aid_t aid)
   return answer.value;
 }
 
-std::string ModelChecker::simcall_to_string(MessageType type, aid_t aid, int times_considered)
+std::string ModelChecker::simcall_dot_label(aid_t aid, int times_considered)
 {
   xbt_assert(mc_model_checker != nullptr, "This should be called from the checker side");
 
   s_mc_message_simcall_to_string_t m;
   memset(&m, 0, sizeof(m));
-  m.type            = type;
+  m.type            = MessageType::SIMCALL_DOT_LABEL;
   m.aid             = aid;
   m.time_considered = times_considered;
   checker_side_.get_channel().send(m);
@@ -358,27 +375,14 @@ std::string ModelChecker::simcall_to_string(MessageType type, aid_t aid, int tim
   s_mc_message_simcall_to_string_answer_t answer;
   ssize_t s = checker_side_.get_channel().receive(answer);
   xbt_assert(s != -1, "Could not receive message");
-  xbt_assert(s == sizeof(answer) && answer.type == MessageType::SIMCALL_TO_STRING_ANSWER,
+  xbt_assert(s == sizeof(answer) && answer.type == MessageType::SIMCALL_DOT_LABEL_ANSWER,
              "Received unexpected message %s (%i, size=%i) "
              "expected MessageType::SIMCALL_TO_STRING_ANSWER (%i, size=%i)",
-             to_c_str(answer.type), (int)answer.type, (int)s, (int)MessageType::SIMCALL_TO_STRING_ANSWER,
+             to_c_str(answer.type), (int)answer.type, (int)s, (int)MessageType::SIMCALL_DOT_LABEL_ANSWER,
              (int)sizeof(answer));
 
-  return std::string(answer.value);
-}
-
-std::string ModelChecker::simcall_to_string(aid_t aid, int times_considered)
-{
-  std::string answer = simcall_to_string(MessageType::SIMCALL_TO_STRING, aid, times_considered);
-  XBT_DEBUG("to_string(%ld) is returning %s", aid, answer.c_str());
-  return answer;
-}
-
-std::string ModelChecker::simcall_dot_label(aid_t aid, int times_considered)
-{
-  std::string answer = simcall_to_string(MessageType::SIMCALL_DOT_LABEL, aid, times_considered);
-  XBT_DEBUG("dot_label(%ld) is returning %s", aid, answer.c_str());
-  return answer;
+  XBT_DEBUG("dot_label(%ld) is returning %s", aid, answer.value);
+  return answer.value;
 }
 
 void ModelChecker::finalize_app(bool terminate_asap)