Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: add an observer to sleep simcalls
[simgrid.git] / src / mc / remote / AppSide.cpp
index 450546c..a74b126 100644 (file)
@@ -152,7 +152,7 @@ void AppSide::handle_finalize(const s_mc_message_int_t* msg) const
   if (terminate_asap)
     ::_Exit(0);
 }
-void AppSide::handle_fork(const s_mc_message_int_t* msg)
+void AppSide::handle_fork(const s_mc_message_fork_t* msg)
 {
   int status;
   int pid;
@@ -174,11 +174,10 @@ void AppSide::handle_fork(const s_mc_message_int_t* msg)
 
     struct sockaddr_un addr = {};
     addr.sun_family         = AF_UNIX;
-    snprintf(addr.sun_path, 64, "/tmp/simgrid-mc-%" PRIu64, msg->value);
-    auto addr_size = offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path);
+    std::copy_n(begin(msg->socket_name), MC_SOCKET_NAME_LEN, addr.sun_path);
 
-    xbt_assert(connect(sock, (struct sockaddr*)&addr, addr_size) >= 0,
-               "Cannot connect to Checker on %s: %s.", addr.sun_path, strerror(errno));
+    xbt_assert(connect(sock, (struct sockaddr*)&addr, sizeof addr) >= 0, "Cannot connect to Checker on %c%s: %s.",
+               (addr.sun_path[0] ? addr.sun_path[0] : '@'), addr.sun_path + 1, strerror(errno));
 
     channel_.reset_socket(sock);
 
@@ -226,6 +225,9 @@ void AppSide::handle_actors_status() const
 
   std::vector<s_mc_message_actors_status_one_t> status;
   for (auto const& [aid, actor] : actor_list) {
+    xbt_assert(actor);
+    xbt_assert(actor->simcall_.observer_, "simcall %s in actor %s has no observer.", actor->simcall_.get_cname(),
+               actor->get_cname());
     s_mc_message_actors_status_one_t one = {};
     one.type                             = MessageType::ACTORS_STATUS_REPLY_TRANSITION;
     one.aid                              = aid;
@@ -247,7 +249,6 @@ void AppSide::handle_actors_status() const
   // Serialize each transition to describe what each actor is doing
   XBT_DEBUG("Deliver ACTOR_TRANSITION_PROBE payload");
   for (const auto& actor_status : status) {
-
     const auto& actor        = actor_list.at(actor_status.aid);
     const int max_considered = actor_status.max_considered;
 
@@ -269,6 +270,7 @@ void AppSide::handle_actors_status() const
       strncpy(probe.buffer.data(), str.c_str(), probe.buffer.size() - 1);
       probe.buffer.back() = '\0';
 
+      XBT_DEBUG("send ACTOR_TRANSITION_PROBE(%s) ~> '%s'", actor->get_cname(), str.c_str());
       xbt_assert(channel_.send(probe) == 0, "Could not send ACTOR_TRANSITION_PROBE payload: %s", strerror(errno));
     }
     // NOTE: We do NOT need to reset `times_considered` for each actor's
@@ -328,8 +330,8 @@ void AppSide::handle_messages()
         break;
 
       case MessageType::FORK:
-        assert_msg_size("FORK", s_mc_message_int_t);
-        handle_fork((s_mc_message_int_t*)message_buffer.data());
+        assert_msg_size("FORK", s_mc_message_fork_t);
+        handle_fork((s_mc_message_fork_t*)message_buffer.data());
         break;
 
       case MessageType::WAIT_CHILD:
@@ -364,6 +366,7 @@ void AppSide::main_loop()
   simgrid::mc::processes_time.resize(simgrid::kernel::actor::ActorImpl::get_maxpid());
   MC_ignore_heap(simgrid::mc::processes_time.data(),
                  simgrid::mc::processes_time.size() * sizeof(simgrid::mc::processes_time[0]));
+  kernel::activity::CommImpl::setup_mc();
 
   sthread_disable();
   coverage_checkpoint();
@@ -395,7 +398,24 @@ void AppSide::ignore_memory(void* addr, std::size_t size) const
   message.size = size;
   xbt_assert(channel_.send(message) == 0, "Could not send IGNORE_MEMORY message to model-checker: %s", strerror(errno));
 #else
-  xbt_die("Cannot really call ignore_heap() in non-SIMGRID_MC mode.");
+  xbt_die("Cannot really call ignore_memory() in non-SIMGRID_MC mode.");
+#endif
+}
+
+void AppSide::unignore_memory(void* addr, std::size_t size) const
+{
+  if (not MC_is_active() || not need_memory_info_)
+    return;
+
+#if SIMGRID_HAVE_STATEFUL_MC
+  s_mc_message_ignore_memory_t message = {};
+  message.type                         = MessageType::UNIGNORE_MEMORY;
+  message.addr                         = (std::uintptr_t)addr;
+  message.size                         = size;
+  xbt_assert(channel_.send(message) == 0, "Could not send UNIGNORE_MEMORY message to model-checker: %s",
+             strerror(errno));
+#else
+  xbt_die("Cannot really call unignore_memory() in non-SIMGRID_MC mode.");
 #endif
 }