1 /* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "activity-lifecycle.hpp"
8 // Normally, we should be able use Catch2's REQUIRE_THROWS_AS(...), but it generates errors with Address Sanitizer.
9 // They're certainly false positive. Nevermind and use this simpler replacement.
10 #define REQUIRE_NETWORK_FAILURE(...) \
14 FAIL("Expected exception NetworkFailureException not caught"); \
15 } catch (simgrid::NetworkFailureException const&) { \
16 XBT_VERB("got expected NetworkFailureException"); \
20 TEST_CASE("Activity lifecycle: direct communication activities")
22 XBT_INFO("#####[ launch next \"direct-comm\" test ]#####");
24 BEGIN_SECTION("dcomm")
26 XBT_INFO("Launch a dcomm(5s), and let it proceed");
29 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5", all_hosts[1], [&global]() {
30 assert_exit(true, 5.);
31 all_hosts[1]->sendto(all_hosts[2], 5000);
35 simgrid::s4u::this_actor::sleep_for(9);
36 INFO("Did the forked actor modify the global after sleeping, or was it killed before?");
42 BEGIN_SECTION("dcomm actor killed at start")
44 XBT_INFO("Launch a dcomm(5s), and kill it right after start");
45 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_killed", all_hosts[1], []() {
46 assert_exit(false, 0);
47 all_hosts[1]->sendto(all_hosts[2], 5000);
48 FAIL("I should be dead now");
51 simgrid::s4u::this_actor::yield();
57 BEGIN_SECTION("dcomm actor killed in middle")
59 XBT_INFO("Launch a dcomm(5s), and kill it after 2 secs");
60 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_killed", all_hosts[1], []() {
61 assert_exit(false, 2);
62 all_hosts[1]->sendto(all_hosts[2], 5000);
63 FAIL("I should be dead now");
66 simgrid::s4u::this_actor::sleep_for(2);
72 BEGIN_SECTION("dcomm host restarted at start")
74 XBT_INFO("Launch a dcomm(5s), and restart its host right after start");
75 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], []() {
76 assert_exit(false, 0);
77 all_hosts[1]->sendto(all_hosts[2], 5000);
78 FAIL("I should be dead now");
81 simgrid::s4u::this_actor::yield();
82 dcomm5->get_host()->turn_off();
83 dcomm5->get_host()->turn_on();
88 BEGIN_SECTION("dcomm host restarted in middle")
90 XBT_INFO("Launch a dcomm(5s), and restart its host after 2 secs");
91 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], []() {
92 assert_exit(false, 2);
93 all_hosts[1]->sendto(all_hosts[2], 5000);
94 FAIL("I should be dead now");
97 simgrid::s4u::this_actor::sleep_for(2);
98 dcomm5->get_host()->turn_off();
99 dcomm5->get_host()->turn_on();
104 BEGIN_SECTION("dcomm host restarted at end")
106 XBT_INFO("Launch a dcomm(5s), and restart its host right when it stops");
107 bool execution_done = false;
109 simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], [&execution_done]() {
110 assert_exit(true, 5);
111 all_hosts[1]->sendto(all_hosts[2], 5000);
112 execution_done = true;
115 simgrid::s4u::Actor::create("killer", all_hosts[0], []() {
116 simgrid::s4u::this_actor::sleep_for(5);
118 all_hosts[1]->turn_off();
119 all_hosts[1]->turn_on();
122 simgrid::s4u::this_actor::sleep_for(9);
123 INFO("Was restarted actor already dead in the scheduling round during which the host_off simcall was issued?");
124 REQUIRE(execution_done);
129 BEGIN_SECTION("dcomm link restarted at start")
131 XBT_INFO("Launch a dcomm(5s), and restart the used link right after start");
132 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], []() {
133 assert_exit(true, 0);
134 REQUIRE_NETWORK_FAILURE(all_hosts[1]->sendto(all_hosts[2], 5000));
137 simgrid::s4u::this_actor::yield();
138 auto link = simgrid::s4u::Engine::get_instance()->link_by_name("link1");
145 BEGIN_SECTION("dcomm link restarted in middle")
147 XBT_INFO("Launch a dcomm(5s), and restart the used link after 2 secs");
148 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], []() {
149 assert_exit(true, 2);
150 REQUIRE_NETWORK_FAILURE(all_hosts[1]->sendto(all_hosts[2], 5000));
153 simgrid::s4u::this_actor::sleep_for(2);
154 auto link = simgrid::s4u::Engine::get_instance()->link_by_name("link1");
161 BEGIN_SECTION("dcomm link restarted at end")
163 XBT_INFO("Launch a dcomm(5s), and restart the used link right when it stops");
164 bool execution_done = false;
166 simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], [&execution_done]() {
167 assert_exit(true, 5);
168 all_hosts[1]->sendto(all_hosts[2], 5000);
169 execution_done = true;
172 simgrid::s4u::Actor::create("killer", all_hosts[0], []() {
173 simgrid::s4u::this_actor::sleep_for(5);
175 auto link = simgrid::s4u::Engine::get_instance()->link_by_name("link1");
180 simgrid::s4u::this_actor::sleep_for(9);
181 INFO("Was restarted actor already dead in the scheduling round during which the host_off simcall was issued?");
182 REQUIRE(execution_done);
187 simgrid::s4u::this_actor::sleep_for(10);