Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert host-on-off-recv
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 23 Feb 2020 14:36:53 +0000 (15:36 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 23 Feb 2020 19:12:44 +0000 (20:12 +0100)
MANIFEST.in
teshsuite/msg/CMakeLists.txt
teshsuite/msg/host_on_off_recv/host_on_off_recv.c [deleted file]
teshsuite/msg/host_on_off_recv/host_on_off_recv.tesh [deleted file]
teshsuite/s4u/CMakeLists.txt
teshsuite/s4u/host-on-off-recv/host-on-off-recv.cpp [new file with mode: 0644]
teshsuite/s4u/host-on-off-recv/host-on-off-recv.tesh [new file with mode: 0644]

index f7df6c9..370bba2 100644 (file)
@@ -655,8 +655,6 @@ include teshsuite/msg/get_sender/get_sender.c
 include teshsuite/msg/get_sender/get_sender.tesh
 include teshsuite/msg/host_on_off_processes/host_on_off_processes.cpp
 include teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh
-include teshsuite/msg/host_on_off_recv/host_on_off_recv.c
-include teshsuite/msg/host_on_off_recv/host_on_off_recv.tesh
 include teshsuite/msg/io-file/io-file.c
 include teshsuite/msg/io-file/io-file.tesh
 include teshsuite/msg/platform-properties/platform-properties.c
@@ -720,6 +718,8 @@ include teshsuite/s4u/concurrent_rw/concurrent_rw.cpp
 include teshsuite/s4u/concurrent_rw/concurrent_rw.tesh
 include teshsuite/s4u/evaluate-get-route-time/evaluate-get-route-time.cpp
 include teshsuite/s4u/evaluate-parse-time/evaluate-parse-time.cpp
+include teshsuite/s4u/host-on-off-recv/host-on-off-recv.cpp
+include teshsuite/s4u/host-on-off-recv/host-on-off-recv.tesh
 include teshsuite/s4u/host-on-off/host-on-off.cpp
 include teshsuite/s4u/host-on-off/host-on-off.tesh
 include teshsuite/s4u/is-router/is-router.cpp
index ec84203..5b73034 100644 (file)
@@ -1,7 +1,7 @@
 # C examples
 foreach(x async-wait
           cloud-two-tasks
-          get_sender host_on_off_recv
+          get_sender
           process-lifetime
           energy-ptask platform-properties
           io-file
@@ -74,7 +74,7 @@ if(enable_msg)
     async-wait
     app-bittorrent
     cloud-two-tasks
-    host_on_off_processes host_on_off_recv
+    host_on_off_processes
     get_sender
     task_destroy_cancel task_listen_from task_progress 
     process-lifetime
diff --git a/teshsuite/msg/host_on_off_recv/host_on_off_recv.c b/teshsuite/msg/host_on_off_recv/host_on_off_recv.c
deleted file mode 100644 (file)
index 73abb69..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/* Copyright (c) 2010-2020. 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 "simgrid/msg.h"            /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-
-static const char* mailbox = "comm";
-
-static int master(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
-{
-  msg_host_t jupiter = MSG_host_by_name("Jupiter");
-
-  XBT_INFO("Master starting");
-  MSG_process_sleep(0.5);
-
-  msg_task_t task = MSG_task_create("COMM", 0, 100000000, NULL);
-  msg_comm_t comm = MSG_task_isend(task, mailbox);
-
-  MSG_process_sleep(0.5);
-
-  XBT_INFO("Turning off the slave host");
-  MSG_host_off(jupiter);
-
-  if (comm) {
-    MSG_task_destroy(task);
-    MSG_comm_wait(comm, -1);
-    MSG_comm_destroy(comm);
-  }
-  XBT_INFO("Master has finished");
-
-  return 0;
-}
-
-static int slave(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
-{
-  XBT_INFO("Slave receiving");
-  msg_task_t task = NULL;
-  msg_error_t error = MSG_task_receive(&(task), mailbox);
-  if (error) {
-    if (error != MSG_HOST_FAILURE)
-      XBT_ERROR("Error while receiving message");
-    else
-      XBT_DEBUG("The host has been turned off, this was expected");
-    return 1;
-  }
-
-  XBT_ERROR("Slave should be off already.");
-  return 1;
-}
-
-int main(int argc, char *argv[])
-{
-  msg_error_t res;
-
-  MSG_init(&argc, argv);
-  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
-
-  MSG_create_environment(argv[1]);
-
-  MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
-  MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("Jupiter"));
-
-  res = MSG_main();
-
-  XBT_INFO("Simulation time %g", MSG_get_clock());
-
-  return res != MSG_OK;
-}
diff --git a/teshsuite/msg/host_on_off_recv/host_on_off_recv.tesh b/teshsuite/msg/host_on_off_recv/host_on_off_recv.tesh
deleted file mode 100644 (file)
index d4baec9..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-$ ${bindir}/host_on_off_recv ${platfdir}/small_platform.xml
-> [Tremblay:master:(1) 0.000000] [msg_test/INFO] Master starting
-> [Jupiter:slave:(2) 0.000000] [msg_test/INFO] Slave receiving
-> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Turning off the slave host
-> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Master has finished
-> [1.000000] [msg_test/INFO] Simulation time 1
index a640cbe..c8d623a 100644 (file)
@@ -3,7 +3,7 @@ foreach(x actor actor-autorestart
         comm-pt2pt wait-any-for
         cloud-interrupt-migration cloud-sharing
         concurrent_rw 
-        host-on-off
+        host-on-off host-on-off-recv
         basic-link-test evaluate-get-route-time evaluate-parse-time is-router
         storage_client_server listen_async pid )
   add_executable       (${x}  EXCLUDE_FROM_ALL ${x}/${x}.cpp)
@@ -30,7 +30,7 @@ foreach(x actor actor-autorestart
   ADD_TESH_FACTORIES(tesh-s4u-${x} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh)
 endforeach()
 
-foreach(x basic-link-test host-on-off is-router listen_async pid storage_client_server cloud-sharing)
+foreach(x basic-link-test host-on-off host-on-off-recv is-router listen_async pid storage_client_server cloud-sharing)
   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh)
   ADD_TESH(tesh-s4u-${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh)
 endforeach()
diff --git a/teshsuite/s4u/host-on-off-recv/host-on-off-recv.cpp b/teshsuite/s4u/host-on-off-recv/host-on-off-recv.cpp
new file mode 100644 (file)
index 0000000..3dc299e
--- /dev/null
@@ -0,0 +1,69 @@
+/* Copyright (c) 2010-2020. 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 "simgrid/s4u.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this example");
+
+static void master()
+{
+  simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("comm");
+  simgrid::s4u::Host* jupiter    = simgrid::s4u::Host::by_name("Jupiter");
+
+  XBT_INFO("Master starting");
+  simgrid::s4u::this_actor::sleep_for(0.5);
+
+  std::string* payload       = new std::string("COMM");
+  simgrid::s4u::CommPtr comm = mailbox->put_async(payload, 1E8);
+
+  simgrid::s4u::this_actor::sleep_for(0.5);
+
+  XBT_INFO("Turning off the worker host");
+  jupiter->turn_off();
+
+  try {
+    comm->wait();
+  } catch (const simgrid::NetworkFailureException&) {
+    delete payload;
+  }
+
+  XBT_INFO("Master has finished");
+}
+
+static void worker()
+{
+  const std::string* payload     = nullptr;
+  simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("comm");
+
+  XBT_INFO("Worker receiving");
+  try {
+    payload = static_cast<std::string*>(mailbox->get());
+  } catch (const simgrid::HostFailureException&) {
+    XBT_DEBUG("The host has been turned off, this was expected");
+    delete payload;
+    return;
+  }
+
+  XBT_ERROR("Worker should be off already.");
+}
+
+int main(int argc, char* argv[])
+{
+
+  simgrid::s4u::Engine e(&argc, argv);
+  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s small_platform.xml\n", argv[0], argv[0]);
+
+  e.load_platform(argv[1]);
+
+  simgrid::s4u::Actor::create("master", simgrid::s4u::Host::by_name("Tremblay"), master);
+  simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Jupiter"), worker);
+
+  e.run();
+
+  XBT_INFO("Simulation time %g", e.get_clock());
+
+  return 0;
+}
diff --git a/teshsuite/s4u/host-on-off-recv/host-on-off-recv.tesh b/teshsuite/s4u/host-on-off-recv/host-on-off-recv.tesh
new file mode 100644 (file)
index 0000000..516608f
--- /dev/null
@@ -0,0 +1,6 @@
+$ ./host-on-off-recv ${platfdir}/small_platform.xml
+> [Tremblay:master:(1) 0.000000] [s4u_test/INFO] Master starting
+> [Jupiter:worker:(2) 0.000000] [s4u_test/INFO] Worker receiving
+> [Tremblay:master:(1) 1.000000] [s4u_test/INFO] Turning off the worker host
+> [Tremblay:master:(1) 1.000000] [s4u_test/INFO] Master has finished
+> [1.000000] [s4u_test/INFO] Simulation time 1