Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill EngineWrapper hack and reduce code duplication.
[simgrid.git] / src / kernel / routing / FatTreeZone_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/FatTreeZone.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 std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
16 create_host(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& /*coord*/, int id)
17 {
18   const simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
19   return std::make_pair(host->get_netpoint(), nullptr);
20 }
21 } // namespace
22
23 TEST_CASE("kernel::routing::FatTreeZone: Creating Zone", "")
24 {
25   simgrid::s4u::Engine e("test");
26   simgrid::s4u::ClusterCallbacks callbacks(create_host);
27   REQUIRE(create_fatTree_zone("test", e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9, 10,
28                               simgrid::s4u::Link::SharingPolicy::SHARED));
29 }
30
31 TEST_CASE("kernel::routing::FatTreeZone: Invalid params", "")
32 {
33   simgrid::s4u::Engine e("test");
34   simgrid::s4u::ClusterCallbacks callbacks(create_host);
35
36   SECTION("0 levels")
37   {
38     REQUIRE_THROWS_AS(create_fatTree_zone("test", e.get_netzone_root(), {0, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9, 10,
39                                           simgrid::s4u::Link::SharingPolicy::SHARED),
40                       std::invalid_argument);
41   }
42
43   SECTION("Invalid down links")
44   {
45     REQUIRE_THROWS_AS(create_fatTree_zone("test", e.get_netzone_root(), {2, {4}, {1, 2}, {1, 2}}, callbacks, 1e9, 10,
46                                           simgrid::s4u::Link::SharingPolicy::SHARED),
47                       std::invalid_argument);
48   }
49
50   SECTION("Invalid up links")
51   {
52     REQUIRE_THROWS_AS(create_fatTree_zone("test", e.get_netzone_root(), {2, {4, 4}, {1}, {1, 2}}, callbacks, 1e9, 10,
53                                           simgrid::s4u::Link::SharingPolicy::SHARED),
54                       std::invalid_argument);
55   }
56
57   SECTION("Invalid link count")
58   {
59     REQUIRE_THROWS_AS(create_fatTree_zone("test", e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1}}, callbacks, 1e9, 10,
60                                           simgrid::s4u::Link::SharingPolicy::SHARED),
61                       std::invalid_argument);
62   }
63
64   SECTION("Down links with zeroes")
65   {
66     REQUIRE_THROWS_AS(create_fatTree_zone("test", e.get_netzone_root(), {2, {4, 0}, {1, 2}, {1, 2}}, callbacks, 1e9, 10,
67                                           simgrid::s4u::Link::SharingPolicy::SHARED),
68                       std::invalid_argument);
69   }
70
71   SECTION("Up links with zeroes")
72   {
73     REQUIRE_THROWS_AS(create_fatTree_zone("test", e.get_netzone_root(), {2, {4, 4}, {0, 2}, {1, 2}}, callbacks, 1e9, 10,
74                                           simgrid::s4u::Link::SharingPolicy::SHARED),
75                       std::invalid_argument);
76   }
77
78   SECTION("Link count with zeroes")
79   {
80     REQUIRE_THROWS_AS(create_fatTree_zone("test", e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 0}}, callbacks, 1e9, 10,
81                                           simgrid::s4u::Link::SharingPolicy::SHARED),
82                       std::invalid_argument);
83   }
84
85   SECTION("0 bandwidth")
86   {
87     REQUIRE_THROWS_AS(create_fatTree_zone("test", e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 0, 10,
88                                           simgrid::s4u::Link::SharingPolicy::SHARED),
89                       std::invalid_argument);
90   }
91
92   SECTION("Negative latency")
93   {
94     REQUIRE_THROWS_AS(create_fatTree_zone("test", e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9,
95                                           -10, simgrid::s4u::Link::SharingPolicy::SHARED),
96                       std::invalid_argument);
97   }
98 }