Skip to content

Commit

Permalink
iox-#2301 Fix tests for 32 bit builds
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Aug 23, 2024
1 parent eabd91e commit 2826b2b
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 21 deletions.
5 changes: 3 additions & 2 deletions iceoryx_binding_c/source/c_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ iox_sub_t iox_sub_init(iox_sub_storage_t* self,
auto meWithStoragePointer = new SubscriberWithStoragePointer();
meWithStoragePointer->subscriberStorage = self;
auto me = &meWithStoragePointer->subscriber;
assert(reinterpret_cast<uint64_t>(me) - reinterpret_cast<uint64_t>(meWithStoragePointer) == sizeof(void*)
&& "Size mismatch for SubscriberWithStoragePointer!");
auto ptrDiff = reinterpret_cast<size_t>(me) - reinterpret_cast<size_t>(meWithStoragePointer);
IOX_ENFORCE(ptrDiff >= sizeof(void*), "Size mismatch for SubscriberWithStoragePointer!");
IOX_ENFORCE(ptrDiff <= 2 * sizeof(void*), "Size mismatch for SubscriberWithStoragePointer!");

me->m_portData =
PoshRuntime::getInstance().getMiddlewareSubscriber(ServiceDescription{IdString_t(TruncateToCapacity, service),
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_binding_c/test/moduletests/test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_binding_c/test/moduletests/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion iceoryx_binding_c/test/moduletests/test_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions iceoryx_binding_c/test/moduletests/test_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp"
#include "iceoryx_posh/mepoo/mepoo_config.hpp"
#include "iox/detail/hoofs_error_reporting.hpp"
#include "iox/detail/system_configuration.hpp"

#include "iceoryx_hoofs/testing/fatal_failure.hpp"
#include "iceoryx_posh/roudi_env/minimal_iceoryx_config.hpp"
Expand Down Expand Up @@ -98,8 +99,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;

Expand Down Expand Up @@ -145,6 +146,12 @@ TEST_F(iox_sub_test, initSubscriberWithNotInitializedSubscriberOptionsTerminates
TEST_F(iox_sub_test, initSubscriberWithDefaultOptionsWorks)
{
::testing::Test::RecordProperty("TEST_ID", "40eaa006-4781-46cd-bde3-40fa7d572f29");

if (iox::detail::isCompiledOn32BitSystem())
{
GTEST_SKIP() << "@todo: 2310 This test does not work on 32 bit builds due to the usage of RouDiEnv";
}

RouDiEnv roudiEnv;

iox_runtime_init("hypnotoad");
Expand Down Expand Up @@ -402,6 +409,12 @@ TEST_F(iox_sub_test, hasDataTriggersWaitSetWithCorrectCallback)
TEST_F(iox_sub_test, deinitSubscriberDetachesTriggerFromWaitSet)
{
::testing::Test::RecordProperty("TEST_ID", "93e350fb-5430-43ff-982b-b43c6ae9b890");

if (iox::detail::isCompiledOn32BitSystem())
{
GTEST_SKIP() << "@todo: 2310 This test does not work on 32 bit builds due to the usage of RouDiEnv";
}

RouDiEnv roudiEnv;
iox_runtime_init("hypnotoad");

Expand Down
8 changes: 4 additions & 4 deletions iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>::max()};
constexpr int64_t SECONDS{std::numeric_limits<decltype(timespec::tv_sec)>::max()};
constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U};

auto duration = createDuration(SECONDS, NANOSECONDS);
Expand All @@ -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<int64_t>::max()};
constexpr int64_t SECONDS{std::numeric_limits<decltype(timespec::tv_sec)>::max()};
constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U};

const timespec sut = DurationAccessor::max().timespec(iox::units::TimeSpecReference::None);
Expand Down Expand Up @@ -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<int64_t>::max()};
constexpr int64_t SECONDS{std::numeric_limits<decltype(timespec::tv_sec)>::max()};
constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U};

const timespec sut = DurationAccessor::max().timespec(iox::units::TimeSpecReference::Monotonic);
Expand Down Expand Up @@ -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<int64_t>::max()};
constexpr int64_t SECONDS{std::numeric_limits<decltype(timespec::tv_sec)>::max()};
constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U};

const timespec sut = DurationAccessor::max().timespec(iox::units::TimeSpecReference::Epoch);
Expand Down
3 changes: 3 additions & 0 deletions iceoryx_hoofs/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
25 changes: 16 additions & 9 deletions iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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<uint8_t*>(RAW_MEMORY_BASE)};
constexpr uint32_t EXPECTED_INDEX{42};
uint8_t* const CHUNK_PTR{RAW_MEMORY_PTR + static_cast<uint64_t>(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<uint8_t*>(RAW_MEMORY_BASE)};
constexpr uint32_t EXPECTED_INDEX{42};
uint8_t* const CHUNK_PTR{RAW_MEMORY_PTR + static_cast<uint64_t>(EXPECTED_INDEX) * CHUNK_SIZE};

EXPECT_THAT(index, Eq(EXPECTED_INDEX));
EXPECT_THAT(reinterpret_cast<uint64_t>(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<uint64_t>(CHUNK_PTR) - RAW_MEMORY_BASE, Gt(5 * GB));
}
}

TEST_F(MemPool_test, MempoolCtorInitialisesTheObjectWithValuesPassedToTheCtor)
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_posh/test/moduletests/test_mepoo_segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 2826b2b

Please sign in to comment.