basic-link-test basic-parsing-test evaluate-get-route-time evaluate-parse-time is-router
storage_client_server listen_async pid
trace-integration
- vm-live-migration)
+ vm-live-migration vm-suicide)
add_executable (${x} EXCLUDE_FROM_ALL ${x}/${x}.cpp)
target_link_libraries(${x} simgrid)
set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
foreach(x actor actor-autorestart actor-suspend
activity-lifecycle comm-get-sender wait-any-for
cloud-interrupt-migration cloud-two-execs concurrent_rw
- vm-live-migration)
+ vm-live-migration vm-suicide)
set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh)
ADD_TESH_FACTORIES(tesh-s4u-${x} "*" --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()
--- /dev/null
+/* Copyright (c) 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. */
+
+#include "simgrid/s4u.hpp"
+#include "simgrid/s4u/VirtualMachine.hpp"
+
+#include <limits>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(example, "Messages specific to this example");
+
+/* Test for issue https://github.com/simgrid/simgrid/issues/322: Issue when an actor kills his host vm
+ *
+ * A VM is created, and destroyed either from the outside or from the inside.
+ *
+ * The latter case initially failed because:
+ * - a call to "vm->destroy()" implicitly does a "vm->shutdown()" first;
+ * - when an actor wanted to destroy its own VM, it was killed by the shutdown phase,
+ * and could not finish the destruction.
+ */
+
+/* Output infos about physical hosts first: name, load, actors present in them
+ * and then output infos about vm hosts: name, physical host, load, state, actors present in them
+ */
+static void print_status(const std::vector<simgrid::s4u::Host*>& hosts)
+{
+ XBT_INFO("---- HOSTS and VMS STATUS ----");
+ XBT_INFO("--- HOSTS ---");
+ for (auto const& host : hosts) {
+ XBT_INFO("+ Name:%s Load:%f", host->get_cname(), host->get_load());
+ for (auto const& actor : host->get_all_actors())
+ XBT_INFO("++ actor: %s", actor->get_cname());
+ }
+ XBT_INFO("--- VMS ---");
+ for (auto const& host : simgrid::s4u::Engine::get_instance()->get_all_hosts()) {
+ if (auto vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host)) {
+ XBT_INFO("+ Name:%s Host:%s Load:%f State: %s", vm->get_cname(), vm->get_pm()->get_cname(), vm->get_load(),
+ simgrid::s4u::VirtualMachine::to_c_str(vm->get_state()));
+ for (auto const& actor : host->get_all_actors())
+ XBT_INFO("++ actor: %s", actor->get_cname());
+ }
+ }
+ XBT_INFO("------------------------------");
+}
+
+/* actor launching an infinite task on all the cores of its vm
+ */
+static void life_cycle_manager()
+{
+ simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(simgrid::s4u::this_actor::get_host());
+
+ for (int i = 0; i < vm->get_core_count(); i++)
+ simgrid::s4u::this_actor::exec_async(std::numeric_limits<double>::max());
+
+ simgrid::s4u::this_actor::sleep_for(50);
+ XBT_INFO("I'm done sleeping, time to kill myself");
+ vm->destroy();
+}
+
+/* master actor (placed on hosts[0])
+ *
+ * create a vm on hoss[1] and hosts[2]
+ * launch an actor creating an infinite task (exec_async) inside this vm
+ *
+ * task is either killed by this master or by the actor himself
+ */
+static void master(const std::vector<simgrid::s4u::Host*>& hosts)
+{
+ for (int i = 1; i <= 2; i++) {
+ simgrid::s4u::VirtualMachine* vm = new simgrid::s4u::VirtualMachine("test_vm", hosts.at(i), 4);
+ vm->start();
+ simgrid::s4u::Actor::create("life_cycle_manager-" + std::to_string(i), vm, life_cycle_manager);
+
+ simgrid::s4u::this_actor::sleep_for(10);
+ print_status(hosts);
+
+ simgrid::s4u::this_actor::sleep_for(30);
+ if (i == 1) {
+ XBT_INFO("Time to kill VM from master");
+ vm->destroy();
+ }
+
+ simgrid::s4u::this_actor::sleep_for(20);
+ print_status(hosts);
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine e(&argc, argv);
+
+ xbt_assert(argc == 2, "Usage: %s platform.xml\n", argv[0]);
+
+ e.load_platform(argv[1]);
+ std::vector<simgrid::s4u::Host*> hosts = e.get_all_hosts();
+ xbt_assert(hosts.size() > 3);
+ hosts.resize(3);
+ simgrid::s4u::Actor::create("test_master", hosts[0], master, hosts);
+
+ e.run();
+ return 0;
+}
--- /dev/null
+#!/usr/bin/env tesh
+
+p Testing the VM suicide
+
+$ ${bindir:=.}/vm-suicide ${platfdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
+> [ 10.000000] (1:test_master@Boivin) ---- HOSTS and VMS STATUS ----
+> [ 10.000000] (1:test_master@Boivin) --- HOSTS ---
+> [ 10.000000] (1:test_master@Boivin) + Name:Boivin Load:0.000000
+> [ 10.000000] (1:test_master@Boivin) ++ actor: test_master
+> [ 10.000000] (1:test_master@Boivin) + Name:Bourassa Load:48492000.000000
+> [ 10.000000] (1:test_master@Boivin) + Name:Fafard Load:0.000000
+> [ 10.000000] (1:test_master@Boivin) --- VMS ---
+> [ 10.000000] (1:test_master@Boivin) + Name:test_vm Host:Bourassa Load:48492000.000000 State: RUNNING
+> [ 10.000000] (1:test_master@Boivin) ++ actor: life_cycle_manager-1
+> [ 10.000000] (1:test_master@Boivin) ------------------------------
+> [ 40.000000] (1:test_master@Boivin) Time to kill VM from master
+> [ 60.000000] (1:test_master@Boivin) ---- HOSTS and VMS STATUS ----
+> [ 60.000000] (1:test_master@Boivin) --- HOSTS ---
+> [ 60.000000] (1:test_master@Boivin) + Name:Boivin Load:0.000000
+> [ 60.000000] (1:test_master@Boivin) ++ actor: test_master
+> [ 60.000000] (1:test_master@Boivin) + Name:Bourassa Load:0.000000
+> [ 60.000000] (1:test_master@Boivin) + Name:Fafard Load:0.000000
+> [ 60.000000] (1:test_master@Boivin) --- VMS ---
+> [ 60.000000] (1:test_master@Boivin) ------------------------------
+> [ 70.000000] (1:test_master@Boivin) ---- HOSTS and VMS STATUS ----
+> [ 70.000000] (1:test_master@Boivin) --- HOSTS ---
+> [ 70.000000] (1:test_master@Boivin) + Name:Boivin Load:0.000000
+> [ 70.000000] (1:test_master@Boivin) ++ actor: test_master
+> [ 70.000000] (1:test_master@Boivin) + Name:Bourassa Load:0.000000
+> [ 70.000000] (1:test_master@Boivin) + Name:Fafard Load:76296000.000000
+> [ 70.000000] (1:test_master@Boivin) --- VMS ---
+> [ 70.000000] (1:test_master@Boivin) + Name:test_vm Host:Fafard Load:76296000.000000 State: RUNNING
+> [ 70.000000] (1:test_master@Boivin) ++ actor: life_cycle_manager-2
+> [ 70.000000] (1:test_master@Boivin) ------------------------------
+> [110.000000] (3:life_cycle_manager-2@test_vm) I'm done sleeping, time to kill myself
+> [120.000000] (1:test_master@Boivin) ---- HOSTS and VMS STATUS ----
+> [120.000000] (1:test_master@Boivin) --- HOSTS ---
+> [120.000000] (1:test_master@Boivin) + Name:Boivin Load:0.000000
+> [120.000000] (1:test_master@Boivin) ++ actor: test_master
+> [120.000000] (1:test_master@Boivin) + Name:Bourassa Load:0.000000
+> [120.000000] (1:test_master@Boivin) + Name:Fafard Load:0.000000
+> [120.000000] (1:test_master@Boivin) --- VMS ---
+> [120.000000] (1:test_master@Boivin) ------------------------------