Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix doc.
[simgrid.git] / src / kernel / resource / NetworkModelFactors_test.cpp
1 /* Copyright (c) 2017-2022. 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/s4u/Engine.hpp"
9 #include "simgrid/sg_config.hpp"
10 #include "src/internal_config.h" // HAVE_SMPI
11 #include "src/kernel/resource/NetworkModelFactors.hpp"
12
13 static double factor_cb(double, const simgrid::s4u::Host*, const simgrid::s4u::Host*,
14                         const std::vector<simgrid::s4u::Link*>&, const std::unordered_set<simgrid::s4u::NetZone*>&)
15 {
16   return 1.0;
17 }
18
19 TEST_CASE("kernel::resource::NetworkModelFactors: Factors invalid callbacks: exception", "")
20 {
21   std::vector<std::string> models{"LV08", "CM02"};
22 #if HAVE_SMPI
23   models.emplace_back("SMPI");
24   models.emplace_back("IB");
25 #endif
26
27   for (const auto& model : models) {
28     _sg_cfg_init_status = 0; /* HACK: clear config global to be able to do set_config in UTs */
29     simgrid::s4u::Engine e("test");
30     simgrid::s4u::Engine::set_config("network/model:" + model);
31     simgrid::s4u::create_full_zone("root");
32
33     SECTION("Model: " + model)
34     {
35       const auto* zone = e.get_netzone_root();
36       REQUIRE_THROWS_AS(zone->set_latency_factor_cb({}), std::invalid_argument);
37       REQUIRE_THROWS_AS(zone->set_latency_factor_cb(nullptr), std::invalid_argument);
38       REQUIRE_THROWS_AS(zone->set_bandwidth_factor_cb({}), std::invalid_argument);
39       REQUIRE_THROWS_AS(zone->set_bandwidth_factor_cb(nullptr), std::invalid_argument);
40     }
41   }
42 }
43
44 TEST_CASE("kernel::resource::NetworkModelFactors: Invalid network/latency-factor and network/bandwidth-factor", "")
45 {
46   std::vector<std::string> models{"LV08", "CM02"};
47 #if HAVE_SMPI
48   models.emplace_back("SMPI");
49   models.emplace_back("IB");
50 #endif
51
52   for (const auto& model : models) {
53     _sg_cfg_init_status = 0; /* HACK: clear config global to be able to do set_config in UTs */
54     simgrid::s4u::Engine e("test");
55     simgrid::s4u::Engine::set_config("network/model:" + model);
56     simgrid::s4u::Engine::set_config("network/latency-factor:10");
57     simgrid::s4u::Engine::set_config("network/bandwidth-factor:0.3");
58     simgrid::s4u::create_full_zone("root");
59
60     SECTION("Model: " + model)
61     {
62       const auto* zone = e.get_netzone_root();
63       REQUIRE_THROWS_AS(zone->set_latency_factor_cb(factor_cb), std::invalid_argument);
64       REQUIRE_THROWS_AS(zone->set_bandwidth_factor_cb(factor_cb), std::invalid_argument);
65     }
66   }
67 }