From 22b2625c2cfb6d54d0d7c59e6850bd6a2a70c9d6 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 6 Sep 2023 19:19:16 +0200 Subject: [PATCH] iox-#1533 Remove the gtest dependency from `RouDiEnv` --- iceoryx_posh/CMakeLists.txt | 7 ++- .../popo/building_blocks/unique_port_id.hpp | 10 ++++ iceoryx_posh/roudi_env/CMakeLists.txt | 43 ++++++++--------- .../iceoryx_posh/roudi_env/roudi_env.hpp | 5 +- iceoryx_posh/roudi_env/source/roudi_env.cpp | 13 ++---- .../popo/building_blocks/unique_port_id.cpp | 5 ++ iceoryx_posh/testing/CMakeLists.txt | 46 +++++++++---------- 7 files changed, 67 insertions(+), 62 deletions(-) diff --git a/iceoryx_posh/CMakeLists.txt b/iceoryx_posh/CMakeLists.txt index ab76579a118..6280e5cfc3d 100644 --- a/iceoryx_posh/CMakeLists.txt +++ b/iceoryx_posh/CMakeLists.txt @@ -299,9 +299,12 @@ setup_install_directories_and_export_package( INCLUDE_DIRECTORIES include/ ) -add_subdirectory(roudi_env) -add_subdirectory(testing) + +if(ROUDI_ENVIRONMENT OR BUILD_TEST) + add_subdirectory(roudi_env) +endif() if(BUILD_TEST) + add_subdirectory(testing) add_subdirectory(test) endif() diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp index 1b5abc52e8c..ab65593a05e 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp @@ -25,6 +25,11 @@ namespace iox { +namespace roudi_env +{ +class RouDiEnv; +} + namespace popo { /// @brief Struct to signal the constructor to create an invalid id @@ -74,6 +79,11 @@ class UniquePortId : public NewType([](auto, auto) {}); - iox::popo::UniquePortId::setUniqueRouDiId(uniqueRouDiId); + popo::UniquePortId::rouDiEnvOverideUniqueRouDiId(uniqueRouDiId); } RouDiEnv::RouDiEnv(const RouDiConfig_t& roudiConfig, const roudi::MonitoringMode monitoringMode, const uint16_t uniqueRouDiId) - : RouDiEnv(BaseCTor::BASE, uniqueRouDiId) + : RouDiEnv(MainCTor{}, uniqueRouDiId) { m_roudiComponents = std::unique_ptr(new roudi::IceOryxRouDiComponents(roudiConfig)); m_roudiApp = @@ -51,9 +48,7 @@ RouDiEnv::~RouDiEnv() { if (m_runtimes.m_doCleanupOnDestruction) { - // setUniqueRouDiId is called multiple times but it is okay for the tests - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler([](auto, auto) {}); - popo::UniquePortId::setUniqueRouDiId(roudi::DEFAULT_UNIQUE_ROUDI_ID); + popo::UniquePortId::rouDiEnvOverideUniqueRouDiId(roudi::DEFAULT_UNIQUE_ROUDI_ID); } cleanupRuntimes(); } diff --git a/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp b/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp index a775a4991c1..d2393584a96 100644 --- a/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp +++ b/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp @@ -63,6 +63,11 @@ void UniquePortId::setUniqueRouDiId(const uint16_t id) noexcept uniqueRouDiId.store(id, std::memory_order_relaxed); } +void UniquePortId::rouDiEnvOverideUniqueRouDiId(const uint16_t id) noexcept +{ + uniqueRouDiId.store(id, std::memory_order_relaxed); +} + bool UniquePortId::finalizeSetUniqueRouDiId() noexcept { static bool finalized{false}; diff --git a/iceoryx_posh/testing/CMakeLists.txt b/iceoryx_posh/testing/CMakeLists.txt index 24f57c52d70..2e50caf9c36 100644 --- a/iceoryx_posh/testing/CMakeLists.txt +++ b/iceoryx_posh/testing/CMakeLists.txt @@ -15,27 +15,25 @@ # # SPDX-License-Identifier: Apache-2.0 -if(ROUDI_ENVIRONMENT OR BUILD_TEST) - # - ######### posh roudi environment ########## - # - find_package(GTest CONFIG REQUIRED) - find_package(iceoryx_hoofs_testing REQUIRED) - iox_add_library( - STATIC - TARGET iceoryx_posh_testing - NAMESPACE iceoryx_posh_testing - PROJECT_PREFIX ${PREFIX} - BUILD_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include - INSTALL_INTERFACE include/${PREFIX} - EXPORT_INCLUDE_DIRS include/ - PUBLIC_LIBS GTest::gtest - GTest::gmock - iceoryx_posh::iceoryx_posh_roudi_env - PRIVATE_LIBS iceoryx_posh::iceoryx_posh - iceoryx_hoofs::iceoryx_hoofs - iceoryx_hoofs_testing::iceoryx_hoofs_testing - FILES - source/roudi_gtest.cpp - ) -endif() +# +######### posh testing ########## +# +find_package(GTest CONFIG REQUIRED) +find_package(iceoryx_hoofs_testing REQUIRED) +iox_add_library( + STATIC + TARGET iceoryx_posh_testing + NAMESPACE iceoryx_posh_testing + PROJECT_PREFIX ${PREFIX} + BUILD_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include + INSTALL_INTERFACE include/${PREFIX} + EXPORT_INCLUDE_DIRS include/ + PUBLIC_LIBS GTest::gtest + GTest::gmock + iceoryx_posh::iceoryx_posh_roudi_env + PRIVATE_LIBS iceoryx_posh::iceoryx_posh + iceoryx_hoofs::iceoryx_hoofs + iceoryx_hoofs_testing::iceoryx_hoofs_testing + FILES + source/roudi_gtest.cpp +)