Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Missing include (for uintptr_t).
[simgrid.git] / teshsuite / catch_simgrid.cpp
1 /* Copyright (c) 2010-2022. 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 #define CATCH_CONFIG_RUNNER // we supply our own main()
7
8 #include "catch_simgrid.hpp"
9
10 #include <xbt/config.hpp>
11
12 XBT_LOG_NEW_CATEGORY(s4u_test, "Messages specific for this s4u example");
13
14 std::vector<simgrid::s4u::Host*> all_hosts;
15
16 /* Helper function easing the testing of actor's ending condition */
17 void assert_exit(bool exp_success, double duration)
18 {
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");
27   });
28 }
29
30 /* Helper function in charge of doing some sanity checks after each test */
31 void assert_cleanup()
32 {
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");
43     }
44   }
45   // TODO: Check that all LMM are empty
46 }
47
48 int main(int argc, char* argv[])
49 {
50   simgrid::config::set_value("help-nostop", true);
51   simgrid::s4u::Engine e(&argc, argv);
52
53   std::string platf;
54   if (argc > 1) {
55     platf   = argv[1];
56     argv[1] = argv[0];
57     argv++;
58     argc--;
59   } else {
60     XBT_WARN("No platform file provided. Using './testing_platform.xml'");
61     platf = "./testing_platform.xml";
62   }
63   e.load_platform(platf);
64
65   int status = 42;
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); });
69
70   e.run();
71   XBT_INFO("Simulation done");
72   return status;
73 }