From ce5536885b73b39680ac8efa5990f6ddea79ec12 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 10 Oct 2024 14:49:37 -0700 Subject: [PATCH] =?UTF-8?q?add=20some=20tests=20with=20filter=20config=20f?= =?UTF-8?q?iles=20and=20make=20sure=20the=20cloning=20fil=E2=80=A6=20(#267?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Git Log Summary - **Added Tests** - Implemented tests with filter config files. - Ensured that cloning filters default to clone as the operation. - **Clang-Tidy Fixes** - Fixed various clang-tidy warnings and issues. - Applied clang-tidy checks and made necessary fixes. - **Pre-commit Auto Fixes** - Applied auto-fixes from pre-commit.com hooks multiple times. - For more information, see [pre-commit.ci](https://pre-commit.ci). - **Code Review Suggestions** - Incorporated suggestions from code review. ### Co-authors Co-authored-by: Ryan Mast 3969255+nightlark@users.noreply.github.com Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/helics/application_api/Federate.cpp | 35 +- src/helics/application_api/Filters.cpp | 1 + .../application_api/MessageFederate.cpp | 6 + .../MessageFederateManager.cpp | 36 +- tests/helics/application_api/FilterTests.cpp | 1691 +++++++++-------- .../MessageFederateAdditionalTests.cpp | 376 ++-- tests/helics/test_files/filter_test1.json | 30 + tests/helics/test_files/filter_test2.json | 33 + tests/helics/test_files/filter_test3.json | 32 + tests/helics/test_files/filter_test4.json | 29 + tests/helics/test_files/filter_test5.json | 28 + 11 files changed, 1301 insertions(+), 996 deletions(-) create mode 100644 tests/helics/test_files/filter_test1.json create mode 100644 tests/helics/test_files/filter_test2.json create mode 100644 tests/helics/test_files/filter_test3.json create mode 100644 tests/helics/test_files/filter_test4.json create mode 100644 tests/helics/test_files/filter_test5.json diff --git a/src/helics/application_api/Federate.cpp b/src/helics/application_api/Federate.cpp index bc1d33281f..1e6fdc844a 100644 --- a/src/helics/application_api/Federate.cpp +++ b/src/helics/application_api/Federate.cpp @@ -1252,12 +1252,10 @@ static Translator& generateTranslator(Federate* fed, } return trans; } - -static Filter& generateFilter(Federate* fed, +static Filter& registerFilter(Federate* fed, bool global, bool cloning, std::string_view name, - FilterTypes operation, std::string_view inputType, std::string_view outputType) { @@ -1271,14 +1269,20 @@ static Filter& generateFilter(Federate* fed, fed->registerFilter(name, inputType, outputType); } if (cloning) { - Filter& filt = - (global) ? fed->registerGlobalCloningFilter(name) : fed->registerCloningFilter(name); - if (operation != FilterTypes::CUSTOM) { - filt.setFilterType(static_cast(operation)); - } - return filt; + return (global) ? fed->registerGlobalCloningFilter(name) : fed->registerCloningFilter(name); } - Filter& filt = (global) ? fed->registerCloningFilter(name) : fed->registerFilter(name); + return (global) ? fed->registerGlobalFilter(name) : fed->registerFilter(name); +} + +static Filter& generateFilter(Federate* fed, + bool global, + bool cloning, + std::string_view name, + FilterTypes operation, + std::string_view inputType, + std::string_view outputType) +{ + auto& filt = registerFilter(fed, global, cloning, name, inputType, outputType); if (operation != FilterTypes::CUSTOM) { filt.setFilterType(static_cast(operation)); } @@ -1436,17 +1440,20 @@ void Federate::registerConnectorInterfacesJsonDetail(const fileops::JsonBuffer& const std::string key = getOrDefault(filt, "name", emptyStr); const std::string inputType = getOrDefault(filt, "inputType", emptyStr); const std::string outputType = getOrDefault(filt, "outputType", emptyStr); - const bool cloningflag = getOrDefault(filt, "cloning", false); + const bool cloningFlag = getOrDefault(filt, "cloning", false); const bool useTypes = !((inputType.empty()) && (outputType.empty())); const bool global = fileops::getOrDefault(filt, "global", defaultGlobal); - const std::string operation = getOrDefault(filt, "operation", std::string("custom")); + const std::string operation = + getOrDefault(filt, + "operation", + (cloningFlag) ? std::string("clone") : std::string("custom")); auto opType = filterTypeFromString(operation); if (!checkValidFilterType(useTypes, opType, operation)) { continue; } auto& filter = - generateFilter(this, global, cloningflag, key, opType, inputType, outputType); + generateFilter(this, global, cloningFlag, key, opType, inputType, outputType); loadOptions(this, filt, filter); addTargetVariations(filt, "source", "endpoints", [&filter](const std::string& target) { @@ -1459,7 +1466,7 @@ void Federate::registerConnectorInterfacesJsonDetail(const fileops::JsonBuffer& filter.addDestinationTarget(target); }); - if (cloningflag) { + if (cloningFlag) { addTargets(filt, "delivery", [&filter](const std::string& target) { static_cast(filter).addDeliveryEndpoint(target); }); diff --git a/src/helics/application_api/Filters.cpp b/src/helics/application_api/Filters.cpp index 7294117e41..4498ea0427 100644 --- a/src/helics/application_api/Filters.cpp +++ b/src/helics/application_api/Filters.cpp @@ -18,6 +18,7 @@ SPDX-License-Identifier: BSD-3-Clause namespace helics { static const std::map filterTypes{ {"clone", FilterTypes::CLONE}, + {"cloning", FilterTypes::CLONE}, {"delay", FilterTypes::DELAY}, {"randomdelay", FilterTypes::RANDOM_DELAY}, {"random_delay", FilterTypes::RANDOM_DELAY}, diff --git a/src/helics/application_api/MessageFederate.cpp b/src/helics/application_api/MessageFederate.cpp index e692a6269d..0493ad9ce5 100644 --- a/src/helics/application_api/MessageFederate.cpp +++ b/src/helics/application_api/MessageFederate.cpp @@ -214,6 +214,12 @@ static void loadOptions(MessageFederate* fed, const Inp& data, Endpoint& ept) addTargetVariations(data, "destination", "endpoints", [&ept](std::string_view endpoint) { ept.addDestinationEndpoint(endpoint); }); + addTargetVariations(data, "source", "targets", [&ept](std::string_view endpoint) { + ept.addSourceEndpoint(endpoint); + }); + addTargetVariations(data, "destination", "targets", [&ept](std::string_view endpoint) { + ept.addDestinationEndpoint(endpoint); + }); addTargets(data, "destFilters", [&ept](std::string_view filt) { ept.addDestinationFilter(filt); }); diff --git a/src/helics/application_api/MessageFederateManager.cpp b/src/helics/application_api/MessageFederateManager.cpp index eee2e97076..20d1d9e4cc 100644 --- a/src/helics/application_api/MessageFederateManager.cpp +++ b/src/helics/application_api/MessageFederateManager.cpp @@ -17,9 +17,9 @@ SPDX-License-Identifier: BSD-3-Clause namespace helics { MessageFederateManager::MessageFederateManager(Core* coreOb, MessageFederate* fed, - LocalFederateId id, + LocalFederateId fedid, bool singleThreaded): - mLocalEndpoints(!singleThreaded), coreObject(coreOb), mFed(fed), fedID(id), + mLocalEndpoints(!singleThreaded), coreObject(coreOb), mFed(fed), fedID(fedid), eptData(!singleThreaded), messageOrder(!singleThreaded) { } @@ -113,11 +113,12 @@ bool MessageFederateManager::hasMessage() const bool MessageFederateManager::hasMessage(const Endpoint& ept) { + bool result{false}; if (ept.dataReference != nullptr) { - auto* eptDat = reinterpret_cast(ept.dataReference); - return (!eptDat->messages.empty()); + auto* eptDat = static_cast(ept.dataReference); + result = (!eptDat->messages.empty()); } - return false; + return result; } /** @@ -126,7 +127,7 @@ bool MessageFederateManager::hasMessage(const Endpoint& ept) uint64_t MessageFederateManager::pendingMessageCount(const Endpoint& ept) { if (ept.dataReference != nullptr) { - auto* eptDat = reinterpret_cast(ept.dataReference); + auto* eptDat = static_cast(ept.dataReference); return eptDat->messages.size(); } return 0; @@ -139,20 +140,25 @@ prefer to just use getMessage until it returns an invalid Message. uint64_t MessageFederateManager::pendingMessageCount() const { auto eptDat = eptData.lock_shared(); - uint64_t sz = 0; + return std::accumulate(eptDat.begin(), eptDat.end(), 0, [](uint64_t count, const auto& ept) { + return count + static_cast(ept.messages.size()); + }); + /* + uint64_t size{ 0 }; for (const auto& mq : eptDat) { - sz += mq.messages.size(); + size = size + mq.messages.size(); } - return sz; + return size; + */ } std::unique_ptr MessageFederateManager::getMessage(const Endpoint& ept) { if (ept.dataReference != nullptr) { auto* eptDat = reinterpret_cast(ept.dataReference); - auto mv = eptDat->messages.pop(); - if (mv) { - return std::move(*mv); + auto message = eptDat->messages.pop(); + if (message) { + return std::move(*message); } } return nullptr; @@ -164,9 +170,9 @@ std::unique_ptr MessageFederateManager::getMessage() auto eptDat = eptData.lock(); for (auto& edat : eptDat) { if (!edat.messages.empty()) { - auto ms = edat.messages.pop(); - if (ms) { - return std::move(*ms); + auto message = edat.messages.pop(); + if (message) { + return std::move(*message); } } } diff --git a/tests/helics/application_api/FilterTests.cpp b/tests/helics/application_api/FilterTests.cpp index 2f549d162b..d32b939f19 100644 --- a/tests/helics/application_api/FilterTests.cpp +++ b/tests/helics/application_api/FilterTests.cpp @@ -57,25 +57,25 @@ TEST_P(filter_single_type_test, message_filter_registration) mFed->registerGlobalEndpoint("port1"); mFed->registerGlobalEndpoint("port2"); - auto& f1 = fFed->registerFilter("filter1"); - f1.addSourceTarget("port1"); - EXPECT_TRUE(f1.getHandle().isValid()); - auto& f2 = fFed->registerFilter("filter2"); - f2.addDestinationTarget("port2"); - EXPECT_TRUE(f2.getHandle().isValid()); - auto& ep1 = fFed->registerEndpoint("fout"); - EXPECT_TRUE(ep1.getHandle().isValid()); + auto& filt1 = fFed->registerFilter("filter1"); + filt1.addSourceTarget("port1"); + EXPECT_TRUE(filt1.getHandle().isValid()); + auto& filt2 = fFed->registerFilter("filter2"); + filt2.addDestinationTarget("port2"); + EXPECT_TRUE(filt2.getHandle().isValid()); + auto& ept1 = fFed->registerEndpoint("fout"); + EXPECT_TRUE(ept1.getHandle().isValid()); mFed->finalizeAsync(); std::this_thread::sleep_for(std::chrono::milliseconds(50)); - auto& f3 = fFed->registerCloningFilter(); - f3.addSourceTarget("filter0/fout"); - f3.addDestinationTarget("port2"); - EXPECT_TRUE(f3.getHandle() != f2.getHandle()); - - auto& f4 = fFed->registerFilter(); - f4.addSourceTarget("filter0/fout"); - EXPECT_TRUE(f4.getHandle() != f3.getHandle()); + auto& filt3 = fFed->registerCloningFilter(); + filt3.addSourceTarget("filter0/fout"); + filt3.addDestinationTarget("port2"); + EXPECT_TRUE(filt3.getHandle() != filt2.getHandle()); + + auto& filt4 = fFed->registerFilter(); + filt4.addSourceTarget("filter0/fout"); + EXPECT_TRUE(filt4.getHandle() != filt3.getHandle()); fFed->finalize(); // std::cout << "fFed returned\n"; mFed->finalizeComplete(); @@ -96,15 +96,15 @@ TEST_P(filter_single_type_test, message_filter_function) auto fFed = GetFederateAs(0); auto mFed = GetFederateAs(1); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto& f1 = fFed->registerFilter("filter1"); - f1.addSourceTarget("port1"); - EXPECT_TRUE(f1.getHandle().isValid()); + auto& filt1 = fFed->registerFilter("filter1"); + filt1.addSourceTarget("port1"); + EXPECT_TRUE(filt1.getHandle().isValid()); auto timeOperator = std::make_shared(); timeOperator->setTimeFunction([](helics::Time time_in) { return time_in + 2.5; }); - fFed->setFilterOperator(f1, timeOperator); + fFed->setFilterOperator(filt1, timeOperator); fFed->enterExecutingModeAsync(); mFed->enterExecutingMode(); @@ -112,7 +112,7 @@ TEST_P(filter_single_type_test, message_filter_function) EXPECT_TRUE(fFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed->requestTimeAsync(1.0); fFed->requestTime(1.0); @@ -121,26 +121,28 @@ TEST_P(filter_single_type_test, message_filter_function) auto res = mFed->hasMessage(); EXPECT_TRUE(!res); if (res) { - auto m3 = mFed->getMessage(p2); + auto message3 = mFed->getMessage(ept2); + (void)(message3); } mFed->requestTimeAsync(2.0); fFed->requestTime(2.0); mFed->requestTimeComplete(); - EXPECT_TRUE(!mFed->hasMessage(p2)); - if (mFed->hasMessage(p2)) { - auto m3 = mFed->getMessage(p2); + EXPECT_TRUE(!mFed->hasMessage(ept2)); + if (mFed->hasMessage(ept2)) { + auto message3 = mFed->getMessage(ept2); + (void)(message3); } fFed->requestTimeAsync(3.0); auto retTime = mFed->requestTime(3.0); EXPECT_EQ(retTime, 3.0); - ASSERT_TRUE(mFed->hasMessage(p2)); + ASSERT_TRUE(mFed->hasMessage(ept2)); - auto m2 = mFed->getMessage(p2); - EXPECT_EQ(m2->source, "port1"); - EXPECT_EQ(m2->original_source, "port1"); - EXPECT_EQ(m2->dest, "port2"); - EXPECT_EQ(m2->data.size(), data.size()); - EXPECT_EQ(m2->time, 2.5); + auto message2 = mFed->getMessage(ept2); + EXPECT_EQ(message2->source, "port1"); + EXPECT_EQ(message2->original_source, "port1"); + EXPECT_EQ(message2->dest, "port2"); + EXPECT_EQ(message2->data.size(), data.size()); + EXPECT_EQ(message2->time, 2.5); mFed->requestTime(3.0); fFed->requestTimeComplete(); @@ -164,8 +166,8 @@ TEST_P(filter_single_type_test, message_filter_object) auto fFed = GetFederateAs(0); auto mFed = GetFederateAs(1); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); auto& Filt = helics::make_filter(helics::FilterTypes::DELAY, fFed.get()); Filt.addSourceTarget("port1"); @@ -177,7 +179,7 @@ TEST_P(filter_single_type_test, message_filter_object) EXPECT_TRUE(fFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed->requestTimeAsync(1.0); fFed->requestTime(1.0); @@ -189,19 +191,19 @@ TEST_P(filter_single_type_test, message_filter_object) mFed->requestTimeAsync(2.0); fFed->requestTime(2.0); mFed->requestTimeComplete(); - ASSERT_TRUE(!mFed->hasMessage(p2)); + ASSERT_TRUE(!mFed->hasMessage(ept2)); fFed->requestTimeAsync(3.0); /*auto retTime = */ mFed->requestTime(3.0); - ASSERT_TRUE(mFed->hasMessage(p2)); + ASSERT_TRUE(mFed->hasMessage(ept2)); - auto m2 = mFed->getMessage(p2); - EXPECT_EQ(m2->source, "port1"); - EXPECT_EQ(m2->original_source, "port1"); - EXPECT_EQ(m2->dest, "port2"); - EXPECT_EQ(m2->data.size(), data.size()); - EXPECT_EQ(m2->time, 2.5); + auto message2 = mFed->getMessage(ept2); + EXPECT_EQ(message2->source, "port1"); + EXPECT_EQ(message2->original_source, "port1"); + EXPECT_EQ(message2->dest, "port2"); + EXPECT_EQ(message2->data.size(), data.size()); + EXPECT_EQ(message2->time, 2.5); mFed->requestTime(3.0); fFed->requestTimeComplete(); @@ -225,15 +227,15 @@ TEST_P(filter_single_type_test, message_dest_filter_function) auto fFed = GetFederateAs(0); auto mFed = GetFederateAs(1); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto& f1 = fFed->registerFilter("filter1"); - f1.addDestinationTarget("port2"); - EXPECT_TRUE(f1.getHandle().isValid()); + auto& filt1 = fFed->registerFilter("filter1"); + filt1.addDestinationTarget("port2"); + EXPECT_TRUE(filt1.getHandle().isValid()); auto timeOperator = std::make_shared(); timeOperator->setTimeFunction([](helics::Time time_in) { return time_in + 2.5; }); - fFed->setFilterOperator(f1, timeOperator); + fFed->setFilterOperator(filt1, timeOperator); fFed->enterExecutingModeAsync(); mFed->enterExecutingMode(); @@ -241,30 +243,30 @@ TEST_P(filter_single_type_test, message_dest_filter_function) EXPECT_TRUE(fFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed->requestTime(1.0); auto res = mFed->hasMessage(); if (res) { - auto m = mFed->getMessage(); + auto message = mFed->getMessage(); EXPECT_TRUE(!res); } mFed->requestTime(2.0); - ASSERT_TRUE(!mFed->hasMessage(p2)); + ASSERT_TRUE(!mFed->hasMessage(ept2)); fFed->requestTimeAsync(3.0); /*auto retTime = */ mFed->requestTime(3.0); - ASSERT_TRUE(mFed->hasMessage(p2)); + ASSERT_TRUE(mFed->hasMessage(ept2)); - auto m2 = mFed->getMessage(p2); - EXPECT_EQ(m2->source, "port1"); - EXPECT_EQ(m2->original_source, "port1"); - EXPECT_EQ(m2->dest, "port2"); - EXPECT_EQ(m2->data.size(), data.size()); - EXPECT_EQ(m2->time, 2.5); + auto message2 = mFed->getMessage(ept2); + EXPECT_EQ(message2->source, "port1"); + EXPECT_EQ(message2->original_source, "port1"); + EXPECT_EQ(message2->dest, "port2"); + EXPECT_EQ(message2->data.size(), data.size()); + EXPECT_EQ(message2->time, 2.5); mFed->requestTime(3.0); fFed->requestTimeComplete(); @@ -281,22 +283,22 @@ simulation TEST_P(filter_single_type_test, message_source_filter_function) { - auto p = GetParam(); - auto broker = AddBroker(p, 2); - AddFederates(p, 2, broker, 0.5, "message"); + auto typeParam = GetParam(); + auto broker = AddBroker(typeParam, 2); + AddFederates(typeParam, 2, broker, 0.5, "message"); auto mFed1 = GetFederateAs(0); auto mFed2 = GetFederateAs(1); - auto& p1 = mFed1->registerGlobalEndpoint("port1"); - auto& p2 = mFed2->registerGlobalEndpoint("port2"); + auto& ept1 = mFed1->registerGlobalEndpoint("port1"); + auto& ept2 = mFed2->registerGlobalEndpoint("port2"); - auto& f1 = mFed2->registerFilter("filter1"); - f1.addSourceTarget("port1"); - EXPECT_TRUE(f1.getHandle().isValid()); + auto& filt1 = mFed2->registerFilter("filter1"); + filt1.addSourceTarget("port1"); + EXPECT_TRUE(filt1.getHandle().isValid()); auto timeOperator = std::make_shared(); timeOperator->setTimeFunction([](helics::Time time_in) { return time_in + 2.5; }); - mFed2->setFilterOperator(f1, timeOperator); + mFed2->setFilterOperator(filt1, timeOperator); mFed1->enterExecutingModeAsync(); mFed2->enterExecutingMode(); @@ -304,7 +306,7 @@ TEST_P(filter_single_type_test, message_source_filter_function) EXPECT_TRUE(mFed2->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed1->requestTimeAsync(1.0); mFed2->requestTimeAsync(1.0); @@ -322,15 +324,15 @@ TEST_P(filter_single_type_test, message_source_filter_function) mFed1->requestTimeAsync(2.0); mFed2->requestTime(2.0); mFed1->requestTimeComplete(); - ASSERT_TRUE(!mFed2->hasMessage(p2)); + ASSERT_TRUE(!mFed2->hasMessage(ept2)); mFed1->requestTimeAsync(3.0); auto retTime = mFed2->requestTime(3.0); EXPECT_TRUE(retTime == 2.5); - ASSERT_TRUE(mFed2->hasMessage(p2)); + ASSERT_TRUE(mFed2->hasMessage(ept2)); - auto m2 = mFed2->getMessage(p2); + auto message2 = mFed2->getMessage(ept2); mFed2->requestTime(3.0); mFed1->requestTimeComplete(); @@ -355,13 +357,13 @@ TEST_P(filter_single_type_test, message_dest_filter_object) auto fFed = GetFederateAs(0); auto mFed = GetFederateAs(1); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto f1 = + auto filt1 = helics::make_filter(helics::FilterTypes::DELAY, fFed->getCorePointer().get(), "filter1"); - f1->addDestinationTarget("port2"); - f1->set("delay", 2.5); + filt1->addDestinationTarget("port2"); + filt1->set("delay", 2.5); fFed->enterExecutingModeAsync(); mFed->enterExecutingMode(); @@ -371,7 +373,7 @@ TEST_P(filter_single_type_test, message_dest_filter_object) EXPECT_TRUE(fFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed->requestTimeAsync(1.0); fFed->requestTime(1.0); @@ -384,19 +386,19 @@ TEST_P(filter_single_type_test, message_dest_filter_object) mFed->requestTimeAsync(2.0); fFed->requestTime(2.0); mFed->requestTimeComplete(); - ASSERT_TRUE(!mFed->hasMessage(p2)); + ASSERT_TRUE(!mFed->hasMessage(ept2)); fFed->requestTimeAsync(3.0); /*auto retTime = */ mFed->requestTime(3.0); - ASSERT_TRUE(mFed->hasMessage(p2)); + ASSERT_TRUE(mFed->hasMessage(ept2)); - auto m2 = mFed->getMessage(p2); - EXPECT_EQ(m2->source, "port1"); - EXPECT_EQ(m2->original_source, "port1"); - EXPECT_EQ(m2->dest, "port2"); - EXPECT_EQ(m2->data.size(), data.size()); - EXPECT_EQ(m2->time, 2.5); + auto message2 = mFed->getMessage(ept2); + EXPECT_EQ(message2->source, "port1"); + EXPECT_EQ(message2->original_source, "port1"); + EXPECT_EQ(message2->dest, "port2"); + EXPECT_EQ(message2->data.size(), data.size()); + EXPECT_EQ(message2->time, 2.5); mFed->requestTime(3.0); fFed->requestTimeComplete(); @@ -411,20 +413,20 @@ TEST_P(filter_single_type_test, message_dest_filter_object) EXPECT_TRUE(!mCore->isConnected()); } -static bool two_stage_filter_test(std::shared_ptr& mFed, - std::shared_ptr& fFed1, - std::shared_ptr& fFed2, - helics::Endpoint& p1, - helics::Endpoint& p2, - helics::Filter& f1, - helics::Filter& f2) +static bool twoStageFilterTest(std::shared_ptr& mFed, + std::shared_ptr& fFed1, + std::shared_ptr& fFed2, + helics::Endpoint& ept1, + helics::Endpoint& ept2, + helics::Filter& filt1, + helics::Filter& filt2) { bool correct = true; auto timeOperator = std::make_shared(); timeOperator->setTimeFunction([](helics::Time time_in) { return time_in + 1.25; }); - fFed1->setFilterOperator(f1, timeOperator); - fFed2->setFilterOperator(f2, timeOperator); + fFed1->setFilterOperator(filt1, timeOperator); + fFed2->setFilterOperator(filt2, timeOperator); fFed1->enterExecutingModeAsync(); fFed2->enterExecutingModeAsync(); @@ -432,10 +434,10 @@ static bool two_stage_filter_test(std::shared_ptr& mFed fFed1->enterExecutingModeComplete(); fFed2->enterExecutingModeComplete(); - auto& p2Name = p2.getName(); + auto& p2Name = ept2.getName(); EXPECT_TRUE(fFed1->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, p2Name); + ept1.sendTo(data, p2Name); mFed->requestTimeAsync(1.0); fFed1->requestTimeAsync(1.0); @@ -453,28 +455,28 @@ static bool two_stage_filter_test(std::shared_ptr& mFed fFed1->requestTime(2.0); mFed->requestTimeComplete(); fFed2->requestTimeComplete(); - if (mFed->hasMessage(p2)) { + if (mFed->hasMessage(ept2)) { correct = false; } fFed1->requestTimeAsync(3.0); fFed2->requestTimeAsync(3.0); /*auto retTime = */ mFed->requestTime(3.0); - if (!mFed->hasMessage(p2)) { + if (!mFed->hasMessage(ept2)) { printf("missing message\n"); correct = false; } - if (mFed->hasMessage(p2)) { - auto m2 = mFed->getMessage(p2); - const auto& ept1Name = p1.getName(); + if (mFed->hasMessage(ept2)) { + auto message2 = mFed->getMessage(ept2); + const auto& ept1Name = ept1.getName(); if (ept1Name.size() > 1) { - EXPECT_EQ(m2->source, p1.getName()); - EXPECT_EQ(m2->original_source, p1.getName()); + EXPECT_EQ(message2->source, ept1.getName()); + EXPECT_EQ(message2->original_source, ept1.getName()); } - EXPECT_EQ(m2->dest, p2Name); - EXPECT_EQ(m2->data.size(), data.size()); - EXPECT_EQ(m2->time, 2.5); + EXPECT_EQ(message2->dest, p2Name); + EXPECT_EQ(message2->data.size(), data.size()); + EXPECT_EQ(message2->time, 2.5); } fFed1->requestTimeComplete(); @@ -515,18 +517,18 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage) auto fFed2 = GetFederateAs(1); auto mFed = GetFederateAs(2); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto& f1 = fFed->registerFilter("filter1"); - f1.addSourceTarget("port1"); - EXPECT_TRUE(f1.getHandle().isValid()); + auto& filt1 = fFed->registerFilter("filter1"); + filt1.addSourceTarget("port1"); + EXPECT_TRUE(filt1.getHandle().isValid()); - auto& f2 = fFed2->registerFilter("filter2"); - f2.addSourceTarget("port1"); - EXPECT_TRUE(f2.getHandle().isValid()); + auto& filt2 = fFed2->registerFilter("filter2"); + filt2.addSourceTarget("port1"); + EXPECT_TRUE(filt2.getHandle().isValid()); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -542,20 +544,20 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage_endpoint_targe auto fFed2 = GetFederateAs(1); auto mFed = GetFederateAs(2); - auto& p1 = mFed->registerEndpoint(); - auto& p2 = mFed->registerGlobalEndpoint("port2"); - p1.addSourceFilter("filter1"); - p1.addSourceFilter("filter2"); + auto& ept1 = mFed->registerEndpoint(); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); + ept1.addSourceFilter("filter1"); + ept1.addSourceFilter("filter2"); - auto& f1 = fFed->registerGlobalFilter("filter1"); + auto& filt1 = fFed->registerGlobalFilter("filter1"); - EXPECT_TRUE(f1.getHandle().isValid()); + EXPECT_TRUE(filt1.getHandle().isValid()); - auto& f2 = fFed2->registerGlobalFilter("filter2"); + auto& filt2 = fFed2->registerGlobalFilter("filter2"); - EXPECT_TRUE(f2.getHandle().isValid()); + EXPECT_TRUE(filt2.getHandle().isValid()); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -573,20 +575,20 @@ TEST_F(filter, message_filter_function_two_stage_endpoint_target_alias) fFed2->addAlias("filter1", "filterA"); broker->addAlias("filter2", "filterB"); - auto& p1 = mFed->registerEndpoint(); - auto& p2 = mFed->registerGlobalEndpoint("port2"); - p1.addSourceFilter("filterA"); - p1.addSourceFilter("filterB"); + auto& ept1 = mFed->registerEndpoint(); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); + ept1.addSourceFilter("filterA"); + ept1.addSourceFilter("filterB"); - auto& f1 = fFed->registerGlobalFilter("filter1"); + auto& filt1 = fFed->registerGlobalFilter("filter1"); - EXPECT_TRUE(f1.getHandle().isValid()); + EXPECT_TRUE(filt1.getHandle().isValid()); - auto& f2 = fFed2->registerGlobalFilter("filter2"); + auto& filt2 = fFed2->registerGlobalFilter("filter2"); - EXPECT_TRUE(f2.getHandle().isValid()); + EXPECT_TRUE(filt2.getHandle().isValid()); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -602,21 +604,21 @@ TEST_F(filter, message_filter_function_two_stage_endpoint_target_alias_regex) auto fFed2 = GetFederateAs(1); auto mFed = GetFederateAs(2); - fFed2->addAlias("ff11", "fBBBEA"); - broker->addAlias("ff22", "fBBBEB"); - auto& p1 = mFed->registerEndpoint(); - auto& p2 = mFed->registerGlobalEndpoint("port2"); - p1.addSourceFilter("REGEX:fBBBE."); + fFed2->addAlias("ffilt11", "fBBBEA"); + broker->addAlias("ffilt22", "fBBBEB"); + auto& ept1 = mFed->registerEndpoint(); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); + ept1.addSourceFilter("REGEX:fBBBE."); - auto& f1 = fFed->registerGlobalFilter("ff11"); + auto& filt1 = fFed->registerGlobalFilter("ffilt11"); - EXPECT_TRUE(f1.getHandle().isValid()); + EXPECT_TRUE(filt1.getHandle().isValid()); - auto& f2 = fFed2->registerGlobalFilter("ff22"); + auto& filt2 = fFed2->registerGlobalFilter("ffilt22"); - EXPECT_TRUE(f2.getHandle().isValid()); + EXPECT_TRUE(filt2.getHandle().isValid()); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -633,20 +635,20 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage_endpoint_targe auto mFed = GetFederateAs(2); // nameless endpoint - auto& p1 = mFed->registerEndpoint(); - auto& p2 = mFed->registerGlobalEndpoint("port2"); - p1.addSourceFilter("filter1"); - p2.addDestinationFilter("filter2"); + auto& ept1 = mFed->registerEndpoint(); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); + ept1.addSourceFilter("filter1"); + ept2.addDestinationFilter("filter2"); - auto& f1 = fFed->registerGlobalFilter("filter1"); + auto& filt1 = fFed->registerGlobalFilter("filter1"); - EXPECT_TRUE(f1.getHandle().isValid()); + EXPECT_TRUE(filt1.getHandle().isValid()); - auto& f2 = fFed2->registerGlobalFilter("filter2"); + auto& filt2 = fFed2->registerGlobalFilter("filter2"); - EXPECT_TRUE(f2.getHandle().isValid()); + EXPECT_TRUE(filt2.getHandle().isValid()); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -661,22 +663,22 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage_broker_filter_ auto fFed2 = GetFederateAs(1); auto mFed = GetFederateAs(2); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); std::this_thread::sleep_for(std::chrono::milliseconds(200)); broker->addSourceFilterToEndpoint("filter1", "port1"); broker->addDestinationFilterToEndpoint("filter2", "port2"); - auto& f1 = fFed->registerGlobalFilter("filter1"); + auto& filt1 = fFed->registerGlobalFilter("filter1"); - EXPECT_TRUE(f1.getHandle().isValid()); + EXPECT_TRUE(filt1.getHandle().isValid()); - auto& f2 = fFed2->registerGlobalFilter("filter2"); + auto& filt2 = fFed2->registerGlobalFilter("filter2"); - EXPECT_TRUE(f2.getHandle().isValid()); + EXPECT_TRUE(filt2.getHandle().isValid()); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -691,23 +693,23 @@ TEST_F(filter, message_filter_function_two_stage_brokerApp_filter_link) auto fFed2 = GetFederateAs(1); auto mFed = GetFederateAs(2); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); std::this_thread::sleep_for(std::chrono::milliseconds(200)); helics::BrokerApp brk(broker); brk.addSourceFilterToEndpoint("filter1", "port1"); brk.addDestinationFilterToEndpoint("filter2", "port2"); - auto& f1 = fFed->registerGlobalFilter("filter1"); + auto& filt1 = fFed->registerGlobalFilter("filter1"); - EXPECT_TRUE(f1.getHandle().isValid()); + EXPECT_TRUE(filt1.getHandle().isValid()); - auto& f2 = fFed2->registerGlobalFilter("filter2"); + auto& filt2 = fFed2->registerGlobalFilter("filter2"); - EXPECT_TRUE(f2.getHandle().isValid()); + EXPECT_TRUE(filt2.getHandle().isValid()); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } #ifdef HELICS_ENABLE_ZMQ_CORE @@ -728,31 +730,31 @@ TEST_F(filter, reroute_separate) auto rec = GetFederateAs(1); auto filt = GetFederateAs(2); - auto& p1 = send->registerGlobalEndpoint("send"); - auto& p2 = rec->registerGlobalEndpoint("rec"); - p1.setDefaultDestination("rec"); - auto& p3 = filt->registerGlobalEndpoint("reroute"); + auto& ept1 = send->registerGlobalEndpoint("send"); + auto& ept2 = rec->registerGlobalEndpoint("rec"); + ept1.setDefaultDestination("rec"); + auto& reroute1 = filt->registerGlobalEndpoint("reroute"); - auto& f1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); + auto& filt1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); - f1.addSourceTarget("send"); - f1.setString("newdestination", "reroute"); + filt1.addSourceTarget("send"); + filt1.setString("newdestination", "reroute"); - auto act1 = [&p1, &send]() { + auto act1 = [&ept1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - p1.send("this is a message"); - tr = send->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + ept1.send("this is a message"); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; int cntb{0}; auto act2 = [&rec, &cntb]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); if (rec->hasMessage()) { ++cntb; } @@ -760,24 +762,24 @@ TEST_F(filter, reroute_separate) rec->finalize(); }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); int cnt{0}; filt->enterExecutingMode(); - helics::Time tr = helics::timeZero; + helics::Time requestTime = helics::timeZero; helics::Time ptr = helics::timeZero; - while (tr < 20.0) { - tr = filt->requestTime(21.0); - if (tr < 20.0) { - EXPECT_EQ(tr - ptr, 1.0); - ptr = tr; + while (requestTime < 20.0) { + requestTime = filt->requestTime(21.0); + if (requestTime < 20.0) { + EXPECT_EQ(requestTime - ptr, 1.0); + ptr = requestTime; } ++cnt; } - t1.join(); - t2.join(); - EXPECT_EQ(p2.pendingMessageCount(), 0U); - EXPECT_EQ(p3.pendingMessageCount(), 10U); + thread1.join(); + thread2.join(); + EXPECT_EQ(ept2.pendingMessageCount(), 0U); + EXPECT_EQ(reroute1.pendingMessageCount(), 10U); EXPECT_EQ(cnt, 11); EXPECT_EQ(cntb, 0); filt->finalize(); @@ -794,47 +796,47 @@ TEST_F(filter, many_filters) auto send = GetFederateAs(0); auto rec = GetFederateAs(1); - auto& p1 = send->registerGlobalEndpoint("send"); - auto& p2 = rec->registerGlobalEndpoint("rec"); - p1.setDefaultDestination("rec"); + auto& ept1 = send->registerGlobalEndpoint("send"); + auto& ept2 = rec->registerGlobalEndpoint("rec"); + ept1.setDefaultDestination("rec"); std::vector> filterFeds; for (int ii = 0; ii < 18; ++ii) { auto filt = GetFederateAs(2 + ii); - auto& f1 = filt->registerFilter("f1"); - auto op = std::make_shared(); - op->setDataFunction([ii](helics::SmallBuffer& db) { db.push_back('a' + ii); }); - f1.setOperator(op); - f1.addSourceTarget("send"); + auto& filt1 = filt->registerFilter("filt1"); + auto dataOp = std::make_shared(); + dataOp->setDataFunction([ii](helics::SmallBuffer& buffer) { buffer.push_back('a' + ii); }); + filt1.setOperator(dataOp); + filt1.addSourceTarget("send"); filterFeds.push_back(std::move(filt)); } - auto act1 = [&p1, &send]() { + auto act1 = [&ept1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - p1.send("this is a message"); - tr = send->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + ept1.send("this is a message"); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; int cntb{0}; - auto act2 = [&rec, &cntb, &p2]() { + auto act2 = [&rec, &cntb, &ept2]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); - if (p2.hasMessage()) { + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); + if (ept2.hasMessage()) { ++cntb; - auto m = p2.getMessage(); - EXPECT_EQ(m->data.size(), 17U + 18U); + auto message = ept2.getMessage(); + EXPECT_EQ(message->data.size(), 17U + 18U); } } rec->finalize(); }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); for (auto& ffed : filterFeds) { ffed->enterExecutingModeAsync(); @@ -844,9 +846,9 @@ TEST_F(filter, many_filters) ffed->requestTimeAsync(50); } - t1.join(); - t2.join(); - EXPECT_EQ(p2.pendingMessageCount(), 0U); + thread1.join(); + thread2.join(); + EXPECT_EQ(ept2.pendingMessageCount(), 0U); EXPECT_EQ(cntb, 10); for (auto& ffed : filterFeds) { @@ -865,50 +867,50 @@ TEST_F(filter, many_filters_multi) auto send = GetFederateAs(0); auto rec = GetFederateAs(1); - auto& p1 = send->registerGlobalEndpoint("send"); - auto& p2 = rec->registerGlobalEndpoint("rec"); - p1.setDefaultDestination("rec"); + auto& ept1 = send->registerGlobalEndpoint("send"); + auto& ept2 = rec->registerGlobalEndpoint("rec"); + ept1.setDefaultDestination("rec"); std::vector> filterFeds; for (int ii = 0; ii < 8; ++ii) { auto filt = GetFederateAs(2 + ii); - auto& f1 = filt->registerFilter("f1"); - auto op = std::make_shared(); - op->setDataFunction([ii](helics::SmallBuffer& db) { db.push_back('a' + ii); }); - f1.setOperator(op); - f1.addSourceTarget("send"); + auto& filt1 = filt->registerFilter("filt1"); + auto dataOp = std::make_shared(); + dataOp->setDataFunction([ii](helics::SmallBuffer& buffer) { buffer.push_back('a' + ii); }); + filt1.setOperator(dataOp); + filt1.addSourceTarget("send"); filterFeds.push_back(std::move(filt)); } - auto act1 = [&p1, &send]() { + auto act1 = [&ept1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - p1.send("this is a message1"); - p1.send("this is a message2"); - p1.send("this is a message3"); - p1.send("this is a message4"); - tr = send->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + ept1.send("this is a message1"); + ept1.send("this is a message2"); + ept1.send("this is a message3"); + ept1.send("this is a message4"); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; int cntb{0}; - auto act2 = [&rec, &cntb, &p2]() { + auto act2 = [&rec, &cntb, &ept2]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); - while (p2.hasMessage()) { + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); + while (ept2.hasMessage()) { ++cntb; - auto m = p2.getMessage(); - EXPECT_EQ(m->data.size(), 18U + 8U); + auto message = ept2.getMessage(); + EXPECT_EQ(message->data.size(), 18U + 8U); } } rec->finalize(); }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); for (auto& ffed : filterFeds) { ffed->enterExecutingModeAsync(); @@ -918,9 +920,9 @@ TEST_F(filter, many_filters_multi) ffed->requestTimeAsync(50); } - t1.join(); - t2.join(); - EXPECT_EQ(p2.pendingMessageCount(), 0U); + thread1.join(); + thread2.join(); + EXPECT_EQ(ept2.pendingMessageCount(), 0U); EXPECT_EQ(cntb, 40); for (auto& ffed : filterFeds) { @@ -940,60 +942,60 @@ TEST_F(filter, reroute_cascade) auto send = GetFederateAs(0); auto rec = GetFederateAs(1); - auto& s1 = send->registerGlobalEndpoint("send"); - auto& r1 = rec->registerGlobalEndpoint("rec1"); - auto& r2 = rec->registerGlobalEndpoint("rec2"); - auto& r3 = rec->registerGlobalEndpoint("rec3"); - auto& r4 = rec->registerGlobalEndpoint("rec4"); - auto& r5 = rec->registerGlobalEndpoint("rec5"); - auto& r6 = rec->registerGlobalEndpoint("rec6"); - auto& r7 = rec->registerGlobalEndpoint("rec7"); - auto& r8 = rec->registerGlobalEndpoint("rec8"); - auto& r9 = rec->registerGlobalEndpoint("rec9"); - s1.setDefaultDestination("rec1"); + auto& send1 = send->registerGlobalEndpoint("send"); + auto& rec1 = rec->registerGlobalEndpoint("rec1"); + auto& rec2 = rec->registerGlobalEndpoint("rec2"); + auto& rec3 = rec->registerGlobalEndpoint("rec3"); + auto& rec4 = rec->registerGlobalEndpoint("rec4"); + auto& rec5 = rec->registerGlobalEndpoint("rec5"); + auto& rec6 = rec->registerGlobalEndpoint("rec6"); + auto& rec7 = rec->registerGlobalEndpoint("rec7"); + auto& rec8 = rec->registerGlobalEndpoint("rec8"); + auto& rec9 = rec->registerGlobalEndpoint("rec9"); + send1.setDefaultDestination("rec1"); std::vector> filterFeds; std::vector filters; for (int ii = 0; ii < 8; ++ii) { auto filt = GetFederateAs(2 + ii); - auto& f1 = helics::make_filter(helics::FilterTypes::REROUTE, - filt.get(), - std::string("rrfilt") + std::to_string(ii)); - f1.addDestinationTarget(std::string("rec") + std::to_string(ii + 1)); - f1.setString("newdestination", std::string("rec") + std::to_string(ii + 2)); - filters.push_back(f1); + auto& filt1 = helics::make_filter(helics::FilterTypes::REROUTE, + filt.get(), + std::string("rrfilt") + std::to_string(ii)); + filt1.addDestinationTarget(std::string("rec") + std::to_string(ii + 1)); + filt1.setString("newdestination", std::string("rec") + std::to_string(ii + 2)); + filters.push_back(filt1); filterFeds.push_back(std::move(filt)); } - auto act1 = [&s1, &send]() { + auto act1 = [&send1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - s1.send("this is a message1"); - s1.send("this is a message2"); - s1.send("this is a message3"); - s1.send("this is a message4"); - tr = send->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + send1.send("this is a message1"); + send1.send("this is a message2"); + send1.send("this is a message3"); + send1.send("this is a message4"); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; int cntb{0}; - auto act2 = [&rec, &cntb, &r9]() { + auto act2 = [&rec, &cntb, &rec9]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); - while (r9.hasMessage()) { + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); + while (rec9.hasMessage()) { ++cntb; - auto m = r9.getMessage(); - EXPECT_EQ(m->data.size(), 18U); + auto message = rec9.getMessage(); + EXPECT_EQ(message->data.size(), 18U); } } rec->finalize(); }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); for (auto& ffed : filterFeds) { ffed->enterExecutingModeAsync(); @@ -1003,16 +1005,16 @@ TEST_F(filter, reroute_cascade) ffed->requestTimeAsync(50); } - t1.join(); - t2.join(); - EXPECT_EQ(r1.pendingMessageCount(), 0U); - EXPECT_EQ(r2.pendingMessageCount(), 0U); - EXPECT_EQ(r3.pendingMessageCount(), 0U); - EXPECT_EQ(r4.pendingMessageCount(), 0U); - EXPECT_EQ(r5.pendingMessageCount(), 0U); - EXPECT_EQ(r6.pendingMessageCount(), 0U); - EXPECT_EQ(r7.pendingMessageCount(), 0U); - EXPECT_EQ(r8.pendingMessageCount(), 0U); + thread1.join(); + thread2.join(); + EXPECT_EQ(rec1.pendingMessageCount(), 0U); + EXPECT_EQ(rec2.pendingMessageCount(), 0U); + EXPECT_EQ(rec3.pendingMessageCount(), 0U); + EXPECT_EQ(rec4.pendingMessageCount(), 0U); + EXPECT_EQ(rec5.pendingMessageCount(), 0U); + EXPECT_EQ(rec6.pendingMessageCount(), 0U); + EXPECT_EQ(rec7.pendingMessageCount(), 0U); + EXPECT_EQ(rec8.pendingMessageCount(), 0U); EXPECT_EQ(cntb, 40); for (auto& ffed : filterFeds) { @@ -1021,40 +1023,40 @@ TEST_F(filter, reroute_cascade) } } -class rfcheck { +class RecFilterCheck { private: - std::thread id; + std::thread thread; std::shared_ptr mFed; int mIndex{0}; public: int mCnt{0}; - rfcheck() = default; - rfcheck(std::shared_ptr fed, int index): + RecFilterCheck() = default; + RecFilterCheck(std::shared_ptr fed, int index): mFed(std::move(fed)), mIndex(index) { } void run() { - auto& r1 = mFed->registerGlobalEndpoint(std::string("rec") + std::to_string(mIndex)); - auto act1 = [this, &r1]() { + auto& rec1 = mFed->registerGlobalEndpoint(std::string("rec") + std::to_string(mIndex)); + auto act1 = [this, &rec1]() { mFed->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = mFed->requestTimeAdvance(1.0); - while (r1.hasMessage()) { + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = mFed->requestTimeAdvance(1.0); + while (rec1.hasMessage()) { ++mCnt; - auto m = r1.getMessage(); - EXPECT_EQ(m->data.size(), 18U); + auto message = rec1.getMessage(); + EXPECT_EQ(message->data.size(), 18U); } } mFed->finalize(); }; - id = std::thread(act1); + thread = std::thread(act1); } - void join() { id.join(); } + void join() { thread.join(); } }; /** this test case fails as of yet with no good path to resolving it yet*/ @@ -1081,28 +1083,28 @@ TEST_F(filter, reroute_cascade_2_ci_skip) std::vector filters; for (int ii = 0; ii < 8; ++ii) { auto filt = GetFederateAs(10 + ii); - auto& f1 = helics::make_filter(helics::FilterTypes::REROUTE, + auto& filt1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), std::string("rrfilt") + std::to_string(ii)); - f1.addDestinationTarget(std::string("rec") + std::to_string(ii + 1)); - f1.setString("newdestination", std::string("rec") + std::to_string(ii + 2)); - filters.push_back(f1); + filt1.addDestinationTarget(std::string("rec") + std::to_string(ii + 1)); + filt1.setString("newdestination", std::string("rec") + std::to_string(ii + 2)); + filters.push_back(filt1); filterFeds.push_back(std::move(filt)); } auto acts = [&s1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { s1.send("this is a message1"); s1.send("this is a message2"); s1.send("this is a message3"); s1.send("this is a message4"); - tr = send->requestTimeAdvance(1.0); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; - auto t1 = std::thread(acts); + auto thread1 = std::thread(acts); for (auto& rfed : recFeds) { rfed.run(); @@ -1115,10 +1117,10 @@ TEST_F(filter, reroute_cascade_2_ci_skip) ffed->requestTimeAsync(50); } - helics::Time tr = helics::timeZero; + helics::Time requestTime = helics::timeZero; helics::Time ptr = helics::timeZero; - t1.join(); + thread1.join(); for (auto& rfed : recFeds) { rfed.join(); @@ -1153,31 +1155,31 @@ TEST_F(filter, reroute_separate2) auto rec = GetFederateAs(1); auto filt = GetFederateAs(2); - auto& p1 = send->registerGlobalEndpoint("send"); - auto& p2 = rec->registerGlobalEndpoint("rec"); - p1.setDefaultDestination("rec"); - auto& p3 = filt->registerGlobalEndpoint("reroute"); + auto& ept1 = send->registerGlobalEndpoint("send"); + auto& ept2 = rec->registerGlobalEndpoint("rec"); + ept1.setDefaultDestination("rec"); + auto& reroute1 = filt->registerGlobalEndpoint("reroute"); - auto& f1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); + auto& filt1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); - f1.addSourceTarget("send"); - f1.setString("newdestination", "reroute"); + filt1.addSourceTarget("send"); + filt1.setString("newdestination", "reroute"); - auto act1 = [&p1, &send]() { + auto act1 = [&ept1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - p1.send("this is a message"); - tr = send->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + ept1.send("this is a message"); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; auto act2 = [&rec]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); } rec->finalize(); }; @@ -1185,27 +1187,27 @@ TEST_F(filter, reroute_separate2) int cnt{0}; auto act3 = [&filt, &cnt]() { filt->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 20.0) { - tr = filt->requestTime(helics::Time::maxVal()); + helics::Time requestTime = helics::timeZero; + while (requestTime < 20.0) { + requestTime = filt->requestTime(helics::Time::maxVal()); ++cnt; } }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); - auto t3 = std::thread(act3); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); + auto thread3 = std::thread(act3); - t1.join(); - t2.join(); + thread1.join(); + thread2.join(); // std::this_thread::sleep_for(std::chrono::milliseconds(2000)); // auto res = broker->query("root", "global_time_debugging"); - t3.join(); + thread3.join(); filt->finalize(); - EXPECT_EQ(p2.pendingMessageCount(), 0U); - EXPECT_EQ(p3.pendingMessageCount(), 10U); + EXPECT_EQ(ept2.pendingMessageCount(), 0U); + EXPECT_EQ(reroute1.pendingMessageCount(), 10U); EXPECT_EQ(cnt, 11); // auto res2 = broker->query("root", "global_time_debugging"); broker->waitForDisconnect(); @@ -1223,48 +1225,48 @@ TEST_F(filter, reroute_separate3) auto rec = GetFederateAs(1); auto filt = GetFederateAs(2); - auto& p1 = send->registerGlobalEndpoint("send"); - auto& p2 = rec->registerGlobalEndpoint("rec"); - p1.setDefaultDestination("rec"); - auto& p3 = filt->registerGlobalEndpoint("reroute"); + auto& ept1 = send->registerGlobalEndpoint("send"); + auto& ept2 = rec->registerGlobalEndpoint("rec"); + ept1.setDefaultDestination("rec"); + auto& reroute1 = filt->registerGlobalEndpoint("reroute"); - auto& f1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); + auto& filt1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); - f1.addSourceTarget("send"); - f1.setString("newdestination", "reroute"); + filt1.addSourceTarget("send"); + filt1.setString("newdestination", "reroute"); - auto act1 = [&p1, &send]() { + auto act1 = [&ept1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - p1.send("this is a message"); - tr = send->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + ept1.send("this is a message"); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; auto act2 = [&rec]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); } rec->finalize(); }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); int cnt{0}; filt->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 20.0) { - tr = filt->requestTime(helics::Time::maxVal()); + helics::Time requestTime = helics::timeZero; + while (requestTime < 20.0) { + requestTime = filt->requestTime(helics::Time::maxVal()); ++cnt; } - t1.join(); - t2.join(); - EXPECT_EQ(p2.pendingMessageCount(), 0U); - EXPECT_EQ(p3.pendingMessageCount(), 10U); + thread1.join(); + thread2.join(); + EXPECT_EQ(ept2.pendingMessageCount(), 0U); + EXPECT_EQ(reroute1.pendingMessageCount(), 10U); EXPECT_EQ(cnt, 11); filt->finalize(); } @@ -1282,31 +1284,31 @@ TEST_F(filter, reroute_separate_dest_target) send->setProperty(HELICS_PROPERTY_TIME_GRANT_TIMEOUT, 1.0); rec->setProperty(HELICS_PROPERTY_TIME_GRANT_TIMEOUT, 1.0); filt->setProperty(HELICS_PROPERTY_TIME_GRANT_TIMEOUT, 1.0); - auto& p1 = send->registerGlobalEndpoint("send"); - auto& p2 = rec->registerGlobalEndpoint("rec"); - p1.setDefaultDestination("rec"); - auto& p3 = filt->registerGlobalEndpoint("reroute"); + auto& ept1 = send->registerGlobalEndpoint("send"); + auto& ept2 = rec->registerGlobalEndpoint("rec"); + ept1.setDefaultDestination("rec"); + auto& reroute1 = filt->registerGlobalEndpoint("reroute"); - auto& f1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); + auto& filt1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); - f1.addDestinationTarget("rec"); - f1.setString("newdestination", "reroute"); + filt1.addDestinationTarget("rec"); + filt1.setString("newdestination", "reroute"); - auto act1 = [&p1, &send]() { + auto act1 = [&ept1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - p1.send("this is a message"); - tr = send->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + ept1.send("this is a message"); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; int cntb{0}; auto act2 = [&rec, &cntb]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); if (rec->hasMessage()) { ++cntb; } @@ -1314,22 +1316,22 @@ TEST_F(filter, reroute_separate_dest_target) rec->finalize(); }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); int cnt{0}; filt->enterExecutingMode(); - std::vector tm; - tm.reserve(12); - helics::Time tr = helics::timeZero; - while (tr < 20.0) { - tr = filt->requestTime(21.0); + std::vector timeVector; + timeVector.reserve(12); + helics::Time requestTime = helics::timeZero; + while (requestTime < 20.0) { + requestTime = filt->requestTime(21.0); ++cnt; - tm.emplace_back(tr); + timeVector.emplace_back(requestTime); } - t1.join(); - t2.join(); - EXPECT_EQ(p2.pendingMessageCount(), 0U); - EXPECT_EQ(p3.pendingMessageCount(), 10U); + thread1.join(); + thread2.join(); + EXPECT_EQ(ept2.pendingMessageCount(), 0U); + EXPECT_EQ(reroute1.pendingMessageCount(), 10U); EXPECT_EQ(cnt, 10); if (cnt == 11) { EXPECT_EQ(cnt, 10); @@ -1349,28 +1351,28 @@ TEST_F(filter, separate_slow_filter_ci_skip) auto rec = GetFederateAs(1); auto filt = GetFederateAs(2); - auto& p1 = send->registerGlobalEndpoint("send"); + auto& ept1 = send->registerGlobalEndpoint("send"); rec->registerGlobalEndpoint("rec"); - p1.setDefaultDestination("rec"); + ept1.setDefaultDestination("rec"); - auto& f1 = helics::make_filter(helics::FilterTypes::CUSTOM, filt.get(), "rrfilt"); + auto& filt1 = helics::make_filter(helics::FilterTypes::CUSTOM, filt.get(), "rrfilt"); - auto op = std::make_shared(); - auto mop = [](std::unique_ptr m) { + auto customOp = std::make_shared(); + auto mop = [](std::unique_ptr message) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); - m->data.append("bb"); - return m; + message->data.append("bb"); + return message; }; - op->setMessageFunction(mop); - f1.setOperator(op); - f1.addSourceTarget("send"); - auto act1 = [&p1, &send]() { + customOp->setMessageFunction(mop); + filt1.setOperator(customOp); + filt1.addSourceTarget("send"); + auto act1 = [&ept1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - p1.send("this is a message"); - tr = send->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + ept1.send("this is a message"); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; @@ -1378,28 +1380,28 @@ TEST_F(filter, separate_slow_filter_ci_skip) int mcnt{0}; auto act2 = [&rec, &cntb, &mcnt]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); ++cntb; while (rec->hasMessage()) { ++mcnt; - auto m = rec->getMessage(); - EXPECT_EQ(m->data.to_string().back(), 'b'); + auto message = rec->getMessage(); + EXPECT_EQ(message->data.to_string().back(), 'b'); } } rec->finalize(); }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); filt->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 20.0) { - tr = filt->requestTime(21.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 20.0) { + requestTime = filt->requestTime(21.0); } - t1.join(); - t2.join(); + thread1.join(); + thread2.join(); EXPECT_EQ(mcnt, 10); EXPECT_EQ(cntb, 10); filt->finalize(); @@ -1416,28 +1418,28 @@ TEST_F(filter, separate_slow_dest_filter_ci_skip) auto rec = GetFederateAs(1); auto filt = GetFederateAs(2); - auto& p1 = send->registerGlobalEndpoint("send"); + auto& ept1 = send->registerGlobalEndpoint("send"); rec->registerGlobalEndpoint("rec"); - p1.setDefaultDestination("rec"); + ept1.setDefaultDestination("rec"); - auto& f1 = helics::make_filter(helics::FilterTypes::CUSTOM, filt.get(), "rrfilt"); + auto& filt1 = helics::make_filter(helics::FilterTypes::CUSTOM, filt.get(), "rrfilt"); - auto op = std::make_shared(); - auto mop = [](std::unique_ptr m) { + auto customOp = std::make_shared(); + auto mop = [](std::unique_ptr message) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); - m->data.append("bb"); - return m; + message->data.append("bb"); + return message; }; - op->setMessageFunction(mop); - f1.setOperator(op); - f1.addDestinationTarget("rec"); - auto act1 = [&p1, &send]() { + customOp->setMessageFunction(mop); + filt1.setOperator(customOp); + filt1.addDestinationTarget("rec"); + auto act1 = [&ept1, &send]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - p1.send("this is a message"); - tr = send->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + ept1.send("this is a message"); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; @@ -1445,28 +1447,28 @@ TEST_F(filter, separate_slow_dest_filter_ci_skip) int mcnt{0}; auto act2 = [&rec, &cntb, &mcnt]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); ++cntb; while (rec->hasMessage()) { ++mcnt; - auto m = rec->getMessage(); - EXPECT_EQ(m->data.to_string().back(), 'b'); + auto message = rec->getMessage(); + EXPECT_EQ(message->data.to_string().back(), 'b'); } } rec->finalize(); }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); filt->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 20.0) { - tr = filt->requestTime(21.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 20.0) { + requestTime = filt->requestTime(21.0); } - t1.join(); - t2.join(); + thread1.join(); + thread2.join(); EXPECT_EQ(mcnt, 10); EXPECT_EQ(cntb, 10); filt->finalize(); @@ -1484,58 +1486,58 @@ TEST_F(filter, reroute_separate2_5message_nocov) auto rec = GetFederateAs(1); auto filt = GetFederateAs(2); - auto& s1 = send->registerGlobalEndpoint("send1"); - auto& s2 = send->registerGlobalEndpoint("send2"); - auto& s3 = send->registerGlobalEndpoint("send3"); - auto& s4 = send->registerGlobalEndpoint("send4"); - auto& s5 = send->registerGlobalEndpoint("send5"); + auto& send1 = send->registerGlobalEndpoint("send1"); + auto& send2 = send->registerGlobalEndpoint("send2"); + auto& send3 = send->registerGlobalEndpoint("send3"); + auto& send4 = send->registerGlobalEndpoint("send4"); + auto& send5 = send->registerGlobalEndpoint("send5"); - auto& r1 = rec->registerGlobalEndpoint("rec1"); - auto& r2 = rec->registerGlobalEndpoint("rec2"); - auto& r3 = rec->registerGlobalEndpoint("rec3"); - auto& r4 = rec->registerGlobalEndpoint("rec4"); - auto& r5 = rec->registerGlobalEndpoint("rec5"); + auto& rec1 = rec->registerGlobalEndpoint("rec1"); + auto& rec2 = rec->registerGlobalEndpoint("rec2"); + auto& rec3 = rec->registerGlobalEndpoint("rec3"); + auto& rec4 = rec->registerGlobalEndpoint("rec4"); + auto& rec5 = rec->registerGlobalEndpoint("rec5"); - s1.setDefaultDestination("rec1"); - s2.setDefaultDestination("rec2"); - s3.setDefaultDestination("rec3"); - s4.setDefaultDestination("rec4"); - s5.setDefaultDestination("rec5"); + send1.setDefaultDestination("rec1"); + send2.setDefaultDestination("rec2"); + send3.setDefaultDestination("rec3"); + send4.setDefaultDestination("rec4"); + send5.setDefaultDestination("rec5"); - auto& p3 = filt->registerGlobalEndpoint("reroute"); + auto& reroute1 = filt->registerGlobalEndpoint("reroute"); - auto& f1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); + auto& filt1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); - f1.addSourceTarget("send1"); - f1.addSourceTarget("send2"); - f1.addSourceTarget("send3"); - f1.addSourceTarget("send4"); - f1.addSourceTarget("send5"); + filt1.addSourceTarget("send1"); + filt1.addSourceTarget("send2"); + filt1.addSourceTarget("send3"); + filt1.addSourceTarget("send4"); + filt1.addSourceTarget("send5"); - f1.setString("newdestination", "reroute"); + filt1.setString("newdestination", "reroute"); auto act1 = [&]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - s1.send("this is a message1"); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + send1.send("this is a message1"); - s2.send("this is a message2"); + send2.send("this is a message2"); // std::this_thread::sleep_for(std::chrono::milliseconds(200)); - s3.send("this is a message3"); - s4.send("this is a message4"); - s5.send("this is a message5"); + send3.send("this is a message3"); + send4.send("this is a message4"); + send5.send("this is a message5"); // std::this_thread::sleep_for(std::chrono::milliseconds(200)); - tr = send->requestTimeAdvance(1.0); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; auto act2 = [&rec]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); } rec->finalize(); }; @@ -1544,44 +1546,45 @@ TEST_F(filter, reroute_separate2_5message_nocov) std::vector mcount; auto act3 = [&]() { filt->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 20.0) { - tr = filt->requestTime(helics::Time::maxVal()); + helics::Time requestTime = helics::timeZero; + while (requestTime < 20.0) { + requestTime = filt->requestTime(helics::Time::maxVal()); mcount.push_back(0); - while (p3.hasMessage()) { - auto m = p3.getMessage(); + while (reroute1.hasMessage()) { + auto message = reroute1.getMessage(); + (void)message; ++mcount[cnt]; } ++cnt; } }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); - auto t3 = std::thread(act3); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); + auto thread3 = std::thread(act3); - t1.join(); - t2.join(); + thread1.join(); + thread2.join(); // std::this_thread::sleep_for(std::chrono::milliseconds(2000)); // auto res = broker->query("root", "global_time_debugging"); - t3.join(); + thread3.join(); filt->finalize(); - EXPECT_EQ(r1.pendingMessageCount(), 0U); - EXPECT_EQ(r2.pendingMessageCount(), 0U); - EXPECT_EQ(r3.pendingMessageCount(), 0U); - EXPECT_EQ(r4.pendingMessageCount(), 0U); - EXPECT_EQ(r5.pendingMessageCount(), 0U); + EXPECT_EQ(rec1.pendingMessageCount(), 0U); + EXPECT_EQ(rec2.pendingMessageCount(), 0U); + EXPECT_EQ(rec3.pendingMessageCount(), 0U); + EXPECT_EQ(rec4.pendingMessageCount(), 0U); + EXPECT_EQ(rec5.pendingMessageCount(), 0U); - EXPECT_EQ(p3.pendingMessageCount(), 0U); + EXPECT_EQ(reroute1.pendingMessageCount(), 0U); EXPECT_EQ(cnt, 11); int totalMessageCount{0}; int index = 0; - for (auto& mc : mcount) { - totalMessageCount += mc; - EXPECT_TRUE(mc == 5 || mc == 0) << "incorrect # of messages in interval [" << index - << "], (" << mc << ") messages instead of 5 "; + for (auto& count : mcount) { + totalMessageCount += count; + EXPECT_TRUE(count == 5 || count == 0) << "incorrect # of messages in interval [" << index + << "], (" << count << ") messages instead of 5 "; ++index; } EXPECT_EQ(totalMessageCount, 50); @@ -1601,60 +1604,60 @@ TEST_F(filter, reroute_separate2_5000message_ci_skip_nocov) auto rec = GetFederateAs(1); auto filt = GetFederateAs(2); - auto& s1 = send->registerGlobalEndpoint("send1"); - auto& s2 = send->registerGlobalEndpoint("send2"); - auto& s3 = send->registerGlobalEndpoint("send3"); - auto& s4 = send->registerGlobalEndpoint("send4"); - auto& s5 = send->registerGlobalEndpoint("send5"); + auto& send1 = send->registerGlobalEndpoint("send1"); + auto& send2 = send->registerGlobalEndpoint("send2"); + auto& send3 = send->registerGlobalEndpoint("send3"); + auto& send4 = send->registerGlobalEndpoint("send4"); + auto& send5 = send->registerGlobalEndpoint("send5"); - auto& r1 = rec->registerGlobalEndpoint("rec1"); - auto& r2 = rec->registerGlobalEndpoint("rec2"); - auto& r3 = rec->registerGlobalEndpoint("rec3"); - auto& r4 = rec->registerGlobalEndpoint("rec4"); - auto& r5 = rec->registerGlobalEndpoint("rec5"); + auto& rec1 = rec->registerGlobalEndpoint("rec1"); + auto& rec2 = rec->registerGlobalEndpoint("rec2"); + auto& rec3 = rec->registerGlobalEndpoint("rec3"); + auto& rec4 = rec->registerGlobalEndpoint("rec4"); + auto& rec5 = rec->registerGlobalEndpoint("rec5"); - s1.setDefaultDestination("rec1"); - s2.setDefaultDestination("rec2"); - s3.setDefaultDestination("rec3"); - s4.setDefaultDestination("rec4"); - s5.setDefaultDestination("rec5"); + send1.setDefaultDestination("rec1"); + send2.setDefaultDestination("rec2"); + send3.setDefaultDestination("rec3"); + send4.setDefaultDestination("rec4"); + send5.setDefaultDestination("rec5"); - auto& p3 = filt->registerGlobalEndpoint("reroute"); + auto& reroute1 = filt->registerGlobalEndpoint("reroute"); - auto& f1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); + auto& filt1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt"); - f1.addSourceTarget("send1"); - f1.addSourceTarget("send2"); - f1.addSourceTarget("send3"); - f1.addSourceTarget("send4"); - f1.addSourceTarget("send5"); + filt1.addSourceTarget("send1"); + filt1.addSourceTarget("send2"); + filt1.addSourceTarget("send3"); + filt1.addSourceTarget("send4"); + filt1.addSourceTarget("send5"); - f1.setString("newdestination", "reroute"); + filt1.setString("newdestination", "reroute"); auto act1 = [&]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { for (int kk = 0; kk < 100; ++kk) { - s1.send("this is a message1"); + send1.send("this is a message1"); - s2.send("this is a message2"); + send2.send("this is a message2"); // std::this_thread::sleep_for(std::chrono::milliseconds(200)); - s3.send("this is a message3"); - s4.send("this is a message4"); - s5.send("this is a message5"); + send3.send("this is a message3"); + send4.send("this is a message4"); + send5.send("this is a message5"); } // std::this_thread::sleep_for(std::chrono::milliseconds(200)); - tr = send->requestTimeAdvance(1.0); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; auto act2 = [&rec]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + requestTime = rec->requestTimeAdvance(1.0); } rec->finalize(); }; @@ -1663,44 +1666,45 @@ TEST_F(filter, reroute_separate2_5000message_ci_skip_nocov) std::vector mcount; auto act3 = [&]() { filt->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 20.0) { - tr = filt->requestTime(helics::Time::maxVal()); + helics::Time requestTime = helics::timeZero; + while (requestTime < 20.0) { + requestTime = filt->requestTime(helics::Time::maxVal()); mcount.push_back(0); - while (p3.hasMessage()) { - auto m = p3.getMessage(); + while (reroute1.hasMessage()) { + auto message = reroute1.getMessage(); + (void)message; ++mcount[cnt]; } ++cnt; } }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); - auto t3 = std::thread(act3); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); + auto thread3 = std::thread(act3); - t1.join(); - t2.join(); + thread1.join(); + thread2.join(); // std::this_thread::sleep_for(std::chrono::milliseconds(2000)); // auto res = broker->query("root", "global_time_debugging"); - t3.join(); + thread3.join(); filt->finalize(); - EXPECT_EQ(r1.pendingMessageCount(), 0U); - EXPECT_EQ(r2.pendingMessageCount(), 0U); - EXPECT_EQ(r3.pendingMessageCount(), 0U); - EXPECT_EQ(r4.pendingMessageCount(), 0U); - EXPECT_EQ(r5.pendingMessageCount(), 0U); + EXPECT_EQ(rec1.pendingMessageCount(), 0U); + EXPECT_EQ(rec2.pendingMessageCount(), 0U); + EXPECT_EQ(rec3.pendingMessageCount(), 0U); + EXPECT_EQ(rec4.pendingMessageCount(), 0U); + EXPECT_EQ(rec5.pendingMessageCount(), 0U); - EXPECT_EQ(p3.pendingMessageCount(), 0U); + EXPECT_EQ(reroute1.pendingMessageCount(), 0U); EXPECT_EQ(cnt, 11); int totalMessageCount{0}; int index = 0; - for (auto& mc : mcount) { - totalMessageCount += mc; - EXPECT_TRUE(mc == 500 || mc == 0) << "incorrect # of messages in interval [" << index - << "], (" << mc << ") messages instead of 50 "; + for (auto& count : mcount) { + totalMessageCount += count; + EXPECT_TRUE(count == 500 || count == 0) << "incorrect # of messages in interval [" << index + << "], (" << count << ") messages instead of 50 "; ++index; } EXPECT_EQ(totalMessageCount, 5000); @@ -1720,66 +1724,66 @@ TEST_F(filter, reroute_separate2_5message_b_nocov) auto rec = GetFederateAs(1); auto filt = GetFederateAs(2); - auto& s1 = send->registerGlobalEndpoint("send1"); - auto& s2 = send->registerGlobalEndpoint("send2"); - auto& s3 = send->registerGlobalEndpoint("send3"); - auto& s4 = send->registerGlobalEndpoint("send4"); - auto& s5 = send->registerGlobalEndpoint("send5"); - - auto& r1 = rec->registerGlobalEndpoint("rec1"); - auto& r2 = rec->registerGlobalEndpoint("rec2"); - auto& r3 = rec->registerGlobalEndpoint("rec3"); - auto& r4 = rec->registerGlobalEndpoint("rec4"); - auto& r5 = rec->registerGlobalEndpoint("rec5"); - - s1.setDefaultDestination("rec1"); - s2.setDefaultDestination("rec2"); - s3.setDefaultDestination("rec3"); - s4.setDefaultDestination("rec4"); - s5.setDefaultDestination("rec5"); - - auto& p3 = filt->registerGlobalEndpoint("reroute"); - - auto& f1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt1"); - auto& f2 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt2"); - auto& f3 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt3"); - auto& f4 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt4"); - auto& f5 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt5"); - - f1.addSourceTarget("send1"); - f2.addSourceTarget("send2"); - f3.addSourceTarget("send3"); - f4.addSourceTarget("send4"); - f5.addSourceTarget("send5"); - - f1.setString("newdestination", "reroute"); - f2.setString("newdestination", "reroute"); - f3.setString("newdestination", "reroute"); - f4.setString("newdestination", "reroute"); - f5.setString("newdestination", "reroute"); + auto& send1 = send->registerGlobalEndpoint("send1"); + auto& send2 = send->registerGlobalEndpoint("send2"); + auto& send3 = send->registerGlobalEndpoint("send3"); + auto& send4 = send->registerGlobalEndpoint("send4"); + auto& send5 = send->registerGlobalEndpoint("send5"); + + auto& rec1 = rec->registerGlobalEndpoint("rec1"); + auto& rec2 = rec->registerGlobalEndpoint("rec2"); + auto& rec3 = rec->registerGlobalEndpoint("rec3"); + auto& rec4 = rec->registerGlobalEndpoint("rec4"); + auto& rec5 = rec->registerGlobalEndpoint("rec5"); + + send1.setDefaultDestination("rec1"); + send2.setDefaultDestination("rec2"); + send3.setDefaultDestination("rec3"); + send4.setDefaultDestination("rec4"); + send5.setDefaultDestination("rec5"); + + auto& ept3 = filt->registerGlobalEndpoint("reroute"); + + auto& filt1 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt1"); + auto& filt2 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt2"); + auto& filt3 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt3"); + auto& filt4 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt4"); + auto& filt5 = helics::make_filter(helics::FilterTypes::REROUTE, filt.get(), "rrfilt5"); + + filt1.addSourceTarget("send1"); + filt2.addSourceTarget("send2"); + filt3.addSourceTarget("send3"); + filt4.addSourceTarget("send4"); + filt5.addSourceTarget("send5"); + + filt1.setString("newdestination", "reroute"); + filt2.setString("newdestination", "reroute"); + filt3.setString("newdestination", "reroute"); + filt4.setString("newdestination", "reroute"); + filt5.setString("newdestination", "reroute"); auto act1 = [&]() { send->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - s1.send("this is a message1"); + helics::Time requestTime = helics::timeZero; + while (requestTime < 10.0) { + send1.send("this is a message1"); - s2.send("this is a message2"); + send2.send("this is a message2"); // std::this_thread::sleep_for(std::chrono::milliseconds(200)); - s3.send("this is a message3"); - s4.send("this is a message4"); - s5.send("this is a message5"); + send3.send("this is a message3"); + send4.send("this is a message4"); + send5.send("this is a message5"); // std::this_thread::sleep_for(std::chrono::milliseconds(200)); - tr = send->requestTimeAdvance(1.0); + requestTime = send->requestTimeAdvance(1.0); } send->finalize(); }; auto act2 = [&rec]() { rec->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 10.0) { - tr = rec->requestTimeAdvance(1.0); + helics::Time currentTime = helics::timeZero; + while (currentTime < 10.0) { + currentTime = rec->requestTimeAdvance(1.0); } rec->finalize(); }; @@ -1788,44 +1792,44 @@ TEST_F(filter, reroute_separate2_5message_b_nocov) std::vector mcount; auto act3 = [&]() { filt->enterExecutingMode(); - helics::Time tr = helics::timeZero; - while (tr < 20.0) { - tr = filt->requestTime(helics::Time::maxVal()); + helics::Time currentTime = helics::timeZero; + while (currentTime < 20.0) { + currentTime = filt->requestTime(helics::Time::maxVal()); mcount.push_back(0); - while (p3.hasMessage()) { - auto m = p3.getMessage(); + while (ept3.hasMessage()) { + auto message = ept3.getMessage(); ++mcount[cnt]; } ++cnt; } }; - auto t1 = std::thread(act1); - auto t2 = std::thread(act2); - auto t3 = std::thread(act3); + auto thread1 = std::thread(act1); + auto thread2 = std::thread(act2); + auto thread3 = std::thread(act3); - t1.join(); - t2.join(); + thread1.join(); + thread2.join(); // std::this_thread::sleep_for(std::chrono::milliseconds(2000)); // auto res = broker->query("root", "global_time_debugging"); - t3.join(); + thread3.join(); filt->finalize(); - EXPECT_EQ(r1.pendingMessageCount(), 0U); - EXPECT_EQ(r2.pendingMessageCount(), 0U); - EXPECT_EQ(r3.pendingMessageCount(), 0U); - EXPECT_EQ(r4.pendingMessageCount(), 0U); - EXPECT_EQ(r5.pendingMessageCount(), 0U); + EXPECT_EQ(rec1.pendingMessageCount(), 0U); + EXPECT_EQ(rec2.pendingMessageCount(), 0U); + EXPECT_EQ(rec3.pendingMessageCount(), 0U); + EXPECT_EQ(rec4.pendingMessageCount(), 0U); + EXPECT_EQ(rec5.pendingMessageCount(), 0U); - EXPECT_EQ(p3.pendingMessageCount(), 0U); + EXPECT_EQ(ept3.pendingMessageCount(), 0U); EXPECT_EQ(cnt, 11); int totalMessageCount{0}; int index{0}; - for (auto& mc : mcount) { - totalMessageCount += mc; - EXPECT_TRUE(mc == 5 || mc == 0) << "incorrect # of messages in interval [" << index - << "], (" << mc << ") messages instead of 5 "; + for (auto& count : mcount) { + totalMessageCount += count; + EXPECT_TRUE(count == 5 || count == 0) << "incorrect # of messages in interval [" << index + << "], (" << count << ") messages instead of 5 "; ++index; } EXPECT_EQ(totalMessageCount, 50); @@ -1844,23 +1848,23 @@ TEST_F(filter, message_filter_function_two_stage_coreApp_filter_link) auto fFed2 = GetFederateAs(1); auto mFed = GetFederateAs(2); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - helics::CoreApp cr(mFed->getCorePointer()); - cr.addSourceFilterToEndpoint("filter1", "port1"); - cr.addDestinationFilterToEndpoint("filter2", "port2"); + helics::CoreApp cApp(mFed->getCorePointer()); + cApp.addSourceFilterToEndpoint("filter1", "port1"); + cApp.addDestinationFilterToEndpoint("filter2", "port2"); - auto& f1 = fFed->registerGlobalFilter("filter1"); + auto& filt1 = fFed->registerGlobalFilter("filter1"); - EXPECT_TRUE(f1.getHandle().isValid()); + EXPECT_TRUE(filt1.getHandle().isValid()); - auto& f2 = fFed2->registerGlobalFilter("filter2"); + auto& filt2 = fFed2->registerGlobalFilter("filter2"); - EXPECT_TRUE(f2.getHandle().isValid()); + EXPECT_TRUE(filt2.getHandle().isValid()); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -1874,16 +1878,16 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage_broker_filter_ auto fFed = GetFederateAs(0); auto fFed2 = GetFederateAs(1); auto mFed = GetFederateAs(2); - auto& f1 = fFed->registerGlobalFilter("filter1"); - auto& f2 = fFed2->registerGlobalFilter("filter2"); + auto& filt1 = fFed->registerGlobalFilter("filter1"); + auto& filt2 = fFed2->registerGlobalFilter("filter2"); std::this_thread::sleep_for(std::chrono::milliseconds(200)); broker->addSourceFilterToEndpoint("filter1", "port1"); broker->addDestinationFilterToEndpoint("filter2", "port2"); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -1898,16 +1902,16 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage_broker_filter_ auto fFed2 = GetFederateAs(1); auto mFed = GetFederateAs(2); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto& f1 = fFed->registerGlobalFilter("filter1"); - auto& f2 = fFed2->registerGlobalFilter("filter2"); + auto& filt1 = fFed->registerGlobalFilter("filter1"); + auto& filt2 = fFed2->registerGlobalFilter("filter2"); std::this_thread::sleep_for(std::chrono::milliseconds(200)); broker->addSourceFilterToEndpoint("filter1", "port1"); broker->addDestinationFilterToEndpoint("filter2", "port2"); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -1926,13 +1930,13 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage_broker_filter_ auto fFed2 = GetFederateAs(1); auto mFed = GetFederateAs(2); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto& f1 = fFed->registerGlobalFilter("filter1"); - auto& f2 = fFed2->registerGlobalFilter("filter2"); + auto& filt1 = fFed->registerGlobalFilter("filter1"); + auto& filt2 = fFed2->registerGlobalFilter("filter2"); - bool res = two_stage_filter_test(mFed, fFed, fFed2, p1, p2, f1, f2); + bool res = twoStageFilterTest(mFed, fFed, fFed2, ept1, ept2, filt1, filt2); EXPECT_TRUE(res); } @@ -1955,16 +1959,16 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage_object) ASSERT_TRUE(fFed); ASSERT_TRUE(fFed2); ASSERT_TRUE(mFed); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto& f1 = helics::make_filter(helics::FilterTypes::DELAY, fFed.get(), "filter1"); - f1.addSourceTarget("port1"); - f1.set("delay", 1.25); + auto& filt1 = helics::make_filter(helics::FilterTypes::DELAY, fFed.get(), "filter1"); + filt1.addSourceTarget("port1"); + filt1.set("delay", 1.25); - auto& f2 = helics::make_filter(helics::FilterTypes::DELAY, fFed.get(), "filter2"); - f2.addSourceTarget("port1"); - f2.set("delay", 1.25); + auto& filt2 = helics::make_filter(helics::FilterTypes::DELAY, fFed.get(), "filter2"); + filt2.addSourceTarget("port1"); + filt2.set("delay", 1.25); fFed->enterExecutingModeAsync(); fFed2->enterExecutingModeAsync(); @@ -1974,7 +1978,7 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage_object) EXPECT_TRUE(fFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed->requestTimeAsync(1.0); fFed->requestTimeAsync(1.0); @@ -1989,22 +1993,22 @@ TEST_P(filter_single_type_test, message_filter_function_two_stage_object) fFed->requestTime(2.0); mFed->requestTimeComplete(); fFed2->requestTimeComplete(); - ASSERT_TRUE(!mFed->hasMessage(p2)); + ASSERT_TRUE(!mFed->hasMessage(ept2)); fFed->requestTimeAsync(3.0); fFed2->requestTimeAsync(3.0); /*auto retTime = */ mFed->requestTime(3.0); - if (!mFed->hasMessage(p2)) { + if (!mFed->hasMessage(ept2)) { printf("missing message\n"); } - ASSERT_TRUE(mFed->hasMessage(p2)); + ASSERT_TRUE(mFed->hasMessage(ept2)); - auto m2 = mFed->getMessage(p2); - EXPECT_EQ(m2->source, "port1"); - EXPECT_EQ(m2->original_source, "port1"); - EXPECT_EQ(m2->dest, "port2"); - EXPECT_EQ(m2->data.size(), data.size()); - EXPECT_EQ(m2->time, 2.5); + auto message2 = mFed->getMessage(ept2); + EXPECT_EQ(message2->source, "port1"); + EXPECT_EQ(message2->original_source, "port1"); + EXPECT_EQ(message2->dest, "port2"); + EXPECT_EQ(message2->data.size(), data.size()); + EXPECT_EQ(message2->time, 2.5); fFed->requestTimeComplete(); fFed2->requestTimeComplete(); @@ -2036,16 +2040,16 @@ TEST_P(filter_single_type_test, message_filter_function2) ASSERT_TRUE(fFed); ASSERT_TRUE(mFed); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto& f1 = fFed->registerFilter("filter1"); - f1.addSourceTarget("port1"); - f1.addSourceTarget("port2"); - EXPECT_TRUE(f1.getHandle().isValid()); + auto& filt1 = fFed->registerFilter("filter1"); + filt1.addSourceTarget("port1"); + filt1.addSourceTarget("port2"); + EXPECT_TRUE(filt1.getHandle().isValid()); auto timeOperator = std::make_shared(); timeOperator->setTimeFunction([](helics::Time time_in) { return time_in + 2.5; }); - fFed->setFilterOperator(f1, timeOperator); + fFed->setFilterOperator(filt1, timeOperator); fFed->enterExecutingModeAsync(); mFed->enterExecutingMode(); @@ -2053,7 +2057,7 @@ TEST_P(filter_single_type_test, message_filter_function2) EXPECT_TRUE(fFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed->requestTimeAsync(1.0); fFed->requestTime(1.0); @@ -2061,27 +2065,27 @@ TEST_P(filter_single_type_test, message_filter_function2) auto res = mFed->hasMessage(); EXPECT_TRUE(!res); - p2.sendTo(data, "port1"); + ept2.sendTo(data, "port1"); mFed->requestTimeAsync(2.0); fFed->requestTime(2.0); mFed->requestTimeComplete(); - ASSERT_TRUE(!mFed->hasMessage(p2)); + ASSERT_TRUE(!mFed->hasMessage(ept2)); std::this_thread::yield(); mFed->requestTime(3.0); - ASSERT_TRUE(mFed->hasMessage(p2)); + ASSERT_TRUE(mFed->hasMessage(ept2)); - auto m2 = mFed->getMessage(p2); - EXPECT_EQ(m2->source, "port1"); - EXPECT_EQ(m2->original_source, "port1"); - EXPECT_EQ(m2->dest, "port2"); - EXPECT_EQ(m2->data.size(), data.size()); - EXPECT_EQ(m2->time, 2.5); + auto message2 = mFed->getMessage(ept2); + EXPECT_EQ(message2->source, "port1"); + EXPECT_EQ(message2->original_source, "port1"); + EXPECT_EQ(message2->dest, "port2"); + EXPECT_EQ(message2->data.size(), data.size()); + EXPECT_EQ(message2->time, 2.5); - EXPECT_TRUE(!mFed->hasMessage(p1)); + EXPECT_TRUE(!mFed->hasMessage(ept1)); mFed->requestTime(4.0); - EXPECT_TRUE(mFed->hasMessage(p1)); + EXPECT_TRUE(mFed->hasMessage(ept1)); mFed->finalizeAsync(); fFed->finalize(); mFed->finalizeComplete(); @@ -2099,16 +2103,16 @@ TEST_P(filter_single_type_test, message_filter_function2_rem_target) ASSERT_TRUE(fFed); ASSERT_TRUE(mFed); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto& f1 = fFed->registerFilter("filter1"); - f1.addSourceTarget("port1"); - f1.addSourceTarget("port2"); - EXPECT_TRUE(f1.getHandle().isValid()); + auto& filt1 = fFed->registerFilter("filter1"); + filt1.addSourceTarget("port1"); + filt1.addSourceTarget("port2"); + EXPECT_TRUE(filt1.getHandle().isValid()); auto timeOperator = std::make_shared(); timeOperator->setTimeFunction([](helics::Time time_in) { return time_in + 2.5; }); - fFed->setFilterOperator(f1, timeOperator); + fFed->setFilterOperator(filt1, timeOperator); fFed->enterExecutingModeAsync(); mFed->enterExecutingMode(); @@ -2116,7 +2120,7 @@ TEST_P(filter_single_type_test, message_filter_function2_rem_target) EXPECT_TRUE(fFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed->requestTimeAsync(1.0); fFed->requestTime(1.0); @@ -2124,38 +2128,38 @@ TEST_P(filter_single_type_test, message_filter_function2_rem_target) auto res = mFed->hasMessage(); EXPECT_TRUE(!res); - p2.sendTo(data, "port1"); + ept2.sendTo(data, "port1"); mFed->requestTimeAsync(2.0); fFed->requestTime(2.0); mFed->requestTimeComplete(); - ASSERT_TRUE(!mFed->hasMessage(p2)); + ASSERT_TRUE(!mFed->hasMessage(ept2)); std::this_thread::yield(); mFed->requestTime(3.0); - ASSERT_TRUE(mFed->hasMessage(p2)); + ASSERT_TRUE(mFed->hasMessage(ept2)); - auto m2 = mFed->getMessage(p2); - EXPECT_EQ(m2->source, "port1"); - EXPECT_EQ(m2->original_source, "port1"); - EXPECT_EQ(m2->dest, "port2"); - EXPECT_EQ(m2->data.size(), data.size()); - EXPECT_EQ(m2->time, 2.5); + auto message2 = mFed->getMessage(ept2); + EXPECT_EQ(message2->source, "port1"); + EXPECT_EQ(message2->original_source, "port1"); + EXPECT_EQ(message2->dest, "port2"); + EXPECT_EQ(message2->data.size(), data.size()); + EXPECT_EQ(message2->time, 2.5); - EXPECT_TRUE(!mFed->hasMessage(p1)); + EXPECT_TRUE(!mFed->hasMessage(ept1)); mFed->requestTime(4.0); - EXPECT_TRUE(mFed->hasMessage(p1)); - f1.removeTarget("port1"); + EXPECT_TRUE(mFed->hasMessage(ept1)); + filt1.removeTarget("port1"); mFed->requestTimeAsync(5.0); fFed->requestTime(5.0); mFed->requestTimeComplete(); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed->requestTimeAsync(6.0); fFed->requestTime(6.0); mFed->requestTimeComplete(); // now the message hasn't been delayed - EXPECT_TRUE(mFed->hasMessage(p2)); + EXPECT_TRUE(mFed->hasMessage(ept2)); mFed->finalize(); fFed->finalize(); @@ -2175,9 +2179,9 @@ TEST_F(filter_test, message_clone_test) auto dFed = GetFederateAs(1); auto dcFed = GetFederateAs(2); - auto& p1 = sFed->registerGlobalEndpoint("src"); - auto& p2 = dFed->registerGlobalEndpoint("dest"); - auto& p3 = dcFed->registerGlobalEndpoint("cm"); + auto& ept1 = sFed->registerGlobalEndpoint("src"); + auto& ept2 = dFed->registerGlobalEndpoint("dest"); + auto& ept3 = dcFed->registerGlobalEndpoint("cm"); helics::CloningFilter cFilt(dcFed.get()); cFilt.addSourceTarget("src"); @@ -2191,7 +2195,7 @@ TEST_F(filter_test, message_clone_test) EXPECT_TRUE(sFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "dest"); + ept1.sendTo(data, "dest"); sFed->requestTimeAsync(1.0); dcFed->requestTimeAsync(1.0); @@ -2203,11 +2207,11 @@ TEST_F(filter_test, message_clone_test) EXPECT_TRUE(res); if (res) { - auto m2 = dFed->getMessage(p2); - EXPECT_EQ(m2->source, "src"); - EXPECT_EQ(m2->original_source, "src"); - EXPECT_EQ(m2->dest, "dest"); - EXPECT_EQ(m2->data.size(), data.size()); + auto message2 = dFed->getMessage(ept2); + EXPECT_EQ(message2->source, "src"); + EXPECT_EQ(message2->original_source, "src"); + EXPECT_EQ(message2->dest, "dest"); + EXPECT_EQ(message2->data.size(), data.size()); } // now check the message clone @@ -2215,12 +2219,12 @@ TEST_F(filter_test, message_clone_test) EXPECT_TRUE(res); if (res) { - auto m2 = dcFed->getMessage(p3); - EXPECT_EQ(m2->source, "src"); - EXPECT_EQ(m2->original_source, "src"); - EXPECT_EQ(m2->dest, "cm"); - EXPECT_EQ(m2->original_dest, "dest"); - EXPECT_EQ(m2->data.size(), data.size()); + auto message2 = dcFed->getMessage(ept3); + EXPECT_EQ(message2->source, "src"); + EXPECT_EQ(message2->original_source, "src"); + EXPECT_EQ(message2->dest, "cm"); + EXPECT_EQ(message2->original_dest, "dest"); + EXPECT_EQ(message2->data.size(), data.size()); } sFed->finalizeAsync(); @@ -2244,10 +2248,10 @@ TEST_F(filter_test, message_multi_clone_test) auto dFed = GetFederateAs(2); auto dcFed = GetFederateAs(3); - auto& p1 = sFed->registerGlobalEndpoint("src"); - auto& p2 = sFed2->registerGlobalEndpoint("src2"); - auto& p3 = dFed->registerGlobalEndpoint("dest"); - auto& p4 = dcFed->registerGlobalEndpoint("cm"); + auto& ept1 = sFed->registerGlobalEndpoint("src"); + auto& ept2 = sFed2->registerGlobalEndpoint("src2"); + auto& destEpt = dFed->registerGlobalEndpoint("dest"); + auto& cmEpt = dcFed->registerGlobalEndpoint("cm"); helics::CloningFilter cFilt(dcFed.get()); cFilt.addSourceTarget("src"); @@ -2265,8 +2269,8 @@ TEST_F(filter_test, message_multi_clone_test) EXPECT_TRUE(sFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); helics::SmallBuffer data2(400, 'b'); - p1.sendTo(data, "dest"); - p2.sendTo(data2, "dest"); + ept1.sendTo(data, "dest"); + ept2.sendTo(data2, "dest"); sFed->requestTimeAsync(1.0); sFed2->requestTimeAsync(1.0); dcFed->requestTimeAsync(1.0); @@ -2275,52 +2279,52 @@ TEST_F(filter_test, message_multi_clone_test) sFed2->requestTimeComplete(); dcFed->requestTimeComplete(); - auto mcnt = dFed->pendingMessageCount(p3); + auto mcnt = dFed->pendingMessageCount(destEpt); EXPECT_EQ(mcnt, 2); auto res = dFed->hasMessage(); EXPECT_TRUE(res); if (res) { - auto m2 = dFed->getMessage(p3); - EXPECT_EQ(m2->source, "src"); - EXPECT_EQ(m2->original_source, "src"); - EXPECT_EQ(m2->dest, "dest"); - EXPECT_EQ(m2->data.size(), data.size()); + auto message2 = dFed->getMessage(destEpt); + EXPECT_EQ(message2->source, "src"); + EXPECT_EQ(message2->original_source, "src"); + EXPECT_EQ(message2->dest, "dest"); + EXPECT_EQ(message2->data.size(), data.size()); res = dFed->hasMessage(); EXPECT_TRUE(res); if (res) { - m2 = dFed->getMessage(p3); - EXPECT_EQ(m2->source, "src2"); - EXPECT_EQ(m2->original_source, "src2"); - EXPECT_EQ(m2->dest, "dest"); - EXPECT_EQ(m2->data.size(), data2.size()); + message2 = dFed->getMessage(destEpt); + EXPECT_EQ(message2->source, "src2"); + EXPECT_EQ(message2->original_source, "src2"); + EXPECT_EQ(message2->dest, "dest"); + EXPECT_EQ(message2->data.size(), data2.size()); } } // now check the message clone - mcnt = dcFed->pendingMessageCount(p4); + mcnt = dcFed->pendingMessageCount(cmEpt); EXPECT_EQ(mcnt, 2); res = dcFed->hasMessage(); EXPECT_TRUE(res); if (res) { - auto m2 = dcFed->getMessage(p4); - EXPECT_EQ(m2->source, "src"); - EXPECT_EQ(m2->original_source, "src"); - EXPECT_EQ(m2->dest, "cm"); - EXPECT_EQ(m2->original_dest, "dest"); - EXPECT_EQ(m2->data.size(), data.size()); + auto message2 = dcFed->getMessage(cmEpt); + EXPECT_EQ(message2->source, "src"); + EXPECT_EQ(message2->original_source, "src"); + EXPECT_EQ(message2->dest, "cm"); + EXPECT_EQ(message2->original_dest, "dest"); + EXPECT_EQ(message2->data.size(), data.size()); res = dcFed->hasMessage(); EXPECT_TRUE(res); if (res) { - m2 = dcFed->getMessage(p4); - EXPECT_EQ(m2->source, "src2"); - EXPECT_EQ(m2->original_source, "src2"); - EXPECT_EQ(m2->dest, "cm"); - EXPECT_EQ(m2->original_dest, "dest"); - EXPECT_EQ(m2->data.size(), data2.size()); + message2 = dcFed->getMessage(cmEpt); + EXPECT_EQ(message2->source, "src2"); + EXPECT_EQ(message2->original_source, "src2"); + EXPECT_EQ(message2->dest, "cm"); + EXPECT_EQ(message2->original_dest, "dest"); + EXPECT_EQ(message2->data.size(), data2.size()); } } @@ -2346,15 +2350,15 @@ TEST_P(filter_single_type_test, filter_core_termination) auto fFed = GetFederateAs(0); auto mFed = GetFederateAs(1); - auto& p1 = mFed->registerGlobalEndpoint("port1"); - auto& p2 = mFed->registerGlobalEndpoint("port2"); + auto& ept1 = mFed->registerGlobalEndpoint("port1"); + auto& ept2 = mFed->registerGlobalEndpoint("port2"); - auto c2 = fFed->getCorePointer(); - auto f1 = c2->registerFilter("filter1", std::string(), std::string()); - c2->addSourceTarget(f1, "port1"); + auto coreP = fFed->getCorePointer(); + auto filt1 = coreP->registerFilter("filter1", std::string(), std::string()); + coreP->addSourceTarget(filt1, "port1"); auto timeOperator = std::make_shared(); timeOperator->setTimeFunction([](helics::Time time_in) { return time_in + 2.5; }); - c2->setFilterOperator(f1, timeOperator); + coreP->setFilterOperator(filt1, timeOperator); fFed->enterExecutingModeAsync(); mFed->enterExecutingMode(); @@ -2362,7 +2366,7 @@ TEST_P(filter_single_type_test, filter_core_termination) EXPECT_TRUE(fFed->getCurrentMode() == helics::Federate::Modes::EXECUTING); helics::SmallBuffer data(500, 'a'); - p1.sendTo(data, "port2"); + ept1.sendTo(data, "port2"); mFed->requestTimeAsync(1.0); fFed->requestTime(1.0); @@ -2372,33 +2376,158 @@ TEST_P(filter_single_type_test, filter_core_termination) EXPECT_TRUE(!res); mFed->requestTime(2.0); - ASSERT_TRUE(!mFed->hasMessage(p2)); - EXPECT_TRUE(c2->isConnected()); + ASSERT_TRUE(!mFed->hasMessage(ept2)); + EXPECT_TRUE(coreP->isConnected()); mFed->requestTime(3.0); - p1.sendTo(data, "port2"); - ASSERT_TRUE(mFed->hasMessage(p2)); - - auto m2 = mFed->getMessage(p2); - EXPECT_EQ(m2->source, "port1"); - EXPECT_EQ(m2->original_source, "port1"); - EXPECT_EQ(m2->dest, "port2"); - EXPECT_EQ(m2->data.size(), data.size()); - EXPECT_EQ(m2->time, 2.5); - - auto tr = mFed->requestTime(4.0); - EXPECT_TRUE(!mFed->hasMessage(p2)); - tr = mFed->requestTime(6.0); - EXPECT_TRUE(mFed->hasMessage(p2)); + ept1.sendTo(data, "port2"); + ASSERT_TRUE(mFed->hasMessage(ept2)); + + auto message2 = mFed->getMessage(ept2); + EXPECT_EQ(message2->source, "port1"); + EXPECT_EQ(message2->original_source, "port1"); + EXPECT_EQ(message2->dest, "port2"); + EXPECT_EQ(message2->data.size(), data.size()); + EXPECT_EQ(message2->time, 2.5); + + auto requestTime = mFed->requestTime(4.0); + EXPECT_TRUE(!mFed->hasMessage(ept2)); + requestTime = mFed->requestTime(6.0); + EXPECT_TRUE(mFed->hasMessage(ept2)); mFed->finalize(); fFed->finalizeComplete(); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - if (c2->isConnected()) { + if (coreP->isConnected()) { std::this_thread::sleep_for(std::chrono::milliseconds(400)); } - EXPECT_TRUE(!c2->isConnected()); + EXPECT_TRUE(!coreP->isConnected()); EXPECT_TRUE(fFed->getCurrentMode() == helics::Federate::Modes::FINALIZE); } +// test for filter configuration of different flavors +TEST_F(filter, filter_config_test1) +{ + auto fed1 = + std::make_shared(std::string(TEST_DIR) + "filter_test1.json"); + + EXPECT_NO_THROW(fed1->enterExecutingMode()); + + EXPECT_EQ(fed1->getFilterCount(), 1U); + + EXPECT_EQ(fed1->getEndpointCount(), 3U); + auto& ept1 = fed1->getEndpoint(0); + auto& ept2 = fed1->getEndpoint(1); + + ept1.send("1"); + fed1->requestNextStep(); + EXPECT_FALSE(ept2.hasMessage()); + fed1->requestNextStep(); + EXPECT_TRUE(ept2.hasMessage()); + + fed1->finalize(); + + FullDisconnect(); +} + +// test for filter configuration of different flavors +TEST_F(filter, filter_config_test2) +{ + auto fed1 = + std::make_shared(std::string(TEST_DIR) + "filter_test2.json"); + + EXPECT_NO_THROW(fed1->enterExecutingMode()); + + EXPECT_EQ(fed1->getFilterCount(), 1U); + + EXPECT_EQ(fed1->getEndpointCount(), 3U); + auto& ept1 = fed1->getEndpoint(0); + auto& ept2 = fed1->getEndpoint(1); + + ept1.send("1"); + fed1->requestNextStep(); + EXPECT_FALSE(ept2.hasMessage()); + fed1->requestNextStep(); + EXPECT_TRUE(ept2.hasMessage()); + + fed1->finalize(); + + FullDisconnect(); +} + +// test for filter configuration of different flavors +TEST_F(filter, filter_config_test3) +{ + auto fed1 = + std::make_shared(std::string(TEST_DIR) + "filter_test3.json"); + + EXPECT_NO_THROW(fed1->enterExecutingMode()); + + EXPECT_EQ(fed1->getFilterCount(), 1U); + + EXPECT_EQ(fed1->getEndpointCount(), 3U); + auto& ept1 = fed1->getEndpoint(0); + auto& ept2 = fed1->getEndpoint(1); + auto& ept3 = fed1->getEndpoint(2); + + ept1.send("1"); + fed1->requestNextStep(); + EXPECT_FALSE(ept2.hasMessage()); + EXPECT_TRUE(ept3.hasMessage()); + + fed1->finalize(); + + FullDisconnect(); +} + +// test for filter configuration of different flavors +TEST_F(filter, filter_config_test4) +{ + auto fed1 = + std::make_shared(std::string(TEST_DIR) + "filter_test4.json"); + + EXPECT_NO_THROW(fed1->enterExecutingMode()); + + EXPECT_EQ(fed1->getFilterCount(), 1U); + + EXPECT_EQ(fed1->getEndpointCount(), 3U); + auto& ept1 = fed1->getEndpoint(0); + auto& ept2 = fed1->getEndpoint(1); + auto& ept3 = fed1->getEndpoint(2); + + ept1.send("1"); + fed1->requestNextStep(); + EXPECT_TRUE(ept2.hasMessage()); + EXPECT_TRUE(ept3.hasMessage()); + + fed1->finalize(); + + FullDisconnect(); +} + +// test for filter configuration of different flavors +TEST_F(filter, filter_config_test5) +{ + auto fed1 = + std::make_shared(std::string(TEST_DIR) + "filter_test5.json"); + + EXPECT_NO_THROW(fed1->enterExecutingMode()); + + EXPECT_EQ(fed1->getFilterCount(), 1U); + + EXPECT_EQ(fed1->getEndpointCount(), 3U); + auto& ept1 = fed1->getEndpoint(0); + auto& ept2 = fed1->getEndpoint(1); + auto& ept3 = fed1->getEndpoint(2); + + ept1.send("1"); + fed1->requestNextStep(); + EXPECT_TRUE(ept2.hasMessage()); + EXPECT_TRUE(ept3.hasMessage()); + + fed1->finalize(); + + FullDisconnect(); +} + INSTANTIATE_TEST_SUITE_P(filter, filter_single_type_test, ::testing::ValuesIn(CoreTypes_simple), diff --git a/tests/helics/application_api/MessageFederateAdditionalTests.cpp b/tests/helics/application_api/MessageFederateAdditionalTests.cpp index 9ec4431ca1..fc3b49b966 100644 --- a/tests/helics/application_api/MessageFederateAdditionalTests.cpp +++ b/tests/helics/application_api/MessageFederateAdditionalTests.cpp @@ -60,24 +60,24 @@ TEST_F(mfed_tests, endpoint_registration) SetupTest("test", 1); auto mFed1 = GetFederateAs(0); - auto& epid = mFed1->registerEndpoint("ep1"); - auto& epid2 = mFed1->registerGlobalEndpoint("ep2", "random"); + auto& ep1 = mFed1->registerEndpoint("ep1"); + auto& ep2 = mFed1->registerGlobalEndpoint("ep2", "random"); mFed1->enterExecutingMode(); EXPECT_TRUE(mFed1->getCurrentMode() == helics::Federate::Modes::EXECUTING); - auto& sv = epid.getName(); - auto& sv2 = epid2.getName(); - EXPECT_EQ(sv, "fed0/ep1"); - EXPECT_EQ(sv2, "ep2"); + auto& ep1Name = ep1.getName(); + auto& ep2Name = ep2.getName(); + EXPECT_EQ(ep1Name, "fed0/ep1"); + EXPECT_EQ(ep2Name, "ep2"); - EXPECT_EQ(epid.getExtractionType(), ""); - EXPECT_EQ(epid2.getExtractionType(), "random"); + EXPECT_EQ(ep1.getExtractionType(), ""); + EXPECT_EQ(ep2.getExtractionType(), "random"); - EXPECT_TRUE(mFed1->getEndpoint("ep1").getHandle() == epid.getHandle()); - EXPECT_TRUE(mFed1->getEndpoint("fed0/ep1").getHandle() == epid.getHandle()); - EXPECT_TRUE(mFed1->getEndpoint("ep2").getHandle() == epid2.getHandle()); + EXPECT_TRUE(mFed1->getEndpoint("ep1").getHandle() == ep1.getHandle()); + EXPECT_TRUE(mFed1->getEndpoint("fed0/ep1").getHandle() == ep1.getHandle()); + EXPECT_TRUE(mFed1->getEndpoint("ep2").getHandle() == ep2.getHandle()); mFed1->finalize(); EXPECT_TRUE(mFed1->getCurrentMode() == helics::Federate::Modes::FINALIZE); @@ -95,10 +95,10 @@ TEST_P(mfed_add_single_type_tests, endpoint_registration_objs) EXPECT_TRUE(mFed1->getCurrentMode() == helics::Federate::Modes::EXECUTING); - auto const& sv = epid.getName(); - auto const& sv2 = epid2.getName(); - EXPECT_EQ(sv, "fed0/ep1"); - EXPECT_EQ(sv2, "ep2"); + auto const& endpoint1Name = epid.getName(); + auto const& endpoint2Name = epid2.getName(); + EXPECT_EQ(endpoint1Name, "fed0/ep1"); + EXPECT_EQ(endpoint2Name, "ep2"); EXPECT_EQ(epid.getType(), ""); EXPECT_EQ(epid2.getType(), "random"); @@ -149,11 +149,11 @@ TEST_P(mfed_add_single_type_tests, send_receive_callback) EXPECT_TRUE(rxend == epid2.getHandle()); EXPECT_EQ(timeRx, helics::Time(1.0)); - auto M = mFed1->getMessage(epid2); - ASSERT_TRUE(M); - ASSERT_EQ(M->data.size(), data.size()); + auto message = mFed1->getMessage(epid2); + ASSERT_TRUE(message); + ASSERT_EQ(message->data.size(), data.size()); - EXPECT_EQ(M->data[245], data[245]); + EXPECT_EQ(message->data[245], data[245]); mFed1->finalize(); EXPECT_TRUE(mFed1->getCurrentMode() == helics::Federate::Modes::FINALIZE); @@ -196,11 +196,11 @@ TEST_P(mfed_add_single_type_tests, send_receive_callback_obj) EXPECT_TRUE(rxend == ep2.getHandle()); EXPECT_EQ(timeRx, helics::Time(1.0)); - auto M = ep2.getMessage(); - ASSERT_TRUE(M); - ASSERT_EQ(M->data.size(), data.size()); + auto message = ep2.getMessage(); + ASSERT_TRUE(message); + ASSERT_EQ(message->data.size(), data.size()); - EXPECT_EQ(M->data[245], data[245]); + EXPECT_EQ(message->data[245], data[245]); mFed1->finalize(); EXPECT_TRUE(mFed1->getCurrentMode() == helics::Federate::Modes::FINALIZE); @@ -239,11 +239,11 @@ TEST_P(mfed_add_single_type_tests, send_receive_callback_obj2) EXPECT_TRUE(!res); EXPECT_TRUE(rxend == ep2.getHandle()); EXPECT_EQ(timeRx, helics::Time(1.0)); - auto M = ep2.getMessage(); - ASSERT_TRUE(M); - ASSERT_EQ(M->data.size(), data.size()); + auto message = ep2.getMessage(); + ASSERT_TRUE(message); + ASSERT_EQ(message->data.size(), data.size()); - EXPECT_EQ(M->data[245], data[245]); + EXPECT_EQ(message->data[245], data[245]); mFed1->finalize(); EXPECT_TRUE(mFed1->getCurrentMode() == helics::Federate::Modes::FINALIZE); } @@ -255,14 +255,14 @@ TEST_P(mfed_add_all_type_tests, send_receive_2fed_multisend_callback) auto mFed1 = GetFederateAs(0); auto mFed2 = GetFederateAs(1); - auto& epid = mFed1->registerEndpoint("ep1"); - auto& epid2 = mFed2->registerGlobalEndpoint("ep2", "random"); + auto& ep1 = mFed1->registerEndpoint("ep1"); + auto& ep2 = mFed2->registerGlobalEndpoint("ep2", "random"); std::atomic e1cnt{0}; std::atomic e2cnt{0}; - mFed1->setMessageNotificationCallback(epid, + mFed1->setMessageNotificationCallback(ep1, [&](const helics::Endpoint& /*unused*/, helics::Time /*unused*/) { ++e1cnt; }); - mFed2->setMessageNotificationCallback(epid2, + mFed2->setMessageNotificationCallback(ep2, [&](const helics::Endpoint& /*unused*/, helics::Time /*unused*/) { ++e2cnt; }); // mFed1->getCorePointer()->setLoggingLevel(0, 5); @@ -279,10 +279,10 @@ TEST_P(mfed_add_all_type_tests, send_receive_2fed_multisend_callback) helics::SmallBuffer data2(400, std::byte{'b'}); helics::SmallBuffer data3(300, std::byte{'c'}); helics::SmallBuffer data4(200, std::byte{'d'}); - epid.sendTo(data1, "ep2"); - epid.sendTo(data2, "ep2"); - epid.sendTo(data3, "ep2"); - epid.sendTo(data4, "ep2"); + ep1.sendTo(data1, "ep2"); + ep1.sendTo(data2, "ep2"); + ep1.sendTo(data3, "ep2"); + ep1.sendTo(data4, "ep2"); // move the time to 1.0 mFed1->requestTimeAsync(1.0); auto gtime = mFed2->requestTime(1.0); @@ -291,34 +291,37 @@ TEST_P(mfed_add_all_type_tests, send_receive_2fed_multisend_callback) EXPECT_EQ(mFed1->requestTimeComplete(), 1.0); EXPECT_TRUE(!mFed1->hasMessage()); - EXPECT_TRUE(!mFed1->hasMessage(epid)); - auto cnt = mFed2->pendingMessageCount(epid2); + EXPECT_TRUE(!mFed1->hasMessage(ep1)); + auto cnt = mFed2->pendingMessageCount(ep2); EXPECT_EQ(cnt, 4); - auto M1 = mFed2->getMessage(epid2); - ASSERT_TRUE(M1); - ASSERT_EQ(M1->data.size(), data1.size()); + cnt = mFed2->pendingMessageCount(); + EXPECT_EQ(cnt, 4); + + auto message1 = mFed2->getMessage(ep2); + ASSERT_TRUE(message1); + ASSERT_EQ(message1->data.size(), data1.size()); - EXPECT_EQ(M1->data[245], data1[245]); + EXPECT_EQ(message1->data[245], data1[245]); // check the count decremented - cnt = mFed2->pendingMessageCount(epid2); + cnt = mFed2->pendingMessageCount(ep2); EXPECT_EQ(cnt, 3); - auto M2 = mFed2->getMessage(); - ASSERT_TRUE(M2); - ASSERT_EQ(M2->data.size(), data2.size()); - EXPECT_EQ(M2->data[245], data2[245]); - cnt = mFed2->pendingMessageCount(epid2); + auto message2 = mFed2->getMessage(); + ASSERT_TRUE(message2); + ASSERT_EQ(message2->data.size(), data2.size()); + EXPECT_EQ(message2->data[245], data2[245]); + cnt = mFed2->pendingMessageCount(ep2); EXPECT_EQ(cnt, 2); - auto M3 = mFed2->getMessage(); - auto M4 = mFed2->getMessage(epid2); - EXPECT_EQ(M3->data.size(), data3.size()); - EXPECT_EQ(M4->data.size(), data4.size()); + auto message3 = mFed2->getMessage(); + auto message4 = mFed2->getMessage(ep2); + EXPECT_EQ(message3->data.size(), data3.size()); + EXPECT_EQ(message4->data.size(), data4.size()); - EXPECT_EQ(M4->source, "fed0/ep1"); - EXPECT_EQ(M4->dest, "ep2"); - EXPECT_EQ(M4->original_source, "fed0/ep1"); - EXPECT_EQ(M4->time, 0.0); + EXPECT_EQ(message4->source, "fed0/ep1"); + EXPECT_EQ(message4->dest, "ep2"); + EXPECT_EQ(message4->original_source, "fed0/ep1"); + EXPECT_EQ(message4->time, 0.0); EXPECT_EQ(e1cnt, 0); EXPECT_EQ(e2cnt, 4); mFed1->finalizeAsync(); @@ -339,7 +342,7 @@ class PingPongFed { std::string name; //!< the name of the federate helics::CoreType coreType; std::vector> triggers; - helics::Endpoint* ep{nullptr}; + helics::Endpoint* ept{nullptr}; int index{0}; public: @@ -356,24 +359,24 @@ class PingPongFed { private: void initialize() { - helics::FederateInfo fi(coreType); - fi.coreName = "pptest"; - fi.coreInitString = "-f 3"; - fi.setProperty(HELICS_PROPERTY_TIME_DELTA, delta); + helics::FederateInfo fedInfo(coreType); + fedInfo.coreName = "pptest"; + fedInfo.coreInitString = "-f 3"; + fedInfo.setProperty(HELICS_PROPERTY_TIME_DELTA, delta); #ifdef ENABLE_OUTPUT std::cout << std::string("about to create federate ") + name + "\n"; #endif - mFed = std::make_unique(name, fi); + mFed = std::make_unique(name, fedInfo); #ifdef ENABLE_OUTPUT std::cout << std::string("registering federate ") + name + "\n"; #endif - ep = &mFed->registerEndpoint("port"); + ept = &mFed->registerEndpoint("port"); } void processMessages(helics::Time currentTime) { - while (mFed->hasMessage(*ep)) { - auto mess = mFed->getMessage(*ep); + while (mFed->hasMessage(*ept)) { + auto mess = mFed->getMessage(*ept); auto messString = mess->data.to_string(); if (messString == "ping") { #ifdef ENABLE_OUTPUT @@ -385,7 +388,7 @@ class PingPongFed { mess->source = name; mess->original_source = mess->source; mess->time = currentTime; - ep->send(std::move(mess)); + ept->send(std::move(mess)); pings++; } else if (messString == "pong") { pongs++; @@ -407,7 +410,7 @@ class PingPongFed { std::cout << name << ": send ping to " << triggers[index].second << " at time " << static_cast(nextTime) << '\n'; #endif - ep->sendTo("ping", triggers[index].second); + ept->sendTo("ping", triggers[index].second); ++index; if (index >= static_cast(triggers.size())) { break; @@ -444,30 +447,30 @@ TEST_P(mfed_add_type_tests, threefedPingPong) auto brk = AddBroker(GetParam(), "-f 3"); auto crtype = helics::core::coreTypeFromString(GetParam()); - PingPongFed p1("fedA", 0.5, crtype); - PingPongFed p2("fedB", 0.5, crtype); - PingPongFed p3("fedC", 0.5, crtype); - - p1.addTrigger(0.5, "fedB/port"); - p1.addTrigger(0.5, "fedC/port"); - p1.addTrigger(3.0, "fedB/port"); - p2.addTrigger(1.5, "fedA/port"); - p3.addTrigger(3.0, "fedB/port"); - p3.addTrigger(4.0, "fedA/port"); - - auto t1 = std::thread([&p1]() { p1.run(6.0); }); - auto t2 = std::thread([&p2]() { p2.run(6.0); }); - auto t3 = std::thread([&p3]() { p3.run(6.0); }); - - t1.join(); - t2.join(); - t3.join(); - EXPECT_EQ(p1.pings, 2); - EXPECT_EQ(p2.pings, 3); - EXPECT_EQ(p3.pings, 1); - EXPECT_EQ(p1.pongs, 3); - EXPECT_EQ(p2.pongs, 1); - EXPECT_EQ(p3.pongs, 2); + PingPongFed ping1("fedA", 0.5, crtype); + PingPongFed ping2("fedB", 0.5, crtype); + PingPongFed ping3("fedC", 0.5, crtype); + + ping1.addTrigger(0.5, "fedB/port"); + ping1.addTrigger(0.5, "fedC/port"); + ping1.addTrigger(3.0, "fedB/port"); + ping2.addTrigger(1.5, "fedA/port"); + ping3.addTrigger(3.0, "fedB/port"); + ping3.addTrigger(4.0, "fedA/port"); + + auto thread1 = std::thread([&ping1]() { ping1.run(6.0); }); + auto thread2 = std::thread([&ping2]() { ping2.run(6.0); }); + auto thread3 = std::thread([&ping3]() { ping3.run(6.0); }); + + thread1.join(); + thread2.join(); + thread3.join(); + EXPECT_EQ(ping1.pings, 2); + EXPECT_EQ(ping2.pings, 3); + EXPECT_EQ(ping3.pings, 1); + EXPECT_EQ(ping1.pongs, 3); + EXPECT_EQ(ping2.pongs, 1); + EXPECT_EQ(ping3.pongs, 2); } INSTANTIATE_TEST_SUITE_P(mfed_add_tests, @@ -506,9 +509,9 @@ TEST_P(mfed_file_config_files, test_file_load) EXPECT_EQ(mFed.getName(), "messageFed"); EXPECT_EQ(mFed.getEndpointCount(), 2); - auto id = mFed.getEndpoint("ept1"); - EXPECT_EQ(id.getExtractionType(), "genmessage"); - EXPECT_EQ(id.getInfo(), "this is an information string for use by the application"); + auto& ept1 = mFed.getEndpoint("ept1"); + EXPECT_EQ(ept1.getExtractionType(), "genmessage"); + EXPECT_EQ(ept1.getInfo(), "this is an information string for use by the application"); EXPECT_EQ(mFed.query("global_value", "global1"), "this is a global1 value"); EXPECT_EQ(mFed.query("global_value", "global2"), "this is another global value"); @@ -531,8 +534,8 @@ TEST_P(mfed_file_filter_config_files, test_file_load_filter) EXPECT_EQ(mFed.getName(), "filterFed"); EXPECT_EQ(mFed.getEndpointCount(), 3); - auto id = mFed.getEndpoint("ept1"); - EXPECT_EQ(id.getExtractionType(), "genmessage"); + auto& ept1 = mFed.getEndpoint("ept1"); + EXPECT_EQ(ept1.getExtractionType(), "genmessage"); EXPECT_EQ(mFed.getFilterCount(), 3); @@ -543,10 +546,10 @@ TEST_P(mfed_file_filter_config_files, test_file_load_filter) EXPECT_EQ(mFed.getFilter(0).getInfo(), "this is an information string for use by the application"); - auto cr = mFed.getCorePointer(); + auto core = mFed.getCorePointer(); mFed.disconnect(); - cr->disconnect(); - cr.reset(); + core->disconnect(); + core.reset(); } INSTANTIATE_TEST_SUITE_P(mfed_add_tests, @@ -568,15 +571,15 @@ TEST_F(mfed_tests, send_message1) mFed1->requestNextStep(); - auto m1 = ep2.getMessage(); - EXPECT_EQ(m1->data.size(), 26U); + auto message = ep2.getMessage(); + EXPECT_EQ(message->data.size(), 26U); ep1.sendToAt(message1.c_str(), 31, "ep2", 1.7); auto res = mFed1->requestTime(2.0); EXPECT_EQ(res, 1.7); - m1 = ep2.getMessage(); - EXPECT_EQ(m1->data.size(), 31U); + message = ep2.getMessage(); + EXPECT_EQ(message->data.size(), 31U); mFed1->finalize(); } @@ -599,10 +602,10 @@ TEST(messageFederate, constructor1) auto ept1 = mf2.registerEndpoint(); EXPECT_FALSE(mf2.hasMessage(ept1)); EXPECT_EQ(mf2.pendingMessageCount(ept1), 0); - auto m1 = mf2.getMessage(ept1); - EXPECT_FALSE(m1); + auto message = mf2.getMessage(ept1); + EXPECT_FALSE(message); - EXPECT_THROW(ept1.send(std::move(m1)), helics::InvalidFunctionCall); + EXPECT_THROW(ept1.send(std::move(message)), helics::InvalidFunctionCall); mf2.enterExecutingMode(); mf2.finalize(); @@ -612,10 +615,10 @@ TEST(messageFederate, constructor1) TEST(messageFederate, constructor2) { - auto cr = helics::CoreFactory::create(helics::CoreType::TEST, "--name=cb --autobroker"); - helics::FederateInfo fi(helics::CoreType::TEST); - fi.setProperty(HELICS_PROPERTY_INT_LOG_LEVEL, HELICS_LOG_LEVEL_ERROR); - helics::MessageFederate mf1("fed1", cr, fi); + auto core = helics::CoreFactory::create(helics::CoreType::TEST, "--name=cb --autobroker"); + helics::FederateInfo fedInfo(helics::CoreType::TEST); + fedInfo.setProperty(HELICS_PROPERTY_INT_LOG_LEVEL, HELICS_LOG_LEVEL_ERROR); + helics::MessageFederate mf1("fed1", core, fedInfo); mf1.registerInterfaces(std::string(TEST_DIR) + "example_message_fed_testb.json"); @@ -625,26 +628,26 @@ TEST(messageFederate, constructor2) EXPECT_NO_THROW(mf1.enterExecutingMode()); mf1.finalize(); - cr.reset(); + core.reset(); } TEST(messageFederate, constructor3) { - helics::CoreApp cr("--coretype=test --name=cb2 --autobroker"); + helics::CoreApp core("--coretype=test --name=cb2 --autobroker"); - helics::FederateInfo fi(helics::CoreType::TEST); - fi.setProperty(HELICS_PROPERTY_INT_LOG_LEVEL, HELICS_LOG_LEVEL_ERROR); - helics::MessageFederate mf1("fed1", cr, fi); + helics::FederateInfo fedInfo(helics::CoreType::TEST); + fedInfo.setProperty(HELICS_PROPERTY_INT_LOG_LEVEL, HELICS_LOG_LEVEL_ERROR); + helics::MessageFederate mf1("fed1", core, fedInfo); mf1.registerInterfaces(std::string(TEST_DIR) + "example_message_fed_testb.json"); - EXPECT_TRUE(cr.isConnected()); + EXPECT_TRUE(core.isConnected()); mf1.registerGlobalFilter("filt1"); mf1.registerGlobalFilter("filt2"); EXPECT_NO_THROW(mf1.enterExecutingMode()); mf1.finalize(); - EXPECT_NO_THROW(cr.getCopyofCorePointer()->waitForDisconnect()); + EXPECT_NO_THROW(core.getCopyofCorePointer()->waitForDisconnect()); } TEST(messageFederate, constructor4) @@ -849,10 +852,10 @@ TEST_F(mfed_tests, message_init_iteration) EXPECT_TRUE(ep2.hasMessage()); - auto m = ep2.getMessage(); - if (m) { - EXPECT_EQ(m->data.size(), 26U); - EXPECT_LT(m->time, helics::timeZero); + auto message = ep2.getMessage(); + if (message) { + EXPECT_EQ(message->data.size(), 26U); + EXPECT_LT(message->time, helics::timeZero); } mFed2->enterExecutingMode(); mFed1->enterExecutingModeComplete(); @@ -891,36 +894,37 @@ TEST_F(mfed_tests, missing_endpoint) std::this_thread::sleep_for(std::chrono::milliseconds(100)); mFed1->requestTime(1.0); - auto mm = mlog.lock(); - EXPECT_EQ(mm->size(), 1U); - if (!mm->empty()) { - EXPECT_EQ(mm->front().first, HELICS_LOG_LEVEL_WARNING); - EXPECT_THAT(mm->front().second, HasSubstr("ep92")); - EXPECT_THAT(mm->front().second, HasSubstr("ep1")); + auto logs = mlog.lock(); + EXPECT_EQ(logs->size(), 1U); + if (!logs->empty()) { + EXPECT_EQ(logs->front().first, HELICS_LOG_LEVEL_WARNING); + EXPECT_THAT(logs->front().second, HasSubstr("ep92")); + EXPECT_THAT(logs->front().second, HasSubstr("ep1")); } - mm.unlock(); + logs.unlock(); ep2.sendTo(message1.c_str(), 26, "ep92"); std::this_thread::sleep_for(std::chrono::milliseconds(100)); mFed1->requestTime(2.0); // no warning from this one - mm = mlog.lock(); - EXPECT_EQ(mm->size(), 1U); - mm.unlock(); + logs = mlog.lock(); + EXPECT_EQ(logs->size(), 1U); + logs.unlock(); ep3.sendTo(message1.c_str(), 26, "ep92"); std::this_thread::sleep_for(std::chrono::milliseconds(100)); try { mFed1->requestTime(3.0); } - catch (...) { + catch (const helics::HelicsException&) { + ; } - mm = mlog.lock(); - EXPECT_EQ(mm->size(), 2U); - if (!mm->empty()) { - EXPECT_EQ(mm->back().first, HELICS_LOG_LEVEL_ERROR); - EXPECT_THAT(mm->back().second, HasSubstr("ep92")); - EXPECT_THAT(mm->back().second, HasSubstr("ep3")); + logs = mlog.lock(); + EXPECT_EQ(logs->size(), 2U); + if (!logs->empty()) { + EXPECT_EQ(logs->back().first, HELICS_LOG_LEVEL_ERROR); + EXPECT_THAT(logs->back().second, HasSubstr("ep92")); + EXPECT_THAT(logs->back().second, HasSubstr("ep3")); } - mm.unlock(); + logs.unlock(); mFed1->finalize(); } @@ -954,10 +958,10 @@ TEST_F(mfed_tests, targeted_endpoint_send_error1) EXPECT_TRUE(ep2.hasMessage()); EXPECT_FALSE(ep4.hasMessage()); EXPECT_FALSE(ep3.hasMessage()); - auto m = ep2.getMessage(); - if (m) { - EXPECT_EQ(m->data.size(), 26U); - EXPECT_EQ(m->time, helics::timeZero); + auto message = ep2.getMessage(); + if (message) { + EXPECT_EQ(message->data.size(), 26U); + EXPECT_EQ(message->time, helics::timeZero); } mFed2->finalize(); @@ -994,10 +998,10 @@ TEST_F(mfed_tests, targeted_endpoint_send_error2) EXPECT_TRUE(ep2.hasMessage()); EXPECT_FALSE(ep4.hasMessage()); EXPECT_FALSE(ep3.hasMessage()); - auto m = ep2.getMessage(); - if (m) { - EXPECT_EQ(m->data.size(), 26U); - EXPECT_EQ(m->time, helics::timeZero); + auto message = ep2.getMessage(); + if (message) { + EXPECT_EQ(message->data.size(), 26U); + EXPECT_EQ(message->time, helics::timeZero); } mFed2->finalize(); @@ -1040,10 +1044,10 @@ TEST_F(mfed_tests, targeted_endpoint_send_error3) EXPECT_TRUE(ep2.hasMessage()); EXPECT_FALSE(ep4.hasMessage()); EXPECT_FALSE(ep3.hasMessage()); - auto m = ep2.getMessage(); - if (m) { - EXPECT_EQ(m->data.size(), 26U); - EXPECT_EQ(m->time, helics::timeZero); + auto message = ep2.getMessage(); + if (message) { + EXPECT_EQ(message->data.size(), 26U); + EXPECT_EQ(message->time, helics::timeZero); } mFed2->finalize(); @@ -1085,44 +1089,44 @@ TEST_F(mfed_tests, targeted_endpoint_send_all) EXPECT_TRUE(ep2.hasMessage()); EXPECT_TRUE(ep4.hasMessage()); EXPECT_FALSE(ep3.hasMessage()); - auto m = ep2.getMessage(); - if (m) { - EXPECT_EQ(m->data.size(), 26U); - EXPECT_EQ(m->time, helics::timeZero); + auto message = ep2.getMessage(); + if (message) { + EXPECT_EQ(message->data.size(), 26U); + EXPECT_EQ(message->time, helics::timeZero); } - auto m2 = ep4.getMessage(); - if (m2) { - EXPECT_EQ(m2->data.size(), 26U); - EXPECT_EQ(m2->time, helics::timeZero); + auto message2 = ep4.getMessage(); + if (message2) { + EXPECT_EQ(message2->data.size(), 26U); + EXPECT_EQ(message2->time, helics::timeZero); } EXPECT_TRUE(ep2.hasMessage()); EXPECT_TRUE(ep4.hasMessage()); - m = ep2.getMessage(); - if (m) { - EXPECT_EQ(m->data.size(), 26U); - EXPECT_EQ(m->time, helics::timeZero); + message = ep2.getMessage(); + if (message) { + EXPECT_EQ(message->data.size(), 26U); + EXPECT_EQ(message->time, helics::timeZero); } - m2 = ep4.getMessage(); - if (m2) { - EXPECT_EQ(m2->data.size(), 26U); - EXPECT_EQ(m2->time, helics::timeZero); + message2 = ep4.getMessage(); + if (message2) { + EXPECT_EQ(message2->data.size(), 26U); + EXPECT_EQ(message2->time, helics::timeZero); } EXPECT_TRUE(ep2.hasMessage()); EXPECT_TRUE(ep4.hasMessage()); - m = ep2.getMessage(); - if (m) { - EXPECT_EQ(m->data.size(), 26U); - EXPECT_EQ(m->time, helics::timeZero); + message = ep2.getMessage(); + if (message) { + EXPECT_EQ(message->data.size(), 26U); + EXPECT_EQ(message->time, helics::timeZero); } - m2 = ep4.getMessage(); - if (m2) { - EXPECT_EQ(m2->data.size(), 26U); - EXPECT_EQ(m2->time, helics::timeZero); + message2 = ep4.getMessage(); + if (message2) { + EXPECT_EQ(message2->data.size(), 26U); + EXPECT_EQ(message2->time, helics::timeZero); } mFed2->finalize(); @@ -1163,14 +1167,14 @@ TEST_F(mfed_tests, reentrant_fed_endpoint) // check the messages EXPECT_TRUE(ept1.hasMessage()); EXPECT_TRUE(ept2.hasMessage()); - auto m = ept1.getMessage(); - if (m) { - EXPECT_EQ(m->to_string(), "test_from2"); + auto message = ept1.getMessage(); + if (message) { + EXPECT_EQ(message->to_string(), "test_from2"); } - m = ept2.getMessage(); - if (m) { - EXPECT_EQ(m->to_string(), "test_from1"); + message = ept2.getMessage(); + if (message) { + EXPECT_EQ(message->to_string(), "test_from1"); } // close and reconnect federate auto mFed2Name = mFed2->getName(); @@ -1207,9 +1211,9 @@ TEST_F(mfed_tests, reentrant_fed_endpoint) // check the new messages EXPECT_TRUE(ept1.hasMessage()); - m = ept1.getMessage(); - if (m) { - EXPECT_EQ(m->to_string(), "test_from2_part2"); + message = ept1.getMessage(); + if (message) { + EXPECT_EQ(message->to_string(), "test_from2_part2"); } mFed1->disconnect(); @@ -1220,9 +1224,9 @@ TEST_F(mfed_tests, reentrant_fed_endpoint) tres = mFed2Redo.requestNextStep(); EXPECT_EQ(tres, 5.0); EXPECT_TRUE(ept2redo.hasMessage()); - m = ept2redo.getMessage(); - if (m) { - EXPECT_EQ(m->to_string(), "test_from1_part2"); + message = ept2redo.getMessage(); + if (message) { + EXPECT_EQ(message->to_string(), "test_from1_part2"); } mFed2Redo.disconnect(); } diff --git a/tests/helics/test_files/filter_test1.json b/tests/helics/test_files/filter_test1.json new file mode 100644 index 0000000000..55015d2821 --- /dev/null +++ b/tests/helics/test_files/filter_test1.json @@ -0,0 +1,30 @@ +{ + "name": "filt_test1", + "coretype": "test", + "coreinitstring": "--autobroker", + "defaultglobal": true, + "period": 1.0, + + "endpoints": [ + { + "name": "ept1", + "destinationtargets": "ept2" + }, + { + "name": "ept2" + }, + { + "name": "ept3" + } + ], + "filters": [ + { + "operation": "delay", + "sourcetargets": "ept1", + "properties": { + "value": 1.8, + "name": "delay" + } + } + ] +} diff --git a/tests/helics/test_files/filter_test2.json b/tests/helics/test_files/filter_test2.json new file mode 100644 index 0000000000..fb2303cf7d --- /dev/null +++ b/tests/helics/test_files/filter_test2.json @@ -0,0 +1,33 @@ +{ + "name": "filt_test1", + "coretype": "test", + "coreinitstring": "--autobroker", + "defaultglobal": true, + "period": 1.0, + + "endpoints": [ + { + "name": "ept1", + "destinationtargets": "ept2", + "targeted": true + }, + { + "name": "ept2", + "targeted": true + }, + { + "name": "ept3", + "targeted": true + } + ], + "filters": [ + { + "operation": "delay", + "sourcetargets": "ept1", + "properties": { + "value": 1.8, + "name": "delay" + } + } + ] +} diff --git a/tests/helics/test_files/filter_test3.json b/tests/helics/test_files/filter_test3.json new file mode 100644 index 0000000000..09e0f8f4bd --- /dev/null +++ b/tests/helics/test_files/filter_test3.json @@ -0,0 +1,32 @@ +{ + "name": "filt_test1", + "coretype": "test", + "coreinitstring": "--autobroker", + "defaultglobal": true, + "period": 1.0, + + "endpoints": [ + { + "name": "ept1", + "destinationtargets": "ept2", + "targeted": true + }, + { + "name": "ept2", + "targeted": true + }, + { + "name": "ept3" + } + ], + "filters": [ + { + "operation": "reroute", + "sourcetargets": "ept1", + "properties": { + "value": "ept3", + "name": "newdestination" + } + } + ] +} diff --git a/tests/helics/test_files/filter_test4.json b/tests/helics/test_files/filter_test4.json new file mode 100644 index 0000000000..4cf871426b --- /dev/null +++ b/tests/helics/test_files/filter_test4.json @@ -0,0 +1,29 @@ +{ + "name": "filt_test1", + "coretype": "test", + "coreinitstring": "--autobroker", + "defaultglobal": true, + "period": 1.0, + + "endpoints": [ + { + "name": "ept1", + "destinationtargets": "ept2", + "targeted": true + }, + { + "name": "ept2", + "targeted": true + }, + { + "name": "ept3" + } + ], + "filters": [ + { + "sourcetargets": "ept1", + "cloning": true, + "delivery": "ept3" + } + ] +} diff --git a/tests/helics/test_files/filter_test5.json b/tests/helics/test_files/filter_test5.json new file mode 100644 index 0000000000..43570f5f13 --- /dev/null +++ b/tests/helics/test_files/filter_test5.json @@ -0,0 +1,28 @@ +{ + "name": "filt_test1", + "coretype": "test", + "coreinitstring": "--autobroker", + "defaultglobal": true, + "period": 1.0, + + "endpoints": [ + { + "name": "ept1", + "destinationtargets": "ept2" + }, + { + "name": "ept2" + }, + { + "name": "ept3" + } + ], + "filters": [ + { + "destinationtargets": "ept2", + "cloning": true, + "operation": "cloning", + "delivery": "ept3" + } + ] +}