1 /* Copyright (c) 2010-2022. 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 "catch_simgrid.hpp"
8 TEST_CASE("Activity lifecycle: exec activities")
10 XBT_INFO("#####[ launch next \"exec\" test ]#####");
14 XBT_INFO("Launch an execute(5s), and let it proceed");
17 simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], [&global]() {
18 assert_exit(true, 5.);
19 simgrid::s4u::this_actor::execute(500000000);
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("exec killed at start")
32 XBT_INFO("Launch an execute(5s), and kill it right after start");
33 simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5_killed", all_hosts[1], []() {
34 assert_exit(false, 0);
35 simgrid::s4u::this_actor::execute(500000000);
36 FAIL("I should be dead now");
39 simgrid::s4u::this_actor::yield();
45 BEGIN_SECTION("exec killed in middle")
47 XBT_INFO("Launch an execute(5s), and kill it after 2 secs");
48 simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5_killed", all_hosts[1], []() {
49 assert_exit(false, 2);
50 simgrid::s4u::this_actor::execute(500000000);
51 FAIL("I should be dead now");
54 simgrid::s4u::this_actor::sleep_for(2);
60 BEGIN_SECTION("exec restarted at start")
62 XBT_INFO("Launch an execute(5s), and restart its host right after start");
63 simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5_restarted", all_hosts[1], []() {
64 assert_exit(false, 0);
65 simgrid::s4u::this_actor::execute(500000000);
66 FAIL("I should be dead now");
69 simgrid::s4u::this_actor::yield();
70 exec5->get_host()->turn_off();
71 exec5->get_host()->turn_on();
76 BEGIN_SECTION("exec restarted in middle")
78 XBT_INFO("Launch an execute(5s), and restart its host after 2 secs");
79 simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5_restarted", all_hosts[1], []() {
80 assert_exit(false, 2);
81 simgrid::s4u::this_actor::execute(500000000);
82 FAIL("I should be dead now");
85 simgrid::s4u::this_actor::sleep_for(2);
86 exec5->get_host()->turn_off();
87 exec5->get_host()->turn_on();
92 BEGIN_SECTION("exec restarted at end")
94 XBT_INFO("Launch an execute(5s), and restart its host right when it stops");
95 bool execution_done = false;
97 simgrid::s4u::Actor::create("exec5_restarted", all_hosts[1], [&execution_done]() {
99 simgrid::s4u::this_actor::execute(500000000);
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 simgrid::s4u::this_actor::sleep_for(10);