Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't duplicate macro definition.
[simgrid.git] / teshsuite / s4u / activity-lifecycle / testing_comm_direct.cpp
1 /* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "activity-lifecycle.hpp"
7
8 TEST_CASE("Activity lifecycle: direct communication activities")
9 {
10   XBT_INFO("#####[ launch next \"direct-comm\" test ]#####");
11
12   BEGIN_SECTION("dcomm")
13   {
14     XBT_INFO("Launch a dcomm(5s), and let it proceed");
15     bool global = false;
16
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);
20       global = true;
21     });
22
23     simgrid::s4u::this_actor::sleep_for(9);
24     INFO("Did the forked actor modify the global after sleeping, or was it killed before?");
25     REQUIRE(global);
26
27     END_SECTION;
28   }
29
30   BEGIN_SECTION("dcomm actor killed at start")
31   {
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");
37     });
38
39     simgrid::s4u::this_actor::yield();
40     dcomm5->kill();
41
42     END_SECTION;
43   }
44
45   BEGIN_SECTION("dcomm actor killed in middle")
46   {
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");
52     });
53
54     simgrid::s4u::this_actor::sleep_for(2);
55     dcomm5->kill();
56
57     END_SECTION;
58   }
59
60   BEGIN_SECTION("dcomm host restarted at start")
61   {
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");
67     });
68
69     simgrid::s4u::this_actor::yield();
70     dcomm5->get_host()->turn_off();
71     dcomm5->get_host()->turn_on();
72
73     END_SECTION;
74   }
75
76   BEGIN_SECTION("dcomm host restarted in middle")
77   {
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");
83     });
84
85     simgrid::s4u::this_actor::sleep_for(2);
86     dcomm5->get_host()->turn_off();
87     dcomm5->get_host()->turn_on();
88
89     END_SECTION;
90   }
91
92   BEGIN_SECTION("dcomm host restarted at end")
93   {
94     XBT_INFO("Launch a dcomm(5s), and restart its host right when it stops");
95     bool execution_done = false;
96
97     simgrid::s4u::Actor::create("dcomm5_restarted", all_hosts[1], [&execution_done]() {
98       assert_exit(true, 5);
99       all_hosts[1]->sendto(all_hosts[2], 5000);
100       execution_done = true;
101     });
102
103     simgrid::s4u::Actor::create("killer", all_hosts[0], []() {
104       simgrid::s4u::this_actor::sleep_for(5);
105       XBT_VERB("Killer!");
106       all_hosts[1]->turn_off();
107       all_hosts[1]->turn_on();
108     });
109
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);
113
114     END_SECTION;
115   }
116
117   BEGIN_SECTION("dcomm link restarted at start")
118   {
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));
123     });
124
125     simgrid::s4u::this_actor::yield();
126     auto link = simgrid::s4u::Engine::get_instance()->link_by_name("link1");
127     link->turn_off();
128     link->turn_on();
129
130     END_SECTION;
131   }
132
133   BEGIN_SECTION("dcomm link restarted in middle")
134   {
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));
139     });
140
141     simgrid::s4u::this_actor::sleep_for(2);
142     auto link = simgrid::s4u::Engine::get_instance()->link_by_name("link1");
143     link->turn_off();
144     link->turn_on();
145
146     END_SECTION;
147   }
148
149   BEGIN_SECTION("dcomm link restarted at end")
150   {
151     XBT_INFO("Launch a dcomm(5s), and restart the used link right when it stops");
152     bool execution_done = false;
153
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;
158     });
159
160     simgrid::s4u::Actor::create("killer", all_hosts[0], []() {
161       simgrid::s4u::this_actor::sleep_for(5);
162       XBT_VERB("Killer!");
163       auto link = simgrid::s4u::Engine::get_instance()->link_by_name("link1");
164       link->turn_off();
165       link->turn_on();
166     });
167
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);
171
172     END_SECTION;
173   }
174
175   simgrid::s4u::this_actor::sleep_for(10);
176   assert_cleanup();
177 }