From 9e4db85ebd951c8bbe13079d7543cd43227f9786 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 21 Feb 2020 13:29:46 +0100 Subject: [PATCH] convert host-on-off test to s4u --- MANIFEST.in | 4 +- teshsuite/msg/CMakeLists.txt | 4 +- teshsuite/msg/host_on_off/host_on_off.c | 113 --------------------- teshsuite/msg/host_on_off/host_on_off.tesh | 13 --- teshsuite/s4u/CMakeLists.txt | 6 +- teshsuite/s4u/host-on-off/host-on-off.cpp | 107 +++++++++++++++++++ teshsuite/s4u/host-on-off/host-on-off.tesh | 13 +++ 7 files changed, 128 insertions(+), 132 deletions(-) delete mode 100644 teshsuite/msg/host_on_off/host_on_off.c delete mode 100644 teshsuite/msg/host_on_off/host_on_off.tesh create mode 100644 teshsuite/s4u/host-on-off/host-on-off.cpp create mode 100644 teshsuite/s4u/host-on-off/host-on-off.tesh diff --git a/MANIFEST.in b/MANIFEST.in index 63b79b56a3..686526cda7 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -653,8 +653,6 @@ include teshsuite/msg/energy-ptask/energy-ptask.c include teshsuite/msg/energy-ptask/energy-ptask.tesh include teshsuite/msg/get_sender/get_sender.c include teshsuite/msg/get_sender/get_sender.tesh -include teshsuite/msg/host_on_off/host_on_off.c -include teshsuite/msg/host_on_off/host_on_off.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 @@ -718,6 +716,8 @@ include teshsuite/s4u/cloud-sharing/cloud-sharing.tesh include teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp include teshsuite/s4u/concurrent_rw/concurrent_rw.cpp include teshsuite/s4u/concurrent_rw/concurrent_rw.tesh +include teshsuite/s4u/host-on-off/host-on-off.cpp +include teshsuite/s4u/host-on-off/host-on-off.tesh include teshsuite/s4u/listen_async/listen_async.cpp include teshsuite/s4u/listen_async/listen_async.tesh include teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index 1e2215ec41..ec84203048 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -1,7 +1,7 @@ # C examples foreach(x async-wait cloud-two-tasks - get_sender host_on_off host_on_off_recv + get_sender host_on_off_recv 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 host_on_off_processes host_on_off_recv + host_on_off_processes host_on_off_recv get_sender task_destroy_cancel task_listen_from task_progress process-lifetime diff --git a/teshsuite/msg/host_on_off/host_on_off.c b/teshsuite/msg/host_on_off/host_on_off.c deleted file mode 100644 index 19097d1bd9..0000000000 --- a/teshsuite/msg/host_on_off/host_on_off.c +++ /dev/null @@ -1,113 +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" - -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); - -static int slave(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) -{ - msg_task_t task = NULL; - XBT_ATTRIB_UNUSED int res; - int id = -1; - const char * mailbox = "jupi"; - - while (1) { - res = MSG_task_receive(&(task), mailbox); - if (res == MSG_HOST_FAILURE) { - XBT_DEBUG("The host has been turned off, this was expected"); - return 1; - } - xbt_assert(res == MSG_OK, "MSG_task_get failed"); - - if (!strcmp(MSG_task_get_name(task), "finalize")) { - MSG_task_destroy(task); - break; - } - MSG_task_execute(task); - XBT_INFO("Task \"%s\" done", MSG_task_get_name(task)); - - MSG_task_destroy(task); - task = NULL; - id--; - } - XBT_INFO("I'm done. See you!"); - return 0; -} - -static int master(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) -{ - double task_comp_size = 5E7; - double task_comm_size = 1E6; - - const char * mailbox = "jupi"; - msg_host_t jupiter = MSG_host_by_name("Jupiter"); - - msg_task_t task = MSG_task_create("task on", task_comp_size, task_comm_size, NULL); - XBT_INFO("Sending \"%s\"", MSG_task_get_name(task)); - if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK) - MSG_task_destroy(task); - - MSG_process_sleep(1); - MSG_host_off(jupiter); - - task = MSG_task_create("task off", task_comp_size, task_comm_size, NULL); - XBT_INFO("Sending \"%s\"", MSG_task_get_name(task)); - if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK) - MSG_task_destroy(task); - - MSG_host_on(jupiter); - - xbt_dynar_t jupi_processes = xbt_dynar_new(sizeof(msg_process_t), NULL); - MSG_host_get_process_list(jupiter, jupi_processes); - msg_process_t process = NULL; - unsigned int cursor; - xbt_dynar_foreach (jupi_processes, cursor, process) { - MSG_process_kill(process); - } - xbt_dynar_free(&jupi_processes); - - task = MSG_task_create("task on without proc", task_comp_size, task_comm_size, NULL); - XBT_INFO("Sending \"%s\"", MSG_task_get_name(task)); - if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK) - MSG_task_destroy(task); - - char **argvF = xbt_new(char*, 2); - argvF[0] = xbt_strdup("slave"); - MSG_process_create_with_arguments("slave", slave, NULL, MSG_host_by_name("Jupiter"), 1, argvF); - - task = MSG_task_create("task on with proc", task_comp_size, task_comm_size, NULL); - XBT_INFO("Sending \"%s\"", MSG_task_get_name(task)); - if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK) - MSG_task_destroy(task); - - task = MSG_task_create("finalize", 0, 0, 0); - XBT_INFO("Sending \"%s\"", MSG_task_get_name(task)); - if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK) - MSG_task_destroy(task); - - XBT_INFO("Goodbye now!"); - return 0; -} - -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/host_on_off.tesh b/teshsuite/msg/host_on_off/host_on_off.tesh deleted file mode 100644 index 64210eec7f..0000000000 --- a/teshsuite/msg/host_on_off/host_on_off.tesh +++ /dev/null @@ -1,13 +0,0 @@ - -$ ${bindir}/host_on_off ${platfdir}/small_platform.xml -> [Tremblay:master:(1) 0.000000] [msg_test/INFO] Sending "task on" -> [Jupiter:slave:(2) 0.824497] [msg_test/INFO] Task "task on" done -> [Tremblay:master:(1) 1.169155] [msg_test/INFO] Sending "task off" -> [Tremblay:master:(1) 2.169155] [msg_test/INFO] Sending "task on without proc" -> [Tremblay:master:(1) 3.169155] [msg_test/INFO] Sending "task on with proc" -> [Tremblay:master:(1) 3.338309] [msg_test/INFO] Sending "finalize" -> [Jupiter:slave:(3) 3.993652] [msg_test/INFO] Task "task on with proc" done -> [Tremblay:master:(1) 4.012666] [msg_test/INFO] Goodbye now! -> [Jupiter:slave:(3) 4.012666] [msg_test/INFO] I'm done. See you! -> [4.012666] [msg_test/INFO] Simulation time 4.01267 - diff --git a/teshsuite/s4u/CMakeLists.txt b/teshsuite/s4u/CMakeLists.txt index 6162ecb4dc..d425b29384 100644 --- a/teshsuite/s4u/CMakeLists.txt +++ b/teshsuite/s4u/CMakeLists.txt @@ -2,7 +2,9 @@ foreach(x actor actor-autorestart activity-lifecycle comm-pt2pt wait-any-for cloud-interrupt-migration cloud-sharing - concurrent_rw storage_client_server listen_async pid ) + concurrent_rw + host-on-off + storage_client_server listen_async pid ) 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}) @@ -27,7 +29,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 listen_async pid storage_client_server cloud-sharing) +foreach(x host-on-off 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/host-on-off.cpp b/teshsuite/s4u/host-on-off/host-on-off.cpp new file mode 100644 index 0000000000..6566ce5b10 --- /dev/null +++ b/teshsuite/s4u/host-on-off/host-on-off.cpp @@ -0,0 +1,107 @@ +/* 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 s4u example"); + +static void worker() +{ + std::string* payload; + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("jupi"); + + while (1) { + try { + payload = static_cast(mailbox->get()); + } catch (simgrid::HostFailureException&) { + XBT_DEBUG("The host has been turned off, this was expected"); + return; + } + + if (*payload == "finalize") { + delete payload; + break; + } + simgrid::s4u::this_actor::execute(5E7); + + XBT_INFO("Task \"%s\" done", payload->c_str()); + delete payload; + } + XBT_INFO("I'm done. See you!"); +} + +static void master() +{ + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("jupi"); + simgrid::s4u::Host* jupiter = simgrid::s4u::Host::by_name("Jupiter"); + + std::string* payload = new std::string("task on"); + + XBT_INFO("Sending \"task on\""); + mailbox->put_async(payload, 1E6)->wait_for(1); + + simgrid::s4u::this_actor::sleep_for(1); + jupiter->turn_off(); + + XBT_INFO("Sending \"task off\""); + payload = new std::string("task off"); + try { + mailbox->put_async(payload, 1E6)->wait_for(1); + } catch (simgrid::TimeoutException&) { + delete payload; + } + + jupiter->turn_on(); + + std::vector jupi_actors = jupiter->get_all_actors(); + for (const auto& actor : jupi_actors) + actor->kill(); + + XBT_INFO("Sending \"task on without actor\""); + payload = new std::string("task on without actor"); + try { + mailbox->put_async(payload, 1E6)->wait_for(1); + } catch (simgrid::TimeoutException&) { + delete payload; + } + + simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Jupiter"), worker); + + XBT_INFO("Sending \"task on with actor\""); + payload = new std::string("task on with actor"); + try { + mailbox->put_async(payload, 1E6)->wait_for(1); + } catch (simgrid::TimeoutException&) { + delete payload; + } + + XBT_INFO("Sending \"finalize\""); + payload = new std::string("finalize"); + try { + mailbox->put_async(payload, 0)->wait_for(1); + } catch (simgrid::TimeoutException&) { + delete payload; + } + + XBT_INFO("Goodbye now!"); +} + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine e(&argc, argv); + xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_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/host-on-off.tesh b/teshsuite/s4u/host-on-off/host-on-off.tesh new file mode 100644 index 0000000000..7d5d9ce908 --- /dev/null +++ b/teshsuite/s4u/host-on-off/host-on-off.tesh @@ -0,0 +1,13 @@ + +$ ./host-on-off ${platfdir}/small_platform.xml +> [Tremblay:master:(1) 0.000000] [s4u_test/INFO] Sending "task on" +> [Jupiter:worker:(2) 0.824497] [s4u_test/INFO] Task "task on" done +> [Tremblay:master:(1) 1.169155] [s4u_test/INFO] Sending "task off" +> [Tremblay:master:(1) 2.169155] [s4u_test/INFO] Sending "task on without actor" +> [Tremblay:master:(1) 3.169155] [s4u_test/INFO] Sending "task on with actor" +> [Tremblay:master:(1) 3.338309] [s4u_test/INFO] Sending "finalize" +> [Jupiter:worker:(3) 3.993652] [s4u_test/INFO] Task "task on with actor" done +> [Tremblay:master:(1) 4.012666] [s4u_test/INFO] Goodbye now! +> [Jupiter:worker:(3) 4.012666] [s4u_test/INFO] I'm done. See you! +> [4.012666] [s4u_test/INFO] Simulation time 4.01267 + -- 2.20.1