Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1533 Remove the gtest dependency from RouDiEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Sep 6, 2023
1 parent a4ac9a5 commit e5aef22
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 62 deletions.
7 changes: 5 additions & 2 deletions iceoryx_posh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@

namespace iox
{
namespace roudi_env
{
class RouDiEnv;
}

namespace popo
{
/// @brief Struct to signal the constructor to create an invalid id
Expand Down Expand Up @@ -74,6 +79,11 @@ class UniquePortId : public NewType<UniquePortId,
static uint16_t getUniqueRouDiId() noexcept;

private:
friend class roudi_env::RouDiEnv;
// since the RouDiEnv gets restarted multiple times within a process, this helps to
// reset the unique RouDi id during tests
static void rouDiEnvOverideUniqueRouDiId(const uint16_t id) noexcept;

// returns true if setUniqueRouDiId was already called or a non-invalid UniquePortId
// was created, otherwise false
static bool finalizeSetUniqueRouDiId() noexcept;
Expand Down
43 changes: 19 additions & 24 deletions iceoryx_posh/roudi_env/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,22 @@
# This package must NOT depend in any way on gtest or any other testing framework since
# it will be used from other languages like Rust for integration testing.

if(ROUDI_ENVIRONMENT OR BUILD_TEST)
#
######### posh roudi env ##########
#
find_package(iceoryx_hoofs_testing REQUIRED)
iox_add_library(
STATIC
TARGET iceoryx_posh_roudi_env
NAMESPACE iceoryx_posh
PROJECT_PREFIX ${PREFIX}
BUILD_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
PRIVATE_LIBS iceoryx_posh::iceoryx_posh
iceoryx_hoofs::iceoryx_hoofs
iceoryx_hoofs_testing::iceoryx_hoofs_testing
iceoryx_posh::iceoryx_posh_roudi
FILES
source/minimal_roudi_config.cpp
source/roudi_env.cpp
source/runtime_test_interface.cpp
)
endif()

#
######### posh roudi env ##########
#
iox_add_library(
STATIC
TARGET iceoryx_posh_roudi_env
NAMESPACE iceoryx_posh
PROJECT_PREFIX ${PREFIX}
BUILD_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
PRIVATE_LIBS iceoryx_posh::iceoryx_posh
iceoryx_hoofs::iceoryx_hoofs
iceoryx_posh::iceoryx_posh_roudi
FILES
source/minimal_roudi_config.cpp
source/roudi_env.cpp
source/runtime_test_interface.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ class RouDiEnv

protected:
/// @note this is due to ambiguity of the cTor with the default parameter
enum class BaseCTor
struct MainCTor
{
BASE,
};
/// @brief for implementations on top of RouDiEnv
RouDiEnv(BaseCTor, const uint16_t uniqueRouDiId = 0u);
RouDiEnv(MainCTor, const uint16_t uniqueRouDiId = 0u);

void cleanupRuntimes();

Expand Down
13 changes: 4 additions & 9 deletions iceoryx_posh/roudi_env/source/roudi_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "iceoryx_posh/roudi_env/roudi_env.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/memory_map.hpp"
#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" // get rid of this
#include "iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp"
#include "iceoryx_posh/internal/roudi/roudi.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"
Expand All @@ -28,17 +27,15 @@ namespace iox
{
namespace roudi_env
{
RouDiEnv::RouDiEnv(BaseCTor, const uint16_t uniqueRouDiId)
RouDiEnv::RouDiEnv(MainCTor, const uint16_t uniqueRouDiId)
{
// setUniqueRouDiId is called multiple times but it is okay for the tests
auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler<iox::PoshError>([](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<roudi::IceOryxRouDiComponents>(new roudi::IceOryxRouDiComponents(roudiConfig));
m_roudiApp =
Expand All @@ -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<iox::PoshError>([](auto, auto) {});
popo::UniquePortId::setUniqueRouDiId(roudi::DEFAULT_UNIQUE_ROUDI_ID);
popo::UniquePortId::rouDiEnvOverideUniqueRouDiId(roudi::DEFAULT_UNIQUE_ROUDI_ID);
}
cleanupRuntimes();
}
Expand Down
5 changes: 5 additions & 0 deletions iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
46 changes: 22 additions & 24 deletions iceoryx_posh/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit e5aef22

Please sign in to comment.