1 /* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved. */
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. */
8 #include "simgrid/kernel/resource/NetworkModelIntf.hpp"
9 #include "simgrid/s4u/Engine.hpp"
10 #include "simgrid/sg_config.hpp"
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*>&)
18 TEST_CASE("kernel::resource::NetworkModelIntf: Factors invalid callbacks: exception", "")
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");
26 SECTION("Model: " + model)
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);
37 TEST_CASE("kernel::resource::NetworkModelIntf: Invalid network/latency-factor and network/bandwidth-factor", "")
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");
47 SECTION("Model: " + model)
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);
56 TEST_CASE("kernel::resource::NetworkModelIntf: Invalid smpi/lat-factor and smpi/bw-factor", "")
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");
66 SECTION("Model: " + model)
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);