diff --git a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp index 61483619a2..ebad3fc8aa 100644 --- a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp +++ b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp @@ -1,5 +1,6 @@ // Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Bartlomiej Kozaryna . 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. @@ -152,7 +153,8 @@ struct ChunkHeader private: // the order of these members must be changed carefully and if this happens, the m_chunkHeaderVersion // needs to be adapted in order to be able to detect incompatibilities between publisher/subscriber - // or record&replay, m_chunkHeaderVersion should therefore neither changed the type, nor the position + // or record&replay, m_chunkHeaderVersion should therefore neither changed the type, + // nor the position (offset from the beginning) uint32_t m_userHeaderSize{0U}; uint8_t m_chunkHeaderVersion{CHUNK_HEADER_VERSION}; diff --git a/iceoryx_posh/source/mepoo/chunk_settings.cpp b/iceoryx_posh/source/mepoo/chunk_settings.cpp index 624e1dafd0..b4848cfca2 100644 --- a/iceoryx_posh/source/mepoo/chunk_settings.cpp +++ b/iceoryx_posh/source/mepoo/chunk_settings.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Bartlomiej Kozaryna . 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. diff --git a/iceoryx_posh/source/mepoo/mem_pool.cpp b/iceoryx_posh/source/mepoo/mem_pool.cpp index 0e1a3a0ad6..a4bfb2fe56 100644 --- a/iceoryx_posh/source/mepoo/mem_pool.cpp +++ b/iceoryx_posh/source/mepoo/mem_pool.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. // Copyright (c) 2023 by Mathias Kraus . All rights reserved. +// Copyright (c) 2024 by Bartlomiej Kozaryna . 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. @@ -49,7 +50,8 @@ MemPool::MemPool(const greater_or_equal chunkS { if (isMultipleOfAlignment(chunkSize)) { - IOX_EXPECTS(m_chunkSize <= std::numeric_limits::max() / m_numberOfChunks); + IOX_EXPECTS_WITH_MSG(m_chunkSize <= std::numeric_limits::max() / m_numberOfChunks, + "Chunk size * number of chunks must not exceed the maximum value of uint64_t!"); auto allocationResult = chunkMemoryAllocator.allocate(static_cast(m_numberOfChunks) * m_chunkSize, CHUNK_MEMORY_ALIGNMENT); IOX_EXPECTS(allocationResult.has_value()); diff --git a/iceoryx_posh/test/integrationtests/test_client_server.cpp b/iceoryx_posh/test/integrationtests/test_client_server.cpp index 5cf034d12a..58f9b51622 100644 --- a/iceoryx_posh/test/integrationtests/test_client_server.cpp +++ b/iceoryx_posh/test/integrationtests/test_client_server.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Bartlomiej Kozaryna . 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. @@ -35,7 +36,7 @@ using namespace iox::capro; using namespace iox::runtime; using namespace iox::roudi_env; -constexpr uint64_t BIG_PAYLOAD_SIZE = std::numeric_limits::max() + 105UL; +constexpr uint64_t SIZE_LARGER_THAN_4GB = std::numeric_limits::max() + 41065UL; class DummyRequest { @@ -63,7 +64,7 @@ class DummyResponse struct BigPayloadStruct { - uint8_t bigPayload[BIG_PAYLOAD_SIZE]{0U}; + uint8_t bigPayload[SIZE_LARGER_THAN_4GB]{0U}; }; class ClientServer_test : public RouDi_GTest @@ -97,10 +98,15 @@ constexpr iox::units::Duration ClientServer_test::DEADLOCK_TIMEOUT; class BigPayloadClientServer_test : public ClientServer_test { + static constexpr uint64_t additionalSizeForUserHeader = + 2 * std::max(sizeof(iox::popo::RequestHeader), sizeof(iox::popo::ResponseHeader)); + public: BigPayloadClientServer_test() - : ClientServer_test( - MinimalRouDiConfigBuilder().payloadChunkSize(BIG_PAYLOAD_SIZE + 128).payloadChunkCount(2).create()) + : ClientServer_test(MinimalRouDiConfigBuilder() + .payloadChunkSize(SIZE_LARGER_THAN_4GB + additionalSizeForUserHeader) + .payloadChunkCount(2) + .create()) { } @@ -490,7 +496,7 @@ TEST_F(BigPayloadClientServer_test, TypedApiWithBigPayloadWithMatchingOptionsWor constexpr int64_t SEQUENCE_ID{73}; constexpr uint64_t FIRST{4095}; - constexpr uint64_t LAST{BIG_PAYLOAD_SIZE - 1}; + constexpr uint64_t LAST{SIZE_LARGER_THAN_4GB - 1}; constexpr uint64_t STEP{4096}; constexpr uint8_t SHIFT{13U}; @@ -503,9 +509,11 @@ TEST_F(BigPayloadClientServer_test, TypedApiWithBigPayloadWithMatchingOptionsWor ASSERT_FALSE(loanResult.has_error()); auto& request = loanResult.value(); request.getRequestHeader().setSequenceId(SEQUENCE_ID); + uint8_t valueCounter = 0; for (uint64_t i = FIRST; i <= LAST; i += STEP) { - request->bigPayload[i] = static_cast((i / STEP) % 256U); + request->bigPayload[i] = valueCounter; + valueCounter++; } ASSERT_FALSE(client.send(std::move(request)).has_error()); } @@ -532,9 +540,11 @@ TEST_F(BigPayloadClientServer_test, TypedApiWithBigPayloadWithMatchingOptionsWor ASSERT_FALSE(takeResult.has_error()); auto& response = takeResult.value(); EXPECT_THAT(response.getResponseHeader().getSequenceId(), Eq(SEQUENCE_ID)); + uint8_t valueCounter = 0; for (uint64_t i = FIRST; i <= LAST; i += STEP) { - ASSERT_THAT(response->bigPayload[i], Eq(static_cast(((i / STEP) % 256U) + SHIFT))); + ASSERT_THAT(response->bigPayload[i], Eq(static_cast(valueCounter + SHIFT))); + valueCounter++; } } } @@ -545,7 +555,7 @@ TEST_F(BigPayloadClientServer_test, UntypedApiWithBigPayloadWithMatchingOptionsW constexpr int64_t SEQUENCE_ID{37}; constexpr uint64_t FIRST{4095}; - constexpr uint64_t LAST{BIG_PAYLOAD_SIZE - 1}; + constexpr uint64_t LAST{SIZE_LARGER_THAN_4GB - 1}; constexpr uint64_t STEP{4096}; constexpr uint8_t SHIFT{13U}; @@ -558,9 +568,11 @@ TEST_F(BigPayloadClientServer_test, UntypedApiWithBigPayloadWithMatchingOptionsW ASSERT_FALSE(loanResult.has_error()); auto request = static_cast(loanResult.value()); RequestHeader::fromPayload(request)->setSequenceId(SEQUENCE_ID); + uint8_t valueCounter = 0; for (uint64_t i = FIRST; i <= LAST; i += STEP) { - request->bigPayload[i] = static_cast((i / STEP) % 256U); + request->bigPayload[i] = valueCounter; + valueCounter++; } ASSERT_FALSE(client.send(request).has_error()); } @@ -589,9 +601,11 @@ TEST_F(BigPayloadClientServer_test, UntypedApiWithBigPayloadWithMatchingOptionsW ASSERT_FALSE(takeResult.has_error()); auto response = static_cast(takeResult.value()); EXPECT_THAT(ResponseHeader::fromPayload(response)->getSequenceId(), Eq(SEQUENCE_ID)); + uint8_t valueCounter = 0; for (uint64_t i = FIRST; i <= LAST; i += STEP) { - ASSERT_THAT(response->bigPayload[i], Eq(static_cast(((i / STEP) % 256U) + SHIFT))); + ASSERT_THAT(response->bigPayload[i], Eq(static_cast(valueCounter + SHIFT))); + valueCounter++; } client.releaseResponse(response); } diff --git a/iceoryx_posh/test/integrationtests/test_publisher_subscriber_communication.cpp b/iceoryx_posh/test/integrationtests/test_publisher_subscriber_communication.cpp index 0eb8684102..25e1de438b 100644 --- a/iceoryx_posh/test/integrationtests/test_publisher_subscriber_communication.cpp +++ b/iceoryx_posh/test/integrationtests/test_publisher_subscriber_communication.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. // Copyright (c) 2022 by NXP. All rights reserved. +// Copyright (c) 2024 by Bartlomiej Kozaryna . 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. @@ -41,7 +42,7 @@ using namespace iox::popo; using namespace iox::roudi_env; using namespace iox::testing; -constexpr uint64_t BIG_PAYLOAD_SIZE = std::numeric_limits::max() + 105UL; +constexpr uint64_t SIZE_LARGER_THAN_4GB = std::numeric_limits::max() + 41065UL; template struct ComplexDataType @@ -52,7 +53,7 @@ struct ComplexDataType struct BigPayloadStruct { - uint8_t bigPayload[BIG_PAYLOAD_SIZE]; + uint8_t bigPayload[SIZE_LARGER_THAN_4GB]; }; class PublisherSubscriberCommunication_test : public RouDi_GTest @@ -149,10 +150,16 @@ class PublisherSubscriberCommunication_test : public RouDi_GTest class PublisherSubscriberCommunicationWithBigPayload_test : public PublisherSubscriberCommunication_test { + static constexpr uint64_t additionalSizeForUserHeader = + 2 * std::max(sizeof(iox::popo::RequestHeader), sizeof(iox::popo::ResponseHeader)); + public: PublisherSubscriberCommunicationWithBigPayload_test() : PublisherSubscriberCommunication_test( - MinimalRouDiConfigBuilder().payloadChunkSize(BIG_PAYLOAD_SIZE + 128).payloadChunkCount(2).create()) + MinimalRouDiConfigBuilder() + .payloadChunkSize(SIZE_LARGER_THAN_4GB + additionalSizeForUserHeader) + .payloadChunkCount(2) + .create()) { } @@ -753,11 +760,13 @@ TEST_F(PublisherSubscriberCommunicationWithBigPayload_test, SendingComplexDataTy auto publisher = createPublisher(); auto subscriber = createSubscriber(); + constexpr uint64_t PAGE_SIZE = 4096; + ASSERT_FALSE(publisher->loan() .and_then([](auto& sample) { - for (uint64_t i = 4095; i < BIG_PAYLOAD_SIZE; i += 4096) + for (uint64_t i = PAGE_SIZE - 1; i < SIZE_LARGER_THAN_4GB; i += PAGE_SIZE) { - sample->complexType.bigPayload[i] = static_cast((i / 4096) % 256U); + sample->complexType.bigPayload[i] = static_cast(i / PAGE_SIZE); } sample.publish(); }) @@ -765,10 +774,9 @@ TEST_F(PublisherSubscriberCommunicationWithBigPayload_test, SendingComplexDataTy EXPECT_FALSE(subscriber->take() .and_then([](auto& sample) { - for (uint64_t i = 4095; i < BIG_PAYLOAD_SIZE; i += 4096) + for (uint64_t i = PAGE_SIZE - 1; i < SIZE_LARGER_THAN_4GB; i += PAGE_SIZE) { - ASSERT_THAT(sample->complexType.bigPayload[i], - Eq(static_cast((i / 4096) % 256U))); + ASSERT_THAT(sample->complexType.bigPayload[i], Eq(static_cast(i / PAGE_SIZE))); } }) .has_error());