Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way VMs are created.
[simgrid.git] / teshsuite / s4u / host-on-off-actors / host-on-off-actors.cpp
index 246ceec..8e0fa5a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2021. 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. */
@@ -10,7 +10,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example")
 
 int tasks_done = 0;
 
-static void actor_daemon()
+XBT_ATTRIB_NORETURN static void actor_daemon()
 {
   const simgrid::s4u::Host* host = simgrid::s4u::Host::current();
   XBT_INFO("  Start daemon on %s (%f)", host->get_cname(), host->get_speed());
@@ -19,13 +19,13 @@ static void actor_daemon()
     simgrid::s4u::this_actor::execute(host->get_speed());
     tasks_done++;
   }
-  XBT_INFO("  daemon done. See you!");
+  xbt_die("  daemon done. See you!");
 }
 
 static void commTX()
 {
   XBT_INFO("  Start TX");
-  std::string* payload = new std::string("COMM");
+  auto* payload = new std::string("COMM");
   simgrid::s4u::Mailbox::by_name("comm")->put_init(payload, 100000000)->detach();
   // We should wait a bit (if not the process will end before the communication, hence an exception on the other side).
   try {
@@ -40,10 +40,9 @@ static void commTX()
 
 static void commRX()
 {
-  const std::string* payload = nullptr;
   XBT_INFO("  Start RX");
   try {
-    payload = static_cast<std::string*>(simgrid::s4u::Mailbox::by_name("comm")->get());
+    auto payload = simgrid::s4u::Mailbox::by_name("comm")->get_unique<std::string>();
     XBT_INFO("  Receive message: %s", payload->c_str());
   } catch (const simgrid::HostFailureException&) {
     XBT_INFO("  Receive message: HOST_FAILURE");
@@ -51,7 +50,6 @@ static void commRX()
     XBT_INFO("  Receive message: TRANSFER_FAILURE");
   }
 
-  delete payload;
   XBT_INFO("  RX Done");
 }
 
@@ -126,7 +124,7 @@ static void test_launcher(int test_number)
       XBT_INFO("Test 6: Turn on Jupiter, assign a VM on Jupiter, launch an actor inside the VM, and turn off the node");
 
       // Create VM0
-      vm0 = new simgrid::s4u::VirtualMachine("vm0", jupiter, 1);
+      vm0 = jupiter->create_vm("vm0", 1);
       vm0->start();
 
       daemon = simgrid::s4u::Actor::create("actor_daemon", vm0, actor_daemon);
@@ -157,16 +155,15 @@ static void test_launcher(int test_number)
 int main(int argc, char* argv[])
 {
   simgrid::s4u::Engine e(&argc, argv);
-  xbt_assert(argc == 3, "Usage: %s platform_file test_number\n\tExample: %s msg_platform.xml 1\n", argv[0], argv[0]);
+  xbt_assert(argc == 3, "Usage: %s platform_file test_number\n\tExample: %s platform.xml 1\n", argv[0], argv[0]);
 
   e.load_platform(argv[1]);
 
-  simgrid::s4u::Actor::create("test_launcher", simgrid::s4u::Host::by_name("Tremblay"), test_launcher,
-                              std::stoi(argv[2]));
+  simgrid::s4u::Actor::create("test_launcher", e.host_by_name("Tremblay"), test_launcher, std::stoi(argv[2]));
 
   e.run();
 
-  XBT_INFO("Simulation time %g", e.get_clock());
+  XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
 
   return 0;
 }