From bba53ea25d34a4a00503a939b5abe0b4edaad467 Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Wed, 21 Apr 2021 22:12:39 +0200 Subject: [PATCH] Initialize models together with netzone root Remove static to initialize models once, anyway we have only one engine in a simulation by now. Hope someday we'll be able to initialize the models properly. Remove workaround in UTs --- src/kernel/routing/NetZoneImpl.cpp | 7 ++----- src/kernel/routing/StarZone_test.cpp | 10 ---------- src/kernel/routing/TorusZone_test.cpp | 19 ++++--------------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index cd92db9544..610e2333e8 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -71,11 +71,9 @@ NetZoneImpl::NetZoneImpl(const std::string& name) : piface_(this), name_(name) * Without globals and with current surf_*_model_description init functions, we need * the root netzone to exist when creating the models. * This was usually done at sg_platf.cpp, during XML parsing */ - if (not s4u::Engine::get_instance()->get_netzone_root()) + if (not s4u::Engine::get_instance()->get_netzone_root()) { s4u::Engine::get_instance()->set_netzone_root(&piface_); - - static bool surf_parse_models_setup_already_called = false; - if (not surf_parse_models_setup_already_called) { + /* root netzone set, initialize models */ simgrid::s4u::Engine::on_platform_creation(); /* Initialize the surf models. That must be done after we got all config, and before we need the models. @@ -85,7 +83,6 @@ NetZoneImpl::NetZoneImpl(const std::string& name) : piface_(this), name_(name) * (FIXME: check it out by creating a file beginning with one of these tags) * but cluster and peer come down to zone creations, so putting this verification here is correct. */ - surf_parse_models_setup_already_called = true; surf_config_models_setup(); } diff --git a/src/kernel/routing/StarZone_test.cpp b/src/kernel/routing/StarZone_test.cpp index 849489c90f..8f57da121f 100644 --- a/src/kernel/routing/StarZone_test.cpp +++ b/src/kernel/routing/StarZone_test.cpp @@ -11,7 +11,6 @@ #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/NetZone.hpp" #include "src/surf/network_interface.hpp" -#include "src/surf/surf_interface.hpp" // create models #include "src/surf/xml/platf_private.hpp" // RouteCreationArgs and friends namespace { @@ -89,11 +88,8 @@ TEST_CASE("kernel::routing::StarZone: Adding routes (netzones): exception", "") // https://github.com/catchorg/Catch2/issues/853 TEST_CASE("kernel::routing::StarZone: Get routes: assert", "[.][assert]") { - /* workaround to initialize things, they must be done in this particular order */ EngineWrapper e("test"); auto* zone = new simgrid::kernel::routing::StarZone("test"); - surf_network_model_init_LegrandVelho(); - surf_cpu_model_init_Cas01(); const auto* host1 = zone->create_host("netpoint1", {100}); const auto* host2 = zone->create_host("netpoint2", {100}); @@ -159,11 +155,8 @@ TEST_CASE("kernel::routing::StarZone: Adding routes (netzones): valid", "") TEST_CASE("kernel::routing::StarZone: Get routes (hosts)", "") { - /* workaround to initialize things, they must be done in this particular order */ EngineWrapper e("test"); auto* zone = new simgrid::kernel::routing::StarZone("test"); - surf_network_model_init_LegrandVelho(); - surf_cpu_model_init_Cas01(); const auto* host1 = zone->create_host("netpoint1", {100}); const auto* host2 = zone->create_host("netpoint2", {100}); @@ -235,11 +228,8 @@ TEST_CASE("kernel::routing::StarZone: Get routes (hosts)", "") TEST_CASE("kernel::routing::StarZone: Get routes (netzones)", "") { - /* workaround to initialize things, they must be done in this particular order */ EngineWrapper e("test"); auto* zone = new simgrid::kernel::routing::StarZone("test"); - surf_network_model_init_LegrandVelho(); - surf_cpu_model_init_Cas01(); auto* subzone1 = (new simgrid::kernel::routing::NetPoint("subzone1", simgrid::kernel::routing::NetPoint::Type::NetZone)) diff --git a/src/kernel/routing/TorusZone_test.cpp b/src/kernel/routing/TorusZone_test.cpp index 29d20c4109..c741931d76 100644 --- a/src/kernel/routing/TorusZone_test.cpp +++ b/src/kernel/routing/TorusZone_test.cpp @@ -11,7 +11,6 @@ #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/NetZone.hpp" #include "src/surf/network_interface.hpp" -#include "src/surf/surf_interface.hpp" // create models #include "src/surf/xml/platf_private.hpp" // RouteCreationArgs and friends namespace { @@ -21,12 +20,7 @@ class EngineWrapper { public: simgrid::s4u::Engine e; - explicit EngineWrapper(std::string name) : argv(&name[0]), e(&argc, &argv) - { - simgrid::s4u::create_full_zone("root"); - surf_network_model_init_LegrandVelho(); - surf_cpu_model_init_Cas01(); - } + explicit EngineWrapper(std::string name) : argv(&name[0]), e(&argc, &argv) {} }; std::pair @@ -52,34 +46,29 @@ TEST_CASE("kernel::routing::TorusZone: Creating Zone", "") TEST_CASE("kernel::routing::TorusZone: Invalid params", "") { + using namespace simgrid::s4u; + EngineWrapper e("test"); + SECTION("Empty dimensions") { - using namespace simgrid::s4u; - EngineWrapper e("test"); REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {}, 1e9, 10, simgrid::s4u::Link::SharingPolicy::SHARED, create_host), std::invalid_argument); } SECTION("One 0 dimension") { - using namespace simgrid::s4u; - EngineWrapper e("test"); REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 0, 2}, 1e9, 10, simgrid::s4u::Link::SharingPolicy::SHARED, create_host), std::invalid_argument); } SECTION("Invalid bandwidth") { - using namespace simgrid::s4u; - EngineWrapper e("test"); REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 0, 10, simgrid::s4u::Link::SharingPolicy::SHARED, create_host), std::invalid_argument); } SECTION("Invalid latency") { - using namespace simgrid::s4u; - EngineWrapper e("test"); REQUIRE_THROWS_AS(create_torus_zone("test", e.e.get_netzone_root(), {3, 2, 2}, 1e9, -10, simgrid::s4u::Link::SharingPolicy::SHARED, create_host), std::invalid_argument); -- 2.20.1