From d8e4f8a7156742a445d6fe26b09e0c86525a7154 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Mon, 25 Jan 2021 15:21:01 +0100 Subject: [PATCH 01/26] iox-#454 create test file for class roudi Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi.cpp | 482 +++++++++++++++++++ 1 file changed, 482 insertions(+) create mode 100644 iceoryx_posh/test/moduletests/test_roudi.cpp diff --git a/iceoryx_posh/test/moduletests/test_roudi.cpp b/iceoryx_posh/test/moduletests/test_roudi.cpp new file mode 100644 index 0000000000..c73746afa3 --- /dev/null +++ b/iceoryx_posh/test/moduletests/test_roudi.cpp @@ -0,0 +1,482 @@ +// Copyright (c) 2021 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "iceoryx_posh/internal/roudi/roudi.hpp" +#include "iceoryx_posh/internal/roudi_environment/roudi_environment.hpp" +#include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp" +#include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/internal/runtime/message_queue_message.hpp" + +#include +#include +#include + +using namespace ::testing; +using ::testing::Return; + +using namespace iox::roudi; +using namespace iox::runtime; + +namespace iox +{ +namespace test +{ +/// @req IOX_SWRS_112, IOX_SWRS_200 +/// @brief Test goal: "This test suite verifies that the BaseClass function is verified" +/// @pre describe what needs to be done in setup() +/// @post describe what needs to be done in teardown() +/// @note name of the Testfixture should match to the Class you want to test + +class RoudiClassTest : public RouDi +{ +public: + RoudiClassTest(iox::roudi::RouDiMemoryInterface& roudiMemoryInterface, + iox::roudi::PortManager& portManager, + iox::roudi::RouDi::RoudiStartupParameters roudiStartupParameters): RouDi(roudiMemoryInterface, portManager, roudiStartupParameters) + { + } + + void startMQThreadTest() + { + this->startMQThread(); + } + + void shutDownTest() + { + this->shutdown(); + } + + void processMessageTest(const runtime::MqMessage& message, + const iox::runtime::MqMessageType& cmd, + const ProcessName_t& processName) + { + this->processMessage(message, + cmd, + processName); + } + + const PortManager* getPortManager() + { + return m_portManager; + } +}; + +class RouDiBaseClass_test : public Test +{ + public: + + +}; + +TEST_F(RouDiBaseClass_test, ConstructorIsSuccessfull) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, false})); + + EXPECT_THAT(m_roudiApp, Not(Eq(nullptr))); + + m_roudiApp->shutDownTest(); +} + +TEST_F(RouDiBaseClass_test, ConstructorThreadStartNotImmediateIsSuccessfull) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, false, RouDi::MQThreadStart::DEFER_START})); + + m_roudiApp->startMQThreadTest(); + + EXPECT_DEATH(m_roudiApp->startMQThreadTest(), ".*"); + + m_roudiApp->shutDownTest(); +} + +TEST_F(RouDiBaseClass_test, ShutDownKillProcessInDestructorTrueIsSuccessfull) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "AppName" << "123123" << "456" << "789" << "123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +TEST_F(RouDiBaseClass_test, ShutDownCalledTwoTimesIsSuccessfull) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + m_roudiApp->shutDownTest(); + + m_roudiApp->shutDownTest(); +} + +TEST_F(RouDiBaseClass_test, SendCorrectRegMessagetoRoudiReturnSuccessfullySent) +{ + const iox::ProcessName_t m_runtimeName{"App"}; + RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; + PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; + + MqMessage message; + MqMessage m_receiveBuffer; + const iox::NodeName_t m_nodeName{"testNode"}; + message << mqMessageTypeToString(MqMessageType::REG) << "App" << std::to_string(getpid()) + << std::to_string(posix::PosixUser::getUserOfCurrentProcess().getID()) + << std::to_string(0) + << static_cast(version::VersionInfo::getCurrentVersion()).toString(); + + const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); + + EXPECT_TRUE(m_receiveBuffer.isValid()); + EXPECT_TRUE(successfullySent); +} + +TEST_F(RouDiBaseClass_test, SendWrongRegMessagetoRoudiReturnError) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::REG) + << "App" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); +} + +TEST_F(RouDiBaseClass_test, ProcessMessageChangeCounter) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::SERVICE_REGISTRY_CHANGE_COUNTER) + << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisher) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + const iox::NodeName_t m_nodeName{"testNode"}; + message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "m_appName" + << static_cast(iox::capro::ServiceDescription(99U, 1U, 20U)).toString() << std::to_string(13U) + << m_nodeName << static_cast(iox::runtime::PortConfigInfo(11U, 22U, 33U)).toString(); + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisherError) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriber) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << "AppName" << "123123" << "456" << "789" << "123" << "abc"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriberError) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariable) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << "AppName"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariableError) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterface) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << "AppName" << "123123" << "456"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterfaceError) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplication) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_APPLICATION) << "AppName"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplicationError) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_APPLICATION) << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateNode) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName" << "123123" << "456"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageCreateNodeError) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageFindService) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageFindServiceError) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << "AppName"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageKeepAlive) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::KEEPALIVE) << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +/// @note name of the Testcase shall describe the test case in detail to avoid additional comments +TEST_F(RouDiBaseClass_test, ProcessMessageError) +{ + std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + + MqMessage message; + message << mqMessageTypeToString(MqMessageType::ERROR) << "AppName" << "123123"; + auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); + std::string processName = message.getElementAtIndex(1); + + m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + + m_roudiApp->shutDownTest(); +} + +} // namespace test +} // namespace iox From ea8b73571775f4c518d895209acae09739c4598f Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Tue, 26 Jan 2021 17:09:30 +0100 Subject: [PATCH 02/26] iox-#454 clang format test file Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi.cpp | 393 +++++++++++-------- 1 file changed, 228 insertions(+), 165 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi.cpp b/iceoryx_posh/test/moduletests/test_roudi.cpp index c73746afa3..e1e18b53d8 100644 --- a/iceoryx_posh/test/moduletests/test_roudi.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi.cpp @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/roudi/roudi.hpp" #include "iceoryx_posh/internal/roudi_environment/roudi_environment.hpp" -#include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp" -#include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/runtime/message_queue_message.hpp" +#include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp" +#include "iceoryx_posh/runtime/posh_runtime.hpp" #include #include @@ -41,11 +41,12 @@ namespace test class RoudiClassTest : public RouDi { -public: + public: RoudiClassTest(iox::roudi::RouDiMemoryInterface& roudiMemoryInterface, - iox::roudi::PortManager& portManager, - iox::roudi::RouDi::RoudiStartupParameters roudiStartupParameters): RouDi(roudiMemoryInterface, portManager, roudiStartupParameters) - { + iox::roudi::PortManager& portManager, + iox::roudi::RouDi::RoudiStartupParameters roudiStartupParameters) + : RouDi(roudiMemoryInterface, portManager, roudiStartupParameters) + { } void startMQThreadTest() @@ -59,12 +60,10 @@ class RoudiClassTest : public RouDi } void processMessageTest(const runtime::MqMessage& message, - const iox::runtime::MqMessageType& cmd, - const ProcessName_t& processName) + const iox::runtime::MqMessageType& cmd, + const ProcessName_t& processName) { - this->processMessage(message, - cmd, - processName); + this->processMessage(message, cmd, processName); } const PortManager* getPortManager() @@ -76,59 +75,69 @@ class RoudiClassTest : public RouDi class RouDiBaseClass_test : public Test { public: - - }; TEST_F(RouDiBaseClass_test, ConstructorIsSuccessfull) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, false})); + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, false})); - EXPECT_THAT(m_roudiApp, Not(Eq(nullptr))); + EXPECT_NE(m_roudiApp, nullptr); m_roudiApp->shutDownTest(); } TEST_F(RouDiBaseClass_test, ConstructorThreadStartNotImmediateIsSuccessfull) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, false, RouDi::MQThreadStart::DEFER_START})); + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest( + m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, false, RouDi::MQThreadStart::DEFER_START})); m_roudiApp->startMQThreadTest(); EXPECT_DEATH(m_roudiApp->startMQThreadTest(), ".*"); - + m_roudiApp->shutDownTest(); } TEST_F(RouDiBaseClass_test, ShutDownKillProcessInDestructorTrueIsSuccessfull) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "AppName" << "123123" << "456" << "789" << "123"; + message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "AppName" + << "123123" + << "456" + << "789" + << "123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); + std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } TEST_F(RouDiBaseClass_test, ShutDownCalledTwoTimesIsSuccessfull) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + m_roudiApp->shutDownTest(); m_roudiApp->shutDownTest(); @@ -144,9 +153,8 @@ TEST_F(RouDiBaseClass_test, SendCorrectRegMessagetoRoudiReturnSuccessfullySent) MqMessage m_receiveBuffer; const iox::NodeName_t m_nodeName{"testNode"}; message << mqMessageTypeToString(MqMessageType::REG) << "App" << std::to_string(getpid()) - << std::to_string(posix::PosixUser::getUserOfCurrentProcess().getID()) - << std::to_string(0) - << static_cast(version::VersionInfo::getCurrentVersion()).toString(); + << std::to_string(posix::PosixUser::getUserOfCurrentProcess().getID()) << std::to_string(0) + << static_cast(version::VersionInfo::getCurrentVersion()).toString(); const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); @@ -156,54 +164,61 @@ TEST_F(RouDiBaseClass_test, SendCorrectRegMessagetoRoudiReturnSuccessfullySent) TEST_F(RouDiBaseClass_test, SendWrongRegMessagetoRoudiReturnError) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); MqMessage message; - message << mqMessageTypeToString(MqMessageType::REG) - << "App" << "123123"; + message << mqMessageTypeToString(MqMessageType::REG) << "App" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); + std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); } TEST_F(RouDiBaseClass_test, ProcessMessageChangeCounter) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::SERVICE_REGISTRY_CHANGE_COUNTER) - << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::SERVICE_REGISTRY_CHANGE_COUNTER) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisher) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); MqMessage message; const iox::NodeName_t m_nodeName{"testNode"}; message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "m_appName" - << static_cast(iox::capro::ServiceDescription(99U, 1U, 20U)).toString() << std::to_string(13U) - << m_nodeName << static_cast(iox::runtime::PortConfigInfo(11U, 22U, 33U)).toString(); + << static_cast(iox::capro::ServiceDescription(99U, 1U, 20U)).toString() + << std::to_string(13U) << m_nodeName + << static_cast(iox::runtime::PortConfigInfo(11U, 22U, 33U)).toString(); auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -211,17 +226,20 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisher) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisherError) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -229,17 +247,24 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisherError) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriber) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << "AppName" << "123123" << "456" << "789" << "123" << "abc"; + message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << "AppName" + << "123123" + << "456" + << "789" + << "123" + << "abc"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -247,17 +272,20 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriber) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriberError) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -265,17 +293,19 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriberError) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariable) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << "AppName"; + message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << "AppName"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -283,17 +313,20 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariable) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariableError) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -301,17 +334,21 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariableError) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterface) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << "AppName" << "123123" << "456"; + message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << "AppName" + << "123123" + << "456"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -319,17 +356,20 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterface) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterfaceError) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -337,17 +377,19 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterfaceError) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplication) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; message << mqMessageTypeToString(MqMessageType::CREATE_APPLICATION) << "AppName"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -355,17 +397,20 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplication) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplicationError) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_APPLICATION) << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::CREATE_APPLICATION) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -373,17 +418,21 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplicationError) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateNode) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName" << "123123" << "456"; + message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName" + << "123123" + << "456"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -391,17 +440,20 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateNode) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateNodeError) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -409,17 +461,20 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateNodeError) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageFindService) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -427,17 +482,19 @@ TEST_F(RouDiBaseClass_test, ProcessMessageFindService) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageFindServiceError) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; message << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << "AppName"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -445,17 +502,20 @@ TEST_F(RouDiBaseClass_test, ProcessMessageFindServiceError) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageKeepAlive) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::KEEPALIVE) << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::KEEPALIVE) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } @@ -463,17 +523,20 @@ TEST_F(RouDiBaseClass_test, ProcessMessageKeepAlive) /// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageError) { - std::unique_ptr m_roudiComponents = std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - + std::unique_ptr m_roudiComponents = + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr m_roudiApp = std::unique_ptr( + new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, + m_roudiComponents->m_portManager, + RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + MqMessage message; - message << mqMessageTypeToString(MqMessageType::ERROR) << "AppName" << "123123"; + message << mqMessageTypeToString(MqMessageType::ERROR) << "AppName" + << "123123"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message,cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); m_roudiApp->shutDownTest(); } From c169306c841fa720f844ec85fe91339bd177af6b Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Mon, 25 Jan 2021 16:39:33 +0100 Subject: [PATCH 03/26] iox-#454 Add unit tests to improve coverage for class roudi_portmanager Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index ec82fec66b..97cc5d5cb9 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -562,3 +562,114 @@ TEST_F(PortManager_test, PortDestroy) } } } + +TEST_F(PortManager_test, Nodeoverflow) +{ + std::string nodename = "nodeName"; + + for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) + { + auto newNodeName = nodename + std::to_string(i); + auto newNodeData = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName),iox::NodeName_t(iox::cxx::TruncateToCapacity,newNodeName)); + EXPECT_THAT(newNodeData, Ne(nullptr)); + } + + { // test if overflow errors get hit + + auto errorHandlerCalled{false}; + auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { + errorHandlerCalled = true; + }); + + auto nodePointer = m_portManager->acquireNodeData("Processnode","node"); + EXPECT_THAT(nodePointer, Eq(nullptr)); + EXPECT_TRUE(errorHandlerCalled); + } + + // delete one and add one should be possible now + { + unsigned int testi = 0; + auto newNodeName = nodename + std::to_string(testi); + m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName)); + + auto nodePointer = m_portManager->acquireNodeData( + iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName),iox::NodeName_t(iox::cxx::TruncateToCapacity,newNodeName)); + EXPECT_THAT(nodePointer, Ne(nullptr)); + } +} + +TEST_F(PortManager_test, NodeDestroy) +{ + std::vector nodeContainer; + std::string nodeName = "nodeName"; + + // first aquire all possible condition variables + for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) + { + auto newnodeName = nodeName + std::to_string(i); + auto nodeDataResult = m_portManager->acquireNodeData("Process",iox::NodeName_t(iox::cxx::TruncateToCapacity,newnodeName)); + EXPECT_THAT(nodeDataResult, Ne(nullptr)); + nodeContainer.push_back(nodeDataResult); + } + + // so now no one should be available + { + auto nodeDataResult = m_portManager->acquireNodeData("Process","node"); + EXPECT_THAT(nodeDataResult, Eq(nullptr)); + } + + // set the destroy flag and let the discovery loop take care + for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) + { + nodeContainer[i]->m_toBeDestroyed.store(true, std::memory_order_relaxed); + } + m_portManager->doDiscovery(); + nodeContainer.clear(); // These pointers are dangling now + + // so we should able to get some more now + for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) + { + auto nodeDataResult = m_portManager->acquireNodeData("Process","node"); + EXPECT_THAT(nodeDataResult, Ne(nullptr)); + } +} + +TEST_F(PortManager_test, InterfaceDestroy) +{ + std::vector interfaceContainer; + + std::string process = "process"; + + std::string itf = "itf"; + + // first aquire all possible condition variables + for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) + { + auto newItfName = itf + std::to_string(i); + auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); + EXPECT_THAT(interp, Ne(nullptr)); + interfaceContainer.push_back(interp); + } + + // so now no one should be available + { + auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL,"process"); + EXPECT_THAT(interp, Eq(nullptr)); + } + + // set the destroy flag and let the discovery loop take care + for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) + { + interfaceContainer[i]->m_toBeDestroyed.store(true, std::memory_order_relaxed); + } + m_portManager->doDiscovery(); + interfaceContainer.clear(); // These pointers are dangling now + + // so we should able to get some more now + for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) + { + auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL,"process"); + EXPECT_THAT(interp, Ne(nullptr)); + } +} From bb1fdb3f51e8d1859a1c1034e5302a10a16eec03 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Mon, 25 Jan 2021 21:00:24 +0100 Subject: [PATCH 04/26] iox-#454 Add unit test ServiceRegistryChangeCounter and clean for class roudi_portmanager Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 46 +++++++++++++++---- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 97cc5d5cb9..22c5059f96 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -119,6 +119,11 @@ class PortManager_test : public Test iox::cxx::GenericRAII m_uniqueRouDiId{[] { iox::popo::internal::setUniqueRouDiId(0); }, [] { iox::popo::internal::unsetUniqueRouDiId(); }}; + + void InterOpWait() + { + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + } }; @@ -563,14 +568,15 @@ TEST_F(PortManager_test, PortDestroy) } } -TEST_F(PortManager_test, Nodeoverflow) +TEST_F(PortManager_test, CheckNodeoverflow) { std::string nodename = "nodeName"; for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) { auto newNodeName = nodename + std::to_string(i); - auto newNodeData = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName),iox::NodeName_t(iox::cxx::TruncateToCapacity,newNodeName)); + auto newNodeData = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName), + iox::NodeName_t(iox::cxx::TruncateToCapacity, newNodeName)); EXPECT_THAT(newNodeData, Ne(nullptr)); } @@ -582,7 +588,7 @@ TEST_F(PortManager_test, Nodeoverflow) errorHandlerCalled = true; }); - auto nodePointer = m_portManager->acquireNodeData("Processnode","node"); + auto nodePointer = m_portManager->acquireNodeData("Processnode", "node"); EXPECT_THAT(nodePointer, Eq(nullptr)); EXPECT_TRUE(errorHandlerCalled); } @@ -593,8 +599,8 @@ TEST_F(PortManager_test, Nodeoverflow) auto newNodeName = nodename + std::to_string(testi); m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName)); - auto nodePointer = m_portManager->acquireNodeData( - iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName),iox::NodeName_t(iox::cxx::TruncateToCapacity,newNodeName)); + auto nodePointer = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName), + iox::NodeName_t(iox::cxx::TruncateToCapacity, newNodeName)); EXPECT_THAT(nodePointer, Ne(nullptr)); } } @@ -608,14 +614,15 @@ TEST_F(PortManager_test, NodeDestroy) for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) { auto newnodeName = nodeName + std::to_string(i); - auto nodeDataResult = m_portManager->acquireNodeData("Process",iox::NodeName_t(iox::cxx::TruncateToCapacity,newnodeName)); + auto nodeDataResult = + m_portManager->acquireNodeData("Process", iox::NodeName_t(iox::cxx::TruncateToCapacity, newnodeName)); EXPECT_THAT(nodeDataResult, Ne(nullptr)); nodeContainer.push_back(nodeDataResult); } // so now no one should be available { - auto nodeDataResult = m_portManager->acquireNodeData("Process","node"); + auto nodeDataResult = m_portManager->acquireNodeData("Process", "node"); EXPECT_THAT(nodeDataResult, Eq(nullptr)); } @@ -630,7 +637,7 @@ TEST_F(PortManager_test, NodeDestroy) // so we should able to get some more now for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) { - auto nodeDataResult = m_portManager->acquireNodeData("Process","node"); + auto nodeDataResult = m_portManager->acquireNodeData("Process", "node"); EXPECT_THAT(nodeDataResult, Ne(nullptr)); } } @@ -654,7 +661,7 @@ TEST_F(PortManager_test, InterfaceDestroy) // so now no one should be available { - auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL,"process"); + auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); EXPECT_THAT(interp, Eq(nullptr)); } @@ -669,7 +676,26 @@ TEST_F(PortManager_test, InterfaceDestroy) // so we should able to get some more now for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) { - auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL,"process"); + auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); EXPECT_THAT(interp, Ne(nullptr)); } } + +TEST_F(PortManager_test, ServiceRegistryChangeCounter) +{ + auto serviceCounter = m_portManager->serviceRegistryChangeCounter(); + auto initialCout = serviceCounter->load(); + PublisherOptions publisherOptions{1}; + + PublisherPortUser publisher( + m_portManager + ->acquirePublisherPortData( + {1, 1, 1}, publisherOptions, "guiseppe", m_payloadMemoryManager, "node", PortConfigInfo()) + .value()); + + publisher.offer(); + m_portManager->doDiscovery(); + this->InterOpWait(); + + EXPECT_TRUE(initialCout + 1 == serviceCounter->load()); +} From a71cc4bf3a27d7e6b03a2d62bf4bf30a2d74ce1d Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Tue, 26 Jan 2021 17:09:49 +0100 Subject: [PATCH 05/26] iox-#454 merge improve-coverage-of-unit-test-in-folder-roudi Signed-off-by: Jimmy Belloche From 8e6b7d76468f47bcb883ba37556fde4f1c32c773 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Tue, 26 Jan 2021 17:20:24 +0100 Subject: [PATCH 06/26] iox-#454 Change test names and use uint32_t Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 22c5059f96..f99ac143de 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -568,11 +568,11 @@ TEST_F(PortManager_test, PortDestroy) } } -TEST_F(PortManager_test, CheckNodeoverflow) +TEST_F(PortManager_test, CheckNodeOverflowErrorReturnsnullptrForAcquireNodeData) { std::string nodename = "nodeName"; - for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) + for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) { auto newNodeName = nodename + std::to_string(i); auto newNodeData = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName), @@ -605,13 +605,13 @@ TEST_F(PortManager_test, CheckNodeoverflow) } } -TEST_F(PortManager_test, NodeDestroy) +TEST_F(PortManager_test, UseDestroyNodeReturnsNotNullPtrToAcquireNodeData) { std::vector nodeContainer; std::string nodeName = "nodeName"; // first aquire all possible condition variables - for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) + for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) { auto newnodeName = nodeName + std::to_string(i); auto nodeDataResult = @@ -627,7 +627,7 @@ TEST_F(PortManager_test, NodeDestroy) } // set the destroy flag and let the discovery loop take care - for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) + for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) { nodeContainer[i]->m_toBeDestroyed.store(true, std::memory_order_relaxed); } @@ -635,14 +635,14 @@ TEST_F(PortManager_test, NodeDestroy) nodeContainer.clear(); // These pointers are dangling now // so we should able to get some more now - for (unsigned int i = 0; i < iox::MAX_NODE_NUMBER; i++) + for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) { auto nodeDataResult = m_portManager->acquireNodeData("Process", "node"); EXPECT_THAT(nodeDataResult, Ne(nullptr)); } } -TEST_F(PortManager_test, InterfaceDestroy) +TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfacePortData) { std::vector interfaceContainer; @@ -651,7 +651,7 @@ TEST_F(PortManager_test, InterfaceDestroy) std::string itf = "itf"; // first aquire all possible condition variables - for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) + for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) { auto newItfName = itf + std::to_string(i); auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); @@ -666,7 +666,7 @@ TEST_F(PortManager_test, InterfaceDestroy) } // set the destroy flag and let the discovery loop take care - for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) + for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) { interfaceContainer[i]->m_toBeDestroyed.store(true, std::memory_order_relaxed); } @@ -674,17 +674,17 @@ TEST_F(PortManager_test, InterfaceDestroy) interfaceContainer.clear(); // These pointers are dangling now // so we should able to get some more now - for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) + for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) { auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); EXPECT_THAT(interp, Ne(nullptr)); } } -TEST_F(PortManager_test, ServiceRegistryChangeCounter) +TEST_F(PortManager_test, OfferPublisherServiceReturnsServiceRegistryChangeCounter) { auto serviceCounter = m_portManager->serviceRegistryChangeCounter(); - auto initialCout = serviceCounter->load(); + auto initialCount = serviceCounter->load(); PublisherOptions publisherOptions{1}; PublisherPortUser publisher( @@ -697,5 +697,5 @@ TEST_F(PortManager_test, ServiceRegistryChangeCounter) m_portManager->doDiscovery(); this->InterOpWait(); - EXPECT_TRUE(initialCout + 1 == serviceCounter->load()); + EXPECT_TRUE(initialCount + 1 == serviceCounter->load()); } From a5a0274c6a747961b59b93cee0aad4d41be55f33 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Tue, 26 Jan 2021 17:33:45 +0100 Subject: [PATCH 07/26] iox-#454 Use EXPECT_EQ and EXPECT_NE in place of EXPECT_THAT Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index f99ac143de..aa34d544fb 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -575,9 +575,9 @@ TEST_F(PortManager_test, CheckNodeOverflowErrorReturnsnullptrForAcquireNodeData) for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) { auto newNodeName = nodename + std::to_string(i); - auto newNodeData = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName), + auto nodePointer = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName), iox::NodeName_t(iox::cxx::TruncateToCapacity, newNodeName)); - EXPECT_THAT(newNodeData, Ne(nullptr)); + EXPECT_NE(nodePointer, nullptr); } { // test if overflow errors get hit @@ -589,7 +589,7 @@ TEST_F(PortManager_test, CheckNodeOverflowErrorReturnsnullptrForAcquireNodeData) }); auto nodePointer = m_portManager->acquireNodeData("Processnode", "node"); - EXPECT_THAT(nodePointer, Eq(nullptr)); + EXPECT_EQ(nodePointer, nullptr); EXPECT_TRUE(errorHandlerCalled); } @@ -601,7 +601,7 @@ TEST_F(PortManager_test, CheckNodeOverflowErrorReturnsnullptrForAcquireNodeData) auto nodePointer = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName), iox::NodeName_t(iox::cxx::TruncateToCapacity, newNodeName)); - EXPECT_THAT(nodePointer, Ne(nullptr)); + EXPECT_NE(nodePointer, nullptr); } } @@ -616,14 +616,14 @@ TEST_F(PortManager_test, UseDestroyNodeReturnsNotNullPtrToAcquireNodeData) auto newnodeName = nodeName + std::to_string(i); auto nodeDataResult = m_portManager->acquireNodeData("Process", iox::NodeName_t(iox::cxx::TruncateToCapacity, newnodeName)); - EXPECT_THAT(nodeDataResult, Ne(nullptr)); + EXPECT_NE(nodeDataResult, nullptr); nodeContainer.push_back(nodeDataResult); } // so now no one should be available { auto nodeDataResult = m_portManager->acquireNodeData("Process", "node"); - EXPECT_THAT(nodeDataResult, Eq(nullptr)); + EXPECT_EQ(nodeDataResult, nullptr); } // set the destroy flag and let the discovery loop take care @@ -638,7 +638,7 @@ TEST_F(PortManager_test, UseDestroyNodeReturnsNotNullPtrToAcquireNodeData) for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) { auto nodeDataResult = m_portManager->acquireNodeData("Process", "node"); - EXPECT_THAT(nodeDataResult, Ne(nullptr)); + EXPECT_NE(nodeDataResult, nullptr); } } @@ -655,14 +655,14 @@ TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfaceP { auto newItfName = itf + std::to_string(i); auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); - EXPECT_THAT(interp, Ne(nullptr)); + EXPECT_NE(interp, nullptr); interfaceContainer.push_back(interp); } // so now no one should be available { auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); - EXPECT_THAT(interp, Eq(nullptr)); + EXPECT_EQ(interp, nullptr); } // set the destroy flag and let the discovery loop take care @@ -677,7 +677,7 @@ TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfaceP for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) { auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); - EXPECT_THAT(interp, Ne(nullptr)); + EXPECT_NE(interp, nullptr); } } From 06a1fb380d073828f1b4bb59e7b9447837804558 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Tue, 26 Jan 2021 18:22:52 +0100 Subject: [PATCH 08/26] iox-#454 Define process name and node name in test base Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index aa34d544fb..a24a1b5fdc 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -61,6 +61,10 @@ class PortManager_test : public Test PortManagerTester* m_portManager{nullptr}; uint16_t m_instIdCounter, m_eventIdCounter, m_sIdCounter; + + iox::ProcessName_t m_Process{"TestProcess"}; + iox::NodeName_t m_Node{"TestNode"}; + void SetUp() override { testing::internal::CaptureStderr(); @@ -588,7 +592,7 @@ TEST_F(PortManager_test, CheckNodeOverflowErrorReturnsnullptrForAcquireNodeData) errorHandlerCalled = true; }); - auto nodePointer = m_portManager->acquireNodeData("Processnode", "node"); + auto nodePointer = m_portManager->acquireNodeData(m_Process, m_Node); EXPECT_EQ(nodePointer, nullptr); EXPECT_TRUE(errorHandlerCalled); } @@ -615,14 +619,14 @@ TEST_F(PortManager_test, UseDestroyNodeReturnsNotNullPtrToAcquireNodeData) { auto newnodeName = nodeName + std::to_string(i); auto nodeDataResult = - m_portManager->acquireNodeData("Process", iox::NodeName_t(iox::cxx::TruncateToCapacity, newnodeName)); + m_portManager->acquireNodeData(m_Process, iox::NodeName_t(iox::cxx::TruncateToCapacity, newnodeName)); EXPECT_NE(nodeDataResult, nullptr); nodeContainer.push_back(nodeDataResult); } // so now no one should be available { - auto nodeDataResult = m_portManager->acquireNodeData("Process", "node"); + auto nodeDataResult = m_portManager->acquireNodeData(m_Process, m_Node); EXPECT_EQ(nodeDataResult, nullptr); } @@ -637,7 +641,7 @@ TEST_F(PortManager_test, UseDestroyNodeReturnsNotNullPtrToAcquireNodeData) // so we should able to get some more now for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) { - auto nodeDataResult = m_portManager->acquireNodeData("Process", "node"); + auto nodeDataResult = m_portManager->acquireNodeData(m_Process, m_Node); EXPECT_NE(nodeDataResult, nullptr); } } @@ -645,23 +649,21 @@ TEST_F(PortManager_test, UseDestroyNodeReturnsNotNullPtrToAcquireNodeData) TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfacePortData) { std::vector interfaceContainer; - - std::string process = "process"; - std::string itf = "itf"; // first aquire all possible condition variables for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) { auto newItfName = itf + std::to_string(i); - auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); + auto interp = m_portManager->acquireInterfacePortData( + iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); EXPECT_NE(interp, nullptr); interfaceContainer.push_back(interp); } // so now no one should be available { - auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); + auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, m_Process); EXPECT_EQ(interp, nullptr); } @@ -676,7 +678,7 @@ TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfaceP // so we should able to get some more now for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) { - auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "process"); + auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, m_Process); EXPECT_NE(interp, nullptr); } } @@ -690,7 +692,7 @@ TEST_F(PortManager_test, OfferPublisherServiceReturnsServiceRegistryChangeCounte PublisherPortUser publisher( m_portManager ->acquirePublisherPortData( - {1, 1, 1}, publisherOptions, "guiseppe", m_payloadMemoryManager, "node", PortConfigInfo()) + {1, 1, 1}, publisherOptions, m_Process, m_payloadMemoryManager, m_Node, PortConfigInfo()) .value()); publisher.offer(); From 3c914ec1d03110401bd3879620a37af90cb82c92 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Mon, 1 Feb 2021 14:12:35 +0100 Subject: [PATCH 09/26] iox-#454 improve unit test for class roudi Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi.cpp | 206 ++++++++----------- 1 file changed, 85 insertions(+), 121 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi.cpp b/iceoryx_posh/test/moduletests/test_roudi.cpp index e1e18b53d8..95e0b50cf6 100644 --- a/iceoryx_posh/test/moduletests/test_roudi.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi.cpp @@ -33,11 +33,7 @@ namespace iox { namespace test { -/// @req IOX_SWRS_112, IOX_SWRS_200 -/// @brief Test goal: "This test suite verifies that the BaseClass function is verified" -/// @pre describe what needs to be done in setup() -/// @post describe what needs to be done in teardown() -/// @note name of the Testfixture should match to the Class you want to test +/// @brief Test goal: Verify base class roudi class RoudiClassTest : public RouDi { @@ -165,7 +161,7 @@ TEST_F(RouDiBaseClass_test, SendCorrectRegMessagetoRoudiReturnSuccessfullySent) TEST_F(RouDiBaseClass_test, SendWrongRegMessagetoRoudiReturnError) { std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); + std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().optimize())); std::unique_ptr m_roudiApp = std::unique_ptr( new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, m_roudiComponents->m_portManager, @@ -182,48 +178,43 @@ TEST_F(RouDiBaseClass_test, SendWrongRegMessagetoRoudiReturnError) TEST_F(RouDiBaseClass_test, ProcessMessageChangeCounter) { - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + const iox::ProcessName_t m_runtimeName{"App"}; + RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; + PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; MqMessage message; - message << mqMessageTypeToString(MqMessageType::SERVICE_REGISTRY_CHANGE_COUNTER) << "AppName" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); + MqMessage m_receiveBuffer; + message << mqMessageTypeToString(MqMessageType::SERVICE_REGISTRY_CHANGE_COUNTER) << m_runtimeName; - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - m_roudiApp->shutDownTest(); + EXPECT_TRUE(m_receiveBuffer.isValid()); + EXPECT_TRUE(successfullySent); } TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisher) { - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + const iox::ProcessName_t m_runtimeName{"App"}; + RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; + PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; MqMessage message; + MqMessage m_receiveBuffer; + iox::popo::PublisherOptions publisherOptions; + publisherOptions.historyCapacity = 13U; const iox::NodeName_t m_nodeName{"testNode"}; - message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "m_appName" + + message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << m_runtimeName << static_cast(iox::capro::ServiceDescription(99U, 1U, 20U)).toString() - << std::to_string(13U) << m_nodeName + << std::to_string(publisherOptions.historyCapacity) << m_nodeName << static_cast(iox::runtime::PortConfigInfo(11U, 22U, 33U)).toString(); - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - m_roudiApp->shutDownTest(); + EXPECT_TRUE(m_receiveBuffer.isValid()); + EXPECT_TRUE(successfullySent); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisherError) { std::unique_ptr m_roudiComponents = @@ -244,32 +235,30 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisherError) m_roudiApp->shutDownTest(); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriber) { - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + const iox::ProcessName_t m_runtimeName{"App"}; + RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; + PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << "AppName" - << "123123" - << "456" - << "789" - << "123" - << "abc"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); + MqMessage m_receiveBuffer; + iox::popo::SubscriberOptions subscriberOptions; + subscriberOptions.historyRequest = 13U; + subscriberOptions.queueCapacity = 42U; + const iox::NodeName_t m_nodeName{"testNode"}; - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << m_runtimeName + << static_cast(iox::capro::ServiceDescription(99U, 1U, 20U)).toString() + << std::to_string(subscriberOptions.historyRequest) << std::to_string(subscriberOptions.queueCapacity) + << m_nodeName << static_cast(iox::runtime::PortConfigInfo(11U, 22U, 33U)).toString(); - m_roudiApp->shutDownTest(); + const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); + + EXPECT_TRUE(m_receiveBuffer.isValid()); + EXPECT_TRUE(successfullySent); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriberError) { std::unique_ptr m_roudiComponents = @@ -290,27 +279,22 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriberError) m_roudiApp->shutDownTest(); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariable) { - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + const iox::ProcessName_t m_runtimeName{"App"}; + RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; + PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << "AppName"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); + MqMessage m_receiveBuffer; + message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << m_runtimeName; - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - m_roudiApp->shutDownTest(); + EXPECT_TRUE(m_receiveBuffer.isValid()); + EXPECT_TRUE(successfullySent); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariableError) { std::unique_ptr m_roudiComponents = @@ -331,29 +315,24 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariableError) m_roudiApp->shutDownTest(); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterface) { - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + const iox::ProcessName_t m_runtimeName{"App"}; + RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; + PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; + const iox::NodeName_t m_nodeName{"testNode"}; MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << "AppName" - << "123123" - << "456"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); + MqMessage m_receiveBuffer; + message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << m_runtimeName + << static_cast(iox::capro::Interfaces::INTERNAL) << m_nodeName; - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - m_roudiApp->shutDownTest(); + EXPECT_TRUE(m_receiveBuffer.isValid()); + EXPECT_TRUE(successfullySent); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterfaceError) { std::unique_ptr m_roudiComponents = @@ -374,27 +353,22 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterfaceError) m_roudiApp->shutDownTest(); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplication) { - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + const iox::ProcessName_t m_runtimeName{"App"}; + RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; + PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_APPLICATION) << "AppName"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); + MqMessage m_receiveBuffer; + message << mqMessageTypeToString(MqMessageType::CREATE_APPLICATION) << m_runtimeName; - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - m_roudiApp->shutDownTest(); + EXPECT_TRUE(m_receiveBuffer.isValid()); + EXPECT_TRUE(successfullySent); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplicationError) { std::unique_ptr m_roudiComponents = @@ -415,29 +389,26 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplicationError) m_roudiApp->shutDownTest(); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateNode) { - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + const iox::ProcessName_t m_runtimeName{"App"}; + RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; + PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; + const iox::NodeName_t m_nodeName{"testNode"}; + const uint32_t nodeDeviceIdentifier = 1U; + iox::runtime::NodeProperty nodeProperty(m_nodeName, nodeDeviceIdentifier); MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName" - << "123123" - << "456"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); + MqMessage m_receiveBuffer; + message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << m_runtimeName + << static_cast(nodeProperty).toString(); - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - m_roudiApp->shutDownTest(); + EXPECT_TRUE(m_receiveBuffer.isValid()); + EXPECT_TRUE(successfullySent); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageCreateNodeError) { std::unique_ptr m_roudiComponents = @@ -458,28 +429,23 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateNodeError) m_roudiApp->shutDownTest(); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageFindService) { - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); + const iox::ProcessName_t m_runtimeName{"App"}; + RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; + PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; MqMessage message; - message << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << "AppName" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); + MqMessage m_receiveBuffer; + message << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << m_runtimeName + << static_cast(iox::capro::ServiceDescription()).toString(); - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); + const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - m_roudiApp->shutDownTest(); + EXPECT_TRUE(m_receiveBuffer.isValid()); + EXPECT_TRUE(successfullySent); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageFindServiceError) { std::unique_ptr m_roudiComponents = @@ -499,7 +465,6 @@ TEST_F(RouDiBaseClass_test, ProcessMessageFindServiceError) m_roudiApp->shutDownTest(); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageKeepAlive) { std::unique_ptr m_roudiComponents = @@ -520,7 +485,6 @@ TEST_F(RouDiBaseClass_test, ProcessMessageKeepAlive) m_roudiApp->shutDownTest(); } -/// @note name of the Testcase shall describe the test case in detail to avoid additional comments TEST_F(RouDiBaseClass_test, ProcessMessageError) { std::unique_ptr m_roudiComponents = From 3030e11d29a9cdfdde3b38f57843d0311104b752 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Mon, 1 Feb 2021 17:02:22 +0100 Subject: [PATCH 10/26] iox-#454 improve unit test for class roudi Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi.cpp b/iceoryx_posh/test/moduletests/test_roudi.cpp index 95e0b50cf6..5956a81aeb 100644 --- a/iceoryx_posh/test/moduletests/test_roudi.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi.cpp @@ -419,8 +419,7 @@ TEST_F(RouDiBaseClass_test, ProcessMessageCreateNodeError) RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName" - << "123123"; + message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName"; auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); std::string processName = message.getElementAtIndex(1); From bcce50dacdbfc0913cb2c9d0ed4c18465bcf8d06 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Tue, 2 Feb 2021 12:33:33 +0100 Subject: [PATCH 11/26] iox-#454 refactoring unit test for class roudi port manager Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 84 +------------------ 1 file changed, 2 insertions(+), 82 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index a24a1b5fdc..b1d76d1d81 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -63,7 +63,6 @@ class PortManager_test : public Test uint16_t m_instIdCounter, m_eventIdCounter, m_sIdCounter; iox::ProcessName_t m_Process{"TestProcess"}; - iox::NodeName_t m_Node{"TestNode"}; void SetUp() override { @@ -124,10 +123,6 @@ class PortManager_test : public Test iox::cxx::GenericRAII m_uniqueRouDiId{[] { iox::popo::internal::setUniqueRouDiId(0); }, [] { iox::popo::internal::unsetUniqueRouDiId(); }}; - void InterOpWait() - { - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } }; @@ -572,80 +567,6 @@ TEST_F(PortManager_test, PortDestroy) } } -TEST_F(PortManager_test, CheckNodeOverflowErrorReturnsnullptrForAcquireNodeData) -{ - std::string nodename = "nodeName"; - - for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - auto newNodeName = nodename + std::to_string(i); - auto nodePointer = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName), - iox::NodeName_t(iox::cxx::TruncateToCapacity, newNodeName)); - EXPECT_NE(nodePointer, nullptr); - } - - { // test if overflow errors get hit - - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( - [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { - errorHandlerCalled = true; - }); - - auto nodePointer = m_portManager->acquireNodeData(m_Process, m_Node); - EXPECT_EQ(nodePointer, nullptr); - EXPECT_TRUE(errorHandlerCalled); - } - - // delete one and add one should be possible now - { - unsigned int testi = 0; - auto newNodeName = nodename + std::to_string(testi); - m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName)); - - auto nodePointer = m_portManager->acquireNodeData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newNodeName), - iox::NodeName_t(iox::cxx::TruncateToCapacity, newNodeName)); - EXPECT_NE(nodePointer, nullptr); - } -} - -TEST_F(PortManager_test, UseDestroyNodeReturnsNotNullPtrToAcquireNodeData) -{ - std::vector nodeContainer; - std::string nodeName = "nodeName"; - - // first aquire all possible condition variables - for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - auto newnodeName = nodeName + std::to_string(i); - auto nodeDataResult = - m_portManager->acquireNodeData(m_Process, iox::NodeName_t(iox::cxx::TruncateToCapacity, newnodeName)); - EXPECT_NE(nodeDataResult, nullptr); - nodeContainer.push_back(nodeDataResult); - } - - // so now no one should be available - { - auto nodeDataResult = m_portManager->acquireNodeData(m_Process, m_Node); - EXPECT_EQ(nodeDataResult, nullptr); - } - - // set the destroy flag and let the discovery loop take care - for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - nodeContainer[i]->m_toBeDestroyed.store(true, std::memory_order_relaxed); - } - m_portManager->doDiscovery(); - nodeContainer.clear(); // These pointers are dangling now - - // so we should able to get some more now - for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - auto nodeDataResult = m_portManager->acquireNodeData(m_Process, m_Node); - EXPECT_NE(nodeDataResult, nullptr); - } -} - TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfacePortData) { std::vector interfaceContainer; @@ -683,7 +604,7 @@ TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfaceP } } -TEST_F(PortManager_test, OfferPublisherServiceReturnsServiceRegistryChangeCounter) +TEST_F(PortManager_test, OfferPublisherServiceUpdatesServiceRegistryChangeCounter) { auto serviceCounter = m_portManager->serviceRegistryChangeCounter(); auto initialCount = serviceCounter->load(); @@ -692,12 +613,11 @@ TEST_F(PortManager_test, OfferPublisherServiceReturnsServiceRegistryChangeCounte PublisherPortUser publisher( m_portManager ->acquirePublisherPortData( - {1, 1, 1}, publisherOptions, m_Process, m_payloadMemoryManager, m_Node, PortConfigInfo()) + {1, 1, 1}, publisherOptions, m_Process, m_payloadMemoryManager, PortConfigInfo()) .value()); publisher.offer(); m_portManager->doDiscovery(); - this->InterOpWait(); EXPECT_TRUE(initialCount + 1 == serviceCounter->load()); } From 83131d341388d652b8d354cabe5cd36e4d0041fa Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Tue, 2 Feb 2021 13:47:13 +0100 Subject: [PATCH 12/26] iox-#454 ASSERT_NE in place of EXPECT_NE before pushing to the container Signed-off-by: Manel Melaouhi --- iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index b1d76d1d81..e99219916e 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -578,7 +578,7 @@ TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfaceP auto newItfName = itf + std::to_string(i); auto interp = m_portManager->acquireInterfacePortData( iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); - EXPECT_NE(interp, nullptr); + ASSERT_NE(interp, nullptr); interfaceContainer.push_back(interp); } From de378c677521c249f97b8cfabefa53e3433a6f3b Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Tue, 2 Feb 2021 14:37:03 +0100 Subject: [PATCH 13/26] iox-#454 Update port manager test file with some comments and replace EXPECT_* with ASSERT_* for two tests Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 127 +++++++++++++++++- 1 file changed, 123 insertions(+), 4 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index e99219916e..9cec0df787 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -122,7 +122,6 @@ class PortManager_test : public Test iox::cxx::GenericRAII m_uniqueRouDiId{[] { iox::popo::internal::setUniqueRouDiId(0); }, [] { iox::popo::internal::unsetUniqueRouDiId(); }}; - }; @@ -331,6 +330,7 @@ TEST_F(PortManager_test, InterfacesOverflow) { unsigned int testi = 0; auto newItfName = itf + std::to_string(testi); + // this is done because there is no removeInterfaceData method in the PortManager class m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); auto interfacePointer = m_portManager->acquireInterfacePortData( @@ -368,6 +368,7 @@ TEST_F(PortManager_test, ApplicationsOverflow) { unsigned int testi = 0; auto newAppName = app + std::to_string(testi); + // this is done because there is no removeApplicationData method in the PortManager class m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); auto appPointer = @@ -406,6 +407,7 @@ TEST_F(PortManager_test, ConditionVariablesOverflow) { unsigned int testi = 0; auto newProcessName = process + std::to_string(testi); + // this is done because there is no removeConditionVariableData method in the PortManager class m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); auto conditionVariableDataResult = m_portManager->acquireConditionVariableData( @@ -424,7 +426,7 @@ TEST_F(PortManager_test, ConditionVariablesDestroy) for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) { auto conditionVariableDataResult = m_portManager->acquireConditionVariableData("JustFollowTheHypnoToad"); - EXPECT_FALSE(conditionVariableDataResult.has_error()); + ASSERT_FALSE(conditionVariableDataResult.has_error()); condVarContainer.push_back(conditionVariableDataResult.value()); } @@ -450,6 +452,124 @@ TEST_F(PortManager_test, ConditionVariablesDestroy) } } +TEST_F(PortManager_test, AcquiringMaximumNumberOfNodesWorks) +{ + std::string process = "Process"; + std::string node = "Node"; + + for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) + { + iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); + iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); + auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); + EXPECT_THAT(nodeData.has_error(), Eq(false)); + EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName)); + EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName)); + } +} + +TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) +{ + std::string process = "Process"; + std::string node = "Node"; + + // first acquire all possible NodeData + for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) + { + iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); + iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); + auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); + ASSERT_THAT(nodeData.has_error(), Eq(false)); + } + + // test if overflow errors get hit + auto errorHandlerCalled{false}; + auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { + errorHandlerCalled = true; + }); + + auto nodeData = m_portManager->acquireNodeData("AnotherProcess", "AnotherNode"); + EXPECT_THAT(nodeData.has_error(), Eq(true)); + EXPECT_THAT(errorHandlerCalled, Eq(true)); + EXPECT_THAT(nodeData.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); +} + +TEST_F(PortManager_test, DeletingNodeWorks) +{ + std::string process = "Process"; + std::string node = "Node"; + + // first acquire all possible NodeData + for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) + { + iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); + iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); + auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); + ASSERT_THAT(nodeData.has_error(), Eq(false)); + } + + // test if overflow errors get hit + auto errorHandlerCalled{false}; + auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { + errorHandlerCalled = true; + }); + + auto nodeData = m_portManager->acquireNodeData("AnotherProcess", "AnotherNode"); + ASSERT_THAT(nodeData.has_error(), Eq(true)); + ASSERT_THAT(errorHandlerCalled, Eq(true)); + ASSERT_THAT(nodeData.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); + + // delete one and add one NodeData should be possible now + unsigned int i = 0U; + iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); + iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); + // this is done because there is no removeNodeData method in the PortManager class + m_portManager->deletePortsOfProcess(newProcessName); + + nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); + EXPECT_THAT(nodeData.has_error(), Eq(false)); + EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName)); + EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName)); +} + + +TEST_F(PortManager_test, DestroyNodeDataAndAddNewNodeDataSucceeds) +{ + iox::ProcessName_t process = "Humuhumunukunukuapua'a"; + iox::NodeName_t node = "Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu"; + std::vector nodeContainer; + + // first acquire all possible NodeData + for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) + { + auto nodeData = m_portManager->acquireNodeData(process, node); + ASSERT_FALSE(nodeData.has_error()); + nodeContainer.push_back(nodeData.value()); + } + + // so now no NodeData should be available + auto nodeData = m_portManager->acquireNodeData(process, node); + EXPECT_THAT(nodeData.has_error(), Eq(true)); + + // set the destroy flag and let the discovery loop take care + for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) + { + nodeContainer[i]->m_toBeDestroyed.store(true, std::memory_order_relaxed); + } + m_portManager->doDiscovery(); + nodeContainer.clear(); + + // so we should be able to get some more now + for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) + { + auto nodeData = m_portManager->acquireNodeData(process, node); + EXPECT_THAT(nodeData.has_error(), Eq(false)); + } +} + + TEST_F(PortManager_test, PortDestroy) { iox::ProcessName_t p1 = "myProcess1"; @@ -612,8 +732,7 @@ TEST_F(PortManager_test, OfferPublisherServiceUpdatesServiceRegistryChangeCounte PublisherPortUser publisher( m_portManager - ->acquirePublisherPortData( - {1, 1, 1}, publisherOptions, m_Process, m_payloadMemoryManager, PortConfigInfo()) + ->acquirePublisherPortData({1, 1, 1}, publisherOptions, m_Process, m_payloadMemoryManager, PortConfigInfo()) .value()); publisher.offer(); From 8388ea1c1c827c6014bbd950a0f3d51936b529e6 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Wed, 3 Feb 2021 08:40:43 +0100 Subject: [PATCH 14/26] iox-#454 remove unit test file class roudi as refactoring needed Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi.cpp | 508 ------------------- 1 file changed, 508 deletions(-) delete mode 100644 iceoryx_posh/test/moduletests/test_roudi.cpp diff --git a/iceoryx_posh/test/moduletests/test_roudi.cpp b/iceoryx_posh/test/moduletests/test_roudi.cpp deleted file mode 100644 index 5956a81aeb..0000000000 --- a/iceoryx_posh/test/moduletests/test_roudi.cpp +++ /dev/null @@ -1,508 +0,0 @@ -// Copyright (c) 2021 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "iceoryx_posh/iceoryx_posh_types.hpp" -#include "iceoryx_posh/internal/roudi/roudi.hpp" -#include "iceoryx_posh/internal/roudi_environment/roudi_environment.hpp" -#include "iceoryx_posh/internal/runtime/message_queue_message.hpp" -#include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp" -#include "iceoryx_posh/runtime/posh_runtime.hpp" - -#include -#include -#include - -using namespace ::testing; -using ::testing::Return; - -using namespace iox::roudi; -using namespace iox::runtime; - -namespace iox -{ -namespace test -{ -/// @brief Test goal: Verify base class roudi - -class RoudiClassTest : public RouDi -{ - public: - RoudiClassTest(iox::roudi::RouDiMemoryInterface& roudiMemoryInterface, - iox::roudi::PortManager& portManager, - iox::roudi::RouDi::RoudiStartupParameters roudiStartupParameters) - : RouDi(roudiMemoryInterface, portManager, roudiStartupParameters) - { - } - - void startMQThreadTest() - { - this->startMQThread(); - } - - void shutDownTest() - { - this->shutdown(); - } - - void processMessageTest(const runtime::MqMessage& message, - const iox::runtime::MqMessageType& cmd, - const ProcessName_t& processName) - { - this->processMessage(message, cmd, processName); - } - - const PortManager* getPortManager() - { - return m_portManager; - } -}; - -class RouDiBaseClass_test : public Test -{ - public: -}; - -TEST_F(RouDiBaseClass_test, ConstructorIsSuccessfull) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, false})); - - EXPECT_NE(m_roudiApp, nullptr); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ConstructorThreadStartNotImmediateIsSuccessfull) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr(new RoudiClassTest( - m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, false, RouDi::MQThreadStart::DEFER_START})); - - m_roudiApp->startMQThreadTest(); - - EXPECT_DEATH(m_roudiApp->startMQThreadTest(), ".*"); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ShutDownKillProcessInDestructorTrueIsSuccessfull) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "AppName" - << "123123" - << "456" - << "789" - << "123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ShutDownCalledTwoTimesIsSuccessfull) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - m_roudiApp->shutDownTest(); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, SendCorrectRegMessagetoRoudiReturnSuccessfullySent) -{ - const iox::ProcessName_t m_runtimeName{"App"}; - RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; - PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; - - MqMessage message; - MqMessage m_receiveBuffer; - const iox::NodeName_t m_nodeName{"testNode"}; - message << mqMessageTypeToString(MqMessageType::REG) << "App" << std::to_string(getpid()) - << std::to_string(posix::PosixUser::getUserOfCurrentProcess().getID()) << std::to_string(0) - << static_cast(version::VersionInfo::getCurrentVersion()).toString(); - - const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - - EXPECT_TRUE(m_receiveBuffer.isValid()); - EXPECT_TRUE(successfullySent); -} - -TEST_F(RouDiBaseClass_test, SendWrongRegMessagetoRoudiReturnError) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().optimize())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::REG) << "App" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageChangeCounter) -{ - const iox::ProcessName_t m_runtimeName{"App"}; - RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; - PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; - - MqMessage message; - MqMessage m_receiveBuffer; - message << mqMessageTypeToString(MqMessageType::SERVICE_REGISTRY_CHANGE_COUNTER) << m_runtimeName; - - const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - - EXPECT_TRUE(m_receiveBuffer.isValid()); - EXPECT_TRUE(successfullySent); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisher) -{ - const iox::ProcessName_t m_runtimeName{"App"}; - RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; - PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; - - MqMessage message; - MqMessage m_receiveBuffer; - iox::popo::PublisherOptions publisherOptions; - publisherOptions.historyCapacity = 13U; - const iox::NodeName_t m_nodeName{"testNode"}; - - message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << m_runtimeName - << static_cast(iox::capro::ServiceDescription(99U, 1U, 20U)).toString() - << std::to_string(publisherOptions.historyCapacity) << m_nodeName - << static_cast(iox::runtime::PortConfigInfo(11U, 22U, 33U)).toString(); - - const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - - EXPECT_TRUE(m_receiveBuffer.isValid()); - EXPECT_TRUE(successfullySent); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreatePublisherError) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_PUBLISHER) << "AppName" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriber) -{ - const iox::ProcessName_t m_runtimeName{"App"}; - RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; - PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; - - MqMessage message; - MqMessage m_receiveBuffer; - iox::popo::SubscriberOptions subscriberOptions; - subscriberOptions.historyRequest = 13U; - subscriberOptions.queueCapacity = 42U; - const iox::NodeName_t m_nodeName{"testNode"}; - - message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << m_runtimeName - << static_cast(iox::capro::ServiceDescription(99U, 1U, 20U)).toString() - << std::to_string(subscriberOptions.historyRequest) << std::to_string(subscriberOptions.queueCapacity) - << m_nodeName << static_cast(iox::runtime::PortConfigInfo(11U, 22U, 33U)).toString(); - - const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - - EXPECT_TRUE(m_receiveBuffer.isValid()); - EXPECT_TRUE(successfullySent); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateSubscriberError) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_SUBSCRIBER) << "AppName" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariable) -{ - const iox::ProcessName_t m_runtimeName{"App"}; - RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; - PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; - - MqMessage message; - MqMessage m_receiveBuffer; - message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << m_runtimeName; - - const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - - EXPECT_TRUE(m_receiveBuffer.isValid()); - EXPECT_TRUE(successfullySent); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateConditionVariableError) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_CONDITION_VARIABLE) << "AppName" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterface) -{ - const iox::ProcessName_t m_runtimeName{"App"}; - RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; - PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; - const iox::NodeName_t m_nodeName{"testNode"}; - - MqMessage message; - MqMessage m_receiveBuffer; - message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << m_runtimeName - << static_cast(iox::capro::Interfaces::INTERNAL) << m_nodeName; - - const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - - EXPECT_TRUE(m_receiveBuffer.isValid()); - EXPECT_TRUE(successfullySent); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateInterfaceError) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_INTERFACE) << "AppName" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplication) -{ - const iox::ProcessName_t m_runtimeName{"App"}; - RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; - PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; - - MqMessage message; - MqMessage m_receiveBuffer; - message << mqMessageTypeToString(MqMessageType::CREATE_APPLICATION) << m_runtimeName; - - const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - - EXPECT_TRUE(m_receiveBuffer.isValid()); - EXPECT_TRUE(successfullySent); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateApplicationError) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_APPLICATION) << "AppName" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateNode) -{ - const iox::ProcessName_t m_runtimeName{"App"}; - RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; - PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; - const iox::NodeName_t m_nodeName{"testNode"}; - const uint32_t nodeDeviceIdentifier = 1U; - iox::runtime::NodeProperty nodeProperty(m_nodeName, nodeDeviceIdentifier); - - MqMessage message; - MqMessage m_receiveBuffer; - message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << m_runtimeName - << static_cast(nodeProperty).toString(); - - const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - - EXPECT_TRUE(m_receiveBuffer.isValid()); - EXPECT_TRUE(successfullySent); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageCreateNodeError) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::CREATE_NODE) << "AppName"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageFindService) -{ - const iox::ProcessName_t m_runtimeName{"App"}; - RouDiEnvironment m_roudiEnv{iox::RouDiConfig_t().setDefaults()}; - PoshRuntime* m_runtime{&iox::runtime::PoshRuntime::initRuntime(m_runtimeName)}; - - MqMessage message; - MqMessage m_receiveBuffer; - message << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << m_runtimeName - << static_cast(iox::capro::ServiceDescription()).toString(); - - const auto successfullySent = m_runtime->sendRequestToRouDi(message, m_receiveBuffer); - - EXPECT_TRUE(m_receiveBuffer.isValid()); - EXPECT_TRUE(successfullySent); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageFindServiceError) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::FIND_SERVICE) << "AppName"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageKeepAlive) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::KEEPALIVE) << "AppName" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -TEST_F(RouDiBaseClass_test, ProcessMessageError) -{ - std::unique_ptr m_roudiComponents = - std::unique_ptr(new IceOryxRouDiComponents(iox::RouDiConfig_t().setDefaults())); - std::unique_ptr m_roudiApp = std::unique_ptr( - new RoudiClassTest(m_roudiComponents->m_rouDiMemoryManager, - m_roudiComponents->m_portManager, - RouDi::RoudiStartupParameters{roudi::MonitoringMode::ON, true})); - - MqMessage message; - message << mqMessageTypeToString(MqMessageType::ERROR) << "AppName" - << "123123"; - auto cmd = runtime::stringToMqMessageType(message.getElementAtIndex(0).c_str()); - std::string processName = message.getElementAtIndex(1); - - m_roudiApp->processMessageTest(message, cmd, ProcessName_t(cxx::TruncateToCapacity, processName)); - - m_roudiApp->shutDownTest(); -} - -} // namespace test -} // namespace iox From c17b337f2ede9d62d3e3955c43062035a385c358 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Tue, 9 Feb 2021 11:24:09 +0100 Subject: [PATCH 15/26] iox-#454 add template for set Destroy Flag And Clear Container Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index bc0bed9ae6..4881bd6d0e 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -124,6 +124,15 @@ class PortManager_test : public Test [] { iox::popo::internal::unsetUniqueRouDiId(); }}; }; +template +void setDestroyFlagAndClearContainer(vector& Container) +{ + for (auto item : Container) + { + item->m_toBeDestroyed.store(true, std::memory_order_relaxed); + } + Container.clear(); +} TEST_F(PortManager_test, doDiscovery_singleShotPublisherFirst) { @@ -409,7 +418,7 @@ TEST_F(PortManager_test, ConditionVariablesOverflow) } } -TEST_F(PortManager_test, ConditionVariablesDestroy) +TEST_F(PortManager_test, AcquireConditionVariablesDataAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) { std::vector condVarContainer; @@ -430,12 +439,8 @@ TEST_F(PortManager_test, ConditionVariablesDestroy) } // set the destroy flag and let the discovery loop take care - for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) - { - condVarContainer[i]->m_toBeDestroyed.store(true, std::memory_order_relaxed); - } + setDestroyFlagAndClearContainer(condVarContainer); m_portManager->doDiscovery(); - condVarContainer.clear(); // These pointers are dangling now // so we should able to get some more now for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) @@ -528,7 +533,7 @@ TEST_F(PortManager_test, DeletingNodeWorks) } -TEST_F(PortManager_test, DestroyNodeDataAndAddNewNodeDataSucceeds) +TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) { iox::ProcessName_t process = "Humuhumunukunukuapua'a"; iox::NodeName_t node = "Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu"; @@ -547,12 +552,8 @@ TEST_F(PortManager_test, DestroyNodeDataAndAddNewNodeDataSucceeds) EXPECT_THAT(nodeData.has_error(), Eq(true)); // set the destroy flag and let the discovery loop take care - for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - nodeContainer[i]->m_toBeDestroyed.store(true, std::memory_order_relaxed); - } + setDestroyFlagAndClearContainer(nodeContainer); m_portManager->doDiscovery(); - nodeContainer.clear(); // so we should be able to get some more now for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) @@ -676,7 +677,7 @@ TEST_F(PortManager_test, PortDestroy) } } -TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfacePortData) +TEST_F(PortManager_test, AcquireInterfacePortDataAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) { std::vector interfaceContainer; std::string itf = "itf"; @@ -698,12 +699,8 @@ TEST_F(PortManager_test, UseDestroyInterfaceReturnsNotNullPtrToAcquireInterfaceP } // set the destroy flag and let the discovery loop take care - for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) - { - interfaceContainer[i]->m_toBeDestroyed.store(true, std::memory_order_relaxed); - } + setDestroyFlagAndClearContainer(interfaceContainer); m_portManager->doDiscovery(); - interfaceContainer.clear(); // These pointers are dangling now // so we should able to get some more now for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) @@ -727,5 +724,5 @@ TEST_F(PortManager_test, OfferPublisherServiceUpdatesServiceRegistryChangeCounte publisher.offer(); m_portManager->doDiscovery(); - EXPECT_TRUE(initialCount + 1 == serviceCounter->load()); + EXPECT_EQ(initialCount + 1 == serviceCounter->load(), true); } From 180a32eb1a395bd0f9611ac25b080cf91732bb1d Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Tue, 9 Feb 2021 13:10:56 +0100 Subject: [PATCH 16/26] iox-#454 split into two tests, the overflow check and the remove with acquire a new one Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 95 +++++++++++-------- 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 4881bd6d0e..05baa768f2 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -241,7 +241,7 @@ TEST_F(PortManager_test, doDiscovery_rightOrdering) EXPECT_THAT(subscriber2.getSubscriptionState(), Eq(iox::SubscribeState::SUBSCRIBED)); } -TEST_F(PortManager_test, PublisherOverflow) +TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) { iox::ProcessName_t p1 = "test1"; decltype(iox::MAX_PUBLISHERS) pubForP1 = iox::MAX_PUBLISHERS; @@ -273,7 +273,7 @@ TEST_F(PortManager_test, PublisherOverflow) } } -TEST_F(PortManager_test, SubscriberOverflow) +TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) { iox::ProcessName_t p1 = "test1"; @@ -303,7 +303,7 @@ TEST_F(PortManager_test, SubscriberOverflow) } } -TEST_F(PortManager_test, InterfacesOverflow) +TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails) { std::string itf = "itf"; @@ -312,7 +312,7 @@ TEST_F(PortManager_test, InterfacesOverflow) auto newItfName = itf + std::to_string(i); auto interp = m_portManager->acquireInterfacePortData( iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); - EXPECT_THAT(interp, Ne(nullptr)); + EXPECT_NE(interp, nullptr); } // test if overflow errors get hit @@ -324,9 +324,22 @@ TEST_F(PortManager_test, InterfacesOverflow) }); auto interfacePointer = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "itfPenguin"); - EXPECT_THAT(interfacePointer, Eq(nullptr)); + EXPECT_EQ(interfacePointer, nullptr); EXPECT_TRUE(errorHandlerCalled); } +} + +TEST_F(PortManager_test, deleteInterfacePortfromMaximumNumberAndAddOneIsSuccessful) +{ + std::string itf = "itf"; + + for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) + { + auto newItfName = itf + std::to_string(i); + auto interp = m_portManager->acquireInterfacePortData( + iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); + EXPECT_NE(interp, nullptr); + } // delete one and add one should be possible now { @@ -337,11 +350,11 @@ TEST_F(PortManager_test, InterfacesOverflow) auto interfacePointer = m_portManager->acquireInterfacePortData( iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); - EXPECT_THAT(interfacePointer, Ne(nullptr)); + EXPECT_NE(interfacePointer, nullptr); } } -TEST_F(PortManager_test, ApplicationsOverflow) +TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfApplicationsFails) { std::string app = "app"; @@ -350,7 +363,7 @@ TEST_F(PortManager_test, ApplicationsOverflow) auto newAppName = app + std::to_string(i); auto appp = m_portManager->acquireApplicationPortData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); - EXPECT_THAT(appp, Ne(nullptr)); + EXPECT_NE(appp, nullptr); } // test if overflow errors get hit @@ -362,9 +375,22 @@ TEST_F(PortManager_test, ApplicationsOverflow) }); auto appPointer = m_portManager->acquireApplicationPortData("appPenguin"); - EXPECT_THAT(appPointer, Eq(nullptr)); + EXPECT_EQ(appPointer, nullptr); EXPECT_TRUE(errorHandlerCalled); } +} + +TEST_F(PortManager_test, deleteApplicationPortfromMaximumNumberAndAddOneIsSuccessful) +{ + std::string app = "app"; + + for (unsigned int i = 0; i < iox::MAX_PROCESS_NUMBER; i++) + { + auto newAppName = app + std::to_string(i); + auto appp = + m_portManager->acquireApplicationPortData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); + EXPECT_NE(appp, nullptr); + } // delete one and add one should be possible now { @@ -375,11 +401,11 @@ TEST_F(PortManager_test, ApplicationsOverflow) auto appPointer = m_portManager->acquireApplicationPortData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); - EXPECT_THAT(appPointer, Ne(nullptr)); + EXPECT_NE(appPointer, nullptr); } } -TEST_F(PortManager_test, ConditionVariablesOverflow) +TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFails) { std::string process = "HypnoToadForEver"; @@ -404,6 +430,19 @@ TEST_F(PortManager_test, ConditionVariablesOverflow) EXPECT_TRUE(errorHandlerCalled); EXPECT_THAT(conditionVariableDataResult.get_error(), Eq(PortPoolError::CONDITION_VARIABLE_LIST_FULL)); } +} + +TEST_F(PortManager_test, deleteConditionVariablePortfromMaximumNumberAndAddOneIsSuccessful) +{ + std::string process = "HypnoToadForEver"; + + for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) + { + auto newProcessName = process + std::to_string(i); + auto conditionVariableDataResult = m_portManager->acquireConditionVariableData( + iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); + EXPECT_FALSE(conditionVariableDataResult.has_error()); + } // delete one and add one should be possible now { @@ -450,22 +489,6 @@ TEST_F(PortManager_test, AcquireConditionVariablesDataAfterDestroyingPreviouslyA } } -TEST_F(PortManager_test, AcquiringMaximumNumberOfNodesWorks) -{ - std::string process = "Process"; - std::string node = "Node"; - - for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); - iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); - auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); - EXPECT_THAT(nodeData.has_error(), Eq(false)); - EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName)); - EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName)); - } -} - TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) { std::string process = "Process"; @@ -478,6 +501,8 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); ASSERT_THAT(nodeData.has_error(), Eq(false)); + EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName)); + EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName)); } // test if overflow errors get hit @@ -493,7 +518,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) EXPECT_THAT(nodeData.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); } -TEST_F(PortManager_test, DeletingNodeWorks) +TEST_F(PortManager_test, deleteNodePortfromMaximumNumberandAddOneIsSuccessful) { std::string process = "Process"; std::string node = "Node"; @@ -507,18 +532,6 @@ TEST_F(PortManager_test, DeletingNodeWorks) ASSERT_THAT(nodeData.has_error(), Eq(false)); } - // test if overflow errors get hit - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( - [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { - errorHandlerCalled = true; - }); - - auto nodeData = m_portManager->acquireNodeData("AnotherProcess", "AnotherNode"); - ASSERT_THAT(nodeData.has_error(), Eq(true)); - ASSERT_THAT(errorHandlerCalled, Eq(true)); - ASSERT_THAT(nodeData.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); - // delete one and add one NodeData should be possible now unsigned int i = 0U; iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); @@ -526,7 +539,7 @@ TEST_F(PortManager_test, DeletingNodeWorks) // this is done because there is no removeNodeData method in the PortManager class m_portManager->deletePortsOfProcess(newProcessName); - nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); + auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); EXPECT_THAT(nodeData.has_error(), Eq(false)); EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName)); EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName)); From 389e11c2384c4ff11feaf5e3bec381c20dc2149d Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Thu, 11 Feb 2021 09:55:52 +0100 Subject: [PATCH 17/26] iox-#454 split destroy ports test into two tests, destroy and cleanup Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 05baa768f2..5285eb2a04 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -576,8 +576,7 @@ TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsS } } - -TEST_F(PortManager_test, PortDestroy) +TEST_F(PortManager_test, DestroyPortsInProcessP2ChangesStatesOfPortsInProcessP1) { iox::ProcessName_t p1 = "myProcess1"; iox::ProcessName_t p2 = "myProcess2"; @@ -645,19 +644,38 @@ TEST_F(PortManager_test, PortDestroy) EXPECT_THAT(subscriber1.getSubscriptionState(), Eq(iox::SubscribeState::WAIT_FOR_OFFER)); } } +} + +TEST_F(PortManager_test, CleanupProcessP2ChangesStatesOfPortsInProcessP1) +{ + iox::ProcessName_t p1 = "myProcess1"; + iox::ProcessName_t p2 = "myProcess2"; + iox::capro::ServiceDescription cap1(1, 1, 1); + iox::capro::ServiceDescription cap2(2, 2, 2); + PublisherOptions publisherOptions{1, "node"}; + SubscriberOptions subscriberOptions{1, 1, "node"}; + + // two processes p1 and p2 each with a publisher and subscriber that match to the other process + auto publisherData1 = + m_portManager->acquirePublisherPortData(cap1, publisherOptions, p1, m_payloadMemoryManager, PortConfigInfo()) + .value(); + auto subscriberData1 = + m_portManager->acquireSubscriberPortData(cap2, subscriberOptions, p1, PortConfigInfo()).value(); - // re-create the ports of process p2 - publisherData2 = + auto publisherData2 = m_portManager->acquirePublisherPortData(cap2, publisherOptions, p2, m_payloadMemoryManager, PortConfigInfo()) .value(); - subscriberData2 = m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, p2, PortConfigInfo()).value(); + auto subscriberData2 = + m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, p2, PortConfigInfo()).value(); // let them connect { PublisherPortUser publisher1(publisherData1); ASSERT_TRUE(publisher1); + publisher1.offer(); SubscriberPortUser subscriber1(subscriberData1); ASSERT_TRUE(subscriber1); + subscriber1.subscribe(); PublisherPortUser publisher2(publisherData2); ASSERT_TRUE(publisher2); From a842d874967f35ae2acce6fa0778983a802f36cc Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Thu, 11 Feb 2021 11:01:39 +0100 Subject: [PATCH 18/26] iox-#496 update license header Signed-off-by: Manel Melaouhi --- iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 5285eb2a04..a80ce68db2 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2021 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019, 2021 by Robert Bosch GmbH. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,6 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 #include "test.hpp" From 7668ea58ac12895f7e492c06fc8102b60e1da8b9 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Thu, 11 Feb 2021 14:02:35 +0100 Subject: [PATCH 19/26] iox-#496 update copyright. Signed-off-by: Manel Melaouhi --- iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index a80ce68db2..848b231109 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2021 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2019, 2021 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From df2982bc5dbd1c7a0df7dd375925772055949eb3 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Fri, 12 Feb 2021 15:24:43 +0100 Subject: [PATCH 20/26] iox-#454 fix review findings Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 58 +++++++++---------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 848b231109..63467a61a0 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019, 2021 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019 - 2021 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2021 by Robert Bosch GmbH. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -331,7 +332,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails) } } -TEST_F(PortManager_test, deleteInterfacePortfromMaximumNumberAndAddOneIsSuccessful) +TEST_F(PortManager_test, DeleteInterfacePortfromMaximumNumberAndAddOneIsSuccessful) { std::string itf = "itf"; @@ -382,7 +383,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfApplicationsFails) } } -TEST_F(PortManager_test, deleteApplicationPortfromMaximumNumberAndAddOneIsSuccessful) +TEST_F(PortManager_test, DeleteApplicationPortfromMaximumNumberAndAddOneIsSuccessful) { std::string app = "app"; @@ -434,7 +435,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFa } } -TEST_F(PortManager_test, deleteConditionVariablePortfromMaximumNumberAndAddOneIsSuccessful) +TEST_F(PortManager_test, DeleteConditionVariablePortfromMaximumNumberAndAddOneIsSuccessful) { std::string process = "HypnoToadForEver"; @@ -491,6 +492,22 @@ TEST_F(PortManager_test, AcquireConditionVariablesDataAfterDestroyingPreviouslyA } } +TEST_F(PortManager_test, AcquiringMaximumNumberOfNodesWorks) +{ + std::string process = "Process"; + std::string node = "Node"; + + for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) + { + iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); + iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); + auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); + EXPECT_THAT(nodeData.has_error(), Eq(false)); + EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName)); + EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName)); + } +} + TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) { std::string process = "Process"; @@ -503,8 +520,6 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); ASSERT_THAT(nodeData.has_error(), Eq(false)); - EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName)); - EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName)); } // test if overflow errors get hit @@ -520,7 +535,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) EXPECT_THAT(nodeData.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); } -TEST_F(PortManager_test, deleteNodePortfromMaximumNumberandAddOneIsSuccessful) +TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) { std::string process = "Process"; std::string node = "Node"; @@ -578,7 +593,7 @@ TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsS } } -TEST_F(PortManager_test, DestroyPortsInProcessP2ChangesStatesOfPortsInProcessP1) +TEST_F(PortManager_test, PortsDestroyInP2ChangeStatesOfPortsInProcessP1) { iox::ProcessName_t p1 = "myProcess1"; iox::ProcessName_t p2 = "myProcess2"; @@ -646,38 +661,19 @@ TEST_F(PortManager_test, DestroyPortsInProcessP2ChangesStatesOfPortsInProcessP1) EXPECT_THAT(subscriber1.getSubscriptionState(), Eq(iox::SubscribeState::WAIT_FOR_OFFER)); } } -} - -TEST_F(PortManager_test, CleanupProcessP2ChangesStatesOfPortsInProcessP1) -{ - iox::ProcessName_t p1 = "myProcess1"; - iox::ProcessName_t p2 = "myProcess2"; - iox::capro::ServiceDescription cap1(1, 1, 1); - iox::capro::ServiceDescription cap2(2, 2, 2); - PublisherOptions publisherOptions{1, "node"}; - SubscriberOptions subscriberOptions{1, 1, "node"}; - // two processes p1 and p2 each with a publisher and subscriber that match to the other process - auto publisherData1 = - m_portManager->acquirePublisherPortData(cap1, publisherOptions, p1, m_payloadMemoryManager, PortConfigInfo()) - .value(); - auto subscriberData1 = - m_portManager->acquireSubscriberPortData(cap2, subscriberOptions, p1, PortConfigInfo()).value(); - - auto publisherData2 = + // re-create the ports of process p2 + publisherData2 = m_portManager->acquirePublisherPortData(cap2, publisherOptions, p2, m_payloadMemoryManager, PortConfigInfo()) .value(); - auto subscriberData2 = - m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, p2, PortConfigInfo()).value(); + subscriberData2 = m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, p2, PortConfigInfo()).value(); // let them connect { PublisherPortUser publisher1(publisherData1); ASSERT_TRUE(publisher1); - publisher1.offer(); SubscriberPortUser subscriber1(subscriberData1); ASSERT_TRUE(subscriber1); - subscriber1.subscribe(); PublisherPortUser publisher2(publisherData2); ASSERT_TRUE(publisher2); @@ -757,5 +753,5 @@ TEST_F(PortManager_test, OfferPublisherServiceUpdatesServiceRegistryChangeCounte publisher.offer(); m_portManager->doDiscovery(); - EXPECT_EQ(initialCount + 1 == serviceCounter->load(), true); + EXPECT_EQ(serviceCounter->load(), initialCount + 1); } From 64c59843ae27fbaf669f9fc118576cd81c5eb6ca Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Fri, 12 Feb 2021 15:48:30 +0100 Subject: [PATCH 21/26] iox-#454 add method exhaustInterfacePorts with optional lambda. Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 63467a61a0..6384e0ea77 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -125,6 +125,21 @@ class PortManager_test : public Test iox::cxx::GenericRAII m_uniqueRouDiId{[] { iox::popo::internal::setUniqueRouDiId(0); }, [] { iox::popo::internal::unsetUniqueRouDiId(); }}; + + void exhaustInterfacePorts(std::string itf, std::function f = std::function()) + { + for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) + { + auto newItfName = itf + std::to_string(i); + auto Interfaceport = m_portManager->acquireInterfacePortData( + iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); + ASSERT_NE(Interfaceport, nullptr); + if (f) + { + f(Interfaceport); + } + } + } }; template @@ -310,13 +325,8 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails) { std::string itf = "itf"; - for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) - { - auto newItfName = itf + std::to_string(i); - auto interp = m_portManager->acquireInterfacePortData( - iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); - EXPECT_NE(interp, nullptr); - } + // first aquire all possible Interfaces + exhaustInterfacePorts(itf); // test if overflow errors get hit { @@ -336,13 +346,8 @@ TEST_F(PortManager_test, DeleteInterfacePortfromMaximumNumberAndAddOneIsSuccessf { std::string itf = "itf"; - for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) - { - auto newItfName = itf + std::to_string(i); - auto interp = m_portManager->acquireInterfacePortData( - iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); - EXPECT_NE(interp, nullptr); - } + // first aquire all possible Interfaces + exhaustInterfacePorts(itf); // delete one and add one should be possible now { @@ -711,15 +716,9 @@ TEST_F(PortManager_test, AcquireInterfacePortDataAfterDestroyingPreviouslyAcquir std::vector interfaceContainer; std::string itf = "itf"; - // first aquire all possible condition variables - for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) - { - auto newItfName = itf + std::to_string(i); - auto interp = m_portManager->acquireInterfacePortData( - iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); - ASSERT_NE(interp, nullptr); - interfaceContainer.push_back(interp); - } + // first aquire all possible interfaces + exhaustInterfacePorts(itf,[&](auto InterafcePort){ + interfaceContainer.push_back(InterafcePort);}); // so now no one should be available { From ea140aedce094f1e9dcb9292fc06995c6df9f0fa Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Fri, 12 Feb 2021 16:15:43 +0100 Subject: [PATCH 22/26] iox-#454 add method exhaustCondVarPorts with optional lambda Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 6384e0ea77..40f9c4f7a5 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -126,7 +126,9 @@ class PortManager_test : public Test iox::cxx::GenericRAII m_uniqueRouDiId{[] { iox::popo::internal::setUniqueRouDiId(0); }, [] { iox::popo::internal::unsetUniqueRouDiId(); }}; - void exhaustInterfacePorts(std::string itf, std::function f = std::function()) + void exhaustInterfacePorts( + std::string itf, + std::function f = std::function()) { for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) { @@ -140,6 +142,23 @@ class PortManager_test : public Test } } } + + void exhaustCondVarPorts(std::string process, + std::function f = + std::function()) + { + for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) + { + auto newProcessName = process + std::to_string(i); + auto CondVarport = m_portManager->acquireConditionVariableData( + iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); + ASSERT_FALSE(CondVarport.has_error()); + if (f) + { + f(CondVarport.value()); + } + } + } }; template @@ -417,13 +436,8 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFa { std::string process = "HypnoToadForEver"; - for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) - { - auto newProcessName = process + std::to_string(i); - auto conditionVariableDataResult = m_portManager->acquireConditionVariableData( - iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - EXPECT_FALSE(conditionVariableDataResult.has_error()); - } + // first aquire all possible condition variables + exhaustCondVarPorts(process); // test if overflow errors get hit { @@ -444,13 +458,8 @@ TEST_F(PortManager_test, DeleteConditionVariablePortfromMaximumNumberAndAddOneIs { std::string process = "HypnoToadForEver"; - for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) - { - auto newProcessName = process + std::to_string(i); - auto conditionVariableDataResult = m_portManager->acquireConditionVariableData( - iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - EXPECT_FALSE(conditionVariableDataResult.has_error()); - } + // first aquire all possible condition variables + exhaustCondVarPorts(process); // delete one and add one should be possible now { @@ -472,12 +481,7 @@ TEST_F(PortManager_test, AcquireConditionVariablesDataAfterDestroyingPreviouslyA std::string process = "HypnoToadForEver"; // first aquire all possible condition variables - for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) - { - auto conditionVariableDataResult = m_portManager->acquireConditionVariableData("JustFollowTheHypnoToad"); - ASSERT_FALSE(conditionVariableDataResult.has_error()); - condVarContainer.push_back(conditionVariableDataResult.value()); - } + exhaustCondVarPorts(process, [&](auto CondVarport) { condVarContainer.push_back(CondVarport); }); // so now no one should be available { @@ -717,8 +721,7 @@ TEST_F(PortManager_test, AcquireInterfacePortDataAfterDestroyingPreviouslyAcquir std::string itf = "itf"; // first aquire all possible interfaces - exhaustInterfacePorts(itf,[&](auto InterafcePort){ - interfaceContainer.push_back(InterafcePort);}); + exhaustInterfacePorts(itf, [&](auto InterafcePort) { interfaceContainer.push_back(InterafcePort); }); // so now no one should be available { From ddef67f7f5b899d14512451d595c4bf7862da6e1 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Tue, 16 Feb 2021 13:59:43 +0100 Subject: [PATCH 23/26] iox-#454 add method exhaustNodePorts with three optional lambda Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 40f9c4f7a5..38dc69e1a2 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -159,6 +159,24 @@ class PortManager_test : public Test } } } + + void exhaustNodePorts(std::string node, + std::string process, + std::function f = + std::function()) + { + for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) + { + iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); + iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); + auto NodePort = m_portManager->acquireNodeData(newProcessName, newNodeName); + ASSERT_FALSE(NodePort.has_error()); + if (f) + { + f(NodePort.value(), newNodeName, newProcessName); + } + } + } }; template @@ -501,20 +519,15 @@ TEST_F(PortManager_test, AcquireConditionVariablesDataAfterDestroyingPreviouslyA } } -TEST_F(PortManager_test, AcquiringMaximumNumberOfNodesWorks) +TEST_F(PortManager_test, AcquireMaxNumberOfNodePorts) { std::string process = "Process"; std::string node = "Node"; - for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); - iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); - auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); - EXPECT_THAT(nodeData.has_error(), Eq(false)); - EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName)); - EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName)); - } + exhaustNodePorts(node, process, [&](auto NodePort, auto newNodeName, auto newProcessName) { + EXPECT_THAT(NodePort->m_node, StrEq(newNodeName)); + EXPECT_THAT(NodePort->m_process, StrEq(newProcessName)); + }); } TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) @@ -523,13 +536,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) std::string node = "Node"; // first acquire all possible NodeData - for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); - iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); - auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); - ASSERT_THAT(nodeData.has_error(), Eq(false)); - } + exhaustNodePorts(node, process); // test if overflow errors get hit auto errorHandlerCalled{false}; @@ -550,13 +557,7 @@ TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) std::string node = "Node"; // first acquire all possible NodeData - for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); - iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); - auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); - ASSERT_THAT(nodeData.has_error(), Eq(false)); - } + exhaustNodePorts(node, process); // delete one and add one NodeData should be possible now unsigned int i = 0U; @@ -579,12 +580,11 @@ TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsS std::vector nodeContainer; // first acquire all possible NodeData - for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - auto nodeData = m_portManager->acquireNodeData(process, node); - ASSERT_FALSE(nodeData.has_error()); - nodeContainer.push_back(nodeData.value()); - } + exhaustNodePorts(node, process, [&](auto NodePort, auto newNodeName, auto newProcessName) { + nodeContainer.push_back(NodePort); + EXPECT_THAT(NodePort->m_node, StrEq(newNodeName)); + EXPECT_THAT(NodePort->m_process, StrEq(newProcessName)); + }); // so now no NodeData should be available auto nodeData = m_portManager->acquireNodeData(process, node); @@ -602,7 +602,7 @@ TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsS } } -TEST_F(PortManager_test, PortsDestroyInP2ChangeStatesOfPortsInProcessP1) +TEST_F(PortManager_test, PortsDestroyInProcessP2ChangeStatesOfPortsInProcessP1) { iox::ProcessName_t p1 = "myProcess1"; iox::ProcessName_t p2 = "myProcess2"; From 09f62c1e1889efe6df55108447b4012e320fb584 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Fri, 19 Feb 2021 18:09:24 +0100 Subject: [PATCH 24/26] iox-#454 fix review findings to improve code style Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 282 +++++++++--------- 1 file changed, 144 insertions(+), 138 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 38dc69e1a2..501d55bf31 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2019 - 2021 by Apex.AI Inc. All rights reserved. -// Copyright (c) 2021 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2019 - 2021 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ class PortManager_test : public Test uint16_t m_instIdCounter, m_eventIdCounter, m_sIdCounter; - iox::ProcessName_t m_Process{"TestProcess"}; + iox::ProcessName_t m_ProcessName{"TestProcess"}; void SetUp() override { @@ -126,54 +126,72 @@ class PortManager_test : public Test iox::cxx::GenericRAII m_uniqueRouDiId{[] { iox::popo::internal::setUniqueRouDiId(0); }, [] { iox::popo::internal::unsetUniqueRouDiId(); }}; - void exhaustInterfacePorts( - std::string itf, + void acquireMaxNumberOfInterfaces( + std::string itfName, std::function f = std::function()) { for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) { - auto newItfName = itf + std::to_string(i); - auto Interfaceport = m_portManager->acquireInterfacePortData( + auto newItfName = itfName + std::to_string(i); + auto interfaceport = m_portManager->acquireInterfacePortData( iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); - ASSERT_NE(Interfaceport, nullptr); + ASSERT_NE(interfaceport, nullptr); if (f) { - f(Interfaceport); + f(interfaceport); } } } - void exhaustCondVarPorts(std::string process, - std::function f = - std::function()) + void acquireMaxNumberOfApplications( + std::string appName, + std::function f = std::function()) + { + for (unsigned int i = 0; i < iox::MAX_PROCESS_NUMBER; i++) + { + auto newAppName = appName + std::to_string(i); + auto applicationport = + m_portManager->acquireApplicationPortData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); + ASSERT_NE(applicationport, nullptr); + if (f) + { + f(applicationport); + } + } + } + + void acquireMaxNumberOfConditionVariables(std::string processName, + std::function f = + std::function()) { for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) { - auto newProcessName = process + std::to_string(i); - auto CondVarport = m_portManager->acquireConditionVariableData( + auto newProcessName = processName + std::to_string(i); + auto condVarport = m_portManager->acquireConditionVariableData( iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - ASSERT_FALSE(CondVarport.has_error()); + ASSERT_FALSE(condVarport.has_error()); if (f) { - f(CondVarport.value()); + f(condVarport.value()); } } } - void exhaustNodePorts(std::string node, - std::string process, - std::function f = - std::function()) + void + acquireMaxNumberOfNodes(std::string nodeName, + std::string processName, + std::function f = + std::function()) { for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) { - iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); - iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); - auto NodePort = m_portManager->acquireNodeData(newProcessName, newNodeName); - ASSERT_FALSE(NodePort.has_error()); + iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, processName + std::to_string(i)); + iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, nodeName + std::to_string(i)); + auto nodePort = m_portManager->acquireNodeData(newProcessName, newNodeName); + ASSERT_FALSE(nodePort.has_error()); if (f) { - f(NodePort.value(), newNodeName, newProcessName); + f(nodePort.value(), newNodeName, newProcessName); } } } @@ -298,7 +316,7 @@ TEST_F(PortManager_test, doDiscovery_rightOrdering) TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) { - iox::ProcessName_t p1 = "test1"; + iox::ProcessName_t processName1 = "test1"; decltype(iox::MAX_PUBLISHERS) pubForP1 = iox::MAX_PUBLISHERS; std::vector avaPublisher1(pubForP1); PublisherOptions publisherOptions{1, "run1"}; @@ -306,7 +324,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) for (unsigned int i = 0; i < pubForP1; i++) { auto publisherPortDataResult = m_portManager->acquirePublisherPortData( - getUniqueSD(), publisherOptions, p1, m_payloadMemoryManager, PortConfigInfo()); + getUniqueSD(), publisherOptions, processName1, m_payloadMemoryManager, PortConfigInfo()); ASSERT_FALSE(publisherPortDataResult.has_error()); avaPublisher1[i] = publisherPortDataResult.value(); @@ -321,7 +339,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) const iox::ErrorLevel) { errorHandlerCalled = true; }); auto publisherPortDataResult = m_portManager->acquirePublisherPortData( - getUniqueSD(), publisherOptions, p1, m_payloadMemoryManager, PortConfigInfo()); + getUniqueSD(), publisherOptions, processName1, m_payloadMemoryManager, PortConfigInfo()); EXPECT_TRUE(errorHandlerCalled); ASSERT_TRUE(publisherPortDataResult.has_error()); EXPECT_THAT(publisherPortDataResult.get_error(), Eq(PortPoolError::PUBLISHER_PORT_LIST_FULL)); @@ -330,7 +348,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) { - iox::ProcessName_t p1 = "test1"; + iox::ProcessName_t processName1 = "test1"; decltype(iox::MAX_SUBSCRIBERS) subForP1 = iox::MAX_SUBSCRIBERS; std::vector avaSubscriber1(subForP1); @@ -339,7 +357,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) for (unsigned int i = 0; i < subForP1; i++) { auto subscriberPortDataResult = - m_portManager->acquireSubscriberPortData(getUniqueSD(), subscriberOptions, p1, PortConfigInfo()); + m_portManager->acquireSubscriberPortData(getUniqueSD(), subscriberOptions, processName1, PortConfigInfo()); ASSERT_THAT(subscriberPortDataResult.has_error(), Eq(false)); avaSubscriber1[i] = subscriberPortDataResult.value(); } @@ -352,7 +370,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); auto subscriberPortDataResult = - m_portManager->acquireSubscriberPortData(getUniqueSD(), subscriberOptions, p1, PortConfigInfo()); + m_portManager->acquireSubscriberPortData(getUniqueSD(), subscriberOptions, processName1, PortConfigInfo()); EXPECT_TRUE(errorHandlerCalled); EXPECT_THAT(subscriberPortDataResult.get_error(), Eq(PortPoolError::SUBSCRIBER_PORT_LIST_FULL)); } @@ -360,10 +378,10 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails) { - std::string itf = "itf"; + std::string itfName = "itf"; // first aquire all possible Interfaces - exhaustInterfacePorts(itf); + acquireMaxNumberOfInterfaces(itfName); // test if overflow errors get hit { @@ -381,15 +399,15 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails) TEST_F(PortManager_test, DeleteInterfacePortfromMaximumNumberAndAddOneIsSuccessful) { - std::string itf = "itf"; + std::string itfName = "itf"; // first aquire all possible Interfaces - exhaustInterfacePorts(itf); + acquireMaxNumberOfInterfaces(itfName); // delete one and add one should be possible now { unsigned int testi = 0; - auto newItfName = itf + std::to_string(testi); + auto newItfName = itfName + std::to_string(testi); // this is done because there is no removeInterfaceData method in the PortManager class m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); @@ -399,17 +417,28 @@ TEST_F(PortManager_test, DeleteInterfacePortfromMaximumNumberAndAddOneIsSuccessf } } +TEST_F(PortManager_test, AcquireInterfacePortDataAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) +{ + std::vector interfaceContainer; + std::string itfName = "itf"; + + // first aquire all possible interfaces + acquireMaxNumberOfInterfaces(itfName, [&](auto InterafcePort) { interfaceContainer.push_back(InterafcePort); }); + + // set the destroy flag and let the discovery loop take care + setDestroyFlagAndClearContainer(interfaceContainer); + m_portManager->doDiscovery(); + + // so we should able to get some more now + acquireMaxNumberOfInterfaces(itfName); +} + TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfApplicationsFails) { - std::string app = "app"; + std::string appName = "app"; - for (unsigned int i = 0; i < iox::MAX_PROCESS_NUMBER; i++) - { - auto newAppName = app + std::to_string(i); - auto appp = - m_portManager->acquireApplicationPortData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); - EXPECT_NE(appp, nullptr); - } + // first aquire all possible applications + acquireMaxNumberOfApplications(appName); // test if overflow errors get hit { @@ -427,20 +456,15 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfApplicationsFails) TEST_F(PortManager_test, DeleteApplicationPortfromMaximumNumberAndAddOneIsSuccessful) { - std::string app = "app"; + std::string appName = "app"; - for (unsigned int i = 0; i < iox::MAX_PROCESS_NUMBER; i++) - { - auto newAppName = app + std::to_string(i); - auto appp = - m_portManager->acquireApplicationPortData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); - EXPECT_NE(appp, nullptr); - } + // first aquire all possible applications + acquireMaxNumberOfApplications(appName); // delete one and add one should be possible now { unsigned int testi = 0; - auto newAppName = app + std::to_string(testi); + auto newAppName = appName + std::to_string(testi); // this is done because there is no removeApplicationData method in the PortManager class m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); @@ -450,12 +474,30 @@ TEST_F(PortManager_test, DeleteApplicationPortfromMaximumNumberAndAddOneIsSucces } } +TEST_F(PortManager_test, AcquireApplicationDataAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) +{ + std::vector ApplicationContainer; + + std::string appName = "app"; + + // first aquire all possible applications + acquireMaxNumberOfApplications(appName, + [&](auto Applicationport) { ApplicationContainer.push_back(Applicationport); }); + + // set the destroy flag and let the discovery loop take care + setDestroyFlagAndClearContainer(ApplicationContainer); + m_portManager->doDiscovery(); + + // so we should able to get some more now + acquireMaxNumberOfApplications(appName); +} + TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFails) { - std::string process = "HypnoToadForEver"; + std::string processName = "HypnoToadForEver"; // first aquire all possible condition variables - exhaustCondVarPorts(process); + acquireMaxNumberOfConditionVariables(processName); // test if overflow errors get hit { @@ -474,15 +516,15 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFa TEST_F(PortManager_test, DeleteConditionVariablePortfromMaximumNumberAndAddOneIsSuccessful) { - std::string process = "HypnoToadForEver"; + std::string processName = "HypnoToadForEver"; // first aquire all possible condition variables - exhaustCondVarPorts(process); + acquireMaxNumberOfConditionVariables(processName); // delete one and add one should be possible now { unsigned int testi = 0; - auto newProcessName = process + std::to_string(testi); + auto newProcessName = processName + std::to_string(testi); // this is done because there is no removeConditionVariableData method in the PortManager class m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); @@ -496,35 +538,26 @@ TEST_F(PortManager_test, AcquireConditionVariablesDataAfterDestroyingPreviouslyA { std::vector condVarContainer; - std::string process = "HypnoToadForEver"; + std::string processName = "HypnoToadForEver"; // first aquire all possible condition variables - exhaustCondVarPorts(process, [&](auto CondVarport) { condVarContainer.push_back(CondVarport); }); - - // so now no one should be available - { - auto conditionVariableDataResult = m_portManager->acquireConditionVariableData("JustFollowTheHypnoToad"); - EXPECT_TRUE(conditionVariableDataResult.has_error()); - } + acquireMaxNumberOfConditionVariables(processName, + [&](auto CondVarport) { condVarContainer.push_back(CondVarport); }); // set the destroy flag and let the discovery loop take care setDestroyFlagAndClearContainer(condVarContainer); m_portManager->doDiscovery(); // so we should able to get some more now - for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) - { - auto conditionVariableDataResult = m_portManager->acquireConditionVariableData("JustFollowTheHypnoToad"); - EXPECT_FALSE(conditionVariableDataResult.has_error()); - } + acquireMaxNumberOfConditionVariables(processName); } TEST_F(PortManager_test, AcquireMaxNumberOfNodePorts) { - std::string process = "Process"; - std::string node = "Node"; + std::string processName = "Process"; + std::string nodeName = "Node"; - exhaustNodePorts(node, process, [&](auto NodePort, auto newNodeName, auto newProcessName) { + acquireMaxNumberOfNodes(nodeName, processName, [&](auto NodePort, auto newNodeName, auto newProcessName) { EXPECT_THAT(NodePort->m_node, StrEq(newNodeName)); EXPECT_THAT(NodePort->m_process, StrEq(newProcessName)); }); @@ -532,11 +565,11 @@ TEST_F(PortManager_test, AcquireMaxNumberOfNodePorts) TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) { - std::string process = "Process"; - std::string node = "Node"; + std::string processName = "Process"; + std::string nodeName = "Node"; // first acquire all possible NodeData - exhaustNodePorts(node, process); + acquireMaxNumberOfNodes(nodeName, processName); // test if overflow errors get hit auto errorHandlerCalled{false}; @@ -553,16 +586,16 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) { - std::string process = "Process"; - std::string node = "Node"; + std::string processName = "Process"; + std::string nodeName = "Node"; // first acquire all possible NodeData - exhaustNodePorts(node, process); + acquireMaxNumberOfNodes(nodeName, processName); // delete one and add one NodeData should be possible now unsigned int i = 0U; - iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i)); - iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i)); + iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, processName + std::to_string(i)); + iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, nodeName + std::to_string(i)); // this is done because there is no removeNodeData method in the PortManager class m_portManager->deletePortsOfProcess(newProcessName); @@ -575,54 +608,48 @@ TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) { - iox::ProcessName_t process = "Humuhumunukunukuapua'a"; - iox::NodeName_t node = "Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu"; + iox::ProcessName_t processName = "Humuhumunukunukuapua'a"; + iox::NodeName_t nodeName = "Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu"; std::vector nodeContainer; // first acquire all possible NodeData - exhaustNodePorts(node, process, [&](auto NodePort, auto newNodeName, auto newProcessName) { + acquireMaxNumberOfNodes(nodeName, processName, [&](auto NodePort, auto newNodeName, auto newProcessName) { nodeContainer.push_back(NodePort); EXPECT_THAT(NodePort->m_node, StrEq(newNodeName)); EXPECT_THAT(NodePort->m_process, StrEq(newProcessName)); }); - // so now no NodeData should be available - auto nodeData = m_portManager->acquireNodeData(process, node); - EXPECT_THAT(nodeData.has_error(), Eq(true)); - // set the destroy flag and let the discovery loop take care setDestroyFlagAndClearContainer(nodeContainer); m_portManager->doDiscovery(); // so we should be able to get some more now - for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++) - { - auto nodeData = m_portManager->acquireNodeData(process, node); - EXPECT_THAT(nodeData.has_error(), Eq(false)); - } + acquireMaxNumberOfNodes(nodeName, processName); } -TEST_F(PortManager_test, PortsDestroyInProcessP2ChangeStatesOfPortsInProcessP1) +TEST_F(PortManager_test, PortsDestroyInProcess2ChangeStatesOfPortsInProcess1) { - iox::ProcessName_t p1 = "myProcess1"; - iox::ProcessName_t p2 = "myProcess2"; + iox::ProcessName_t processName1 = "myProcess1"; + iox::ProcessName_t processName2 = "myProcess2"; iox::capro::ServiceDescription cap1(1, 1, 1); iox::capro::ServiceDescription cap2(2, 2, 2); PublisherOptions publisherOptions{1, "node"}; SubscriberOptions subscriberOptions{1, 1, "node"}; - // two processes p1 and p2 each with a publisher and subscriber that match to the other process + // two processes process1 and process2 each with a publisher and subscriber that match to the other process auto publisherData1 = - m_portManager->acquirePublisherPortData(cap1, publisherOptions, p1, m_payloadMemoryManager, PortConfigInfo()) + m_portManager + ->acquirePublisherPortData(cap1, publisherOptions, processName1, m_payloadMemoryManager, PortConfigInfo()) .value(); auto subscriberData1 = - m_portManager->acquireSubscriberPortData(cap2, subscriberOptions, p1, PortConfigInfo()).value(); + m_portManager->acquireSubscriberPortData(cap2, subscriberOptions, processName1, PortConfigInfo()).value(); auto publisherData2 = - m_portManager->acquirePublisherPortData(cap2, publisherOptions, p2, m_payloadMemoryManager, PortConfigInfo()) + m_portManager + ->acquirePublisherPortData(cap2, publisherOptions, processName2, m_payloadMemoryManager, PortConfigInfo()) .value(); auto subscriberData2 = - m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, p2, PortConfigInfo()).value(); + m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, processName2, PortConfigInfo()).value(); // let them connect { @@ -648,7 +675,7 @@ TEST_F(PortManager_test, PortsDestroyInProcessP2ChangeStatesOfPortsInProcessP1) EXPECT_THAT(subscriber2.getSubscriptionState(), Eq(iox::SubscribeState::SUBSCRIBED)); } - // destroy the ports of process p2 and check if states of ports in p1 changed as expected + // destroy the ports of process2 and check if states of ports in process1 changed as expected { PublisherPortUser publisher1(publisherData1); ASSERT_TRUE(publisher1); @@ -671,11 +698,13 @@ TEST_F(PortManager_test, PortsDestroyInProcessP2ChangeStatesOfPortsInProcessP1) } } - // re-create the ports of process p2 + // re-create the ports of process processName2 publisherData2 = - m_portManager->acquirePublisherPortData(cap2, publisherOptions, p2, m_payloadMemoryManager, PortConfigInfo()) + m_portManager + ->acquirePublisherPortData(cap2, publisherOptions, processName2, m_payloadMemoryManager, PortConfigInfo()) .value(); - subscriberData2 = m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, p2, PortConfigInfo()).value(); + subscriberData2 = + m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, processName2, PortConfigInfo()).value(); // let them connect { @@ -699,9 +728,9 @@ TEST_F(PortManager_test, PortsDestroyInProcessP2ChangeStatesOfPortsInProcessP1) EXPECT_THAT(subscriber2.getSubscriptionState(), Eq(iox::SubscribeState::SUBSCRIBED)); } - // cleanup process p2 and check if states of ports in p1 changed as expected + // cleanup process process2 and check if states of ports in process1 changed as expected { - m_portManager->deletePortsOfProcess(p2); + m_portManager->deletePortsOfProcess(processName2); PublisherPortUser publisher1(publisherData1); ASSERT_TRUE(publisher1); SubscriberPortUser subscriber1(subscriberData1); @@ -715,42 +744,19 @@ TEST_F(PortManager_test, PortsDestroyInProcessP2ChangeStatesOfPortsInProcessP1) } } -TEST_F(PortManager_test, AcquireInterfacePortDataAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) -{ - std::vector interfaceContainer; - std::string itf = "itf"; - - // first aquire all possible interfaces - exhaustInterfacePorts(itf, [&](auto InterafcePort) { interfaceContainer.push_back(InterafcePort); }); - - // so now no one should be available - { - auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, m_Process); - EXPECT_EQ(interp, nullptr); - } - - // set the destroy flag and let the discovery loop take care - setDestroyFlagAndClearContainer(interfaceContainer); - m_portManager->doDiscovery(); - - // so we should able to get some more now - for (uint32_t i = 0U; i < iox::MAX_INTERFACE_NUMBER; i++) - { - auto interp = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, m_Process); - EXPECT_NE(interp, nullptr); - } -} - TEST_F(PortManager_test, OfferPublisherServiceUpdatesServiceRegistryChangeCounter) { auto serviceCounter = m_portManager->serviceRegistryChangeCounter(); + ASSERT_NE(serviceCounter, nullptr); + auto initialCount = serviceCounter->load(); PublisherOptions publisherOptions{1}; - PublisherPortUser publisher( - m_portManager - ->acquirePublisherPortData({1, 1, 1}, publisherOptions, m_Process, m_payloadMemoryManager, PortConfigInfo()) - .value()); + auto publisherportdata = m_portManager->acquirePublisherPortData( + {1, 1, 1}, publisherOptions, m_ProcessName, m_payloadMemoryManager, PortConfigInfo()); + ASSERT_FALSE(publisherportdata.has_error()); + + PublisherPortUser publisher(publisherportdata.value()); publisher.offer(); m_portManager->doDiscovery(); From b188b7336035ec38abb43ad0e675a84c879b2a39 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Fri, 19 Feb 2021 20:23:23 +0100 Subject: [PATCH 25/26] iox-#454 update test cases after fixing some review remarks Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 141 +++++++++--------- 1 file changed, 70 insertions(+), 71 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 501d55bf31..3a0c67a244 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -127,35 +127,35 @@ class PortManager_test : public Test [] { iox::popo::internal::unsetUniqueRouDiId(); }}; void acquireMaxNumberOfInterfaces( - std::string itfName, + std::string processName, std::function f = std::function()) { for (unsigned int i = 0; i < iox::MAX_INTERFACE_NUMBER; i++) { - auto newItfName = itfName + std::to_string(i); - auto interfaceport = m_portManager->acquireInterfacePortData( - iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); - ASSERT_NE(interfaceport, nullptr); + auto newProcessName = processName + std::to_string(i); + auto interfacePort = m_portManager->acquireInterfacePortData( + iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); + ASSERT_NE(interfacePort, nullptr); if (f) { - f(interfaceport); + f(interfacePort); } } } void acquireMaxNumberOfApplications( - std::string appName, + std::string processName, std::function f = std::function()) { for (unsigned int i = 0; i < iox::MAX_PROCESS_NUMBER; i++) { - auto newAppName = appName + std::to_string(i); - auto applicationport = - m_portManager->acquireApplicationPortData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); - ASSERT_NE(applicationport, nullptr); + auto NewProcessName = processName + std::to_string(i); + auto applicationPort = m_portManager->acquireApplicationPortData( + iox::ProcessName_t(iox::cxx::TruncateToCapacity, NewProcessName)); + ASSERT_NE(applicationPort, nullptr); if (f) { - f(applicationport); + f(applicationPort); } } } @@ -167,12 +167,12 @@ class PortManager_test : public Test for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) { auto newProcessName = processName + std::to_string(i); - auto condVarport = m_portManager->acquireConditionVariableData( + auto condVarPort = m_portManager->acquireConditionVariableData( iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - ASSERT_FALSE(condVarport.has_error()); + ASSERT_FALSE(condVarPort.has_error()); if (f) { - f(condVarport.value()); + f(condVarPort.value()); } } } @@ -198,13 +198,13 @@ class PortManager_test : public Test }; template -void setDestroyFlagAndClearContainer(vector& Container) +void setDestroyFlagAndClearContainer(vector& container) { - for (auto item : Container) + for (auto& item : container) { item->m_toBeDestroyed.store(true, std::memory_order_relaxed); } - Container.clear(); + container.clear(); } TEST_F(PortManager_test, doDiscovery_singleShotPublisherFirst) @@ -378,10 +378,10 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails) { - std::string itfName = "itf"; + std::string processName = "itf"; // first aquire all possible Interfaces - acquireMaxNumberOfInterfaces(itfName); + acquireMaxNumberOfInterfaces(processName); // test if overflow errors get hit { @@ -391,54 +391,54 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails) errorHandlerCalled = true; }); - auto interfacePointer = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "itfPenguin"); - EXPECT_EQ(interfacePointer, nullptr); + auto interfacePort = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "itfPenguin"); + EXPECT_EQ(interfacePort, nullptr); EXPECT_TRUE(errorHandlerCalled); } } TEST_F(PortManager_test, DeleteInterfacePortfromMaximumNumberAndAddOneIsSuccessful) { - std::string itfName = "itf"; + std::string processName = "itf"; // first aquire all possible Interfaces - acquireMaxNumberOfInterfaces(itfName); + acquireMaxNumberOfInterfaces(processName); // delete one and add one should be possible now { unsigned int testi = 0; - auto newItfName = itfName + std::to_string(testi); + auto newProcessName = processName + std::to_string(testi); // this is done because there is no removeInterfaceData method in the PortManager class - m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); + m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - auto interfacePointer = m_portManager->acquireInterfacePortData( - iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newItfName)); - EXPECT_NE(interfacePointer, nullptr); + auto interfacePort = m_portManager->acquireInterfacePortData( + iox::capro::Interfaces::INTERNAL, iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); + EXPECT_NE(interfacePort, nullptr); } } TEST_F(PortManager_test, AcquireInterfacePortDataAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) { std::vector interfaceContainer; - std::string itfName = "itf"; + std::string processName = "itf"; // first aquire all possible interfaces - acquireMaxNumberOfInterfaces(itfName, [&](auto InterafcePort) { interfaceContainer.push_back(InterafcePort); }); + acquireMaxNumberOfInterfaces(processName, [&](auto InterafcePort) { interfaceContainer.push_back(InterafcePort); }); // set the destroy flag and let the discovery loop take care setDestroyFlagAndClearContainer(interfaceContainer); m_portManager->doDiscovery(); // so we should able to get some more now - acquireMaxNumberOfInterfaces(itfName); + acquireMaxNumberOfInterfaces(processName); } TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfApplicationsFails) { - std::string appName = "app"; + std::string processName = "app"; // first aquire all possible applications - acquireMaxNumberOfApplications(appName); + acquireMaxNumberOfApplications(processName); // test if overflow errors get hit { @@ -448,48 +448,47 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfApplicationsFails) errorHandlerCalled = true; }); - auto appPointer = m_portManager->acquireApplicationPortData("appPenguin"); - EXPECT_EQ(appPointer, nullptr); + auto appPort = m_portManager->acquireApplicationPortData("appPenguin"); + EXPECT_EQ(appPort, nullptr); EXPECT_TRUE(errorHandlerCalled); } } TEST_F(PortManager_test, DeleteApplicationPortfromMaximumNumberAndAddOneIsSuccessful) { - std::string appName = "app"; + std::string processName = "app"; // first aquire all possible applications - acquireMaxNumberOfApplications(appName); + acquireMaxNumberOfApplications(processName); // delete one and add one should be possible now { unsigned int testi = 0; - auto newAppName = appName + std::to_string(testi); + auto newprocessName = processName + std::to_string(testi); // this is done because there is no removeApplicationData method in the PortManager class - m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); + m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newprocessName)); - auto appPointer = - m_portManager->acquireApplicationPortData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newAppName)); - EXPECT_NE(appPointer, nullptr); + auto appPort = + m_portManager->acquireApplicationPortData(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newprocessName)); + EXPECT_NE(appPort, nullptr); } } -TEST_F(PortManager_test, AcquireApplicationDataAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) +TEST_F(PortManager_test, AcquireApplicationPortAfterDestroyingPreviouslyAcquiredOnesIsSuccessful) { - std::vector ApplicationContainer; + std::vector appContainer; - std::string appName = "app"; + std::string processName = "app"; // first aquire all possible applications - acquireMaxNumberOfApplications(appName, - [&](auto Applicationport) { ApplicationContainer.push_back(Applicationport); }); + acquireMaxNumberOfApplications(processName, [&](auto appPort) { appContainer.push_back(appPort); }); // set the destroy flag and let the discovery loop take care - setDestroyFlagAndClearContainer(ApplicationContainer); + setDestroyFlagAndClearContainer(appContainer); m_portManager->doDiscovery(); // so we should able to get some more now - acquireMaxNumberOfApplications(appName); + acquireMaxNumberOfApplications(processName); } TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFails) @@ -507,10 +506,10 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFa errorHandlerCalled = true; }); - auto conditionVariableDataResult = m_portManager->acquireConditionVariableData("AnotherToad"); - EXPECT_TRUE(conditionVariableDataResult.has_error()); + auto conditionVariablePort = m_portManager->acquireConditionVariableData("AnotherToad"); + EXPECT_TRUE(conditionVariablePort.has_error()); EXPECT_TRUE(errorHandlerCalled); - EXPECT_THAT(conditionVariableDataResult.get_error(), Eq(PortPoolError::CONDITION_VARIABLE_LIST_FULL)); + EXPECT_THAT(conditionVariablePort.get_error(), Eq(PortPoolError::CONDITION_VARIABLE_LIST_FULL)); } } @@ -528,9 +527,9 @@ TEST_F(PortManager_test, DeleteConditionVariablePortfromMaximumNumberAndAddOneIs // this is done because there is no removeConditionVariableData method in the PortManager class m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - auto conditionVariableDataResult = m_portManager->acquireConditionVariableData( + auto conditionVariablePort = m_portManager->acquireConditionVariableData( iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - EXPECT_FALSE(conditionVariableDataResult.has_error()); + EXPECT_FALSE(conditionVariablePort.has_error()); } } @@ -542,7 +541,7 @@ TEST_F(PortManager_test, AcquireConditionVariablesDataAfterDestroyingPreviouslyA // first aquire all possible condition variables acquireMaxNumberOfConditionVariables(processName, - [&](auto CondVarport) { condVarContainer.push_back(CondVarport); }); + [&](auto CondVarPort) { condVarContainer.push_back(CondVarPort); }); // set the destroy flag and let the discovery loop take care setDestroyFlagAndClearContainer(condVarContainer); @@ -578,10 +577,10 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) errorHandlerCalled = true; }); - auto nodeData = m_portManager->acquireNodeData("AnotherProcess", "AnotherNode"); - EXPECT_THAT(nodeData.has_error(), Eq(true)); + auto nodePort = m_portManager->acquireNodeData("AnotherProcess", "AnotherNode"); + EXPECT_THAT(nodePort.has_error(), Eq(true)); EXPECT_THAT(errorHandlerCalled, Eq(true)); - EXPECT_THAT(nodeData.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); + EXPECT_THAT(nodePort.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); } TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) @@ -599,10 +598,10 @@ TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) // this is done because there is no removeNodeData method in the PortManager class m_portManager->deletePortsOfProcess(newProcessName); - auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName); - EXPECT_THAT(nodeData.has_error(), Eq(false)); - EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName)); - EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName)); + auto nodePort = m_portManager->acquireNodeData(newProcessName, newNodeName); + ASSERT_THAT(nodePort.has_error(), Eq(false)); + EXPECT_THAT(nodePort.value()->m_node, StrEq(newNodeName)); + EXPECT_THAT(nodePort.value()->m_process, StrEq(newProcessName)); } @@ -613,11 +612,11 @@ TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsS std::vector nodeContainer; // first acquire all possible NodeData - acquireMaxNumberOfNodes(nodeName, processName, [&](auto NodePort, auto newNodeName, auto newProcessName) { - nodeContainer.push_back(NodePort); - EXPECT_THAT(NodePort->m_node, StrEq(newNodeName)); - EXPECT_THAT(NodePort->m_process, StrEq(newProcessName)); - }); + acquireMaxNumberOfNodes(nodeName, + processName, + [&](auto NodePort, auto newNodeName [[gnu::unused]], auto newProcessName [[gnu::unused]]) { + nodeContainer.push_back(NodePort); + }); // set the destroy flag and let the discovery loop take care setDestroyFlagAndClearContainer(nodeContainer); @@ -752,11 +751,11 @@ TEST_F(PortManager_test, OfferPublisherServiceUpdatesServiceRegistryChangeCounte auto initialCount = serviceCounter->load(); PublisherOptions publisherOptions{1}; - auto publisherportdata = m_portManager->acquirePublisherPortData( + auto publisherPortData = m_portManager->acquirePublisherPortData( {1, 1, 1}, publisherOptions, m_ProcessName, m_payloadMemoryManager, PortConfigInfo()); - ASSERT_FALSE(publisherportdata.has_error()); + ASSERT_FALSE(publisherPortData.has_error()); - PublisherPortUser publisher(publisherportdata.value()); + PublisherPortUser publisher(publisherPortData.value()); publisher.offer(); m_portManager->doDiscovery(); From c6438e116150252be96203d3f45ade2760c76102 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Mon, 22 Feb 2021 12:43:46 +0100 Subject: [PATCH 26/26] iox-#454 update naming and delete extra variables Signed-off-by: Manel Melaouhi --- .../moduletests/test_roudi_portmanager.cpp | 81 +++++++++---------- 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 3a0c67a244..40420e297f 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019 - 2021 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2019, 2021 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -149,9 +149,9 @@ class PortManager_test : public Test { for (unsigned int i = 0; i < iox::MAX_PROCESS_NUMBER; i++) { - auto NewProcessName = processName + std::to_string(i); + auto newProcessName = processName + std::to_string(i); auto applicationPort = m_portManager->acquireApplicationPortData( - iox::ProcessName_t(iox::cxx::TruncateToCapacity, NewProcessName)); + iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); ASSERT_NE(applicationPort, nullptr); if (f) { @@ -167,12 +167,12 @@ class PortManager_test : public Test for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) { auto newProcessName = processName + std::to_string(i); - auto condVarPort = m_portManager->acquireConditionVariableData( + auto condVar = m_portManager->acquireConditionVariableData( iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - ASSERT_FALSE(condVarPort.has_error()); + ASSERT_FALSE(condVar.has_error()); if (f) { - f(condVarPort.value()); + f(condVar.value()); } } } @@ -187,11 +187,11 @@ class PortManager_test : public Test { iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, processName + std::to_string(i)); iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, nodeName + std::to_string(i)); - auto nodePort = m_portManager->acquireNodeData(newProcessName, newNodeName); - ASSERT_FALSE(nodePort.has_error()); + auto node = m_portManager->acquireNodeData(newProcessName, newNodeName); + ASSERT_FALSE(node.has_error()); if (f) { - f(nodePort.value(), newNodeName, newProcessName); + f(node.value(), newNodeName, newProcessName); } } } @@ -316,18 +316,15 @@ TEST_F(PortManager_test, doDiscovery_rightOrdering) TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) { - iox::ProcessName_t processName1 = "test1"; - decltype(iox::MAX_PUBLISHERS) pubForP1 = iox::MAX_PUBLISHERS; - std::vector avaPublisher1(pubForP1); + iox::ProcessName_t processName = "test1"; PublisherOptions publisherOptions{1, "run1"}; - for (unsigned int i = 0; i < pubForP1; i++) + for (unsigned int i = 0; i < iox::MAX_PUBLISHERS; i++) { auto publisherPortDataResult = m_portManager->acquirePublisherPortData( - getUniqueSD(), publisherOptions, processName1, m_payloadMemoryManager, PortConfigInfo()); + getUniqueSD(), publisherOptions, processName, m_payloadMemoryManager, PortConfigInfo()); ASSERT_FALSE(publisherPortDataResult.has_error()); - avaPublisher1[i] = publisherPortDataResult.value(); } { // test if overflow errors get hit @@ -339,7 +336,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) const iox::ErrorLevel) { errorHandlerCalled = true; }); auto publisherPortDataResult = m_portManager->acquirePublisherPortData( - getUniqueSD(), publisherOptions, processName1, m_payloadMemoryManager, PortConfigInfo()); + getUniqueSD(), publisherOptions, processName, m_payloadMemoryManager, PortConfigInfo()); EXPECT_TRUE(errorHandlerCalled); ASSERT_TRUE(publisherPortDataResult.has_error()); EXPECT_THAT(publisherPortDataResult.get_error(), Eq(PortPoolError::PUBLISHER_PORT_LIST_FULL)); @@ -349,17 +346,13 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) { iox::ProcessName_t processName1 = "test1"; - - decltype(iox::MAX_SUBSCRIBERS) subForP1 = iox::MAX_SUBSCRIBERS; - std::vector avaSubscriber1(subForP1); SubscriberOptions subscriberOptions{1, 1, "run1"}; - for (unsigned int i = 0; i < subForP1; i++) + for (unsigned int i = 0; i < iox::MAX_SUBSCRIBERS; i++) { auto subscriberPortDataResult = m_portManager->acquireSubscriberPortData(getUniqueSD(), subscriberOptions, processName1, PortConfigInfo()); - ASSERT_THAT(subscriberPortDataResult.has_error(), Eq(false)); - avaSubscriber1[i] = subscriberPortDataResult.value(); + ASSERT_FALSE(subscriberPortDataResult.has_error()); } { // test if overflow errors get hit @@ -423,7 +416,7 @@ TEST_F(PortManager_test, AcquireInterfacePortDataAfterDestroyingPreviouslyAcquir std::string processName = "itf"; // first aquire all possible interfaces - acquireMaxNumberOfInterfaces(processName, [&](auto InterafcePort) { interfaceContainer.push_back(InterafcePort); }); + acquireMaxNumberOfInterfaces(processName, [&](auto interafcePort) { interfaceContainer.push_back(interafcePort); }); // set the destroy flag and let the discovery loop take care setDestroyFlagAndClearContainer(interfaceContainer); @@ -506,10 +499,10 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFa errorHandlerCalled = true; }); - auto conditionVariablePort = m_portManager->acquireConditionVariableData("AnotherToad"); - EXPECT_TRUE(conditionVariablePort.has_error()); + auto conditionVariableResult = m_portManager->acquireConditionVariableData("AnotherToad"); + EXPECT_TRUE(conditionVariableResult.has_error()); EXPECT_TRUE(errorHandlerCalled); - EXPECT_THAT(conditionVariablePort.get_error(), Eq(PortPoolError::CONDITION_VARIABLE_LIST_FULL)); + EXPECT_THAT(conditionVariableResult.get_error(), Eq(PortPoolError::CONDITION_VARIABLE_LIST_FULL)); } } @@ -527,9 +520,9 @@ TEST_F(PortManager_test, DeleteConditionVariablePortfromMaximumNumberAndAddOneIs // this is done because there is no removeConditionVariableData method in the PortManager class m_portManager->deletePortsOfProcess(iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - auto conditionVariablePort = m_portManager->acquireConditionVariableData( + auto conditionVariableResult = m_portManager->acquireConditionVariableData( iox::ProcessName_t(iox::cxx::TruncateToCapacity, newProcessName)); - EXPECT_FALSE(conditionVariablePort.has_error()); + EXPECT_FALSE(conditionVariableResult.has_error()); } } @@ -540,8 +533,7 @@ TEST_F(PortManager_test, AcquireConditionVariablesDataAfterDestroyingPreviouslyA std::string processName = "HypnoToadForEver"; // first aquire all possible condition variables - acquireMaxNumberOfConditionVariables(processName, - [&](auto CondVarPort) { condVarContainer.push_back(CondVarPort); }); + acquireMaxNumberOfConditionVariables(processName, [&](auto condVar) { condVarContainer.push_back(condVar); }); // set the destroy flag and let the discovery loop take care setDestroyFlagAndClearContainer(condVarContainer); @@ -556,9 +548,9 @@ TEST_F(PortManager_test, AcquireMaxNumberOfNodePorts) std::string processName = "Process"; std::string nodeName = "Node"; - acquireMaxNumberOfNodes(nodeName, processName, [&](auto NodePort, auto newNodeName, auto newProcessName) { - EXPECT_THAT(NodePort->m_node, StrEq(newNodeName)); - EXPECT_THAT(NodePort->m_process, StrEq(newProcessName)); + acquireMaxNumberOfNodes(nodeName, processName, [&](auto node, auto newNodeName, auto newProcessName) { + EXPECT_THAT(node->m_node, StrEq(newNodeName)); + EXPECT_THAT(node->m_process, StrEq(newProcessName)); }); } @@ -577,10 +569,10 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) errorHandlerCalled = true; }); - auto nodePort = m_portManager->acquireNodeData("AnotherProcess", "AnotherNode"); - EXPECT_THAT(nodePort.has_error(), Eq(true)); + auto nodeResult = m_portManager->acquireNodeData("AnotherProcess", "AnotherNode"); + EXPECT_THAT(nodeResult.has_error(), Eq(true)); EXPECT_THAT(errorHandlerCalled, Eq(true)); - EXPECT_THAT(nodePort.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); + EXPECT_THAT(nodeResult.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); } TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) @@ -598,10 +590,10 @@ TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) // this is done because there is no removeNodeData method in the PortManager class m_portManager->deletePortsOfProcess(newProcessName); - auto nodePort = m_portManager->acquireNodeData(newProcessName, newNodeName); - ASSERT_THAT(nodePort.has_error(), Eq(false)); - EXPECT_THAT(nodePort.value()->m_node, StrEq(newNodeName)); - EXPECT_THAT(nodePort.value()->m_process, StrEq(newProcessName)); + auto nodeResult = m_portManager->acquireNodeData(newProcessName, newNodeName); + ASSERT_THAT(nodeResult.has_error(), Eq(false)); + EXPECT_THAT(nodeResult.value()->m_node, StrEq(newNodeName)); + EXPECT_THAT(nodeResult.value()->m_process, StrEq(newProcessName)); } @@ -612,11 +604,10 @@ TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsS std::vector nodeContainer; // first acquire all possible NodeData - acquireMaxNumberOfNodes(nodeName, - processName, - [&](auto NodePort, auto newNodeName [[gnu::unused]], auto newProcessName [[gnu::unused]]) { - nodeContainer.push_back(NodePort); - }); + acquireMaxNumberOfNodes( + nodeName, processName, [&](auto node, auto newNodeName [[gnu::unused]], auto newProcessName [[gnu::unused]]) { + nodeContainer.push_back(node); + }); // set the destroy flag and let the discovery loop take care setDestroyFlagAndClearContainer(nodeContainer);