X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/bb0ba40db3bacbba2a7a7e6066b0a59f597c2fad..596e36117322c22fd31372e7803bc197bcd4a016:/src/kernel/resource/profile/Profile_test.cpp diff --git a/src/kernel/resource/profile/Profile_test.cpp b/src/kernel/resource/profile/Profile_test.cpp index 8bb95a8412..97ff0ab71d 100644 --- a/src/kernel/resource/profile/Profile_test.cpp +++ b/src/kernel/resource/profile/Profile_test.cpp @@ -1,16 +1,14 @@ -/* Copyright (c) 2017-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2017-2023. 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 "src/3rd-party/catch.hpp" -#include "simgrid/kernel/resource/Resource.hpp" -#include "src/kernel/resource/profile/DatedValue.hpp" +#include "simgrid/kernel/ProfileBuilder.hpp" +#include "src/kernel/resource/Resource.hpp" #include "src/kernel/resource/profile/Event.hpp" -#include "src/kernel/resource/profile/Profile.hpp" #include "src/kernel/resource/profile/StochasticDatedValue.hpp" -#include "src/surf/surf_interface.hpp" #include "xbt/log.h" #include "xbt/misc.h" @@ -20,44 +18,47 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(unit, "Unit tests of the Trace Manager"); -double thedate; class MockedResource : public simgrid::kernel::resource::Resource { public: - explicit MockedResource() : simgrid::kernel::resource::Resource(nullptr, "fake", nullptr) {} + static double the_date; + + explicit MockedResource() : Resource("fake"){} void apply_event(simgrid::kernel::profile::Event* event, double value) override { - XBT_VERB("t=%.1f: Change value to %lg (idx: %u)", thedate, value, event->idx); + XBT_VERB("t=%.1f: Change value to %lg (idx: %u)", the_date, value, event->idx); tmgr_trace_event_unref(&event); } bool is_used() const override { return true; } }; +double MockedResource::the_date; + static std::vector trace2vector(const char* str) { std::vector res; - simgrid::kernel::profile::Profile* trace = simgrid::kernel::profile::Profile::from_string("TheName", str, 0); + simgrid::kernel::profile::Profile* trace = simgrid::kernel::profile::ProfileBuilder::from_string("TheName", str, 0); XBT_VERB("---------------------------------------------------------"); XBT_VERB("data>>\n%s<event_list) + for (auto const& evt : trace->get_event_list()) XBT_VERB("event: d:%lg v:%lg", evt.date_, evt.value_); MockedResource daResource; simgrid::kernel::profile::FutureEvtSet fes; - simgrid::kernel::profile::Event* insertedIt = trace->schedule(&fes, &daResource); + const simgrid::kernel::profile::Event* insertedIt = trace->schedule(&fes, &daResource); while (fes.next_date() <= 20.0 && fes.next_date() >= 0) { - thedate = fes.next_date(); + MockedResource::the_date = fes.next_date(); double value; simgrid::kernel::resource::Resource* resource; - simgrid::kernel::profile::Event* it = fes.pop_leq(thedate, &value, &resource); + simgrid::kernel::profile::Event* it = fes.pop_leq(MockedResource::the_date, &value, &resource); if (it == nullptr) continue; REQUIRE(it == insertedIt); // Check that we find what we've put if (value >= 0) { - res.emplace_back(thedate, value); + res.emplace_back(MockedResource::the_date, value); } else { - XBT_DEBUG("%.1f: ignore an event (idx: %u)\n", thedate, it->idx); + XBT_DEBUG("%.1f: ignore an event (idx: %u)\n", MockedResource::the_date, it->idx); } resource->apply_event(it, value); } @@ -65,14 +66,6 @@ static std::vector trace2vector(const char return res; } -static std::vector trace2selist(const char* str) -{ - simgrid::kernel::profile::Profile* trace = simgrid::kernel::profile::Profile::from_string("TheName", str, 0); - std::vector stocevlist = trace->stochastic_event_list; - tmgr_finalize(); - return stocevlist; -} - TEST_CASE("kernel::profile: Resource profiles, defining the external load", "kernel::profile") { SECTION("No event, no loop") @@ -154,19 +147,19 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker SECTION("One stochastic event (parsing)") { + using simgrid::kernel::profile::Distribution; std::vector got = trace2selist("STOCHASTIC\n" "DET 0 UNIF 10 20"); std::vector want; - want.push_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); // The initial fake event - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0}, - simgrid::kernel::profile::Dist_Unif, {10, 20})); + want.emplace_back(Distribution::DET, std::vector{0}, Distribution::UNIF, std::vector{10, 20}); REQUIRE(want == got); } SECTION("Several stochastic events (all possible parsing forms)") { + using simgrid::kernel::profile::Distribution; std::vector got = trace2selist("STOCHASTIC\n" "DET 0 DET 4\n" "NORMAL 25 10 DET 3\n" @@ -174,15 +167,10 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker "DET 5 UNIF 5 25"); std::vector want; - want.push_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0}, - simgrid::kernel::profile::Dist_Det, {4})); - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Norm, {25, 10}, - simgrid::kernel::profile::Dist_Det, {3})); - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Unif, {10, 20}, - simgrid::kernel::profile::Dist_Norm, {25, 10})); - want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {5}, - simgrid::kernel::profile::Dist_Unif, {5, 25})); + want.emplace_back(Distribution::DET, std::vector{0}, Distribution::DET, std::vector{4}); + want.emplace_back(Distribution::NORM, std::vector{25, 10}, Distribution::DET, std::vector{3}); + want.emplace_back(Distribution::UNIF, std::vector{10, 20}, Distribution::NORM, std::vector{25, 10}); + want.emplace_back(Distribution::DET, std::vector{5}, Distribution::UNIF, std::vector{5, 25}); REQUIRE(want == got); } @@ -197,8 +185,8 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker std::vector want; // The following values were drawn using the XBT_RNG_xbt method /outside/ the testcase. - want.push_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683)); - want.push_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772)); + want.emplace_back(0, 19.29616086867082813683); + want.emplace_back(2.32719992449416279712, 20.16807234800742065772); REQUIRE(want == got); } @@ -215,10 +203,10 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker // In this case, the main use of the last stochastic event is to set when the first event takes place. std::vector want; - want.push_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683)); - want.push_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772)); - want.push_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 0)); - want.push_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 10.39759496468994726115)); + want.emplace_back(0, 19.29616086867082813683); + want.emplace_back(2.32719992449416279712, 20.16807234800742065772); + want.emplace_back(3.51111873684917075167, 0); + want.emplace_back(3.51111873684917075167, 10.39759496468994726115); REQUIRE(want == got); }