Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fixes in UTs
[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
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::TorusZone: Creating Zone", "")
24 {
25   simgrid::s4u::Engine e("test");
26   simgrid::s4u::ClusterCallbacks callbacks(create_host);
27   REQUIRE(create_torus_zone("test", e.get_netzone_root(), {3, 3, 3}, callbacks, 1e9, 10,
28                             simgrid::s4u::Link::SharingPolicy::SHARED));
29 }
30
31 TEST_CASE("kernel::routing::TorusZone: Invalid params", "")
32 {
33   simgrid::s4u::Engine e("test");
34   simgrid::s4u::ClusterCallbacks callbacks(create_host);
35
36   SECTION("Empty dimensions")
37   {
38     REQUIRE_THROWS_AS(create_torus_zone("test", e.get_netzone_root(), {}, callbacks, 1e9, 10,
39                                         simgrid::s4u::Link::SharingPolicy::SHARED),
40                       std::invalid_argument);
41   }
42   SECTION("One 0 dimension")
43   {
44     REQUIRE_THROWS_AS(create_torus_zone("test", e.get_netzone_root(), {3, 0, 2}, callbacks, 1e9, 10,
45                                         simgrid::s4u::Link::SharingPolicy::SHARED),
46                       std::invalid_argument);
47   }
48   SECTION("Invalid bandwidth")
49   {
50     REQUIRE_THROWS_AS(create_torus_zone("test", e.get_netzone_root(), {3, 2, 2}, callbacks, 0, 10,
51                                         simgrid::s4u::Link::SharingPolicy::SHARED),
52                       std::invalid_argument);
53   }
54   SECTION("Invalid latency")
55   {
56     REQUIRE_THROWS_AS(create_torus_zone("test", e.get_netzone_root(), {3, 2, 2}, callbacks, 1e9, -10,
57                                         simgrid::s4u::Link::SharingPolicy::SHARED),
58                       std::invalid_argument);
59   }
60 }