Skip to content

Commit

Permalink
iox-#2157 Refactor tests and add cc
Browse files Browse the repository at this point in the history
  • Loading branch information
kozakusek committed Feb 1, 2024
1 parent f694aca commit ba5178c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 20 deletions.
4 changes: 3 additions & 1 deletion iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>. 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.
Expand Down Expand Up @@ -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};
Expand Down
1 change: 1 addition & 0 deletions iceoryx_posh/source/mepoo/chunk_settings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Bartlomiej Kozaryna <[email protected]>. 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.
Expand Down
4 changes: 3 additions & 1 deletion iceoryx_posh/source/mepoo/mem_pool.cpp
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>. All rights reserved.
// Copyright (c) 2024 by Bartlomiej Kozaryna <[email protected]>. 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.
Expand Down Expand Up @@ -49,7 +50,8 @@ MemPool::MemPool(const greater_or_equal<uint64_t, CHUNK_MEMORY_ALIGNMENT> chunkS
{
if (isMultipleOfAlignment(chunkSize))
{
IOX_EXPECTS(m_chunkSize <= std::numeric_limits<uint64_t>::max() / m_numberOfChunks);
IOX_EXPECTS_WITH_MSG(m_chunkSize <= std::numeric_limits<uint64_t>::max() / m_numberOfChunks,
"Chunk size * number of chunks must not exceed the maximum value of uint64_t!");
auto allocationResult = chunkMemoryAllocator.allocate(static_cast<uint64_t>(m_numberOfChunks) * m_chunkSize,
CHUNK_MEMORY_ALIGNMENT);
IOX_EXPECTS(allocationResult.has_value());
Expand Down
34 changes: 24 additions & 10 deletions iceoryx_posh/test/integrationtests/test_client_server.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2024 by Bartlomiej Kozaryna <[email protected]>. 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.
Expand Down Expand Up @@ -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<uint32_t>::max() + 105UL;
constexpr uint64_t SIZE_LARGER_THAN_4GB = std::numeric_limits<uint32_t>::max() + 41065UL;

class DummyRequest
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
{
}

Expand Down Expand Up @@ -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};

Expand All @@ -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<uint8_t>((i / STEP) % 256U);
request->bigPayload[i] = valueCounter;
valueCounter++;
}
ASSERT_FALSE(client.send(std::move(request)).has_error());
}
Expand All @@ -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<uint8_t>(((i / STEP) % 256U) + SHIFT)));
ASSERT_THAT(response->bigPayload[i], Eq(static_cast<uint8_t>(valueCounter + SHIFT)));
valueCounter++;
}
}
}
Expand All @@ -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};

Expand All @@ -558,9 +568,11 @@ TEST_F(BigPayloadClientServer_test, UntypedApiWithBigPayloadWithMatchingOptionsW
ASSERT_FALSE(loanResult.has_error());
auto request = static_cast<BigPayloadStruct*>(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<uint8_t>((i / STEP) % 256U);
request->bigPayload[i] = valueCounter;
valueCounter++;
}
ASSERT_FALSE(client.send(request).has_error());
}
Expand Down Expand Up @@ -589,9 +601,11 @@ TEST_F(BigPayloadClientServer_test, UntypedApiWithBigPayloadWithMatchingOptionsW
ASSERT_FALSE(takeResult.has_error());
auto response = static_cast<const BigPayloadStruct*>(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<uint8_t>(((i / STEP) % 256U) + SHIFT)));
ASSERT_THAT(response->bigPayload[i], Eq(static_cast<uint8_t>(valueCounter + SHIFT)));
valueCounter++;
}
client.releaseResponse(response);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>. 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.
Expand Down Expand Up @@ -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<uint32_t>::max() + 105UL;
constexpr uint64_t SIZE_LARGER_THAN_4GB = std::numeric_limits<uint32_t>::max() + 41065UL;

template <typename T>
struct ComplexDataType
Expand All @@ -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
Expand Down Expand Up @@ -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())
{
}

Expand Down Expand Up @@ -753,22 +760,23 @@ TEST_F(PublisherSubscriberCommunicationWithBigPayload_test, SendingComplexDataTy
auto publisher = createPublisher<Type_t>();
auto subscriber = createSubscriber<Type_t>();

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<uint8_t>((i / 4096) % 256U);
sample->complexType.bigPayload[i] = static_cast<uint8_t>(i / PAGE_SIZE);
}
sample.publish();
})
.has_error());

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<uint8_t>((i / 4096) % 256U)));
ASSERT_THAT(sample->complexType.bigPayload[i], Eq(static_cast<uint8_t>(i / PAGE_SIZE)));
}
})
.has_error());
Expand Down

0 comments on commit ba5178c

Please sign in to comment.