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 #define CATCH_CONFIG_RUNNER // we supply our own main()
8 #include "activity-lifecycle.hpp"
10 #include <xbt/config.hpp>
12 XBT_LOG_NEW_CATEGORY(s4u_test, "Messages specific for this s4u example");
14 std::vector<simgrid::s4u::Host*> all_hosts;
16 /* Helper function easing the testing of actor's ending condition */
17 void assert_exit(bool exp_success, double duration)
19 double expected_time = simgrid::s4u::Engine::get_clock() + duration;
20 simgrid::s4u::this_actor::on_exit([exp_success, expected_time](bool got_failed) {
21 XBT_VERB("Running checks on exit");
22 INFO("Check exit status. Expected: " << exp_success);
23 REQUIRE(exp_success == not got_failed);
24 INFO("Check date at exit. Expected: " + std::to_string(expected_time));
25 REQUIRE(simgrid::s4u::Engine::get_clock() == Approx(expected_time));
26 XBT_VERB("Checks on exit successful");
30 /* Helper function in charge of doing some sanity checks after each test */
33 /* Check that no actor remain (but on host[0], where main_dispatcher lives */
34 for (unsigned int i = 0; i < all_hosts.size(); i++) {
35 std::vector<simgrid::s4u::ActorPtr> all_actors = all_hosts[i]->get_all_actors();
36 unsigned int expected_count = (i == 0) ? 1 : 0; // host[0] contains main_dispatcher, all other are empty
37 if (all_actors.size() != expected_count) {
38 INFO("Host " << all_hosts[i]->get_cname() << " contains " << all_actors.size() << " actors but " << expected_count
39 << " are expected (i=" << i << "). Existing actors: ");
40 for (auto act : all_actors)
41 UNSCOPED_INFO(" - " << act->get_cname());
42 FAIL("This is wrong");
45 // TODO: Check that all LMM are empty
48 int main(int argc, char* argv[])
50 simgrid::config::set_value("help-nostop", true);
51 simgrid::s4u::Engine e(&argc, argv);
60 XBT_WARN("No platform file provided. Using './testing_platform.xml'");
61 platf = "./testing_platform.xml";
63 e.load_platform(platf);
66 all_hosts = e.get_all_hosts();
67 simgrid::s4u::Actor::create("main_dispatcher", all_hosts[0],
68 [&argc, &argv, &status]() { status = Catch::Session().run(argc, argv); });
71 XBT_INFO("Simulation done");