Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initialize models together with netzone root
authorBruno Donassolo <bruno.donassolo@inria.fr>
Wed, 21 Apr 2021 20:12:39 +0000 (22:12 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Fri, 23 Apr 2021 08:39:06 +0000 (10:39 +0200)
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
src/kernel/routing/StarZone_test.cpp
src/kernel/routing/TorusZone_test.cpp

index cd92db9..610e233 100644 (file)
@@ -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();
   }
 
index 849489c..8f57da1 100644 (file)
@@ -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))
index 29d20c4..c741931 100644 (file)
@@ -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<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
@@ -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);