Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fixes in UTs
[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   std::vector<std::string> models{"LV08", "CM02"};
21 #if HAVE_SMPI
22   models.push_back("SMPI");
23   models.push_back("IB");
24 #endif
25
26   for (const auto& model : models) {
27     _sg_cfg_init_status = 0; /* HACK: clear config global to be able to do set_config in UTs */
28     simgrid::s4u::Engine e("test");
29     simgrid::s4u::Engine::set_config("network/model:" + model);
30     simgrid::s4u::create_full_zone("root");
31
32     SECTION("Model: " + model)
33     {
34       simgrid::kernel::resource::NetworkModelIntf* m = e.get_netzone_root()->get_network_model();
35       REQUIRE_THROWS_AS(m->set_lat_factor_cb({}), std::invalid_argument);
36       REQUIRE_THROWS_AS(m->set_lat_factor_cb(nullptr), std::invalid_argument);
37       REQUIRE_THROWS_AS(m->set_bw_factor_cb({}), std::invalid_argument);
38       REQUIRE_THROWS_AS(m->set_bw_factor_cb(nullptr), std::invalid_argument);
39     }
40   }
41 }
42
43 TEST_CASE("kernel::resource::NetworkModelIntf: Invalid network/latency-factor and network/bandwidth-factor", "")
44 {
45   for (const auto& model : std::vector<std::string>{"LV08", "CM02"}) {
46     _sg_cfg_init_status = 0; /* HACK: clear config global to be able to do set_config in UTs */
47     simgrid::s4u::Engine e("test");
48     simgrid::s4u::Engine::set_config("network/model:" + model);
49     simgrid::s4u::Engine::set_config("network/latency-factor:10");
50     simgrid::s4u::Engine::set_config("network/bandwidth-factor:0.3");
51     simgrid::s4u::create_full_zone("root");
52
53     SECTION("Model: " + model)
54     {
55       simgrid::kernel::resource::NetworkModelIntf* m = e.get_netzone_root()->get_network_model();
56       REQUIRE_THROWS_AS(m->set_lat_factor_cb(factor_cb), std::invalid_argument);
57       REQUIRE_THROWS_AS(m->set_bw_factor_cb(factor_cb), std::invalid_argument);
58     }
59   }
60 }
61
62 #if HAVE_SMPI
63 TEST_CASE("kernel::resource::NetworkModelIntf: Invalid smpi/lat-factor and smpi/bw-factor", "")
64 {
65   for (const auto& model : std::vector<std::string>{"SMPI", "IB"}) {
66     _sg_cfg_init_status = 0; /* HACK: clear config global to be able to do set_config in UTs */
67     simgrid::s4u::Engine e("test");
68     simgrid::s4u::Engine::set_config("network/model:" + model);
69     simgrid::s4u::Engine::set_config(
70         "smpi/lat-factor:65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493");
71     simgrid::s4u::Engine::set_config("smpi/bw-factor:65472:11.6436;15424:3.48845");
72     simgrid::s4u::create_full_zone("root");
73
74     SECTION("Model: " + model)
75     {
76       simgrid::kernel::resource::NetworkModelIntf* m = e.get_netzone_root()->get_network_model();
77       REQUIRE_THROWS_AS(m->set_lat_factor_cb(factor_cb), std::invalid_argument);
78       REQUIRE_THROWS_AS(m->set_bw_factor_cb(factor_cb), std::invalid_argument);
79     }
80   }
81 }
82 #endif