From: Bruno Donassolo Date: Wed, 21 Apr 2021 10:02:25 +0000 (+0200) Subject: Add some UT for TorusZone X-Git-Tag: v3.28~416 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f365dfb058131f5436c5cd47612c9cf5ebe49993 Add some UT for TorusZone Improve some checks. --- diff --git a/MANIFEST.in b/MANIFEST.in index 8898a5b488..780f9143c3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2209,6 +2209,7 @@ include src/kernel/routing/RoutedZone.cpp include src/kernel/routing/StarZone.cpp include src/kernel/routing/StarZone_test.cpp include src/kernel/routing/TorusZone.cpp +include src/kernel/routing/TorusZone_test.cpp include src/kernel/routing/VivaldiZone.cpp include src/kernel/routing/WifiZone.cpp include src/mc/AddressSpace.hpp diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index 945ecf9867..c16a38846d 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -258,13 +258,17 @@ NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const const std::function& set_loopback, const std::function& set_limiter) { - auto* zone = new kernel::routing::TorusZone(name); - zone->set_topology(dimensions); - if (parent) - zone->set_parent(parent->get_impl()); - int tot_elements = std::accumulate(dimensions.begin(), dimensions.end(), 1, std::multiplies<>()); - xbt_assert(tot_elements > 0, "TorusZone: incorrect dimensions, unable to create %d elements", tot_elements); + if (dimensions.empty() || tot_elements <= 0) + throw std::invalid_argument("TorusZone: incorrect dimensions parameter, each value must be > 0"); + if (bandwidth <= 0) + throw std::invalid_argument("TorusZone: incorrect bandwidth for internode communication, bw=" + + std::to_string(bandwidth)); + if (latency < 0) + throw std::invalid_argument("TorusZone: incorrect latency for internode communication, lat=" + + std::to_string(latency)); + + // auxiliary function to get dims from index auto index_to_dims = [&dimensions](int index) { std::vector dims_array(dimensions.size()); for (int i = dimensions.size() - 1; i >= 0 && index > 0; --i) { @@ -275,24 +279,40 @@ NetZone* create_torus_zone(const std::string& name, const NetZone* parent, const return dims_array; }; + auto* zone = new kernel::routing::TorusZone(name); + zone->set_topology(dimensions); + if (parent) + zone->set_parent(parent->get_impl()); + for (int i = 0; i < tot_elements; i++) { kernel::routing::NetPoint *netpoint = nullptr, *gw = nullptr; auto dims = index_to_dims(i); std::tie(netpoint, gw) = set_netpoint(zone->get_iface(), dims, i); + xbt_assert(netpoint, "TorusZone::set_netpoint(elem=%d): Invalid netpoint (nullptr)", i); + if (netpoint->is_netzone()) { + xbt_assert(gw && not gw->is_netzone(), + "TorusZone::set_netpoint(elem=%d): Netpoint (%s) is a netzone, but gateway (%s) is invalid", i, + netpoint->get_cname(), gw ? gw->get_cname() : "nullptr"); + } else { + xbt_assert(not gw, "TorusZone: Netpoint (%s) isn't netzone, gateway must be nullptr", netpoint->get_cname()); + } // FIXME: add gateway if set + if (set_loopback) { Link* loopback = set_loopback(zone->get_iface(), dims, i); - xbt_assert(loopback, "Invalid loopback link (nullptr) for element %d", i); + xbt_assert(loopback, "TorusZone::set_loopback: Invalid loopback link (nullptr) for element %d", i); zone->set_loopback(); zone->add_private_link_at(zone->node_pos(netpoint->id()), {loopback->get_impl(), loopback->get_impl()}); } + if (set_limiter) { Link* limiter = set_limiter(zone->get_iface(), dims, i); - xbt_assert(limiter, "Invalid limiter link (nullptr) for element %d", i); + xbt_assert(limiter, "TorusZone::set_limiter: Invalid limiter link (nullptr) for element %d", i); zone->set_limiter(); zone->add_private_link_at(zone->node_pos_with_loopback(netpoint->id()), {limiter->get_impl(), limiter->get_impl()}); } + kernel::routing::ClusterCreationArgs params; params.id = name; params.bw = bandwidth; diff --git a/src/kernel/routing/TorusZone_test.cpp b/src/kernel/routing/TorusZone_test.cpp new file mode 100644 index 0000000000..29d20c4109 --- /dev/null +++ b/src/kernel/routing/TorusZone_test.cpp @@ -0,0 +1,87 @@ +/* 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. */ + +#include "catch.hpp" + +#include "simgrid/kernel/routing/NetPoint.hpp" +#include "simgrid/kernel/routing/TorusZone.hpp" +#include "simgrid/s4u/Engine.hpp" +#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 { +class EngineWrapper { + int argc = 1; + char* argv; + +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(); + } +}; + +std::pair +create_host(simgrid::s4u::NetZone* zone, const std::vector& coord, int id) +{ + 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", "") +{ + using namespace simgrid::s4u; + EngineWrapper e("test"); + auto create_host = [](NetZone* zone, const std::vector& coord, + int id) -> std::pair { + Host* host = zone->create_host(std::to_string(id), 1e9)->seal(); + return std::make_pair(host->get_netpoint(), nullptr); + }; + REQUIRE(create_torus_zone("test", e.e.get_netzone_root(), {3, 3, 3}, 1e9, 10, + simgrid::s4u::Link::SharingPolicy::SHARED, create_host)); +} + +TEST_CASE("kernel::routing::TorusZone: Invalid params", "") +{ + 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); + } +} \ No newline at end of file diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index 33f4d2326a..7a9af11cfc 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -125,6 +125,7 @@ ENDIF() set(UNIT_TESTS src/xbt/unit-tests_main.cpp src/kernel/resource/profile/Profile_test.cpp src/kernel/routing/StarZone_test.cpp + src/kernel/routing/TorusZone_test.cpp src/xbt/config_test.cpp src/xbt/dict_test.cpp src/xbt/dynar_test.cpp