Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b4eb9f39ab5b35251718fa7c5549df9e59bba820
[simgrid.git] / src / kernel / resource / NetworkModelIntf_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/resource/NetworkModelIntf.hpp"
9 #include "simgrid/s4u/Engine.hpp"
10 #include "simgrid/sg_config.hpp"
11
12 static double factor_cb(double, const simgrid::s4u::Host*, const simgrid::s4u::Host*,
13                         const std::vector<simgrid::s4u::Link*>&, const std::unordered_set<simgrid::s4u::NetZone*>&)
14 {
15   return 1.0;
16 }
17
18 TEST_CASE("kernel::resource::NetworkModelIntf: Factors invalid callbacks: exception", "")
19 {
20   for (const auto& model : std::vector<std::string>{"LV08", "SMPI", "IB", "CM02"}) {
21     _sg_cfg_init_status = 0; /* HACK: clear config global to be able to do set_config in UTs */
22     simgrid::s4u::Engine e("test");
23     e.set_config("network/model:" + model);
24     simgrid::s4u::create_full_zone("root");
25
26     SECTION("Model: " + model)
27     {
28       simgrid::kernel::resource::NetworkModelIntf* model = e.get_netzone_root()->get_network_model();
29       REQUIRE_THROWS_AS(model->set_lat_factor_cb({}), std::invalid_argument);
30       REQUIRE_THROWS_AS(model->set_lat_factor_cb(nullptr), std::invalid_argument);
31       REQUIRE_THROWS_AS(model->set_bw_factor_cb({}), std::invalid_argument);
32       REQUIRE_THROWS_AS(model->set_bw_factor_cb(nullptr), std::invalid_argument);
33     }
34   }
35 }
36
37 TEST_CASE("kernel::resource::NetworkModelIntf: Invalid network/latency-factor and network/bandwidth-factor", "")
38 {
39   for (const auto& model : std::vector<std::string>{"LV08", "CM02"}) {
40     _sg_cfg_init_status = 0; /* HACK: clear config global to be able to do set_config in UTs */
41     simgrid::s4u::Engine e("test");
42     e.set_config("network/model:" + model);
43     e.set_config("network/latency-factor:10");
44     e.set_config("network/bandwidth-factor:0.3");
45     simgrid::s4u::create_full_zone("root");
46
47     SECTION("Model: " + model)
48     {
49       simgrid::kernel::resource::NetworkModelIntf* model = e.get_netzone_root()->get_network_model();
50       REQUIRE_THROWS_AS(model->set_lat_factor_cb(factor_cb), std::invalid_argument);
51       REQUIRE_THROWS_AS(model->set_bw_factor_cb(factor_cb), std::invalid_argument);
52     }
53   }
54 }
55
56 TEST_CASE("kernel::resource::NetworkModelIntf: Invalid smpi/lat-factor and smpi/bw-factor", "")
57 {
58   for (const auto& model : std::vector<std::string>{"SMPI", "IB"}) {
59     _sg_cfg_init_status = 0; /* HACK: clear config global to be able to do set_config in UTs */
60     simgrid::s4u::Engine e("test");
61     e.set_config("network/model:" + model);
62     e.set_config("smpi/lat-factor:65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493");
63     e.set_config("smpi/bw-factor:65472:11.6436;15424:3.48845");
64     simgrid::s4u::create_full_zone("root");
65
66     SECTION("Model: " + model)
67     {
68       simgrid::kernel::resource::NetworkModelIntf* model = e.get_netzone_root()->get_network_model();
69       REQUIRE_THROWS_AS(model->set_lat_factor_cb(factor_cb), std::invalid_argument);
70       REQUIRE_THROWS_AS(model->set_bw_factor_cb(factor_cb), std::invalid_argument);
71     }
72   }
73 }