Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factor common code.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 21 Jul 2021 14:16:50 +0000 (16:16 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 22 Jul 2021 12:34:48 +0000 (14:34 +0200)
MANIFEST.in
src/kernel/routing/DragonflyZone_test.cpp
src/kernel/routing/FatTreeZone_test.cpp
src/kernel/routing/NetZone_test.hpp [new file with mode: 0644]
src/kernel/routing/TorusZone_test.cpp
tools/cmake/Tests.cmake

index 166953e..fcc89b0 100644 (file)
@@ -2254,6 +2254,7 @@ include src/kernel/routing/FullZone.cpp
 include src/kernel/routing/FullZone_test.cpp
 include src/kernel/routing/NetPoint.cpp
 include src/kernel/routing/NetZoneImpl.cpp
+include src/kernel/routing/NetZone_test.hpp
 include src/kernel/routing/RoutedZone.cpp
 include src/kernel/routing/StarZone.cpp
 include src/kernel/routing/StarZone_test.cpp
index 02a2a96..f90dd3d 100644 (file)
@@ -5,25 +5,14 @@
 
 #include "catch.hpp"
 
+#include "NetZone_test.hpp" // CreateHost callback
 #include "simgrid/kernel/routing/DragonflyZone.hpp"
-#include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/s4u/Engine.hpp"
-#include "simgrid/s4u/Host.hpp"
-#include "simgrid/s4u/NetZone.hpp"
-
-namespace {
-std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
-create_host(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& /*coord*/, int id)
-{
-  const simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
-  return std::make_pair(host->get_netpoint(), nullptr);
-}
-} // namespace
 
 TEST_CASE("kernel::routing::DragonflyZone: Creating Zone", "")
 {
   simgrid::s4u::Engine e("test");
-  simgrid::s4u::ClusterCallbacks callbacks(create_host);
+  simgrid::s4u::ClusterCallbacks callbacks(CreateHost{});
   REQUIRE(create_dragonfly_zone("test", e.get_netzone_root(), {{3, 4}, {4, 3}, {5, 1}, 2}, callbacks, 1e9, 10,
                                 simgrid::s4u::Link::SharingPolicy::SHARED));
 }
@@ -31,7 +20,7 @@ TEST_CASE("kernel::routing::DragonflyZone: Creating Zone", "")
 TEST_CASE("kernel::routing::DragonflyZone: Invalid params", "")
 {
   simgrid::s4u::Engine e("test");
-  simgrid::s4u::ClusterCallbacks callbacks(create_host);
+  simgrid::s4u::ClusterCallbacks callbacks(CreateHost{});
 
   SECTION("0 nodes")
   {
index 18f3e9e..ebf1153 100644 (file)
@@ -5,25 +5,14 @@
 
 #include "catch.hpp"
 
+#include "NetZone_test.hpp" // CreateHost callback
 #include "simgrid/kernel/routing/FatTreeZone.hpp"
-#include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/s4u/Engine.hpp"
-#include "simgrid/s4u/Host.hpp"
-#include "simgrid/s4u/NetZone.hpp"
-
-namespace {
-std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
-create_host(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& /*coord*/, int id)
-{
-  const simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
-  return std::make_pair(host->get_netpoint(), nullptr);
-}
-} // namespace
 
 TEST_CASE("kernel::routing::FatTreeZone: Creating Zone", "")
 {
   simgrid::s4u::Engine e("test");
-  simgrid::s4u::ClusterCallbacks callbacks(create_host);
+  simgrid::s4u::ClusterCallbacks callbacks(CreateHost{});
   REQUIRE(create_fatTree_zone("test", e.get_netzone_root(), {2, {4, 4}, {1, 2}, {1, 2}}, callbacks, 1e9, 10,
                               simgrid::s4u::Link::SharingPolicy::SHARED));
 }
@@ -31,7 +20,7 @@ TEST_CASE("kernel::routing::FatTreeZone: Creating Zone", "")
 TEST_CASE("kernel::routing::FatTreeZone: Invalid params", "")
 {
   simgrid::s4u::Engine e("test");
-  simgrid::s4u::ClusterCallbacks callbacks(create_host);
+  simgrid::s4u::ClusterCallbacks callbacks(CreateHost{});
 
   SECTION("0 levels")
   {
diff --git a/src/kernel/routing/NetZone_test.hpp b/src/kernel/routing/NetZone_test.hpp
new file mode 100644 (file)
index 0000000..1850025
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved.               */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef NETZONE_TEST_HPP
+#define NETZONE_TEST_HPP
+
+#include "simgrid/kernel/routing/NetPoint.hpp"
+#include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/NetZone.hpp"
+
+// Callback function common to several routing unit tests
+struct CreateHost {
+  std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
+  operator()(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& /*coord*/, int id) const
+  {
+    const simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
+    return std::make_pair(host->get_netpoint(), nullptr);
+  }
+};
+
+#endif
index a33a15c..cdaf198 100644 (file)
@@ -5,25 +5,14 @@
 
 #include "catch.hpp"
 
-#include "simgrid/kernel/routing/NetPoint.hpp"
+#include "NetZone_test.hpp" // CreateHost callback
 #include "simgrid/kernel/routing/TorusZone.hpp"
 #include "simgrid/s4u/Engine.hpp"
-#include "simgrid/s4u/Host.hpp"
-#include "simgrid/s4u/NetZone.hpp"
-
-namespace {
-std::pair<simgrid::kernel::routing::NetPoint*, simgrid::kernel::routing::NetPoint*>
-create_host(simgrid::s4u::NetZone* zone, const std::vector<unsigned int>& /*coord*/, int id)
-{
-  const simgrid::s4u::Host* host = zone->create_host(std::to_string(id), 1e9)->seal();
-  return std::make_pair(host->get_netpoint(), nullptr);
-}
-} // namespace
 
 TEST_CASE("kernel::routing::TorusZone: Creating Zone", "")
 {
   simgrid::s4u::Engine e("test");
-  simgrid::s4u::ClusterCallbacks callbacks(create_host);
+  simgrid::s4u::ClusterCallbacks callbacks(CreateHost{});
   REQUIRE(create_torus_zone("test", e.get_netzone_root(), {3, 3, 3}, callbacks, 1e9, 10,
                             simgrid::s4u::Link::SharingPolicy::SHARED));
 }
@@ -31,7 +20,7 @@ TEST_CASE("kernel::routing::TorusZone: Creating Zone", "")
 TEST_CASE("kernel::routing::TorusZone: Invalid params", "")
 {
   simgrid::s4u::Engine e("test");
-  simgrid::s4u::ClusterCallbacks callbacks(create_host);
+  simgrid::s4u::ClusterCallbacks callbacks(CreateHost{});
 
   SECTION("Empty dimensions")
   {
index fb4291c..47e378e 100644 (file)
@@ -144,6 +144,7 @@ if (SIMGRID_HAVE_MC)
 else()
   set(EXTRA_DIST ${EXTRA_DIST} src/mc/sosp/Snapshot_test.cpp src/mc/sosp/PageStore_test.cpp)
 endif()  
+set(EXTRA_DIST ${EXTRA_DIST} src/kernel/routing/NetZone_test.hpp)
 
 add_executable       (unit-tests EXCLUDE_FROM_ALL ${UNIT_TESTS})
 add_dependencies     (tests unit-tests)