From 7860e39d80f0633a765221c52721971a4d1a8fe0 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 23 Aug 2024 00:26:37 +0200 Subject: [PATCH] iox-#2301 Fix tests for 32 bit builds --- .../test/moduletests/test_client.cpp | 2 +- .../test/moduletests/test_publisher.cpp | 2 +- .../test/moduletests/test_server.cpp | 2 +- .../test/moduletests/test_subscriber.cpp | 4 +-- .../moduletests/test_time_unit_duration.cpp | 8 +++--- iceoryx_hoofs/testing/CMakeLists.txt | 3 +++ .../test/moduletests/test_mepoo_mempool.cpp | 25 ++++++++++++------- .../test/moduletests/test_mepoo_segment.cpp | 2 +- 8 files changed, 29 insertions(+), 19 deletions(-) diff --git a/iceoryx_binding_c/test/moduletests/test_client.cpp b/iceoryx_binding_c/test/moduletests/test_client.cpp index 02861d195f..3f74e6a615 100644 --- a/iceoryx_binding_c/test/moduletests/test_client.cpp +++ b/iceoryx_binding_c/test/moduletests/test_client.cpp @@ -109,7 +109,7 @@ class iox_client_test : public Test char managementMemory[MANAGEMENT_MEMORY_SIZE]; iox::BumpAllocator mgmtAllocator{managementMemory, MANAGEMENT_MEMORY_SIZE}; static constexpr uint64_t DATA_MEMORY_SIZE = 1024 * 1024; - char dataMemory[DATA_MEMORY_SIZE]; + alignas(8) char dataMemory[DATA_MEMORY_SIZE]; iox::BumpAllocator dataAllocator{dataMemory, DATA_MEMORY_SIZE}; iox::mepoo::MemoryManager memoryManager; iox::mepoo::MePooConfig memoryConfig; diff --git a/iceoryx_binding_c/test/moduletests/test_publisher.cpp b/iceoryx_binding_c/test/moduletests/test_publisher.cpp index 484cf185dd..ee9f37e126 100644 --- a/iceoryx_binding_c/test/moduletests/test_publisher.cpp +++ b/iceoryx_binding_c/test/moduletests/test_publisher.cpp @@ -97,7 +97,7 @@ class iox_pub_test : public Test } static constexpr size_t MEMORY_SIZE = 1024 * 1024; - uint8_t m_memory[MEMORY_SIZE]; + alignas(8) uint8_t m_memory[MEMORY_SIZE]; static constexpr uint32_t NUM_CHUNKS_IN_POOL = 20; static constexpr uint64_t CHUNK_SIZE = 256; diff --git a/iceoryx_binding_c/test/moduletests/test_server.cpp b/iceoryx_binding_c/test/moduletests/test_server.cpp index 7b6f9ca793..642847c076 100644 --- a/iceoryx_binding_c/test/moduletests/test_server.cpp +++ b/iceoryx_binding_c/test/moduletests/test_server.cpp @@ -104,7 +104,7 @@ class iox_server_test : public Test char managementMemory[MANAGEMENT_MEMORY_SIZE]; iox::BumpAllocator mgmtAllocator{managementMemory, MANAGEMENT_MEMORY_SIZE}; static constexpr uint64_t DATA_MEMORY_SIZE = 1024 * 1024; - char dataMemory[DATA_MEMORY_SIZE]; + alignas(8) char dataMemory[DATA_MEMORY_SIZE]; iox::BumpAllocator dataAllocator{dataMemory, DATA_MEMORY_SIZE}; iox::mepoo::MemoryManager memoryManager; iox::mepoo::MePooConfig memoryConfig; diff --git a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp index b75647ed91..9198258ce9 100644 --- a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp +++ b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp @@ -98,8 +98,8 @@ class iox_sub_test : public Test } static iox_sub_t m_triggerCallbackLatestArgument; - static constexpr size_t MEMORY_SIZE = 1024 * 1024 * 100; - uint8_t m_memory[MEMORY_SIZE]; + static constexpr size_t MEMORY_SIZE = 1024 * 1024; + alignas(8) uint8_t m_memory[MEMORY_SIZE]; static constexpr uint32_t NUM_CHUNKS_IN_POOL = MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY + 2U; static constexpr uint64_t CHUNK_SIZE = 128U; diff --git a/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp b/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp index 5cf61a5026..8c5f842d2b 100644 --- a/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp +++ b/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp @@ -1050,7 +1050,7 @@ TEST(Duration_test, ConvertTimespecWithNoneReferenceFromDurationMoreThanOneSecon TEST(Duration_test, ConvertTimespecWithNoneReferenceFromDurationResultsNotYetInSaturation) { ::testing::Test::RecordProperty("TEST_ID", "70f11b99-78ec-442a-aefe-4dd9152b7903"); - constexpr int64_t SECONDS{std::numeric_limits::max()}; + constexpr int64_t SECONDS{std::numeric_limits::max()}; constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U}; auto duration = createDuration(SECONDS, NANOSECONDS); @@ -1064,7 +1064,7 @@ TEST(Duration_test, ConvertTimespecWithNoneReferenceFromDurationResultsNotYetInS TEST(Duration_test, ConvertTimespecWithNoneReferenceFromMaxDurationResultsInSaturation) { ::testing::Test::RecordProperty("TEST_ID", "3bf4bb34-46f3-4889-84f5-9220b32fff73"); - constexpr int64_t SECONDS{std::numeric_limits::max()}; + constexpr int64_t SECONDS{std::numeric_limits::max()}; constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U}; const timespec sut = DurationAccessor::max().timespec(iox::units::TimeSpecReference::None); @@ -1101,7 +1101,7 @@ TEST(Duration_test, ConvertTimespecWithMonotonicReference) TEST(Duration_test, ConvertTimespecWithMonotonicReferenceFromMaxDurationResultsInSaturation) { ::testing::Test::RecordProperty("TEST_ID", "ff5a1fe2-65c8-490a-b31d-4d8ea615c91a"); - constexpr int64_t SECONDS{std::numeric_limits::max()}; + constexpr int64_t SECONDS{std::numeric_limits::max()}; constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U}; const timespec sut = DurationAccessor::max().timespec(iox::units::TimeSpecReference::Monotonic); @@ -1129,7 +1129,7 @@ TEST(Duration_test, ConvertTimespecWithEpochReference) TEST(Duration_test, ConvertTimespecWithEpochReferenceFromMaxDurationResultsInSaturation) { ::testing::Test::RecordProperty("TEST_ID", "97ff4204-a7f7-43ef-b81e-0e359d1dce93"); - constexpr int64_t SECONDS{std::numeric_limits::max()}; + constexpr int64_t SECONDS{std::numeric_limits::max()}; constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U}; const timespec sut = DurationAccessor::max().timespec(iox::units::TimeSpecReference::Epoch); diff --git a/iceoryx_hoofs/testing/CMakeLists.txt b/iceoryx_hoofs/testing/CMakeLists.txt index fffa71d365..202ec59977 100644 --- a/iceoryx_hoofs/testing/CMakeLists.txt +++ b/iceoryx_hoofs/testing/CMakeLists.txt @@ -38,6 +38,9 @@ iox_add_library( error_reporting/testing_support.cpp ) +# deactivate _FORTIFY_SOURCE since it causes issues with longjmp in the testing logger and error handler +target_compile_options(iceoryx_hoofs_testing PRIVATE -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0) + if(TEST_WITH_ADDITIONAL_USER) target_compile_definitions(iceoryx_hoofs_testing PUBLIC -DTEST_WITH_ADDITIONAL_USER) endif(TEST_WITH_ADDITIONAL_USER) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp index 53749a4469..80b1cd207f 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp @@ -20,6 +20,7 @@ #include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/bump_allocator.hpp" #include "iox/detail/hoofs_error_reporting.hpp" +#include "iox/detail/system_configuration.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" @@ -46,9 +47,6 @@ class MemPool_test : public Test { } - void SetUp(){}; - void TearDown(){}; - alignas(MemPool::CHUNK_MEMORY_ALIGNMENT) uint8_t m_rawMemory[NUMBER_OF_CHUNKS * CHUNK_SIZE + LOFFLI_MEMORY_REQUIREMENT]; iox::BumpAllocator allocator; @@ -138,14 +136,23 @@ TEST_F(MemPool_test, MempoolPointeToIndexConversionForMemoryOffsetsLargerThan4GB constexpr uint64_t GB{1ULL << 30}; constexpr uint64_t CHUNK_SIZE{128 * MB}; constexpr uint64_t RAW_MEMORY_BASE{0x7f60d90c5000ULL}; - uint8_t* const RAW_MEMORY_PTR{reinterpret_cast(RAW_MEMORY_BASE)}; - constexpr uint32_t EXPECTED_INDEX{42}; - uint8_t* const CHUNK_PTR{RAW_MEMORY_PTR + static_cast(EXPECTED_INDEX) * CHUNK_SIZE}; - const auto index = MemPool::pointerToIndex(CHUNK_PTR, CHUNK_SIZE, RAW_MEMORY_PTR); + if constexpr (iox::detail::isCompiledOn32BitSystem()) + { + GTEST_SKIP() << "This test does not work on 32 bit builds since it requires pointer larger than the 32 bit " + "address space"; + } + else + { + uint8_t* const RAW_MEMORY_PTR{reinterpret_cast(RAW_MEMORY_BASE)}; + constexpr uint32_t EXPECTED_INDEX{42}; + uint8_t* const CHUNK_PTR{RAW_MEMORY_PTR + static_cast(EXPECTED_INDEX) * CHUNK_SIZE}; - EXPECT_THAT(index, Eq(EXPECTED_INDEX)); - EXPECT_THAT(reinterpret_cast(CHUNK_PTR) - RAW_MEMORY_BASE, Gt(5 * GB)); + const auto index = MemPool::pointerToIndex(CHUNK_PTR, CHUNK_SIZE, RAW_MEMORY_PTR); + + EXPECT_THAT(index, Eq(EXPECTED_INDEX)); + EXPECT_THAT(reinterpret_cast(CHUNK_PTR) - RAW_MEMORY_BASE, Gt(5 * GB)); + } } TEST_F(MemPool_test, MempoolCtorInitialisesTheObjectWithValuesPassedToTheCtor) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp index 12406772fb..03e87ff121 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp @@ -90,7 +90,7 @@ class MePooSegment_test : public Test uint64_t m_memorySizeInBytes{0}; void* m_baseAddressHint{nullptr}; static constexpr int MEM_SIZE = 100000; - char memory[MEM_SIZE]; + alignas(8) char memory[MEM_SIZE]; shm_handle_t filehandle; static createFct createVerificator; };