Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New: s4u::create_dragonfly_zone
[simgrid.git] / src / kernel / routing / DragonflyZone_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/DragonflyZone.hpp"
9 #include "simgrid/kernel/routing/NetPoint.hpp"
10 #include "simgrid/s4u/Engine.hpp"
11 #include "simgrid/s4u/Host.hpp"
12 #include "simgrid/s4u/NetZone.hpp"
13
14 namespace {
15 class EngineWrapper {
16 public:
17   explicit EngineWrapper(std::string name) : argv(&name[0]), e(&argc, &argv) {}
18   int argc = 1;
19   char* argv;
20   simgrid::s4u::Engine e;
21 };
22
23 std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
24 create_host(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& /*coord*/, int id)
25 {
26   const simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
27   return std::make_pair(host->get_netpoint(), nullptr);
28 }
29 } // namespace
30
31 TEST_CASE("kernel::routing::DragonflyZone: Creating Zone", "")
32 {
33   using namespace simgrid::s4u;
34   EngineWrapper e("test");
35   REQUIRE(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, 1e9, 10,
36                                 simgrid::s4u::Link::SharingPolicy::SHARED, create_host));
37 }
38
39 TEST_CASE("kernel::routing::DragonflyZone: Invalid params", "")
40 {
41   using namespace simgrid::s4u;
42   EngineWrapper e("test");
43
44   SECTION("0 nodes")
45   {
46     REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 0}, 1e9, 10,
47                                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
48                       std::invalid_argument);
49   }
50
51   SECTION("0 groups")
52   {
53     REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{0, 4}, {4, 3}, {5, 1}, 2}, 1e9, 10,
54                                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
55                       std::invalid_argument);
56   }
57   SECTION("0 groups links")
58   {
59     REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 0}, {4, 3}, {5, 1}, 2}, 1e9, 10,
60                                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
61                       std::invalid_argument);
62   }
63
64   SECTION("0 chassis")
65   {
66     REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {0, 3}, {5, 1}, 2}, 1e9, 10,
67                                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
68                       std::invalid_argument);
69   }
70
71   SECTION("0 chassis links")
72   {
73     REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 0}, {5, 1}, 2}, 1e9, 10,
74                                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
75                       std::invalid_argument);
76   }
77
78   SECTION("0 routers")
79   {
80     REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {0, 1}, 2}, 1e9, 10,
81                                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
82                       std::invalid_argument);
83   }
84
85   SECTION("0 routers links")
86   {
87     REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 0}, 2}, 1e9, 10,
88                                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
89                       std::invalid_argument);
90   }
91
92   SECTION("0 bandwidth")
93   {
94     REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, 0, 10,
95                                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
96                       std::invalid_argument);
97   }
98
99   SECTION("Negative latency")
100   {
101     REQUIRE_THROWS_AS(create_dragonfly_zone("test", e.e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, 1e9, -10,
102                                             simgrid::s4u::Link::SharingPolicy::SHARED, create_host),
103                       std::invalid_argument);
104   }
105 }