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 TEST_CASE("Activity lifecycle: direct communication activities")
10 XBT_INFO("#####[ launch next \"direct-comm\" test ]#####");
12 BEGIN_SECTION("dcomm")
14 XBT_INFO("Launch a dcomm(5s), and let it proceed");
17 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5", all_hosts[1], [&global]() {
18 assert_exit(true, 5.);
19 all_hosts[1]->sendto(all_hosts[2], 5000);
23 simgrid::s4u::this_actor::sleep_for(9);
24 INFO("Did the forked actor modify the global after sleeping, or was it killed before?");
30 BEGIN_SECTION("dcomm actor killed at start")
32 XBT_INFO("Launch a dcomm(5s), and kill it right after start");
33 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_killed", all_hosts[1], []() {
34 assert_exit(false, 0);
35 all_hosts[1]->sendto(all_hosts[2], 5000);
36 FAIL("I should be dead now");
39 simgrid::s4u::this_actor::yield();
45 BEGIN_SECTION("dcomm actor killed in middle")
47 XBT_INFO("Launch a dcomm(5s), and kill it after 2 secs");
48 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_killed", all_hosts[1], []() {
49 assert_exit(false, 2);
50 all_hosts[1]->sendto(all_hosts[2], 5000);
51 FAIL("I should be dead now");
54 simgrid::s4u::this_actor::sleep_for(2);
60 BEGIN_SECTION("dcomm host restarted at start")
62 XBT_INFO("Launch a dcomm(5s), and restart its host right after start");
63 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], []() {
64 assert_exit(false, 0);
65 all_hosts[1]->sendto(all_hosts[2], 5000);
66 FAIL("I should be dead now");
69 simgrid::s4u::this_actor::yield();
70 dcomm5->get_host()->turn_off();
71 dcomm5->get_host()->turn_on();
76 BEGIN_SECTION("dcomm host restarted in middle")
78 XBT_INFO("Launch a dcomm(5s), and restart its host after 2 secs");
79 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], []() {
80 assert_exit(false, 2);
81 all_hosts[1]->sendto(all_hosts[2], 5000);
82 FAIL("I should be dead now");
85 simgrid::s4u::this_actor::sleep_for(2);
86 dcomm5->get_host()->turn_off();
87 dcomm5->get_host()->turn_on();
92 BEGIN_SECTION("dcomm host restarted at end")
94 XBT_INFO("Launch a dcomm(5s), and restart its host right when it stops");
95 bool execution_done = false;
97 simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], [&execution_done]() {
99 all_hosts[1]->sendto(all_hosts[2], 5000);
100 execution_done = true;
103 simgrid::s4u::Actor::create("killer", all_hosts[0], []() {
104 simgrid::s4u::this_actor::sleep_for(5);
106 all_hosts[1]->turn_off();
107 all_hosts[1]->turn_on();
110 simgrid::s4u::this_actor::sleep_for(9);
111 INFO("Was restarted actor already dead in the scheduling round during which the host_off simcall was issued?");
112 REQUIRE(execution_done);
117 BEGIN_SECTION("dcomm link restarted at start")
119 XBT_INFO("Launch a dcomm(5s), and restart the used link right after start");
120 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], []() {
121 assert_exit(true, 0);
122 REQUIRE_NETWORK_FAILURE(all_hosts[1]->sendto(all_hosts[2], 5000));
125 simgrid::s4u::this_actor::yield();
126 auto link = simgrid::s4u::Engine::get_instance()->link_by_name("link1");
133 BEGIN_SECTION("dcomm link restarted in middle")
135 XBT_INFO("Launch a dcomm(5s), and restart the used link after 2 secs");
136 simgrid::s4u::ActorPtr dcomm5 = simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], []() {
137 assert_exit(true, 2);
138 REQUIRE_NETWORK_FAILURE(all_hosts[1]->sendto(all_hosts[2], 5000));
141 simgrid::s4u::this_actor::sleep_for(2);
142 auto link = simgrid::s4u::Engine::get_instance()->link_by_name("link1");
149 BEGIN_SECTION("dcomm link restarted at end")
151 XBT_INFO("Launch a dcomm(5s), and restart the used link right when it stops");
152 bool execution_done = false;
154 simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], [&execution_done]() {
155 assert_exit(true, 5);
156 all_hosts[1]->sendto(all_hosts[2], 5000);
157 execution_done = true;
160 simgrid::s4u::Actor::create("killer", all_hosts[0], []() {
161 simgrid::s4u::this_actor::sleep_for(5);
163 auto link = simgrid::s4u::Engine::get_instance()->link_by_name("link1");
168 simgrid::s4u::this_actor::sleep_for(9);
169 INFO("Was restarted actor already dead in the scheduling round during which the host_off simcall was issued?");
170 REQUIRE(execution_done);
175 simgrid::s4u::this_actor::sleep_for(10);