From: Arnaud Giersch Date: Tue, 22 Jun 2021 09:48:41 +0000 (+0200) Subject: Add a test in teshsuite for Comm::wait_all_for. X-Git-Tag: v3.28~78 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5d536011dbb04c717e9cea64435c782312041ddb Add a test in teshsuite for Comm::wait_all_for. --- diff --git a/MANIFEST.in b/MANIFEST.in index 01ad5249c6..3245396995 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -767,6 +767,8 @@ include teshsuite/s4u/vm-live-migration/vm-live-migration.cpp include teshsuite/s4u/vm-live-migration/vm-live-migration.tesh include teshsuite/s4u/vm-suicide/vm-suicide.cpp include teshsuite/s4u/vm-suicide/vm-suicide.tesh +include teshsuite/s4u/wait-all-for/wait-all-for.cpp +include teshsuite/s4u/wait-all-for/wait-all-for.tesh include teshsuite/s4u/wait-any-for/wait-any-for.cpp include teshsuite/s4u/wait-any-for/wait-any-for.tesh include teshsuite/simdag/availability/availability.c diff --git a/teshsuite/s4u/CMakeLists.txt b/teshsuite/s4u/CMakeLists.txt index 43f0ca108d..2e248797bd 100644 --- a/teshsuite/s4u/CMakeLists.txt +++ b/teshsuite/s4u/CMakeLists.txt @@ -1,6 +1,6 @@ foreach(x actor actor-autorestart actor-suspend activity-lifecycle - comm-get-sender comm-pt2pt wait-any-for + comm-get-sender comm-pt2pt wait-all-for wait-any-for cloud-interrupt-migration cloud-two-execs concurrent_rw host-on-off host-on-off-actors host-on-off-recv @@ -27,7 +27,7 @@ set_property(TARGET activity-lifecycle APPEND PROPERTY INCLUDE_DIRECTORIES "${IN ## Add the tests. ## Some need to be run with all factories, some don't need tesh to run foreach(x actor actor-autorestart actor-suspend - activity-lifecycle comm-get-sender wait-any-for + activity-lifecycle comm-get-sender wait-all-for wait-any-for cloud-interrupt-migration cloud-two-execs concurrent_rw vm-live-migration vm-suicide) set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) diff --git a/teshsuite/s4u/wait-all-for/wait-all-for.cpp b/teshsuite/s4u/wait-all-for/wait-all-for.cpp new file mode 100644 index 0000000000..7c7453d52b --- /dev/null +++ b/teshsuite/s4u/wait-all-for/wait-all-for.cpp @@ -0,0 +1,53 @@ +/* Copyright (c) 2019-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 +#include +#include +#include + +XBT_LOG_NEW_DEFAULT_CATEGORY(meh, "meh"); + +static void worker() +{ + auto mbox = simgrid::s4u::Mailbox::by_name("meh"); + int input1 = 42; + int input2 = 51; + + XBT_INFO("Sending and receiving %d and %d asynchronously", input1, input2); + + auto put1 = mbox->put_async(&input1, 1000 * 1000 * 500); + auto put2 = mbox->put_async(&input2, 1000 * 1000 * 1000); + + int* out1; + auto get1 = mbox->get_async(&out1); + + int* out2; + auto get2 = mbox->get_async(&out2); + + XBT_INFO("All comms have started"); + std::vector comms = {put1, put2, get1, get2}; + + while (not comms.empty()) { + size_t index = simgrid::s4u::Comm::wait_all_for(&comms, 0.5); + if (index < comms.size()) + XBT_INFO("wait_all_for: Timeout reached"); + XBT_INFO("wait_all_for: %zu comms finished (#comms=%zu)", index, comms.size()); + comms.erase(comms.begin(), comms.begin() + index); + } + + XBT_INFO("All comms have finished"); + XBT_INFO("Got %d and %d", *out1, *out2); +} + +int main(int argc, char* argv[]) + +{ + simgrid::s4u::Engine e(&argc, argv); + e.load_platform(argv[1]); + simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Tremblay"), worker); + e.run(); + return 0; +} diff --git a/teshsuite/s4u/wait-all-for/wait-all-for.tesh b/teshsuite/s4u/wait-all-for/wait-all-for.tesh new file mode 100644 index 0000000000..c7b30a9f9a --- /dev/null +++ b/teshsuite/s4u/wait-all-for/wait-all-for.tesh @@ -0,0 +1,19 @@ +#!/usr/bin/env tesh + +p Testing the wait_all_for feature of S4U + +! output sort 19 +$ ${bindir:=.}/wait-all-for ${platfdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" +> [ 0.000000] (1:worker@Tremblay) Sending and receiving 42 and 51 asynchronously +> [ 0.000000] (1:worker@Tremblay) All comms have started +> [ 0.500000] (1:worker@Tremblay) wait_all_for: Timeout reached +> [ 0.500000] (1:worker@Tremblay) wait_all_for: 0 comms finished (#comms=4) +> [ 1.000000] (1:worker@Tremblay) wait_all_for: Timeout reached +> [ 1.000000] (1:worker@Tremblay) wait_all_for: 0 comms finished (#comms=4) +> [ 1.500000] (1:worker@Tremblay) wait_all_for: Timeout reached +> [ 1.500000] (1:worker@Tremblay) wait_all_for: 1 comms finished (#comms=4) +> [ 2.000000] (1:worker@Tremblay) wait_all_for: Timeout reached +> [ 2.000000] (1:worker@Tremblay) wait_all_for: 0 comms finished (#comms=3) +> [ 2.070331] (1:worker@Tremblay) wait_all_for: 3 comms finished (#comms=3) +> [ 2.070331] (1:worker@Tremblay) All comms have finished +> [ 2.070331] (1:worker@Tremblay) Got 42 and 51