Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initialize models together with netzone root
[simgrid.git] / src / kernel / routing / TorusZone_test.cpp
1 /* Copyright (c) 2017-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 "catch.hpp"
7
8 #include "simgrid/kernel/routing/NetPoint.hpp"
9 #include "simgrid/kernel/routing/TorusZone.hpp"
10 #include "simgrid/s4u/Engine.hpp"
11 #include "simgrid/s4u/Host.hpp"
12 #include "simgrid/s4u/NetZone.hpp"
13 #include "src/surf/network_interface.hpp"
14 #include "src/surf/xml/platf_private.hpp" // RouteCreationArgs and friends
15
16 namespace {
17 class EngineWrapper {
18   int argc = 1;
19   char* argv;
20
21 public:
22   simgrid::s4u::Engine e;
23   explicit EngineWrapper(std::string name) : argv(&name[0]), e(&argc, &argv) {}
24 };
25
26 std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
27 create_host(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& coord, int id)
28 {
29   simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
30   return std::make_pair(host->get_netpoint(), nullptr);
31 }
32 } // namespace
33
34 TEST_CASE("kernel::routing::TorusZone: Creating Zone", "")
35 {
36   using namespace simgrid::s4u;
37   EngineWrapper e("test");
38   auto create_host = [](NetZone* zone, const std::vector<unsigned int>& coord,
39                         int id) -> std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*> {
40     Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
41     return std::make_pair(host->get_netpoint(), nullptr);
42   };
43   REQUIRE(create_torus_zone("test", e.e.get_netzone_root(), {3, 3, 3}, 1e9, 10,
44                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host));
45 }
46
47 TEST_CASE("kernel::routing::TorusZone: Invalid params", "")
48 {
49   using namespace simgrid::s4u;
50   EngineWrapper e("test");
51
52   SECTION("Empty dimensions")
53   {
54     REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {}, 1e9, 10,
55                                         simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
56                       std::invalid_argument);
57   }
58   SECTION("One 0 dimension")
59   {
60     REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 0, 2}, 1e9, 10,
61                                         simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
62                       std::invalid_argument);
63   }
64   SECTION("Invalid bandwidth")
65   {
66     REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 0, 10,
67                                         simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
68                       std::invalid_argument);
69   }
70   SECTION("Invalid latency")
71   {
72     REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 1e9, -10,
73                                         simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
74                       std::invalid_argument);
75   }
76 }