From 2d1a2bfc0ec3f2dd2e551bd2a72eff6024c80875 Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Thu, 21 Jan 2021 13:36:00 +0530 Subject: [PATCH 01/89] iox-#496 added unit test for port_pool in roudi folder Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_roudi_portpool.cpp | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 iceoryx_posh/test/moduletests/test_roudi_portpool.cpp diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp new file mode 100644 index 0000000000..0e85472075 --- /dev/null +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -0,0 +1,56 @@ +// Copyright (c) 2021 by Robert Bosch GmbH. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "iceoryx_posh/internal/roudi/port_pool_data.hpp" +#include "iceoryx_posh/internal/runtime/node_data.hpp" +#include "iceoryx_posh/roudi/port_pool.hpp" +#include +#include + +using namespace ::testing; +using ::testing::Return; + +namespace example +{ +namespace test +{ +class PortPool_test : public Test +{ + public: + iox::roudi::PortPoolData* portPoolData = new iox::roudi::PortPoolData{}; +}; + +TEST_F(PortPool_test, AddNodeDataFailsWhenNodeListIsFull) +{ + auto errorHandlerCalled{false}; + iox::Error errorHandlerType; + auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + [&](const iox::Error error, const std::function, const iox::ErrorLevel) { + errorHandlerType = error; + errorHandlerCalled = true; + }); + + for (uint32_t i = 0; i < iox::MAX_NODE_NUMBER; ++i) + { + portPoolData->m_nodeMembers.insert("processName", "nodeName", i); + } + + iox::roudi::PortPool portPool(*portPoolData); + portPool.addNodeData("processName", "nameName", 999u); + + EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__NODELIST_OVERFLOW); +} + +} // namespace test +} // namespace example From e80140dc19f38ec4f06cd1506422794218704877 Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Fri, 29 Jan 2021 15:46:01 +0530 Subject: [PATCH 02/89] iox-#496 fix review points Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_roudi_portpool.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 0e85472075..b6055f6b30 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -15,20 +15,17 @@ #include "iceoryx_posh/internal/roudi/port_pool_data.hpp" #include "iceoryx_posh/internal/runtime/node_data.hpp" #include "iceoryx_posh/roudi/port_pool.hpp" -#include -#include +#include "test.hpp" using namespace ::testing; using ::testing::Return; -namespace example -{ namespace test { class PortPool_test : public Test { public: - iox::roudi::PortPoolData* portPoolData = new iox::roudi::PortPoolData{}; + iox::roudi::PortPoolData portPoolData; }; TEST_F(PortPool_test, AddNodeDataFailsWhenNodeListIsFull) @@ -41,16 +38,15 @@ TEST_F(PortPool_test, AddNodeDataFailsWhenNodeListIsFull) errorHandlerCalled = true; }); - for (uint32_t i = 0; i < iox::MAX_NODE_NUMBER; ++i) + for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; ++i) { - portPoolData->m_nodeMembers.insert("processName", "nodeName", i); + portPoolData.m_nodeMembers.insert("processName", "nodeName", i); } - iox::roudi::PortPool portPool(*portPoolData); - portPool.addNodeData("processName", "nameName", 999u); - + iox::roudi::PortPool sut(portPoolData); + sut.addNodeData("processName", "nameName", 999U); + ASSERT_THAT(errorHandlerCalled, Eq(true)); EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__NODELIST_OVERFLOW); } } // namespace test -} // namespace example From 7f93ded4d8d12f31514860be1cc3fedef3b28bdf Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Wed, 3 Feb 2021 18:09:06 +0530 Subject: [PATCH 03/89] iox-#496 fix review point Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- iceoryx_posh/test/moduletests/test_roudi_portpool.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index b6055f6b30..85c1919991 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -26,6 +26,7 @@ class PortPool_test : public Test { public: iox::roudi::PortPoolData portPoolData; + iox::roudi::PortPool sut{portPoolData}; }; TEST_F(PortPool_test, AddNodeDataFailsWhenNodeListIsFull) @@ -38,13 +39,10 @@ TEST_F(PortPool_test, AddNodeDataFailsWhenNodeListIsFull) errorHandlerCalled = true; }); - for (uint32_t i = 0U; i < iox::MAX_NODE_NUMBER; ++i) + for (uint32_t i = 0U; i <= iox::MAX_NODE_NUMBER; ++i) { - portPoolData.m_nodeMembers.insert("processName", "nodeName", i); + sut.addNodeData("processName", "nameName", i); } - - iox::roudi::PortPool sut(portPoolData); - sut.addNodeData("processName", "nameName", 999U); ASSERT_THAT(errorHandlerCalled, Eq(true)); EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__NODELIST_OVERFLOW); } From e250daa6dbbaf035be1ec8a6ab94b85b9f13827a Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Mon, 8 Feb 2021 22:38:16 +0530 Subject: [PATCH 04/89] iox-#496 added moduletest for port_pool Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_roudi_portpool.cpp | 211 +++++++++++++++++- 1 file changed, 210 insertions(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 85c1919991..5b21cb2a5c 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -14,14 +14,18 @@ #include "iceoryx_posh/internal/roudi/port_pool_data.hpp" #include "iceoryx_posh/internal/runtime/node_data.hpp" +#include "iceoryx_posh/popo/typed_subscriber.hpp" #include "iceoryx_posh/roudi/port_pool.hpp" #include "test.hpp" using namespace ::testing; using ::testing::Return; +using namespace iox::capro; namespace test { +static constexpr uint32_t DEFAULT_DEVICE_ID{0u}; +static constexpr uint32_t DEFAULT_MEMORY_TYPE{0u}; class PortPool_test : public Test { public: @@ -29,6 +33,33 @@ class PortPool_test : public Test iox::roudi::PortPool sut{portPoolData}; }; +TEST_F(PortPool_test, AddNodeDataSuccessfully) +{ + auto nodeData = sut.addNodeData("processName", "nodeName", 999U); + + ASSERT_THAT(nodeData.value()->m_process, Eq(iox::ProcessName_t("processName"))); + ASSERT_THAT(nodeData.value()->m_node, Eq(iox::ProcessName_t("nodeName"))); + ASSERT_THAT(nodeData.value()->m_nodeDeviceIdentifier, Eq(999U)); +} + + +TEST_F(PortPool_test, AddMaxNodeDataSuccessfully) +{ + iox::cxx::vector nodeContainer; + + for (uint32_t i = 1U; i <= iox::MAX_NODE_NUMBER; ++i) + { + auto nodeData = sut.addNodeData("processName", "nodeName", i); + if (!nodeData.has_error()) + { + nodeContainer.push_back(nodeData.value()); + } + } + + ASSERT_THAT(nodeContainer.size(), Eq(iox::MAX_NODE_NUMBER)); +} + + TEST_F(PortPool_test, AddNodeDataFailsWhenNodeListIsFull) { auto errorHandlerCalled{false}; @@ -41,10 +72,188 @@ TEST_F(PortPool_test, AddNodeDataFailsWhenNodeListIsFull) for (uint32_t i = 0U; i <= iox::MAX_NODE_NUMBER; ++i) { - sut.addNodeData("processName", "nameName", i); + sut.addNodeData("processName", "nodeName", i); } + ASSERT_THAT(errorHandlerCalled, Eq(true)); EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__NODELIST_OVERFLOW); } + +TEST_F(PortPool_test, GetNodeDataListSuccessfully) +{ + sut.addNodeData("processName", "nodeName", 999U); + auto nodeDataList = sut.getNodeDataList(); + + ASSERT_THAT(nodeDataList.size(), Eq(1U)); +} + +TEST_F(PortPool_test, GetMaxNodeDataListSuccessfully) +{ + iox::cxx::vector nodeContainer; + + for (uint32_t i = 1U; i <= iox::MAX_NODE_NUMBER; ++i) + { + auto nodeData = sut.addNodeData("processName", "nodeName", i); + if (!nodeData.has_error()) + { + nodeContainer.push_back(nodeData.value()); + } + } + + auto nodeDataList = sut.getNodeDataList(); + ASSERT_THAT(nodeDataList.size(), Eq(iox::MAX_NODE_NUMBER)); +} + + +TEST_F(PortPool_test, AddPublisherPortSuccessfully) +{ + iox::capro::ServiceDescription serviceDescription("service1", "instance1"); + iox::mepoo::MemoryManager memoryManager; + iox::ProcessName_t applicationName("AppNmae"); + iox::popo::PublisherOptions publisherOptions; + + auto publisherPort = sut.addPublisherPort(serviceDescription, &memoryManager, applicationName, publisherOptions); + + EXPECT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); + EXPECT_EQ(publisherPort.value()->m_processName, iox::ProcessName_t{"AppNmae"}); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); + EXPECT_EQ(publisherPort.value()->m_nodeName, iox::NodeName_t{""}); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); +} + +TEST_F(PortPool_test, AddMaxPublisherPortSuccessfully) +{ + iox::mepoo::MemoryManager memoryManager; + iox::popo::PublisherOptions publisherOptions; + + for (uint32_t i = 0; i < iox::MAX_PUBLISHERS; ++i) + { + std::string service = "service" + std::to_string(i); + std::string instance = "instance" + std::to_string(i); + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + + + auto publisherPort = sut.addPublisherPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), + iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, + &memoryManager, + applicationName, + publisherOptions); + + EXPECT_THAT(publisherPort.value()->m_serviceDescription, + Eq(ServiceDescription{iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), + iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)})); + EXPECT_EQ(publisherPort.value()->m_processName, applicationName); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); + EXPECT_EQ(publisherPort.value()->m_nodeName, iox::NodeName_t{""}); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + } +} + +TEST_F(PortPool_test, AddPublisherPortOverflow) +{ + iox::mepoo::MemoryManager memoryManager; + iox::popo::PublisherOptions publisherOptions; + + auto errorHandlerCalled{false}; + iox::Error errorHandlerType; + auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + [&](const iox::Error error, const std::function, const iox::ErrorLevel) { + errorHandlerType = error; + errorHandlerCalled = true; + }); + + for (uint32_t i = 0; i <= iox::MAX_PUBLISHERS; ++i) + { + std::string service = "service" + std::to_string(i); + std::string instance = "instance" + std::to_string(i); + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + + + auto publisherPort = sut.addPublisherPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), + iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, + &memoryManager, + applicationName, + publisherOptions); + } + + ASSERT_THAT(errorHandlerCalled, Eq(true)); + EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW); +} + +TEST_F(PortPool_test, AddSubscriberPortSuccessfully) +{ + iox::capro::ServiceDescription serviceDescription("service1", "instance1"); + iox::ProcessName_t applicationName("AppNmae"); + iox::popo::SubscriberOptions subscriberOptions; + + auto subscriberPort = sut.addSubscriberPort(serviceDescription, applicationName, subscriberOptions); + + EXPECT_THAT(subscriberPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); + EXPECT_EQ(subscriberPort.value()->m_processName, iox::ProcessName_t{"AppNmae"}); + EXPECT_EQ(subscriberPort.value()->m_nodeName, iox::NodeName_t{""}); + EXPECT_EQ(subscriberPort.value()->m_historyRequest, 0U); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_queue.capacity(), 256U); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); +} + +TEST_F(PortPool_test, AddMaximumSubscriberPortSuccessfully) +{ + iox::popo::SubscriberOptions subscriberOptions; + + for (uint32_t i = 0; i < iox::MAX_SUBSCRIBERS; ++i) + { + std::string service = "service" + std::to_string(i); + std::string instance = "instance" + std::to_string(i); + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + + + auto subscriberPort = sut.addSubscriberPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), + iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, + applicationName, + subscriberOptions); + + EXPECT_THAT(subscriberPort.value()->m_serviceDescription, + Eq(ServiceDescription{iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), + iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)})); + EXPECT_EQ(subscriberPort.value()->m_processName, applicationName); + EXPECT_EQ(subscriberPort.value()->m_nodeName, iox::NodeName_t{""}); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + } +} + + +TEST_F(PortPool_test, AddSubscriberPortOverflow) +{ + iox::popo::SubscriberOptions subscriberOptions; + + auto errorHandlerCalled{false}; + iox::Error errorHandlerType; + auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + [&](const iox::Error error, const std::function, const iox::ErrorLevel) { + errorHandlerType = error; + errorHandlerCalled = true; + }); + + for (uint32_t i = 0; i <= iox::MAX_SUBSCRIBERS; ++i) + { + std::string service = "service" + std::to_string(i); + std::string instance = "instance" + std::to_string(i); + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + + + auto publisherPort = sut.addSubscriberPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), + iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, + applicationName, + subscriberOptions); + } + + ASSERT_THAT(errorHandlerCalled, Eq(true)); + EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); +} + } // namespace test From 22d52e5a32bd065e0a2969bb310d5970dd831502 Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Wed, 10 Feb 2021 12:48:44 +0530 Subject: [PATCH 05/89] iox-#496 added moduletest for port_pool Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_roudi_portpool.cpp | 110 ++++++++++++++---- 1 file changed, 90 insertions(+), 20 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 5b21cb2a5c..05063bd6cd 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -31,6 +31,12 @@ class PortPool_test : public Test public: iox::roudi::PortPoolData portPoolData; iox::roudi::PortPool sut{portPoolData}; + + iox::capro::ServiceDescription serviceDescription{"service1", "instance1"}; + iox::ProcessName_t applicationName{"AppNmae"}; + iox::mepoo::MemoryManager memoryManager; + iox::popo::PublisherOptions publisherOptions; + iox::popo::SubscriberOptions subscriberOptions; }; TEST_F(PortPool_test, AddNodeDataSuccessfully) @@ -105,14 +111,17 @@ TEST_F(PortPool_test, GetMaxNodeDataListSuccessfully) ASSERT_THAT(nodeDataList.size(), Eq(iox::MAX_NODE_NUMBER)); } +TEST_F(PortPool_test, RemoveNodeDataSuccessfully) +{ + auto nodeData = sut.addNodeData("processName", "nodeName", 999U); + sut.removeNodeData(nodeData.value()); + auto nodeDataList = sut.getNodeDataList(); + + ASSERT_THAT(nodeDataList.size(), Eq(0U)); +} TEST_F(PortPool_test, AddPublisherPortSuccessfully) { - iox::capro::ServiceDescription serviceDescription("service1", "instance1"); - iox::mepoo::MemoryManager memoryManager; - iox::ProcessName_t applicationName("AppNmae"); - iox::popo::PublisherOptions publisherOptions; - auto publisherPort = sut.addPublisherPort(serviceDescription, &memoryManager, applicationName, publisherOptions); EXPECT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); @@ -125,9 +134,6 @@ TEST_F(PortPool_test, AddPublisherPortSuccessfully) TEST_F(PortPool_test, AddMaxPublisherPortSuccessfully) { - iox::mepoo::MemoryManager memoryManager; - iox::popo::PublisherOptions publisherOptions; - for (uint32_t i = 0; i < iox::MAX_PUBLISHERS; ++i) { std::string service = "service" + std::to_string(i); @@ -154,9 +160,6 @@ TEST_F(PortPool_test, AddMaxPublisherPortSuccessfully) TEST_F(PortPool_test, AddPublisherPortOverflow) { - iox::mepoo::MemoryManager memoryManager; - iox::popo::PublisherOptions publisherOptions; - auto errorHandlerCalled{false}; iox::Error errorHandlerType; auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( @@ -183,12 +186,46 @@ TEST_F(PortPool_test, AddPublisherPortOverflow) EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW); } -TEST_F(PortPool_test, AddSubscriberPortSuccessfully) +TEST_F(PortPool_test, GetPublisherPortDataListSuccessfully) { - iox::capro::ServiceDescription serviceDescription("service1", "instance1"); - iox::ProcessName_t applicationName("AppNmae"); - iox::popo::SubscriberOptions subscriberOptions; + sut.addPublisherPort(serviceDescription, &memoryManager, applicationName, publisherOptions); + auto publisherPortDataList = sut.getPublisherPortDataList(); + + ASSERT_THAT(publisherPortDataList.size(), Eq(1U)); +} + +TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) +{ + for (uint32_t i = 0; i < iox::MAX_PUBLISHERS; ++i) + { + std::string service = "service" + std::to_string(i); + std::string instance = "instance" + std::to_string(i); + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + + + auto publisherPort = sut.addPublisherPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), + iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, + &memoryManager, + applicationName, + publisherOptions); + } + + auto publisherPortDataList = sut.getPublisherPortDataList(); + + ASSERT_THAT(publisherPortDataList.size(), Eq(iox::MAX_PUBLISHERS)); +} + +TEST_F(PortPool_test, RemovePublisherPortSuccessfully) +{ + auto publisherPort = sut.addPublisherPort(serviceDescription, &memoryManager, applicationName, publisherOptions); + sut.removePublisherPort(publisherPort.value()); + auto publisherPortDataList = sut.getPublisherPortDataList(); + + ASSERT_THAT(publisherPortDataList.size(), Eq(0U)); +} +TEST_F(PortPool_test, AddSubscriberPortSuccessfully) +{ auto subscriberPort = sut.addSubscriberPort(serviceDescription, applicationName, subscriberOptions); EXPECT_THAT(subscriberPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); @@ -200,10 +237,8 @@ TEST_F(PortPool_test, AddSubscriberPortSuccessfully) EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } -TEST_F(PortPool_test, AddMaximumSubscriberPortSuccessfully) +TEST_F(PortPool_test, AddMaxSubscriberPortSuccessfully) { - iox::popo::SubscriberOptions subscriberOptions; - for (uint32_t i = 0; i < iox::MAX_SUBSCRIBERS; ++i) { std::string service = "service" + std::to_string(i); @@ -229,8 +264,6 @@ TEST_F(PortPool_test, AddMaximumSubscriberPortSuccessfully) TEST_F(PortPool_test, AddSubscriberPortOverflow) { - iox::popo::SubscriberOptions subscriberOptions; - auto errorHandlerCalled{false}; iox::Error errorHandlerType; auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( @@ -256,4 +289,41 @@ TEST_F(PortPool_test, AddSubscriberPortOverflow) EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); } +TEST_F(PortPool_test, GetSubscriberPortDataListSuccessfully) +{ + auto subscriberPort = sut.addSubscriberPort(serviceDescription, applicationName, subscriberOptions); + auto subscriberPortDataList = sut.getSubscriberPortDataList(); + + ASSERT_THAT(subscriberPortDataList.size(), Eq(1U)); +} + +TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledSuccessfully) +{ + for (uint32_t i = 0; i < iox::MAX_SUBSCRIBERS; ++i) + { + std::string service = "service" + std::to_string(i); + std::string instance = "instance" + std::to_string(i); + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + + + auto publisherPort = sut.addSubscriberPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), + iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, + applicationName, + subscriberOptions); + } + auto subscriberPortDataList = sut.getSubscriberPortDataList(); + + ASSERT_THAT(subscriberPortDataList.size(), Eq(iox::MAX_SUBSCRIBERS)); +} + +TEST_F(PortPool_test, RemoveSubscriberPortSuccessfully) +{ + auto subscriberPort = sut.addSubscriberPort(serviceDescription, applicationName, subscriberOptions); + + sut.removeSubscriberPort(subscriberPort.value()); + auto subscriberPortDataList = sut.getSubscriberPortDataList(); + + ASSERT_THAT(subscriberPortDataList.size(), Eq(0U)); +} + } // namespace test From db391c0ad5d4b9586a644267dce3b388e2e4d53a Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Mon, 15 Feb 2021 14:08:14 +0530 Subject: [PATCH 06/89] iox-#496 cleanup Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_roudi_portpool.cpp | 151 +++++++++++------- 1 file changed, 93 insertions(+), 58 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 05063bd6cd..cc1fc2d5a8 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -11,6 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/roudi/port_pool_data.hpp" #include "iceoryx_posh/internal/runtime/node_data.hpp" @@ -29,33 +31,36 @@ static constexpr uint32_t DEFAULT_MEMORY_TYPE{0u}; class PortPool_test : public Test { public: - iox::roudi::PortPoolData portPoolData; - iox::roudi::PortPool sut{portPoolData}; - - iox::capro::ServiceDescription serviceDescription{"service1", "instance1"}; - iox::ProcessName_t applicationName{"AppNmae"}; - iox::mepoo::MemoryManager memoryManager; - iox::popo::PublisherOptions publisherOptions; - iox::popo::SubscriberOptions subscriberOptions; + iox::roudi::PortPoolData m_portPoolData; + iox::roudi::PortPool sut{m_portPoolData}; + + iox::capro::ServiceDescription m_serviceDescription{"service1", "instance1"}; + iox::ProcessName_t m_applicationName{"AppName"}; + iox::ProcessName_t m_processName{"processName"}; + iox::ProcessName_t m_nodeName{"nodeName"}; + const uint64_t m_nodeDeviceId = 999U; + iox::mepoo::MemoryManager m_memoryManager; + iox::popo::PublisherOptions m_publisherOptions; + iox::popo::SubscriberOptions m_subscriberOptions; }; -TEST_F(PortPool_test, AddNodeDataSuccessfully) +TEST_F(PortPool_test, AddNodeDataIsSuccessful) { - auto nodeData = sut.addNodeData("processName", "nodeName", 999U); + auto nodeData = sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); - ASSERT_THAT(nodeData.value()->m_process, Eq(iox::ProcessName_t("processName"))); - ASSERT_THAT(nodeData.value()->m_node, Eq(iox::ProcessName_t("nodeName"))); - ASSERT_THAT(nodeData.value()->m_nodeDeviceIdentifier, Eq(999U)); + ASSERT_THAT(nodeData.value()->m_process, Eq(m_processName)); + ASSERT_THAT(nodeData.value()->m_node, Eq(m_nodeName)); + ASSERT_THAT(nodeData.value()->m_nodeDeviceIdentifier, Eq(m_nodeDeviceId)); } -TEST_F(PortPool_test, AddMaxNodeDataSuccessfully) +TEST_F(PortPool_test, AddNodeDataToMaxCapacityIsSuccessful) { iox::cxx::vector nodeContainer; for (uint32_t i = 1U; i <= iox::MAX_NODE_NUMBER; ++i) { - auto nodeData = sut.addNodeData("processName", "nodeName", i); + auto nodeData = sut.addNodeData(m_processName, m_nodeName, i); if (!nodeData.has_error()) { nodeContainer.push_back(nodeData.value()); @@ -66,7 +71,7 @@ TEST_F(PortPool_test, AddMaxNodeDataSuccessfully) } -TEST_F(PortPool_test, AddNodeDataFailsWhenNodeListIsFull) +TEST_F(PortPool_test, AddNodeDataWhenNodeListIsFullReturnsError) { auto errorHandlerCalled{false}; iox::Error errorHandlerType; @@ -78,29 +83,35 @@ TEST_F(PortPool_test, AddNodeDataFailsWhenNodeListIsFull) for (uint32_t i = 0U; i <= iox::MAX_NODE_NUMBER; ++i) { - sut.addNodeData("processName", "nodeName", i); + sut.addNodeData(m_processName, m_nodeName, i); } ASSERT_THAT(errorHandlerCalled, Eq(true)); EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__NODELIST_OVERFLOW); } +TEST_F(PortPool_test, GetNodeDataListWhenEmptyIsSuccessful) +{ + auto nodeDataList = sut.getNodeDataList(); + + ASSERT_THAT(nodeDataList.size(), Eq(0U)); +} -TEST_F(PortPool_test, GetNodeDataListSuccessfully) +TEST_F(PortPool_test, GetNodeDataListIsSuccessful) { - sut.addNodeData("processName", "nodeName", 999U); + sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); auto nodeDataList = sut.getNodeDataList(); ASSERT_THAT(nodeDataList.size(), Eq(1U)); } -TEST_F(PortPool_test, GetMaxNodeDataListSuccessfully) +TEST_F(PortPool_test, GetNodeDataListWithMaxCapacityIsSuccessful) { iox::cxx::vector nodeContainer; for (uint32_t i = 1U; i <= iox::MAX_NODE_NUMBER; ++i) { - auto nodeData = sut.addNodeData("processName", "nodeName", i); + auto nodeData = sut.addNodeData(m_processName, m_nodeName, i); if (!nodeData.has_error()) { nodeContainer.push_back(nodeData.value()); @@ -111,41 +122,42 @@ TEST_F(PortPool_test, GetMaxNodeDataListSuccessfully) ASSERT_THAT(nodeDataList.size(), Eq(iox::MAX_NODE_NUMBER)); } -TEST_F(PortPool_test, RemoveNodeDataSuccessfully) +TEST_F(PortPool_test, RemoveNodeDataIsSuccessful) { - auto nodeData = sut.addNodeData("processName", "nodeName", 999U); + auto nodeData = sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); sut.removeNodeData(nodeData.value()); auto nodeDataList = sut.getNodeDataList(); ASSERT_THAT(nodeDataList.size(), Eq(0U)); } -TEST_F(PortPool_test, AddPublisherPortSuccessfully) +TEST_F(PortPool_test, AddPublisherPortIsSuccessful) { - auto publisherPort = sut.addPublisherPort(serviceDescription, &memoryManager, applicationName, publisherOptions); + auto publisherPort = + sut.addPublisherPort(m_serviceDescription, &m_memoryManager, m_applicationName, m_publisherOptions); EXPECT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); - EXPECT_EQ(publisherPort.value()->m_processName, iox::ProcessName_t{"AppNmae"}); + EXPECT_EQ(publisherPort.value()->m_processName, m_applicationName); EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); EXPECT_EQ(publisherPort.value()->m_nodeName, iox::NodeName_t{""}); EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } -TEST_F(PortPool_test, AddMaxPublisherPortSuccessfully) +TEST_F(PortPool_test, AddMaxPublisherPortWithMaxCapacityIsSuccessful) { for (uint32_t i = 0; i < iox::MAX_PUBLISHERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; auto publisherPort = sut.addPublisherPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, - &memoryManager, + &m_memoryManager, applicationName, - publisherOptions); + m_publisherOptions); EXPECT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), @@ -158,7 +170,7 @@ TEST_F(PortPool_test, AddMaxPublisherPortSuccessfully) } } -TEST_F(PortPool_test, AddPublisherPortOverflow) +TEST_F(PortPool_test, AddPublisherPortWhenOverflowsReurnsError) { auto errorHandlerCalled{false}; iox::Error errorHandlerType; @@ -172,42 +184,53 @@ TEST_F(PortPool_test, AddPublisherPortOverflow) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; auto publisherPort = sut.addPublisherPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, - &memoryManager, + &m_memoryManager, applicationName, - publisherOptions); + m_publisherOptions); } ASSERT_THAT(errorHandlerCalled, Eq(true)); EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW); } -TEST_F(PortPool_test, GetPublisherPortDataListSuccessfully) +TEST_F(PortPool_test, GetPublisherPortDataListIsSuccessful) { - sut.addPublisherPort(serviceDescription, &memoryManager, applicationName, publisherOptions); auto publisherPortDataList = sut.getPublisherPortDataList(); + EXPECT_THAT(publisherPortDataList.size(), Eq(0U)); + + sut.addPublisherPort(m_serviceDescription, &m_memoryManager, m_applicationName, m_publisherOptions); + publisherPortDataList = sut.getPublisherPortDataList(); + ASSERT_THAT(publisherPortDataList.size(), Eq(1U)); } +TEST_F(PortPool_test, GetPublisherPortDataListWhenEmptyIsSuccessful) +{ + auto nodeDataList = sut.getPublisherPortDataList(); + + ASSERT_THAT(nodeDataList.size(), Eq(0U)); +} + TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) { for (uint32_t i = 0; i < iox::MAX_PUBLISHERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; auto publisherPort = sut.addPublisherPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, - &memoryManager, + &m_memoryManager, applicationName, - publisherOptions); + m_publisherOptions); } auto publisherPortDataList = sut.getPublisherPortDataList(); @@ -215,21 +238,22 @@ TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) ASSERT_THAT(publisherPortDataList.size(), Eq(iox::MAX_PUBLISHERS)); } -TEST_F(PortPool_test, RemovePublisherPortSuccessfully) +TEST_F(PortPool_test, RemovePublisherPortIsSuccessful) { - auto publisherPort = sut.addPublisherPort(serviceDescription, &memoryManager, applicationName, publisherOptions); + auto publisherPort = + sut.addPublisherPort(m_serviceDescription, &m_memoryManager, m_applicationName, m_publisherOptions); sut.removePublisherPort(publisherPort.value()); auto publisherPortDataList = sut.getPublisherPortDataList(); ASSERT_THAT(publisherPortDataList.size(), Eq(0U)); } -TEST_F(PortPool_test, AddSubscriberPortSuccessfully) +TEST_F(PortPool_test, AddSubscriberPortIsSuccessful) { - auto subscriberPort = sut.addSubscriberPort(serviceDescription, applicationName, subscriberOptions); + auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); - EXPECT_THAT(subscriberPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); - EXPECT_EQ(subscriberPort.value()->m_processName, iox::ProcessName_t{"AppNmae"}); + EXPECT_THAT(subscriberPort.value()->m_serviceDescription, Eq(m_serviceDescription)); + EXPECT_EQ(subscriberPort.value()->m_processName, m_applicationName); EXPECT_EQ(subscriberPort.value()->m_nodeName, iox::NodeName_t{""}); EXPECT_EQ(subscriberPort.value()->m_historyRequest, 0U); EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_queue.capacity(), 256U); @@ -237,19 +261,19 @@ TEST_F(PortPool_test, AddSubscriberPortSuccessfully) EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } -TEST_F(PortPool_test, AddMaxSubscriberPortSuccessfully) +TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) { for (uint32_t i = 0; i < iox::MAX_SUBSCRIBERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; auto subscriberPort = sut.addSubscriberPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, applicationName, - subscriberOptions); + m_subscriberOptions); EXPECT_THAT(subscriberPort.value()->m_serviceDescription, Eq(ServiceDescription{iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), @@ -262,7 +286,7 @@ TEST_F(PortPool_test, AddMaxSubscriberPortSuccessfully) } -TEST_F(PortPool_test, AddSubscriberPortOverflow) +TEST_F(PortPool_test, AddSubscriberPortWhenOverflowsReurnsError) { auto errorHandlerCalled{false}; iox::Error errorHandlerType; @@ -276,49 +300,60 @@ TEST_F(PortPool_test, AddSubscriberPortOverflow) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; auto publisherPort = sut.addSubscriberPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, applicationName, - subscriberOptions); + m_subscriberOptions); } ASSERT_THAT(errorHandlerCalled, Eq(true)); EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); } -TEST_F(PortPool_test, GetSubscriberPortDataListSuccessfully) +TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful) { - auto subscriberPort = sut.addSubscriberPort(serviceDescription, applicationName, subscriberOptions); auto subscriberPortDataList = sut.getSubscriberPortDataList(); + EXPECT_THAT(subscriberPortDataList.size(), Eq(0U)); + + auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); + subscriberPortDataList = sut.getSubscriberPortDataList(); + ASSERT_THAT(subscriberPortDataList.size(), Eq(1U)); } -TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledSuccessfully) +TEST_F(PortPool_test, GetSubscriberPortDataListWhenEmptyIsSuccessful) +{ + auto nodeDataList = sut.getSubscriberPortDataList(); + + ASSERT_THAT(nodeDataList.size(), Eq(0U)); +} + +TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful) { for (uint32_t i = 0; i < iox::MAX_SUBSCRIBERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppNmae" + std::to_string(i)}; + iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; auto publisherPort = sut.addSubscriberPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, applicationName, - subscriberOptions); + m_subscriberOptions); } auto subscriberPortDataList = sut.getSubscriberPortDataList(); ASSERT_THAT(subscriberPortDataList.size(), Eq(iox::MAX_SUBSCRIBERS)); } -TEST_F(PortPool_test, RemoveSubscriberPortSuccessfully) +TEST_F(PortPool_test, RemoveSubscriberPortIsSuccessful) { - auto subscriberPort = sut.addSubscriberPort(serviceDescription, applicationName, subscriberOptions); + auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); sut.removeSubscriberPort(subscriberPort.value()); auto subscriberPortDataList = sut.getSubscriberPortDataList(); From dcd538f4355d25d1272ca4e56e4cbfe4a6926c52 Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Tue, 16 Feb 2021 12:19:24 +0530 Subject: [PATCH 07/89] iox-#496 added moduletest for interfaceport in portpool Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_roudi_portpool.cpp | 261 ++++++++++++------ 1 file changed, 170 insertions(+), 91 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index cc1fc2d5a8..2ac5ed5e6f 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -24,6 +24,8 @@ using namespace ::testing; using ::testing::Return; using namespace iox::capro; +namespace iox +{ namespace test { static constexpr uint32_t DEFAULT_DEVICE_ID{0u}; @@ -31,17 +33,17 @@ static constexpr uint32_t DEFAULT_MEMORY_TYPE{0u}; class PortPool_test : public Test { public: - iox::roudi::PortPoolData m_portPoolData; - iox::roudi::PortPool sut{m_portPoolData}; + roudi::PortPoolData m_portPoolData; + roudi::PortPool sut{m_portPoolData}; - iox::capro::ServiceDescription m_serviceDescription{"service1", "instance1"}; - iox::ProcessName_t m_applicationName{"AppName"}; - iox::ProcessName_t m_processName{"processName"}; - iox::ProcessName_t m_nodeName{"nodeName"}; + ServiceDescription m_serviceDescription{"service1", "instance1"}; + ProcessName_t m_applicationName{"AppName"}; + ProcessName_t m_processName{"processName"}; + ProcessName_t m_nodeName{"nodeName"}; const uint64_t m_nodeDeviceId = 999U; - iox::mepoo::MemoryManager m_memoryManager; - iox::popo::PublisherOptions m_publisherOptions; - iox::popo::SubscriberOptions m_subscriberOptions; + mepoo::MemoryManager m_memoryManager; + popo::PublisherOptions m_publisherOptions; + popo::SubscriberOptions m_subscriberOptions; }; TEST_F(PortPool_test, AddNodeDataIsSuccessful) @@ -53,12 +55,11 @@ TEST_F(PortPool_test, AddNodeDataIsSuccessful) ASSERT_THAT(nodeData.value()->m_nodeDeviceIdentifier, Eq(m_nodeDeviceId)); } - -TEST_F(PortPool_test, AddNodeDataToMaxCapacityIsSuccessful) +TEST_F(PortPool_test, AddNodeDataWithMaxCapacityIsSuccessful) { - iox::cxx::vector nodeContainer; + cxx::vector nodeContainer; - for (uint32_t i = 1U; i <= iox::MAX_NODE_NUMBER; ++i) + for (uint32_t i = 1U; i <= MAX_NODE_NUMBER; ++i) { auto nodeData = sut.addNodeData(m_processName, m_nodeName, i); if (!nodeData.has_error()) @@ -67,27 +68,27 @@ TEST_F(PortPool_test, AddNodeDataToMaxCapacityIsSuccessful) } } - ASSERT_THAT(nodeContainer.size(), Eq(iox::MAX_NODE_NUMBER)); + ASSERT_THAT(nodeContainer.size(), Eq(MAX_NODE_NUMBER)); } TEST_F(PortPool_test, AddNodeDataWhenNodeListIsFullReturnsError) { auto errorHandlerCalled{false}; - iox::Error errorHandlerType; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( - [&](const iox::Error error, const std::function, const iox::ErrorLevel) { + Error errorHandlerType; + auto errorHandlerGuard = + ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; }); - for (uint32_t i = 0U; i <= iox::MAX_NODE_NUMBER; ++i) + for (uint32_t i = 0U; i <= MAX_NODE_NUMBER; ++i) { sut.addNodeData(m_processName, m_nodeName, i); } - ASSERT_THAT(errorHandlerCalled, Eq(true)); - EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__NODELIST_OVERFLOW); + ASSERT_EQ(errorHandlerCalled, true); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__NODELIST_OVERFLOW); } TEST_F(PortPool_test, GetNodeDataListWhenEmptyIsSuccessful) @@ -107,9 +108,9 @@ TEST_F(PortPool_test, GetNodeDataListIsSuccessful) TEST_F(PortPool_test, GetNodeDataListWithMaxCapacityIsSuccessful) { - iox::cxx::vector nodeContainer; + cxx::vector nodeContainer; - for (uint32_t i = 1U; i <= iox::MAX_NODE_NUMBER; ++i) + for (uint32_t i = 1U; i <= MAX_NODE_NUMBER; ++i) { auto nodeData = sut.addNodeData(m_processName, m_nodeName, i); if (!nodeData.has_error()) @@ -119,7 +120,7 @@ TEST_F(PortPool_test, GetNodeDataListWithMaxCapacityIsSuccessful) } auto nodeDataList = sut.getNodeDataList(); - ASSERT_THAT(nodeDataList.size(), Eq(iox::MAX_NODE_NUMBER)); + ASSERT_THAT(nodeDataList.size(), Eq(MAX_NODE_NUMBER)); } TEST_F(PortPool_test, RemoveNodeDataIsSuccessful) @@ -139,32 +140,32 @@ TEST_F(PortPool_test, AddPublisherPortIsSuccessful) EXPECT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); EXPECT_EQ(publisherPort.value()->m_processName, m_applicationName); EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); - EXPECT_EQ(publisherPort.value()->m_nodeName, iox::NodeName_t{""}); + EXPECT_EQ(publisherPort.value()->m_nodeName, NodeName_t{""}); EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } TEST_F(PortPool_test, AddMaxPublisherPortWithMaxCapacityIsSuccessful) { - for (uint32_t i = 0; i < iox::MAX_PUBLISHERS; ++i) + for (uint32_t i = 0; i < MAX_PUBLISHERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; + ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - auto publisherPort = sut.addPublisherPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), - iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, - &m_memoryManager, - applicationName, - m_publisherOptions); + auto publisherPort = sut.addPublisherPort( + {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, + &m_memoryManager, + applicationName, + m_publisherOptions); EXPECT_THAT(publisherPort.value()->m_serviceDescription, - Eq(ServiceDescription{iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), - iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)})); + Eq(ServiceDescription{IdString_t(cxx::TruncateToCapacity, service), + IdString_t(cxx::TruncateToCapacity, instance)})); EXPECT_EQ(publisherPort.value()->m_processName, applicationName); EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); - EXPECT_EQ(publisherPort.value()->m_nodeName, iox::NodeName_t{""}); + EXPECT_EQ(publisherPort.value()->m_nodeName, NodeName_t{""}); EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } @@ -173,29 +174,29 @@ TEST_F(PortPool_test, AddMaxPublisherPortWithMaxCapacityIsSuccessful) TEST_F(PortPool_test, AddPublisherPortWhenOverflowsReurnsError) { auto errorHandlerCalled{false}; - iox::Error errorHandlerType; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( - [&](const iox::Error error, const std::function, const iox::ErrorLevel) { + Error errorHandlerType; + auto errorHandlerGuard = + ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; }); - for (uint32_t i = 0; i <= iox::MAX_PUBLISHERS; ++i) + for (uint32_t i = 0; i <= MAX_PUBLISHERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; + ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - auto publisherPort = sut.addPublisherPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), - iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, - &m_memoryManager, - applicationName, - m_publisherOptions); + auto publisherPort = sut.addPublisherPort( + {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, + &m_memoryManager, + applicationName, + m_publisherOptions); } ASSERT_THAT(errorHandlerCalled, Eq(true)); - EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW); } TEST_F(PortPool_test, GetPublisherPortDataListIsSuccessful) @@ -219,23 +220,23 @@ TEST_F(PortPool_test, GetPublisherPortDataListWhenEmptyIsSuccessful) TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) { - for (uint32_t i = 0; i < iox::MAX_PUBLISHERS; ++i) + for (uint32_t i = 0; i < MAX_PUBLISHERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; + ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - auto publisherPort = sut.addPublisherPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), - iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, - &m_memoryManager, - applicationName, - m_publisherOptions); + auto publisherPort = sut.addPublisherPort( + {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, + &m_memoryManager, + applicationName, + m_publisherOptions); } auto publisherPortDataList = sut.getPublisherPortDataList(); - ASSERT_THAT(publisherPortDataList.size(), Eq(iox::MAX_PUBLISHERS)); + ASSERT_THAT(publisherPortDataList.size(), Eq(MAX_PUBLISHERS)); } TEST_F(PortPool_test, RemovePublisherPortIsSuccessful) @@ -254,7 +255,7 @@ TEST_F(PortPool_test, AddSubscriberPortIsSuccessful) EXPECT_THAT(subscriberPort.value()->m_serviceDescription, Eq(m_serviceDescription)); EXPECT_EQ(subscriberPort.value()->m_processName, m_applicationName); - EXPECT_EQ(subscriberPort.value()->m_nodeName, iox::NodeName_t{""}); + EXPECT_EQ(subscriberPort.value()->m_nodeName, NodeName_t{""}); EXPECT_EQ(subscriberPort.value()->m_historyRequest, 0U); EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_queue.capacity(), 256U); EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); @@ -263,23 +264,23 @@ TEST_F(PortPool_test, AddSubscriberPortIsSuccessful) TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) { - for (uint32_t i = 0; i < iox::MAX_SUBSCRIBERS; ++i) + for (uint32_t i = 0; i < MAX_SUBSCRIBERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; + ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - auto subscriberPort = sut.addSubscriberPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), - iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, - applicationName, - m_subscriberOptions); + auto subscriberPort = sut.addSubscriberPort( + {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, + applicationName, + m_subscriberOptions); EXPECT_THAT(subscriberPort.value()->m_serviceDescription, - Eq(ServiceDescription{iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), - iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)})); + Eq(ServiceDescription{IdString_t(cxx::TruncateToCapacity, service), + IdString_t(cxx::TruncateToCapacity, instance)})); EXPECT_EQ(subscriberPort.value()->m_processName, applicationName); - EXPECT_EQ(subscriberPort.value()->m_nodeName, iox::NodeName_t{""}); + EXPECT_EQ(subscriberPort.value()->m_nodeName, NodeName_t{""}); EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } @@ -289,66 +290,63 @@ TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) TEST_F(PortPool_test, AddSubscriberPortWhenOverflowsReurnsError) { auto errorHandlerCalled{false}; - iox::Error errorHandlerType; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( - [&](const iox::Error error, const std::function, const iox::ErrorLevel) { + Error errorHandlerType; + auto errorHandlerGuard = + ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; }); - for (uint32_t i = 0; i <= iox::MAX_SUBSCRIBERS; ++i) + for (uint32_t i = 0; i <= MAX_SUBSCRIBERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; + ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - auto publisherPort = sut.addSubscriberPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), - iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, - applicationName, - m_subscriberOptions); + auto publisherPort = sut.addSubscriberPort( + {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, + applicationName, + m_subscriberOptions); } ASSERT_THAT(errorHandlerCalled, Eq(true)); - EXPECT_EQ(errorHandlerType, iox::Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); } -TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful) +TEST_F(PortPool_test, GetSubscriberPortDataListWhenEmptyIsSuccessful) { - auto subscriberPortDataList = sut.getSubscriberPortDataList(); - - EXPECT_THAT(subscriberPortDataList.size(), Eq(0U)); - - auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); - subscriberPortDataList = sut.getSubscriberPortDataList(); + auto nodeDataList = sut.getSubscriberPortDataList(); - ASSERT_THAT(subscriberPortDataList.size(), Eq(1U)); + ASSERT_THAT(nodeDataList.size(), Eq(0U)); } -TEST_F(PortPool_test, GetSubscriberPortDataListWhenEmptyIsSuccessful) + +TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful) { - auto nodeDataList = sut.getSubscriberPortDataList(); + auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); + auto subscriberPortDataList = sut.getSubscriberPortDataList(); - ASSERT_THAT(nodeDataList.size(), Eq(0U)); + ASSERT_THAT(subscriberPortDataList.size(), Eq(1U)); } TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful) { - for (uint32_t i = 0; i < iox::MAX_SUBSCRIBERS; ++i) + for (uint32_t i = 0; i < MAX_SUBSCRIBERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); - iox::ProcessName_t applicationName = {iox::cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; + ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - auto publisherPort = sut.addSubscriberPort({iox::capro::IdString_t(iox::cxx::TruncateToCapacity, service), - iox::capro::IdString_t(iox::cxx::TruncateToCapacity, instance)}, - applicationName, - m_subscriberOptions); + auto publisherPort = sut.addSubscriberPort( + {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, + applicationName, + m_subscriberOptions); } auto subscriberPortDataList = sut.getSubscriberPortDataList(); - ASSERT_THAT(subscriberPortDataList.size(), Eq(iox::MAX_SUBSCRIBERS)); + ASSERT_THAT(subscriberPortDataList.size(), Eq(MAX_SUBSCRIBERS)); } TEST_F(PortPool_test, RemoveSubscriberPortIsSuccessful) @@ -361,4 +359,85 @@ TEST_F(PortPool_test, RemoveSubscriberPortIsSuccessful) ASSERT_THAT(subscriberPortDataList.size(), Eq(0U)); } +TEST_F(PortPool_test, AddInterfacePortIsSuccessful) +{ + auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); + EXPECT_THAT(interfacePortData.value()->m_processName, Eq(m_applicationName)); + EXPECT_THAT(interfacePortData.value()->m_serviceDescription.getSourceInterface(), Eq(Interfaces::INTERNAL)); +} + +TEST_F(PortPool_test, AddInterfacePortWithMaxCapacityIsSuccessful) +{ + cxx::vector interfacePortContainer; + + for (uint32_t i = 1U; i <= MAX_INTERFACE_NUMBER; ++i) + { + auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); + if (!interfacePortData.has_error()) + { + interfacePortContainer.push_back(interfacePortData.value()); + } + } + + ASSERT_THAT(interfacePortContainer.size(), Eq(MAX_INTERFACE_NUMBER)); +} + +TEST_F(PortPool_test, AddInterfacePortWhenContainerIsFullReturnsError) +{ + auto errorHandlerCalled{false}; + Error errorHandlerType; + auto errorHandlerGuard = + ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + errorHandlerType = error; + errorHandlerCalled = true; + }); + + for (uint32_t i = 0U; i <= MAX_INTERFACE_NUMBER; ++i) + { + auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); + } + + ASSERT_EQ(errorHandlerCalled, true); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__INTERFACELIST_OVERFLOW); +} + +TEST_F(PortPool_test, GetInterfacePortDataListWhenEmptyIsSuccessful) +{ + auto interfacePortDataList = sut.getInterfacePortDataList(); + + EXPECT_THAT(interfacePortDataList.size(), Eq(0U)); +} + +TEST_F(PortPool_test, GetInterfacePortDataListIsSuccessful) +{ + auto interfacePort = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); + auto interfacePortDataList = sut.getInterfacePortDataList(); + + ASSERT_THAT(interfacePortDataList.size(), Eq(1U)); +} + +TEST_F(PortPool_test, GetInterfacePortDataListCompletelyFilledIsSuccessful) +{ + for (uint32_t i = 0; i < MAX_INTERFACE_NUMBER; ++i) + { + ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; + + auto interfacePort = sut.addInterfacePort(applicationName, Interfaces::INTERNAL); + } + auto interfacePortDataList = sut.getInterfacePortDataList(); + + ASSERT_THAT(interfacePortDataList.size(), Eq(MAX_INTERFACE_NUMBER)); +} + +TEST_F(PortPool_test, RemoveInterfacePortIsSuccessful) +{ + auto interfacePort = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); + + sut.removeInterfacePort(interfacePort.value()); + auto interfacePortDataList = sut.getInterfacePortDataList(); + + ASSERT_THAT(interfacePortDataList.size(), Eq(0U)); +} + } // namespace test +} // namespace iox \ No newline at end of file From 6aac8373e2fb6e6f9a9427d37faf8f167b21be51 Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Wed, 17 Feb 2021 15:20:29 +0530 Subject: [PATCH 08/89] iox-#496 added moduletest for application_port and conditinal_variable_data in port_pool Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_roudi_portpool.cpp | 295 ++++++++++++++---- 1 file changed, 229 insertions(+), 66 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 2ac5ed5e6f..f7d3facf8b 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -50,9 +50,9 @@ TEST_F(PortPool_test, AddNodeDataIsSuccessful) { auto nodeData = sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); - ASSERT_THAT(nodeData.value()->m_process, Eq(m_processName)); - ASSERT_THAT(nodeData.value()->m_node, Eq(m_nodeName)); - ASSERT_THAT(nodeData.value()->m_nodeDeviceIdentifier, Eq(m_nodeDeviceId)); + ASSERT_EQ(nodeData.value()->m_process, m_processName); + ASSERT_EQ(nodeData.value()->m_node, m_nodeName); + ASSERT_EQ(nodeData.value()->m_nodeDeviceIdentifier, m_nodeDeviceId); } TEST_F(PortPool_test, AddNodeDataWithMaxCapacityIsSuccessful) @@ -68,7 +68,7 @@ TEST_F(PortPool_test, AddNodeDataWithMaxCapacityIsSuccessful) } } - ASSERT_THAT(nodeContainer.size(), Eq(MAX_NODE_NUMBER)); + ASSERT_EQ(nodeContainer.size(), MAX_NODE_NUMBER); } @@ -87,15 +87,15 @@ TEST_F(PortPool_test, AddNodeDataWhenNodeListIsFullReturnsError) sut.addNodeData(m_processName, m_nodeName, i); } - ASSERT_EQ(errorHandlerCalled, true); - EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__NODELIST_OVERFLOW); + ASSERT_TRUE(errorHandlerCalled); + ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__NODELIST_OVERFLOW); } TEST_F(PortPool_test, GetNodeDataListWhenEmptyIsSuccessful) { auto nodeDataList = sut.getNodeDataList(); - ASSERT_THAT(nodeDataList.size(), Eq(0U)); + ASSERT_EQ(nodeDataList.size(), 0U); } TEST_F(PortPool_test, GetNodeDataListIsSuccessful) @@ -103,7 +103,7 @@ TEST_F(PortPool_test, GetNodeDataListIsSuccessful) sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); auto nodeDataList = sut.getNodeDataList(); - ASSERT_THAT(nodeDataList.size(), Eq(1U)); + ASSERT_EQ(nodeDataList.size(), 1U); } TEST_F(PortPool_test, GetNodeDataListWithMaxCapacityIsSuccessful) @@ -120,16 +120,18 @@ TEST_F(PortPool_test, GetNodeDataListWithMaxCapacityIsSuccessful) } auto nodeDataList = sut.getNodeDataList(); - ASSERT_THAT(nodeDataList.size(), Eq(MAX_NODE_NUMBER)); + + ASSERT_EQ(nodeDataList.size(), MAX_NODE_NUMBER); } TEST_F(PortPool_test, RemoveNodeDataIsSuccessful) { auto nodeData = sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); + sut.removeNodeData(nodeData.value()); auto nodeDataList = sut.getNodeDataList(); - ASSERT_THAT(nodeDataList.size(), Eq(0U)); + ASSERT_EQ(nodeDataList.size(), 0U); } TEST_F(PortPool_test, AddPublisherPortIsSuccessful) @@ -137,12 +139,12 @@ TEST_F(PortPool_test, AddPublisherPortIsSuccessful) auto publisherPort = sut.addPublisherPort(m_serviceDescription, &m_memoryManager, m_applicationName, m_publisherOptions); - EXPECT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); - EXPECT_EQ(publisherPort.value()->m_processName, m_applicationName); - EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); - EXPECT_EQ(publisherPort.value()->m_nodeName, NodeName_t{""}); - EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); - EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + ASSERT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); + ASSERT_EQ(publisherPort.value()->m_processName, m_applicationName); + ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); + ASSERT_EQ(publisherPort.value()->m_nodeName, NodeName_t{""}); + ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } TEST_F(PortPool_test, AddMaxPublisherPortWithMaxCapacityIsSuccessful) @@ -153,25 +155,24 @@ TEST_F(PortPool_test, AddMaxPublisherPortWithMaxCapacityIsSuccessful) std::string instance = "instance" + std::to_string(i); ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - auto publisherPort = sut.addPublisherPort( {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, &m_memoryManager, applicationName, m_publisherOptions); - EXPECT_THAT(publisherPort.value()->m_serviceDescription, + ASSERT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)})); - EXPECT_EQ(publisherPort.value()->m_processName, applicationName); - EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); - EXPECT_EQ(publisherPort.value()->m_nodeName, NodeName_t{""}); - EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); - EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + ASSERT_EQ(publisherPort.value()->m_processName, applicationName); + ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); + ASSERT_EQ(publisherPort.value()->m_nodeName, NodeName_t{""}); + ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } } -TEST_F(PortPool_test, AddPublisherPortWhenOverflowsReurnsError) +TEST_F(PortPool_test, AddPublisherPortWhenPublisherListOverflowsReurnsError) { auto errorHandlerCalled{false}; Error errorHandlerType; @@ -187,35 +188,34 @@ TEST_F(PortPool_test, AddPublisherPortWhenOverflowsReurnsError) std::string instance = "instance" + std::to_string(i); ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - - auto publisherPort = sut.addPublisherPort( + sut.addPublisherPort( {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, &m_memoryManager, applicationName, m_publisherOptions); } - ASSERT_THAT(errorHandlerCalled, Eq(true)); - EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW); + ASSERT_TRUE(errorHandlerCalled); + ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW); } TEST_F(PortPool_test, GetPublisherPortDataListIsSuccessful) { auto publisherPortDataList = sut.getPublisherPortDataList(); - EXPECT_THAT(publisherPortDataList.size(), Eq(0U)); + ASSERT_EQ(publisherPortDataList.size(), 0U); sut.addPublisherPort(m_serviceDescription, &m_memoryManager, m_applicationName, m_publisherOptions); publisherPortDataList = sut.getPublisherPortDataList(); - ASSERT_THAT(publisherPortDataList.size(), Eq(1U)); + ASSERT_EQ(publisherPortDataList.size(), 1U); } TEST_F(PortPool_test, GetPublisherPortDataListWhenEmptyIsSuccessful) { auto nodeDataList = sut.getPublisherPortDataList(); - ASSERT_THAT(nodeDataList.size(), Eq(0U)); + ASSERT_EQ(nodeDataList.size(), 0U); } TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) @@ -226,8 +226,7 @@ TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) std::string instance = "instance" + std::to_string(i); ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - - auto publisherPort = sut.addPublisherPort( + sut.addPublisherPort( {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, &m_memoryManager, applicationName, @@ -236,7 +235,7 @@ TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) auto publisherPortDataList = sut.getPublisherPortDataList(); - ASSERT_THAT(publisherPortDataList.size(), Eq(MAX_PUBLISHERS)); + ASSERT_EQ(publisherPortDataList.size(), MAX_PUBLISHERS); } TEST_F(PortPool_test, RemovePublisherPortIsSuccessful) @@ -246,20 +245,20 @@ TEST_F(PortPool_test, RemovePublisherPortIsSuccessful) sut.removePublisherPort(publisherPort.value()); auto publisherPortDataList = sut.getPublisherPortDataList(); - ASSERT_THAT(publisherPortDataList.size(), Eq(0U)); + ASSERT_EQ(publisherPortDataList.size(), 0U); } TEST_F(PortPool_test, AddSubscriberPortIsSuccessful) { auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); - EXPECT_THAT(subscriberPort.value()->m_serviceDescription, Eq(m_serviceDescription)); - EXPECT_EQ(subscriberPort.value()->m_processName, m_applicationName); - EXPECT_EQ(subscriberPort.value()->m_nodeName, NodeName_t{""}); - EXPECT_EQ(subscriberPort.value()->m_historyRequest, 0U); - EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_queue.capacity(), 256U); - EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); - EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + ASSERT_EQ(subscriberPort.value()->m_serviceDescription, m_serviceDescription); + ASSERT_EQ(subscriberPort.value()->m_processName, m_applicationName); + ASSERT_EQ(subscriberPort.value()->m_nodeName, NodeName_t{""}); + ASSERT_EQ(subscriberPort.value()->m_historyRequest, 0U); + ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_queue.capacity(), 256U); + ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) @@ -276,18 +275,18 @@ TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) applicationName, m_subscriberOptions); - EXPECT_THAT(subscriberPort.value()->m_serviceDescription, + ASSERT_THAT(subscriberPort.value()->m_serviceDescription, Eq(ServiceDescription{IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)})); - EXPECT_EQ(subscriberPort.value()->m_processName, applicationName); - EXPECT_EQ(subscriberPort.value()->m_nodeName, NodeName_t{""}); - EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); - EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + ASSERT_EQ(subscriberPort.value()->m_processName, applicationName); + ASSERT_EQ(subscriberPort.value()->m_nodeName, NodeName_t{""}); + ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } } -TEST_F(PortPool_test, AddSubscriberPortWhenOverflowsReurnsError) +TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReurnsError) { auto errorHandlerCalled{false}; Error errorHandlerType; @@ -310,15 +309,15 @@ TEST_F(PortPool_test, AddSubscriberPortWhenOverflowsReurnsError) m_subscriberOptions); } - ASSERT_THAT(errorHandlerCalled, Eq(true)); - EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); + ASSERT_TRUE(errorHandlerCalled); + ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); } TEST_F(PortPool_test, GetSubscriberPortDataListWhenEmptyIsSuccessful) { auto nodeDataList = sut.getSubscriberPortDataList(); - ASSERT_THAT(nodeDataList.size(), Eq(0U)); + ASSERT_EQ(nodeDataList.size(), 0U); } @@ -327,7 +326,7 @@ TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful) auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); auto subscriberPortDataList = sut.getSubscriberPortDataList(); - ASSERT_THAT(subscriberPortDataList.size(), Eq(1U)); + ASSERT_EQ(subscriberPortDataList.size(), 1U); } TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful) @@ -346,7 +345,7 @@ TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful) } auto subscriberPortDataList = sut.getSubscriberPortDataList(); - ASSERT_THAT(subscriberPortDataList.size(), Eq(MAX_SUBSCRIBERS)); + ASSERT_EQ(subscriberPortDataList.size(), MAX_SUBSCRIBERS); } TEST_F(PortPool_test, RemoveSubscriberPortIsSuccessful) @@ -356,14 +355,15 @@ TEST_F(PortPool_test, RemoveSubscriberPortIsSuccessful) sut.removeSubscriberPort(subscriberPort.value()); auto subscriberPortDataList = sut.getSubscriberPortDataList(); - ASSERT_THAT(subscriberPortDataList.size(), Eq(0U)); + ASSERT_EQ(subscriberPortDataList.size(), 0U); } TEST_F(PortPool_test, AddInterfacePortIsSuccessful) { auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); - EXPECT_THAT(interfacePortData.value()->m_processName, Eq(m_applicationName)); - EXPECT_THAT(interfacePortData.value()->m_serviceDescription.getSourceInterface(), Eq(Interfaces::INTERNAL)); + + ASSERT_EQ(interfacePortData.value()->m_processName, m_applicationName); + ASSERT_EQ(interfacePortData.value()->m_serviceDescription.getSourceInterface(), Interfaces::INTERNAL); } TEST_F(PortPool_test, AddInterfacePortWithMaxCapacityIsSuccessful) @@ -379,10 +379,10 @@ TEST_F(PortPool_test, AddInterfacePortWithMaxCapacityIsSuccessful) } } - ASSERT_THAT(interfacePortContainer.size(), Eq(MAX_INTERFACE_NUMBER)); + ASSERT_EQ(interfacePortContainer.size(), MAX_INTERFACE_NUMBER); } -TEST_F(PortPool_test, AddInterfacePortWhenContainerIsFullReturnsError) +TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError) { auto errorHandlerCalled{false}; Error errorHandlerType; @@ -397,15 +397,15 @@ TEST_F(PortPool_test, AddInterfacePortWhenContainerIsFullReturnsError) auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); } - ASSERT_EQ(errorHandlerCalled, true); - EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__INTERFACELIST_OVERFLOW); + ASSERT_TRUE(errorHandlerCalled); + ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__INTERFACELIST_OVERFLOW); } TEST_F(PortPool_test, GetInterfacePortDataListWhenEmptyIsSuccessful) { auto interfacePortDataList = sut.getInterfacePortDataList(); - EXPECT_THAT(interfacePortDataList.size(), Eq(0U)); + ASSERT_EQ(interfacePortDataList.size(), 0U); } TEST_F(PortPool_test, GetInterfacePortDataListIsSuccessful) @@ -413,7 +413,7 @@ TEST_F(PortPool_test, GetInterfacePortDataListIsSuccessful) auto interfacePort = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); auto interfacePortDataList = sut.getInterfacePortDataList(); - ASSERT_THAT(interfacePortDataList.size(), Eq(1U)); + ASSERT_EQ(interfacePortDataList.size(), 1U); } TEST_F(PortPool_test, GetInterfacePortDataListCompletelyFilledIsSuccessful) @@ -421,12 +421,11 @@ TEST_F(PortPool_test, GetInterfacePortDataListCompletelyFilledIsSuccessful) for (uint32_t i = 0; i < MAX_INTERFACE_NUMBER; ++i) { ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - - auto interfacePort = sut.addInterfacePort(applicationName, Interfaces::INTERNAL); + sut.addInterfacePort(applicationName, Interfaces::INTERNAL); } auto interfacePortDataList = sut.getInterfacePortDataList(); - ASSERT_THAT(interfacePortDataList.size(), Eq(MAX_INTERFACE_NUMBER)); + ASSERT_EQ(interfacePortDataList.size(), MAX_INTERFACE_NUMBER); } TEST_F(PortPool_test, RemoveInterfacePortIsSuccessful) @@ -436,8 +435,172 @@ TEST_F(PortPool_test, RemoveInterfacePortIsSuccessful) sut.removeInterfacePort(interfacePort.value()); auto interfacePortDataList = sut.getInterfacePortDataList(); - ASSERT_THAT(interfacePortDataList.size(), Eq(0U)); + ASSERT_EQ(interfacePortDataList.size(), 0U); +} + +TEST_F(PortPool_test, AddApplicationPortIsSuccessful) +{ + auto applicationPortData = sut.addApplicationPort(m_applicationName); + + ASSERT_EQ(applicationPortData.value()->m_processName, m_applicationName); +} + +TEST_F(PortPool_test, AddApplicationPortWithMaxCapacityIsSuccessful) +{ + cxx::vector applicationContainer; + + for (uint32_t i = 1U; i <= MAX_PROCESS_NUMBER; ++i) + { + auto applicationPortData = sut.addApplicationPort(m_applicationName); + if (!applicationPortData.has_error()) + { + applicationContainer.push_back(applicationPortData.value()); + } + } + + ASSERT_EQ(applicationContainer.size(), MAX_PROCESS_NUMBER); +} + +TEST_F(PortPool_test, AddApplicationPortWhenApplicationListOverflowsReturnsError) +{ + auto errorHandlerCalled{false}; + Error errorHandlerType; + auto errorHandlerGuard = + ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + errorHandlerType = error; + errorHandlerCalled = true; + }); + + for (uint32_t i = 0U; i <= MAX_PROCESS_NUMBER; ++i) + { + auto pplicationData = sut.addApplicationPort(m_applicationName); + } + + ASSERT_TRUE(errorHandlerCalled); + ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__APPLICATIONLIST_OVERFLOW); +} + +TEST_F(PortPool_test, GetApplicationPortDataListWhenEmptyIsSuccessful) +{ + auto applicationPortDataList = sut.getApplicationPortDataList(); + + ASSERT_EQ(applicationPortDataList.size(), 0U); +} + +TEST_F(PortPool_test, GetApplicationPortDataListIsSuccessful) +{ + sut.addApplicationPort(m_applicationName); + auto applicationPortDataList = sut.getApplicationPortDataList(); + + ASSERT_EQ(applicationPortDataList.size(), 1U); +} + +TEST_F(PortPool_test, GetApplicationPortDataListCompletelyFilledIsSuccessful) +{ + for (uint32_t i = 0; i < MAX_PROCESS_NUMBER; ++i) + { + ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; + sut.addApplicationPort(applicationName); + } + auto applicationPortDataList = sut.getApplicationPortDataList(); + + ASSERT_EQ(applicationPortDataList.size(), MAX_PROCESS_NUMBER); +} + +TEST_F(PortPool_test, RemoveApplicationPortIsSuccessful) +{ + auto applicationPortData = sut.addApplicationPort(m_applicationName); + + sut.removeApplicationPort(applicationPortData.value()); + auto applicationPortDataList = sut.getApplicationPortDataList(); + + ASSERT_EQ(applicationPortDataList.size(), 0U); +} + +TEST_F(PortPool_test, AddConditionVariableDataIsSuccessful) +{ + auto conditionVariableData = sut.addConditionVariableData(m_applicationName); + + ASSERT_EQ(conditionVariableData.value()->m_process, m_applicationName); } +TEST_F(PortPool_test, AddConditionVariableDataWithMaxCapacityIsSuccessful) +{ + cxx::vector conditionVariableContainer; + + for (uint32_t i = 1U; i <= MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) + { + auto conditionVariableData = sut.addConditionVariableData(m_applicationName); + if (!conditionVariableData.has_error()) + { + conditionVariableContainer.push_back(conditionVariableData.value()); + } + } + + ASSERT_EQ(conditionVariableContainer.size(), MAX_NUMBER_OF_CONDITION_VARIABLES); +} + +TEST_F(PortPool_test, AddConditionVariableDataWhenContainerIsFullReturnsError) +{ + auto errorHandlerCalled{false}; + Error errorHandlerType; + auto errorHandlerGuard = + ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + errorHandlerType = error; + errorHandlerCalled = true; + }); + + for (uint32_t i = 0U; i <= MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) + { + auto conditionVariableData = sut.addConditionVariableData(m_applicationName); + } + + ASSERT_TRUE(errorHandlerCalled); + ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW); +} + +TEST_F(PortPool_test, GetConditionVariableDataListWhenEmptyIsSuccessful) +{ + auto condtionalVariableData = sut.getConditionVariableDataList(); + + ASSERT_EQ(condtionalVariableData.size(), 0U); +} + +TEST_F(PortPool_test, GetConditionVariableDataListIsSuccessful) +{ + sut.addConditionVariableData(m_applicationName); + auto condtionalVariableData = sut.getConditionVariableDataList(); + + ASSERT_EQ(condtionalVariableData.size(), 1U); +} + +TEST_F(PortPool_test, GetConditionVariableDataListCompletelyFilledIsSuccessful) +{ + for (uint32_t i = 0; i < MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) + { + ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; + sut.addConditionVariableData(applicationName); + } + auto condtionalVariableData = sut.getConditionVariableDataList(); + + ASSERT_EQ(condtionalVariableData.size(), MAX_NUMBER_OF_CONDITION_VARIABLES); +} + +TEST_F(PortPool_test, RemoveConditionVariableDataIsSuccessful) +{ + auto conditionVariableData = sut.addConditionVariableData(m_applicationName); + + sut.removeConditionVariableData(conditionVariableData.value()); + auto condtionalVariableData = sut.getConditionVariableDataList(); + + ASSERT_EQ(condtionalVariableData.size(), 0U); +} + +TEST_F(PortPool_test, GetServiceRegistryChangeCounterIsSuccessful) +{ + auto serviceCounter = sut.serviceRegistryChangeCounter(); + + ASSERT_EQ(serviceCounter->load(), 0U); +} } // namespace test } // namespace iox \ No newline at end of file From 96b984ffaedade59cfac3ac59f8205f88b7fa6c0 Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Wed, 17 Feb 2021 19:43:07 +0530 Subject: [PATCH 09/89] iox-#496 updated file header Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- iceoryx_posh/test/moduletests/test_roudi_portpool.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 85c1919991..b8bb189c10 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -11,6 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/roudi/port_pool_data.hpp" #include "iceoryx_posh/internal/runtime/node_data.hpp" From 65fd92f9ddd62e1db107f17e11e1f05a6115bcb5 Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Mon, 22 Feb 2021 16:28:09 +0530 Subject: [PATCH 10/89] iox-#496 fixed failure after merge from eclipse master Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- iceoryx_posh/test/moduletests/test_roudi_portpool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index f7d3facf8b..97e2f54d86 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -16,7 +16,7 @@ #include "iceoryx_posh/internal/roudi/port_pool_data.hpp" #include "iceoryx_posh/internal/runtime/node_data.hpp" -#include "iceoryx_posh/popo/typed_subscriber.hpp" +#include "iceoryx_posh/popo/subscriber_options.hpp" #include "iceoryx_posh/roudi/port_pool.hpp" #include "test.hpp" From 67351107e1a653d557e376644070ce86ef40ff0e Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Tue, 23 Feb 2021 13:16:17 +0530 Subject: [PATCH 11/89] iox-#496 change to optimize to increase coverage for roudi/roudi_config.cpp Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_posh_runtime_single_process.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp b/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp index 5f5c846e71..1a760f6b2f 100644 --- a/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp +++ b/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp @@ -47,7 +47,7 @@ class PoshRuntimeSingleProcess_test : public Test TEST_F(PoshRuntimeSingleProcess_test, ConstructorPoshRuntimeSingleProcessIsSuccess) { - iox::RouDiConfig_t defaultRouDiConfig = iox::RouDiConfig_t().setDefaults(); + iox::RouDiConfig_t defaultRouDiConfig = iox::RouDiConfig_t().optimize(); IceOryxRouDiComponents roudiComponents(defaultRouDiConfig); RouDi roudi(roudiComponents.m_rouDiMemoryManager, From 066d562102c435622ca77324eee79f08ea24f928 Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Tue, 23 Feb 2021 17:11:11 +0530 Subject: [PATCH 12/89] iox-#496 cleanup Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_roudi_portpool.cpp | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 97e2f54d86..118d9fadef 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -91,19 +91,19 @@ TEST_F(PortPool_test, AddNodeDataWhenNodeListIsFullReturnsError) ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__NODELIST_OVERFLOW); } -TEST_F(PortPool_test, GetNodeDataListWhenEmptyIsSuccessful) +TEST_F(PortPool_test, GetNodeDataListIsSuccessful) { + sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); auto nodeDataList = sut.getNodeDataList(); - ASSERT_EQ(nodeDataList.size(), 0U); + ASSERT_EQ(nodeDataList.size(), 1U); } -TEST_F(PortPool_test, GetNodeDataListIsSuccessful) +TEST_F(PortPool_test, GetNodeDataListWhenEmptyIsSuccessful) { - sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); auto nodeDataList = sut.getNodeDataList(); - ASSERT_EQ(nodeDataList.size(), 1U); + ASSERT_EQ(nodeDataList.size(), 0U); } TEST_F(PortPool_test, GetNodeDataListWithMaxCapacityIsSuccessful) @@ -147,7 +147,7 @@ TEST_F(PortPool_test, AddPublisherPortIsSuccessful) ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } -TEST_F(PortPool_test, AddMaxPublisherPortWithMaxCapacityIsSuccessful) +TEST_F(PortPool_test, AddPublisherPortWithMaxCapacityIsSuccessful) { for (uint32_t i = 0; i < MAX_PUBLISHERS; ++i) { @@ -313,14 +313,6 @@ TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReurnsError) ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); } -TEST_F(PortPool_test, GetSubscriberPortDataListWhenEmptyIsSuccessful) -{ - auto nodeDataList = sut.getSubscriberPortDataList(); - - ASSERT_EQ(nodeDataList.size(), 0U); -} - - TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful) { auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); @@ -329,6 +321,13 @@ TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful) ASSERT_EQ(subscriberPortDataList.size(), 1U); } +TEST_F(PortPool_test, GetSubscriberPortDataListWhenEmptyIsSuccessful) +{ + auto nodeDataList = sut.getSubscriberPortDataList(); + + ASSERT_EQ(nodeDataList.size(), 0U); +} + TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful) { for (uint32_t i = 0; i < MAX_SUBSCRIBERS; ++i) @@ -337,7 +336,6 @@ TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful) std::string instance = "instance" + std::to_string(i); ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - auto publisherPort = sut.addSubscriberPort( {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, applicationName, @@ -401,19 +399,19 @@ TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError) ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__INTERFACELIST_OVERFLOW); } -TEST_F(PortPool_test, GetInterfacePortDataListWhenEmptyIsSuccessful) +TEST_F(PortPool_test, GetInterfacePortDataListIsSuccessful) { + auto interfacePort = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); auto interfacePortDataList = sut.getInterfacePortDataList(); - ASSERT_EQ(interfacePortDataList.size(), 0U); + ASSERT_EQ(interfacePortDataList.size(), 1U); } -TEST_F(PortPool_test, GetInterfacePortDataListIsSuccessful) +TEST_F(PortPool_test, GetInterfacePortDataListWhenEmptyIsSuccessful) { - auto interfacePort = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); auto interfacePortDataList = sut.getInterfacePortDataList(); - ASSERT_EQ(interfacePortDataList.size(), 1U); + ASSERT_EQ(interfacePortDataList.size(), 0U); } TEST_F(PortPool_test, GetInterfacePortDataListCompletelyFilledIsSuccessful) @@ -559,19 +557,19 @@ TEST_F(PortPool_test, AddConditionVariableDataWhenContainerIsFullReturnsError) ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW); } -TEST_F(PortPool_test, GetConditionVariableDataListWhenEmptyIsSuccessful) +TEST_F(PortPool_test, GetConditionVariableDataListIsSuccessful) { + sut.addConditionVariableData(m_applicationName); auto condtionalVariableData = sut.getConditionVariableDataList(); - ASSERT_EQ(condtionalVariableData.size(), 0U); + ASSERT_EQ(condtionalVariableData.size(), 1U); } -TEST_F(PortPool_test, GetConditionVariableDataListIsSuccessful) +TEST_F(PortPool_test, GetConditionVariableDataListWhenEmptyIsSuccessful) { - sut.addConditionVariableData(m_applicationName); auto condtionalVariableData = sut.getConditionVariableDataList(); - ASSERT_EQ(condtionalVariableData.size(), 1U); + ASSERT_EQ(condtionalVariableData.size(), 0U); } TEST_F(PortPool_test, GetConditionVariableDataListCompletelyFilledIsSuccessful) From 70f624449353c17c28cbc67590f7a56625c7625f Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Wed, 3 Feb 2021 08:26:23 +0100 Subject: [PATCH 13/89] iox-#454 create test file for class iceoryx roudi app and roudi app Signed-off-by: Jimmy Belloche --- .../moduletests/test_iceoryx_roudi_app.cpp | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 iceoryx_posh/test/moduletests/test_iceoryx_roudi_app.cpp diff --git a/iceoryx_posh/test/moduletests/test_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_iceoryx_roudi_app.cpp new file mode 100644 index 0000000000..9b048165ec --- /dev/null +++ b/iceoryx_posh/test/moduletests/test_iceoryx_roudi_app.cpp @@ -0,0 +1,106 @@ +// Copyright (c) 2019, 2021 by Robert Bosch GmbH, Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "iceoryx_posh/roudi/iceoryx_roudi_app.hpp" +#include "iceoryx_posh/roudi/roudi_cmd_line_parser_config_file_option.hpp" +#include "iceoryx_posh/roudi/roudi_config_toml_file_provider.hpp" +#include "iceoryx_posh/internal/log/posh_logging.hpp" + +#include +#include + +using namespace ::testing; +using ::testing::Return; + +using iox::roudi::IceOryxRouDiApp; + +namespace iox +{ +namespace test +{ + +class IceoryxRoudiApp_Child : public IceOryxRouDiApp +{ + public: + + IceoryxRoudiApp_Child(const config::CmdLineParser& cmdLineParser, const RouDiConfig_t& roudiConfig):IceOryxRouDiApp(cmdLineParser,roudiConfig) + { + } + + bool getVariableMRun() + { + return m_run; + } + + void setVariableMRun(bool condition) + { + m_run = condition; + } + + uint8_t callRun() noexcept + { + return run(); + } +}; + +/// @brief Test goal: This file tests class roudi app +class IceoryxRoudiApp_test : public Test +{ + public: + + iox::config::CmdLineParserConfigFileOption cmdLineParser; + int argc; + char* argv[]; + + virtual void setUp() + { + cmdLineParser.parse(argc, argv); + } +}; + +TEST_F(IceoryxRoudiApp_test, CheckConstructorIsSuccessfull) +{ + iox::config::TomlRouDiConfigFileProvider configFileProvider(cmdLineParser); + + iox::RouDiConfig_t roudiConfig = + configFileProvider.parse() + .or_else([](iox::roudi::RouDiConfigFileParseError& parseResult) { + iox::LogFatal() << "Couldn't parse config file. Error: " + << iox::cxx::convertEnumToString(iox::roudi::ROUDI_CONFIG_FILE_PARSE_ERROR_STRINGS, + parseResult); + std::terminate(); + }) + .value(); + + //iox::config::TomlRouDiConfigFileProvider configFileProvider(cmdLineParser); + + IceoryxRoudiApp_Child roudi(cmdLineParser, iox::RouDiConfig_t().setDefaults()); + + EXPECT_TRUE(roudi.getVariableMRun()); + +} + +TEST_F(IceoryxRoudiApp_test, CheckRunMethodWithMRunFalseReturnExitSuccess) +{ + IceoryxRoudiApp_Child roudi(cmdLineParser, iox::RouDiConfig_t().setDefaults()); + + roudi.setVariableMRun(false); + + uint8_t result = roudi.callRun(); + + EXPECT_EQ(result, EXIT_SUCCESS); +} + +} // namespace test +} // namespace iox \ No newline at end of file From 753db4dc1a1458ff1a4e83b006d8c19a9f3a506b Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Wed, 3 Feb 2021 10:09:49 +0100 Subject: [PATCH 14/89] iox-#454 rename file iceoryx roudi app test Signed-off-by: Jimmy Belloche --- ...i_app.cpp => test_roudi_iceoryx_roudi_app.cpp} | 15 --------------- 1 file changed, 15 deletions(-) rename iceoryx_posh/test/moduletests/{test_iceoryx_roudi_app.cpp => test_roudi_iceoryx_roudi_app.cpp} (77%) diff --git a/iceoryx_posh/test/moduletests/test_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp similarity index 77% rename from iceoryx_posh/test/moduletests/test_iceoryx_roudi_app.cpp rename to iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index 9b048165ec..0ca85bafc4 100644 --- a/iceoryx_posh/test/moduletests/test_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -71,24 +71,9 @@ class IceoryxRoudiApp_test : public Test TEST_F(IceoryxRoudiApp_test, CheckConstructorIsSuccessfull) { - iox::config::TomlRouDiConfigFileProvider configFileProvider(cmdLineParser); - - iox::RouDiConfig_t roudiConfig = - configFileProvider.parse() - .or_else([](iox::roudi::RouDiConfigFileParseError& parseResult) { - iox::LogFatal() << "Couldn't parse config file. Error: " - << iox::cxx::convertEnumToString(iox::roudi::ROUDI_CONFIG_FILE_PARSE_ERROR_STRINGS, - parseResult); - std::terminate(); - }) - .value(); - - //iox::config::TomlRouDiConfigFileProvider configFileProvider(cmdLineParser); - IceoryxRoudiApp_Child roudi(cmdLineParser, iox::RouDiConfig_t().setDefaults()); EXPECT_TRUE(roudi.getVariableMRun()); - } TEST_F(IceoryxRoudiApp_test, CheckRunMethodWithMRunFalseReturnExitSuccess) From 8e305fd10ae5ba7cf4b2d76b4a25a49f7d36b668 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Tue, 9 Feb 2021 13:54:40 +0100 Subject: [PATCH 15/89] iox-#454 improve test for roudi app Signed-off-by: Jimmy Belloche --- .../test_roudi_iceoryx_roudi_app.cpp | 85 +++++++++++++++++-- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index 0ca85bafc4..350f204276 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -34,7 +34,7 @@ class IceoryxRoudiApp_Child : public IceOryxRouDiApp { public: - IceoryxRoudiApp_Child(const config::CmdLineParser& cmdLineParser, const RouDiConfig_t& roudiConfig):IceOryxRouDiApp(cmdLineParser,roudiConfig) + IceoryxRoudiApp_Child(const config::CmdLineArgs_t& cmdLineArgs, const RouDiConfig_t& roudiConfig):IceOryxRouDiApp(cmdLineArgs,roudiConfig) { } @@ -60,25 +60,53 @@ class IceoryxRoudiApp_test : public Test public: iox::config::CmdLineParserConfigFileOption cmdLineParser; - int argc; - char* argv[]; virtual void setUp() { - cmdLineParser.parse(argc, argv); + } }; TEST_F(IceoryxRoudiApp_test, CheckConstructorIsSuccessfull) { - IceoryxRoudiApp_Child roudi(cmdLineParser, iox::RouDiConfig_t().setDefaults()); + constexpr uint8_t numberOfArgs{1U}; + char* args[numberOfArgs]; + char appName[] = "./foo"; + args[0] = &appName[0]; + + auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + + IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); EXPECT_TRUE(roudi.getVariableMRun()); } +TEST_F(IceoryxRoudiApp_test, CreateTwoRoudiAppIsSuccessfull) +{ + constexpr uint8_t numberOfArgs{1U}; + char* args[numberOfArgs]; + char appName[] = "./foo"; + args[0] = &appName[0]; + + auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + + IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); + + IceoryxRoudiApp_Child roudiTest(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); + + EXPECT_TRUE(roudiTest.getVariableMRun()); +} + TEST_F(IceoryxRoudiApp_test, CheckRunMethodWithMRunFalseReturnExitSuccess) { - IceoryxRoudiApp_Child roudi(cmdLineParser, iox::RouDiConfig_t().setDefaults()); + constexpr uint8_t numberOfArgs{1U}; + char* args[numberOfArgs]; + char appName[] = "./foo"; + args[0] = &appName[0]; + + auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + + IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); roudi.setVariableMRun(false); @@ -87,5 +115,50 @@ TEST_F(IceoryxRoudiApp_test, CheckRunMethodWithMRunFalseReturnExitSuccess) EXPECT_EQ(result, EXIT_SUCCESS); } +TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgVersionSetRunVariableToFalse) +{ + constexpr uint8_t numberOfArgs{2U}; + char* args[numberOfArgs]; + char appName[] = "./foo"; + char option[] = "-v"; + args[0] = &appName[0]; + args[1] = &option[0]; + + auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + + IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); + + EXPECT_FALSE(roudi.getVariableMRun()); +} + +/*TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdSetRunVariableToFalse) +{ + constexpr uint8_t numberOfArgs{3U}; + char* args[numberOfArgs]; + char appName[] = "./foo"; + char option[] = "-u"; + char value[] = "4242"; + args[0] = &appName[0]; + args[1] = &option[0]; + args[2] = &value[0]; + + auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + + iox::cxx::optional detectedError; + auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { + detectedError.emplace(error); + EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); + }); + + IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); + + IceoryxRoudiApp_Child roudiTest(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); + + ASSERT_THAT(detectedError.has_value(), Eq(true)); + EXPECT_THAT(detectedError.value(), + Eq(iox::Error::kPOPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_UNIQUE_ID)); +}*/ + } // namespace test } // namespace iox \ No newline at end of file From cdf198d66ff8f5cae05e47c4caa2c927046d3ab3 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Wed, 10 Feb 2021 13:24:35 +0100 Subject: [PATCH 16/89] iox-#454 improve existing test Signed-off-by: Jimmy Belloche --- .../test_roudi_iceoryx_roudi_app.cpp | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index 350f204276..59213f5cd2 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "iceoryx_posh/internal/log/posh_logging.hpp" #include "iceoryx_posh/roudi/iceoryx_roudi_app.hpp" #include "iceoryx_posh/roudi/roudi_cmd_line_parser_config_file_option.hpp" #include "iceoryx_posh/roudi/roudi_config_toml_file_provider.hpp" -#include "iceoryx_posh/internal/log/posh_logging.hpp" #include #include @@ -24,17 +24,17 @@ using namespace ::testing; using ::testing::Return; using iox::roudi::IceOryxRouDiApp; +using namespace iox::config; namespace iox { namespace test { - class IceoryxRoudiApp_Child : public IceOryxRouDiApp { - public: - - IceoryxRoudiApp_Child(const config::CmdLineArgs_t& cmdLineArgs, const RouDiConfig_t& roudiConfig):IceOryxRouDiApp(cmdLineArgs,roudiConfig) + public: + IceoryxRoudiApp_Child(const config::CmdLineArgs_t& cmdLineArgs, const RouDiConfig_t& roudiConfig) + : IceOryxRouDiApp(cmdLineArgs, roudiConfig) { } @@ -58,13 +58,13 @@ class IceoryxRoudiApp_Child : public IceOryxRouDiApp class IceoryxRoudiApp_test : public Test { public: + CmdLineParserConfigFileOption cmdLineParser; - iox::config::CmdLineParserConfigFileOption cmdLineParser; - - virtual void setUp() + void TearDown() { - - } + // Reset optind to be able to parse again + optind = 0; + }; }; TEST_F(IceoryxRoudiApp_test, CheckConstructorIsSuccessfull) @@ -115,28 +115,12 @@ TEST_F(IceoryxRoudiApp_test, CheckRunMethodWithMRunFalseReturnExitSuccess) EXPECT_EQ(result, EXIT_SUCCESS); } -TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgVersionSetRunVariableToFalse) -{ - constexpr uint8_t numberOfArgs{2U}; - char* args[numberOfArgs]; - char appName[] = "./foo"; - char option[] = "-v"; - args[0] = &appName[0]; - args[1] = &option[0]; - - auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); - - IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); - - EXPECT_FALSE(roudi.getVariableMRun()); -} - -/*TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdSetRunVariableToFalse) +TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdSetRunVariableToFalse) { constexpr uint8_t numberOfArgs{3U}; char* args[numberOfArgs]; char appName[] = "./foo"; - char option[] = "-u"; + char option[] = "--unique-roudi-id"; char value[] = "4242"; args[0] = &appName[0]; args[1] = &option[0]; @@ -156,9 +140,25 @@ TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgVersionSetRunVariableToFals IceoryxRoudiApp_Child roudiTest(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); ASSERT_THAT(detectedError.has_value(), Eq(true)); - EXPECT_THAT(detectedError.value(), - Eq(iox::Error::kPOPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_UNIQUE_ID)); -}*/ + EXPECT_THAT(detectedError.value(), Eq(iox::Error::kPOPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_UNIQUE_ID)); +} + +TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgVersionSetRunVariableToFalse) +{ + constexpr uint8_t numberOfArgs{2U}; + char* args[numberOfArgs]; + char appName[] = "./foo"; + char option[] = "-v"; + args[0] = &appName[0]; + args[1] = &option[0]; + + auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + + IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); + + EXPECT_FALSE(roudi.getVariableMRun()); +} + } // namespace test } // namespace iox \ No newline at end of file From 1b48a05d8b3fafd7d265295e5b2eddd1179892bb Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Wed, 10 Feb 2021 13:44:16 +0100 Subject: [PATCH 17/89] iox-#454 change test name Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index 59213f5cd2..fa2ccfe6df 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -115,7 +115,7 @@ TEST_F(IceoryxRoudiApp_test, CheckRunMethodWithMRunFalseReturnExitSuccess) EXPECT_EQ(result, EXIT_SUCCESS); } -TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdSetRunVariableToFalse) +TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdTwoTimesReturnError) { constexpr uint8_t numberOfArgs{3U}; char* args[numberOfArgs]; From 6fb2542a171ea032f80beff5003ef8a68fd6355a Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Wed, 10 Feb 2021 16:55:07 +0100 Subject: [PATCH 18/89] iox-#454 improve test assertion Signed-off-by: Jimmy Belloche --- .../test_roudi_iceoryx_roudi_app.cpp | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index fa2ccfe6df..faa2fe6271 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -38,12 +38,27 @@ class IceoryxRoudiApp_Child : public IceOryxRouDiApp { } - bool getVariableMRun() + bool getVariableRun() { return m_run; } - void setVariableMRun(bool condition) + iox::log::LogLevel getLogLevel() + { + return m_logLevel; + } + + roudi::MonitoringMode getMonitoringMode() + { + return m_monitoringMode; + } + + RouDiConfig_t getConfig() + { + return m_config; + } + + void setVariableRun(bool condition) { m_run = condition; } @@ -67,7 +82,7 @@ class IceoryxRoudiApp_test : public Test }; }; -TEST_F(IceoryxRoudiApp_test, CheckConstructorIsSuccessfull) +TEST_F(IceoryxRoudiApp_test, VerifyConstructorIsSuccessfull) { constexpr uint8_t numberOfArgs{1U}; char* args[numberOfArgs]; @@ -78,7 +93,9 @@ TEST_F(IceoryxRoudiApp_test, CheckConstructorIsSuccessfull) IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); - EXPECT_TRUE(roudi.getVariableMRun()); + EXPECT_TRUE(roudi.getVariableRun()); + EXPECT_THAT(roudi.getLogLevel(), Eq(iox::log::LogLevel::kWarn)); + EXPECT_THAT(roudi.getMonitoringMode(), Eq(roudi::MonitoringMode::ON)); } TEST_F(IceoryxRoudiApp_test, CreateTwoRoudiAppIsSuccessfull) @@ -94,7 +111,7 @@ TEST_F(IceoryxRoudiApp_test, CreateTwoRoudiAppIsSuccessfull) IceoryxRoudiApp_Child roudiTest(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); - EXPECT_TRUE(roudiTest.getVariableMRun()); + EXPECT_TRUE(roudiTest.getVariableRun()); } TEST_F(IceoryxRoudiApp_test, CheckRunMethodWithMRunFalseReturnExitSuccess) @@ -108,7 +125,7 @@ TEST_F(IceoryxRoudiApp_test, CheckRunMethodWithMRunFalseReturnExitSuccess) IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); - roudi.setVariableMRun(false); + roudi.setVariableRun(false); uint8_t result = roudi.callRun(); @@ -156,7 +173,7 @@ TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgVersionSetRunVariableToFals IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); - EXPECT_FALSE(roudi.getVariableMRun()); + EXPECT_FALSE(roudi.getVariableRun()); } From 34f0b6f9226d8bdd30e5809121bf8cc5d5cd6b0f Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Wed, 10 Feb 2021 17:00:04 +0100 Subject: [PATCH 19/89] iox-#454 change copyright header Signed-off-by: Jimmy Belloche From e13a04209454543248fdf6995c68e03085a04dac Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Thu, 11 Feb 2021 09:48:03 +0100 Subject: [PATCH 20/89] iox-#454 revert change and add copyrighet header update Signed-off-by: Jimmy Belloche --- iceoryx_posh/source/roudi/application/roudi_app.cpp | 2 -- iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iceoryx_posh/source/roudi/application/roudi_app.cpp b/iceoryx_posh/source/roudi/application/roudi_app.cpp index 0477a4ba8b..d1d1a0ada3 100644 --- a/iceoryx_posh/source/roudi/application/roudi_app.cpp +++ b/iceoryx_posh/source/roudi/application/roudi_app.cpp @@ -12,8 +12,6 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -// -// SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/roudi/roudi_app.hpp" diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index faa2fe6271..8b2248369e 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -11,6 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/log/posh_logging.hpp" #include "iceoryx_posh/roudi/iceoryx_roudi_app.hpp" From 9ca6ce5f1d60333dbad54d94656518b04bf72865 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Thu, 11 Feb 2021 16:06:00 +0100 Subject: [PATCH 21/89] iox-#454 fix review findings Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index 8b2248369e..a478cf1891 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -19,7 +19,6 @@ #include "iceoryx_posh/roudi/roudi_cmd_line_parser_config_file_option.hpp" #include "iceoryx_posh/roudi/roudi_config_toml_file_provider.hpp" -#include #include using namespace ::testing; From 36e4c1509c6b6bccdcbdf64d0f86ee840a10b32c Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Thu, 11 Feb 2021 16:25:29 +0100 Subject: [PATCH 22/89] iox-#454 fix review findings again Signed-off-by: Jimmy Belloche --- .../test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index a478cf1891..fed752cb08 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/roudi/roudi_cmd_line_parser_config_file_option.hpp" #include "iceoryx_posh/roudi/roudi_config_toml_file_provider.hpp" -#include +#include "test.hpp" using namespace ::testing; using ::testing::Return; @@ -115,7 +115,7 @@ TEST_F(IceoryxRoudiApp_test, CreateTwoRoudiAppIsSuccessfull) EXPECT_TRUE(roudiTest.getVariableRun()); } -TEST_F(IceoryxRoudiApp_test, CheckRunMethodWithMRunFalseReturnExitSuccess) +TEST_F(IceoryxRoudiApp_test, VerifyRunMethodWithFalseConditionReturnExitSuccess) { constexpr uint8_t numberOfArgs{1U}; char* args[numberOfArgs]; From 88f228618acb31b370cd036b3d8b65a8a0841819 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Fri, 12 Feb 2021 10:34:34 +0100 Subject: [PATCH 23/89] iox-#454 change header file again Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index fed752cb08..366022987a 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019, 2021 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019, 2021 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2019, 2021 by Robert Bosch GmbH. 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. From 8c7138897eb3b5a4b09d557afd36b3725931d392 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Fri, 12 Feb 2021 13:03:33 +0100 Subject: [PATCH 24/89] iox-#454 update header file Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index 366022987a..09e68813a3 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -1,5 +1,4 @@ -// Copyright (c) 2019, 2021 by Apex.AI Inc. All rights reserved. -// Copyright (c) 2019, 2021 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Robert Bosch GmbH. 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. From 057dcc871965d0a3db82b4427e8f4a2915b2c266 Mon Sep 17 00:00:00 2001 From: chiranjeevi maddi Date: Mon, 1 Mar 2021 21:12:37 +0530 Subject: [PATCH 25/89] iox-#454 revert roudi_app file Signed-off-by: chiranjeevi maddi --- iceoryx_posh/source/roudi/application/roudi_app.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iceoryx_posh/source/roudi/application/roudi_app.cpp b/iceoryx_posh/source/roudi/application/roudi_app.cpp index d1d1a0ada3..0477a4ba8b 100644 --- a/iceoryx_posh/source/roudi/application/roudi_app.cpp +++ b/iceoryx_posh/source/roudi/application/roudi_app.cpp @@ -12,6 +12,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/roudi/roudi_app.hpp" From 24a819f125a9bdc56f121ab25493fff476a4d47f Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Tue, 2 Mar 2021 08:48:03 +0100 Subject: [PATCH 26/89] iox-#454 add new line at end of file Signed-off-by: Jimmy Belloche --- .../test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index 09e68813a3..eccc03f88a 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -55,7 +55,7 @@ class IceoryxRoudiApp_Child : public IceOryxRouDiApp } RouDiConfig_t getConfig() - { + { return m_config; } @@ -179,4 +179,4 @@ TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgVersionSetRunVariableToFals } // namespace test -} // namespace iox \ No newline at end of file +} // namespace iox From 281887ade2fa74672e9d953930166f3e2928f28d Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Fri, 5 Mar 2021 10:06:32 +0100 Subject: [PATCH 27/89] iox-#454 add include getopt.hpp for windows build Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index eccc03f88a..7e6d07a6d5 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -18,6 +18,7 @@ #include "iceoryx_posh/roudi/iceoryx_roudi_app.hpp" #include "iceoryx_posh/roudi/roudi_cmd_line_parser_config_file_option.hpp" #include "iceoryx_posh/roudi/roudi_config_toml_file_provider.hpp" +#include "iceoryx_utils/platform/getopt.hpp" #include "test.hpp" From 0caad32fd06f9118029b73a7839c0757641dc821 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Mon, 8 Mar 2021 11:15:27 +0100 Subject: [PATCH 28/89] iox-#454 remove useless function from test class Signed-off-by: Jimmy Belloche --- .../test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index 7e6d07a6d5..d7e4565591 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -55,11 +55,6 @@ class IceoryxRoudiApp_Child : public IceOryxRouDiApp return m_monitoringMode; } - RouDiConfig_t getConfig() - { - return m_config; - } - void setVariableRun(bool condition) { m_run = condition; From 18411985ea161c00042820b1a4d1a0db7c43fae5 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Tue, 9 Mar 2021 21:03:43 +0100 Subject: [PATCH 29/89] iox-#404 First attempt for posix::FileLock Signed-off-by: Simon Hoinkis --- iceoryx_utils/CMakeLists.txt | 1 + .../iceoryx_utils/posix_wrapper/file_lock.hpp | 77 +++++++++++++++++++ .../source/posix_wrapper/file_lock.cpp | 65 ++++++++++++++++ .../test/moduletests/test_posix_file_lock.cpp | 49 ++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp create mode 100644 iceoryx_utils/source/posix_wrapper/file_lock.cpp create mode 100644 iceoryx_utils/test/moduletests/test_posix_file_lock.cpp diff --git a/iceoryx_utils/CMakeLists.txt b/iceoryx_utils/CMakeLists.txt index 9352dcfd93..670ba073ff 100644 --- a/iceoryx_utils/CMakeLists.txt +++ b/iceoryx_utils/CMakeLists.txt @@ -150,6 +150,7 @@ add_library(iceoryx_utils source/log/logstream.cpp source/posix_wrapper/access_control.cpp source/posix_wrapper/mutex.cpp + source/posix_wrapper/file_lock.cpp source/posix_wrapper/semaphore.cpp source/posix_wrapper/timer.cpp source/posix_wrapper/timespec.cpp diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp new file mode 100644 index 0000000000..01ca273b09 --- /dev/null +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -0,0 +1,77 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 +#ifndef IOX_UTILS_POSIX_WRAPPER_FILE_LOCK_HPP +#define IOX_UTILS_POSIX_WRAPPER_FILE_LOCK_HPP + +#include "iceoryx_utils/cxx/expected.hpp" +#include "iceoryx_utils/cxx/helplets.hpp" +#include "iceoryx_utils/cxx/smart_c.hpp" +#include "iceoryx_utils/cxx/string.hpp" +#include "iceoryx_utils/design_pattern/creation.hpp" + +#include + +namespace iox +{ +namespace posix +{ +enum class FileLockError +{ + INVALID_STATE, + LOCKED_BY_OTHER_PROCESS, + NAME_TOO_LONG, + UNABLE_TO_OPEN_HANDLE, + UNDEFINED +}; + +constexpr char PATH_PREFIX[] = "/var/lock/"; + +/// @brief Posix file lock C++ Wrapping class +/// @code +/// auto lock = posix::FileLock::Create(); +/// @endcode +class FileLock : public DesignPattern::Creation +{ + public: + static constexpr int32_t ERROR_CODE = -1; + using FileName_t = cxx::string<100>; + + /// @brief + FileLock(FileName_t name) noexcept; + + FileLock(const FileLock&) = delete; + FileLock& operator=(const FileLock&) = delete; + FileLock(FileLock&& rhs) noexcept = default; + FileLock& operator=(FileLock&& rhs) noexcept = default; + + ~FileLock() noexcept; + + private: + int32_t m_fd; + + private: + friend class DesignPattern::Creation; + + /// @brief + /// @param[in] + FileLock() noexcept; + + FileLockError errnoToEnum(const int errnoValue) const noexcept; +}; +} // namespace posix +} // namespace iox + +#endif // IOX_UTILS_POSIX_WRAPPER_FILE_LOCK_HPP diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp new file mode 100644 index 0000000000..1fc785ff00 --- /dev/null +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -0,0 +1,65 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/posix_wrapper/file_lock.hpp" +#include "iceoryx_utils/cxx/smart_c.hpp" +#include "iceoryx_utils/platform/fcntl.hpp" +#include "iceoryx_utils/platform/platform_correction.hpp" + +#include + +namespace iox +{ +namespace posix +{ +FileLock::FileLock(FileName_t name) noexcept +{ + cxx::string<200> fullPath = PATH_PREFIX + name; + constexpr int OFlags = O_CREAT | O_RDWR; + + auto openCall = + cxx::makeSmartC(open, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, fullPath.c_str(), OFlags); + + if (openCall.hasErrors()) + { + m_isInitialized = false; + } + else + { + m_fd = openCall.getReturnValue(); + + auto lockCall = + cxx::makeSmartC(flock, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_fd, LOCK_EX | LOCK_NB); + + if (!lockCall.hasErrors()) + { + m_isInitialized = true; + } + else + { + if (lockCall.getErrNum() == EWOULDBLOCK) + { + m_errorValue = FileLockError::LOCKED_BY_OTHER_PROCESS; + } + } + } +} + +FileLock::~FileLock() noexcept +{} + +} // namespace posix +} // namespace iox diff --git a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp new file mode 100644 index 0000000000..99fa65f754 --- /dev/null +++ b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp @@ -0,0 +1,49 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/posix_wrapper/file_lock.hpp" +#include "test.hpp" + +using namespace ::testing; +using namespace iox::posix; +using namespace iox::cxx; + +class FileLock_test : public Test +{ + public: + FileLock_test() + { + } + + void SetUp() + { + } + + void TearDown() + { + } + + ~FileLock_test() + { + } +}; + +constexpr char TEST_SHM_NAME[] = "TestProcess"; + +TEST_F(FileLock_test, LockAndReleaseWorks) +{ + iox::posix::FileLock::create(TEST_SHM_NAME); +} From 3e06ab51e2e5463cf1559cc77278d8cafe8de26d Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Wed, 10 Mar 2021 18:34:37 +0100 Subject: [PATCH 30/89] iox-#404 Add test cases for FileLock Signed-off-by: Simon Hoinkis --- .../test/moduletests/test_posix_file_lock.cpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp index 99fa65f754..bf27d99a31 100644 --- a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp +++ b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp @@ -43,7 +43,26 @@ class FileLock_test : public Test constexpr char TEST_SHM_NAME[] = "TestProcess"; +TEST_F(FileLock_test, LockWorks) +{ + auto sut1 = iox::posix::FileLock::create(TEST_SHM_NAME); + ASSERT_FALSE(sut1.has_error()); +} + TEST_F(FileLock_test, LockAndReleaseWorks) { - iox::posix::FileLock::create(TEST_SHM_NAME); + { + auto sut1 = iox::posix::FileLock::create(TEST_SHM_NAME); + } + auto sut2 = iox::posix::FileLock::create(TEST_SHM_NAME); + ASSERT_FALSE(sut2.has_error()); +} + +TEST_F(FileLock_test, LockAndNoReleaseLeadsToError) +{ + auto sut1 = iox::posix::FileLock::create(TEST_SHM_NAME); + auto sut2 = iox::posix::FileLock::create(TEST_SHM_NAME); + ASSERT_FALSE(sut1.has_error()); + ASSERT_TRUE(sut2.has_error()); + EXPECT_THAT(sut2.get_error(), Eq(FileLockError::LOCKED_BY_OTHER_PROCESS)); } From f69aa31264782aa25a81cac47b37a5135aa9ee6a Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Thu, 11 Mar 2021 14:57:24 +0100 Subject: [PATCH 31/89] iox-#404 Finish off posix::FileLock implementation Signed-off-by: Simon Hoinkis --- .../iceoryx_utils/posix_wrapper/file_lock.hpp | 36 ++- .../include/iceoryx_utils/platform/fcntl.hpp | 2 + iceoryx_utils/platform/linux/source/fnctl.cpp | 22 ++ .../include/iceoryx_utils/platform/fcntl.hpp | 2 + iceoryx_utils/platform/mac/source/fnctl.cpp | 22 ++ .../include/iceoryx_utils/platform/fcntl.hpp | 2 + iceoryx_utils/platform/qnx/source/fnctl.cpp | 22 ++ .../include/iceoryx_utils/platform/fcntl.hpp | 2 + .../include/iceoryx_utils/platform/unistd.hpp | 1 - iceoryx_utils/platform/win/source/fnctl.cpp | 22 ++ .../source/posix_wrapper/file_lock.cpp | 261 +++++++++++++++++- 11 files changed, 369 insertions(+), 25 deletions(-) create mode 100644 iceoryx_utils/platform/linux/source/fnctl.cpp create mode 100644 iceoryx_utils/platform/mac/source/fnctl.cpp create mode 100644 iceoryx_utils/platform/qnx/source/fnctl.cpp create mode 100644 iceoryx_utils/platform/win/source/fnctl.cpp diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index 01ca273b09..66384131c7 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -32,9 +32,22 @@ enum class FileLockError { INVALID_STATE, LOCKED_BY_OTHER_PROCESS, - NAME_TOO_LONG, - UNABLE_TO_OPEN_HANDLE, - UNDEFINED + ACCESS_DENIED, + INVALID_FILE_NAME, + FILE_EXISTS, + INTERRUPTED_BY_SIGNAL, + QUOTA_EXHAUSTED, + INVALID_ARGUMENTS, + SYSTEM_LIMIT, + PROCESS_LIMIT, + NO_SUCH_FILE, + SPECIAL_FILE, + TEMP_FILE_NOT_SUPPORTED, + FILE_TOO_LARGE, + FILE_IN_USE, + INVALID_FILE_DESCRIPTOR, + OUT_OF_MEMORY, + INTERNAL_LOGIC_ERROR, }; constexpr char PATH_PREFIX[] = "/var/lock/"; @@ -47,27 +60,30 @@ class FileLock : public DesignPattern::Creation { public: static constexpr int32_t ERROR_CODE = -1; + static constexpr int32_t INVALID_FD = -1; using FileName_t = cxx::string<100>; /// @brief FileLock(FileName_t name) noexcept; - + FileLock(const FileLock&) = delete; FileLock& operator=(const FileLock&) = delete; - FileLock(FileLock&& rhs) noexcept = default; - FileLock& operator=(FileLock&& rhs) noexcept = default; + FileLock(FileLock&& rhs) noexcept; + FileLock& operator=(FileLock&& rhs) noexcept; ~FileLock() noexcept; private: - int32_t m_fd; + int32_t m_fd{INVALID_FD}; + FileName_t m_name{""}; - private: friend class DesignPattern::Creation; - /// @brief - /// @param[in] FileLock() noexcept; + cxx::expected initializeFileLock() noexcept; + cxx::error createErrorFromErrnum(const int32_t errnum) const noexcept; + cxx::expected closeFileDescriptor() noexcept; + cxx::expected destroy() noexcept; FileLockError errnoToEnum(const int errnoValue) const noexcept; }; diff --git a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp index 807773b9b4..5cbe220dbe 100644 --- a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp @@ -18,4 +18,6 @@ #include +int openPlatformFileHandle(const char* pathname, int flags, mode_t mode); + #endif // IOX_UTILS_LINUX_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/linux/source/fnctl.cpp b/iceoryx_utils/platform/linux/source/fnctl.cpp new file mode 100644 index 0000000000..7d9c2d38e1 --- /dev/null +++ b/iceoryx_utils/platform/linux/source/fnctl.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2021 by Apex.AI. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/platform/fcntl.hpp" + +int openPlatformFileHandle(const char* pathname, int flags, mode_t mode) +{ + return open(pathname, flags, mode); +} \ No newline at end of file diff --git a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp index 3721a349b4..ea7d5ad8a8 100644 --- a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp @@ -18,4 +18,6 @@ #include +int openPlatformFileHandle(const char* pathname, int flags, mode_t mode); + #endif // IOX_UTILS_MAC_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/mac/source/fnctl.cpp b/iceoryx_utils/platform/mac/source/fnctl.cpp new file mode 100644 index 0000000000..7d9c2d38e1 --- /dev/null +++ b/iceoryx_utils/platform/mac/source/fnctl.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2021 by Apex.AI. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/platform/fcntl.hpp" + +int openPlatformFileHandle(const char* pathname, int flags, mode_t mode) +{ + return open(pathname, flags, mode); +} \ No newline at end of file diff --git a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp index 17f6c26d14..04e418d95e 100644 --- a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp @@ -18,4 +18,6 @@ #include +int openPlatformFileHandle(const char* pathname, int flags, mode_t mode); + #endif // IOX_UTILS_QNX_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/qnx/source/fnctl.cpp b/iceoryx_utils/platform/qnx/source/fnctl.cpp new file mode 100644 index 0000000000..7d9c2d38e1 --- /dev/null +++ b/iceoryx_utils/platform/qnx/source/fnctl.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2021 by Apex.AI. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/platform/fcntl.hpp" + +int openPlatformFileHandle(const char* pathname, int flags, mode_t mode) +{ + return open(pathname, flags, mode); +} \ No newline at end of file diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp index 8c013b148a..f50045c416 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp @@ -28,4 +28,6 @@ #define O_WRONLY _O_WRONLY #define O_NONBLOCK 0x0 +int openPlatformFileHandle(const char* pathname, int flags, mode_t mode); + #endif // IOX_UTILS_WIN_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp index 780f38696e..39b676478e 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp @@ -44,6 +44,5 @@ class HandleTranslator int ftruncate(int fildes, off_t length); long sysconf(int name); -int closePlatformFileHandle(int fd); #endif // IOX_UTILS_WIN_PLATFORM_UNISTD_HPP diff --git a/iceoryx_utils/platform/win/source/fnctl.cpp b/iceoryx_utils/platform/win/source/fnctl.cpp new file mode 100644 index 0000000000..4bbbd648a2 --- /dev/null +++ b/iceoryx_utils/platform/win/source/fnctl.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2021 by Apex.AI. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/platform/fcntl.hpp" + +int openPlatformFileHandle(const char* pathname, int flags, mode_t mode) +{ + return 0; +} \ No newline at end of file diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index 1fc785ff00..3618284b59 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -18,6 +18,7 @@ #include "iceoryx_utils/cxx/smart_c.hpp" #include "iceoryx_utils/platform/fcntl.hpp" #include "iceoryx_utils/platform/platform_correction.hpp" +#include "iceoryx_utils/platform/unistd.hpp" #include @@ -26,40 +27,272 @@ namespace iox namespace posix { FileLock::FileLock(FileName_t name) noexcept + : m_name(name) { - cxx::string<200> fullPath = PATH_PREFIX + name; - constexpr int OFlags = O_CREAT | O_RDWR; + initializeFileLock().and_then([this]() { this->m_isInitialized = true; }).or_else([this](FileLockError& error) { + this->m_isInitialized = false; + this->m_errorValue = error; + }); +} + +cxx::expected FileLock::initializeFileLock() noexcept +{ + cxx::string<200> fullPath = PATH_PREFIX + m_name + ".lock"; + constexpr int oFlags = O_CREAT | O_RDWR; + mode_t mode = S_IRWXU; - auto openCall = - cxx::makeSmartC(open, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, fullPath.c_str(), OFlags); + auto openCall = cxx::makeSmartC(openPlatformFileHandle, + cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, + {ERROR_CODE}, + {}, + fullPath.c_str(), + oFlags, + mode); if (openCall.hasErrors()) { - m_isInitialized = false; + return createErrorFromErrnum(openCall.getErrNum()); } else { m_fd = openCall.getReturnValue(); - auto lockCall = - cxx::makeSmartC(flock, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_fd, LOCK_EX | LOCK_NB); + auto lockCall = cxx::makeSmartC( + flock, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {EWOULDBLOCK}, m_fd, LOCK_EX | LOCK_NB); - if (!lockCall.hasErrors()) + if (lockCall.hasErrors()) { - m_isInitialized = true; + closeFileDescriptor(); + // possible errors in closeFileDescriptor() are masked and we inform the user about the actual error + return createErrorFromErrnum(openCall.getErrNum()); + } + else if (lockCall.getErrNum() == EWOULDBLOCK) + { + closeFileDescriptor(); + // possible errors in closeFileDescriptor() are masked and we inform the user about the actual error + return cxx::error(FileLockError::LOCKED_BY_OTHER_PROCESS); } else { - if (lockCall.getErrNum() == EWOULDBLOCK) - { - m_errorValue = FileLockError::LOCKED_BY_OTHER_PROCESS; - } + return cxx::success<>(); } } } +FileLock::FileLock(FileLock&& rhs) noexcept +{ + *this = std::move(rhs); +} + +FileLock& FileLock::operator=(FileLock&& rhs) noexcept +{ + if (this != &rhs) + { + if (destroy().has_error()) + { + std::cerr << "Unable to cleanup file lock \"" << m_name + << "\" in the move constructor/move assingment operator" << std::endl; + } + + CreationPattern_t::operator=(std::move(rhs)); + + m_name = std::move(rhs.m_name); + m_fd = std::move(rhs.m_fd); + + rhs.m_fd = INVALID_FD; + } + + return *this; +} + +cxx::expected FileLock::destroy() noexcept +{ + if (m_isInitialized) + { + return closeFileDescriptor(); + } + + return cxx::success(); +} + FileLock::~FileLock() noexcept -{} +{ + closeFileDescriptor(); +} + +cxx::expected FileLock::closeFileDescriptor() noexcept +{ + if (m_fd != INVALID_FD) + { + auto closeCall = + cxx::makeSmartC(closePlatformFileHandle, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_fd); + + if (!closeCall.hasErrors()) + { + m_fd = INVALID_FD; + m_isInitialized = false; + + return cxx::success(); + } + else + { + return createErrorFromErrnum(closeCall.getErrNum()); + } + } + return cxx::success<>(); +} + +cxx::error FileLock::createErrorFromErrnum(const int32_t errnum) const noexcept +{ + switch (errnum) + { + case EACCES: + { + std::cerr << "permission to access file denied \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::ACCESS_DENIED); + } + case EBUSY: + { + std::cerr << "provided invalid arguments for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_ARGUMENTS); + } + case EDQUOT: + { + std::cerr << "user disk quota exhausted for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::QUOTA_EXHAUSTED); + } + case EEXIST: + { + std::cerr << "file \"" << m_name << "\"" + << " already exists" << std::endl; + return cxx::error(FileLockError::FILE_EXISTS); + } + case EFAULT: + { + std::cerr << "outside address space error for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_FILE_NAME); + } + case EFBIG: + { + std::cerr << "overflow for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_FILE_NAME); + } + case EINTR: + { + std::cerr << "Interrupted by signal for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INTERRUPTED_BY_SIGNAL); + } + case EINVAL: + { + std::cerr << "provided invalid arguments for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_ARGUMENTS); + } + case EISDIR: + { + std::cerr << "Writing access requested for directory \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_ARGUMENTS); + } + case ELOOP: + { + std::cerr << "too many symbolic links for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_FILE_NAME); + } + case EMFILE: + { + std::cerr << "process limit reached for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::PROCESS_LIMIT); + } + case ENAMETOOLONG: + { + std::cerr << "name too long for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_FILE_NAME); + } + case ENFILE: + { + std::cerr << "system limit reached for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::SYSTEM_LIMIT); + } + case ENODEV: + { + std::cerr << "permission to access file denied \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::ACCESS_DENIED); + } + case ENOENT: + { + std::cerr << "file \"" << m_name << "\"" + << "does not exist" << std::endl; + return cxx::error(FileLockError::NO_SUCH_FILE); + } + case ENOMEM: + { + std::cerr << "out of memory for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::OUT_OF_MEMORY); + } + case ENOSPC: + { + std::cerr << "Device has no space for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::QUOTA_EXHAUSTED); + } + case ENOTDIR: + { + std::cerr << "not a directory error for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_FILE_NAME); + } + case ENXIO: + { + std::cerr << "\"" << m_name << "\"" + << " is a special file and no corresponding device exists" << std::endl; + return cxx::error(FileLockError::SPECIAL_FILE); + } + case EOPNOTSUPP: + { + std::cerr << "filesystem does not support O_TMPFILE for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::TEMP_FILE_NOT_SUPPORTED); + } + case EOVERFLOW: + { + std::cerr << "file \"" << m_name << "\"" + << " is too large to be openend" << std::endl; + return cxx::error(FileLockError::FILE_TOO_LARGE); + } + case EPERM: + { + std::cerr << "permission to access file denied \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::ACCESS_DENIED); + } + case EBADF: + { + std::cerr << "invalid file descriptor for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_FILE_DESCRIPTOR); + } + case EROFS: + { + std::cerr << "read only error for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::INVALID_FILE_NAME); + } + case ETXTBSY: + { + std::cerr << "write access requested for file \"" << m_name << "\"" + << " in use" << std::endl; + return cxx::error(FileLockError::FILE_IN_USE); + } + case EWOULDBLOCK: + { + // no error message needed since this is a normal use case + return cxx::error(FileLockError::LOCKED_BY_OTHER_PROCESS); + } + case ENOLCK: + { + std::cerr << "system limit for locks reached for file \"" << m_name << "\"" << std::endl; + return cxx::error(FileLockError::SYSTEM_LIMIT); + } + default: + { + std::cerr << "internal logic error in unix domain socket \"" << m_name << "\" occurred" << std::endl; + return cxx::error(FileLockError::INTERNAL_LOGIC_ERROR); + } + } +} } // namespace posix } // namespace iox From a64455f1894974bfbf0819140092aae87b07a6fc Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Thu, 11 Mar 2021 16:35:27 +0100 Subject: [PATCH 32/89] iox-#404 Make invalid FileLock c'tor public and add doxygen Signed-off-by: Simon Hoinkis --- .../iceoryx_utils/posix_wrapper/file_lock.hpp | 30 ++++++++++++++----- .../include/iceoryx_utils/platform/fcntl.hpp | 2 +- iceoryx_utils/platform/linux/source/fnctl.cpp | 4 +-- .../include/iceoryx_utils/platform/fcntl.hpp | 2 +- iceoryx_utils/platform/mac/source/fnctl.cpp | 4 +-- .../include/iceoryx_utils/platform/fcntl.hpp | 2 +- iceoryx_utils/platform/qnx/source/fnctl.cpp | 4 +-- .../include/iceoryx_utils/platform/fcntl.hpp | 2 +- iceoryx_utils/platform/win/source/fnctl.cpp | 4 +-- .../source/posix_wrapper/file_lock.cpp | 19 ++++++------ .../test/moduletests/test_posix_file_lock.cpp | 28 ++++++++++------- 11 files changed, 62 insertions(+), 39 deletions(-) diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index 66384131c7..732a56cdb7 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -31,6 +31,7 @@ namespace posix enum class FileLockError { INVALID_STATE, + NOT_INITIALIZED, LOCKED_BY_OTHER_PROCESS, ACCESS_DENIED, INVALID_FILE_NAME, @@ -52,19 +53,31 @@ enum class FileLockError constexpr char PATH_PREFIX[] = "/var/lock/"; -/// @brief Posix file lock C++ Wrapping class +/// @brief Posix file lock C++ wrapping class +/// Following RAII, the lock is acquired on creation and released on destruction. Release the locks works even if +/// the process crashes with a segfault or using SIGKILL. +/// 'lslocks' can be used to display all system-wide locks (see man page) /// @code -/// auto lock = posix::FileLock::Create(); +/// iox::posix::FileLock::create(nameOfmyLock) +/// .and_then([] { std::cout << "We aquired the lock!" << std::endl; }) +/// .or_else([](auto& error) { +/// if (error == FileLockError::LOCKED_BY_OTHER_PROCESS) +/// { +/// std::cout << "Some other process is running and holds the lock!" << std::endl; +/// } +/// }); /// @endcode class FileLock : public DesignPattern::Creation { public: static constexpr int32_t ERROR_CODE = -1; static constexpr int32_t INVALID_FD = -1; - using FileName_t = cxx::string<100>; + using FileName_t = cxx::string<30>; + using PathName_t = cxx::string<100>; - /// @brief - FileLock(FileName_t name) noexcept; + /// @brief Default constructor which creates an invalid FileLock. Can be used to assign a value with the move + /// constructor + FileLock() noexcept; FileLock(const FileLock&) = delete; FileLock& operator=(const FileLock&) = delete; @@ -77,15 +90,16 @@ class FileLock : public DesignPattern::Creation int32_t m_fd{INVALID_FD}; FileName_t m_name{""}; - friend class DesignPattern::Creation; + /// @brief c'tor + /// @param[in] name of the created file lock in PATH_PREFIX + FileLock(FileName_t name) noexcept; - FileLock() noexcept; cxx::expected initializeFileLock() noexcept; cxx::error createErrorFromErrnum(const int32_t errnum) const noexcept; cxx::expected closeFileDescriptor() noexcept; cxx::expected destroy() noexcept; - FileLockError errnoToEnum(const int errnoValue) const noexcept; + friend class DesignPattern::Creation; }; } // namespace posix } // namespace iox diff --git a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp index 5cbe220dbe..6ca4b044d0 100644 --- a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp @@ -18,6 +18,6 @@ #include -int openPlatformFileHandle(const char* pathname, int flags, mode_t mode); +int openFile(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_LINUX_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/linux/source/fnctl.cpp b/iceoryx_utils/platform/linux/source/fnctl.cpp index 7d9c2d38e1..5147857789 100644 --- a/iceoryx_utils/platform/linux/source/fnctl.cpp +++ b/iceoryx_utils/platform/linux/source/fnctl.cpp @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/fcntl.hpp" -int openPlatformFileHandle(const char* pathname, int flags, mode_t mode) +int openFile(const char* pathname, int flags, mode_t mode) { return open(pathname, flags, mode); -} \ No newline at end of file +} diff --git a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp index ea7d5ad8a8..d3939b044e 100644 --- a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp @@ -18,6 +18,6 @@ #include -int openPlatformFileHandle(const char* pathname, int flags, mode_t mode); +int openFile(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_MAC_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/mac/source/fnctl.cpp b/iceoryx_utils/platform/mac/source/fnctl.cpp index 7d9c2d38e1..5147857789 100644 --- a/iceoryx_utils/platform/mac/source/fnctl.cpp +++ b/iceoryx_utils/platform/mac/source/fnctl.cpp @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/fcntl.hpp" -int openPlatformFileHandle(const char* pathname, int flags, mode_t mode) +int openFile(const char* pathname, int flags, mode_t mode) { return open(pathname, flags, mode); -} \ No newline at end of file +} diff --git a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp index 04e418d95e..4f0ecab80d 100644 --- a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp @@ -18,6 +18,6 @@ #include -int openPlatformFileHandle(const char* pathname, int flags, mode_t mode); +int openFile(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_QNX_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/qnx/source/fnctl.cpp b/iceoryx_utils/platform/qnx/source/fnctl.cpp index 7d9c2d38e1..5147857789 100644 --- a/iceoryx_utils/platform/qnx/source/fnctl.cpp +++ b/iceoryx_utils/platform/qnx/source/fnctl.cpp @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/fcntl.hpp" -int openPlatformFileHandle(const char* pathname, int flags, mode_t mode) +int openFile(const char* pathname, int flags, mode_t mode) { return open(pathname, flags, mode); -} \ No newline at end of file +} diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp index f50045c416..dcfbf01f87 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp @@ -28,6 +28,6 @@ #define O_WRONLY _O_WRONLY #define O_NONBLOCK 0x0 -int openPlatformFileHandle(const char* pathname, int flags, mode_t mode); +int openFile(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_WIN_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/win/source/fnctl.cpp b/iceoryx_utils/platform/win/source/fnctl.cpp index 4bbbd648a2..8b8744dd04 100644 --- a/iceoryx_utils/platform/win/source/fnctl.cpp +++ b/iceoryx_utils/platform/win/source/fnctl.cpp @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/fcntl.hpp" -int openPlatformFileHandle(const char* pathname, int flags, mode_t mode) +int openFile(const char* pathname, int flags, mode_t mode) { return 0; -} \ No newline at end of file +} diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index 3618284b59..9f93c60195 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -26,6 +26,12 @@ namespace iox { namespace posix { +FileLock::FileLock() noexcept +{ + this->m_isInitialized = false; + this->m_errorValue = FileLockError::NOT_INITIALIZED; +} + FileLock::FileLock(FileName_t name) noexcept : m_name(name) { @@ -37,17 +43,12 @@ FileLock::FileLock(FileName_t name) noexcept cxx::expected FileLock::initializeFileLock() noexcept { - cxx::string<200> fullPath = PATH_PREFIX + m_name + ".lock"; + PathName_t fullPath(PATH_PREFIX + m_name + ".lock"); constexpr int oFlags = O_CREAT | O_RDWR; - mode_t mode = S_IRWXU; + mode_t mode = S_IRUSR | S_IWUSR; - auto openCall = cxx::makeSmartC(openPlatformFileHandle, - cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, - {ERROR_CODE}, - {}, - fullPath.c_str(), - oFlags, - mode); + auto openCall = cxx::makeSmartC( + openFile, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, fullPath.c_str(), oFlags, mode); if (openCall.hasErrors()) { diff --git a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp index bf27d99a31..50b4f3b701 100644 --- a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp +++ b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp @@ -21,6 +21,14 @@ using namespace ::testing; using namespace iox::posix; using namespace iox::cxx; +constexpr char TEST_NAME[] = "TestProcess"; +constexpr char ANOTHER_TEST_NAME[] = "AnotherTestProcess"; + +/// @req +/// @brief This test suite verifies the behaviour of the class FileLock +/// @pre the file lock for TEST_NAME is acquired +/// @post None +/// @note This should become a FЯIDA integration test once available, in order to test with two processes class FileLock_test : public Test { public: @@ -30,6 +38,9 @@ class FileLock_test : public Test void SetUp() { + auto createResult = iox::posix::FileLock::create(TEST_NAME); + ASSERT_FALSE(createResult.has_error()); + m_sut = std::move(createResult.value()); } void TearDown() @@ -39,30 +50,27 @@ class FileLock_test : public Test ~FileLock_test() { } + iox::posix::FileLock m_sut; }; -constexpr char TEST_SHM_NAME[] = "TestProcess"; - -TEST_F(FileLock_test, LockWorks) +TEST_F(FileLock_test, SecondLockWithDifferentNameWorks) { - auto sut1 = iox::posix::FileLock::create(TEST_SHM_NAME); - ASSERT_FALSE(sut1.has_error()); + auto sut2 = iox::posix::FileLock::create(ANOTHER_TEST_NAME); + ASSERT_FALSE(sut2.has_error()); } TEST_F(FileLock_test, LockAndReleaseWorks) { { - auto sut1 = iox::posix::FileLock::create(TEST_SHM_NAME); + auto sut1 = iox::posix::FileLock::create(ANOTHER_TEST_NAME); } - auto sut2 = iox::posix::FileLock::create(TEST_SHM_NAME); + auto sut2 = iox::posix::FileLock::create(ANOTHER_TEST_NAME); ASSERT_FALSE(sut2.has_error()); } TEST_F(FileLock_test, LockAndNoReleaseLeadsToError) { - auto sut1 = iox::posix::FileLock::create(TEST_SHM_NAME); - auto sut2 = iox::posix::FileLock::create(TEST_SHM_NAME); - ASSERT_FALSE(sut1.has_error()); + auto sut2 = iox::posix::FileLock::create(TEST_NAME); ASSERT_TRUE(sut2.has_error()); EXPECT_THAT(sut2.get_error(), Eq(FileLockError::LOCKED_BY_OTHER_PROCESS)); } From 3c36d70b0229d5cbcfd27dc45ecf9b94576b9ec4 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Thu, 11 Mar 2021 16:47:39 +0100 Subject: [PATCH 33/89] iox-#404 Remove unnecessary includes and rework docu Signed-off-by: Simon Hoinkis --- .../include/iceoryx_utils/posix_wrapper/file_lock.hpp | 10 +++------- .../win/include/iceoryx_utils/platform/unistd.hpp | 1 + iceoryx_utils/source/posix_wrapper/file_lock.cpp | 9 +++++---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index 732a56cdb7..2a1e497f8c 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -17,13 +17,9 @@ #define IOX_UTILS_POSIX_WRAPPER_FILE_LOCK_HPP #include "iceoryx_utils/cxx/expected.hpp" -#include "iceoryx_utils/cxx/helplets.hpp" -#include "iceoryx_utils/cxx/smart_c.hpp" #include "iceoryx_utils/cxx/string.hpp" #include "iceoryx_utils/design_pattern/creation.hpp" -#include - namespace iox { namespace posix @@ -54,9 +50,9 @@ enum class FileLockError constexpr char PATH_PREFIX[] = "/var/lock/"; /// @brief Posix file lock C++ wrapping class -/// Following RAII, the lock is acquired on creation and released on destruction. Release the locks works even if -/// the process crashes with a segfault or using SIGKILL. -/// 'lslocks' can be used to display all system-wide locks (see man page) +/// Following RAII, the lock is acquired on creation and released on destruction. Releasing the locks works even +/// if the process crashes with a segfault or using SIGKILL. 'lslocks' can be used to display all system-wide +/// locks (see man page) /// @code /// iox::posix::FileLock::create(nameOfmyLock) /// .and_then([] { std::cout << "We aquired the lock!" << std::endl; }) diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp index 39b676478e..780f38696e 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp @@ -44,5 +44,6 @@ class HandleTranslator int ftruncate(int fildes, off_t length); long sysconf(int name); +int closePlatformFileHandle(int fd); #endif // IOX_UTILS_WIN_PLATFORM_UNISTD_HPP diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index 9f93c60195..b46a60e43e 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -154,8 +154,9 @@ cxx::error FileLock::createErrorFromErrnum(const int32_t errnum) } case EBUSY: { - std::cerr << "provided invalid arguments for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_ARGUMENTS); + std::cerr << "O_EXCL provided but file \"" << m_name << "\"" + << " is currently used" << std::endl; + return cxx::error(FileLockError::FILE_IN_USE); } case EDQUOT: { @@ -171,7 +172,7 @@ cxx::error FileLock::createErrorFromErrnum(const int32_t errnum) case EFAULT: { std::cerr << "outside address space error for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_FILE_NAME); + return cxx::error(FileLockError::ACCESS_DENIED); } case EFBIG: { @@ -190,7 +191,7 @@ cxx::error FileLock::createErrorFromErrnum(const int32_t errnum) } case EISDIR: { - std::cerr << "Writing access requested for directory \"" << m_name << "\"" << std::endl; + std::cerr << "write access requested for directory \"" << m_name << "\"" << std::endl; return cxx::error(FileLockError::INVALID_ARGUMENTS); } case ELOOP: From 56bcf1be945b5baf4846a8027aa79aa49b28bee3 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Fri, 12 Mar 2021 15:45:43 +0100 Subject: [PATCH 34/89] iox-#404 Return IpcChannelError instead of cxx:error in UnixDomainSocket Signed-off-by: Simon Hoinkis --- .../posix_wrapper/unix_domain_socket.hpp | 2 +- .../posix_wrapper/unix_domain_socket.cpp | 78 +++++++++---------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/iceoryx_utils/include/iceoryx_utils/internal/posix_wrapper/unix_domain_socket.hpp b/iceoryx_utils/include/iceoryx_utils/internal/posix_wrapper/unix_domain_socket.hpp index 7e01ba9a2e..0dff154199 100644 --- a/iceoryx_utils/include/iceoryx_utils/internal/posix_wrapper/unix_domain_socket.hpp +++ b/iceoryx_utils/include/iceoryx_utils/internal/posix_wrapper/unix_domain_socket.hpp @@ -138,7 +138,7 @@ class UnixDomainSocket : public DesignPattern::Creation createErrorFromErrnum(const int32_t errnum) const noexcept; + IpcChannelError convertErrnoToIpcChannelError(const int32_t errnum) const noexcept; static bool isNameValid(const UdsName_t& name) noexcept; diff --git a/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp b/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp index 28be54c46e..59b842b47a 100644 --- a/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp +++ b/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp @@ -178,7 +178,7 @@ cxx::expected UnixDomainSocket::closeFileDescriptor() noexcept } else { - return createErrorFromErrnum(closeCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(closeCall.getErrNum())); } } return cxx::success<>(); @@ -201,8 +201,8 @@ cxx::expected UnixDomainSocket::send(const std::string& msg) co return timedSend(msg, units::Duration::fromSeconds(0ULL)); } -cxx::expected UnixDomainSocket::timedSend(const std::string& msg, - const units::Duration& timeout) const noexcept +cxx::expected UnixDomainSocket::timedSend(const std::string& msg, const units::Duration& timeout) const + noexcept { if (msg.size() >= m_maxMessageSize) // message sizes with null termination must be smaller than m_maxMessageSize { @@ -238,7 +238,7 @@ cxx::expected UnixDomainSocket::timedSend(const std::string& ms if (setsockoptCall.hasErrors()) { - return createErrorFromErrnum(setsockoptCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(setsockoptCall.getErrNum())); } else { @@ -255,7 +255,7 @@ cxx::expected UnixDomainSocket::timedSend(const std::string& ms if (sendCall.hasErrors()) { - return createErrorFromErrnum(sendCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(sendCall.getErrNum())); } else { @@ -276,8 +276,8 @@ cxx::expected UnixDomainSocket::receive() const no } -cxx::expected -UnixDomainSocket::timedReceive(const units::Duration& timeout) const noexcept +cxx::expected UnixDomainSocket::timedReceive(const units::Duration& timeout) const + noexcept { if (IpcChannelSide::CLIENT == m_channelSide) { @@ -299,7 +299,7 @@ UnixDomainSocket::timedReceive(const units::Duration& timeout) const noexcept if (setsockoptCall.hasErrors()) { - return createErrorFromErrnum(setsockoptCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(setsockoptCall.getErrNum())); } else { @@ -318,13 +318,13 @@ UnixDomainSocket::timedReceive(const units::Duration& timeout) const noexcept if (recvCall.hasErrors()) { - return createErrorFromErrnum(recvCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(recvCall.getErrNum())); } /// we have to handle the timeout separately since it is not actual an /// error, it is expected behavior. but we have to still inform the user else if (recvCall.getErrNum() == EAGAIN) { - return createErrorFromErrnum(recvCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(recvCall.getErrNum())); } else { @@ -357,7 +357,7 @@ cxx::expected UnixDomainSocket::initalizeSocket(const IpcChanne if (socketCall.hasErrors()) { - return createErrorFromErrnum(socketCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(socketCall.getErrNum())); } m_sockfd = socketCall.getReturnValue(); @@ -382,7 +382,7 @@ cxx::expected UnixDomainSocket::initalizeSocket(const IpcChanne { closeFileDescriptor(); // possible errors in closeFileDescriptor() are masked and we inform the user about the actual error - return createErrorFromErrnum(bindCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(bindCall.getErrNum())); } } else @@ -401,13 +401,13 @@ cxx::expected UnixDomainSocket::initalizeSocket(const IpcChanne { closeFileDescriptor(); // possible errors in closeFileDescriptor() are masked and we inform the user about the actual error - return createErrorFromErrnum(connectCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(connectCall.getErrNum())); } else if (connectCall.getErrNum() == ENOENT) { closeFileDescriptor(); // possible errors in closeFileDescriptor() are masked and we inform the user about the actual error - return createErrorFromErrnum(connectCall.getErrNum()); + return cxx::error(convertErrnoToIpcChannelError(connectCall.getErrNum())); } else { @@ -426,129 +426,129 @@ cxx::expected UnixDomainSocket::isOutdated() noexcept } -cxx::error UnixDomainSocket::createErrorFromErrnum(const int32_t errnum) const noexcept +IpcChannelError UnixDomainSocket::convertErrnoToIpcChannelError(const int32_t errnum) const noexcept { switch (errnum) { case EACCES: { std::cerr << "permission to create unix domain socket denied \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::ACCESS_DENIED); + return IpcChannelError(IpcChannelError::ACCESS_DENIED); } case EAFNOSUPPORT: { std::cerr << "address family not supported for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_ARGUMENTS); + return IpcChannelError(IpcChannelError::INVALID_ARGUMENTS); } case EINVAL: { std::cerr << "provided invalid arguments for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_ARGUMENTS); + return IpcChannelError(IpcChannelError::INVALID_ARGUMENTS); } case EMFILE: { std::cerr << "process limit reached for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::PROCESS_LIMIT); + return IpcChannelError(IpcChannelError::PROCESS_LIMIT); } case ENFILE: { std::cerr << "system limit reached for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::SYSTEM_LIMIT); + return IpcChannelError(IpcChannelError::SYSTEM_LIMIT); } case ENOBUFS: { std::cerr << "out of memory for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::OUT_OF_MEMORY); + return IpcChannelError(IpcChannelError::OUT_OF_MEMORY); } case ENOMEM: { std::cerr << "out of memory for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::OUT_OF_MEMORY); + return IpcChannelError(IpcChannelError::OUT_OF_MEMORY); } case EPROTONOSUPPORT: { std::cerr << "protocol type not supported for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_ARGUMENTS); + return IpcChannelError(IpcChannelError::INVALID_ARGUMENTS); } case EADDRINUSE: { std::cerr << "unix domain socket already in use \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::CHANNEL_ALREADY_EXISTS); + return IpcChannelError(IpcChannelError::CHANNEL_ALREADY_EXISTS); } case EBADF: { std::cerr << "invalid file descriptor for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_FILE_DESCRIPTOR); + return IpcChannelError(IpcChannelError::INVALID_FILE_DESCRIPTOR); } case ENOTSOCK: { std::cerr << "invalid file descriptor for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_FILE_DESCRIPTOR); + return IpcChannelError(IpcChannelError::INVALID_FILE_DESCRIPTOR); } case EADDRNOTAVAIL: { std::cerr << "interface or address error for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_CHANNEL_NAME); + return IpcChannelError(IpcChannelError::INVALID_CHANNEL_NAME); } case EFAULT: { std::cerr << "outside address space error for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_CHANNEL_NAME); + return IpcChannelError(IpcChannelError::INVALID_CHANNEL_NAME); } case ELOOP: { std::cerr << "too many symbolic links for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_CHANNEL_NAME); + return IpcChannelError(IpcChannelError::INVALID_CHANNEL_NAME); } case ENAMETOOLONG: { std::cerr << "name too long for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_CHANNEL_NAME); + return IpcChannelError(IpcChannelError::INVALID_CHANNEL_NAME); } case ENOTDIR: { std::cerr << "not a directory error for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_CHANNEL_NAME); + return IpcChannelError(IpcChannelError::INVALID_CHANNEL_NAME); } case ENOENT: { // no error message needed since this is a normal use case - return cxx::error(IpcChannelError::NO_SUCH_CHANNEL); + return IpcChannelError(IpcChannelError::NO_SUCH_CHANNEL); } case EROFS: { std::cerr << "read only error for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_CHANNEL_NAME); + return IpcChannelError(IpcChannelError::INVALID_CHANNEL_NAME); } case EIO: { std::cerr << "I/O for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::I_O_ERROR); + return IpcChannelError(IpcChannelError::I_O_ERROR); } case ENOPROTOOPT: { std::cerr << "invalid option for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::INVALID_ARGUMENTS); + return IpcChannelError(IpcChannelError::INVALID_ARGUMENTS); } case ECONNREFUSED: { std::cerr << "No server for unix domain socket \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::NO_SUCH_CHANNEL); + return IpcChannelError(IpcChannelError::NO_SUCH_CHANNEL); } case ECONNRESET: { std::cerr << "connection was reset by peer for \"" << m_name << "\"" << std::endl; - return cxx::error(IpcChannelError::CONNECTION_RESET_BY_PEER); + return IpcChannelError(IpcChannelError::CONNECTION_RESET_BY_PEER); } case EWOULDBLOCK: { // no error message needed since this is a normal use case - return cxx::error(IpcChannelError::TIMEOUT); + return IpcChannelError(IpcChannelError::TIMEOUT); } default: { std::cerr << "internal logic error in unix domain socket \"" << m_name << "\" occurred" << std::endl; - return cxx::error(IpcChannelError::INTERNAL_LOGIC_ERROR); + return IpcChannelError(IpcChannelError::INTERNAL_LOGIC_ERROR); } } } From f7df7a06238be6089ce5b09986b8bf392622d27d Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Fri, 12 Mar 2021 15:50:25 +0100 Subject: [PATCH 35/89] iox-#404 Address review findings: Add move c'tor/assign tests, remove param-less c'tor and don't run tests on Win and Mac Signed-off-by: Simon Hoinkis --- .../iceoryx_utils/posix_wrapper/file_lock.hpp | 13 ++--- .../include/iceoryx_utils/platform/fcntl.hpp | 3 + .../source/posix_wrapper/file_lock.cpp | 38 ++++++------- .../test/moduletests/test_posix_file_lock.cpp | 57 ++++++++++++++++--- 4 files changed, 74 insertions(+), 37 deletions(-) diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index 2a1e497f8c..9cc663a6dd 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -27,12 +27,11 @@ namespace posix enum class FileLockError { INVALID_STATE, - NOT_INITIALIZED, + NO_FILE_NAME_PROVIDED, LOCKED_BY_OTHER_PROCESS, ACCESS_DENIED, INVALID_FILE_NAME, FILE_EXISTS, - INTERRUPTED_BY_SIGNAL, QUOTA_EXHAUSTED, INVALID_ARGUMENTS, SYSTEM_LIMIT, @@ -68,12 +67,8 @@ class FileLock : public DesignPattern::Creation public: static constexpr int32_t ERROR_CODE = -1; static constexpr int32_t INVALID_FD = -1; - using FileName_t = cxx::string<30>; - using PathName_t = cxx::string<100>; - - /// @brief Default constructor which creates an invalid FileLock. Can be used to assign a value with the move - /// constructor - FileLock() noexcept; + using FileName_t = cxx::string<255>; + using PathName_t = cxx::string<1024>; FileLock(const FileLock&) = delete; FileLock& operator=(const FileLock&) = delete; @@ -88,7 +83,7 @@ class FileLock : public DesignPattern::Creation /// @brief c'tor /// @param[in] name of the created file lock in PATH_PREFIX - FileLock(FileName_t name) noexcept; + FileLock(const FileName_t& name) noexcept; cxx::expected initializeFileLock() noexcept; cxx::error createErrorFromErrnum(const int32_t errnum) const noexcept; diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp index dcfbf01f87..d311cc2b0a 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp @@ -17,6 +17,7 @@ #define IOX_UTILS_WIN_PLATFORM_FCNTL_HPP #include +#include #define O_CREAT _O_CREAT #define O_EXCL _O_EXCL @@ -28,6 +29,8 @@ #define O_WRONLY _O_WRONLY #define O_NONBLOCK 0x0 +using mode_t = uint32_t; + int openFile(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_WIN_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index b46a60e43e..5ce8a632fe 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -26,13 +26,7 @@ namespace iox { namespace posix { -FileLock::FileLock() noexcept -{ - this->m_isInitialized = false; - this->m_errorValue = FileLockError::NOT_INITIALIZED; -} - -FileLock::FileLock(FileName_t name) noexcept +FileLock::FileLock(const FileName_t& name) noexcept : m_name(name) { initializeFileLock().and_then([this]() { this->m_isInitialized = true; }).or_else([this](FileLockError& error) { @@ -43,12 +37,21 @@ FileLock::FileLock(FileName_t name) noexcept cxx::expected FileLock::initializeFileLock() noexcept { + if (m_name.empty()) + { + return cxx::error(FileLockError::NO_FILE_NAME_PROVIDED); + } PathName_t fullPath(PATH_PREFIX + m_name + ".lock"); - constexpr int oFlags = O_CREAT | O_RDWR; - mode_t mode = S_IRUSR | S_IWUSR; + constexpr int createFileForReadWrite = O_CREAT | O_RDWR; + mode_t userReadWriteAccess = S_IRUSR | S_IWUSR; - auto openCall = cxx::makeSmartC( - openFile, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, fullPath.c_str(), oFlags, mode); + auto openCall = cxx::makeSmartC(openFile, + cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, + {ERROR_CODE}, + {}, + fullPath.c_str(), + createFileForReadWrite, + userReadWriteAccess); if (openCall.hasErrors()) { @@ -73,11 +76,8 @@ cxx::expected FileLock::initializeFileLock() noexcept // possible errors in closeFileDescriptor() are masked and we inform the user about the actual error return cxx::error(FileLockError::LOCKED_BY_OTHER_PROCESS); } - else - { - return cxx::success<>(); - } } + return cxx::success<>(); } FileLock::FileLock(FileLock&& rhs) noexcept @@ -100,6 +100,7 @@ FileLock& FileLock::operator=(FileLock&& rhs) noexcept m_name = std::move(rhs.m_name); m_fd = std::move(rhs.m_fd); + rhs.m_name.assign(""); rhs.m_fd = INVALID_FD; } @@ -179,11 +180,6 @@ cxx::error FileLock::createErrorFromErrnum(const int32_t errnum) std::cerr << "overflow for file \"" << m_name << "\"" << std::endl; return cxx::error(FileLockError::INVALID_FILE_NAME); } - case EINTR: - { - std::cerr << "Interrupted by signal for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INTERRUPTED_BY_SIGNAL); - } case EINVAL: { std::cerr << "provided invalid arguments for file \"" << m_name << "\"" << std::endl; @@ -290,7 +286,7 @@ cxx::error FileLock::createErrorFromErrnum(const int32_t errnum) } default: { - std::cerr << "internal logic error in unix domain socket \"" << m_name << "\" occurred" << std::endl; + std::cerr << "internal logic error in file \"" << m_name << "\" occurred" << std::endl; return cxx::error(FileLockError::INTERNAL_LOGIC_ERROR); } } diff --git a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp index 50b4f3b701..9c429068cc 100644 --- a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp +++ b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp @@ -14,9 +14,12 @@ // // SPDX-License-Identifier: Apache-2.0 +#if !defined(_WIN32) && !defined(__APPLE__) +#include "iceoryx_utils/cxx/optional.hpp" #include "iceoryx_utils/posix_wrapper/file_lock.hpp" #include "test.hpp" + using namespace ::testing; using namespace iox::posix; using namespace iox::cxx; @@ -25,9 +28,9 @@ constexpr char TEST_NAME[] = "TestProcess"; constexpr char ANOTHER_TEST_NAME[] = "AnotherTestProcess"; /// @req -/// @brief This test suite verifies the behaviour of the class FileLock -/// @pre the file lock for TEST_NAME is acquired -/// @post None +/// @brief This test suite verifies the RAII behaviour of FileLock +/// @pre The file lock for TEST_NAME is acquired +/// @post The file lock for TEST_NAME is released /// @note This should become a FЯIDA integration test once available, in order to test with two processes class FileLock_test : public Test { @@ -38,21 +41,30 @@ class FileLock_test : public Test void SetUp() { - auto createResult = iox::posix::FileLock::create(TEST_NAME); - ASSERT_FALSE(createResult.has_error()); - m_sut = std::move(createResult.value()); + auto maybeFileLock = iox::posix::FileLock::create(TEST_NAME); + ASSERT_FALSE(maybeFileLock.has_error()); + m_sut.emplace(std::move(maybeFileLock.value())); + ASSERT_TRUE(m_sut.has_value()); } void TearDown() { + m_sut.reset(); } ~FileLock_test() { } - iox::posix::FileLock m_sut; + optional m_sut; }; +TEST_F(FileLock_test, EmptyNameLeadsToError) +{ + auto sut2 = iox::posix::FileLock::create(""); + ASSERT_TRUE(sut2.has_error()); + EXPECT_THAT(sut2.get_error(), Eq(FileLockError::NO_FILE_NAME_PROVIDED)); +} + TEST_F(FileLock_test, SecondLockWithDifferentNameWorks) { auto sut2 = iox::posix::FileLock::create(ANOTHER_TEST_NAME); @@ -74,3 +86,34 @@ TEST_F(FileLock_test, LockAndNoReleaseLeadsToError) ASSERT_TRUE(sut2.has_error()); EXPECT_THAT(sut2.get_error(), Eq(FileLockError::LOCKED_BY_OTHER_PROCESS)); } + +TEST_F(FileLock_test, MoveCtorInvalidatesRhs) +{ + auto movedSut{std::move(m_sut.value())}; + ASSERT_FALSE(m_sut.value().isInitialized()); + ASSERT_TRUE(movedSut.isInitialized()); +} + +TEST_F(FileLock_test, MoveCtorTransfersLock) +{ + auto movedSut{std::move(m_sut.value())}; + auto anotherLock = iox::posix::FileLock::create(TEST_NAME); + ASSERT_TRUE(anotherLock.has_error()); + EXPECT_THAT(anotherLock.get_error(), Eq(FileLockError::LOCKED_BY_OTHER_PROCESS)); +} + +TEST_F(FileLock_test, MoveAssignInvalidatesRhs) +{ + auto movedSut = std::move(m_sut.value()); + ASSERT_FALSE(m_sut.value().isInitialized()); + ASSERT_TRUE(movedSut.isInitialized()); +} + +TEST_F(FileLock_test, MoveAssignTransfersLock) +{ + auto movedSut = std::move(m_sut.value()); + auto anotherLock = iox::posix::FileLock::create(TEST_NAME); + ASSERT_TRUE(anotherLock.has_error()); + EXPECT_THAT(anotherLock.get_error(), Eq(FileLockError::LOCKED_BY_OTHER_PROCESS)); +} +#endif From 2ddbae30e0e9163e5a1c3612734b7fa85ba71bb8 Mon Sep 17 00:00:00 2001 From: "Hintz Martin (XC-AD/ESB5)" Date: Mon, 15 Mar 2021 15:13:34 +0100 Subject: [PATCH 36/89] iox-#609 Add generic QNX 7.0 toolchain files Signed-off-by: Hintz Martin (XC-AD/ESB5) --- .../toolchains/qnx/qnx_sdp70_aarch64le.cmake | 4 ++ tools/toolchains/qnx/qnx_sdp70_common.cmake | 60 +++++++++++++++++++ tools/toolchains/qnx/qnx_sdp70_x86_64.cmake | 4 ++ 3 files changed, 68 insertions(+) create mode 100644 tools/toolchains/qnx/qnx_sdp70_aarch64le.cmake create mode 100644 tools/toolchains/qnx/qnx_sdp70_common.cmake create mode 100644 tools/toolchains/qnx/qnx_sdp70_x86_64.cmake diff --git a/tools/toolchains/qnx/qnx_sdp70_aarch64le.cmake b/tools/toolchains/qnx/qnx_sdp70_aarch64le.cmake new file mode 100644 index 0000000000..07ee7dc1db --- /dev/null +++ b/tools/toolchains/qnx/qnx_sdp70_aarch64le.cmake @@ -0,0 +1,4 @@ +SET(CMAKE_SYSTEM_PROCESSOR aarch64) +SET(arch gcc_ntoaarch64le) + +include(${CMAKE_CURRENT_LIST_DIR}/qnx_sdp70_common.cmake) diff --git a/tools/toolchains/qnx/qnx_sdp70_common.cmake b/tools/toolchains/qnx/qnx_sdp70_common.cmake new file mode 100644 index 0000000000..cdfc07ffd2 --- /dev/null +++ b/tools/toolchains/qnx/qnx_sdp70_common.cmake @@ -0,0 +1,60 @@ +SET(CMAKE_SYSTEM_NAME QNX) +SET(TOOLCHAIN QNX) + +include(CMakeForceCompiler) +SET(CMAKE_SYSTEM_VERSION 7.0.0) + +SET(CMAKE_SHARED_LIBRARY_PREFIX "lib") +SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so") +SET(CMAKE_STATIC_LIBRARY_PREFIX "lib") +SET(CMAKE_STATIC_LIBRARY_SUFFIX ".a") + +if(NOT DEFINED ENV{QNX_HOST}) + message(FATAL_ERROR "Environment variable QNX_HOST not set!") +endif(NOT DEFINED ENV{QNX_HOST}) +if(NOT DEFINED ENV{QNX_TARGET}) + message(FATAL_ERROR "Environment variable QNX_TARGET not set!") +endif(NOT DEFINED ENV{QNX_TARGET}) + +SET(QNX_HOST "$ENV{QNX_HOST}") +SET(QNX_TARGET "$ENV{QNX_TARGET}") + +SET(CMAKE_MAKE_PROGRAM "${QNX_HOST}/usr/bin/make" CACHE PATH "QNX Make Program") +SET(CMAKE_SH "${QNX_HOST}/usr/bin/ksh" CACHE PATH "QNX shell Program") + +set(CMAKE_C_COMPILER "${QNX_HOST}/usr/bin/qcc") +set(CMAKE_C_COMPILER_TARGET ${arch}) +set(CMAKE_CXX_COMPILER "${QNX_HOST}/usr/bin/q++") +set(CMAKE_CXX_COMPILER_TARGET ${arch}) + +SET(CMAKE_STRIP "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-strip" CACHE PATH "strip") +SET(CMAKE_AR "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-ar" CACHE PATH "archive") +SET(CMAKE_LINKER "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-ld" CACHE PATH "linker") +SET(CMAKE_NM "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-nm" CACHE PATH "nm") +SET(CMAKE_OBJCOPY "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-objcopy" CACHE PATH "objcopy") +SET(CMAKE_OBJDUMP "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-objdump" CACHE PATH "objdump") +SET(CMAKE_RANLIB "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-ranlib" CACHE PATH "ranlib") + +SET(CMAKE_C_FLAGS_DEBUG "-g -O0 -fno-builtin") +SET(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") + +SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -fno-builtin") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") + +SET(CMAKE_FIND_ROOT_PATH ${QNX_TARGET}) +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +add_compile_options("-D_QNX_SOURCE=1") + +# QNX 7 ships with QCC 5.4.0 (based on GCC). Cmake cannot detect the compiler features, +# so they're added manually. The correct detection can be done if you set as cross-compiler +# SET(CMAKE_CXX_COMPILER ${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-c++) +# The file with the detected compile features is then in the build directory named CMakeCXXCompiler.cmake +# A similar bug was reported for Android, see: https://bugreports.qt.io/browse/QTBUG-54666 + +set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17") +set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters") +set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates") +set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates") diff --git a/tools/toolchains/qnx/qnx_sdp70_x86_64.cmake b/tools/toolchains/qnx/qnx_sdp70_x86_64.cmake new file mode 100644 index 0000000000..6ca24e37fb --- /dev/null +++ b/tools/toolchains/qnx/qnx_sdp70_x86_64.cmake @@ -0,0 +1,4 @@ +SET(CMAKE_SYSTEM_PROCESSOR x86_64) +SET(arch gcc_ntox86_64) + +include(${CMAKE_CURRENT_LIST_DIR}/qnx_sdp70_common.cmake) From 815a867923643ccba8224caea737576a6d2224f9 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Mon, 15 Mar 2021 16:44:11 +0100 Subject: [PATCH 37/89] iox-#404 Address reviewing findings adding copyright header, use 'iox_*' prefix and combine EFBIG and EOVERFLOW Signed-off-by: Simon Hoinkis --- .../linux/include/iceoryx_utils/platform/fcntl.hpp | 3 ++- .../linux/include/iceoryx_utils/platform/unistd.hpp | 2 +- iceoryx_utils/platform/linux/source/fnctl.cpp | 4 ++-- iceoryx_utils/platform/linux/source/unistd.cpp | 2 +- .../mac/include/iceoryx_utils/platform/fcntl.hpp | 3 ++- .../mac/include/iceoryx_utils/platform/unistd.hpp | 2 +- iceoryx_utils/platform/mac/source/fnctl.cpp | 4 ++-- iceoryx_utils/platform/mac/source/unistd.cpp | 2 +- .../qnx/include/iceoryx_utils/platform/fcntl.hpp | 3 ++- .../qnx/include/iceoryx_utils/platform/unistd.hpp | 2 +- iceoryx_utils/platform/qnx/source/fnctl.cpp | 4 ++-- iceoryx_utils/platform/qnx/source/unistd.cpp | 2 +- .../win/include/iceoryx_utils/platform/fcntl.hpp | 3 ++- .../win/include/iceoryx_utils/platform/unistd.hpp | 2 +- iceoryx_utils/platform/win/source/fnctl.cpp | 4 ++-- iceoryx_utils/platform/win/source/unistd.cpp | 2 +- iceoryx_utils/source/posix_wrapper/file_lock.cpp | 12 ++++-------- 17 files changed, 28 insertions(+), 28 deletions(-) diff --git a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp index 6ca4b044d0..e7083f2649 100644 --- a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/fcntl.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -18,6 +19,6 @@ #include -int openFile(const char* pathname, int flags, mode_t mode); +int iox_open(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_LINUX_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/unistd.hpp index 80cef873b7..05b5f37062 100644 --- a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/unistd.hpp @@ -18,6 +18,6 @@ #include -int closePlatformFileHandle(int fd); +int iox_close(int fd); #endif // IOX_UTILS_LINUX_PLATFORM_UNISTD_HPP diff --git a/iceoryx_utils/platform/linux/source/fnctl.cpp b/iceoryx_utils/platform/linux/source/fnctl.cpp index 5147857789..40544ce630 100644 --- a/iceoryx_utils/platform/linux/source/fnctl.cpp +++ b/iceoryx_utils/platform/linux/source/fnctl.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 by Apex.AI. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/fcntl.hpp" -int openFile(const char* pathname, int flags, mode_t mode) +int iox_open(const char* pathname, int flags, mode_t mode) { return open(pathname, flags, mode); } diff --git a/iceoryx_utils/platform/linux/source/unistd.cpp b/iceoryx_utils/platform/linux/source/unistd.cpp index 5962d0f036..c56410e5eb 100644 --- a/iceoryx_utils/platform/linux/source/unistd.cpp +++ b/iceoryx_utils/platform/linux/source/unistd.cpp @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/unistd.hpp" -int closePlatformFileHandle(int fd) +int iox_close(int fd) { return close(fd); } \ No newline at end of file diff --git a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp index d3939b044e..b22e015a1f 100644 --- a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/fcntl.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -18,6 +19,6 @@ #include -int openFile(const char* pathname, int flags, mode_t mode); +int iox_open(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_MAC_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/unistd.hpp index 65c34e6ff4..7fd84ce403 100644 --- a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/unistd.hpp @@ -18,6 +18,6 @@ #include -int closePlatformFileHandle(int fd); +int iox_close(int fd); #endif // IOX_UTILS_MAC_PLATFORM_UNISTD_HPP diff --git a/iceoryx_utils/platform/mac/source/fnctl.cpp b/iceoryx_utils/platform/mac/source/fnctl.cpp index 5147857789..40544ce630 100644 --- a/iceoryx_utils/platform/mac/source/fnctl.cpp +++ b/iceoryx_utils/platform/mac/source/fnctl.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 by Apex.AI. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/fcntl.hpp" -int openFile(const char* pathname, int flags, mode_t mode) +int iox_open(const char* pathname, int flags, mode_t mode) { return open(pathname, flags, mode); } diff --git a/iceoryx_utils/platform/mac/source/unistd.cpp b/iceoryx_utils/platform/mac/source/unistd.cpp index 804bdbd7a5..5ccfdf04a3 100644 --- a/iceoryx_utils/platform/mac/source/unistd.cpp +++ b/iceoryx_utils/platform/mac/source/unistd.cpp @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/unistd.hpp" -int closePlatformFileHandle(int fd) +int iox_close(int fd) { return close(fd); } diff --git a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp index 4f0ecab80d..6590ae231c 100644 --- a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/fcntl.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -18,6 +19,6 @@ #include -int openFile(const char* pathname, int flags, mode_t mode); +int iox_open(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_QNX_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/unistd.hpp index 031d32a990..6807412570 100644 --- a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/unistd.hpp @@ -18,6 +18,6 @@ #include -int closePlatformFileHandle(int fd); +int iox_close(int fd); #endif // IOX_UTILS_QNX_PLATFORM_UNISTD_HPP diff --git a/iceoryx_utils/platform/qnx/source/fnctl.cpp b/iceoryx_utils/platform/qnx/source/fnctl.cpp index 5147857789..40544ce630 100644 --- a/iceoryx_utils/platform/qnx/source/fnctl.cpp +++ b/iceoryx_utils/platform/qnx/source/fnctl.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 by Apex.AI. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/fcntl.hpp" -int openFile(const char* pathname, int flags, mode_t mode) +int iox_open(const char* pathname, int flags, mode_t mode) { return open(pathname, flags, mode); } diff --git a/iceoryx_utils/platform/qnx/source/unistd.cpp b/iceoryx_utils/platform/qnx/source/unistd.cpp index 804bdbd7a5..5ccfdf04a3 100644 --- a/iceoryx_utils/platform/qnx/source/unistd.cpp +++ b/iceoryx_utils/platform/qnx/source/unistd.cpp @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/unistd.hpp" -int closePlatformFileHandle(int fd) +int iox_close(int fd) { return close(fd); } diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp index d311cc2b0a..1f4793be7d 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -31,6 +32,6 @@ using mode_t = uint32_t; -int openFile(const char* pathname, int flags, mode_t mode); +int iox_open(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_WIN_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp index 780f38696e..ba6b813005 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp @@ -44,6 +44,6 @@ class HandleTranslator int ftruncate(int fildes, off_t length); long sysconf(int name); -int closePlatformFileHandle(int fd); +int iox_close(int fd); #endif // IOX_UTILS_WIN_PLATFORM_UNISTD_HPP diff --git a/iceoryx_utils/platform/win/source/fnctl.cpp b/iceoryx_utils/platform/win/source/fnctl.cpp index 8b8744dd04..c9c618359b 100644 --- a/iceoryx_utils/platform/win/source/fnctl.cpp +++ b/iceoryx_utils/platform/win/source/fnctl.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 by Apex.AI. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -16,7 +16,7 @@ #include "iceoryx_utils/platform/fcntl.hpp" -int openFile(const char* pathname, int flags, mode_t mode) +int iox_open(const char* pathname, int flags, mode_t mode) { return 0; } diff --git a/iceoryx_utils/platform/win/source/unistd.cpp b/iceoryx_utils/platform/win/source/unistd.cpp index 7bdd411283..66c8290865 100644 --- a/iceoryx_utils/platform/win/source/unistd.cpp +++ b/iceoryx_utils/platform/win/source/unistd.cpp @@ -58,7 +58,7 @@ long sysconf(int name) return 0; } -int closePlatformFileHandle(int fd) +int iox_close(int fd) { auto success = Win32Call(CloseHandle(HandleTranslator::getInstance().get(fd))); HandleTranslator::getInstance().remove(fd); diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index 5ce8a632fe..cb143c9467 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -176,9 +176,11 @@ cxx::error FileLock::createErrorFromErrnum(const int32_t errnum) return cxx::error(FileLockError::ACCESS_DENIED); } case EFBIG: + case EOVERFLOW: { - std::cerr << "overflow for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_FILE_NAME); + std::cerr << "file \"" << m_name << "\"" + << " is too large to be openend" << std::endl; + return cxx::error(FileLockError::FILE_TOO_LARGE); } case EINVAL: { @@ -247,12 +249,6 @@ cxx::error FileLock::createErrorFromErrnum(const int32_t errnum) std::cerr << "filesystem does not support O_TMPFILE for file \"" << m_name << "\"" << std::endl; return cxx::error(FileLockError::TEMP_FILE_NOT_SUPPORTED); } - case EOVERFLOW: - { - std::cerr << "file \"" << m_name << "\"" - << " is too large to be openend" << std::endl; - return cxx::error(FileLockError::FILE_TOO_LARGE); - } case EPERM: { std::cerr << "permission to access file denied \"" << m_name << "\"" << std::endl; From 80f5fafc2f671b438f63060aa21e47eb7404a256 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Mon, 15 Mar 2021 16:55:51 +0100 Subject: [PATCH 38/89] iox-#404 Address reviewing findings replacing createErrorFromErrnum with convertErrnoToFileLockError Signed-off-by: Simon Hoinkis --- iceoryx_examples/iceperf/uds.cpp | 4 +- iceoryx_posh/source/roudi/roudi_lock.cpp | 2 +- .../iceoryx_utils/posix_wrapper/file_lock.hpp | 2 +- .../source/posix_wrapper/file_lock.cpp | 65 +++++++++---------- .../shared_memory_object/shared_memory.cpp | 2 +- .../posix_wrapper/unix_domain_socket.cpp | 2 +- 6 files changed, 38 insertions(+), 39 deletions(-) diff --git a/iceoryx_examples/iceperf/uds.cpp b/iceoryx_examples/iceperf/uds.cpp index cc8a04c354..1d0523a930 100644 --- a/iceoryx_examples/iceperf/uds.cpp +++ b/iceoryx_examples/iceperf/uds.cpp @@ -111,7 +111,7 @@ void UDS::shutdown() noexcept if (m_sockfdPublisher != INVALID_FD) { auto closeCall = iox::cxx::makeSmartC( - closePlatformFileHandle, iox::cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_sockfdPublisher); + iox_close, iox::cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_sockfdPublisher); if (closeCall.hasErrors()) { @@ -122,7 +122,7 @@ void UDS::shutdown() noexcept if (m_sockfdSubscriber != INVALID_FD) { - auto closeCall = iox::cxx::makeSmartC(closePlatformFileHandle, + auto closeCall = iox::cxx::makeSmartC(iox_close, iox::cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, diff --git a/iceoryx_posh/source/roudi/roudi_lock.cpp b/iceoryx_posh/source/roudi/roudi_lock.cpp index 776175cdec..04a6f3903c 100644 --- a/iceoryx_posh/source/roudi/roudi_lock.cpp +++ b/iceoryx_posh/source/roudi/roudi_lock.cpp @@ -51,7 +51,7 @@ RouDiLock::~RouDiLock() { // Close socket auto l_socket_close = - cxx::makeSmartC(closePlatformFileHandle, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {-1}, {}, m_socket_fd); + cxx::makeSmartC(iox_close, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {-1}, {}, m_socket_fd); if (l_socket_close.hasErrors()) { diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index 9cc663a6dd..b662d37ad3 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -86,7 +86,7 @@ class FileLock : public DesignPattern::Creation FileLock(const FileName_t& name) noexcept; cxx::expected initializeFileLock() noexcept; - cxx::error createErrorFromErrnum(const int32_t errnum) const noexcept; + FileLockError convertErrnoToFileLockError(const int32_t errnum) const noexcept; cxx::expected closeFileDescriptor() noexcept; cxx::expected destroy() noexcept; diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index cb143c9467..4177ec544b 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -45,7 +45,7 @@ cxx::expected FileLock::initializeFileLock() noexcept constexpr int createFileForReadWrite = O_CREAT | O_RDWR; mode_t userReadWriteAccess = S_IRUSR | S_IWUSR; - auto openCall = cxx::makeSmartC(openFile, + auto openCall = cxx::makeSmartC(iox_open, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, @@ -55,7 +55,7 @@ cxx::expected FileLock::initializeFileLock() noexcept if (openCall.hasErrors()) { - return createErrorFromErrnum(openCall.getErrNum()); + return cxx::error(convertErrnoToFileLockError(openCall.getErrNum())); } else { @@ -68,7 +68,7 @@ cxx::expected FileLock::initializeFileLock() noexcept { closeFileDescriptor(); // possible errors in closeFileDescriptor() are masked and we inform the user about the actual error - return createErrorFromErrnum(openCall.getErrNum()); + return cxx::error(convertErrnoToFileLockError(openCall.getErrNum())); } else if (lockCall.getErrNum() == EWOULDBLOCK) { @@ -126,8 +126,7 @@ cxx::expected FileLock::closeFileDescriptor() noexcept { if (m_fd != INVALID_FD) { - auto closeCall = - cxx::makeSmartC(closePlatformFileHandle, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_fd); + auto closeCall = cxx::makeSmartC(iox_close, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_fd); if (!closeCall.hasErrors()) { @@ -138,152 +137,152 @@ cxx::expected FileLock::closeFileDescriptor() noexcept } else { - return createErrorFromErrnum(closeCall.getErrNum()); + return cxx::error(convertErrnoToFileLockError(closeCall.getErrNum())); } } return cxx::success<>(); } -cxx::error FileLock::createErrorFromErrnum(const int32_t errnum) const noexcept +FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const noexcept { switch (errnum) { case EACCES: { std::cerr << "permission to access file denied \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::ACCESS_DENIED); + return FileLockError::ACCESS_DENIED; } case EBUSY: { std::cerr << "O_EXCL provided but file \"" << m_name << "\"" << " is currently used" << std::endl; - return cxx::error(FileLockError::FILE_IN_USE); + return FileLockError::FILE_IN_USE; } case EDQUOT: { std::cerr << "user disk quota exhausted for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::QUOTA_EXHAUSTED); + return FileLockError::QUOTA_EXHAUSTED; } case EEXIST: { std::cerr << "file \"" << m_name << "\"" << " already exists" << std::endl; - return cxx::error(FileLockError::FILE_EXISTS); + return FileLockError::FILE_EXISTS; } case EFAULT: { std::cerr << "outside address space error for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::ACCESS_DENIED); + return FileLockError::ACCESS_DENIED; } case EFBIG: case EOVERFLOW: { std::cerr << "file \"" << m_name << "\"" << " is too large to be openend" << std::endl; - return cxx::error(FileLockError::FILE_TOO_LARGE); + return FileLockError::FILE_TOO_LARGE; } case EINVAL: { std::cerr << "provided invalid arguments for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_ARGUMENTS); + return FileLockError::INVALID_ARGUMENTS; } case EISDIR: { std::cerr << "write access requested for directory \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_ARGUMENTS); + return FileLockError::INVALID_ARGUMENTS; } case ELOOP: { std::cerr << "too many symbolic links for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_FILE_NAME); + return FileLockError::INVALID_FILE_NAME; } case EMFILE: { std::cerr << "process limit reached for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::PROCESS_LIMIT); + return FileLockError::PROCESS_LIMIT; } case ENAMETOOLONG: { std::cerr << "name too long for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_FILE_NAME); + return FileLockError::INVALID_FILE_NAME; } case ENFILE: { std::cerr << "system limit reached for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::SYSTEM_LIMIT); + return FileLockError::SYSTEM_LIMIT; } case ENODEV: { std::cerr << "permission to access file denied \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::ACCESS_DENIED); + return FileLockError::ACCESS_DENIED; } case ENOENT: { std::cerr << "file \"" << m_name << "\"" << "does not exist" << std::endl; - return cxx::error(FileLockError::NO_SUCH_FILE); + return FileLockError::NO_SUCH_FILE; } case ENOMEM: { std::cerr << "out of memory for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::OUT_OF_MEMORY); + return FileLockError::OUT_OF_MEMORY; } case ENOSPC: { std::cerr << "Device has no space for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::QUOTA_EXHAUSTED); + return FileLockError::QUOTA_EXHAUSTED; } case ENOTDIR: { std::cerr << "not a directory error for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_FILE_NAME); + return FileLockError::INVALID_FILE_NAME; } case ENXIO: { std::cerr << "\"" << m_name << "\"" << " is a special file and no corresponding device exists" << std::endl; - return cxx::error(FileLockError::SPECIAL_FILE); + return FileLockError::SPECIAL_FILE; } case EOPNOTSUPP: { std::cerr << "filesystem does not support O_TMPFILE for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::TEMP_FILE_NOT_SUPPORTED); + return FileLockError::TEMP_FILE_NOT_SUPPORTED; } case EPERM: { std::cerr << "permission to access file denied \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::ACCESS_DENIED); + return FileLockError::ACCESS_DENIED; } case EBADF: { std::cerr << "invalid file descriptor for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_FILE_DESCRIPTOR); + return FileLockError::INVALID_FILE_DESCRIPTOR; } case EROFS: { std::cerr << "read only error for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::INVALID_FILE_NAME); + return FileLockError::INVALID_FILE_NAME; } case ETXTBSY: { std::cerr << "write access requested for file \"" << m_name << "\"" << " in use" << std::endl; - return cxx::error(FileLockError::FILE_IN_USE); + return FileLockError::FILE_IN_USE; } case EWOULDBLOCK: { // no error message needed since this is a normal use case - return cxx::error(FileLockError::LOCKED_BY_OTHER_PROCESS); + return FileLockError::LOCKED_BY_OTHER_PROCESS; } case ENOLCK: { std::cerr << "system limit for locks reached for file \"" << m_name << "\"" << std::endl; - return cxx::error(FileLockError::SYSTEM_LIMIT); + return FileLockError::SYSTEM_LIMIT; } default: { std::cerr << "internal logic error in file \"" << m_name << "\" occurred" << std::endl; - return cxx::error(FileLockError::INTERNAL_LOGIC_ERROR); + return FileLockError::INTERNAL_LOGIC_ERROR; } } } diff --git a/iceoryx_utils/source/posix_wrapper/shared_memory_object/shared_memory.cpp b/iceoryx_utils/source/posix_wrapper/shared_memory_object/shared_memory.cpp index 5e1ab854c5..cf0f3be481 100644 --- a/iceoryx_utils/source/posix_wrapper/shared_memory_object/shared_memory.cpp +++ b/iceoryx_utils/source/posix_wrapper/shared_memory_object/shared_memory.cpp @@ -191,7 +191,7 @@ bool SharedMemory::close() noexcept if (m_isInitialized) { auto closeCall = - cxx::makeSmartC(closePlatformFileHandle, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {-1}, {}, m_handle); + cxx::makeSmartC(iox_close, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {-1}, {}, m_handle); m_handle = -1; if (closeCall.hasErrors()) { diff --git a/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp b/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp index 59b842b47a..091682d988 100644 --- a/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp +++ b/iceoryx_utils/source/posix_wrapper/unix_domain_socket.cpp @@ -162,7 +162,7 @@ cxx::expected UnixDomainSocket::closeFileDescriptor() noexcept if (m_sockfd != INVALID_FD) { auto closeCall = cxx::makeSmartC( - closePlatformFileHandle, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_sockfd); + iox_close, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_sockfd); if (!closeCall.hasErrors()) { From 42e278baaef21890d77a96dc8f421550fea39ea7 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Mon, 15 Mar 2021 17:28:31 +0100 Subject: [PATCH 39/89] iox-#404 Address reviewing findings removing unreachable errors and destroy() Signed-off-by: Simon Hoinkis --- .../iceoryx_utils/posix_wrapper/file_lock.hpp | 2 +- .../source/posix_wrapper/file_lock.cpp | 43 +++++-------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index b662d37ad3..7926c21da6 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -43,6 +43,7 @@ enum class FileLockError FILE_IN_USE, INVALID_FILE_DESCRIPTOR, OUT_OF_MEMORY, + I_O_ERROR, INTERNAL_LOGIC_ERROR, }; @@ -88,7 +89,6 @@ class FileLock : public DesignPattern::Creation cxx::expected initializeFileLock() noexcept; FileLockError convertErrnoToFileLockError(const int32_t errnum) const noexcept; cxx::expected closeFileDescriptor() noexcept; - cxx::expected destroy() noexcept; friend class DesignPattern::Creation; }; diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index 4177ec544b..ce43c470a7 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -89,7 +89,7 @@ FileLock& FileLock::operator=(FileLock&& rhs) noexcept { if (this != &rhs) { - if (destroy().has_error()) + if (closeFileDescriptor().has_error()) { std::cerr << "Unable to cleanup file lock \"" << m_name << "\" in the move constructor/move assingment operator" << std::endl; @@ -107,24 +107,17 @@ FileLock& FileLock::operator=(FileLock&& rhs) noexcept return *this; } -cxx::expected FileLock::destroy() noexcept +FileLock::~FileLock() noexcept { - if (m_isInitialized) + if (closeFileDescriptor().has_error()) { - return closeFileDescriptor(); + std::cerr << "unable to cleanup file lock \"" << m_name << "\" in the destructor" << std::endl; } - - return cxx::success(); -} - -FileLock::~FileLock() noexcept -{ - closeFileDescriptor(); } cxx::expected FileLock::closeFileDescriptor() noexcept { - if (m_fd != INVALID_FD) + if (isInitialized() && (m_fd != INVALID_FD)) { auto closeCall = cxx::makeSmartC(iox_close, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_fd); @@ -152,12 +145,6 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const std::cerr << "permission to access file denied \"" << m_name << "\"" << std::endl; return FileLockError::ACCESS_DENIED; } - case EBUSY: - { - std::cerr << "O_EXCL provided but file \"" << m_name << "\"" - << " is currently used" << std::endl; - return FileLockError::FILE_IN_USE; - } case EDQUOT: { std::cerr << "user disk quota exhausted for file \"" << m_name << "\"" << std::endl; @@ -201,11 +188,6 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const std::cerr << "process limit reached for file \"" << m_name << "\"" << std::endl; return FileLockError::PROCESS_LIMIT; } - case ENAMETOOLONG: - { - std::cerr << "name too long for file \"" << m_name << "\"" << std::endl; - return FileLockError::INVALID_FILE_NAME; - } case ENFILE: { std::cerr << "system limit reached for file \"" << m_name << "\"" << std::endl; @@ -243,21 +225,11 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const << " is a special file and no corresponding device exists" << std::endl; return FileLockError::SPECIAL_FILE; } - case EOPNOTSUPP: - { - std::cerr << "filesystem does not support O_TMPFILE for file \"" << m_name << "\"" << std::endl; - return FileLockError::TEMP_FILE_NOT_SUPPORTED; - } case EPERM: { std::cerr << "permission to access file denied \"" << m_name << "\"" << std::endl; return FileLockError::ACCESS_DENIED; } - case EBADF: - { - std::cerr << "invalid file descriptor for file \"" << m_name << "\"" << std::endl; - return FileLockError::INVALID_FILE_DESCRIPTOR; - } case EROFS: { std::cerr << "read only error for file \"" << m_name << "\"" << std::endl; @@ -279,6 +251,11 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const std::cerr << "system limit for locks reached for file \"" << m_name << "\"" << std::endl; return FileLockError::SYSTEM_LIMIT; } + case EIO: + { + std::cerr << "I/O for file \"" << m_name << "\"" << std::endl; + return FileLockError::I_O_ERROR; + } default: { std::cerr << "internal logic error in file \"" << m_name << "\" occurred" << std::endl; From a77301ac390992446309f8dd5e0d14eaffe6e254 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Mon, 15 Mar 2021 17:28:55 +0100 Subject: [PATCH 40/89] iox-#404 Try to fix windows build Signed-off-by: Simon Hoinkis --- .../platform/win/include/iceoryx_utils/platform/fcntl.hpp | 3 --- .../platform/win/include/iceoryx_utils/platform/types.hpp | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp index 1f4793be7d..5dd6ef3f5a 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp @@ -18,7 +18,6 @@ #define IOX_UTILS_WIN_PLATFORM_FCNTL_HPP #include -#include #define O_CREAT _O_CREAT #define O_EXCL _O_EXCL @@ -30,8 +29,6 @@ #define O_WRONLY _O_WRONLY #define O_NONBLOCK 0x0 -using mode_t = uint32_t; - int iox_open(const char* pathname, int flags, mode_t mode); #endif // IOX_UTILS_WIN_PLATFORM_FCNTL_HPP diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp index 13e5608431..23c3fbc8f3 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp @@ -17,10 +17,11 @@ #define IOX_UTILS_WIN_PLATFORM_TYPES_HPP #include +#include using gid_t = int; using uid_t = int; -using mode_t = int; +using mode_t = uint32_t; using ssize_t = size_t; using pid_t = int; using nlink_t = int; From 0115ab7bd1c8b3152d2666fd4d886cffb82838bc Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Mon, 15 Mar 2021 18:13:56 +0100 Subject: [PATCH 41/89] iox-#404 Try to fix Windows build and add new test case Signed-off-by: Simon Hoinkis --- .../include/iceoryx_utils/posix_wrapper/file_lock.hpp | 2 +- .../win/include/iceoryx_utils/platform/types.hpp | 2 +- .../test/moduletests/test_posix_file_lock.cpp | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index 7926c21da6..d11546b1de 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -68,7 +68,7 @@ class FileLock : public DesignPattern::Creation public: static constexpr int32_t ERROR_CODE = -1; static constexpr int32_t INVALID_FD = -1; - using FileName_t = cxx::string<255>; + using FileName_t = cxx::string<250>; using PathName_t = cxx::string<1024>; FileLock(const FileLock&) = delete; diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp index 23c3fbc8f3..cb8e0e6d0a 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp @@ -21,7 +21,7 @@ using gid_t = int; using uid_t = int; -using mode_t = uint32_t; +using mode_t = int; using ssize_t = size_t; using pid_t = int; using nlink_t = int; diff --git a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp index 9c429068cc..705b9340e9 100644 --- a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp +++ b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp @@ -65,6 +65,16 @@ TEST_F(FileLock_test, EmptyNameLeadsToError) EXPECT_THAT(sut2.get_error(), Eq(FileLockError::NO_FILE_NAME_PROVIDED)); } +TEST_F(FileLock_test, MaxStringWorks) +{ + FileLock::FileName_t maxString{ + "OeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPalo" + "emaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlanc" + "aOeLaPaloemaBlancaOeLaPaloemaB"}; + auto sut2 = iox::posix::FileLock::create(maxString); + ASSERT_FALSE(sut2.has_error()); +} + TEST_F(FileLock_test, SecondLockWithDifferentNameWorks) { auto sut2 = iox::posix::FileLock::create(ANOTHER_TEST_NAME); From 1c62504c6ab2cb0c1056bfc23eb41ce5e6e2cd41 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Mon, 15 Mar 2021 18:31:45 +0100 Subject: [PATCH 42/89] iox-#404 Another try.. Signed-off-by: Simon Hoinkis --- iceoryx_utils/platform/linux/source/unistd.cpp | 2 +- .../platform/win/include/iceoryx_utils/platform/types.hpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/iceoryx_utils/platform/linux/source/unistd.cpp b/iceoryx_utils/platform/linux/source/unistd.cpp index c56410e5eb..5ccfdf04a3 100644 --- a/iceoryx_utils/platform/linux/source/unistd.cpp +++ b/iceoryx_utils/platform/linux/source/unistd.cpp @@ -19,4 +19,4 @@ int iox_close(int fd) { return close(fd); -} \ No newline at end of file +} diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp index cb8e0e6d0a..411357dff1 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp @@ -17,11 +17,9 @@ #define IOX_UTILS_WIN_PLATFORM_TYPES_HPP #include -#include using gid_t = int; using uid_t = int; -using mode_t = int; using ssize_t = size_t; using pid_t = int; using nlink_t = int; From 93f9c7bb06fee6117298f04ebcbf3bbe15e85f8c Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Mon, 15 Mar 2021 18:58:27 +0100 Subject: [PATCH 43/89] iox-#404 Try again to fix Windows Signed-off-by: Simon Hoinkis --- .../platform/win/include/iceoryx_utils/platform/fcntl.hpp | 2 ++ .../platform/win/include/iceoryx_utils/platform/types.hpp | 1 + 2 files changed, 3 insertions(+) diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp index 5dd6ef3f5a..b8c96ed671 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/fcntl.hpp @@ -17,6 +17,8 @@ #ifndef IOX_UTILS_WIN_PLATFORM_FCNTL_HPP #define IOX_UTILS_WIN_PLATFORM_FCNTL_HPP +#include "iceoryx_utils/platform/types.hpp" + #include #define O_CREAT _O_CREAT diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp index 411357dff1..13e5608431 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/types.hpp @@ -20,6 +20,7 @@ using gid_t = int; using uid_t = int; +using mode_t = int; using ssize_t = size_t; using pid_t = int; using nlink_t = int; From 4b21627f59b707eb4f0dae6ab4f0c89f8bc374df Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Mon, 15 Mar 2021 19:17:23 +0100 Subject: [PATCH 44/89] iox-#404 Add 'iox_*' prefix for flock Signed-off-by: Simon Hoinkis --- .../include/iceoryx_utils/platform/file.hpp | 2 ++ iceoryx_utils/platform/linux/source/file.cpp | 22 +++++++++++++++++++ .../include/iceoryx_utils/platform/file.hpp | 2 ++ iceoryx_utils/platform/mac/source/file.cpp | 22 +++++++++++++++++++ .../include/iceoryx_utils/platform/file.hpp | 2 ++ iceoryx_utils/platform/qnx/source/file.cpp | 22 +++++++++++++++++++ .../include/iceoryx_utils/platform/file.hpp | 1 + iceoryx_utils/platform/win/source/file.cpp | 22 +++++++++++++++++++ .../source/posix_wrapper/file_lock.cpp | 5 ++--- 9 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 iceoryx_utils/platform/linux/source/file.cpp create mode 100644 iceoryx_utils/platform/mac/source/file.cpp create mode 100644 iceoryx_utils/platform/qnx/source/file.cpp create mode 100644 iceoryx_utils/platform/win/source/file.cpp diff --git a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/file.hpp b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/file.hpp index 46c2ba5353..f8c27cfe13 100644 --- a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/file.hpp +++ b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/file.hpp @@ -18,4 +18,6 @@ #include +int iox_flock(int fd, int op); + #endif // IOX_UTILS_LINUX_PLATFORM_FILE_HPP diff --git a/iceoryx_utils/platform/linux/source/file.cpp b/iceoryx_utils/platform/linux/source/file.cpp new file mode 100644 index 0000000000..73416b0256 --- /dev/null +++ b/iceoryx_utils/platform/linux/source/file.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/platform/file.hpp" + +int iox_flock(int fd, int op) +{ + return flock(fd, op); +} diff --git a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/file.hpp b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/file.hpp index 8cb07240e1..1a4d061d65 100644 --- a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/file.hpp +++ b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/file.hpp @@ -18,4 +18,6 @@ #include +int iox_flock(int fd, int op); + #endif // IOX_UTILS_MAC_PLATFORM_FILE_HPP diff --git a/iceoryx_utils/platform/mac/source/file.cpp b/iceoryx_utils/platform/mac/source/file.cpp new file mode 100644 index 0000000000..73416b0256 --- /dev/null +++ b/iceoryx_utils/platform/mac/source/file.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/platform/file.hpp" + +int iox_flock(int fd, int op) +{ + return flock(fd, op); +} diff --git a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/file.hpp b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/file.hpp index 45a288db8b..0d72c96b10 100644 --- a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/file.hpp +++ b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/file.hpp @@ -18,4 +18,6 @@ #include +int iox_flock(int fd, int op); + #endif // IOX_UTILS_QNX_PLATFORM_FILE_HPP diff --git a/iceoryx_utils/platform/qnx/source/file.cpp b/iceoryx_utils/platform/qnx/source/file.cpp new file mode 100644 index 0000000000..73416b0256 --- /dev/null +++ b/iceoryx_utils/platform/qnx/source/file.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/platform/file.hpp" + +int iox_flock(int fd, int op) +{ + return flock(fd, op); +} diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp index f22649831a..9960742b49 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp @@ -16,5 +16,6 @@ #ifndef IOX_UTILS_WIN_PLATFORM_FILE_HPP #define IOX_UTILS_WIN_PLATFORM_FILE_HPP +int iox_flock(int fd, int op); #endif // IOX_UTILS_WIN_PLATFORM_FILE_HPP diff --git a/iceoryx_utils/platform/win/source/file.cpp b/iceoryx_utils/platform/win/source/file.cpp new file mode 100644 index 0000000000..e61fa8122f --- /dev/null +++ b/iceoryx_utils/platform/win/source/file.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +#include "iceoryx_utils/platform/file.hpp" + +int iox_flock(int fd, int op) +{ + return 0; +} diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index ce43c470a7..b0ca7a0919 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -17,11 +17,10 @@ #include "iceoryx_utils/posix_wrapper/file_lock.hpp" #include "iceoryx_utils/cxx/smart_c.hpp" #include "iceoryx_utils/platform/fcntl.hpp" +#include "iceoryx_utils/platform/file.hpp" #include "iceoryx_utils/platform/platform_correction.hpp" #include "iceoryx_utils/platform/unistd.hpp" -#include - namespace iox { namespace posix @@ -62,7 +61,7 @@ cxx::expected FileLock::initializeFileLock() noexcept m_fd = openCall.getReturnValue(); auto lockCall = cxx::makeSmartC( - flock, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {EWOULDBLOCK}, m_fd, LOCK_EX | LOCK_NB); + iox_flock, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {EWOULDBLOCK}, m_fd, LOCK_EX | LOCK_NB); if (lockCall.hasErrors()) { From ce061b6eb5b0b9e3dc475edafb530a464e87c718 Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Thu, 11 Mar 2021 18:11:40 +0530 Subject: [PATCH 45/89] iox-#496 added U postfix for unsigned number and used concrete values over default Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test_posh_runtime_single_process.cpp | 2 +- .../test/moduletests/test_roudi_portpool.cpp | 77 ++++++++++++------- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp b/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp index 1a760f6b2f..5f5c846e71 100644 --- a/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp +++ b/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp @@ -47,7 +47,7 @@ class PoshRuntimeSingleProcess_test : public Test TEST_F(PoshRuntimeSingleProcess_test, ConstructorPoshRuntimeSingleProcessIsSuccess) { - iox::RouDiConfig_t defaultRouDiConfig = iox::RouDiConfig_t().optimize(); + iox::RouDiConfig_t defaultRouDiConfig = iox::RouDiConfig_t().setDefaults(); IceOryxRouDiComponents roudiComponents(defaultRouDiConfig); RouDi roudi(roudiComponents.m_rouDiMemoryManager, diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 118d9fadef..8f1b24ef55 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -28,8 +28,8 @@ namespace iox { namespace test { -static constexpr uint32_t DEFAULT_DEVICE_ID{0u}; -static constexpr uint32_t DEFAULT_MEMORY_TYPE{0u}; +static constexpr uint32_t DEFAULT_DEVICE_ID{20u}; +static constexpr uint32_t DEFAULT_MEMORY_TYPE{100u}; class PortPool_test : public Test { public: @@ -42,8 +42,10 @@ class PortPool_test : public Test ProcessName_t m_nodeName{"nodeName"}; const uint64_t m_nodeDeviceId = 999U; mepoo::MemoryManager m_memoryManager; - popo::PublisherOptions m_publisherOptions; - popo::SubscriberOptions m_subscriberOptions; + popo::PublisherOptions m_publisherOptions{10, "nodeName"}; + popo::SubscriberOptions m_subscriberOptions{ + iox::popo::SubscriberPortData::ChunkQueueData_t::MAX_CAPACITY, 10, "nodeName"}; + iox::mepoo::MemoryInfo m_memoryInfo{DEFAULT_DEVICE_ID, DEFAULT_MEMORY_TYPE}; }; TEST_F(PortPool_test, AddNodeDataIsSuccessful) @@ -97,6 +99,13 @@ TEST_F(PortPool_test, GetNodeDataListIsSuccessful) auto nodeDataList = sut.getNodeDataList(); ASSERT_EQ(nodeDataList.size(), 1U); + + for (const auto& nodeData : nodeDataList) + { + ASSERT_EQ(nodeData->m_process, m_processName); + ASSERT_EQ(nodeData->m_node, m_nodeName); + ASSERT_EQ(nodeData->m_nodeDeviceIdentifier, m_nodeDeviceId); + } } TEST_F(PortPool_test, GetNodeDataListWhenEmptyIsSuccessful) @@ -136,20 +145,20 @@ TEST_F(PortPool_test, RemoveNodeDataIsSuccessful) TEST_F(PortPool_test, AddPublisherPortIsSuccessful) { - auto publisherPort = - sut.addPublisherPort(m_serviceDescription, &m_memoryManager, m_applicationName, m_publisherOptions); + auto publisherPort = sut.addPublisherPort( + m_serviceDescription, &m_memoryManager, m_applicationName, m_publisherOptions, m_memoryInfo); ASSERT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); ASSERT_EQ(publisherPort.value()->m_processName, m_applicationName); - ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); - ASSERT_EQ(publisherPort.value()->m_nodeName, NodeName_t{""}); + ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, m_publisherOptions.historyCapacity); + ASSERT_EQ(publisherPort.value()->m_nodeName, m_publisherOptions.nodeName); ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } TEST_F(PortPool_test, AddPublisherPortWithMaxCapacityIsSuccessful) { - for (uint32_t i = 0; i < MAX_PUBLISHERS; ++i) + for (uint32_t i = 0U; i < MAX_PUBLISHERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); @@ -159,14 +168,15 @@ TEST_F(PortPool_test, AddPublisherPortWithMaxCapacityIsSuccessful) {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, &m_memoryManager, applicationName, - m_publisherOptions); + m_publisherOptions, + m_memoryInfo); ASSERT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)})); ASSERT_EQ(publisherPort.value()->m_processName, applicationName); - ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, 0UL); - ASSERT_EQ(publisherPort.value()->m_nodeName, NodeName_t{""}); + ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, m_publisherOptions.historyCapacity); + ASSERT_EQ(publisherPort.value()->m_nodeName, m_publisherOptions.nodeName); ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } @@ -182,7 +192,7 @@ TEST_F(PortPool_test, AddPublisherPortWhenPublisherListOverflowsReurnsError) errorHandlerCalled = true; }); - for (uint32_t i = 0; i <= MAX_PUBLISHERS; ++i) + for (uint32_t i = 0U; i <= MAX_PUBLISHERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); @@ -220,7 +230,7 @@ TEST_F(PortPool_test, GetPublisherPortDataListWhenEmptyIsSuccessful) TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) { - for (uint32_t i = 0; i < MAX_PUBLISHERS; ++i) + for (uint32_t i = 0U; i < MAX_PUBLISHERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); @@ -250,12 +260,13 @@ TEST_F(PortPool_test, RemovePublisherPortIsSuccessful) TEST_F(PortPool_test, AddSubscriberPortIsSuccessful) { - auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions); + auto subscriberPort = + sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions, m_memoryInfo); ASSERT_EQ(subscriberPort.value()->m_serviceDescription, m_serviceDescription); ASSERT_EQ(subscriberPort.value()->m_processName, m_applicationName); - ASSERT_EQ(subscriberPort.value()->m_nodeName, NodeName_t{""}); - ASSERT_EQ(subscriberPort.value()->m_historyRequest, 0U); + ASSERT_EQ(subscriberPort.value()->m_nodeName, m_subscriberOptions.nodeName); + ASSERT_EQ(subscriberPort.value()->m_historyRequest, m_subscriberOptions.historyRequest); ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_queue.capacity(), 256U); ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); @@ -263,7 +274,7 @@ TEST_F(PortPool_test, AddSubscriberPortIsSuccessful) TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) { - for (uint32_t i = 0; i < MAX_SUBSCRIBERS; ++i) + for (uint32_t i = 0U; i < MAX_SUBSCRIBERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); @@ -273,13 +284,14 @@ TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) auto subscriberPort = sut.addSubscriberPort( {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, applicationName, - m_subscriberOptions); + m_subscriberOptions, + m_memoryInfo); ASSERT_THAT(subscriberPort.value()->m_serviceDescription, Eq(ServiceDescription{IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)})); ASSERT_EQ(subscriberPort.value()->m_processName, applicationName); - ASSERT_EQ(subscriberPort.value()->m_nodeName, NodeName_t{""}); + ASSERT_EQ(subscriberPort.value()->m_nodeName, m_subscriberOptions.nodeName); ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } @@ -296,7 +308,7 @@ TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReurnsError) errorHandlerCalled = true; }); - for (uint32_t i = 0; i <= MAX_SUBSCRIBERS; ++i) + for (uint32_t i = 0U; i <= MAX_SUBSCRIBERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); @@ -330,7 +342,7 @@ TEST_F(PortPool_test, GetSubscriberPortDataListWhenEmptyIsSuccessful) TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful) { - for (uint32_t i = 0; i < MAX_SUBSCRIBERS; ++i) + for (uint32_t i = 0U; i < MAX_SUBSCRIBERS; ++i) { std::string service = "service" + std::to_string(i); std::string instance = "instance" + std::to_string(i); @@ -416,7 +428,7 @@ TEST_F(PortPool_test, GetInterfacePortDataListWhenEmptyIsSuccessful) TEST_F(PortPool_test, GetInterfacePortDataListCompletelyFilledIsSuccessful) { - for (uint32_t i = 0; i < MAX_INTERFACE_NUMBER; ++i) + for (uint32_t i = 0U; i < MAX_INTERFACE_NUMBER; ++i) { ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; sut.addInterfacePort(applicationName, Interfaces::INTERNAL); @@ -471,7 +483,7 @@ TEST_F(PortPool_test, AddApplicationPortWhenApplicationListOverflowsReturnsError for (uint32_t i = 0U; i <= MAX_PROCESS_NUMBER; ++i) { - auto pplicationData = sut.addApplicationPort(m_applicationName); + auto applicationData = sut.addApplicationPort(m_applicationName); } ASSERT_TRUE(errorHandlerCalled); @@ -495,7 +507,7 @@ TEST_F(PortPool_test, GetApplicationPortDataListIsSuccessful) TEST_F(PortPool_test, GetApplicationPortDataListCompletelyFilledIsSuccessful) { - for (uint32_t i = 0; i < MAX_PROCESS_NUMBER; ++i) + for (uint32_t i = 0U; i < MAX_PROCESS_NUMBER; ++i) { ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; sut.addApplicationPort(applicationName); @@ -574,7 +586,7 @@ TEST_F(PortPool_test, GetConditionVariableDataListWhenEmptyIsSuccessful) TEST_F(PortPool_test, GetConditionVariableDataListCompletelyFilledIsSuccessful) { - for (uint32_t i = 0; i < MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) + for (uint32_t i = 0U; i < MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) { ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; sut.addConditionVariableData(applicationName); @@ -594,11 +606,20 @@ TEST_F(PortPool_test, RemoveConditionVariableDataIsSuccessful) ASSERT_EQ(condtionalVariableData.size(), 0U); } -TEST_F(PortPool_test, GetServiceRegistryChangeCounterIsSuccessful) +TEST_F(PortPool_test, GetServiceRegistryChangeCounterReturnsZeroAsInitialValue) { auto serviceCounter = sut.serviceRegistryChangeCounter(); ASSERT_EQ(serviceCounter->load(), 0U); } + + +TEST_F(PortPool_test, GetServiceRegistryChangeCounterIsSuccessfull) +{ + sut.serviceRegistryChangeCounter()->fetch_add(1, std::memory_order_relaxed); + auto serviceCounter = sut.serviceRegistryChangeCounter(); + + ASSERT_EQ(serviceCounter->load(), 1U); +} } // namespace test -} // namespace iox \ No newline at end of file +} // namespace iox From d4992b26c47c317101abf60d2d29db8646e81cba Mon Sep 17 00:00:00 2001 From: "Chari Nehal Dattaram (RBEI/EBB1)" Date: Mon, 15 Mar 2021 13:39:23 +0530 Subject: [PATCH 46/89] iox-#496 refactored tests, replaced assert_* with expect_* , removed redundant code Signed-off-by: Chari Nehal Dattaram (RBEI/EBB1) --- .../test/moduletests/test_roudi_portpool.cpp | 205 ++++++++---------- 1 file changed, 87 insertions(+), 118 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 8f1b24ef55..7307e2e4fa 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -28,8 +28,8 @@ namespace iox { namespace test { -static constexpr uint32_t DEFAULT_DEVICE_ID{20u}; -static constexpr uint32_t DEFAULT_MEMORY_TYPE{100u}; +static constexpr uint32_t DEFAULT_DEVICE_ID{20U}; +static constexpr uint32_t DEFAULT_MEMORY_TYPE{100U}; class PortPool_test : public Test { public: @@ -39,12 +39,12 @@ class PortPool_test : public Test ServiceDescription m_serviceDescription{"service1", "instance1"}; ProcessName_t m_applicationName{"AppName"}; ProcessName_t m_processName{"processName"}; - ProcessName_t m_nodeName{"nodeName"}; + NodeName_t m_nodeName{"nodeName"}; const uint64_t m_nodeDeviceId = 999U; mepoo::MemoryManager m_memoryManager; - popo::PublisherOptions m_publisherOptions{10, "nodeName"}; + popo::PublisherOptions m_publisherOptions{10U, m_nodeName}; popo::SubscriberOptions m_subscriberOptions{ - iox::popo::SubscriberPortData::ChunkQueueData_t::MAX_CAPACITY, 10, "nodeName"}; + iox::popo::SubscriberPortData::ChunkQueueData_t::MAX_CAPACITY, 10U, m_nodeName}; iox::mepoo::MemoryInfo m_memoryInfo{DEFAULT_DEVICE_ID, DEFAULT_MEMORY_TYPE}; }; @@ -52,25 +52,22 @@ TEST_F(PortPool_test, AddNodeDataIsSuccessful) { auto nodeData = sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); - ASSERT_EQ(nodeData.value()->m_process, m_processName); - ASSERT_EQ(nodeData.value()->m_node, m_nodeName); - ASSERT_EQ(nodeData.value()->m_nodeDeviceIdentifier, m_nodeDeviceId); + ASSERT_THAT(nodeData.has_error(), Eq(false)); + EXPECT_EQ(nodeData.value()->m_process, m_processName); + EXPECT_EQ(nodeData.value()->m_node, m_nodeName); + EXPECT_EQ(nodeData.value()->m_nodeDeviceIdentifier, m_nodeDeviceId); } TEST_F(PortPool_test, AddNodeDataWithMaxCapacityIsSuccessful) { - cxx::vector nodeContainer; - for (uint32_t i = 1U; i <= MAX_NODE_NUMBER; ++i) { auto nodeData = sut.addNodeData(m_processName, m_nodeName, i); - if (!nodeData.has_error()) - { - nodeContainer.push_back(nodeData.value()); - } + + ASSERT_THAT(nodeData.has_error(), Eq(false)); } - ASSERT_EQ(nodeContainer.size(), MAX_NODE_NUMBER); + EXPECT_EQ(sut.getNodeDataList().size(), MAX_NODE_NUMBER); } @@ -89,48 +86,41 @@ TEST_F(PortPool_test, AddNodeDataWhenNodeListIsFullReturnsError) sut.addNodeData(m_processName, m_nodeName, i); } - ASSERT_TRUE(errorHandlerCalled); - ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__NODELIST_OVERFLOW); + EXPECT_TRUE(errorHandlerCalled); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__NODELIST_OVERFLOW); } TEST_F(PortPool_test, GetNodeDataListIsSuccessful) { sut.addNodeData(m_processName, m_nodeName, m_nodeDeviceId); - auto nodeDataList = sut.getNodeDataList(); - ASSERT_EQ(nodeDataList.size(), 1U); + auto nodeDataList = sut.getNodeDataList(); - for (const auto& nodeData : nodeDataList) - { - ASSERT_EQ(nodeData->m_process, m_processName); - ASSERT_EQ(nodeData->m_node, m_nodeName); - ASSERT_EQ(nodeData->m_nodeDeviceIdentifier, m_nodeDeviceId); - } + EXPECT_EQ(nodeDataList.size(), 1U); + EXPECT_EQ(nodeDataList[0]->m_process, m_processName); + EXPECT_EQ(nodeDataList[0]->m_node, m_nodeName); + EXPECT_EQ(nodeDataList[0]->m_nodeDeviceIdentifier, m_nodeDeviceId); } TEST_F(PortPool_test, GetNodeDataListWhenEmptyIsSuccessful) { auto nodeDataList = sut.getNodeDataList(); - ASSERT_EQ(nodeDataList.size(), 0U); + EXPECT_EQ(nodeDataList.size(), 0U); } TEST_F(PortPool_test, GetNodeDataListWithMaxCapacityIsSuccessful) { - cxx::vector nodeContainer; - for (uint32_t i = 1U; i <= MAX_NODE_NUMBER; ++i) { auto nodeData = sut.addNodeData(m_processName, m_nodeName, i); - if (!nodeData.has_error()) - { - nodeContainer.push_back(nodeData.value()); - } + + ASSERT_THAT(nodeData.has_error(), Eq(false)); } auto nodeDataList = sut.getNodeDataList(); - ASSERT_EQ(nodeDataList.size(), MAX_NODE_NUMBER); + EXPECT_EQ(nodeDataList.size(), MAX_NODE_NUMBER); } TEST_F(PortPool_test, RemoveNodeDataIsSuccessful) @@ -140,7 +130,7 @@ TEST_F(PortPool_test, RemoveNodeDataIsSuccessful) sut.removeNodeData(nodeData.value()); auto nodeDataList = sut.getNodeDataList(); - ASSERT_EQ(nodeDataList.size(), 0U); + EXPECT_EQ(nodeDataList.size(), 0U); } TEST_F(PortPool_test, AddPublisherPortIsSuccessful) @@ -148,37 +138,31 @@ TEST_F(PortPool_test, AddPublisherPortIsSuccessful) auto publisherPort = sut.addPublisherPort( m_serviceDescription, &m_memoryManager, m_applicationName, m_publisherOptions, m_memoryInfo); - ASSERT_THAT(publisherPort.value()->m_serviceDescription, Eq(ServiceDescription{"service1", "instance1"})); - ASSERT_EQ(publisherPort.value()->m_processName, m_applicationName); - ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, m_publisherOptions.historyCapacity); - ASSERT_EQ(publisherPort.value()->m_nodeName, m_publisherOptions.nodeName); - ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); - ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + ASSERT_THAT(publisherPort.has_error(), Eq(false)); + EXPECT_EQ(publisherPort.value()->m_serviceDescription, m_serviceDescription); + EXPECT_EQ(publisherPort.value()->m_processName, m_applicationName); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, m_publisherOptions.historyCapacity); + EXPECT_EQ(publisherPort.value()->m_nodeName, m_publisherOptions.nodeName); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } TEST_F(PortPool_test, AddPublisherPortWithMaxCapacityIsSuccessful) { for (uint32_t i = 0U; i < MAX_PUBLISHERS; ++i) { - std::string service = "service" + std::to_string(i); - std::string instance = "instance" + std::to_string(i); ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; auto publisherPort = sut.addPublisherPort( - {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, - &m_memoryManager, - applicationName, - m_publisherOptions, - m_memoryInfo); - - ASSERT_THAT(publisherPort.value()->m_serviceDescription, - Eq(ServiceDescription{IdString_t(cxx::TruncateToCapacity, service), - IdString_t(cxx::TruncateToCapacity, instance)})); - ASSERT_EQ(publisherPort.value()->m_processName, applicationName); - ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, m_publisherOptions.historyCapacity); - ASSERT_EQ(publisherPort.value()->m_nodeName, m_publisherOptions.nodeName); - ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); - ASSERT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + m_serviceDescription, &m_memoryManager, applicationName, m_publisherOptions, m_memoryInfo); + + ASSERT_THAT(publisherPort.has_error(), Eq(false)); + EXPECT_EQ(publisherPort.value()->m_serviceDescription, m_serviceDescription); + EXPECT_EQ(publisherPort.value()->m_processName, applicationName); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_historyCapacity, m_publisherOptions.historyCapacity); + EXPECT_EQ(publisherPort.value()->m_nodeName, m_publisherOptions.nodeName); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + EXPECT_EQ(publisherPort.value()->m_chunkSenderData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } } @@ -205,27 +189,27 @@ TEST_F(PortPool_test, AddPublisherPortWhenPublisherListOverflowsReurnsError) m_publisherOptions); } - ASSERT_TRUE(errorHandlerCalled); - ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW); + EXPECT_TRUE(errorHandlerCalled); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW); } TEST_F(PortPool_test, GetPublisherPortDataListIsSuccessful) { auto publisherPortDataList = sut.getPublisherPortDataList(); - ASSERT_EQ(publisherPortDataList.size(), 0U); + EXPECT_EQ(publisherPortDataList.size(), 0U); sut.addPublisherPort(m_serviceDescription, &m_memoryManager, m_applicationName, m_publisherOptions); publisherPortDataList = sut.getPublisherPortDataList(); - ASSERT_EQ(publisherPortDataList.size(), 1U); + EXPECT_EQ(publisherPortDataList.size(), 1U); } TEST_F(PortPool_test, GetPublisherPortDataListWhenEmptyIsSuccessful) { auto nodeDataList = sut.getPublisherPortDataList(); - ASSERT_EQ(nodeDataList.size(), 0U); + EXPECT_EQ(nodeDataList.size(), 0U); } TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) @@ -245,7 +229,7 @@ TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) auto publisherPortDataList = sut.getPublisherPortDataList(); - ASSERT_EQ(publisherPortDataList.size(), MAX_PUBLISHERS); + EXPECT_EQ(publisherPortDataList.size(), MAX_PUBLISHERS); } TEST_F(PortPool_test, RemovePublisherPortIsSuccessful) @@ -255,7 +239,7 @@ TEST_F(PortPool_test, RemovePublisherPortIsSuccessful) sut.removePublisherPort(publisherPort.value()); auto publisherPortDataList = sut.getPublisherPortDataList(); - ASSERT_EQ(publisherPortDataList.size(), 0U); + EXPECT_EQ(publisherPortDataList.size(), 0U); } TEST_F(PortPool_test, AddSubscriberPortIsSuccessful) @@ -263,13 +247,14 @@ TEST_F(PortPool_test, AddSubscriberPortIsSuccessful) auto subscriberPort = sut.addSubscriberPort(m_serviceDescription, m_applicationName, m_subscriberOptions, m_memoryInfo); - ASSERT_EQ(subscriberPort.value()->m_serviceDescription, m_serviceDescription); - ASSERT_EQ(subscriberPort.value()->m_processName, m_applicationName); - ASSERT_EQ(subscriberPort.value()->m_nodeName, m_subscriberOptions.nodeName); - ASSERT_EQ(subscriberPort.value()->m_historyRequest, m_subscriberOptions.historyRequest); - ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_queue.capacity(), 256U); - ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); - ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + ASSERT_THAT(subscriberPort.has_error(), Eq(false)); + EXPECT_EQ(subscriberPort.value()->m_serviceDescription, m_serviceDescription); + EXPECT_EQ(subscriberPort.value()->m_processName, m_applicationName); + EXPECT_EQ(subscriberPort.value()->m_nodeName, m_subscriberOptions.nodeName); + EXPECT_EQ(subscriberPort.value()->m_historyRequest, m_subscriberOptions.historyRequest); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_queue.capacity(), 256U); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) @@ -281,19 +266,15 @@ TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) ProcessName_t applicationName = {cxx::TruncateToCapacity, "AppName" + std::to_string(i)}; - auto subscriberPort = sut.addSubscriberPort( - {IdString_t(cxx::TruncateToCapacity, service), IdString_t(cxx::TruncateToCapacity, instance)}, - applicationName, - m_subscriberOptions, - m_memoryInfo); - - ASSERT_THAT(subscriberPort.value()->m_serviceDescription, - Eq(ServiceDescription{IdString_t(cxx::TruncateToCapacity, service), - IdString_t(cxx::TruncateToCapacity, instance)})); - ASSERT_EQ(subscriberPort.value()->m_processName, applicationName); - ASSERT_EQ(subscriberPort.value()->m_nodeName, m_subscriberOptions.nodeName); - ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); - ASSERT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); + auto subscriberPort = + sut.addSubscriberPort(m_serviceDescription, applicationName, m_subscriberOptions, m_memoryInfo); + + ASSERT_THAT(subscriberPort.has_error(), Eq(false)); + EXPECT_EQ(subscriberPort.value()->m_serviceDescription, m_serviceDescription); + EXPECT_EQ(subscriberPort.value()->m_processName, applicationName); + EXPECT_EQ(subscriberPort.value()->m_nodeName, m_subscriberOptions.nodeName); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); + EXPECT_EQ(subscriberPort.value()->m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); } } @@ -321,8 +302,8 @@ TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReurnsError) m_subscriberOptions); } - ASSERT_TRUE(errorHandlerCalled); - ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); + EXPECT_TRUE(errorHandlerCalled); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW); } TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful) @@ -365,31 +346,27 @@ TEST_F(PortPool_test, RemoveSubscriberPortIsSuccessful) sut.removeSubscriberPort(subscriberPort.value()); auto subscriberPortDataList = sut.getSubscriberPortDataList(); - ASSERT_EQ(subscriberPortDataList.size(), 0U); + EXPECT_EQ(subscriberPortDataList.size(), 0U); } TEST_F(PortPool_test, AddInterfacePortIsSuccessful) { auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); - ASSERT_EQ(interfacePortData.value()->m_processName, m_applicationName); - ASSERT_EQ(interfacePortData.value()->m_serviceDescription.getSourceInterface(), Interfaces::INTERNAL); + ASSERT_THAT(interfacePortData.has_error(), Eq(false)); + EXPECT_EQ(interfacePortData.value()->m_processName, m_applicationName); + EXPECT_EQ(interfacePortData.value()->m_serviceDescription.getSourceInterface(), Interfaces::INTERNAL); } TEST_F(PortPool_test, AddInterfacePortWithMaxCapacityIsSuccessful) { - cxx::vector interfacePortContainer; - for (uint32_t i = 1U; i <= MAX_INTERFACE_NUMBER; ++i) { auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); - if (!interfacePortData.has_error()) - { - interfacePortContainer.push_back(interfacePortData.value()); - } + ASSERT_THAT(interfacePortData.has_error(), Eq(false)); } - ASSERT_EQ(interfacePortContainer.size(), MAX_INTERFACE_NUMBER); + EXPECT_EQ(sut.getInterfacePortDataList().size(), MAX_INTERFACE_NUMBER); } TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError) @@ -407,8 +384,8 @@ TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError) auto interfacePortData = sut.addInterfacePort(m_applicationName, Interfaces::INTERNAL); } - ASSERT_TRUE(errorHandlerCalled); - ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__INTERFACELIST_OVERFLOW); + EXPECT_TRUE(errorHandlerCalled); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__INTERFACELIST_OVERFLOW); } TEST_F(PortPool_test, GetInterfacePortDataListIsSuccessful) @@ -452,23 +429,19 @@ TEST_F(PortPool_test, AddApplicationPortIsSuccessful) { auto applicationPortData = sut.addApplicationPort(m_applicationName); - ASSERT_EQ(applicationPortData.value()->m_processName, m_applicationName); + ASSERT_THAT(applicationPortData.has_error(), Eq(false)); + EXPECT_EQ(applicationPortData.value()->m_processName, m_applicationName); } TEST_F(PortPool_test, AddApplicationPortWithMaxCapacityIsSuccessful) { - cxx::vector applicationContainer; - for (uint32_t i = 1U; i <= MAX_PROCESS_NUMBER; ++i) { auto applicationPortData = sut.addApplicationPort(m_applicationName); - if (!applicationPortData.has_error()) - { - applicationContainer.push_back(applicationPortData.value()); - } + ASSERT_THAT(applicationPortData.has_error(), Eq(false)); } - ASSERT_EQ(applicationContainer.size(), MAX_PROCESS_NUMBER); + EXPECT_EQ(sut.getApplicationPortDataList().size(), MAX_PROCESS_NUMBER); } TEST_F(PortPool_test, AddApplicationPortWhenApplicationListOverflowsReturnsError) @@ -486,8 +459,8 @@ TEST_F(PortPool_test, AddApplicationPortWhenApplicationListOverflowsReturnsError auto applicationData = sut.addApplicationPort(m_applicationName); } - ASSERT_TRUE(errorHandlerCalled); - ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__APPLICATIONLIST_OVERFLOW); + EXPECT_TRUE(errorHandlerCalled); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__APPLICATIONLIST_OVERFLOW); } TEST_F(PortPool_test, GetApplicationPortDataListWhenEmptyIsSuccessful) @@ -531,23 +504,19 @@ TEST_F(PortPool_test, AddConditionVariableDataIsSuccessful) { auto conditionVariableData = sut.addConditionVariableData(m_applicationName); - ASSERT_EQ(conditionVariableData.value()->m_process, m_applicationName); + ASSERT_THAT(conditionVariableData.has_error(), Eq(false)); + EXPECT_EQ(conditionVariableData.value()->m_process, m_applicationName); } TEST_F(PortPool_test, AddConditionVariableDataWithMaxCapacityIsSuccessful) { - cxx::vector conditionVariableContainer; - for (uint32_t i = 1U; i <= MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) { auto conditionVariableData = sut.addConditionVariableData(m_applicationName); - if (!conditionVariableData.has_error()) - { - conditionVariableContainer.push_back(conditionVariableData.value()); - } + ASSERT_THAT(conditionVariableData.has_error(), Eq(false)); } - ASSERT_EQ(conditionVariableContainer.size(), MAX_NUMBER_OF_CONDITION_VARIABLES); + EXPECT_EQ(sut.getConditionVariableDataList().size(), MAX_NUMBER_OF_CONDITION_VARIABLES); } TEST_F(PortPool_test, AddConditionVariableDataWhenContainerIsFullReturnsError) @@ -565,8 +534,8 @@ TEST_F(PortPool_test, AddConditionVariableDataWhenContainerIsFullReturnsError) auto conditionVariableData = sut.addConditionVariableData(m_applicationName); } - ASSERT_TRUE(errorHandlerCalled); - ASSERT_EQ(errorHandlerType, Error::kPORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW); + EXPECT_TRUE(errorHandlerCalled); + EXPECT_EQ(errorHandlerType, Error::kPORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW); } TEST_F(PortPool_test, GetConditionVariableDataListIsSuccessful) @@ -610,7 +579,7 @@ TEST_F(PortPool_test, GetServiceRegistryChangeCounterReturnsZeroAsInitialValue) { auto serviceCounter = sut.serviceRegistryChangeCounter(); - ASSERT_EQ(serviceCounter->load(), 0U); + EXPECT_EQ(serviceCounter->load(), 0U); } From da2dfff8201530b399af6e1cd029a6042d7af4c9 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Tue, 16 Mar 2021 10:51:05 +0100 Subject: [PATCH 47/89] iox-#404 Rework FileLock error codes and fix missing errno for Windows Signed-off-by: Simon Hoinkis --- .../iceoryx_utils/posix_wrapper/file_lock.hpp | 6 ++--- .../include/iceoryx_utils/platform/errno.hpp | 21 ++++++++++++++++ .../include/iceoryx_utils/platform/errno.hpp | 21 ++++++++++++++++ .../include/iceoryx_utils/platform/errno.hpp | 21 ++++++++++++++++ .../include/iceoryx_utils/platform/errno.hpp | 24 +++++++++++++++++++ .../include/iceoryx_utils/platform/file.hpp | 5 ++++ .../source/posix_wrapper/file_lock.cpp | 24 ++++++++++--------- 7 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 iceoryx_utils/platform/linux/include/iceoryx_utils/platform/errno.hpp create mode 100644 iceoryx_utils/platform/mac/include/iceoryx_utils/platform/errno.hpp create mode 100644 iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/errno.hpp create mode 100644 iceoryx_utils/platform/win/include/iceoryx_utils/platform/errno.hpp diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index d11546b1de..04ec4b5e83 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -31,19 +31,17 @@ enum class FileLockError LOCKED_BY_OTHER_PROCESS, ACCESS_DENIED, INVALID_FILE_NAME, - FILE_EXISTS, QUOTA_EXHAUSTED, - INVALID_ARGUMENTS, + INVALID_PARAMETERS, SYSTEM_LIMIT, PROCESS_LIMIT, NO_SUCH_FILE, SPECIAL_FILE, - TEMP_FILE_NOT_SUPPORTED, FILE_TOO_LARGE, FILE_IN_USE, - INVALID_FILE_DESCRIPTOR, OUT_OF_MEMORY, I_O_ERROR, + SYS_CALL_NOT_IMPLEMENTED, INTERNAL_LOGIC_ERROR, }; diff --git a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/errno.hpp b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/errno.hpp new file mode 100644 index 0000000000..f9ebe92fb8 --- /dev/null +++ b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/errno.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 +#ifndef IOX_UTILS_LINUX_PLATFORM_ERRNO_HPP +#define IOX_UTILS_LINUX_PLATFORM_ERRNO_HPP + +#include + +#endif // IOX_UTILS_LINUX_PLATFORM_ERRNO_HPP diff --git a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/errno.hpp b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/errno.hpp new file mode 100644 index 0000000000..d92a6cfc89 --- /dev/null +++ b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/errno.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 +#ifndef IOX_UTILS_MAC_PLATFORM_ERRNO_HPP +#define IOX_UTILS_MAC_PLATFORM_ERRNO_HPP + +#include + +#endif // IOX_UTILS_MAC_PLATFORM_ERRNO_HPP diff --git a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/errno.hpp b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/errno.hpp new file mode 100644 index 0000000000..f105ba6293 --- /dev/null +++ b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/errno.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 +#ifndef IOX_UTILS_QNX_PLATFORM_ERRNO_HPP +#define IOX_UTILS_QNX_PLATFORM_ERRNO_HPP + +#include + +#endif // IOX_UTILS_QNX_PLATFORM_ERRNO_HPP diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/errno.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/errno.hpp new file mode 100644 index 0000000000..71c5967582 --- /dev/null +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/errno.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2021 by Apex.AI Inc. 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. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 +#ifndef IOX_UTILS_WIN_PLATFORM_ERRNO_HPP +#define IOX_UTILS_WIN_PLATFORM_ERRNO_HPP + +#include +#include + +#define EDQUOT WSAEDQUOT + +#endif // IOX_UTILS_WIN_PLATFORM_ERRNO_HPP diff --git a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp index 9960742b49..250b979896 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp @@ -16,6 +16,11 @@ #ifndef IOX_UTILS_WIN_PLATFORM_FILE_HPP #define IOX_UTILS_WIN_PLATFORM_FILE_HPP +#define LOCK_SH 1 +#define LOCK_EX 2 +#define LOCK_UN 8 +#define LOCK_NB 4 + int iox_flock(int fd, int op); #endif // IOX_UTILS_WIN_PLATFORM_FILE_HPP diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index b0ca7a0919..364ce1abd5 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -16,11 +16,14 @@ #include "iceoryx_utils/posix_wrapper/file_lock.hpp" #include "iceoryx_utils/cxx/smart_c.hpp" +#include "iceoryx_utils/platform/errno.hpp" #include "iceoryx_utils/platform/fcntl.hpp" #include "iceoryx_utils/platform/file.hpp" -#include "iceoryx_utils/platform/platform_correction.hpp" +#include "iceoryx_utils/platform/stat.hpp" #include "iceoryx_utils/platform/unistd.hpp" +#include "iceoryx_utils/platform/platform_correction.hpp" + namespace iox { namespace posix @@ -149,12 +152,6 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const std::cerr << "user disk quota exhausted for file \"" << m_name << "\"" << std::endl; return FileLockError::QUOTA_EXHAUSTED; } - case EEXIST: - { - std::cerr << "file \"" << m_name << "\"" - << " already exists" << std::endl; - return FileLockError::FILE_EXISTS; - } case EFAULT: { std::cerr << "outside address space error for file \"" << m_name << "\"" << std::endl; @@ -169,13 +166,13 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const } case EINVAL: { - std::cerr << "provided invalid arguments for file \"" << m_name << "\"" << std::endl; - return FileLockError::INVALID_ARGUMENTS; + std::cerr << "provided invalid characters in basename for file \"" << m_name << "\"" << std::endl; + return FileLockError::INVALID_PARAMETERS; } case EISDIR: { - std::cerr << "write access requested for directory \"" << m_name << "\"" << std::endl; - return FileLockError::INVALID_ARGUMENTS; + std::cerr << "write access requested for directory \"" << PATH_PREFIX << m_name << "\"" << std::endl; + return FileLockError::INVALID_PARAMETERS; } case ELOOP: { @@ -213,6 +210,11 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const std::cerr << "Device has no space for file \"" << m_name << "\"" << std::endl; return FileLockError::QUOTA_EXHAUSTED; } + case ENOSYS: + { + std::cerr << "open() not implemented for filesystem to \"" << m_name << "\"" << std::endl; + return FileLockError::SYS_CALL_NOT_IMPLEMENTED; + } case ENOTDIR: { std::cerr << "not a directory error for file \"" << m_name << "\"" << std::endl; From 1f03d6af0aab26b803ef631d2bc871391290e223 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Tue, 16 Mar 2021 15:16:04 +0100 Subject: [PATCH 48/89] iox-#404 Add copyright header for touched platform files Signed-off-by: Simon Hoinkis --- .../platform/linux/include/iceoryx_utils/platform/file.hpp | 1 + .../platform/linux/include/iceoryx_utils/platform/unistd.hpp | 1 + iceoryx_utils/platform/linux/source/unistd.cpp | 1 + .../platform/mac/include/iceoryx_utils/platform/file.hpp | 1 + .../platform/mac/include/iceoryx_utils/platform/unistd.hpp | 1 + iceoryx_utils/platform/mac/source/unistd.cpp | 1 + .../platform/qnx/include/iceoryx_utils/platform/file.hpp | 1 + .../platform/qnx/include/iceoryx_utils/platform/unistd.hpp | 1 + iceoryx_utils/platform/qnx/source/unistd.cpp | 1 + .../platform/win/include/iceoryx_utils/platform/file.hpp | 1 + .../platform/win/include/iceoryx_utils/platform/unistd.hpp | 1 + iceoryx_utils/platform/win/source/unistd.cpp | 1 + 12 files changed, 12 insertions(+) diff --git a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/file.hpp b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/file.hpp index f8c27cfe13..b85398b272 100644 --- a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/file.hpp +++ b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/file.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/linux/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/unistd.hpp index 05b5f37062..428a443048 100644 --- a/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/linux/include/iceoryx_utils/platform/unistd.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/linux/source/unistd.cpp b/iceoryx_utils/platform/linux/source/unistd.cpp index 5ccfdf04a3..372303bef5 100644 --- a/iceoryx_utils/platform/linux/source/unistd.cpp +++ b/iceoryx_utils/platform/linux/source/unistd.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/mac/include/iceoryx_utils/platform/file.hpp b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/file.hpp index 1a4d061d65..6e4e81374f 100644 --- a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/file.hpp +++ b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/file.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/mac/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/unistd.hpp index 7fd84ce403..a7f90ee2f8 100644 --- a/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/mac/include/iceoryx_utils/platform/unistd.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/mac/source/unistd.cpp b/iceoryx_utils/platform/mac/source/unistd.cpp index 5ccfdf04a3..372303bef5 100644 --- a/iceoryx_utils/platform/mac/source/unistd.cpp +++ b/iceoryx_utils/platform/mac/source/unistd.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/qnx/include/iceoryx_utils/platform/file.hpp b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/file.hpp index 0d72c96b10..cd47fd220a 100644 --- a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/file.hpp +++ b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/file.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/qnx/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/unistd.hpp index 6807412570..e8778e6b9e 100644 --- a/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/qnx/include/iceoryx_utils/platform/unistd.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/qnx/source/unistd.cpp b/iceoryx_utils/platform/qnx/source/unistd.cpp index 5ccfdf04a3..372303bef5 100644 --- a/iceoryx_utils/platform/qnx/source/unistd.cpp +++ b/iceoryx_utils/platform/qnx/source/unistd.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/win/include/iceoryx_utils/platform/file.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp index 250b979896..b3675a3a24 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/file.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp index ba6b813005..09d46ca2fb 100644 --- a/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp +++ b/iceoryx_utils/platform/win/include/iceoryx_utils/platform/unistd.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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_utils/platform/win/source/unistd.cpp b/iceoryx_utils/platform/win/source/unistd.cpp index 66c8290865..1712de660b 100644 --- a/iceoryx_utils/platform/win/source/unistd.cpp +++ b/iceoryx_utils/platform/win/source/unistd.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. From a2566effe443488c305b8e859c431b8a87df822c Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Tue, 16 Mar 2021 16:20:46 +0100 Subject: [PATCH 49/89] iox-#404 Rework File Lock error handling Signed-off-by: Simon Hoinkis --- .../iceoryx_utils/posix_wrapper/file_lock.hpp | 2 +- .../source/posix_wrapper/file_lock.cpp | 22 +++++-------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index 04ec4b5e83..27dbd4401c 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -32,7 +32,7 @@ enum class FileLockError ACCESS_DENIED, INVALID_FILE_NAME, QUOTA_EXHAUSTED, - INVALID_PARAMETERS, + INVALID_CHARACTERS_IN_FILE_NAME, SYSTEM_LIMIT, PROCESS_LIMIT, NO_SUCH_FILE, diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index 364ce1abd5..e0b6e03ca7 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -123,11 +123,11 @@ cxx::expected FileLock::closeFileDescriptor() noexcept { auto closeCall = cxx::makeSmartC(iox_close, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {ERROR_CODE}, {}, m_fd); + m_fd = INVALID_FD; + m_isInitialized = false; + if (!closeCall.hasErrors()) { - m_fd = INVALID_FD; - m_isInitialized = false; - return cxx::success(); } else @@ -166,13 +166,8 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const } case EINVAL: { - std::cerr << "provided invalid characters in basename for file \"" << m_name << "\"" << std::endl; - return FileLockError::INVALID_PARAMETERS; - } - case EISDIR: - { - std::cerr << "write access requested for directory \"" << PATH_PREFIX << m_name << "\"" << std::endl; - return FileLockError::INVALID_PARAMETERS; + std::cerr << "provided invalid characters in file \"" << m_name << "\"" << std::endl; + return FileLockError::INVALID_CHARACTERS_IN_FILE_NAME; } case ELOOP: { @@ -197,7 +192,7 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const case ENOENT: { std::cerr << "file \"" << m_name << "\"" - << "does not exist" << std::endl; + << " does not exist" << std::endl; return FileLockError::NO_SUCH_FILE; } case ENOMEM: @@ -215,11 +210,6 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const std::cerr << "open() not implemented for filesystem to \"" << m_name << "\"" << std::endl; return FileLockError::SYS_CALL_NOT_IMPLEMENTED; } - case ENOTDIR: - { - std::cerr << "not a directory error for file \"" << m_name << "\"" << std::endl; - return FileLockError::INVALID_FILE_NAME; - } case ENXIO: { std::cerr << "\"" << m_name << "\"" From c717345c487926b706e1e9ca9f61ecbb01c69597 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Tue, 16 Mar 2021 16:32:34 +0100 Subject: [PATCH 50/89] iox-#404 Disable codecov check Signed-off-by: Simon Hoinkis --- .codecov.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index 67c32ab7f4..e75759e86f 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -19,8 +19,6 @@ coverage: default: enabled: yes target: 70% - threshold: 2% - base: auto changes: no parsers: From e44498edbc47284be3b55005c61b56c0522dbc5d Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 1 Mar 2021 16:57:59 +0100 Subject: [PATCH 51/89] iox-#14 extend tryGetChunk and getChunk methods for custom header and payload alignment Signed-off-by: Mathias Kraus --- iceoryx_binding_c/source/c_publisher.cpp | 7 +- .../test/moduletests/test_event_info.cpp | 23 ++-- .../test/moduletests/test_listener.cpp | 7 +- .../test/moduletests/test_publisher.cpp | 7 +- .../test/moduletests/test_subscriber.cpp | 31 +++-- .../iceoryx_posh/iceoryx_posh_types.hpp | 8 +- .../internal/mepoo/memory_manager.hpp | 8 +- .../popo/building_blocks/chunk_sender.hpp | 5 +- .../popo/building_blocks/chunk_sender.inl | 10 +- .../popo/ports/publisher_port_user.hpp | 7 +- .../iceoryx_posh/internal/popo/publisher.inl | 13 +- .../internal/popo/untyped_publisher.inl | 3 +- .../introspection/mempool_introspection.inl | 8 +- .../introspection/port_introspection.inl | 15 ++- .../introspection/process_introspection.inl | 8 +- .../include/iceoryx_posh/popo/publisher.hpp | 2 +- iceoryx_posh/source/mepoo/memory_manager.cpp | 9 +- .../source/popo/ports/publisher_port_user.cpp | 9 +- .../test_popo_chunk_building_blocks.cpp | 11 +- .../test_popo_port_user_building_blocks.cpp | 6 +- .../test/integrationtests/test_posh_mepoo.cpp | 23 ++-- iceoryx_posh/test/mocks/publisher_mock.hpp | 5 +- .../moduletests/test_mepoo_memory_manager.cpp | 75 ++++++----- .../test/moduletests/test_mepoo_segment.cpp | 5 +- .../moduletests/test_popo_chunk_receiver.cpp | 21 ++- .../moduletests/test_popo_chunk_sender.cpp | 120 +++++++++++++----- .../test/moduletests/test_popo_publisher.cpp | 26 ++-- .../moduletests/test_popo_publisher_port.cpp | 74 +++++++---- .../test_popo_untyped_publisher.cpp | 8 +- .../test_roudi_mempool_introspection.cpp | 5 +- .../test_roudi_port_introspection.cpp | 7 +- .../test_roudi_process_introspection.cpp | 7 +- 32 files changed, 377 insertions(+), 196 deletions(-) diff --git a/iceoryx_binding_c/source/c_publisher.cpp b/iceoryx_binding_c/source/c_publisher.cpp index 113cd7c05c..2923a1cf6f 100644 --- a/iceoryx_binding_c/source/c_publisher.cpp +++ b/iceoryx_binding_c/source/c_publisher.cpp @@ -101,9 +101,9 @@ void iox_pub_deinit(iox_pub_t const self) iox_AllocationResult iox_pub_loan_chunk(iox_pub_t const self, void** const chunk, const uint32_t payloadSize) { - auto result = PublisherPortUser(self->m_portData).tryAllocateChunk(payloadSize).and_then([&](ChunkHeader* h) { - *chunk = h->payload(); - }); + auto result = PublisherPortUser(self->m_portData) + .tryAllocateChunk(payloadSize, CHUNK_DEFAULT_PAYLOAD_ALIGNMENT) + .and_then([&](ChunkHeader* h) { *chunk = h->payload(); }); if (result.has_error()) { return cpp2c::AllocationResult(result.get_error()); @@ -155,4 +155,3 @@ iox_service_description_t iox_pub_get_service_description(iox_pub_t const self) { return TranslateServiceDescription(PublisherPortUser(self->m_portData).getCaProServiceDescription()); } - diff --git a/iceoryx_binding_c/test/moduletests/test_event_info.cpp b/iceoryx_binding_c/test/moduletests/test_event_info.cpp index 6537725361..16a956b704 100644 --- a/iceoryx_binding_c/test/moduletests/test_event_info.cpp +++ b/iceoryx_binding_c/test/moduletests/test_event_info.cpp @@ -75,6 +75,15 @@ class iox_event_info_test : public Test m_lastEventCallbackArgument = arg; } + iox::mepoo::SharedChunk getChunkFromMemoryManager() + { + constexpr uint32_t PAYLOAD_SIZE{100U}; + return m_memoryManager.getChunk(PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); + } + static UserTrigger* m_lastEventCallbackArgument; ConditionVariableData m_condVar{"myApp"}; @@ -108,7 +117,7 @@ TEST_F(iox_event_info_test, eventInfoHasCorrectId) auto eventInfoVector = m_waitSet.wait(); - ASSERT_THAT(eventInfoVector.size(), Eq(1)); + ASSERT_THAT(eventInfoVector.size(), Eq(1U)); EXPECT_EQ(iox_event_info_get_event_id(eventInfoVector[0]), ARBITRARY_EVENT_ID); } @@ -125,10 +134,9 @@ TEST_F(iox_event_info_test, eventOriginIsUserTriggerPointerWhenItsOriginatingFro TEST_F(iox_event_info_test, eventOriginIsNotUserTriggerPointerWhenItsNotOriginatingFromThem) { - constexpr uint64_t CHUNK_SIZE = 100U; iox_ws_attach_subscriber_event(&m_waitSet, m_subscriberHandle, SubscriberEvent_HAS_DATA, 587U, NULL); this->Subscribe(&m_portPtr); - m_chunkPusher.push(m_memoryManager.getChunk(CHUNK_SIZE)); + m_chunkPusher.push(getChunkFromMemoryManager()); auto eventInfoVector = m_waitSet.wait(); @@ -137,10 +145,9 @@ TEST_F(iox_event_info_test, eventOriginIsNotUserTriggerPointerWhenItsNotOriginat TEST_F(iox_event_info_test, eventOriginIsSubscriberPointerWhenItsOriginatingFromThem) { - constexpr uint64_t CHUNK_SIZE = 100U; iox_ws_attach_subscriber_event(&m_waitSet, m_subscriberHandle, SubscriberEvent_HAS_DATA, 587U, NULL); this->Subscribe(&m_portPtr); - m_chunkPusher.push(m_memoryManager.getChunk(CHUNK_SIZE)); + m_chunkPusher.push(getChunkFromMemoryManager()); auto eventInfoVector = m_waitSet.wait(); @@ -172,10 +179,9 @@ TEST_F(iox_event_info_test, getOriginReturnsPointerToUserTriggerWhenOriginatingF TEST_F(iox_event_info_test, getOriginReturnsNullptrUserTriggerWhenNotOriginatingFromThem) { - constexpr uint64_t CHUNK_SIZE = 100U; iox_ws_attach_subscriber_event(&m_waitSet, m_subscriberHandle, SubscriberEvent_HAS_DATA, 587U, NULL); this->Subscribe(&m_portPtr); - m_chunkPusher.push(m_memoryManager.getChunk(CHUNK_SIZE)); + m_chunkPusher.push(getChunkFromMemoryManager()); auto eventInfoVector = m_waitSet.wait(); @@ -185,10 +191,9 @@ TEST_F(iox_event_info_test, getOriginReturnsNullptrUserTriggerWhenNotOriginating TEST_F(iox_event_info_test, getOriginReturnsPointerToSubscriberWhenOriginatingFromThem) { - constexpr uint64_t CHUNK_SIZE = 100U; iox_ws_attach_subscriber_event(&m_waitSet, m_subscriberHandle, SubscriberEvent_HAS_DATA, 587U, NULL); this->Subscribe(&m_portPtr); - m_chunkPusher.push(m_memoryManager.getChunk(CHUNK_SIZE)); + m_chunkPusher.push(getChunkFromMemoryManager()); auto eventInfoVector = m_waitSet.wait(); diff --git a/iceoryx_binding_c/test/moduletests/test_listener.cpp b/iceoryx_binding_c/test/moduletests/test_listener.cpp index 229f316a15..5dacb1fc81 100644 --- a/iceoryx_binding_c/test/moduletests/test_listener.cpp +++ b/iceoryx_binding_c/test/moduletests/test_listener.cpp @@ -268,9 +268,12 @@ TIMING_TEST_F(iox_listener_test, SubscriberCallbackIsCalledSampleIsReceived, Rep Eq(iox_ListenerResult::ListenerResult_SUCCESS)); Subscribe(m_subscriber[0U]); - m_chunkPusher[0U].push(m_memoryManager.getChunk(100U)); + constexpr uint32_t PAYLOAD_SIZE{100U}; + m_chunkPusher[0U].push(m_memoryManager.getChunk(PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT)); std::this_thread::sleep_for(TIMEOUT); EXPECT_THAT(g_subscriberCallbackArgument, Eq(&m_subscriber[0U])); }); - diff --git a/iceoryx_binding_c/test/moduletests/test_publisher.cpp b/iceoryx_binding_c/test/moduletests/test_publisher.cpp index 68475c0f49..421c6fa7a3 100644 --- a/iceoryx_binding_c/test/moduletests/test_publisher.cpp +++ b/iceoryx_binding_c/test/moduletests/test_publisher.cpp @@ -197,7 +197,11 @@ TEST_F(iox_pub_test, allocate_chunkFailsWhenOutOfChunks) std::vector chunkBucket; while (true) { - auto sharedChunk = m_memoryManager.getChunk(100); + constexpr uint32_t PAYLOAD_SIZE{100U}; + auto sharedChunk = m_memoryManager.getChunk(PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); if (sharedChunk) chunkBucket.emplace_back(sharedChunk); else @@ -317,4 +321,3 @@ TEST(iox_pub_options_test, publisherInitializationTerminatesIfOptionsAreNotIniti EXPECT_DEATH({ iox_pub_init(&storage, "a", "b", "c", &options); }, ".*"); } - diff --git a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp index 907115af48..9aec939fe0 100644 --- a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp +++ b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp @@ -79,6 +79,15 @@ class iox_sub_test : public Test m_triggerCallbackLatestArgument = sub; } + iox::mepoo::SharedChunk getChunkFromMemoryManager() + { + constexpr uint32_t PAYLOAD_SIZE{100U}; + return m_memoryManager.getChunk(PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); + } + static iox_sub_t m_triggerCallbackLatestArgument; static constexpr size_t MEMORY_SIZE = 1024 * 1024 * 100; uint8_t m_memory[MEMORY_SIZE]; @@ -166,7 +175,7 @@ TEST_F(iox_sub_test, initialStateNoChunksAvailable) TEST_F(iox_sub_test, receiveChunkWhenThereIsOne) { this->Subscribe(&m_portPtr); - m_chunkPusher.push(m_memoryManager.getChunk(100U)); + m_chunkPusher.push(getChunkFromMemoryManager()); const void* chunk = nullptr; EXPECT_EQ(iox_sub_take_chunk(m_sut, &chunk), ChunkReceiveResult_SUCCESS); @@ -180,7 +189,7 @@ TEST_F(iox_sub_test, receiveChunkWithContent) int value; }; - auto sharedChunk = m_memoryManager.getChunk(100U); + auto sharedChunk = getChunkFromMemoryManager(); static_cast(sharedChunk.getPayload())->value = 1234; m_chunkPusher.push(sharedChunk); @@ -193,7 +202,7 @@ TEST_F(iox_sub_test, receiveChunkWithContent) TEST_F(iox_sub_test, chunkHeaderCanBeObtainedFromChunkAfterTake) { this->Subscribe(&m_portPtr); - auto sharedChunk = m_memoryManager.getChunk(100U); + auto sharedChunk = getChunkFromMemoryManager(); m_chunkPusher.push(sharedChunk); const void* chunk = nullptr; @@ -211,18 +220,18 @@ TEST_F(iox_sub_test, receiveChunkWhenToManyChunksAreHold) const void* chunk = nullptr; for (uint64_t i = 0U; i < MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY + 1U; ++i) { - m_chunkPusher.push(m_memoryManager.getChunk(100U)); + m_chunkPusher.push(getChunkFromMemoryManager()); iox_sub_take_chunk(m_sut, &chunk); } - m_chunkPusher.push(m_memoryManager.getChunk(100U)); + m_chunkPusher.push(getChunkFromMemoryManager()); EXPECT_EQ(iox_sub_take_chunk(m_sut, &chunk), ChunkReceiveResult_TOO_MANY_CHUNKS_HELD_IN_PARALLEL); } TEST_F(iox_sub_test, releaseChunkWorks) { this->Subscribe(&m_portPtr); - m_chunkPusher.push(m_memoryManager.getChunk(100U)); + m_chunkPusher.push(getChunkFromMemoryManager()); const void* chunk = nullptr; iox_sub_take_chunk(m_sut, &chunk); @@ -237,7 +246,7 @@ TEST_F(iox_sub_test, releaseChunkQueuedChunksWorks) this->Subscribe(&m_portPtr); for (uint64_t i = 0U; i < MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY; ++i) { - m_chunkPusher.push(m_memoryManager.getChunk(100U)); + m_chunkPusher.push(getChunkFromMemoryManager()); } EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY)); @@ -253,7 +262,7 @@ TEST_F(iox_sub_test, initialStateHasNewChunksFalse) TEST_F(iox_sub_test, receivingChunkLeadsToHasNewChunksTrue) { this->Subscribe(&m_portPtr); - m_chunkPusher.push(m_memoryManager.getChunk(100U)); + m_chunkPusher.push(getChunkFromMemoryManager()); EXPECT_TRUE(iox_sub_has_chunks(m_sut)); } @@ -268,7 +277,7 @@ TEST_F(iox_sub_test, sendingTooMuchLeadsToLostChunks) this->Subscribe(&m_portPtr); for (uint64_t i = 0U; i < DefaultChunkQueueConfig::MAX_QUEUE_CAPACITY + 1U; ++i) { - m_chunkPusher.push(m_memoryManager.getChunk(100U)); + m_chunkPusher.push(getChunkFromMemoryManager()); } EXPECT_TRUE(iox_sub_has_lost_chunks(m_sut)); @@ -303,7 +312,7 @@ TEST_F(iox_sub_test, hasDataTriggersWaitSetWithCorrectEventId) { iox_ws_attach_subscriber_event(m_waitSet.get(), m_sut, SubscriberEvent_HAS_DATA, 587U, NULL); this->Subscribe(&m_portPtr); - m_chunkPusher.push(m_memoryManager.getChunk(100U)); + m_chunkPusher.push(getChunkFromMemoryManager()); auto triggerVector = m_waitSet->wait(); @@ -315,7 +324,7 @@ TEST_F(iox_sub_test, hasDataTriggersWaitSetWithCorrectCallback) { iox_ws_attach_subscriber_event(m_waitSet.get(), m_sut, SubscriberEvent_HAS_DATA, 0U, iox_sub_test::triggerCallback); this->Subscribe(&m_portPtr); - m_chunkPusher.push(m_memoryManager.getChunk(100U)); + m_chunkPusher.push(getChunkFromMemoryManager()); auto triggerVector = m_waitSet->wait(); diff --git a/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp b/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp index 40279abfce..89c2b5342a 100644 --- a/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp +++ b/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. -// Copyright (c) 2021 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -122,6 +122,10 @@ constexpr uint32_t MAX_SHM_SEGMENTS = 100U; constexpr uint32_t MAX_NUMBER_OF_MEMORY_PROVIDER = 8U; constexpr uint32_t MAX_NUMBER_OF_MEMORY_BLOCKS_PER_MEMORY_PROVIDER = 64U; +constexpr uint32_t CHUNK_DEFAULT_PAYLOAD_ALIGNMENT{8U}; +constexpr uint32_t CHUNK_NO_CUSTOM_HEADER_SIZE{0U}; +constexpr uint32_t CHUNK_NO_CUSTOM_HEADER_ALIGNMENT{1U}; + // Message Queue constexpr uint32_t ROUDI_MAX_MESSAGES = 5U; constexpr uint32_t ROUDI_MESSAGE_SIZE = 512U; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp index ff01563c52..14474c17c5 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -51,7 +52,10 @@ class MemoryManager posix::Allocator* f_managementAllocator, posix::Allocator* f_payloadAllocator); - SharedChunk getChunk(const MaxSize_t f_size); + SharedChunk getChunk(const MaxSize_t f_size, + const uint32_t payloadAlignment, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment); uint32_t getMempoolChunkSizeForPayloadSize(const uint32_t f_size) const; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp index 6148b3e89b..337c36cf81 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp @@ -67,7 +67,10 @@ class ChunkSender : public ChunkDistributor tryAllocate(const uint32_t payloadSize, - const UniquePortId originId) noexcept; + const UniquePortId originId, + const uint32_t payloadAlignment, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment) noexcept; /// @brief Release an allocated chunk without sending it /// @param[in] chunkHeader, pointer to the ChunkHeader to release diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl index 62c7418012..e2997cb16a 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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,11 @@ inline typename ChunkSender::MemberType_t* ChunkSender inline cxx::expected -ChunkSender::tryAllocate(const uint32_t payloadSize, const UniquePortId originId) noexcept +ChunkSender::tryAllocate(const uint32_t payloadSize, + const UniquePortId originId, + const uint32_t payloadAlignment, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment) noexcept { // use the chunk stored in m_lastChunk if there is one, there is no other owner and the new payload still fits in it const uint32_t neededChunkSize = getMembers()->m_memoryMgr->sizeWithChunkHeaderStruct(payloadSize); @@ -63,7 +68,8 @@ ChunkSender::tryAllocate(const uint32_t payloadSize, const { // BEGIN of critical section, chunk will be lost if process gets hard terminated in between // get a new chunk - mepoo::SharedChunk chunk = getMembers()->m_memoryMgr->getChunk(payloadSize); + mepoo::SharedChunk chunk = + getMembers()->m_memoryMgr->getChunk(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); if (chunk) { diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_user.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_user.hpp index 8775390949..1b26c46d03 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_user.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_user.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -52,7 +53,11 @@ class PublisherPortUser : public BasePort /// @param[in] payloadSize, size of the user paylaod without additional headers /// @return on success pointer to a ChunkHeader which can be used to access the payload and header fields, error if /// not - cxx::expected tryAllocateChunk(const uint32_t payloadSize) noexcept; + cxx::expected + tryAllocateChunk(const uint32_t payloadSize, + const uint32_t payloadAlignment, + const uint32_t customHeaderSize = 0U, + const uint32_t customHeaderAlignment = 1U) noexcept; /// @brief Free an allocated chunk without sending it /// @param[in] chunkHeader, pointer to the ChunkHeader to free diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/publisher.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/publisher.inl index 327e2bab46..c26146e895 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/publisher.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/publisher.inl @@ -35,8 +35,7 @@ template template inline cxx::expected, AllocationError> Publisher::loan(Args&&... args) noexcept { - return std::move( - loanSample(sizeof(T)).and_then([&](auto& sample) { new (sample.get()) T(std::forward(args)...); })); + return std::move(loanSample().and_then([&](auto& sample) { new (sample.get()) T(std::forward(args)...); })); } template @@ -50,7 +49,7 @@ inline cxx::expected Publisher::publishRes static_assert(cxx::has_signature::value, "callable provided to Publisher::publishResultOf must have signature void(T*, ArgsTypes...)"); - return loanSample(sizeof(T)).and_then([&](auto& sample) { + return loanSample().and_then([&](auto& sample) { c(sample.get(), std::forward(args)...); sample.publish(); }); @@ -59,17 +58,17 @@ inline cxx::expected Publisher::publishRes template inline cxx::expected Publisher::publishCopyOf(const T& val) noexcept { - return loanSample(sizeof(T)).and_then([&](auto& sample) { + return loanSample().and_then([&](auto& sample) { *sample.get() = val; // Copy assignment of value into sample's memory allocation. sample.publish(); }); } template -inline cxx::expected, AllocationError> -Publisher::loanSample(const uint32_t size) noexcept +inline cxx::expected, AllocationError> Publisher::loanSample() noexcept { - auto result = port().tryAllocateChunk(size); + auto result = port().tryAllocateChunk( + sizeof(T), alignof(T), iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); if (result.has_error()) { return cxx::error(result.get_error()); diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/untyped_publisher.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/untyped_publisher.inl index e039345042..22bad78a37 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/untyped_publisher.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/untyped_publisher.inl @@ -39,7 +39,8 @@ inline void UntypedPublisherImpl::publish(const void* chunk) n template inline cxx::expected UntypedPublisherImpl::loan(const uint32_t size) noexcept { - auto result = port().tryAllocateChunk(size); + auto result = port().tryAllocateChunk( + size, CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, CHUNK_NO_CUSTOM_HEADER_SIZE, CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); if (result.has_error()) { return cxx::error(result.get_error()); diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl index 16f8a804a3..e130fa43e7 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl @@ -1,4 +1,5 @@ -// Copyright (c) 2019, 2020 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -85,7 +86,10 @@ inline void MemPoolIntrospection:: if (m_publisherPort.hasSubscribers()) { uint32_t id = 0U; - auto maybeChunkHeader = m_publisherPort.tryAllocateChunk(sizeof(MemPoolIntrospectionInfoContainer)); + auto maybeChunkHeader = m_publisherPort.tryAllocateChunk(sizeof(MemPoolIntrospectionInfoContainer), + alignof(MemPoolIntrospectionInfoContainer), + CHUNK_NO_CUSTOM_HEADER_SIZE, + CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); if (maybeChunkHeader.has_error()) { LogWarn() << "Cannot allocate chunk for mempool introspection!"; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/port_introspection.inl b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/port_introspection.inl index 89ccf75f58..43dd1fd95a 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/port_introspection.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/port_introspection.inl @@ -103,7 +103,10 @@ inline void PortIntrospection::send() noexcept template inline void PortIntrospection::sendPortData() noexcept { - auto maybeChunkHeader = m_publisherPort->tryAllocateChunk(sizeof(PortIntrospectionFieldTopic)); + auto maybeChunkHeader = m_publisherPort->tryAllocateChunk(sizeof(PortIntrospectionFieldTopic), + alignof(PortIntrospectionFieldTopic), + CHUNK_NO_CUSTOM_HEADER_SIZE, + CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); if (!maybeChunkHeader.has_error()) { auto sample = static_cast(maybeChunkHeader.value()->payload()); @@ -118,7 +121,10 @@ inline void PortIntrospection::sendPortData() noe template inline void PortIntrospection::sendThroughputData() noexcept { - auto maybeChunkHeader = m_publisherPortThroughput->tryAllocateChunk(sizeof(PortThroughputIntrospectionFieldTopic)); + auto maybeChunkHeader = m_publisherPortThroughput->tryAllocateChunk(sizeof(PortThroughputIntrospectionFieldTopic), + alignof(PortThroughputIntrospectionFieldTopic), + CHUNK_NO_CUSTOM_HEADER_SIZE, + CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); if (!maybeChunkHeader.has_error()) { auto throughputSample = @@ -135,7 +141,10 @@ template inline void PortIntrospection::sendSubscriberPortsData() noexcept { auto maybeChunkHeader = - m_publisherPortSubscriberPortsData->tryAllocateChunk(sizeof(SubscriberPortChangingIntrospectionFieldTopic)); + m_publisherPortSubscriberPortsData->tryAllocateChunk(sizeof(SubscriberPortChangingIntrospectionFieldTopic), + alignof(SubscriberPortChangingIntrospectionFieldTopic), + CHUNK_NO_CUSTOM_HEADER_SIZE, + CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); if (!maybeChunkHeader.has_error()) { auto subscriberPortChangingDataSample = diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/process_introspection.inl b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/process_introspection.inl index b55963fe0a..8ecb288dd5 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/process_introspection.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/process_introspection.inl @@ -1,4 +1,5 @@ -// Copyright (c) 2019, 2020 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -170,7 +171,10 @@ inline void ProcessIntrospection::send() noexcept std::lock_guard guard(m_mutex); if (m_processListNewData) { - auto maybeChunkHeader = m_publisherPort->tryAllocateChunk(sizeof(ProcessIntrospectionFieldTopic)); + auto maybeChunkHeader = m_publisherPort->tryAllocateChunk(sizeof(ProcessIntrospectionFieldTopic), + alignof(ProcessIntrospectionFieldTopic), + CHUNK_NO_CUSTOM_HEADER_SIZE, + CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); if (!maybeChunkHeader.has_error()) { auto sample = static_cast(maybeChunkHeader.value()->payload()); diff --git a/iceoryx_posh/include/iceoryx_posh/popo/publisher.hpp b/iceoryx_posh/include/iceoryx_posh/popo/publisher.hpp index 011fcbfccd..3b6950fda5 100644 --- a/iceoryx_posh/include/iceoryx_posh/popo/publisher.hpp +++ b/iceoryx_posh/include/iceoryx_posh/popo/publisher.hpp @@ -99,7 +99,7 @@ class Publisher : public base_publisher_t, public PublisherInterface private: Sample convertChunkHeaderToSample(const mepoo::ChunkHeader* const header) noexcept; - cxx::expected, AllocationError> loanSample(const uint32_t size) noexcept; + cxx::expected, AllocationError> loanSample() noexcept; using PublisherSampleDeleter = SampleDeleter; PublisherSampleDeleter m_sampleDeleter{port()}; diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index c811cde816..8edbfe763f 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019, 2020 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -155,10 +156,14 @@ void MemoryManager::configureMemoryManager(const MePooConfig& f_mePooConfig, generateChunkManagementPool(f_managementAllocator); } -SharedChunk MemoryManager::getChunk(const MaxSize_t f_size) +SharedChunk MemoryManager::getChunk(const MaxSize_t f_size, + const uint32_t payloadAlignment [[gnu::unused]], + const uint32_t customHeaderSize [[gnu::unused]], + const uint32_t customHeaderAlignment [[gnu::unused]]) { void* chunk{nullptr}; MemPool* memPoolPointer{nullptr}; + // TODO iox-#14 calculate correct size uint32_t adjustedSize = MemoryManager::sizeWithChunkHeaderStruct(f_size); uint32_t totalSizeOfAquiredChunk = 0; diff --git a/iceoryx_posh/source/popo/ports/publisher_port_user.cpp b/iceoryx_posh/source/popo/ports/publisher_port_user.cpp index 5ffe586864..c7bd8c49d9 100644 --- a/iceoryx_posh/source/popo/ports/publisher_port_user.cpp +++ b/iceoryx_posh/source/popo/ports/publisher_port_user.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -38,9 +39,13 @@ PublisherPortUser::MemberType_t* PublisherPortUser::getMembers() noexcept } cxx::expected -PublisherPortUser::tryAllocateChunk(const uint32_t payloadSize) noexcept +PublisherPortUser::tryAllocateChunk(const uint32_t payloadSize, + const uint32_t payloadAlignment, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment) noexcept { - return m_chunkSender.tryAllocate(payloadSize, getUniqueID()); + return m_chunkSender.tryAllocate( + payloadSize, getUniqueID(), payloadAlignment, customHeaderSize, customHeaderAlignment); } void PublisherPortUser::releaseChunk(mepoo::ChunkHeader* const chunkHeader) noexcept diff --git a/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp b/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp index 82cc824566..59a0492cb9 100644 --- a/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp +++ b/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp @@ -80,7 +80,7 @@ class ChunkBuildingBlocks_IntegrationTest : public Test virtual ~ChunkBuildingBlocks_IntegrationTest() { /// @note One chunk is on hold due to the fact that chunkSender and chunkDistributor hold last chunk - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } void SetUp() @@ -94,7 +94,12 @@ class ChunkBuildingBlocks_IntegrationTest : public Test { for (size_t i = 0; i < ITERATIONS; i++) { - m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()) + m_chunkSender + .tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT) .and_then([&](auto chunkHeader) { auto sample = chunkHeader->payload(); new (sample) DummySample(); @@ -245,4 +250,4 @@ TEST_F(ChunkBuildingBlocks_IntegrationTest, TwoHopsThreeThreadsNoSoFi) ASSERT_FALSE(m_popper.hasOverflown()); ASSERT_FALSE(m_chunkReceiver.hasOverflown()); EXPECT_EQ(m_sendCounter, m_receiveCounter); -} \ No newline at end of file +} diff --git a/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp b/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp index 6931dccf28..7caa67bdde 100644 --- a/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp +++ b/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp @@ -294,7 +294,11 @@ class PortUser_IntegrationTest : public Test // Subscriber is ready to receive -> start sending samples for (size_t i = 0U; i < ITERATIONS; i++) { - publisherPortUser.tryAllocateChunk(sizeof(DummySample)) + publisherPortUser + .tryAllocateChunk(sizeof(DummySample), + alignof(DummySample), + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT) .and_then([&](auto chunkHeader) { auto sample = chunkHeader->payload(); new (sample) DummySample(); diff --git a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp index f5b6a7d884..a0ecae30c1 100644 --- a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp +++ b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2019 - 2021 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -286,7 +287,8 @@ class Mepoo_IntegrationTest : public Test bool sendreceivesample(const int& times) { using Topic = MemPoolTestTopic; - constexpr auto topicSize = sizeof(Topic); + constexpr auto TOPIC_SIZE = sizeof(Topic); + constexpr auto TOPIC_ALIGNMENT = alignof(Topic); if (!(publisherPort->isOffered())) { @@ -302,12 +304,17 @@ class Mepoo_IntegrationTest : public Test for (int idx = 0; idx < times; ++idx) { - publisherPort->tryAllocateChunk(topicSize).and_then([&](auto sample) { - new (sample->payload()) Topic; - sample->payloadSize = topicSize; - publisherPort->sendChunk(sample); - m_roudiEnv->InterOpWait(); - }); + publisherPort + ->tryAllocateChunk(TOPIC_SIZE, + TOPIC_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT) + .and_then([&](auto sample) { + new (sample->payload()) Topic; + sample->payloadSize = TOPIC_SIZE; + publisherPort->sendChunk(sample); + m_roudiEnv->InterOpWait(); + }); } return true; diff --git a/iceoryx_posh/test/mocks/publisher_mock.hpp b/iceoryx_posh/test/mocks/publisher_mock.hpp index b84720969f..de16ccec46 100644 --- a/iceoryx_posh/test/mocks/publisher_mock.hpp +++ b/iceoryx_posh/test/mocks/publisher_mock.hpp @@ -53,8 +53,9 @@ class MockPublisherPortUser return getServiceDescription(); } MOCK_CONST_METHOD0(getServiceDescription, iox::capro::ServiceDescription()); - MOCK_METHOD1(tryAllocateChunk, - iox::cxx::expected(const uint32_t)); + MOCK_METHOD4(tryAllocateChunk, + iox::cxx::expected( + const uint32_t, const uint32_t, const uint32_t, const uint32_t)); MOCK_METHOD1(releaseChunk, void(iox::mepoo::ChunkHeader* const)); MOCK_METHOD1(sendChunk, void(iox::mepoo::ChunkHeader* const)); MOCK_METHOD0(tryGetPreviousChunk, iox::cxx::optional()); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 0cd507de4a..8dd99fcdac 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019, 2020 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -43,6 +44,10 @@ class MemoryManager_test : public Test return chunkSize + sizeof(iox::mepoo::ChunkHeader); } + static constexpr uint32_t PAYLOAD_ALIGNMENT = iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT; + static constexpr uint32_t CUSTOM_HEADER_SIZE = iox::CHUNK_NO_CUSTOM_HEADER_SIZE; + static constexpr uint32_t CUSTOM_HEADER_ALIGNMENT = iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT; + iox::posix::Allocator* allocator; void* rawMemory; size_t rawMemorySize = 1000000; @@ -107,7 +112,7 @@ TEST_F(MemoryManager_test, getChunkWithNoMemPool) EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); }); - auto bla = sut->getChunk(15); + auto bla = sut->getChunk(15, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_THAT(bla, Eq(false)); ASSERT_THAT(detectedError.has_value(), Eq(true)); @@ -128,7 +133,7 @@ TEST_F(MemoryManager_test, getTooLargeChunk) EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); }); - auto bla = sut->getChunk(200); + auto bla = sut->getChunk(200, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_THAT(bla, Eq(false)); ASSERT_THAT(detectedError.has_value(), Eq(true)); @@ -139,7 +144,7 @@ TEST_F(MemoryManager_test, getChunkSingleMemPoolSingleChunk) { mempoolconf.addMemPool({128, 10}); sut->configureMemoryManager(mempoolconf, allocator, allocator); - auto bla = sut->getChunk(50); + auto bla = sut->getChunk(50, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_THAT(bla, Eq(true)); } @@ -153,7 +158,7 @@ TEST_F(MemoryManager_test, getChunkSingleMemPoolAllChunks) std::vector chunkStore; for (size_t i = 0; i < ChunkCount; i++) { - chunkStore.push_back(sut->getChunk(50)); + chunkStore.push_back(sut->getChunk(50, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); } @@ -170,10 +175,10 @@ TEST_F(MemoryManager_test, getChunkSingleMemPoolToMuchChunks) std::vector chunkStore; for (size_t i = 0; i < ChunkCount; i++) { - chunkStore.push_back(sut->getChunk(128)); + chunkStore.push_back(sut->getChunk(128, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); } - EXPECT_THAT(sut->getChunk(128), Eq(false)); + EXPECT_THAT(sut->getChunk(128, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT), Eq(false)); } @@ -188,19 +193,19 @@ TEST_F(MemoryManager_test, freeChunkSingleMemPoolFullToEmptyToFull) sut->configureMemoryManager(mempoolconf, allocator, allocator); for (size_t i = 0; i < ChunkCount; i++) { - chunkStore.push_back(sut->getChunk(128)); + chunkStore.push_back(sut->getChunk(128, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); } EXPECT_THAT(sut->getMemPoolInfo(0).m_usedChunks, Eq(ChunkCount)); } - EXPECT_THAT(sut->getMemPoolInfo(0).m_usedChunks, Eq(0)); + EXPECT_THAT(sut->getMemPoolInfo(0).m_usedChunks, Eq(0U)); std::vector chunkStore; for (size_t i = 0; i < ChunkCount; i++) { - chunkStore.push_back(sut->getChunk(128)); + chunkStore.push_back(sut->getChunk(128, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); } @@ -216,16 +221,16 @@ TEST_F(MemoryManager_test, getChunkMultiMemPoolSingleChunk) sut->configureMemoryManager(mempoolconf, allocator, allocator); - auto bla = sut->getChunk(32); + auto bla = sut->getChunk(32, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_THAT(bla, Eq(true)); - bla = sut->getChunk(64); + bla = sut->getChunk(64, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_THAT(bla, Eq(true)); - bla = sut->getChunk(128); + bla = sut->getChunk(128, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_THAT(bla, Eq(true)); - bla = sut->getChunk(256); + bla = sut->getChunk(256, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_THAT(bla, Eq(true)); } @@ -242,16 +247,16 @@ TEST_F(MemoryManager_test, getChunkMultiMemPoolAllChunks) std::vector chunkStore; for (size_t i = 0; i < ChunkCount; i++) { - chunkStore.push_back(sut->getChunk(32)); + chunkStore.push_back(sut->getChunk(32U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); - chunkStore.push_back(sut->getChunk(64)); + chunkStore.push_back(sut->getChunk(64U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); - chunkStore.push_back(sut->getChunk(128)); + chunkStore.push_back(sut->getChunk(128U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); - chunkStore.push_back(sut->getChunk(256)); + chunkStore.push_back(sut->getChunk(256U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); } @@ -274,16 +279,16 @@ TEST_F(MemoryManager_test, getChunkMultiMemPoolTooMuchChunks) std::vector chunkStore; for (size_t i = 0; i < ChunkCount; i++) { - chunkStore.push_back(sut->getChunk(32)); - chunkStore.push_back(sut->getChunk(64)); - chunkStore.push_back(sut->getChunk(128)); - chunkStore.push_back(sut->getChunk(256)); + chunkStore.push_back(sut->getChunk(32U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); + chunkStore.push_back(sut->getChunk(64U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); + chunkStore.push_back(sut->getChunk(128U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); + chunkStore.push_back(sut->getChunk(256U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); } - EXPECT_THAT(sut->getChunk(32), Eq(false)); - EXPECT_THAT(sut->getChunk(64), Eq(false)); - EXPECT_THAT(sut->getChunk(128), Eq(false)); - EXPECT_THAT(sut->getChunk(256), Eq(false)); + EXPECT_THAT(sut->getChunk(32U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT), Eq(false)); + EXPECT_THAT(sut->getChunk(64U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT), Eq(false)); + EXPECT_THAT(sut->getChunk(128U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT), Eq(false)); + EXPECT_THAT(sut->getChunk(256U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT), Eq(false)); } TEST_F(MemoryManager_test, freeChunkMultiMemPoolFullToEmptyToFull) @@ -302,10 +307,10 @@ TEST_F(MemoryManager_test, freeChunkMultiMemPoolFullToEmptyToFull) for (size_t i = 0; i < ChunkCount; i++) { - chunkStore.push_back(sut->getChunk(32)); - chunkStore.push_back(sut->getChunk(64)); - chunkStore.push_back(sut->getChunk(128)); - chunkStore.push_back(sut->getChunk(256)); + chunkStore.push_back(sut->getChunk(32U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); + chunkStore.push_back(sut->getChunk(64U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); + chunkStore.push_back(sut->getChunk(128U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); + chunkStore.push_back(sut->getChunk(256U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); } EXPECT_THAT(sut->getMemPoolInfo(0).m_usedChunks, Eq(ChunkCount)); @@ -322,16 +327,16 @@ TEST_F(MemoryManager_test, freeChunkMultiMemPoolFullToEmptyToFull) std::vector chunkStore; for (size_t i = 0; i < ChunkCount; i++) { - chunkStore.push_back(sut->getChunk(32)); + chunkStore.push_back(sut->getChunk(32U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); - chunkStore.push_back(sut->getChunk(64)); + chunkStore.push_back(sut->getChunk(64U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); - chunkStore.push_back(sut->getChunk(128)); + chunkStore.push_back(sut->getChunk(128U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); - chunkStore.push_back(sut->getChunk(256)); + chunkStore.push_back(sut->getChunk(256U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); EXPECT_THAT(chunkStore.back(), Eq(true)); } @@ -343,7 +348,7 @@ TEST_F(MemoryManager_test, freeChunkMultiMemPoolFullToEmptyToFull) TEST_F(MemoryManager_test, getChunkWithSizeZeroShouldFail) { - EXPECT_DEATH({ sut->getChunk(0); }, ".*"); + EXPECT_DEATH({ sut->getChunk(0U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); }, ".*"); } TEST_F(MemoryManager_test, addMemPoolWithChunkCountZeroShouldFail) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp index 9210d75807..10ccbf3bd5 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp @@ -196,6 +196,9 @@ TEST_F(MePooSegment_test, ADD_TEST_WITH_ADDITIONAL_USER(GetMemoryManager)) ASSERT_THAT(sut.getMemoryManager().getNumberOfMemPools(), Eq(1U)); auto config = sut.getMemoryManager().getMemPoolInfo(0); ASSERT_THAT(config.m_numChunks, Eq(100U)); - auto chunk = sut.getMemoryManager().getChunk(128U); + auto chunk = sut.getMemoryManager().getChunk(128U, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); EXPECT_THAT(chunk.getChunkHeader()->payloadSize, Eq(128U)); } diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp index dd10fd3480..90de92c8db 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp @@ -56,6 +56,15 @@ class ChunkReceiver_test : public Test { } + + iox::mepoo::SharedChunk getChunkFromMemoryManager() + { + return m_memoryManager.getChunk(sizeof(DummySample), + alignof(DummySample), + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); + } + static constexpr size_t MEGABYTE = 1 << 20; static constexpr size_t MEMORY_SIZE = 4 * MEGABYTE; std::unique_ptr m_memory{new char[MEMORY_SIZE]}; @@ -89,7 +98,7 @@ TEST_F(ChunkReceiver_test, getAndReleaseOneChunk) { { // have a scope her to release the shared chunk we allocate - auto sharedChunk = m_memoryManager.getChunk(sizeof(DummySample)); + auto sharedChunk = getChunkFromMemoryManager(); EXPECT_TRUE(sharedChunk); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); m_chunkQueuePusher.push(sharedChunk); @@ -110,7 +119,7 @@ TEST_F(ChunkReceiver_test, getAndReleaseMultipleChunks) for (size_t i = 0; i < iox::MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY; i++) { - auto sharedChunk = m_memoryManager.getChunk(sizeof(DummySample)); + auto sharedChunk = getChunkFromMemoryManager(); EXPECT_TRUE(sharedChunk); auto sample = sharedChunk.getPayload(); new (sample) DummySample(); @@ -143,7 +152,7 @@ TEST_F(ChunkReceiver_test, getTooMuchWithoutRelease) // therefore MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY+1 for (size_t i = 0; i < iox::MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY + 1; i++) { - auto sharedChunk = m_memoryManager.getChunk(sizeof(DummySample)); + auto sharedChunk = getChunkFromMemoryManager(); EXPECT_TRUE(sharedChunk); m_chunkQueuePusher.push(sharedChunk); @@ -153,7 +162,7 @@ TEST_F(ChunkReceiver_test, getTooMuchWithoutRelease) } // but now it breaks - auto sharedChunk = m_memoryManager.getChunk(sizeof(DummySample)); + auto sharedChunk = getChunkFromMemoryManager(); EXPECT_TRUE(sharedChunk); m_chunkQueuePusher.push(sharedChunk); @@ -167,7 +176,7 @@ TEST_F(ChunkReceiver_test, releaseInvalidChunk) { { // have a scope her to release the shared chunk we allocate - auto sharedChunk = m_memoryManager.getChunk(sizeof(DummySample)); + auto sharedChunk = getChunkFromMemoryManager(); EXPECT_TRUE(sharedChunk); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); m_chunkQueuePusher.push(sharedChunk); @@ -195,7 +204,7 @@ TEST_F(ChunkReceiver_test, Cleanup) for (size_t i = 0; i < iox::MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY + iox::MAX_SUBSCRIBER_QUEUE_CAPACITY; i++) { // MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY on user side and MAX_SUBSCRIBER_QUEUE_CAPACITY in the queue - auto sharedChunk = m_memoryManager.getChunk(sizeof(DummySample)); + auto sharedChunk = getChunkFromMemoryManager(); EXPECT_TRUE(sharedChunk); m_chunkQueuePusher.push(sharedChunk); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp index a003a8ce49..d1ef13df10 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -70,6 +71,10 @@ class ChunkSender_test : public Test static constexpr uint64_t HISTORY_CAPACITY = 4; static constexpr uint32_t MAX_NUMBER_QUEUES = 128; + static constexpr uint32_t PAYLOAD_ALIGNMENT = iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT; + static constexpr uint32_t CUSTOM_HEADER_SIZE = iox::CHUNK_NO_CUSTOM_HEADER_SIZE; + static constexpr uint32_t CUSTOM_HEADER_ALIGNMENT = iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT; + iox::cxx::GenericRAII m_uniqueRouDiId{[] { iox::popo::internal::setUniqueRouDiId(0); }, [] { iox::popo::internal::unsetUniqueRouDiId(); }}; iox::posix::Allocator m_memoryAllocator{m_memory, MEMORY_SIZE}; @@ -105,7 +110,8 @@ class ChunkSender_test : public Test TEST_F(ChunkSender_test, allocate_OneChunk) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); } @@ -113,7 +119,8 @@ TEST_F(ChunkSender_test, allocate_OneChunk) TEST_F(ChunkSender_test, allocate_ChunkHasOriginIdSet) { iox::UniquePortId uniqueId; - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), uniqueId); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), uniqueId, alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT((*maybeChunkHeader)->originId, Eq(uniqueId)); @@ -121,8 +128,10 @@ TEST_F(ChunkSender_test, allocate_ChunkHasOriginIdSet) TEST_F(ChunkSender_test, allocate_MultipleChunks) { - auto chunk1 = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); - auto chunk2 = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto chunk1 = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + auto chunk2 = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(chunk1.has_error()); ASSERT_FALSE(chunk2.has_error()); @@ -138,7 +147,11 @@ TEST_F(ChunkSender_test, allocate_Overflow) // tryAllocate chunks until MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY level for (size_t i = 0; i < iox::MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + alignof(DummySample), + CUSTOM_HEADER_SIZE, + CUSTOM_HEADER_ALIGNMENT); if (!maybeChunkHeader.has_error()) { chunks.push_back(*maybeChunkHeader); @@ -153,7 +166,8 @@ TEST_F(ChunkSender_test, allocate_Overflow) Eq(iox::MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY)); // Allocate one more sample for overflow - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_TRUE(maybeChunkHeader.has_error()); EXPECT_THAT(maybeChunkHeader.get_error(), Eq(iox::popo::AllocationError::TOO_MANY_CHUNKS_ALLOCATED_IN_PARALLEL)); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, @@ -167,7 +181,11 @@ TEST_F(ChunkSender_test, freeChunk) // tryAllocate chunks until MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY level for (size_t i = 0; i < iox::MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + alignof(DummySample), + CUSTOM_HEADER_SIZE, + CUSTOM_HEADER_ALIGNMENT); if (!maybeChunkHeader.has_error()) { chunks.push_back(*maybeChunkHeader); @@ -188,7 +206,8 @@ TEST_F(ChunkSender_test, freeChunk) TEST_F(ChunkSender_test, freeInvalidChunk) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); @@ -207,7 +226,8 @@ TEST_F(ChunkSender_test, freeInvalidChunk) TEST_F(ChunkSender_test, sendWithoutReceiver) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); @@ -224,7 +244,11 @@ TEST_F(ChunkSender_test, sendMultipleWithoutReceiverAndAlwaysLast) { for (size_t i = 0; i < 100; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + alignof(DummySample), + CUSTOM_HEADER_SIZE, + CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); if (i > 0) @@ -251,7 +275,11 @@ TEST_F(ChunkSender_test, sendMultipleWithoutReceiverWithHistoryNoLastReuse) { for (size_t i = 0; i < 10 * HISTORY_CAPACITY; i++) { - auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + alignof(DummySample), + CUSTOM_HEADER_SIZE, + CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); auto maybeLastChunk = m_chunkSenderWithHistory.tryGetPreviousChunk(); if (i > 0) @@ -278,7 +306,8 @@ TEST_F(ChunkSender_test, sendOneWithReceiver) { m_chunkSender.tryAddQueue(&m_chunkQueueData); - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); @@ -295,7 +324,7 @@ TEST_F(ChunkSender_test, sendOneWithReceiver) auto popRet = myQueue.tryPop(); EXPECT_TRUE(popRet.has_value()); auto dummySample = *reinterpret_cast(popRet->getPayload()); - EXPECT_THAT(dummySample.dummy, Eq(42)); + EXPECT_THAT(dummySample.dummy, Eq(42U)); } } } @@ -308,7 +337,11 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiver) for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + alignof(DummySample), + CUSTOM_HEADER_SIZE, + CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); if (!maybeChunkHeader.has_error()) @@ -342,7 +375,7 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverExternalSequenceNumber) for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), HEADER_SIZE, HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); if (!maybeChunkHeader.has_error()) @@ -372,7 +405,11 @@ TEST_F(ChunkSender_test, sendTillRunningOutOfChunks) for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + alignof(DummySample), + CUSTOM_HEADER_SIZE, + CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); if (!maybeChunkHeader.has_error()) @@ -390,14 +427,16 @@ TEST_F(ChunkSender_test, sendTillRunningOutOfChunks) errorHandlerCalled = true; }); - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_TRUE(maybeChunkHeader.has_error()); EXPECT_THAT(maybeChunkHeader.get_error(), Eq(iox::popo::AllocationError::RUNNING_OUT_OF_CHUNKS)); } TEST_F(ChunkSender_test, sendInvalidChunk) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); @@ -418,7 +457,11 @@ TEST_F(ChunkSender_test, pushToHistory) { for (size_t i = 0; i < 10 * HISTORY_CAPACITY; i++) { - auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + alignof(DummySample), + CUSTOM_HEADER_SIZE, + CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); m_chunkSenderWithHistory.pushToHistory(*maybeChunkHeader); } @@ -429,7 +472,8 @@ TEST_F(ChunkSender_test, pushToHistory) TEST_F(ChunkSender_test, pushInvalidChunkToHistory) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); @@ -452,7 +496,11 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverNoLastReuse) for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + alignof(DummySample), + CUSTOM_HEADER_SIZE, + CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); if (i > 0) @@ -481,7 +529,11 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverLastReuseBecauseAlreadyConsumed for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), + iox::UniquePortId(), + alignof(DummySample), + CUSTOM_HEADER_SIZE, + CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); if (i > 0) @@ -511,14 +563,16 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverLastReuseBecauseAlreadyConsumed TEST_F(ChunkSender_test, ReuseLastIfSmaller) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(BIG_CHUNK, iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + BIG_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1u)); auto chunkHeader = *maybeChunkHeader; m_chunkSender.send(chunkHeader); - auto chunkSmaller = m_chunkSender.tryAllocate(SMALL_CHUNK, iox::UniquePortId()); + auto chunkSmaller = m_chunkSender.tryAllocate( + SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(chunkSmaller.has_error()); // no small chunk used as big one is recycled @@ -534,14 +588,16 @@ TEST_F(ChunkSender_test, ReuseLastIfSmaller) TEST_F(ChunkSender_test, NoReuseOfLastIfBigger) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(SMALL_CHUNK, iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); auto chunkHeader = *maybeChunkHeader; m_chunkSender.send(chunkHeader); - auto chunkBigger = m_chunkSender.tryAllocate(BIG_CHUNK, iox::UniquePortId()); + auto chunkBigger = m_chunkSender.tryAllocate( + BIG_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(chunkBigger.has_error()); // no reuse, we hav a small and a big chunk in use @@ -557,14 +613,16 @@ TEST_F(ChunkSender_test, NoReuseOfLastIfBigger) TEST_F(ChunkSender_test, ReuseOfLastIfBiggerButFitsInChunk) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(SMALL_CHUNK - 10, iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSender.tryAllocate( + SMALL_CHUNK - 10, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); auto chunkHeader = *maybeChunkHeader; m_chunkSender.send(chunkHeader); - auto chunkBigger = m_chunkSender.tryAllocate(SMALL_CHUNK, iox::UniquePortId()); + auto chunkBigger = m_chunkSender.tryAllocate( + SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(chunkBigger.has_error()); // reuse as it still fits in the small chunk @@ -584,14 +642,16 @@ TEST_F(ChunkSender_test, Cleanup) for (size_t i = 0; i < HISTORY_CAPACITY; i++) { - auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(SMALL_CHUNK, iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate( + SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); m_chunkSenderWithHistory.send(*maybeChunkHeader); } for (size_t i = 0; i < iox::MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY; i++) { - auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(SMALL_CHUNK, iox::UniquePortId()); + auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate( + SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); } diff --git a/iceoryx_posh/test/moduletests/test_popo_publisher.cpp b/iceoryx_posh/test/moduletests/test_popo_publisher.cpp index 88164f10b5..769adf1b31 100644 --- a/iceoryx_posh/test/moduletests/test_popo_publisher.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_publisher.cpp @@ -70,7 +70,7 @@ class PublisherTest : public Test TEST_F(PublisherTest, LoansChunkLargeEnoughForTheType) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); // ===== Test ===== // auto result = sut.loan(); @@ -82,7 +82,7 @@ TEST_F(PublisherTest, LoansChunkLargeEnoughForTheType) TEST_F(PublisherTest, LoanedSampleIsDefaultInitialized) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); // ===== Test ===== // auto result = sut.loan(); @@ -96,7 +96,7 @@ TEST_F(PublisherTest, LoanedSampleIsDefaultInitialized) TEST_F(PublisherTest, LoanWithArgumentsCallsCustomCtor) { constexpr uint64_t CUSTOM_VALUE{73}; - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); // ===== Test ===== // auto result = sut.loan(CUSTOM_VALUE); @@ -131,7 +131,7 @@ TEST_F(PublisherTest, LoanPreviousSampleFails) TEST_F(PublisherTest, CanLoanSamplesAndPublishTheResultOfALambdaWithAdditionalArguments) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); EXPECT_CALL(portMock, sendChunk(chunkMock.chunkHeader())); // ===== Test ===== // @@ -148,7 +148,7 @@ TEST_F(PublisherTest, CanLoanSamplesAndPublishTheResultOfALambdaWithAdditionalAr TEST_F(PublisherTest, CanLoanSamplesAndPublishTheResultOfALambdaWithNoAdditionalArguments) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); EXPECT_CALL(portMock, sendChunk(chunkMock.chunkHeader())); // ===== Test ===== // @@ -171,7 +171,7 @@ TEST_F(PublisherTest, CanLoanSamplesAndPublishTheResultOfACallableStructWithNoAd data->val = 777; }; }; - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); EXPECT_CALL(portMock, sendChunk(chunkMock.chunkHeader())); // ===== Test ===== // @@ -191,7 +191,7 @@ TEST_F(PublisherTest, CanLoanSamplesAndPublishTheResultOfACallableStructWithAddi data->val = 777; }; }; - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); EXPECT_CALL(portMock, sendChunk(chunkMock.chunkHeader())); // ===== Test ===== // @@ -214,7 +214,7 @@ void freeFunctionWithAdditionalArgs(DummyData* allocation, int, float) TEST_F(PublisherTest, CanLoanSamplesAndPublishTheResultOfFunctionPointerWithNoAdditionalArguments) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); EXPECT_CALL(portMock, sendChunk(chunkMock.chunkHeader())); // ===== Test ===== // @@ -226,7 +226,7 @@ TEST_F(PublisherTest, CanLoanSamplesAndPublishTheResultOfFunctionPointerWithNoAd TEST_F(PublisherTest, CanLoanSamplesAndPublishTheResultOfFunctionPointerWithAdditionalArguments) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); EXPECT_CALL(portMock, sendChunk(chunkMock.chunkHeader())); // ===== Test ===== // @@ -238,7 +238,7 @@ TEST_F(PublisherTest, CanLoanSamplesAndPublishTheResultOfFunctionPointerWithAddi TEST_F(PublisherTest, CanLoanSamplesAndPublishCopiesOfProvidedValues) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); EXPECT_CALL(portMock, sendChunk(chunkMock.chunkHeader())); DummyData data(73); @@ -251,7 +251,7 @@ TEST_F(PublisherTest, CanLoanSamplesAndPublishCopiesOfProvidedValues) TEST_F(PublisherTest, LoanFailsAndForwardsAllocationErrorsToCaller) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return( ByMove(iox::cxx::error(iox::popo::AllocationError::RUNNING_OUT_OF_CHUNKS)))); // ===== Test ===== // @@ -265,7 +265,7 @@ TEST_F(PublisherTest, LoanFailsAndForwardsAllocationErrorsToCaller) TEST_F(PublisherTest, LoanedSamplesContainPointerToChunkHeader) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); // ===== Test ===== // auto result = sut.loan(); @@ -278,7 +278,7 @@ TEST_F(PublisherTest, LoanedSamplesContainPointerToChunkHeader) TEST_F(PublisherTest, PublishingSendsUnderlyingMemoryChunkOnPublisherPort) { - EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData))) + EXPECT_CALL(portMock, tryAllocateChunk(sizeof(DummyData), _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); EXPECT_CALL(portMock, sendChunk(chunkMock.chunkHeader())); // ===== Test ===== // diff --git a/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp b/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp index a6ac715833..496a03140c 100644 --- a/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp @@ -65,6 +65,10 @@ class PublisherPort_test : public Test static constexpr uint32_t NUM_CHUNKS_IN_POOL = 20; static constexpr uint32_t CHUNK_SIZE = 128; + static constexpr uint32_t PAYLOAD_ALIGNMENT = iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT; + static constexpr uint32_t CUSTOM_HEADER_SIZE = iox::CHUNK_NO_CUSTOM_HEADER_SIZE; + static constexpr uint32_t CUSTOM_HEADER_ALIGNMENT = iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT; + using ChunkQueueData_t = iox::popo::ChunkQueueData; iox::cxx::GenericRAII m_uniqueRouDiId{[] { iox::popo::internal::setUniqueRouDiId(0); }, @@ -148,7 +152,7 @@ TEST_F(PublisherPort_test, offerCallResultsInOfferCaProMessage) EXPECT_THAT(caproMessage.m_type, Eq(iox::capro::CaproMessageType::OFFER)); EXPECT_THAT(caproMessage.m_serviceDescription, Eq(iox::capro::ServiceDescription("a", "b", "c"))); EXPECT_THAT(caproMessage.m_subType, Eq(iox::capro::CaproMessageSubType::EVENT)); - EXPECT_THAT(caproMessage.m_historyCapacity, Eq(0u)); + EXPECT_THAT(caproMessage.m_historyCapacity, Eq(0U)); } TEST_F(PublisherPort_test, stopOfferCallResultsInNotOfferedState) @@ -202,26 +206,29 @@ TEST_F(PublisherPort_test, TEST_F(PublisherPort_test, allocatingAChunk) { - auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk(10u); + auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + 10U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } TEST_F(PublisherPort_test, releasingAnAllocatedChunkReleasesTheMemory) { - auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk(10u); + auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + 10U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); auto chunkHeader = maybeChunkHeader.value(); m_sutNoOfferOnCreateUserSide.releaseChunk(chunkHeader); // this one is not stored in the last chunk, so all chunks must be free again - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0U)); } TEST_F(PublisherPort_test, allocatedChunkContainsPublisherIdAsOriginId) { - auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk(10u); + auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + 10U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); auto chunkHeader = maybeChunkHeader.value(); EXPECT_THAT(chunkHeader->originId, Eq(m_sutNoOfferOnCreateUserSide.getUniqueID())); @@ -230,29 +237,33 @@ TEST_F(PublisherPort_test, allocatedChunkContainsPublisherIdAsOriginId) TEST_F(PublisherPort_test, allocateAndSendAChunkWithoutSubscriberHoldsTheLast) { - auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk(10u); + auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + 10U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); auto chunkHeader = maybeChunkHeader.value(); m_sutNoOfferOnCreateUserSide.sendChunk(chunkHeader); // this one is stored in the last chunk, so this chunk is still in use - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } TEST_F(PublisherPort_test, allocateAndSendMultipleChunksWithoutSubscriberHoldsOnlyTheLast) { - auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk(10u); + auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + 10U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); auto chunkHeader = maybeChunkHeader.value(); m_sutNoOfferOnCreateUserSide.sendChunk(chunkHeader); - maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk(10u); + maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + 10U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); chunkHeader = maybeChunkHeader.value(); m_sutNoOfferOnCreateUserSide.sendChunk(chunkHeader); - maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk(10u); + maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + 10U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); chunkHeader = maybeChunkHeader.value(); m_sutNoOfferOnCreateUserSide.sendChunk(chunkHeader); // the last is stored in the last chunk, so one chunk is still in use - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } TEST_F(PublisherPort_test, subscribeWhenNotOfferedReturnsNACK) @@ -261,7 +272,7 @@ TEST_F(PublisherPort_test, subscribeWhenNotOfferedReturnsNACK) iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::SUB, iox::capro::ServiceDescription("a", "b", "c")); caproMessage.m_chunkQueueData = &m_chunkQueueData; - caproMessage.m_historyCapacity = 0u; + caproMessage.m_historyCapacity = 0U; auto maybeCaProMessage = m_sutNoOfferOnCreateRouDiSide.dispatchCaProMessageAndGetPossibleResponse(caproMessage); @@ -278,7 +289,7 @@ TEST_F(PublisherPort_test, unsubscribeWhenNotSubscribedReturnsNACK) iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::UNSUB, iox::capro::ServiceDescription("a", "b", "c")); caproMessage.m_chunkQueueData = &m_chunkQueueData; - caproMessage.m_historyCapacity = 0u; + caproMessage.m_historyCapacity = 0U; auto maybeCaproMessage = m_sutNoOfferOnCreateRouDiSide.dispatchCaProMessageAndGetPossibleResponse(caproMessage); @@ -295,7 +306,7 @@ TEST_F(PublisherPort_test, subscribeWhenOfferedReturnsACKAndWeHaveSubscribers) iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::SUB, iox::capro::ServiceDescription("a", "b", "c")); caproMessage.m_chunkQueueData = &m_chunkQueueData; - caproMessage.m_historyCapacity = 0u; + caproMessage.m_historyCapacity = 0U; auto maybeCaProMessage = m_sutNoOfferOnCreateRouDiSide.dispatchCaProMessageAndGetPossibleResponse(caproMessage); @@ -313,7 +324,7 @@ TEST_F(PublisherPort_test, unsubscribeWhenSubscribedReturnsACKAndWeHaveNoMoreSub iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::SUB, iox::capro::ServiceDescription("a", "b", "c")); caproMessage.m_chunkQueueData = &m_chunkQueueData; - caproMessage.m_historyCapacity = 0u; + caproMessage.m_historyCapacity = 0U; auto maybeCaProMessage = m_sutNoOfferOnCreateRouDiSide.dispatchCaProMessageAndGetPossibleResponse(caproMessage); // set CaPro message to UNSUB, the other members are reused caproMessage.m_type = iox::capro::CaproMessageType::UNSUB; @@ -337,7 +348,7 @@ TEST_F(PublisherPort_test, subscribeManyIsFine) iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::SUB, iox::capro::ServiceDescription("a", "b", "c")); caproMessage.m_chunkQueueData = reinterpret_cast(dummyPtr); - caproMessage.m_historyCapacity = 0u; + caproMessage.m_historyCapacity = 0U; for (size_t i = 0; i < iox::MAX_SUBSCRIBERS_PER_PUBLISHER; i++) { @@ -361,7 +372,7 @@ TEST_F(PublisherPort_test, subscribeTillOverflowReturnsNACK) iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::SUB, iox::capro::ServiceDescription("a", "b", "c")); caproMessage.m_chunkQueueData = reinterpret_cast(dummyPtr); - caproMessage.m_historyCapacity = 0u; + caproMessage.m_historyCapacity = 0U; for (size_t i = 0; i < iox::MAX_SUBSCRIBERS_PER_PUBLISHER; i++) { m_sutNoOfferOnCreateRouDiSide.dispatchCaProMessageAndGetPossibleResponse(caproMessage); @@ -384,9 +395,10 @@ TEST_F(PublisherPort_test, sendWhenSubscribedDeliversAChunk) iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::SUB, iox::capro::ServiceDescription("a", "b", "c")); caproMessage.m_chunkQueueData = &m_chunkQueueData; - caproMessage.m_historyCapacity = 0u; + caproMessage.m_historyCapacity = 0U; m_sutNoOfferOnCreateRouDiSide.dispatchCaProMessageAndGetPossibleResponse(caproMessage); - auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk(sizeof(DummySample)); + auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); auto chunkHeader = maybeChunkHeader.value(); auto sample = chunkHeader->payload(); new (sample) DummySample(); @@ -412,7 +424,8 @@ TEST_F(PublisherPort_test, subscribeWithHistoryLikeTheARAField) iox::popo::PublisherPortRouDi sutWithHistoryRouDiSide{&publisherPortDataHistory}; // do it the ara field like way // 1. publish a chunk to a not yet offered publisher - auto maybeChunkHeader = sutWithHistoryUseriSide.tryAllocateChunk(sizeof(DummySample)); + auto maybeChunkHeader = sutWithHistoryUseriSide.tryAllocateChunk( + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); auto chunkHeader = maybeChunkHeader.value(); auto sample = chunkHeader->payload(); new (sample) DummySample(); @@ -426,7 +439,7 @@ TEST_F(PublisherPort_test, subscribeWithHistoryLikeTheARAField) iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::SUB, iox::capro::ServiceDescription("a", "b", "c")); caproMessage.m_chunkQueueData = &m_chunkQueueData; - caproMessage.m_historyCapacity = 1u; // request history of 1 + caproMessage.m_historyCapacity = 1U; // request history of 1 sutWithHistoryRouDiSide.dispatchCaProMessageAndGetPossibleResponse(caproMessage); iox::popo::ChunkQueuePopper m_chunkQueuePopper(&m_chunkQueueData); @@ -448,7 +461,8 @@ TEST_F(PublisherPort_test, noLastChunkWhenNothingSent) TEST_F(PublisherPort_test, lastChunkAvailableAfterSend) { - auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk(10u); + auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + 10U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); auto chunkHeader = maybeChunkHeader.value(); auto firstPayloadPtr = chunkHeader->payload(); m_sutNoOfferOnCreateUserSide.sendChunk(chunkHeader); @@ -464,16 +478,20 @@ TEST_F(PublisherPort_test, cleanupReleasesAllChunks) // push some chunks to history for (size_t i = 0; i < iox::MAX_PUBLISHER_HISTORY; i++) { - auto maybeChunkHeader = m_sutWithHistoryUserSide.tryAllocateChunk(sizeof(DummySample)); + auto maybeChunkHeader = m_sutWithHistoryUserSide.tryAllocateChunk( + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); auto chunkHeader = maybeChunkHeader.value(); m_sutWithHistoryUserSide.sendChunk(chunkHeader); } // allocate some samples - auto maybeChunkHeader1 = m_sutWithHistoryUserSide.tryAllocateChunk(sizeof(DummySample)); - auto maybeChunkHeader2 = m_sutWithHistoryUserSide.tryAllocateChunk(sizeof(DummySample)); - auto maybeChunkHeader3 = m_sutWithHistoryUserSide.tryAllocateChunk(sizeof(DummySample)); + auto maybeChunkHeader1 = m_sutWithHistoryUserSide.tryAllocateChunk( + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + auto maybeChunkHeader2 = m_sutWithHistoryUserSide.tryAllocateChunk( + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + auto maybeChunkHeader3 = m_sutWithHistoryUserSide.tryAllocateChunk( + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); m_sutWithHistoryRouDiSide.releaseAllChunks(); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0U)); } diff --git a/iceoryx_posh/test/moduletests/test_popo_untyped_publisher.cpp b/iceoryx_posh/test/moduletests/test_popo_untyped_publisher.cpp index 92736c25c6..1f00986993 100644 --- a/iceoryx_posh/test/moduletests/test_popo_untyped_publisher.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_untyped_publisher.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2021 by Apex.AI Inc. All rights reserved. // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -50,7 +50,7 @@ class UntypedPublisherTest : public Test TEST_F(UntypedPublisherTest, LoansChunkWithRequestedSize) { constexpr uint32_t ALLOCATION_SIZE = 7U; - EXPECT_CALL(portMock, tryAllocateChunk(ALLOCATION_SIZE)) + EXPECT_CALL(portMock, tryAllocateChunk(ALLOCATION_SIZE, _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); // ===== Test ===== // auto result = sut.loan(ALLOCATION_SIZE); @@ -62,7 +62,7 @@ TEST_F(UntypedPublisherTest, LoansChunkWithRequestedSize) TEST_F(UntypedPublisherTest, LoanFailsIfPortCannotSatisfyAllocationRequest) { constexpr uint32_t ALLOCATION_SIZE = 17U; - EXPECT_CALL(portMock, tryAllocateChunk(ALLOCATION_SIZE)) + EXPECT_CALL(portMock, tryAllocateChunk(ALLOCATION_SIZE, _, _, _)) .WillOnce(Return( ByMove(iox::cxx::error(iox::popo::AllocationError::RUNNING_OUT_OF_CHUNKS)))); // ===== Test ===== // @@ -97,7 +97,7 @@ TEST_F(UntypedPublisherTest, LoanPreviousChunkFails) TEST_F(UntypedPublisherTest, ReleaseDelegatesCallToPort) { constexpr uint32_t ALLOCATION_SIZE = 7U; - EXPECT_CALL(portMock, tryAllocateChunk(ALLOCATION_SIZE)) + EXPECT_CALL(portMock, tryAllocateChunk(ALLOCATION_SIZE, _, _, _)) .WillOnce(Return(ByMove(iox::cxx::success(chunkMock.chunkHeader())))); auto result = sut.loan(ALLOCATION_SIZE); diff --git a/iceoryx_posh/test/moduletests/test_roudi_mempool_introspection.cpp b/iceoryx_posh/test/moduletests/test_roudi_mempool_introspection.cpp index 14508c351b..89a483fac9 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_mempool_introspection.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_mempool_introspection.cpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -209,7 +210,7 @@ TEST_F(MemPoolIntrospection_test, send_noSubscribers) MemPoolInfoContainer memPoolInfoContainer; initMemPoolInfoContainer(memPoolInfoContainer); - EXPECT_CALL(introspectionAccess.getPublisherPort(), tryAllocateChunk(_)).Times(0); + EXPECT_CALL(introspectionAccess.getPublisherPort(), tryAllocateChunk(_, _, _, _)).Times(0); introspectionAccess.send(); } diff --git a/iceoryx_posh/test/moduletests/test_roudi_port_introspection.cpp b/iceoryx_posh/test/moduletests/test_roudi_port_introspection.cpp index b5794cde9d..c2d5eec3d0 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_port_introspection.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_port_introspection.cpp @@ -170,7 +170,7 @@ TEST_F(PortIntrospection_test, sendPortData_EmptyList) auto chunk = std::unique_ptr>(new ChunkMock); bool chunkWasSent = false; - EXPECT_CALL(m_introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_)) + EXPECT_CALL(m_introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_, _, _, _)) .WillOnce(Return(iox::cxx::expected::create_value( chunk.get()->chunkHeader()))); @@ -234,7 +234,7 @@ TEST_F(PortIntrospection_test, addAndRemovePublisher) EXPECT_THAT(m_introspectionAccess.addPublisher(portData2), Eq(true)); EXPECT_THAT(m_introspectionAccess.addPublisher(portData2), Eq(false)); - EXPECT_CALL(m_introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_)) + EXPECT_CALL(m_introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_, _, _, _)) .WillRepeatedly(Return(iox::cxx::expected::create_value( chunk.get()->chunkHeader()))); @@ -365,7 +365,7 @@ TEST_F(PortIntrospection_test, addAndRemoveSubscriber) EXPECT_THAT(m_introspectionAccess.addSubscriber(recData2), Eq(true)); EXPECT_THAT(m_introspectionAccess.addSubscriber(recData2), Eq(false)); - EXPECT_CALL(m_introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_)) + EXPECT_CALL(m_introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_, _, _, _)) .WillRepeatedly(Return(iox::cxx::expected::create_value( chunk.get()->chunkHeader()))); @@ -471,4 +471,3 @@ TEST_F(PortIntrospection_test, DISABLED_thread) std::this_thread::sleep_for( std::chrono::milliseconds(555)); // if the thread doesn't stop, we have 12 runs after the sleep period } - diff --git a/iceoryx_posh/test/moduletests/test_roudi_process_introspection.cpp b/iceoryx_posh/test/moduletests/test_roudi_process_introspection.cpp index f1db8e962d..81954e47fa 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_process_introspection.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_process_introspection.cpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019, 2020 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -66,7 +67,7 @@ class ProcessIntrospection_test : public Test ChunkMock* createMemoryChunkAndSend(ProcessIntrospectionAccess& introspectionAccess) { - EXPECT_CALL(introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_)) + EXPECT_CALL(introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_, _, _, _)) .WillOnce(Return(iox::cxx::expected::create_value( m_chunk.get()->chunkHeader()))); @@ -159,7 +160,7 @@ TEST_F(ProcessIntrospection_test, thread) introspectionAccess.registerPublisherPort(std::move(m_mockPublisherPortUserIntrospection)); - EXPECT_CALL(introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_)) + EXPECT_CALL(introspectionAccess.getPublisherPort().value(), tryAllocateChunk(_, _, _, _)) .WillRepeatedly( Return(iox::cxx::expected::create_value( m_chunk.get()->chunkHeader()))); From 1da239e3b5c8fdd118afa46ce32e8d3cb5590558 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Tue, 2 Mar 2021 12:41:55 +0100 Subject: [PATCH 52/89] iox-#14 pass the payload alignment and custom header parameter to all methods Signed-off-by: Mathias Kraus --- .../internal/mepoo/memory_manager.hpp | 9 +++-- .../internal/mepoo/typed_mem_pool.hpp | 2 +- .../internal/mepoo/typed_mem_pool.inl | 18 +++++---- .../popo/building_blocks/chunk_sender.inl | 3 +- iceoryx_posh/source/mepoo/memory_manager.cpp | 38 +++++++++---------- .../moduletests/test_mepoo_memory_manager.cpp | 18 --------- 6 files changed, 37 insertions(+), 51 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp index 14474c17c5..ad47b39610 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp @@ -57,19 +57,22 @@ class MemoryManager const uint32_t customHeaderSize, const uint32_t customHeaderAlignment); - uint32_t getMempoolChunkSizeForPayloadSize(const uint32_t f_size) const; - uint32_t getNumberOfMemPools() const; MemPoolInfo getMemPoolInfo(uint32_t f_index) const; - static uint32_t sizeWithChunkHeaderStruct(const MaxSize_t f_size); + static uint32_t requiredChunkSize(const uint32_t payloadSize, + const uint32_t payloadAlignment, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment); static uint64_t requiredChunkMemorySize(const MePooConfig& f_mePooConfig); static uint64_t requiredManagementMemorySize(const MePooConfig& f_mePooConfig); static uint64_t requiredFullMemorySize(const MePooConfig& f_mePooConfig); private: + static uint32_t sizeWithChunkHeaderStruct(const MaxSize_t f_size); + void printMemPoolVector() const; void addMemPool(posix::Allocator* f_managementAllocator, posix::Allocator* f_payloadAllocator, diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.hpp index ee76166351..02196bf591 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.hpp @@ -65,9 +65,9 @@ class TypedMemPool static uint64_t requiredManagementMemorySize(const uint64_t f_numberOfChunks) noexcept; static uint64_t requiredChunkMemorySize(const uint64_t f_numberOfChunks) noexcept; static uint64_t requiredFullMemorySize(const uint64_t f_numberOfChunks) noexcept; - static uint64_t getAdjustedPayloadSize() noexcept; private: + static uint64_t requiredChunkSize() noexcept; cxx::expected acquireChunkManagementPointer() noexcept; private: diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl index 053e70f2dc..be9672896f 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl @@ -1,4 +1,5 @@ -// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -29,8 +30,7 @@ template inline TypedMemPool::TypedMemPool(const cxx::greater_or_equal f_numberOfChunks, posix::Allocator* f_managementAllocator, posix::Allocator* f_payloadAllocator) noexcept - : m_memPool( - static_cast(getAdjustedPayloadSize()), f_numberOfChunks, f_managementAllocator, f_payloadAllocator) + : m_memPool(static_cast(requiredChunkSize()), f_numberOfChunks, f_managementAllocator, f_payloadAllocator) , m_chunkManagementPool(sizeof(ChunkManagement), f_numberOfChunks, f_managementAllocator, f_managementAllocator) { } @@ -122,11 +122,13 @@ inline uint32_t TypedMemPool::getUsedChunks() const noexcept } template -inline uint64_t TypedMemPool::getAdjustedPayloadSize() noexcept +inline uint64_t TypedMemPool::requiredChunkSize() noexcept { - return cxx::align(std::max(static_cast(MemoryManager::sizeWithChunkHeaderStruct(sizeof(T))), - posix::Allocator::MEMORY_ALIGNMENT), - MemPool::MEMORY_ALIGNMENT); + return cxx::align( + std::max(static_cast(MemoryManager::requiredChunkSize( + sizeof(T), alignof(T), CHUNK_NO_CUSTOM_HEADER_SIZE, CHUNK_NO_CUSTOM_HEADER_ALIGNMENT)), + posix::Allocator::MEMORY_ALIGNMENT), + MemPool::MEMORY_ALIGNMENT); } template @@ -141,7 +143,7 @@ inline uint64_t TypedMemPool::requiredManagementMemorySize(const uint64_t f_n template inline uint64_t TypedMemPool::requiredChunkMemorySize(const uint64_t f_numberOfChunks) noexcept { - return f_numberOfChunks * getAdjustedPayloadSize(); + return f_numberOfChunks * requiredChunkSize(); } template diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl index e2997cb16a..43bb31f3f3 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl @@ -49,7 +49,8 @@ ChunkSender::tryAllocate(const uint32_t payloadSize, const uint32_t customHeaderAlignment) noexcept { // use the chunk stored in m_lastChunk if there is one, there is no other owner and the new payload still fits in it - const uint32_t neededChunkSize = getMembers()->m_memoryMgr->sizeWithChunkHeaderStruct(payloadSize); + const uint32_t neededChunkSize = getMembers()->m_memoryMgr->requiredChunkSize( + payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); if (getMembers()->m_lastChunk && getMembers()->m_lastChunk.hasNoOtherOwners() && (getMembers()->m_lastChunk.getChunkHeader()->chunkSize >= neededChunkSize)) diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index 8edbfe763f..1f772c599b 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -90,19 +90,13 @@ MemPoolInfo MemoryManager::getMemPoolInfo(uint32_t index) const return m_memPoolVector[index].getInfo(); } -uint32_t MemoryManager::getMempoolChunkSizeForPayloadSize(const uint32_t f_size) const +uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, + const uint32_t payloadAlignment [[gnu::unused]], + const uint32_t customHeaderSize [[gnu::unused]], + const uint32_t customHeaderAlignment [[gnu::unused]]) { - uint32_t adjustedSize = MemoryManager::sizeWithChunkHeaderStruct(f_size); - for (auto& memPool : m_memPoolVector) - { - const auto chunkSize = memPool.getChunkSize(); - if (chunkSize >= adjustedSize) - { - return chunkSize; - } - } - - return 0; + // TODO iox-#14 calculate correct size + return payloadSize + static_cast(sizeof(ChunkHeader)); } uint32_t MemoryManager::sizeWithChunkHeaderStruct(const MaxSize_t f_size) @@ -113,10 +107,14 @@ uint32_t MemoryManager::sizeWithChunkHeaderStruct(const MaxSize_t f_size) uint64_t MemoryManager::requiredChunkMemorySize(const MePooConfig& f_mePooConfig) { uint64_t memorySize{0}; - for (const auto& mempool : f_mePooConfig.m_mempoolConfig) + for (const auto& mempoolConfig : f_mePooConfig.m_mempoolConfig) { - memorySize += - static_cast(mempool.m_chunkCount) * MemoryManager::sizeWithChunkHeaderStruct(mempool.m_size); + // for the required chunk memory size only the size of the ChunkHeader + // and the the payload size is taken into account; + // the user has the option to further partition the chunk payload with + // a custom header and therefore reduce the user payload size + memorySize += static_cast(mempoolConfig.m_chunkCount) + * MemoryManager::sizeWithChunkHeaderStruct(mempoolConfig.m_size); } return memorySize; } @@ -157,14 +155,14 @@ void MemoryManager::configureMemoryManager(const MePooConfig& f_mePooConfig, } SharedChunk MemoryManager::getChunk(const MaxSize_t f_size, - const uint32_t payloadAlignment [[gnu::unused]], - const uint32_t customHeaderSize [[gnu::unused]], - const uint32_t customHeaderAlignment [[gnu::unused]]) + const uint32_t payloadAlignment, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment) { void* chunk{nullptr}; MemPool* memPoolPointer{nullptr}; - // TODO iox-#14 calculate correct size - uint32_t adjustedSize = MemoryManager::sizeWithChunkHeaderStruct(f_size); + uint32_t adjustedSize = + MemoryManager::requiredChunkSize(f_size, payloadAlignment, customHeaderSize, customHeaderAlignment); uint32_t totalSizeOfAquiredChunk = 0; for (auto& memPool : m_memPoolVector) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 8dd99fcdac..22819a5483 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -67,24 +67,6 @@ TEST_F(MemoryManager_test, addMemPoolWrongOrderAtLastElement) EXPECT_DEATH({ sut->configureMemoryManager(mempoolconf, allocator, allocator); }, ".*"); } -TEST_F(MemoryManager_test, getMempoolChunkSizeForPayloadSize) -{ - mempoolconf.addMemPool({32, 10}); - mempoolconf.addMemPool({64, 10}); - mempoolconf.addMemPool({128, 10}); - sut->configureMemoryManager(mempoolconf, allocator, allocator); - EXPECT_THAT(sut->getMempoolChunkSizeForPayloadSize(50), Eq(adjustedChunkSize(64u))); -} - -TEST_F(MemoryManager_test, getChunkSizeForWrongSampleSize) -{ - mempoolconf.addMemPool({32, 10}); - mempoolconf.addMemPool({64, 10}); - mempoolconf.addMemPool({128, 10}); - sut->configureMemoryManager(mempoolconf, allocator, allocator); - EXPECT_THAT(sut->getMempoolChunkSizeForPayloadSize(129), Eq(0u)); -} - TEST_F(MemoryManager_test, wrongcallConfigureMemoryManager) { mempoolconf.addMemPool({32, 10}); From edeea72d51e9034492d4be849cc7e3d6907d5e9b Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Tue, 2 Mar 2021 13:17:09 +0100 Subject: [PATCH 53/89] iox-#14 remove ivalid restriction for payload size from getChunk Signed-off-by: Mathias Kraus --- .../iceoryx_posh/internal/mepoo/memory_manager.hpp | 6 +++--- iceoryx_posh/source/mepoo/memory_manager.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp index ad47b39610..022756c7b7 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp @@ -38,7 +38,7 @@ struct MePooConfig; class MemoryManager { - using MaxSize_t = cxx::range::max() - sizeof(ChunkHeader)>; + using MaxChunkPayloadSize_t = cxx::range::max() - sizeof(ChunkHeader)>; public: MemoryManager() = default; @@ -52,7 +52,7 @@ class MemoryManager posix::Allocator* f_managementAllocator, posix::Allocator* f_payloadAllocator); - SharedChunk getChunk(const MaxSize_t f_size, + SharedChunk getChunk(const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment); @@ -71,7 +71,7 @@ class MemoryManager static uint64_t requiredFullMemorySize(const MePooConfig& f_mePooConfig); private: - static uint32_t sizeWithChunkHeaderStruct(const MaxSize_t f_size); + static uint32_t sizeWithChunkHeaderStruct(const MaxChunkPayloadSize_t size); void printMemPoolVector() const; void addMemPool(posix::Allocator* f_managementAllocator, diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index 1f772c599b..384808715c 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -99,9 +99,9 @@ uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, return payloadSize + static_cast(sizeof(ChunkHeader)); } -uint32_t MemoryManager::sizeWithChunkHeaderStruct(const MaxSize_t f_size) +uint32_t MemoryManager::sizeWithChunkHeaderStruct(const MaxChunkPayloadSize_t size) { - return f_size + static_cast(sizeof(ChunkHeader)); + return size + static_cast(sizeof(ChunkHeader)); } uint64_t MemoryManager::requiredChunkMemorySize(const MePooConfig& f_mePooConfig) @@ -154,7 +154,7 @@ void MemoryManager::configureMemoryManager(const MePooConfig& f_mePooConfig, generateChunkManagementPool(f_managementAllocator); } -SharedChunk MemoryManager::getChunk(const MaxSize_t f_size, +SharedChunk MemoryManager::getChunk(const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment) @@ -162,7 +162,7 @@ SharedChunk MemoryManager::getChunk(const MaxSize_t f_size, void* chunk{nullptr}; MemPool* memPoolPointer{nullptr}; uint32_t adjustedSize = - MemoryManager::requiredChunkSize(f_size, payloadAlignment, customHeaderSize, customHeaderAlignment); + MemoryManager::requiredChunkSize(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); uint32_t totalSizeOfAquiredChunk = 0; for (auto& memPool : m_memPoolVector) @@ -195,7 +195,7 @@ SharedChunk MemoryManager::getChunk(const MaxSize_t f_size, } else if (chunk == nullptr) { - std::cerr << "MemoryManager: unable to acquire a chunk with a payload size of " << f_size << std::endl; + std::cerr << "MemoryManager: unable to acquire a chunk with a payload size of " << payloadSize << std::endl; std::cerr << "The following mempools are available:" << std::endl; printMemPoolVector(); errorHandler(Error::kMEPOO__MEMPOOL_GETCHUNK_POOL_IS_RUNNING_OUT_OF_CHUNKS, nullptr, ErrorLevel::MODERATE); @@ -205,7 +205,7 @@ SharedChunk MemoryManager::getChunk(const MaxSize_t f_size, { auto chunkHeader = new (chunk) ChunkHeader(); chunkHeader->chunkSize = totalSizeOfAquiredChunk; - chunkHeader->payloadSize = f_size; + chunkHeader->payloadSize = payloadSize; auto chunkManagement = new (m_chunkManagementPool.front().getChunk()) ChunkManagement(chunkHeader, memPoolPointer, &m_chunkManagementPool.front()); return SharedChunk(chunkManagement); From 87836f96c81448070cb9b0072e28e81d5b05a776 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 3 Mar 2021 09:31:03 +0100 Subject: [PATCH 54/89] iox-#14 half way with calculation for custom header Signed-off-by: Mathias Kraus --- .../internal/mepoo/typed_mem_pool.inl | 2 +- .../iceoryx_posh/mepoo/chunk_header.hpp | 33 +++++++--- iceoryx_posh/source/mepoo/chunk_header.cpp | 7 +++ iceoryx_posh/source/mepoo/memory_manager.cpp | 60 +++++++++++++++---- iceoryx_posh/test/mocks/chunk_mock.hpp | 19 ++++-- .../moduletests/test_mepoo_shared_chunk.cpp | 7 ++- .../moduletests/test_mepoo_shared_pointer.cpp | 11 +++- .../test_popo_chunk_distributor.cpp | 10 +++- .../moduletests/test_popo_chunk_queue.cpp | 10 +++- 9 files changed, 125 insertions(+), 34 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl index be9672896f..39c5571075 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl @@ -51,7 +51,7 @@ inline cxx::expected TypedMemPool::acqui return cxx::error(TypedMemPoolError::FatalErrorReachedInconsistentState); } - new (chunkHeader) ChunkHeader(); + new (chunkHeader) ChunkHeader(sizeof(T), alignof(T), CHUNK_NO_CUSTOM_HEADER_SIZE, CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); chunkHeader->payloadSize = sizeof(T); new (chunkManagement) ChunkManagement(chunkHeader, &m_memPool, &m_chunkManagementPool); diff --git a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp index dc6246edd6..943542ba4f 100644 --- a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp +++ b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp @@ -25,17 +25,30 @@ namespace iox { namespace mepoo { +/// @brief Helper struct to use as default template parameter when no custom header is used +struct NoCustomHeader +{ +}; + /// @brief IMPORTANT the alignment MUST be 32 or less since all mempools are /// 32 byte aligned otherwise we get alignment problems! struct alignas(32) ChunkHeader { - ChunkHeader() noexcept; + using PayloadOffset_t = uint32_t; + + [[gnu::deprecated]] ChunkHeader() noexcept; + ChunkHeader(const uint32_t payloadSize, + const uint32_t payloadAlignment, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment) noexcept; - /// @brief From the 1.0 release onward, this must be incremented for each incompatible change, e.g. - /// - data width of members changes - /// - members are rearranged - /// - semantic meaning of a member changes - static constexpr uint8_t CHUNK_HEADER_VERSION{1U}; + /// @brief From the 1.0 release onward, this must be incremented for each incompatible change, e.g. + /// - data width of members changes + /// - members are rearranged + /// - semantic meaning of a member changes + static constexpr uint8_t CHUNK_HEADER_VERSION{1U}; + + // BEGIN members /// @brief The size of the whole chunk, including the header uint32_t chunkSize{0U}; @@ -58,7 +71,11 @@ struct alignas(32) ChunkHeader uint32_t payloadSize{0U}; /// @brief The offset of the payload relative to the begin of the chunk - uint32_t payloadOffset{sizeof(ChunkHeader)}; + PayloadOffset_t payloadOffset{sizeof(ChunkHeader)}; + + // END members + + // BEGIN methods /// @brief Get a pointer to the payload carried by the chunk /// @return the pointer to the payload @@ -77,6 +94,8 @@ struct alignas(32) ChunkHeader /// @brief Calculates the used size of the chunk with the ChunkHeader, custom heander and payload /// @return the used size of the chunk uint32_t usedSizeOfChunk(); + + // END methods }; } // namespace mepoo diff --git a/iceoryx_posh/source/mepoo/chunk_header.cpp b/iceoryx_posh/source/mepoo/chunk_header.cpp index cfa2907dc8..1666698e31 100644 --- a/iceoryx_posh/source/mepoo/chunk_header.cpp +++ b/iceoryx_posh/source/mepoo/chunk_header.cpp @@ -24,6 +24,13 @@ namespace mepoo ChunkHeader::ChunkHeader() noexcept { } +ChunkHeader::ChunkHeader(const uint32_t payloadSize, + const uint32_t payloadAlignment, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment) noexcept +{ + // have a look at »Payload Offset Calculation« in chunk_header.md for more details regarding the calculation +} void* ChunkHeader::payload() const noexcept { diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index 384808715c..17f1dd88f9 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -20,6 +20,7 @@ #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" +#include "iceoryx_utils/cxx/algorithm.hpp" #include "iceoryx_utils/cxx/helplets.hpp" #include "iceoryx_utils/error_handling/error_handling.hpp" @@ -91,12 +92,46 @@ MemPoolInfo MemoryManager::getMemPoolInfo(uint32_t index) const } uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, - const uint32_t payloadAlignment [[gnu::unused]], - const uint32_t customHeaderSize [[gnu::unused]], - const uint32_t customHeaderAlignment [[gnu::unused]]) + const uint32_t payloadAlignment, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment) { - // TODO iox-#14 calculate correct size - return payloadSize + static_cast(sizeof(ChunkHeader)); + // TODO return cxx::expected instead of doing the assert + assert(customHeaderAlignment <= alignof(ChunkHeader)); + + // have a look at »Required Chunk Size Calculation« in chunk_header.md for more details regarding the calculation + if (customHeaderSize == 0) + { + // the most simple case with no custom header and the payload adjacent to the ChunkHeader + if (payloadAlignment <= alignof(mepoo::ChunkHeader)) + { + uint64_t chunkSize = static_cast(sizeof(ChunkHeader)) + payloadSize; + + assert(chunkSize <= std::numeric_limits::max()); + + return static_cast(chunkSize); + } + + // the second most simple case with no custom header but the payload alignment + // exceeds the ChunkHeader alignment and is therefore not necessarily adjacent + uint64_t prePayloadAlignmentOverhang = static_cast(sizeof(ChunkHeader) - alignof(ChunkHeader)); + uint64_t chunkSize = prePayloadAlignmentOverhang + payloadAlignment + payloadSize; + + assert(chunkSize <= std::numeric_limits::max()); + + return static_cast(chunkSize); + } + + // the most complex case with a custom header + constexpr uint64_t ALIGNMENT_OF_PAYLOAD_OFFSET_T{alignof(ChunkHeader::PayloadOffset_t)}; + uint64_t headerSize = static_cast(sizeof(ChunkHeader) + customHeaderSize); + uint64_t prePayloadAlignmentOverhang = cxx::align(headerSize, ALIGNMENT_OF_PAYLOAD_OFFSET_T); + uint64_t maxAlignment = algorithm::max(ALIGNMENT_OF_PAYLOAD_OFFSET_T, static_cast(payloadAlignment)); + uint64_t chunkSize = prePayloadAlignmentOverhang + maxAlignment + payloadSize; + + assert(chunkSize <= std::numeric_limits::max()); + + return static_cast(chunkSize); } uint32_t MemoryManager::sizeWithChunkHeaderStruct(const MaxChunkPayloadSize_t size) @@ -161,18 +196,18 @@ SharedChunk MemoryManager::getChunk(const uint32_t payloadSize, { void* chunk{nullptr}; MemPool* memPoolPointer{nullptr}; - uint32_t adjustedSize = + uint32_t requiredChunkSize = MemoryManager::requiredChunkSize(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); - uint32_t totalSizeOfAquiredChunk = 0; + uint32_t aquiredChunkSize = 0; for (auto& memPool : m_memPoolVector) { uint32_t chunkSizeOfMemPool = memPool.getChunkSize(); - if (chunkSizeOfMemPool >= adjustedSize) + if (chunkSizeOfMemPool >= requiredChunkSize) { chunk = memPool.getChunk(); memPoolPointer = &memPool; - totalSizeOfAquiredChunk = chunkSizeOfMemPool; + aquiredChunkSize = chunkSizeOfMemPool; break; } } @@ -188,7 +223,7 @@ SharedChunk MemoryManager::getChunk(const uint32_t payloadSize, { std::cerr << "The following mempools are available:" << std::endl; printMemPoolVector(); - std::cerr << "\nCould not find a fitting mempool for a chunk of size " << adjustedSize << std::endl; + std::cerr << "\nCould not find a fitting mempool for a chunk of size " << requiredChunkSize << std::endl; errorHandler(Error::kMEPOO__MEMPOOL_GETCHUNK_CHUNK_IS_TOO_LARGE, nullptr, ErrorLevel::SEVERE); return SharedChunk(nullptr); @@ -203,8 +238,9 @@ SharedChunk MemoryManager::getChunk(const uint32_t payloadSize, } else { - auto chunkHeader = new (chunk) ChunkHeader(); - chunkHeader->chunkSize = totalSizeOfAquiredChunk; + auto chunkHeader = + new (chunk) ChunkHeader(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); + chunkHeader->chunkSize = aquiredChunkSize; chunkHeader->payloadSize = payloadSize; auto chunkManagement = new (m_chunkManagementPool.front().getChunk()) ChunkManagement(chunkHeader, memPoolPointer, &m_chunkManagementPool.front()); diff --git a/iceoryx_posh/test/mocks/chunk_mock.hpp b/iceoryx_posh/test/mocks/chunk_mock.hpp index 9b330dd512..b803236652 100644 --- a/iceoryx_posh/test/mocks/chunk_mock.hpp +++ b/iceoryx_posh/test/mocks/chunk_mock.hpp @@ -16,6 +16,7 @@ #ifndef IOX_POSH_MOCKS_CHUNK_MOCK_HPP #define IOX_POSH_MOCKS_CHUNK_MOCK_HPP +#include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_utils/cxx/helplets.hpp" @@ -26,17 +27,27 @@ #include #endif -template +template class ChunkMock { public: ChunkMock() { - m_rawMemory = static_cast(iox::cxx::alignedAlloc(Alignment, Size)); + const uint32_t payloadSize = sizeof(Topic); + const uint32_t payloadAlignment = alignof(Topic); + const uint32_t customHeaderSize = + std::is_same::value ? 0U : sizeof(CustomHeader); + const uint32_t customHeaderAlignment = alignof(CustomHeader); + + auto requiredSize = iox::mepoo::MemoryManager::requiredChunkSize( + payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); + + m_rawMemory = static_cast(iox::cxx::alignedAlloc(alignof(iox::mepoo::ChunkHeader), requiredSize)); assert(m_rawMemory != nullptr && "Could not get aligned memory"); - memset(m_rawMemory, 0xFF, Size); + memset(m_rawMemory, 0xFF, requiredSize); - m_chunkHeader = new (m_rawMemory) iox::mepoo::ChunkHeader(); + m_chunkHeader = new (m_rawMemory) + iox::mepoo::ChunkHeader(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); m_topic = static_cast(m_chunkHeader->payload()); } ~ChunkMock() diff --git a/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp b/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp index e55d43f995..c46293fe9c 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp @@ -37,11 +37,16 @@ class SharedChunk_Test : public Test ChunkManagement* GetChunkManagement(void* memoryChunk) { ChunkManagement* v = static_cast(chunkMgmtPool.getChunk()); - ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(); + ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); new (v) ChunkManagement{chunkHeader, &mempool, &chunkMgmtPool}; return v; } + static constexpr uint32_t PAYLOAD_SIZE{64}; + char memory[4096]; iox::posix::Allocator allocator{memory, 4096}; MemPool mempool{64, 10, &allocator, &allocator}; diff --git a/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp b/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp index 689115b5c6..ad12e2b91c 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp @@ -112,7 +112,10 @@ class SharedPointer_Test : public Test ChunkManagement* GetChunkManagement(void* memoryChunk) { ChunkManagement* v = static_cast(chunkMgmtPool.getChunk()); - ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(); + ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); new (v) ChunkManagement{chunkHeader, &mempool, &chunkMgmtPool}; return v; } @@ -125,10 +128,12 @@ class SharedPointer_Test : public Test int resetCounter = ResetCounter(); + static constexpr uint32_t PAYLOAD_SIZE{64}; + char memory[4096]; iox::posix::Allocator allocator{memory, 4096}; - MemPool mempool{64, 10, &allocator, &allocator}; - MemPool chunkMgmtPool{64, 10, &allocator, &allocator}; + MemPool mempool{PAYLOAD_SIZE, 10, &allocator, &allocator}; + MemPool chunkMgmtPool{PAYLOAD_SIZE, 10, &allocator, &allocator}; void* memoryChunk{mempool.getChunk()}; ChunkManagement* chunkManagement = GetChunkManagement(memoryChunk); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index fd632ca776..60a0d38633 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -48,7 +48,10 @@ class ChunkDistributor_test : public Test { ChunkManagement* chunkMgmt = static_cast(chunkMgmtPool.getChunk()); auto chunk = mempool.getChunk(); - ChunkHeader* chunkHeader = new (chunk) ChunkHeader(); + ChunkHeader* chunkHeader = new (chunk) ChunkHeader(PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); new (chunkMgmt) ChunkManagement{chunkHeader, &mempool, &chunkMgmtPool}; *static_cast(chunkHeader->payload()) = value; return SharedChunk(chunkMgmt); @@ -58,14 +61,15 @@ class ChunkDistributor_test : public Test return *static_cast(chunk.getPayload()); } + static constexpr uint32_t PAYLOAD_SIZE{128}; static constexpr size_t MEGABYTE = 1 << 20; static constexpr size_t MEMORY_SIZE = 1 * MEGABYTE; const uint64_t HISTORY_SIZE = 16; static constexpr uint32_t MAX_NUMBER_QUEUES = 128; char memory[MEMORY_SIZE]; iox::posix::Allocator allocator{memory, MEMORY_SIZE}; - MemPool mempool{128, 20, &allocator, &allocator}; - MemPool chunkMgmtPool{128, 20, &allocator, &allocator}; + MemPool mempool{PAYLOAD_SIZE, 20, &allocator, &allocator}; + MemPool chunkMgmtPool{PAYLOAD_SIZE, 20, &allocator, &allocator}; struct ChunkDistributorConfig { diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp index 4ee609b688..3b090a4fa9 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp @@ -42,17 +42,21 @@ class ChunkQueue_testBase { ChunkManagement* chunkMgmt = static_cast(chunkMgmtPool.getChunk()); auto chunk = mempool.getChunk(); - ChunkHeader* chunkHeader = new (chunk) ChunkHeader(); + ChunkHeader* chunkHeader = new (chunk) ChunkHeader(PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); new (chunkMgmt) ChunkManagement{chunkHeader, &mempool, &chunkMgmtPool}; return SharedChunk(chunkMgmt); } + static constexpr uint32_t PAYLOAD_SIZE{128}; static constexpr size_t MEGABYTE = 1 << 20; static constexpr size_t MEMORY_SIZE = 4 * MEGABYTE; std::unique_ptr memory{new char[MEMORY_SIZE]}; iox::posix::Allocator allocator{memory.get(), MEMORY_SIZE}; - MemPool mempool{128, 2 * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; - MemPool chunkMgmtPool{128, 2 * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; + MemPool mempool{PAYLOAD_SIZE, 2 * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; + MemPool chunkMgmtPool{PAYLOAD_SIZE, 2 * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; static constexpr uint32_t RESIZED_CAPACITY{5u}; }; From c4c8ceaf2c3ee93f0c73d1e58a6097dea4c1208c Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Tue, 16 Mar 2021 14:42:48 +0100 Subject: [PATCH 55/89] iox-#14 add calculations for custom header and payload alignment to ChunkHeader Signed-off-by: Mathias Kraus --- .../internal/mepoo/typed_mem_pool.inl | 2 - .../popo/building_blocks/chunk_sender.inl | 5 +- .../iceoryx_posh/mepoo/chunk_header.hpp | 22 ++++-- iceoryx_posh/source/mepoo/chunk_header.cpp | 70 +++++++++++++++++-- iceoryx_posh/source/mepoo/memory_manager.cpp | 3 +- .../test/integrationtests/test_posh_mepoo.cpp | 1 - .../moduletests/test_mepoo_chunk_header.cpp | 52 +++++++++----- .../moduletests/test_mepoo_memory_manager.cpp | 6 +- .../moduletests/test_mepoo_shared_chunk.cpp | 9 ++- .../moduletests/test_popo_chunk_receiver.cpp | 8 ++- .../moduletests/test_popo_chunk_sender.cpp | 58 +++++++++------ 11 files changed, 168 insertions(+), 68 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl index 39c5571075..985c39fce8 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl @@ -52,8 +52,6 @@ inline cxx::expected TypedMemPool::acqui } new (chunkHeader) ChunkHeader(sizeof(T), alignof(T), CHUNK_NO_CUSTOM_HEADER_SIZE, CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); - chunkHeader->payloadSize = sizeof(T); - new (chunkManagement) ChunkManagement(chunkHeader, &m_memPool, &m_chunkManagementPool); return cxx::success(chunkManagement); diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl index 43bb31f3f3..85e6389cc3 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl @@ -57,7 +57,10 @@ ChunkSender::tryAllocate(const uint32_t payloadSize, { if (getMembers()->m_chunksInUse.insert(getMembers()->m_lastChunk)) { - getMembers()->m_lastChunk.getChunkHeader()->payloadSize = payloadSize; + auto chunkHeader = getMembers()->m_lastChunk.getChunkHeader(); + chunkHeader->~ChunkHeader(); + new (chunkHeader) + mepoo::ChunkHeader(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); return cxx::success(getMembers()->m_lastChunk.getChunkHeader()); } else diff --git a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp index 943542ba4f..6a7c8856a8 100644 --- a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp +++ b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019, 2020 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -36,17 +37,24 @@ struct alignas(32) ChunkHeader { using PayloadOffset_t = uint32_t; - [[gnu::deprecated]] ChunkHeader() noexcept; ChunkHeader(const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment) noexcept; - /// @brief From the 1.0 release onward, this must be incremented for each incompatible change, e.g. - /// - data width of members changes - /// - members are rearranged - /// - semantic meaning of a member changes - static constexpr uint8_t CHUNK_HEADER_VERSION{1U}; + // copy/move ctors/assignment operators are deleted since the calculations for the custom header and payload + // alignment are dependent on the address of the this pointer + ChunkHeader(const ChunkHeader&) = delete; + ChunkHeader(ChunkHeader&&) = delete; + + ChunkHeader& operator=(const ChunkHeader&) = delete; + ChunkHeader& operator=(ChunkHeader&&) = delete; + + /// @brief From the 1.0 release onward, this must be incremented for each incompatible change, e.g. + /// - data width of members changes + /// - members are rearranged + /// - semantic meaning of a member changes + static constexpr uint8_t CHUNK_HEADER_VERSION{1U}; // BEGIN members diff --git a/iceoryx_posh/source/mepoo/chunk_header.cpp b/iceoryx_posh/source/mepoo/chunk_header.cpp index 1666698e31..13318b2119 100644 --- a/iceoryx_posh/source/mepoo/chunk_header.cpp +++ b/iceoryx_posh/source/mepoo/chunk_header.cpp @@ -1,4 +1,5 @@ -// Copyright (c) 2019, 2020 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved. +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -21,15 +22,71 @@ namespace iox { namespace mepoo { -ChunkHeader::ChunkHeader() noexcept -{ -} ChunkHeader::ChunkHeader(const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment) noexcept { + static_assert(alignof(ChunkHeader) >= 8U, + "All the calculations expect the ChunkHeader alignment to be at least 8!"); + cxx::Expects(customHeaderAlignment <= alignof(ChunkHeader) + && "The alignment of the custom header must not exceed the alignment of the ChunkHeader!"); + + this->payloadSize = payloadSize; + // have a look at »Payload Offset Calculation« in chunk_header.md for more details regarding the calculation + if (customHeaderSize == 0) + { + if (payloadAlignment <= alignof(mepoo::ChunkHeader)) + { + // the most simple case with no custom header and the payload adjacent to the ChunkHeader + payloadOffset = sizeof(ChunkHeader); + } + else + { + // the second most simple case with no custom header but the payload alignment + // exceeds the ChunkHeader alignment and is therefore not necessarily adjacent + uint64_t addressOfChunkHeader = reinterpret_cast(this); + uint64_t headerEndAddress = addressOfChunkHeader + sizeof(ChunkHeader); + uint64_t alignedPayloadAddress = iox::cxx::align(headerEndAddress, static_cast(payloadAlignment)); + uint64_t offsetToPayload = alignedPayloadAddress - addressOfChunkHeader; + cxx::Ensures(offsetToPayload <= std::numeric_limits::max() + && "Payload offset too large for chunk!"); + payloadOffset = static_cast(offsetToPayload); + + // this is safe since the alignment of the payload is larger than the one from the ChunkHeader + // -> the payload is either adjacent and `backOffset` is at the same location as `payloadOffset` + // or the payload is not adjacent and there is space of at least the alignment of ChunkHeader + // between the ChunkHeader and the payload + auto addressOfBackOffset = alignedPayloadAddress - sizeof(PayloadOffset_t); + auto backOffset = reinterpret_cast(addressOfBackOffset); + *backOffset = payloadOffset; + } + } + else + { + // the most complex case with a custom header + auto addressOfChunkHeader = reinterpret_cast(this); + uint64_t headerEndAddress = addressOfChunkHeader + sizeof(ChunkHeader) + customHeaderSize; + uint64_t potentialBackOffsetAddress = iox::cxx::align(headerEndAddress, alignof(PayloadOffset_t)); + uint64_t potentialPayloadAddress = potentialBackOffsetAddress + sizeof(PayloadOffset_t); + uint64_t alignedPayloadAddress = + iox::cxx::align(potentialPayloadAddress, static_cast(payloadAlignment)); + uint64_t offsetToPayload = alignedPayloadAddress - addressOfChunkHeader; + cxx::Ensures(offsetToPayload <= std::numeric_limits::max() + && "Payload offset too large for chunk!"); + payloadOffset = static_cast(offsetToPayload); + + // this always works if the alignment of PayloadOffset_t and payloadAlignment are equal, + // if not there are two options: + // - either the alignment of the PayloadOffset_t is larger than payloadAlignment + // -> the payload is adjacent to the back-offset and therefore this also works + // - or the alignment of the PayloadOffset_t is smaller than payloadAlignment + // -> the back-offset can be put adjacent to to the Topic since the smaller alignment always fits + auto addressOfBackOffset = alignedPayloadAddress - sizeof(PayloadOffset_t); + auto backOffset = reinterpret_cast(addressOfBackOffset); + *backOffset = payloadOffset; + } } void* ChunkHeader::payload() const noexcept @@ -46,9 +103,8 @@ ChunkHeader* ChunkHeader::fromPayload(const void* const payload) noexcept } uint64_t payloadAddress = reinterpret_cast(payload); // the payload offset is always stored in front of the payload, no matter if a custom header is used or not - // or if the payload has a custom allignment - using PayloadOffsetType = decltype(ChunkHeader::payloadOffset); - auto payloadOffset = reinterpret_cast(payloadAddress - sizeof(PayloadOffsetType)); + // or if the payload has a custom alignment + auto payloadOffset = reinterpret_cast(payloadAddress - sizeof(PayloadOffset_t)); return reinterpret_cast(payloadAddress - *payloadOffset); } diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index 17f1dd88f9..58e63e91a4 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -96,7 +96,7 @@ uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment) { - // TODO return cxx::expected instead of doing the assert + /// @todo iox-#14: return cxx::expected instead of doing the assert assert(customHeaderAlignment <= alignof(ChunkHeader)); // have a look at »Required Chunk Size Calculation« in chunk_header.md for more details regarding the calculation @@ -241,7 +241,6 @@ SharedChunk MemoryManager::getChunk(const uint32_t payloadSize, auto chunkHeader = new (chunk) ChunkHeader(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); chunkHeader->chunkSize = aquiredChunkSize; - chunkHeader->payloadSize = payloadSize; auto chunkManagement = new (m_chunkManagementPool.front().getChunk()) ChunkManagement(chunkHeader, memPoolPointer, &m_chunkManagementPool.front()); return SharedChunk(chunkManagement); diff --git a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp index a0ecae30c1..e8df110fda 100644 --- a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp +++ b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp @@ -311,7 +311,6 @@ class Mepoo_IntegrationTest : public Test iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT) .and_then([&](auto sample) { new (sample->payload()) Topic; - sample->payloadSize = TOPIC_SIZE; publisherPort->sendChunk(sample); m_roudiEnv->InterOpWait(); }); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index ab5dbe50c4..36e1139fa3 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2020 - 2021 by Apex.AI Inc. 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. @@ -22,19 +22,20 @@ using namespace ::testing; using namespace iox::mepoo; -template +template struct alignas(32) ChunkWithPayload { - ChunkHeader m_chunkHeader; - uint8_t m_payload[N]; + ChunkHeader m_chunkHeader{PayloadSize, 1U, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + uint8_t m_payload[PayloadSize]; }; -template +template struct alignas(32) ChunkWithCustomHeaderAndPayload { - ChunkHeader m_chunkHeader; + ChunkHeader m_chunkHeader{PayloadSize, 1U, sizeof(uint64_t), alignof(uint64_t)}; uint64_t m_customHeader; - uint8_t m_payload[N]; + ChunkHeader::PayloadOffset_t m_backOffset; + uint8_t m_payload[PayloadSize]; }; class ChunkHeader_test : public Test @@ -45,7 +46,11 @@ class ChunkHeader_test : public Test TEST_F(ChunkHeader_test, ChunkHeaderHasInitializedMembers) { - ChunkHeader sut; + constexpr uint32_t PAYLOAD_SIZE{0U}; + ChunkHeader sut{PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; EXPECT_THAT(sut.chunkSize, Eq(0U)); @@ -79,7 +84,7 @@ TEST_F(ChunkHeader_test, ChunkHeaderPayloadSizeIsLargeEnoughForMempoolChunk) TEST_F(ChunkHeader_test, CustomHeaderMethodReturnsCorrectCustomHeaderPointer) { - constexpr int32_t PAYLOAD_SIZE{128}; + constexpr uint32_t PAYLOAD_SIZE{128U}; ChunkWithCustomHeaderAndPayload chunk; EXPECT_THAT(chunk.m_chunkHeader.customHeader(), Eq(&chunk.m_customHeader)); @@ -87,7 +92,7 @@ TEST_F(ChunkHeader_test, CustomHeaderMethodReturnsCorrectCustomHeaderPointer) TEST_F(ChunkHeader_test, PayloadMethodReturnsCorrectPayloadPointer) { - constexpr int32_t PAYLOAD_SIZE{128}; + constexpr uint32_t PAYLOAD_SIZE{128U}; ChunkWithPayload chunk; EXPECT_THAT(chunk.m_chunkHeader.payload(), Eq(chunk.m_payload)); @@ -95,7 +100,7 @@ TEST_F(ChunkHeader_test, PayloadMethodReturnsCorrectPayloadPointer) TEST_F(ChunkHeader_test, FromPayloadFunctionReturnsCorrectChunkHeaderPointer) { - constexpr int32_t PAYLOAD_SIZE{128}; + constexpr uint32_t PAYLOAD_SIZE{128U}; ChunkWithPayload chunk; EXPECT_THAT(ChunkHeader::fromPayload(chunk.m_payload), Eq(&chunk.m_chunkHeader)); @@ -108,26 +113,37 @@ TEST_F(ChunkHeader_test, FromPayloadFunctionCalledWithNullptrReturnsNullptr) TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderWhenPayloadIsZero) { - ChunkHeader sut; + constexpr uint32_t PAYLOAD_SIZE{0U}; + ChunkHeader sut{PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + sut.chunkSize = 2 * sizeof(ChunkHeader); EXPECT_THAT(sut.usedSizeOfChunk(), Eq(sizeof(ChunkHeader))); } TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderPlusOneWhenPayloadIsOne) { - ChunkHeader sut; - sut.chunkSize = 2 * sizeof(ChunkHeader); constexpr uint32_t PAYLOAD_SIZE{1U}; - sut.payloadSize = PAYLOAD_SIZE; + ChunkHeader sut{PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + + sut.chunkSize = 2 * sizeof(ChunkHeader); EXPECT_THAT(sut.usedSizeOfChunk(), Eq(sizeof(ChunkHeader) + PAYLOAD_SIZE)); } TEST_F(ChunkHeader_test, usedChunkSizeTerminatesWhenPayloadSizeExceedsChunkSize) { - ChunkHeader sut; - sut.chunkSize = 2 * sizeof(ChunkHeader); constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; - sut.payloadSize = PAYLOAD_SIZE; + ChunkHeader sut{PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + + sut.chunkSize = 2 * sizeof(ChunkHeader); EXPECT_DEATH(sut.usedSizeOfChunk(), ".*"); } diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 22819a5483..55032983ab 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -328,9 +328,11 @@ TEST_F(MemoryManager_test, freeChunkMultiMemPoolFullToEmptyToFull) EXPECT_THAT(sut->getMemPoolInfo(3).m_usedChunks, Eq(ChunkCount)); } -TEST_F(MemoryManager_test, getChunkWithSizeZeroShouldFail) +TEST_F(MemoryManager_test, getChunkWithSizeZeroShouldNotFail) { - EXPECT_DEATH({ sut->getChunk(0U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); }, ".*"); + mempoolconf.addMemPool({32, 10}); + sut->configureMemoryManager(mempoolconf, allocator, allocator); + EXPECT_THAT(sut->getChunk(0U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT), Eq(true)); } TEST_F(MemoryManager_test, addMemPoolWithChunkCountZeroShouldFail) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp b/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp index c46293fe9c..4f8b9e810f 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -193,12 +194,14 @@ TEST_F(SharedChunk_Test, getPayloadWhenInvalid) TEST_F(SharedChunk_Test, getPayloadWhenValid) { + constexpr uint32_t PAYLOAD{1337U}; ChunkHeader* newChunk = static_cast(mempool.getChunk()); - new (newChunk) ChunkHeader(); - new (static_cast(newChunk->payload())) int{1337}; + new (newChunk) ChunkHeader( + sizeof(PAYLOAD), alignof(uint32_t), iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); + new (static_cast(newChunk->payload())) uint32_t{PAYLOAD}; iox::mepoo::SharedChunk sut2(GetChunkManagement(newChunk)); - EXPECT_THAT(*static_cast(sut2.getPayload()), Eq(1337)); + EXPECT_THAT(*static_cast(sut2.getPayload()), Eq(PAYLOAD)); } TEST_F(SharedChunk_Test, MultipleSharedChunksCleanup) diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp index 90de92c8db..86725d1608 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp @@ -192,8 +192,12 @@ TEST_F(ChunkReceiver_test, releaseInvalidChunk) errorHandlerCalled = true; }); - auto myCrazyChunk = std::make_shared(); - m_chunkReceiver.release(myCrazyChunk.get()); + constexpr uint32_t PAYLOAD_SIZE{0U}; + iox::mepoo::ChunkHeader myCrazyChunk{PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + m_chunkReceiver.release(&myCrazyChunk); EXPECT_TRUE(errorHandlerCalled); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp index d1ef13df10..3947d65798 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp @@ -217,8 +217,12 @@ TEST_F(ChunkSender_test, freeInvalidChunk) errorHandlerCalled = true; }); - auto myCrazyChunk = std::make_shared(); - m_chunkSender.release(myCrazyChunk.get()); + constexpr uint32_t PAYLOAD_SIZE{0U}; + iox::mepoo::ChunkHeader myCrazyChunk{PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + m_chunkSender.release(&myCrazyChunk); EXPECT_TRUE(errorHandlerCalled); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); @@ -249,11 +253,11 @@ TEST_F(ChunkSender_test, sendMultipleWithoutReceiverAndAlwaysLast) alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(maybeChunkHeader.has_error()); + ASSERT_FALSE(maybeChunkHeader.has_error()); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); if (i > 0) { - EXPECT_TRUE(maybeLastChunk.has_value()); + ASSERT_TRUE(maybeLastChunk.has_value()); // We get the last chunk again EXPECT_TRUE(*maybeChunkHeader == *maybeLastChunk); EXPECT_TRUE((*maybeChunkHeader)->payload() == (*maybeLastChunk)->payload()); @@ -280,11 +284,11 @@ TEST_F(ChunkSender_test, sendMultipleWithoutReceiverWithHistoryNoLastReuse) alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(maybeChunkHeader.has_error()); + ASSERT_FALSE(maybeChunkHeader.has_error()); auto maybeLastChunk = m_chunkSenderWithHistory.tryGetPreviousChunk(); if (i > 0) { - EXPECT_TRUE(maybeLastChunk.has_value()); + ASSERT_TRUE(maybeLastChunk.has_value()); // We don't get the last chunk again EXPECT_FALSE(*maybeChunkHeader == *maybeLastChunk); EXPECT_FALSE((*maybeChunkHeader)->payload() == (*maybeLastChunk)->payload()); @@ -446,8 +450,12 @@ TEST_F(ChunkSender_test, sendInvalidChunk) errorHandlerCalled = true; }); - auto myCrazyChunk = std::make_shared(); - m_chunkSender.send(myCrazyChunk.get()); + constexpr uint32_t PAYLOAD_SIZE{0U}; + iox::mepoo::ChunkHeader myCrazyChunk{PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + m_chunkSender.send(&myCrazyChunk); EXPECT_TRUE(errorHandlerCalled); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); @@ -483,8 +491,12 @@ TEST_F(ChunkSender_test, pushInvalidChunkToHistory) errorHandlerCalled = true; }); - auto myCrazyChunk = std::make_shared(); - m_chunkSender.pushToHistory(myCrazyChunk.get()); + constexpr uint32_t PAYLOAD_SIZE{0U}; + iox::mepoo::ChunkHeader myCrazyChunk{PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + m_chunkSender.pushToHistory(&myCrazyChunk); EXPECT_TRUE(errorHandlerCalled); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); @@ -501,11 +513,11 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverNoLastReuse) alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(maybeChunkHeader.has_error()); + ASSERT_FALSE(maybeChunkHeader.has_error()); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); if (i > 0) { - EXPECT_TRUE(maybeLastChunk.has_value()); + ASSERT_TRUE(maybeLastChunk.has_value()); // No last chunk for us :-( EXPECT_FALSE(*maybeChunkHeader == *maybeLastChunk); EXPECT_FALSE((*maybeChunkHeader)->payload() == (*maybeLastChunk)->payload()); @@ -534,11 +546,11 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverLastReuseBecauseAlreadyConsumed alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(maybeChunkHeader.has_error()); + ASSERT_FALSE(maybeChunkHeader.has_error()); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); if (i > 0) { - EXPECT_TRUE(maybeLastChunk.has_value()); + ASSERT_TRUE(maybeLastChunk.has_value()); // We get the last chunk again EXPECT_TRUE(*maybeChunkHeader == *maybeLastChunk); EXPECT_TRUE((*maybeChunkHeader)->payload() == (*maybeLastChunk)->payload()); @@ -565,7 +577,7 @@ TEST_F(ChunkSender_test, ReuseLastIfSmaller) { auto maybeChunkHeader = m_chunkSender.tryAllocate( BIG_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(maybeChunkHeader.has_error()); + ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1u)); auto chunkHeader = *maybeChunkHeader; @@ -573,14 +585,14 @@ TEST_F(ChunkSender_test, ReuseLastIfSmaller) auto chunkSmaller = m_chunkSender.tryAllocate( SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(chunkSmaller.has_error()); + ASSERT_FALSE(chunkSmaller.has_error()); // no small chunk used as big one is recycled EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0u)); EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1u)); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); - EXPECT_TRUE(maybeLastChunk.has_value()); + ASSERT_TRUE(maybeLastChunk.has_value()); // We get the last chunk again EXPECT_TRUE(*chunkSmaller == *maybeLastChunk); EXPECT_TRUE((*chunkSmaller)->payload() == (*maybeLastChunk)->payload()); @@ -590,7 +602,7 @@ TEST_F(ChunkSender_test, NoReuseOfLastIfBigger) { auto maybeChunkHeader = m_chunkSender.tryAllocate( SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(maybeChunkHeader.has_error()); + ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); auto chunkHeader = *maybeChunkHeader; @@ -598,14 +610,14 @@ TEST_F(ChunkSender_test, NoReuseOfLastIfBigger) auto chunkBigger = m_chunkSender.tryAllocate( BIG_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(chunkBigger.has_error()); + ASSERT_FALSE(chunkBigger.has_error()); // no reuse, we hav a small and a big chunk in use EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1u)); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); - EXPECT_TRUE(maybeLastChunk.has_value()); + ASSERT_TRUE(maybeLastChunk.has_value()); // not the last chunk EXPECT_FALSE(*chunkBigger == *maybeLastChunk); EXPECT_FALSE((*chunkBigger)->payload() == (*maybeLastChunk)->payload()); @@ -615,7 +627,7 @@ TEST_F(ChunkSender_test, ReuseOfLastIfBiggerButFitsInChunk) { auto maybeChunkHeader = m_chunkSender.tryAllocate( SMALL_CHUNK - 10, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(maybeChunkHeader.has_error()); + ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); auto chunkHeader = *maybeChunkHeader; @@ -623,14 +635,14 @@ TEST_F(ChunkSender_test, ReuseOfLastIfBiggerButFitsInChunk) auto chunkBigger = m_chunkSender.tryAllocate( SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - EXPECT_FALSE(chunkBigger.has_error()); + ASSERT_FALSE(chunkBigger.has_error()); // reuse as it still fits in the small chunk EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(0u)); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); - EXPECT_TRUE(maybeLastChunk.has_value()); + ASSERT_TRUE(maybeLastChunk.has_value()); // not the last chunk EXPECT_TRUE(*chunkBigger == *maybeLastChunk); EXPECT_TRUE((*chunkBigger)->payload() == (*maybeLastChunk)->payload()); From bfcad4589e8f5404a190b82f5046f4d7b5f4b3f5 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Tue, 16 Mar 2021 16:41:56 +0100 Subject: [PATCH 56/89] iox-#14 set the chunk size with the ChunkHeader ctor Signed-off-by: Mathias Kraus --- .../internal/mepoo/typed_mem_pool.inl | 3 +- .../popo/building_blocks/chunk_sender.inl | 3 +- .../iceoryx_posh/mepoo/chunk_header.hpp | 9 +++++- iceoryx_posh/source/mepoo/chunk_header.cpp | 4 ++- iceoryx_posh/source/mepoo/memory_manager.cpp | 16 +++++----- iceoryx_posh/test/mocks/chunk_mock.hpp | 5 +-- .../moduletests/test_mepoo_chunk_header.cpp | 31 +++++++++++++------ .../moduletests/test_mepoo_shared_chunk.cpp | 10 ++++-- .../moduletests/test_mepoo_shared_pointer.cpp | 4 ++- .../test_popo_chunk_distributor.cpp | 4 ++- .../moduletests/test_popo_chunk_queue.cpp | 3 +- .../moduletests/test_popo_chunk_receiver.cpp | 4 ++- .../moduletests/test_popo_chunk_sender.cpp | 12 +++++-- 13 files changed, 75 insertions(+), 33 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl index 985c39fce8..d9be811984 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl @@ -51,7 +51,8 @@ inline cxx::expected TypedMemPool::acqui return cxx::error(TypedMemPoolError::FatalErrorReachedInconsistentState); } - new (chunkHeader) ChunkHeader(sizeof(T), alignof(T), CHUNK_NO_CUSTOM_HEADER_SIZE, CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); + new (chunkHeader) ChunkHeader( + m_memPool.getChunkSize(), sizeof(T), alignof(T), CHUNK_NO_CUSTOM_HEADER_SIZE, CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); new (chunkManagement) ChunkManagement(chunkHeader, &m_memPool, &m_chunkManagementPool); return cxx::success(chunkManagement); diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl index 85e6389cc3..2e3384a481 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl @@ -58,9 +58,10 @@ ChunkSender::tryAllocate(const uint32_t payloadSize, if (getMembers()->m_chunksInUse.insert(getMembers()->m_lastChunk)) { auto chunkHeader = getMembers()->m_lastChunk.getChunkHeader(); + auto chunkSize = chunkHeader->chunkSize; chunkHeader->~ChunkHeader(); new (chunkHeader) - mepoo::ChunkHeader(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); + mepoo::ChunkHeader(chunkSize, payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); return cxx::success(getMembers()->m_lastChunk.getChunkHeader()); } else diff --git a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp index 6a7c8856a8..5eb80a3aff 100644 --- a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp +++ b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp @@ -37,7 +37,14 @@ struct alignas(32) ChunkHeader { using PayloadOffset_t = uint32_t; - ChunkHeader(const uint32_t payloadSize, + /// @brief constructs and initializes a ChunkHeader + /// @param[in] chunkSize is the size of the chunk the ChunkHeader is constructed + /// @param[in] payloadSize is the size of the payload + /// @param[in] payloadAlignment is the alignment of the payload + /// @param[in] customHeaderSize is the size of the custom header; if no custom header is used, use 0 + /// @param[in] customHeaderAlignment is the alignment for the custom header; if no custom header is used, use 1 + ChunkHeader(const uint32_t chunkSize, + const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment) noexcept; diff --git a/iceoryx_posh/source/mepoo/chunk_header.cpp b/iceoryx_posh/source/mepoo/chunk_header.cpp index 13318b2119..cb5e6c6eb9 100644 --- a/iceoryx_posh/source/mepoo/chunk_header.cpp +++ b/iceoryx_posh/source/mepoo/chunk_header.cpp @@ -22,7 +22,8 @@ namespace iox { namespace mepoo { -ChunkHeader::ChunkHeader(const uint32_t payloadSize, +ChunkHeader::ChunkHeader(const uint32_t chunkSize, + const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment) noexcept @@ -32,6 +33,7 @@ ChunkHeader::ChunkHeader(const uint32_t payloadSize, cxx::Expects(customHeaderAlignment <= alignof(ChunkHeader) && "The alignment of the custom header must not exceed the alignment of the ChunkHeader!"); + this->chunkSize = chunkSize; this->payloadSize = payloadSize; // have a look at »Payload Offset Calculation« in chunk_header.md for more details regarding the calculation diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index 58e63e91a4..e100964337 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -96,8 +96,9 @@ uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment) { - /// @todo iox-#14: return cxx::expected instead of doing the assert - assert(customHeaderAlignment <= alignof(ChunkHeader)); + /// @todo iox-#14: return cxx::expected instead of using cxx::Expects/Ensures + cxx::Expects(customHeaderAlignment <= alignof(ChunkHeader) + && "The alignment of the custom header must not exceed the alignment of the ChunkHeader!"); // have a look at »Required Chunk Size Calculation« in chunk_header.md for more details regarding the calculation if (customHeaderSize == 0) @@ -107,7 +108,7 @@ uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, { uint64_t chunkSize = static_cast(sizeof(ChunkHeader)) + payloadSize; - assert(chunkSize <= std::numeric_limits::max()); + cxx::Ensures(chunkSize <= std::numeric_limits::max() && "Size of chunk exceeds limits!"); return static_cast(chunkSize); } @@ -117,7 +118,7 @@ uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, uint64_t prePayloadAlignmentOverhang = static_cast(sizeof(ChunkHeader) - alignof(ChunkHeader)); uint64_t chunkSize = prePayloadAlignmentOverhang + payloadAlignment + payloadSize; - assert(chunkSize <= std::numeric_limits::max()); + cxx::Ensures(chunkSize <= std::numeric_limits::max() && "Size of chunk exceeds limits!"); return static_cast(chunkSize); } @@ -129,7 +130,7 @@ uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, uint64_t maxAlignment = algorithm::max(ALIGNMENT_OF_PAYLOAD_OFFSET_T, static_cast(payloadAlignment)); uint64_t chunkSize = prePayloadAlignmentOverhang + maxAlignment + payloadSize; - assert(chunkSize <= std::numeric_limits::max()); + cxx::Ensures(chunkSize <= std::numeric_limits::max() && "Size of chunk exceeds limits!"); return static_cast(chunkSize); } @@ -238,9 +239,8 @@ SharedChunk MemoryManager::getChunk(const uint32_t payloadSize, } else { - auto chunkHeader = - new (chunk) ChunkHeader(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); - chunkHeader->chunkSize = aquiredChunkSize; + auto chunkHeader = new (chunk) + ChunkHeader(aquiredChunkSize, payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); auto chunkManagement = new (m_chunkManagementPool.front().getChunk()) ChunkManagement(chunkHeader, memPoolPointer, &m_chunkManagementPool.front()); return SharedChunk(chunkManagement); diff --git a/iceoryx_posh/test/mocks/chunk_mock.hpp b/iceoryx_posh/test/mocks/chunk_mock.hpp index b803236652..a8e97a031e 100644 --- a/iceoryx_posh/test/mocks/chunk_mock.hpp +++ b/iceoryx_posh/test/mocks/chunk_mock.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -46,8 +47,8 @@ class ChunkMock assert(m_rawMemory != nullptr && "Could not get aligned memory"); memset(m_rawMemory, 0xFF, requiredSize); - m_chunkHeader = new (m_rawMemory) - iox::mepoo::ChunkHeader(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); + m_chunkHeader = new (m_rawMemory) iox::mepoo::ChunkHeader( + requiredSize, payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); m_topic = static_cast(m_chunkHeader->payload()); } ~ChunkMock() diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 36e1139fa3..798c66f63a 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -25,14 +25,19 @@ using namespace iox::mepoo; template struct alignas(32) ChunkWithPayload { - ChunkHeader m_chunkHeader{PayloadSize, 1U, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + ChunkHeader m_chunkHeader{sizeof(ChunkWithPayload), + PayloadSize, + alignof(uint8_t), + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; uint8_t m_payload[PayloadSize]; }; template struct alignas(32) ChunkWithCustomHeaderAndPayload { - ChunkHeader m_chunkHeader{PayloadSize, 1U, sizeof(uint64_t), alignof(uint64_t)}; + ChunkHeader m_chunkHeader{ + sizeof(ChunkWithCustomHeaderAndPayload), PayloadSize, alignof(uint8_t), sizeof(uint64_t), alignof(uint64_t)}; uint64_t m_customHeader; ChunkHeader::PayloadOffset_t m_backOffset; uint8_t m_payload[PayloadSize]; @@ -46,13 +51,15 @@ class ChunkHeader_test : public Test TEST_F(ChunkHeader_test, ChunkHeaderHasInitializedMembers) { - constexpr uint32_t PAYLOAD_SIZE{0U}; - ChunkHeader sut{PAYLOAD_SIZE, + constexpr uint32_t CHUNK_SIZE{32}; + constexpr uint32_t PAYLOAD_SIZE{8U}; + ChunkHeader sut{CHUNK_SIZE, + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; - EXPECT_THAT(sut.chunkSize, Eq(0U)); + EXPECT_THAT(sut.chunkSize, Eq(CHUNK_SIZE)); // deliberately used a magic number to make the test fail when CHUNK_HEADER_VERSION changes EXPECT_THAT(sut.chunkHeaderVersion, Eq(1U)); @@ -65,7 +72,7 @@ TEST_F(ChunkHeader_test, ChunkHeaderHasInitializedMembers) EXPECT_THAT(sut.sequenceNumber, Eq(0U)); - EXPECT_THAT(sut.payloadSize, Eq(0U)); + EXPECT_THAT(sut.payloadSize, Eq(PAYLOAD_SIZE)); // a default created ChunkHeader has always an adjacent payload EXPECT_THAT(sut.payloadOffset, Eq(sizeof(ChunkHeader))); } @@ -113,8 +120,10 @@ TEST_F(ChunkHeader_test, FromPayloadFunctionCalledWithNullptrReturnsNullptr) TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderWhenPayloadIsZero) { + constexpr uint32_t CHUNK_SIZE{32}; constexpr uint32_t PAYLOAD_SIZE{0U}; - ChunkHeader sut{PAYLOAD_SIZE, + ChunkHeader sut{CHUNK_SIZE, + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; @@ -125,8 +134,10 @@ TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderWhenPayloadIsZero) TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderPlusOneWhenPayloadIsOne) { + constexpr uint32_t CHUNK_SIZE{32}; constexpr uint32_t PAYLOAD_SIZE{1U}; - ChunkHeader sut{PAYLOAD_SIZE, + ChunkHeader sut{CHUNK_SIZE, + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; @@ -137,8 +148,10 @@ TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderPlusOneWhenPayloadIsOne TEST_F(ChunkHeader_test, usedChunkSizeTerminatesWhenPayloadSizeExceedsChunkSize) { + constexpr uint32_t CHUNK_SIZE{32}; constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; - ChunkHeader sut{PAYLOAD_SIZE, + ChunkHeader sut{CHUNK_SIZE, + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; diff --git a/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp b/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp index 4f8b9e810f..864df7be16 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp @@ -38,7 +38,8 @@ class SharedChunk_Test : public Test ChunkManagement* GetChunkManagement(void* memoryChunk) { ChunkManagement* v = static_cast(chunkMgmtPool.getChunk()); - ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(PAYLOAD_SIZE, + ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(chunkMgmtPool.getChunkSize(), + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); @@ -196,8 +197,11 @@ TEST_F(SharedChunk_Test, getPayloadWhenValid) { constexpr uint32_t PAYLOAD{1337U}; ChunkHeader* newChunk = static_cast(mempool.getChunk()); - new (newChunk) ChunkHeader( - sizeof(PAYLOAD), alignof(uint32_t), iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); + new (newChunk) ChunkHeader(mempool.getChunkSize(), + sizeof(PAYLOAD), + alignof(uint32_t), + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); new (static_cast(newChunk->payload())) uint32_t{PAYLOAD}; iox::mepoo::SharedChunk sut2(GetChunkManagement(newChunk)); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp b/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp index ad12e2b91c..0b25addaa6 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -112,7 +113,8 @@ class SharedPointer_Test : public Test ChunkManagement* GetChunkManagement(void* memoryChunk) { ChunkManagement* v = static_cast(chunkMgmtPool.getChunk()); - ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(PAYLOAD_SIZE, + ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(chunkMgmtPool.getChunkSize(), + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index 60a0d38633..61add4e614 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2021 by Apex.AI Inc. 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. @@ -48,7 +49,8 @@ class ChunkDistributor_test : public Test { ChunkManagement* chunkMgmt = static_cast(chunkMgmtPool.getChunk()); auto chunk = mempool.getChunk(); - ChunkHeader* chunkHeader = new (chunk) ChunkHeader(PAYLOAD_SIZE, + ChunkHeader* chunkHeader = new (chunk) ChunkHeader(chunkMgmtPool.getChunkSize(), + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp index 3b090a4fa9..179a967258 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp @@ -42,7 +42,8 @@ class ChunkQueue_testBase { ChunkManagement* chunkMgmt = static_cast(chunkMgmtPool.getChunk()); auto chunk = mempool.getChunk(); - ChunkHeader* chunkHeader = new (chunk) ChunkHeader(PAYLOAD_SIZE, + ChunkHeader* chunkHeader = new (chunk) ChunkHeader(chunkMgmtPool.getChunkSize(), + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp index 86725d1608..2f2671d9c5 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp @@ -192,8 +192,10 @@ TEST_F(ChunkReceiver_test, releaseInvalidChunk) errorHandlerCalled = true; }); + constexpr uint32_t CHUNK_SIZE{32U}; constexpr uint32_t PAYLOAD_SIZE{0U}; - iox::mepoo::ChunkHeader myCrazyChunk{PAYLOAD_SIZE, + iox::mepoo::ChunkHeader myCrazyChunk{CHUNK_SIZE, + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp index 3947d65798..d674de5d0e 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp @@ -217,8 +217,10 @@ TEST_F(ChunkSender_test, freeInvalidChunk) errorHandlerCalled = true; }); + constexpr uint32_t CHUNK_SIZE{32U}; constexpr uint32_t PAYLOAD_SIZE{0U}; - iox::mepoo::ChunkHeader myCrazyChunk{PAYLOAD_SIZE, + iox::mepoo::ChunkHeader myCrazyChunk{CHUNK_SIZE, + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; @@ -450,8 +452,10 @@ TEST_F(ChunkSender_test, sendInvalidChunk) errorHandlerCalled = true; }); + constexpr uint32_t CHUNK_SIZE{32U}; constexpr uint32_t PAYLOAD_SIZE{0U}; - iox::mepoo::ChunkHeader myCrazyChunk{PAYLOAD_SIZE, + iox::mepoo::ChunkHeader myCrazyChunk{CHUNK_SIZE, + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; @@ -491,8 +495,10 @@ TEST_F(ChunkSender_test, pushInvalidChunkToHistory) errorHandlerCalled = true; }); + constexpr uint32_t CHUNK_SIZE{32U}; constexpr uint32_t PAYLOAD_SIZE{0U}; - iox::mepoo::ChunkHeader myCrazyChunk{PAYLOAD_SIZE, + iox::mepoo::ChunkHeader myCrazyChunk{CHUNK_SIZE, + PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; From b5fa61ce245bac5f1c758565c0eec5703cb88186 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Tue, 16 Mar 2021 18:11:12 +0100 Subject: [PATCH 57/89] iox-#14 fix build Signed-off-by: Mathias Kraus --- iceoryx_dds/test/mocks/chunk_mock_dds.hpp | 3 ++- iceoryx_posh/source/mepoo/chunk_header.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iceoryx_dds/test/mocks/chunk_mock_dds.hpp b/iceoryx_dds/test/mocks/chunk_mock_dds.hpp index 68fb6de48d..66a74dd4b4 100644 --- a/iceoryx_dds/test/mocks/chunk_mock_dds.hpp +++ b/iceoryx_dds/test/mocks/chunk_mock_dds.hpp @@ -49,7 +49,8 @@ class ChunkMockDDS memset(m_rawMemory, 0xFF, Size); - m_chunkHeader = new (m_rawMemory) iox::mepoo::ChunkHeader(); + m_chunkHeader = new (m_rawMemory) iox::mepoo::ChunkHeader( + Size, sizeof(T), alignof(T), iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); m_chunkHeader->payloadSize = sizeof(T); // Set the value diff --git a/iceoryx_posh/source/mepoo/chunk_header.cpp b/iceoryx_posh/source/mepoo/chunk_header.cpp index cb5e6c6eb9..6276ca7c2b 100644 --- a/iceoryx_posh/source/mepoo/chunk_header.cpp +++ b/iceoryx_posh/source/mepoo/chunk_header.cpp @@ -70,7 +70,8 @@ ChunkHeader::ChunkHeader(const uint32_t chunkSize, // the most complex case with a custom header auto addressOfChunkHeader = reinterpret_cast(this); uint64_t headerEndAddress = addressOfChunkHeader + sizeof(ChunkHeader) + customHeaderSize; - uint64_t potentialBackOffsetAddress = iox::cxx::align(headerEndAddress, alignof(PayloadOffset_t)); + uint64_t potentialBackOffsetAddress = + iox::cxx::align(headerEndAddress, static_cast(alignof(PayloadOffset_t))); uint64_t potentialPayloadAddress = potentialBackOffsetAddress + sizeof(PayloadOffset_t); uint64_t alignedPayloadAddress = iox::cxx::align(potentialPayloadAddress, static_cast(payloadAlignment)); From 45faa1d2a55b09384cebf0fc94486d4618285219 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Tue, 16 Mar 2021 21:09:12 +0100 Subject: [PATCH 58/89] iox-#14 additional tests for mepoo::MemoryManager Signed-off-by: Mathias Kraus --- doc/design/chunk_header.md | 6 +- iceoryx_posh/source/mepoo/memory_manager.cpp | 5 +- .../moduletests/test_mepoo_memory_manager.cpp | 215 +++++++++++++++++- 3 files changed, 215 insertions(+), 11 deletions(-) diff --git a/doc/design/chunk_header.md b/doc/design/chunk_header.md index e3fdc5e4ae..f6d55e1a41 100644 --- a/doc/design/chunk_header.md +++ b/doc/design/chunk_header.md @@ -115,7 +115,7 @@ Depending on the address of the chunk there is the chance that `ChunkHeader` is payloadOffset = sizeof(ChunkHeader); ``` -2. No custom header and payload alignment exceeds the `ChunkHeader` alignment, which means the payload is either adjacent to the `ChunkHeader` or there is a padding with at least the size of `ChunkHeader` in front of the payload and therefore enough space to store the `back-offset` +2. No custom header and payload alignment exceeds the `ChunkHeader` alignment, which means the payload is either adjacent to the `ChunkHeader` or there is a padding with at least the size of `ChunkHeader` alignment in front of the payload and therefore enough space to store the `back-offset` ``` headerEndAddress = addressof(chunkHeader) + sizeof(chunkHeader); @@ -192,8 +192,8 @@ The following formula is used to calculate the required chunk size. ``` headerSize = sizeof(chunkHeader) + sizeof(customHeader) prePayloadAlignmentOverhang = align(headerSize, alignof(payloadOffset)); -maxAlignment = max(alignof(payloadOffset), payloadAlignment); -chunkSize = prePayloadAlignmentOverhang + maxAlignment + payloadSize; +maxPadding = max(sizeof(payloadOffset), payloadAlignment); +chunkSize = prePayloadAlignmentOverhang + maxPadding + payloadSize; ``` #### Accessing Chunk Header Extension diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index e100964337..79d384b36b 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -124,11 +124,12 @@ uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, } // the most complex case with a custom header + constexpr uint64_t SIZE_OF_PAYLOAD_OFFSET_T{sizeof(ChunkHeader::PayloadOffset_t)}; constexpr uint64_t ALIGNMENT_OF_PAYLOAD_OFFSET_T{alignof(ChunkHeader::PayloadOffset_t)}; uint64_t headerSize = static_cast(sizeof(ChunkHeader) + customHeaderSize); uint64_t prePayloadAlignmentOverhang = cxx::align(headerSize, ALIGNMENT_OF_PAYLOAD_OFFSET_T); - uint64_t maxAlignment = algorithm::max(ALIGNMENT_OF_PAYLOAD_OFFSET_T, static_cast(payloadAlignment)); - uint64_t chunkSize = prePayloadAlignmentOverhang + maxAlignment + payloadSize; + uint64_t maxPadding = algorithm::max(SIZE_OF_PAYLOAD_OFFSET_T, static_cast(payloadAlignment)); + uint64_t chunkSize = prePayloadAlignmentOverhang + maxPadding + payloadSize; cxx::Ensures(chunkSize <= std::numeric_limits::max() && "Size of chunk exceeds limits!"); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 55032983ab..6f239b3930 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -38,12 +38,6 @@ class MemoryManager_test : public Test free(rawMemory); }; - uint32_t adjustedChunkSize(uint32_t chunkSize) - { - // internally, the chunks are adjusted to the additional management information - return chunkSize + sizeof(iox::mepoo::ChunkHeader); - } - static constexpr uint32_t PAYLOAD_ALIGNMENT = iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT; static constexpr uint32_t CUSTOM_HEADER_SIZE = iox::CHUNK_NO_CUSTOM_HEADER_SIZE; static constexpr uint32_t CUSTOM_HEADER_ALIGNMENT = iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT; @@ -340,3 +334,212 @@ TEST_F(MemoryManager_test, addMemPoolWithChunkCountZeroShouldFail) mempoolconf.addMemPool({32, 0}); EXPECT_DEATH({ sut->configureMemoryManager(mempoolconf, allocator, allocator); }, ".*"); } + +TEST_F(MemoryManager_test, requiredChunkSizeWithAllZeroAsParameterResultsInSizeOfChunkHeader) +{ + constexpr uint32_t PAYLOAD_SIZE{0U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{0U}; + constexpr uint32_t CUSTOM_HEADER_SIZE{0U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{0U}; + + constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader)}; + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithZeroPayloadAndDefaultValuesResultsInSizeOfChunkHeader) +{ + constexpr uint32_t PAYLOAD_SIZE{0U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; + constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + + constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader)}; + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithPayloadAlignmentLessThanChunkHeaderAlignmentResultsInAdjacentPayload) +{ + constexpr uint32_t PAYLOAD_SIZE{42U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) / 2}; + constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + + constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + PAYLOAD_SIZE}; + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithPayloadAlignmentEqualToChunkHeaderAlignmentResultsInAdjacentPayload) +{ + constexpr uint32_t PAYLOAD_SIZE{73U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + + constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + PAYLOAD_SIZE}; + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithPayloadAlignmentGreaterThanChunkHeaderAlignmentAddsPaddingBytes) +{ + constexpr uint32_t PAYLOAD_SIZE{37U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; + constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + constexpr uint32_t PADDING_BYTES{PAYLOAD_ALIGNMENT}; + + constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) - alignof(iox::mepoo::ChunkHeader) + PADDING_BYTES + + PAYLOAD_SIZE}; + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentLessThanChunkHeaderAlignmentAndAdjacentPayload) +{ + constexpr uint32_t PAYLOAD_SIZE{42U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; + constexpr uint32_t BACK_OFFSET{sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; + + constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + CUSTOM_HEADER_SIZE + BACK_OFFSET + PAYLOAD_SIZE}; + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(alignof(iox::mepoo::ChunkHeader::PayloadOffset_t), Lt(alignof(iox::mepoo::ChunkHeader))); + EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentLessThanChunkHeaderAlignmentAddsPaddingBytes) +{ + constexpr uint32_t PAYLOAD_SIZE{42U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; + constexpr uint32_t PADDING_BYTES{PAYLOAD_ALIGNMENT}; + + constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + CUSTOM_HEADER_SIZE + PADDING_BYTES + + PAYLOAD_SIZE}; + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(alignof(iox::mepoo::ChunkHeader::PayloadOffset_t), Lt(alignof(iox::mepoo::ChunkHeader))); + EXPECT_THAT(PADDING_BYTES, Ge(sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t))); + EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentEqualToChunkHeaderAlignmentAddsPaddingBytes) +{ + constexpr uint32_t PAYLOAD_SIZE{42U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(iox::mepoo::ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(iox::mepoo::ChunkHeader)}; + constexpr uint32_t PADDING_BYTES{PAYLOAD_ALIGNMENT}; + + constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + CUSTOM_HEADER_SIZE + PADDING_BYTES + + PAYLOAD_SIZE}; + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(PADDING_BYTES, Ge(sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t))); + EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAndPayloadAlignmentAddsPaddingBytes) +{ + constexpr uint32_t PAYLOAD_SIZE{42U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(iox::mepoo::ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(iox::mepoo::ChunkHeader)}; + constexpr uint32_t PADDING_BYTES{PAYLOAD_ALIGNMENT}; + + constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + CUSTOM_HEADER_SIZE + PADDING_BYTES + + PAYLOAD_SIZE}; + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(PADDING_BYTES, Ge(sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t))); + EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithoutCustomPayloadAlignmentAndTooLargePayloadFails) +{ + constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; + constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; + constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + + EXPECT_DEATH( + { + iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + }, + ".*"); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithCustomPayloadAlignmentAndTooLargePayloadFails) +{ + constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; + constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; + constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + + EXPECT_DEATH( + { + iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + }, + ".*"); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAndTooLargePayloadFails) +{ + constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; + constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; + constexpr uint32_t CUSTOM_HEADER_SIZE{8U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{8U}; + + EXPECT_DEATH( + { + iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + }, + ".*"); +} + +TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentLargerThanChunkHeaderAlignmentFails) +{ + constexpr uint32_t PAYLOAD_SIZE{0U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; + constexpr uint32_t CUSTOM_HEADER_SIZE{8U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{2 * alignof(iox::mepoo::ChunkHeader)}; + + EXPECT_DEATH( + { + iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + }, + ".*"); +} From 1ac4df3bda76d47dd6012acdab75f9c8f1c4f80d Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Tue, 16 Mar 2021 21:25:26 +0100 Subject: [PATCH 59/89] iox-#14 simplify code according to review findings Signed-off-by: Mathias Kraus --- iceoryx_binding_c/source/c_publisher.cpp | 2 +- .../internal/popo/building_blocks/chunk_sender.inl | 10 +++++----- iceoryx_posh/source/mepoo/chunk_header.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iceoryx_binding_c/source/c_publisher.cpp b/iceoryx_binding_c/source/c_publisher.cpp index 2923a1cf6f..c0111f4ef6 100644 --- a/iceoryx_binding_c/source/c_publisher.cpp +++ b/iceoryx_binding_c/source/c_publisher.cpp @@ -103,7 +103,7 @@ iox_AllocationResult iox_pub_loan_chunk(iox_pub_t const self, void** const chunk { auto result = PublisherPortUser(self->m_portData) .tryAllocateChunk(payloadSize, CHUNK_DEFAULT_PAYLOAD_ALIGNMENT) - .and_then([&](ChunkHeader* h) { *chunk = h->payload(); }); + .and_then([&chunk](ChunkHeader* h) { *chunk = h->payload(); }); if (result.has_error()) { return cpp2c::AllocationResult(result.get_error()); diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl index 2e3384a481..3eb99c212e 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl @@ -52,17 +52,17 @@ ChunkSender::tryAllocate(const uint32_t payloadSize, const uint32_t neededChunkSize = getMembers()->m_memoryMgr->requiredChunkSize( payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); - if (getMembers()->m_lastChunk && getMembers()->m_lastChunk.hasNoOtherOwners() - && (getMembers()->m_lastChunk.getChunkHeader()->chunkSize >= neededChunkSize)) + auto& lastChunk = getMembers()->m_lastChunk; + if (lastChunk && lastChunk.hasNoOtherOwners() && (lastChunk.getChunkHeader()->chunkSize >= neededChunkSize)) { - if (getMembers()->m_chunksInUse.insert(getMembers()->m_lastChunk)) + if (getMembers()->m_chunksInUse.insert(lastChunk)) { - auto chunkHeader = getMembers()->m_lastChunk.getChunkHeader(); + auto chunkHeader = lastChunk.getChunkHeader(); auto chunkSize = chunkHeader->chunkSize; chunkHeader->~ChunkHeader(); new (chunkHeader) mepoo::ChunkHeader(chunkSize, payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); - return cxx::success(getMembers()->m_lastChunk.getChunkHeader()); + return cxx::success(lastChunk.getChunkHeader()); } else { diff --git a/iceoryx_posh/source/mepoo/chunk_header.cpp b/iceoryx_posh/source/mepoo/chunk_header.cpp index 6276ca7c2b..9e39bb3a27 100644 --- a/iceoryx_posh/source/mepoo/chunk_header.cpp +++ b/iceoryx_posh/source/mepoo/chunk_header.cpp @@ -37,7 +37,7 @@ ChunkHeader::ChunkHeader(const uint32_t chunkSize, this->payloadSize = payloadSize; // have a look at »Payload Offset Calculation« in chunk_header.md for more details regarding the calculation - if (customHeaderSize == 0) + if (customHeaderSize == 0U) { if (payloadAlignment <= alignof(mepoo::ChunkHeader)) { From 874c370a471dcb63d55910d386d487a7ddcdd9e8 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Tue, 16 Mar 2021 21:32:23 +0100 Subject: [PATCH 60/89] iox-#14 add noexcept specifier to mepoo::MemoryManager Signed-off-by: Mathias Kraus --- .../internal/mepoo/memory_manager.hpp | 28 +++++++++---------- iceoryx_posh/source/mepoo/memory_manager.cpp | 24 ++++++++-------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp index 022756c7b7..db98d6cd2f 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp @@ -41,44 +41,44 @@ class MemoryManager using MaxChunkPayloadSize_t = cxx::range::max() - sizeof(ChunkHeader)>; public: - MemoryManager() = default; + MemoryManager() noexcept = default; MemoryManager(const MemoryManager&) = delete; MemoryManager(MemoryManager&&) = delete; MemoryManager& operator=(const MemoryManager&) = delete; MemoryManager& operator=(MemoryManager&&) = delete; - ~MemoryManager() = default; + ~MemoryManager() noexcept = default; void configureMemoryManager(const MePooConfig& f_mePooConfig, posix::Allocator* f_managementAllocator, - posix::Allocator* f_payloadAllocator); + posix::Allocator* f_payloadAllocator) noexcept; SharedChunk getChunk(const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, - const uint32_t customHeaderAlignment); + const uint32_t customHeaderAlignment) noexcept; - uint32_t getNumberOfMemPools() const; + uint32_t getNumberOfMemPools() const noexcept; - MemPoolInfo getMemPoolInfo(uint32_t f_index) const; + MemPoolInfo getMemPoolInfo(uint32_t f_index) const noexcept; static uint32_t requiredChunkSize(const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, - const uint32_t customHeaderAlignment); + const uint32_t customHeaderAlignment) noexcept; - static uint64_t requiredChunkMemorySize(const MePooConfig& f_mePooConfig); - static uint64_t requiredManagementMemorySize(const MePooConfig& f_mePooConfig); - static uint64_t requiredFullMemorySize(const MePooConfig& f_mePooConfig); + static uint64_t requiredChunkMemorySize(const MePooConfig& f_mePooConfig) noexcept; + static uint64_t requiredManagementMemorySize(const MePooConfig& f_mePooConfig) noexcept; + static uint64_t requiredFullMemorySize(const MePooConfig& f_mePooConfig) noexcept; private: - static uint32_t sizeWithChunkHeaderStruct(const MaxChunkPayloadSize_t size); + static uint32_t sizeWithChunkHeaderStruct(const MaxChunkPayloadSize_t size) noexcept; - void printMemPoolVector() const; + void printMemPoolVector() const noexcept; void addMemPool(posix::Allocator* f_managementAllocator, posix::Allocator* f_payloadAllocator, const cxx::greater_or_equal f_payloadSize, - const cxx::greater_or_equal f_numberOfChunks); - void generateChunkManagementPool(posix::Allocator* f_managementAllocator); + const cxx::greater_or_equal f_numberOfChunks) noexcept; + void generateChunkManagementPool(posix::Allocator* f_managementAllocator) noexcept; private: bool m_denyAddMemPool{false}; diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index 79d384b36b..cc2ad9755b 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -31,7 +31,7 @@ namespace iox { namespace mepoo { -void MemoryManager::printMemPoolVector() const +void MemoryManager::printMemPoolVector() const noexcept { for (auto& l_mempool : m_memPoolVector) { @@ -44,7 +44,7 @@ void MemoryManager::printMemPoolVector() const void MemoryManager::addMemPool(posix::Allocator* f_managementAllocator, posix::Allocator* f_payloadAllocator, const cxx::greater_or_equal f_payloadSize, - const cxx::greater_or_equal f_numberOfChunks) + const cxx::greater_or_equal f_numberOfChunks) noexcept { uint32_t adjustedChunkSize = sizeWithChunkHeaderStruct(static_cast(f_payloadSize)); if (m_denyAddMemPool) @@ -70,19 +70,19 @@ void MemoryManager::addMemPool(posix::Allocator* f_managementAllocator, m_totalNumberOfChunks += f_numberOfChunks; } -void MemoryManager::generateChunkManagementPool(posix::Allocator* f_managementAllocator) +void MemoryManager::generateChunkManagementPool(posix::Allocator* f_managementAllocator) noexcept { m_denyAddMemPool = true; uint32_t chunkSize = sizeof(ChunkManagement); m_chunkManagementPool.emplace_back(chunkSize, m_totalNumberOfChunks, f_managementAllocator, f_managementAllocator); } -uint32_t MemoryManager::getNumberOfMemPools() const +uint32_t MemoryManager::getNumberOfMemPools() const noexcept { return static_cast(m_memPoolVector.size()); } -MemPoolInfo MemoryManager::getMemPoolInfo(uint32_t index) const +MemPoolInfo MemoryManager::getMemPoolInfo(uint32_t index) const noexcept { if (index >= m_memPoolVector.size()) { @@ -94,7 +94,7 @@ MemPoolInfo MemoryManager::getMemPoolInfo(uint32_t index) const uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, - const uint32_t customHeaderAlignment) + const uint32_t customHeaderAlignment) noexcept { /// @todo iox-#14: return cxx::expected instead of using cxx::Expects/Ensures cxx::Expects(customHeaderAlignment <= alignof(ChunkHeader) @@ -136,12 +136,12 @@ uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, return static_cast(chunkSize); } -uint32_t MemoryManager::sizeWithChunkHeaderStruct(const MaxChunkPayloadSize_t size) +uint32_t MemoryManager::sizeWithChunkHeaderStruct(const MaxChunkPayloadSize_t size) noexcept { return size + static_cast(sizeof(ChunkHeader)); } -uint64_t MemoryManager::requiredChunkMemorySize(const MePooConfig& f_mePooConfig) +uint64_t MemoryManager::requiredChunkMemorySize(const MePooConfig& f_mePooConfig) noexcept { uint64_t memorySize{0}; for (const auto& mempoolConfig : f_mePooConfig.m_mempoolConfig) @@ -156,7 +156,7 @@ uint64_t MemoryManager::requiredChunkMemorySize(const MePooConfig& f_mePooConfig return memorySize; } -uint64_t MemoryManager::requiredManagementMemorySize(const MePooConfig& f_mePooConfig) +uint64_t MemoryManager::requiredManagementMemorySize(const MePooConfig& f_mePooConfig) noexcept { uint64_t memorySize{0u}; uint32_t sumOfAllChunks{0u}; @@ -174,14 +174,14 @@ uint64_t MemoryManager::requiredManagementMemorySize(const MePooConfig& f_mePooC return memorySize; } -uint64_t MemoryManager::requiredFullMemorySize(const MePooConfig& f_mePooConfig) +uint64_t MemoryManager::requiredFullMemorySize(const MePooConfig& f_mePooConfig) noexcept { return requiredManagementMemorySize(f_mePooConfig) + requiredChunkMemorySize(f_mePooConfig); } void MemoryManager::configureMemoryManager(const MePooConfig& f_mePooConfig, posix::Allocator* f_managementAllocator, - posix::Allocator* f_payloadAllocator) + posix::Allocator* f_payloadAllocator) noexcept { for (auto entry : f_mePooConfig.m_mempoolConfig) { @@ -194,7 +194,7 @@ void MemoryManager::configureMemoryManager(const MePooConfig& f_mePooConfig, SharedChunk MemoryManager::getChunk(const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, - const uint32_t customHeaderAlignment) + const uint32_t customHeaderAlignment) noexcept { void* chunk{nullptr}; MemPool* memPoolPointer{nullptr}; From bf9164ad5ef76bb68dbf58f8ebffa59e0fb7d654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietrich=20Kr=C3=B6nke?= Date: Mon, 15 Mar 2021 13:16:13 +0100 Subject: [PATCH 61/89] iox-#495 remove calculation from callback integrationtests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dietrich Krönke --- .../iceoryx_integrationtest/test_callback_example.py | 4 ++-- .../iceoryx_integrationtest/test_callback_in_c_example.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iceoryx_integrationtest/iceoryx_integrationtest/test_callback_example.py b/iceoryx_integrationtest/iceoryx_integrationtest/test_callback_example.py index 682a6df038..e88234533a 100755 --- a/iceoryx_integrationtest/iceoryx_integrationtest/test_callback_example.py +++ b/iceoryx_integrationtest/iceoryx_integrationtest/test_callback_example.py @@ -90,9 +90,9 @@ def test_callback_example_data_exchange(self, proc_output): proc_output.assertWaitFor( 'Radar.FrontRight.Counter sending : 16', timeout=45, stream='stdout') proc_output.assertWaitFor( - 'received: 10', timeout=45, stream='stdout') + 'received: 20', timeout=45, stream='stdout') proc_output.assertWaitFor( - 'Received samples from FrontLeft and FrontRight. Sum of 9 + 16 = 25', timeout=45, stream='stdout') + 'Received samples from FrontLeft and FrontRight. Sum of', timeout=45, stream='stdout') # These tests run after shutdown and examine the stdout log diff --git a/iceoryx_integrationtest/iceoryx_integrationtest/test_callback_in_c_example.py b/iceoryx_integrationtest/iceoryx_integrationtest/test_callback_in_c_example.py index e4434dd21a..82f44e1dc9 100755 --- a/iceoryx_integrationtest/iceoryx_integrationtest/test_callback_in_c_example.py +++ b/iceoryx_integrationtest/iceoryx_integrationtest/test_callback_in_c_example.py @@ -90,9 +90,9 @@ def test_callback_example_data_exchange(self, proc_output): proc_output.assertWaitFor( 'Radar.FrontRight.Counter sending : 16', timeout=45, stream='stdout') proc_output.assertWaitFor( - 'received: 10', timeout=45, stream='stdout') + 'received: 20', timeout=45, stream='stdout') proc_output.assertWaitFor( - 'Received samples from FrontLeft and FrontRight. Sum of 9 + 22 = 31', timeout=45, stream='stdout') + 'Received samples from FrontLeft and FrontRight. Sum of', timeout=45, stream='stdout') # These tests run after shutdown and examine the stdout log From a8bba4ad12769ccc13c9b995e70e2b7cba350bd7 Mon Sep 17 00:00:00 2001 From: "Hintz Martin (XC-AD/ESB5)" Date: Wed, 17 Mar 2021 09:58:43 +0100 Subject: [PATCH 62/89] iox-#496 Fix typos Signed-off-by: Hintz Martin (XC-AD/ESB5) --- iceoryx_posh/test/moduletests/test_roudi_portpool.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 7307e2e4fa..8db2fb462e 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -166,7 +166,7 @@ TEST_F(PortPool_test, AddPublisherPortWithMaxCapacityIsSuccessful) } } -TEST_F(PortPool_test, AddPublisherPortWhenPublisherListOverflowsReurnsError) +TEST_F(PortPool_test, AddPublisherPortWhenPublisherListOverflowsReturnsError) { auto errorHandlerCalled{false}; Error errorHandlerType; @@ -279,7 +279,7 @@ TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) } -TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReurnsError) +TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReturnsError) { auto errorHandlerCalled{false}; Error errorHandlerType; @@ -582,8 +582,7 @@ TEST_F(PortPool_test, GetServiceRegistryChangeCounterReturnsZeroAsInitialValue) EXPECT_EQ(serviceCounter->load(), 0U); } - -TEST_F(PortPool_test, GetServiceRegistryChangeCounterIsSuccessfull) +TEST_F(PortPool_test, GetServiceRegistryChangeCounterIsSuccessful) { sut.serviceRegistryChangeCounter()->fetch_add(1, std::memory_order_relaxed); auto serviceCounter = sut.serviceRegistryChangeCounter(); From 127733694b1a223f61edffff9c0fa65579a3c12e Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Wed, 17 Mar 2021 11:41:02 +0100 Subject: [PATCH 63/89] iox-#404 Choose saner name for test case Signed-off-by: Simon Hoinkis --- iceoryx_utils/test/moduletests/test_posix_file_lock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp index 705b9340e9..ccf847d7c1 100644 --- a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp +++ b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp @@ -90,7 +90,7 @@ TEST_F(FileLock_test, LockAndReleaseWorks) ASSERT_FALSE(sut2.has_error()); } -TEST_F(FileLock_test, LockAndNoReleaseLeadsToError) +TEST_F(FileLock_test, CreatingSameFileLockAgainFails) { auto sut2 = iox::posix::FileLock::create(TEST_NAME); ASSERT_TRUE(sut2.has_error()); From 8324ea95fbce0833ca2cd5ecd6fa93a8987f7511 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 17 Mar 2021 13:07:13 +0100 Subject: [PATCH 64/89] iox-#14 add U suffix Signed-off-by: Mathias Kraus --- iceoryx_posh/source/mepoo/memory_manager.cpp | 2 +- .../moduletests/test_mepoo_chunk_header.cpp | 8 +++--- .../moduletests/test_popo_chunk_queue.cpp | 26 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index cc2ad9755b..f7010d7639 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -200,7 +200,7 @@ SharedChunk MemoryManager::getChunk(const uint32_t payloadSize, MemPool* memPoolPointer{nullptr}; uint32_t requiredChunkSize = MemoryManager::requiredChunkSize(payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); - uint32_t aquiredChunkSize = 0; + uint32_t aquiredChunkSize = 0U; for (auto& memPool : m_memPoolVector) { diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 798c66f63a..7e58da85e5 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -51,7 +51,7 @@ class ChunkHeader_test : public Test TEST_F(ChunkHeader_test, ChunkHeaderHasInitializedMembers) { - constexpr uint32_t CHUNK_SIZE{32}; + constexpr uint32_t CHUNK_SIZE{32U}; constexpr uint32_t PAYLOAD_SIZE{8U}; ChunkHeader sut{CHUNK_SIZE, PAYLOAD_SIZE, @@ -120,7 +120,7 @@ TEST_F(ChunkHeader_test, FromPayloadFunctionCalledWithNullptrReturnsNullptr) TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderWhenPayloadIsZero) { - constexpr uint32_t CHUNK_SIZE{32}; + constexpr uint32_t CHUNK_SIZE{32U}; constexpr uint32_t PAYLOAD_SIZE{0U}; ChunkHeader sut{CHUNK_SIZE, PAYLOAD_SIZE, @@ -134,7 +134,7 @@ TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderWhenPayloadIsZero) TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderPlusOneWhenPayloadIsOne) { - constexpr uint32_t CHUNK_SIZE{32}; + constexpr uint32_t CHUNK_SIZE{32U}; constexpr uint32_t PAYLOAD_SIZE{1U}; ChunkHeader sut{CHUNK_SIZE, PAYLOAD_SIZE, @@ -148,7 +148,7 @@ TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderPlusOneWhenPayloadIsOne TEST_F(ChunkHeader_test, usedChunkSizeTerminatesWhenPayloadSizeExceedsChunkSize) { - constexpr uint32_t CHUNK_SIZE{32}; + constexpr uint32_t CHUNK_SIZE{32U}; constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; ChunkHeader sut{CHUNK_SIZE, PAYLOAD_SIZE, diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp index 179a967258..94bcc563ed 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp @@ -51,15 +51,15 @@ class ChunkQueue_testBase return SharedChunk(chunkMgmt); } - static constexpr uint32_t PAYLOAD_SIZE{128}; - static constexpr size_t MEGABYTE = 1 << 20; - static constexpr size_t MEMORY_SIZE = 4 * MEGABYTE; + static constexpr uint32_t PAYLOAD_SIZE{128U}; + static constexpr size_t MEGABYTE = 1U << 20U; + static constexpr size_t MEMORY_SIZE = 4U * MEGABYTE; std::unique_ptr memory{new char[MEMORY_SIZE]}; iox::posix::Allocator allocator{memory.get(), MEMORY_SIZE}; - MemPool mempool{PAYLOAD_SIZE, 2 * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; - MemPool chunkMgmtPool{PAYLOAD_SIZE, 2 * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; + MemPool mempool{PAYLOAD_SIZE, 2U * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; + MemPool chunkMgmtPool{PAYLOAD_SIZE, 2U * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; - static constexpr uint32_t RESIZED_CAPACITY{5u}; + static constexpr uint32_t RESIZED_CAPACITY{5U}; }; template @@ -114,7 +114,7 @@ TYPED_TEST(ChunkQueue_test, PushOneChunk) /// @note size not implemented on FIFO if (this->m_variantQueueType != iox::cxx::VariantQueueTypes::FiFo_SingleProducerSingleConsumer) { - EXPECT_THAT(this->m_popper.size(), Eq(1u)); + EXPECT_THAT(this->m_popper.size(), Eq(1U)); } } @@ -128,7 +128,7 @@ TYPED_TEST(ChunkQueue_test, PopOneChunk) /// @note size not implemented on FIFO if (this->m_variantQueueType != iox::cxx::VariantQueueTypes::FiFo_SingleProducerSingleConsumer) { - EXPECT_THAT(this->m_popper.size(), Eq(0u)); + EXPECT_THAT(this->m_popper.size(), Eq(0U)); } } @@ -233,7 +233,7 @@ class ChunkQueueFiFo_test : public Test, public ChunkQueue_testBase /// @note API currently not supported TYPED_TEST(ChunkQueueFiFo_test, DISABLED_InitialSize) { - EXPECT_THAT(this->m_popper.size(), Eq(0u)); + EXPECT_THAT(this->m_popper.size(), Eq(0U)); } /// @note API currently not supported @@ -251,7 +251,7 @@ TYPED_TEST(ChunkQueueFiFo_test, DISABLED_SetCapacity) TYPED_TEST(ChunkQueueFiFo_test, PushFull) { - for (auto i = 0u; i < iox::MAX_SUBSCRIBER_QUEUE_CAPACITY; ++i) + for (auto i = 0U; i < iox::MAX_SUBSCRIBER_QUEUE_CAPACITY; ++i) { auto chunk = this->allocateChunk(); this->m_pusher.push(chunk); @@ -269,7 +269,7 @@ TYPED_TEST(ChunkQueueFiFo_test, PushFull) } // all chunks must be released - EXPECT_THAT(this->mempool.getUsedChunks(), Eq(0u)); + EXPECT_THAT(this->mempool.getUsedChunks(), Eq(0U)); } /// @note this could be changed to a parameterized ChunkQueueOverflowingFIFO_test when there are more FIFOs available @@ -296,7 +296,7 @@ class ChunkQueueSoFi_test : public Test, public ChunkQueue_testBase TYPED_TEST(ChunkQueueSoFi_test, InitialSize) { - EXPECT_THAT(this->m_popper.size(), Eq(0u)); + EXPECT_THAT(this->m_popper.size(), Eq(0U)); } TYPED_TEST(ChunkQueueSoFi_test, Capacity) @@ -328,5 +328,5 @@ TYPED_TEST(ChunkQueueSoFi_test, PushFull) } // all chunks must be released - EXPECT_THAT(this->mempool.getUsedChunks(), Eq(0u)); + EXPECT_THAT(this->mempool.getUsedChunks(), Eq(0U)); } From f0146b01e18e2004cd58d2f17efd4246c8f8f9ad Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 17 Mar 2021 13:49:15 +0100 Subject: [PATCH 65/89] iox-#14 additional tests for ChunkSender Signed-off-by: Mathias Kraus --- .../moduletests/test_popo_chunk_sender.cpp | 71 ++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp index d674de5d0e..7403c588fb 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp @@ -108,12 +108,33 @@ class ChunkSender_test : public Test iox::popo::ChunkSender m_chunkSenderWithHistory{&m_chunkSenderDataWithHistory}; }; -TEST_F(ChunkSender_test, allocate_OneChunk) +TEST_F(ChunkSender_test, allocate_OneChunkWithoutCustomHeaderAndSmallPayloadAlignmentResultsInSmallChunk) { + constexpr uint32_t PAYLOAD_SIZE{SMALL_CHUNK / 2}; + constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + PAYLOAD_SIZE, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + ASSERT_FALSE(maybeChunkHeader.has_error()); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); +} + +TEST_F(ChunkSender_test, allocate_OneChunkWithoutCustomHeaderAndLargePayloadAlignmentResultsInLargeChunk) +{ + constexpr uint32_t PAYLOAD_SIZE{SMALL_CHUNK / 2}; + constexpr uint32_t PAYLOAD_ALIGNMENT{SMALL_CHUNK}; + auto maybeChunkHeader = m_chunkSender.tryAllocate( + PAYLOAD_SIZE, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + ASSERT_FALSE(maybeChunkHeader.has_error()); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); +} + +TEST_F(ChunkSender_test, allocate_OneChunkWithLargeCustomHeaderResultsInLargeChunk) +{ + constexpr uint32_t LARGE_HEADER_SIZE{SMALL_CHUNK}; + auto maybeChunkHeader = m_chunkSender.tryAllocate( + sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), LARGE_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); } TEST_F(ChunkSender_test, allocate_ChunkHasOriginIdSet) @@ -137,7 +158,7 @@ TEST_F(ChunkSender_test, allocate_MultipleChunks) ASSERT_FALSE(chunk2.has_error()); // must be different chunks EXPECT_THAT(*chunk1, Ne(*chunk2)); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(2u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(2U)); } TEST_F(ChunkSender_test, allocate_Overflow) @@ -201,7 +222,7 @@ TEST_F(ChunkSender_test, freeChunk) m_chunkSender.release(chunks[i]); } - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0U)); } TEST_F(ChunkSender_test, freeInvalidChunk) @@ -209,7 +230,7 @@ TEST_F(ChunkSender_test, freeInvalidChunk) auto maybeChunkHeader = m_chunkSender.tryAllocate( sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); auto errorHandlerCalled{false}; auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( @@ -227,7 +248,7 @@ TEST_F(ChunkSender_test, freeInvalidChunk) m_chunkSender.release(&myCrazyChunk); EXPECT_TRUE(errorHandlerCalled); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } TEST_F(ChunkSender_test, sendWithoutReceiver) @@ -235,14 +256,14 @@ TEST_F(ChunkSender_test, sendWithoutReceiver) auto maybeChunkHeader = m_chunkSender.tryAllocate( sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); if (!maybeChunkHeader.has_error()) { auto sample = *maybeChunkHeader; m_chunkSender.send(sample); // chunk is still used because last chunk is stored - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } } @@ -274,7 +295,7 @@ TEST_F(ChunkSender_test, sendMultipleWithoutReceiverAndAlwaysLast) } // Exactly one chunk is used because last chunk is stored - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } TEST_F(ChunkSender_test, sendMultipleWithoutReceiverWithHistoryNoLastReuse) @@ -315,7 +336,7 @@ TEST_F(ChunkSender_test, sendOneWithReceiver) auto maybeChunkHeader = m_chunkSender.tryAllocate( sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); if (!maybeChunkHeader.has_error()) { @@ -444,7 +465,7 @@ TEST_F(ChunkSender_test, sendInvalidChunk) auto maybeChunkHeader = m_chunkSender.tryAllocate( sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); auto errorHandlerCalled{false}; auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( @@ -462,7 +483,7 @@ TEST_F(ChunkSender_test, sendInvalidChunk) m_chunkSender.send(&myCrazyChunk); EXPECT_TRUE(errorHandlerCalled); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } TEST_F(ChunkSender_test, pushToHistory) @@ -487,7 +508,7 @@ TEST_F(ChunkSender_test, pushInvalidChunkToHistory) auto maybeChunkHeader = m_chunkSender.tryAllocate( sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); auto errorHandlerCalled{false}; auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( @@ -505,7 +526,7 @@ TEST_F(ChunkSender_test, pushInvalidChunkToHistory) m_chunkSender.pushToHistory(&myCrazyChunk); EXPECT_TRUE(errorHandlerCalled); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } TEST_F(ChunkSender_test, sendMultipleWithReceiverNoLastReuse) @@ -584,7 +605,7 @@ TEST_F(ChunkSender_test, ReuseLastIfSmaller) auto maybeChunkHeader = m_chunkSender.tryAllocate( BIG_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); auto chunkHeader = *maybeChunkHeader; m_chunkSender.send(chunkHeader); @@ -594,8 +615,8 @@ TEST_F(ChunkSender_test, ReuseLastIfSmaller) ASSERT_FALSE(chunkSmaller.has_error()); // no small chunk used as big one is recycled - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0u)); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0U)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); ASSERT_TRUE(maybeLastChunk.has_value()); @@ -609,7 +630,7 @@ TEST_F(ChunkSender_test, NoReuseOfLastIfBigger) auto maybeChunkHeader = m_chunkSender.tryAllocate( SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); auto chunkHeader = *maybeChunkHeader; m_chunkSender.send(chunkHeader); @@ -619,8 +640,8 @@ TEST_F(ChunkSender_test, NoReuseOfLastIfBigger) ASSERT_FALSE(chunkBigger.has_error()); // no reuse, we hav a small and a big chunk in use - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); ASSERT_TRUE(maybeLastChunk.has_value()); @@ -634,7 +655,7 @@ TEST_F(ChunkSender_test, ReuseOfLastIfBiggerButFitsInChunk) auto maybeChunkHeader = m_chunkSender.tryAllocate( SMALL_CHUNK - 10, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); auto chunkHeader = *maybeChunkHeader; m_chunkSender.send(chunkHeader); @@ -644,8 +665,8 @@ TEST_F(ChunkSender_test, ReuseOfLastIfBiggerButFitsInChunk) ASSERT_FALSE(chunkBigger.has_error()); // reuse as it still fits in the small chunk - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1u)); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(0u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(0U)); auto maybeLastChunk = m_chunkSender.tryGetPreviousChunk(); ASSERT_TRUE(maybeLastChunk.has_value()); @@ -678,5 +699,5 @@ TEST_F(ChunkSender_test, Cleanup) m_chunkSenderWithHistory.releaseAll(); - EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0u)); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(0U)); } From e1720966ed23c58e4832148f074032184f5f1e46 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 17 Mar 2021 13:59:28 +0100 Subject: [PATCH 66/89] iox-#14 additional tests for PublisherPort Signed-off-by: Mathias Kraus --- .../moduletests/test_popo_publisher_port.cpp | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp b/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp index 496a03140c..bbe160e154 100644 --- a/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_publisher_port.cpp @@ -44,7 +44,8 @@ class PublisherPort_test : public Test protected: PublisherPort_test() { - m_mempoolconf.addMemPool({CHUNK_SIZE, NUM_CHUNKS_IN_POOL}); + m_mempoolconf.addMemPool({SMALL_CHUNK, NUM_CHUNKS_IN_POOL}); + m_mempoolconf.addMemPool({BIG_CHUNK, NUM_CHUNKS_IN_POOL}); m_memoryManager.configureMemoryManager(m_mempoolconf, &m_memoryAllocator, &m_memoryAllocator); } @@ -63,7 +64,8 @@ class PublisherPort_test : public Test static constexpr size_t MEMORY_SIZE = 1024 * 1024; uint8_t m_memory[MEMORY_SIZE]; static constexpr uint32_t NUM_CHUNKS_IN_POOL = 20; - static constexpr uint32_t CHUNK_SIZE = 128; + static constexpr uint32_t SMALL_CHUNK = 128; + static constexpr uint32_t BIG_CHUNK = 256; static constexpr uint32_t PAYLOAD_ALIGNMENT = iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT; static constexpr uint32_t CUSTOM_HEADER_SIZE = iox::CHUNK_NO_CUSTOM_HEADER_SIZE; @@ -204,15 +206,38 @@ TEST_F(PublisherPort_test, EXPECT_THAT(caproMessage.m_historyCapacity, Eq(iox::MAX_PUBLISHER_HISTORY)); } -TEST_F(PublisherPort_test, allocatingAChunk) +TEST_F(PublisherPort_test, allocatingAChunkWithoutCustomHeaderAndSmallPayloadAlignmentResultsInSmallChunk) { + constexpr uint32_t PAYLOAD_SIZE{SMALL_CHUNK / 2}; auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( - 10U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } +TEST_F(PublisherPort_test, allocatingAChunkWithoutCustomHeaderAndLargePayloadAlignmentResultsInLargeChunk) +{ + constexpr uint32_t PAYLOAD_SIZE{SMALL_CHUNK / 2}; + constexpr uint32_t LARGE_PAYLOAD_ALIGNMENT{SMALL_CHUNK}; + auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + PAYLOAD_SIZE, LARGE_PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_FALSE(maybeChunkHeader.has_error()); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); +} + +TEST_F(PublisherPort_test, allocatingAChunkWithLargeCustomHeaderResultsInLargeChunk) +{ + constexpr uint32_t PAYLOAD_SIZE{SMALL_CHUNK / 2}; + constexpr uint32_t LARGE_HEADER_SIZE{SMALL_CHUNK}; + auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, LARGE_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_FALSE(maybeChunkHeader.has_error()); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); +} + TEST_F(PublisherPort_test, releasingAnAllocatedChunkReleasesTheMemory) { auto maybeChunkHeader = m_sutNoOfferOnCreateUserSide.tryAllocateChunk( From 7fc5bd8aa59987c0eaeb82c2d7688cdf6fe9e98a Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 17 Mar 2021 14:20:29 +0100 Subject: [PATCH 67/89] iox-#14 switch originId and payloadSize parameter in ChunkSender::tryAllocate Signed-off-by: Mathias Kraus --- .../popo/building_blocks/chunk_sender.hpp | 4 +- .../popo/building_blocks/chunk_sender.inl | 4 +- .../source/popo/ports/publisher_port_user.cpp | 2 +- .../test_popo_chunk_building_blocks.cpp | 4 +- .../moduletests/test_popo_chunk_sender.cpp | 80 +++++++++---------- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp index 337c36cf81..db37c6a838 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp @@ -66,8 +66,8 @@ class ChunkSender : public ChunkDistributor tryAllocate(const uint32_t payloadSize, - const UniquePortId originId, + cxx::expected tryAllocate(const UniquePortId originId, + const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment) noexcept; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl index 3eb99c212e..efb5f13730 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl @@ -42,8 +42,8 @@ inline typename ChunkSender::MemberType_t* ChunkSender inline cxx::expected -ChunkSender::tryAllocate(const uint32_t payloadSize, - const UniquePortId originId, +ChunkSender::tryAllocate(const UniquePortId originId, + const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, const uint32_t customHeaderAlignment) noexcept diff --git a/iceoryx_posh/source/popo/ports/publisher_port_user.cpp b/iceoryx_posh/source/popo/ports/publisher_port_user.cpp index c7bd8c49d9..60abe418f3 100644 --- a/iceoryx_posh/source/popo/ports/publisher_port_user.cpp +++ b/iceoryx_posh/source/popo/ports/publisher_port_user.cpp @@ -45,7 +45,7 @@ PublisherPortUser::tryAllocateChunk(const uint32_t payloadSize, const uint32_t customHeaderAlignment) noexcept { return m_chunkSender.tryAllocate( - payloadSize, getUniqueID(), payloadAlignment, customHeaderSize, customHeaderAlignment); + getUniqueID(), payloadSize, payloadAlignment, customHeaderSize, customHeaderAlignment); } void PublisherPortUser::releaseChunk(mepoo::ChunkHeader* const chunkHeader) noexcept diff --git a/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp b/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp index 59a0492cb9..c69f52b947 100644 --- a/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp +++ b/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp @@ -95,8 +95,8 @@ class ChunkBuildingBlocks_IntegrationTest : public Test for (size_t i = 0; i < ITERATIONS; i++) { m_chunkSender - .tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + .tryAllocate(iox::UniquePortId(), + sizeof(DummySample), iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT) diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp index 7403c588fb..83e6b53111 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp @@ -113,7 +113,7 @@ TEST_F(ChunkSender_test, allocate_OneChunkWithoutCustomHeaderAndSmallPayloadAlig constexpr uint32_t PAYLOAD_SIZE{SMALL_CHUNK / 2}; constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; auto maybeChunkHeader = m_chunkSender.tryAllocate( - PAYLOAD_SIZE, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } @@ -123,7 +123,7 @@ TEST_F(ChunkSender_test, allocate_OneChunkWithoutCustomHeaderAndLargePayloadAlig constexpr uint32_t PAYLOAD_SIZE{SMALL_CHUNK / 2}; constexpr uint32_t PAYLOAD_ALIGNMENT{SMALL_CHUNK}; auto maybeChunkHeader = m_chunkSender.tryAllocate( - PAYLOAD_SIZE, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); } @@ -132,7 +132,7 @@ TEST_F(ChunkSender_test, allocate_OneChunkWithLargeCustomHeaderResultsInLargeChu { constexpr uint32_t LARGE_HEADER_SIZE{SMALL_CHUNK}; auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), LARGE_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), LARGE_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); } @@ -141,7 +141,7 @@ TEST_F(ChunkSender_test, allocate_ChunkHasOriginIdSet) { iox::UniquePortId uniqueId; auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), uniqueId, alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + uniqueId, sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT((*maybeChunkHeader)->originId, Eq(uniqueId)); @@ -150,9 +150,9 @@ TEST_F(ChunkSender_test, allocate_ChunkHasOriginIdSet) TEST_F(ChunkSender_test, allocate_MultipleChunks) { auto chunk1 = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); auto chunk2 = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(chunk1.has_error()); ASSERT_FALSE(chunk2.has_error()); @@ -168,8 +168,8 @@ TEST_F(ChunkSender_test, allocate_Overflow) // tryAllocate chunks until MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY level for (size_t i = 0; i < iox::MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + auto maybeChunkHeader = m_chunkSender.tryAllocate(iox::UniquePortId(), + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -188,7 +188,7 @@ TEST_F(ChunkSender_test, allocate_Overflow) // Allocate one more sample for overflow auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_TRUE(maybeChunkHeader.has_error()); EXPECT_THAT(maybeChunkHeader.get_error(), Eq(iox::popo::AllocationError::TOO_MANY_CHUNKS_ALLOCATED_IN_PARALLEL)); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, @@ -202,8 +202,8 @@ TEST_F(ChunkSender_test, freeChunk) // tryAllocate chunks until MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY level for (size_t i = 0; i < iox::MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + auto maybeChunkHeader = m_chunkSender.tryAllocate(iox::UniquePortId(), + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -228,7 +228,7 @@ TEST_F(ChunkSender_test, freeChunk) TEST_F(ChunkSender_test, freeInvalidChunk) { auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); @@ -254,7 +254,7 @@ TEST_F(ChunkSender_test, freeInvalidChunk) TEST_F(ChunkSender_test, sendWithoutReceiver) { auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); @@ -271,8 +271,8 @@ TEST_F(ChunkSender_test, sendMultipleWithoutReceiverAndAlwaysLast) { for (size_t i = 0; i < 100; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + auto maybeChunkHeader = m_chunkSender.tryAllocate(iox::UniquePortId(), + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -302,8 +302,8 @@ TEST_F(ChunkSender_test, sendMultipleWithoutReceiverWithHistoryNoLastReuse) { for (size_t i = 0; i < 10 * HISTORY_CAPACITY; i++) { - auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(iox::UniquePortId(), + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -334,7 +334,7 @@ TEST_F(ChunkSender_test, sendOneWithReceiver) m_chunkSender.tryAddQueue(&m_chunkQueueData); auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); @@ -364,8 +364,8 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiver) for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + auto maybeChunkHeader = m_chunkSender.tryAllocate(iox::UniquePortId(), + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -402,7 +402,7 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverExternalSequenceNumber) for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), HEADER_SIZE, HEADER_ALIGNMENT); + auto maybeChunkHeader = m_chunkSender.tryAllocate(iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), HEADER_SIZE, HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); if (!maybeChunkHeader.has_error()) @@ -432,8 +432,8 @@ TEST_F(ChunkSender_test, sendTillRunningOutOfChunks) for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + auto maybeChunkHeader = m_chunkSender.tryAllocate(iox::UniquePortId(), + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -455,7 +455,7 @@ TEST_F(ChunkSender_test, sendTillRunningOutOfChunks) }); auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_TRUE(maybeChunkHeader.has_error()); EXPECT_THAT(maybeChunkHeader.get_error(), Eq(iox::popo::AllocationError::RUNNING_OUT_OF_CHUNKS)); } @@ -463,7 +463,7 @@ TEST_F(ChunkSender_test, sendTillRunningOutOfChunks) TEST_F(ChunkSender_test, sendInvalidChunk) { auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); @@ -490,8 +490,8 @@ TEST_F(ChunkSender_test, pushToHistory) { for (size_t i = 0; i < 10 * HISTORY_CAPACITY; i++) { - auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate(iox::UniquePortId(), + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -506,7 +506,7 @@ TEST_F(ChunkSender_test, pushToHistory) TEST_F(ChunkSender_test, pushInvalidChunkToHistory) { auto maybeChunkHeader = m_chunkSender.tryAllocate( - sizeof(DummySample), iox::UniquePortId(), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); @@ -535,8 +535,8 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverNoLastReuse) for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + auto maybeChunkHeader = m_chunkSender.tryAllocate(iox::UniquePortId(), + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -568,8 +568,8 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverLastReuseBecauseAlreadyConsumed for (size_t i = 0; i < NUM_CHUNKS_IN_POOL; i++) { - auto maybeChunkHeader = m_chunkSender.tryAllocate(sizeof(DummySample), - iox::UniquePortId(), + auto maybeChunkHeader = m_chunkSender.tryAllocate(iox::UniquePortId(), + sizeof(DummySample), alignof(DummySample), CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -603,7 +603,7 @@ TEST_F(ChunkSender_test, sendMultipleWithReceiverLastReuseBecauseAlreadyConsumed TEST_F(ChunkSender_test, ReuseLastIfSmaller) { auto maybeChunkHeader = m_chunkSender.tryAllocate( - BIG_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), BIG_CHUNK, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(1).m_usedChunks, Eq(1U)); @@ -611,7 +611,7 @@ TEST_F(ChunkSender_test, ReuseLastIfSmaller) m_chunkSender.send(chunkHeader); auto chunkSmaller = m_chunkSender.tryAllocate( - SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), SMALL_CHUNK, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(chunkSmaller.has_error()); // no small chunk used as big one is recycled @@ -628,7 +628,7 @@ TEST_F(ChunkSender_test, ReuseLastIfSmaller) TEST_F(ChunkSender_test, NoReuseOfLastIfBigger) { auto maybeChunkHeader = m_chunkSender.tryAllocate( - SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), SMALL_CHUNK, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); @@ -636,7 +636,7 @@ TEST_F(ChunkSender_test, NoReuseOfLastIfBigger) m_chunkSender.send(chunkHeader); auto chunkBigger = m_chunkSender.tryAllocate( - BIG_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), BIG_CHUNK, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(chunkBigger.has_error()); // no reuse, we hav a small and a big chunk in use @@ -653,7 +653,7 @@ TEST_F(ChunkSender_test, NoReuseOfLastIfBigger) TEST_F(ChunkSender_test, ReuseOfLastIfBiggerButFitsInChunk) { auto maybeChunkHeader = m_chunkSender.tryAllocate( - SMALL_CHUNK - 10, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), SMALL_CHUNK - 10, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); @@ -661,7 +661,7 @@ TEST_F(ChunkSender_test, ReuseOfLastIfBiggerButFitsInChunk) m_chunkSender.send(chunkHeader); auto chunkBigger = m_chunkSender.tryAllocate( - SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), SMALL_CHUNK, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); ASSERT_FALSE(chunkBigger.has_error()); // reuse as it still fits in the small chunk @@ -682,7 +682,7 @@ TEST_F(ChunkSender_test, Cleanup) for (size_t i = 0; i < HISTORY_CAPACITY; i++) { auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate( - SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), SMALL_CHUNK, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); m_chunkSenderWithHistory.send(*maybeChunkHeader); } @@ -690,7 +690,7 @@ TEST_F(ChunkSender_test, Cleanup) for (size_t i = 0; i < iox::MAX_CHUNKS_ALLOCATED_PER_PUBLISHER_SIMULTANEOUSLY; i++) { auto maybeChunkHeader = m_chunkSenderWithHistory.tryAllocate( - SMALL_CHUNK, iox::UniquePortId(), PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + iox::UniquePortId(), SMALL_CHUNK, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); EXPECT_FALSE(maybeChunkHeader.has_error()); } From 4361f713ae38546ee971545e4690674dad2717cc Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Wed, 17 Mar 2021 18:24:42 +0100 Subject: [PATCH 68/89] iox-#404 Add hint regarding /var/lock directory on QNX and rework installation.md for MkDocs Signed-off-by: Simon Hoinkis --- doc/website/getting-started/installation.md | 149 ++++++++++-------- .../source/posix_wrapper/file_lock.cpp | 5 +- 2 files changed, 84 insertions(+), 70 deletions(-) diff --git a/doc/website/getting-started/installation.md b/doc/website/getting-started/installation.md index 32f7487306..642c23ad18 100644 --- a/doc/website/getting-started/installation.md +++ b/doc/website/getting-started/installation.md @@ -1,35 +1,38 @@ # Installation -iceoryx_utils and iceoryx_posh are deployed as independent cmake packages. Posh is using some functions from utils and is depending on it. You are able to build posh and utils and integrate in into existing cmake projects. +_iceoryx_utils_ and _iceoryx_posh_ are deployed as independent CMake packages. _iceoryx_posh_ is using some functions from _iceoryx_utils_ and is depending on it. ## Prerequisites ### Dependencies - - 64-bit hardware (e.g. x86_64 or aarch64; 32-bit hardware might work, but is not supported) - - [cmake](https://cmake.org), 3.5 or later - - One of the following compilers: - - [gcc](https://gcc.gnu.org), 7.4 or later (5.4 currently supported too) - - [clang](https://clang.llvm.org), 9.0 or later - - [msvc](https://visualstudio.microsoft.com/de/), part of Visual Studio 2019 or later - - [libacl](http://download.savannah.gnu.org/releases/acl/), 2.2 or later. Only for Linux & QNX. - - optional, [ncurses](https://invisible-island.net/ncurses/), 6.2 or later. Required by introspection tool. +- 64-bit hardware (e.g. x86_64 or aarch64; 32-bit hardware might work, but is not supported) +- [cmake](https://cmake.org), 3.5 or later +- One of the following compilers: + - [gcc](https://gcc.gnu.org), 7.4 or later (5.4 currently supported too) + - [clang](https://clang.llvm.org), 9.0 or later + - [msvc](https://visualstudio.microsoft.com/de/), part of Visual Studio 2019 or later +- [libacl](http://download.savannah.gnu.org/releases/acl/), 2.2 or later. Only for Linux & QNX. +- optional, [ncurses](https://invisible-island.net/ncurses/), 6.2 or later. Required by introspection tool. #### Optional, Cyclone DDS Gateway -If you would like to use our Cyclone DDS Gateway you have to install [Cyclone DDS](https://github.com/eclipse-cyclonedds/cyclonedds) first.
+ +If you would like to use our Cyclone DDS Gateway you have to install [Cyclone DDS](https://github.com/eclipse-cyclonedds/cyclonedds) first. Furthermore you have to install: - - [Apache Maven](http://maven.apache.org/download.cgi), 3.5 or later - - [OpenJDK](http://jdk.java.net/11/), 11.0 or later. Alternatively, Java JDK version 8 or later +- [Apache Maven](http://maven.apache.org/download.cgi), 3.5 or later +- [OpenJDK](http://jdk.java.net/11/), 11.0 or later. Alternatively, Java JDK version 8 or later -**Hint:** If you are behind a corporate firewall you may have to adjust the proxy -settings of maven in `/etc/maven/settings.xml`. See: [Maven Proxy Configuration](https://maven.apache.org/settings.html#proxies) +!!! hint + If you are behind a corporate firewall you may have to adjust the proxy + settings of maven in `/etc/maven/settings.xml`. See: [Maven Proxy Configuration](https://maven.apache.org/settings.html#proxies) ### Mac OS -Before installing iceoryx you need to install XCode and git. Optionally, ncurses library is required for +Before installing iceoryx you need to install XCode and git. Optionally, ncurses library is required for the introspection client. To install ncurses locally into your build folder follow these steps -``` + +```bash cd iceoryx ICEORYX_DIR=$PWD mkdir -p build @@ -47,7 +50,8 @@ make install Although we strive to be fully POSIX-compliant, we recommend using Ubuntu 18.04 and at least GCC 7.5.0 for development. You will need to install the following packages: -``` + +```bash sudo apt install gcc g++ cmake libacl1-dev libncurses5-dev pkg-config ``` @@ -57,57 +61,67 @@ Additionally, there is an optional dependency to the MIT licensed [cpptoml](http QNX SDP 7.0 and 7.1 are supported (shipping with gcc 5.4 and gcc 8.3 respectively). -Easiest way to build iceoryx on QNX is using the build script and providing a toolchain file.
+Easiest way to build iceoryx on QNX is using the build script and providing a toolchain file. Example: -``` + +```bash ./tools/iceoryx_build_test.sh -t /home/user/toolchains/qnx/qcc_x86_64_toolchain.cmake ``` +!!! attention + Please make sure the directory `/var/lock` is created by your QNX image ## Build with CMake -**NOTE:** Requires CMake version 3.5 or higher. Building from CMake is the preferred way, for more complex actions like a coverage scan -is a script available (see chapter below). +!!! note + Requires CMake version 3.5 or higher. Building from CMake is the preferred way, for more complex actions like a coverage scan + is a script available (see chapter below). The `CMakeLists.txt` from `iceoryx_meta` can be used to easily develop iceoryx with an IDE. - 1. Clone the repository - ```bash - git clone https://github.com/eclipse-iceoryx/iceoryx.git - ``` - - 2. Generate the necessary build files - ```bash - cd iceoryx - cmake -Bbuild -Hiceoryx_meta #tip: to build all iceoryx components add -DBUILD_ALL to the cmake command - # when you have installed external dependencies like ncurses you have to add them - # to your prefix path - cmake -Bbuild -Hiceoryx_meta -DCMAKE_PREFIX_PATH=$(PWD)/build/dependencies/ - ``` - - 3. Compile the source code - ```bash - cmake --build build - ``` - Tip: You can fasten up the build by appending `-j 4` where 4 stands for the number of parallel build processes. - You can choose more or less depending on your available CPU cores on your machine. - - 4. Install to system - Mac: - ```bash - cmake --build build --target install - ``` - Linux: - ```bash - sudo cmake --build build --target install - ``` - Tip: The installation directory is usually left at its default, which is /usr/local -**NOTE:** Iceoryx is build in Release mode with `-O3` optimization by default. If you want to have debug symbols please -set `CMAKE_BUILD_TYPE=Debug`. +1. Clone the repository + + git clone https://github.com/eclipse-iceoryx/iceoryx.git + +2. Generate the necessary build files + + cd iceoryx + cmake -Bbuild -Hiceoryx_meta + # when you have installed external dependencies like ncurses you have to add them + # to your prefix path + cmake -Bbuild -Hiceoryx_meta -DCMAKE_PREFIX_PATH=$(PWD)/build/dependencies/ + + !!! tip + To build all iceoryx components add `-DBUILD_ALL` to the CMake command + +3. Compile the source code + + cmake --build build + + !!! tip + You can fasten up the build by appending `-j 4` where 4 stands for the number of parallel build processes. + You can choose more or less depending on your available CPU cores on your machine. + +4. Install to system + + Mac: + + cmake --build build --target install + + Linux: + + sudo cmake --build build --target install + + !!! tip + The installation directory is usually left at its default, which is `/usr/local` + + !!! note + iceoryx is build in Release mode with `-O3` optimization by default. If you want to have debug symbols please + set `CMAKE_BUILD_TYPE=Debug`. ### Build options -Please take a look at the cmake file [build_options.cmake](../../../iceoryx_meta/build_options.cmake) to get an overview of the available build options for enabling additional features. +Please take a look at the CMake file [build_options.cmake](../../../iceoryx_meta/build_options.cmake) to get an overview of the available build options for enabling additional features. ### Available CMake switches you can customize for the iceoryx_posh build @@ -129,27 +143,26 @@ As an alternative we provide our build-test script which we use to integrate ice The intention of the script is to more than just building with iceoryx. This is for doing a code coverage scan or for using the adress-sanitizer. The script currently only works for Linux and QNX, it is planned to offer a multi-platform solution. - 1. Clone the repository - ``` - git clone https://github.com/eclipse-iceoryx/iceoryx.git - ``` +1. Clone the repository + + git clone https://github.com/eclipse-iceoryx/iceoryx.git + +1. Build everything - 2. Build everything - ``` - cd iceoryx - ./tools/iceoryx_build_test.sh build-all - ``` + cd iceoryx + ./tools/iceoryx_build_test.sh build-all You can use the help for getting an overview over the available options: - ``` - ./tools/iceoryx_build_test.sh help - ``` + +```bash +./tools/iceoryx_build_test.sh help +``` ## Build with colcon Alternatively, iceoryx can be built with [colcon](https://colcon.readthedocs.io/en/released/user/installation.html) to provide a smooth integration for ROS2 developers. -``` +```bash mkdir -p iceoryx_ws/src cd $_ git clone https://github.com/eclipse-iceoryx/iceoryx.git diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index e0b6e03ca7..d5983d1775 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -191,8 +191,9 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const } case ENOENT: { - std::cerr << "file \"" << m_name << "\"" - << " does not exist" << std::endl; + std::cerr << "directory \"" << PATH_PREFIX << "\"" + << " does not exist. Please create it as described in the filesystem hierarchy standard." + << std::endl; return FileLockError::NO_SUCH_FILE; } case ENOMEM: From 7a1d57e8a5d431d0421fcf7a01635ff5a3648b69 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Wed, 17 Mar 2021 17:34:08 +0100 Subject: [PATCH 69/89] iox-#454 add new tests with empty config Signed-off-by: Jimmy Belloche --- .../test_roudi_iceoryx_roudi_app.cpp | 146 +++++++++++++++--- 1 file changed, 124 insertions(+), 22 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index d7e4565591..26c6367e6a 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -22,6 +22,8 @@ #include "test.hpp" +#include + using namespace ::testing; using ::testing::Return; @@ -32,6 +34,34 @@ namespace iox { namespace test { +class OutputBuffer +{ + public: + OutputBuffer() + { + m_oldBuffer = std::clog.rdbuf(); + std::clog.rdbuf(m_capture.rdbuf()); + } + ~OutputBuffer() + { + std::clog.rdbuf(m_oldBuffer); + } + + std::string str() + { + return m_capture.str(); + } + + void clear() + { + m_capture.str(std::string()); + } + + private: + std::stringstream m_capture; + std::streambuf* m_oldBuffer{nullptr}; +}; + class IceoryxRoudiApp_Child : public IceOryxRouDiApp { public: @@ -64,6 +94,11 @@ class IceoryxRoudiApp_Child : public IceOryxRouDiApp { return run(); } + + bool callWaitForSignal() + { + return waitForSignal(); + } }; /// @brief Test goal: This file tests class roudi app @@ -72,37 +107,49 @@ class IceoryxRoudiApp_test : public Test public: CmdLineParserConfigFileOption cmdLineParser; + void SetUp() override + { + outBuffer.clear(); + } + void TearDown() { // Reset optind to be able to parse again optind = 0; }; + + OutputBuffer outBuffer; + const std::regex colorCode{"\\x1B\\[([0-9]*;?)*m"}; }; -TEST_F(IceoryxRoudiApp_test, VerifyConstructorIsSuccessfull) +TEST_F(IceoryxRoudiApp_test, VerifyConstructorIsSuccessful) { - constexpr uint8_t numberOfArgs{1U}; - char* args[numberOfArgs]; + constexpr uint8_t NUMBER_OF_ARGS{1U}; + char* args[NUMBER_OF_ARGS]; char appName[] = "./foo"; args[0] = &appName[0]; - auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + auto cmdLineArgs = cmdLineParser.parse(NUMBER_OF_ARGS, args); + + ASSERT_FALSE(cmdLineArgs.has_error()); IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); EXPECT_TRUE(roudi.getVariableRun()); - EXPECT_THAT(roudi.getLogLevel(), Eq(iox::log::LogLevel::kWarn)); - EXPECT_THAT(roudi.getMonitoringMode(), Eq(roudi::MonitoringMode::ON)); + EXPECT_EQ(roudi.getLogLevel(), iox::log::LogLevel::kWarn); + EXPECT_EQ(roudi.getMonitoringMode(), roudi::MonitoringMode::ON); } -TEST_F(IceoryxRoudiApp_test, CreateTwoRoudiAppIsSuccessfull) +TEST_F(IceoryxRoudiApp_test, CreateTwoRoudiAppIsSuccessful) { - constexpr uint8_t numberOfArgs{1U}; - char* args[numberOfArgs]; + constexpr uint8_t NUMBER_OF_ARGS{1U}; + char* args[NUMBER_OF_ARGS]; char appName[] = "./foo"; args[0] = &appName[0]; - auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + auto cmdLineArgs = cmdLineParser.parse(NUMBER_OF_ARGS, args); + + ASSERT_FALSE(cmdLineArgs.has_error()); IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); @@ -113,12 +160,14 @@ TEST_F(IceoryxRoudiApp_test, CreateTwoRoudiAppIsSuccessfull) TEST_F(IceoryxRoudiApp_test, VerifyRunMethodWithFalseConditionReturnExitSuccess) { - constexpr uint8_t numberOfArgs{1U}; - char* args[numberOfArgs]; + constexpr uint8_t NUMBER_OF_ARGS{1U}; + char* args[NUMBER_OF_ARGS]; char appName[] = "./foo"; args[0] = &appName[0]; - auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + auto cmdLineArgs = cmdLineParser.parse(NUMBER_OF_ARGS, args); + + ASSERT_FALSE(cmdLineArgs.has_error()); IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); @@ -131,8 +180,8 @@ TEST_F(IceoryxRoudiApp_test, VerifyRunMethodWithFalseConditionReturnExitSuccess) TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdTwoTimesReturnError) { - constexpr uint8_t numberOfArgs{3U}; - char* args[numberOfArgs]; + constexpr uint8_t NUMBER_OF_ARGS{3U}; + char* args[NUMBER_OF_ARGS]; char appName[] = "./foo"; char option[] = "--unique-roudi-id"; char value[] = "4242"; @@ -140,39 +189,92 @@ TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdTwoTimesReturnError args[1] = &option[0]; args[2] = &value[0]; - auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + auto cmdLineArgs = cmdLineParser.parse(NUMBER_OF_ARGS, args); + + ASSERT_FALSE(cmdLineArgs.has_error()); iox::cxx::optional detectedError; auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); + EXPECT_EQ(errorLevel, iox::ErrorLevel::MODERATE); }); IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); IceoryxRoudiApp_Child roudiTest(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); - ASSERT_THAT(detectedError.has_value(), Eq(true)); - EXPECT_THAT(detectedError.value(), Eq(iox::Error::kPOPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_UNIQUE_ID)); + ASSERT_TRUE(detectedError.has_value()); + EXPECT_EQ(detectedError.value(), iox::Error::kPOPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_UNIQUE_ID); } TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgVersionSetRunVariableToFalse) { - constexpr uint8_t numberOfArgs{2U}; - char* args[numberOfArgs]; + constexpr uint8_t NUMBER_OF_ARGS{2U}; + char* args[NUMBER_OF_ARGS]; char appName[] = "./foo"; char option[] = "-v"; args[0] = &appName[0]; args[1] = &option[0]; - auto cmdLineArgs = cmdLineParser.parse(numberOfArgs, args); + auto cmdLineArgs = cmdLineParser.parse(NUMBER_OF_ARGS, args); + + ASSERT_FALSE(cmdLineArgs.has_error()); IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); EXPECT_FALSE(roudi.getVariableRun()); } +TEST_F(IceoryxRoudiApp_test, VerifyConstructorWithEmptyConfigSetRunVariableToFalse) +{ + constexpr uint8_t NUMBER_OF_ARGS{1U}; + char* args[NUMBER_OF_ARGS]; + char appName[] = "./foo"; + args[0] = &appName[0]; + const std::string expected = "A RouDiConfig without segments was specified! Please provide a valid config!"; + + auto cmdLineArgs = cmdLineParser.parse(NUMBER_OF_ARGS, args); + + ASSERT_FALSE(cmdLineArgs.has_error()); + + iox::RouDiConfig_t roudiConfig; + + IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), roudiConfig); + + std::string output = std::regex_replace(outBuffer.str(), colorCode, std::string("")); + + EXPECT_FALSE(roudi.getVariableRun()); + EXPECT_NE(output.find(expected), std::string::npos); +} + +TEST_F(IceoryxRoudiApp_test, VerifyConstructorUsingConfigWithSegmentWithoutMemPoolSetRunVariableToFalse) +{ + constexpr uint8_t NUMBER_OF_ARGS{1U}; + char* args[NUMBER_OF_ARGS]; + char appName[] = "./foo"; + args[0] = &appName[0]; + const std::string expected = + "A RouDiConfig with segments without mempools was specified! Please provide a valid config!"; + + auto cmdLineArgs = cmdLineParser.parse(NUMBER_OF_ARGS, args); + + ASSERT_FALSE(cmdLineArgs.has_error()); + + iox::mepoo::MePooConfig mempoolConfig; + auto currentGroup = iox::posix::PosixGroup::getGroupOfCurrentProcess(); + + iox::RouDiConfig_t roudiConfig; + + roudiConfig.m_sharedMemorySegments.push_back({currentGroup.getName(), currentGroup.getName(), mempoolConfig}); + + IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), roudiConfig); + + std::string output = std::regex_replace(outBuffer.str(), colorCode, std::string("")); + + EXPECT_FALSE(roudi.getVariableRun()); + EXPECT_NE(output.find(expected), std::string::npos); +} } // namespace test } // namespace iox From 7eee0474bcc7710737a06c9738bd1350f69fd30c Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Wed, 17 Mar 2021 17:35:25 +0100 Subject: [PATCH 70/89] iox-#454 remove useless function Signed-off-by: Jimmy Belloche --- .../test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index 26c6367e6a..b7bd737b4b 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -94,11 +94,6 @@ class IceoryxRoudiApp_Child : public IceOryxRouDiApp { return run(); } - - bool callWaitForSignal() - { - return waitForSignal(); - } }; /// @brief Test goal: This file tests class roudi app From a2e4277689d9810cdd41d61dfa9eb17db8693c69 Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Thu, 18 Mar 2021 10:03:11 +0100 Subject: [PATCH 71/89] iox-#404 Fix build and do some cleanups Signed-off-by: Simon Hoinkis --- doc/website/getting-started/installation.md | 8 ++++---- iceoryx_examples/callbacks_in_c/CMakeLists.txt | 3 --- iceoryx_examples/icedelivery_in_c/CMakeLists.txt | 3 --- iceoryx_examples/waitset_in_c/CMakeLists.txt | 3 --- .../include/iceoryx_utils/posix_wrapper/file_lock.hpp | 2 +- iceoryx_utils/source/posix_wrapper/file_lock.cpp | 2 +- iceoryx_utils/test/moduletests/test_posix_file_lock.cpp | 2 +- 7 files changed, 7 insertions(+), 16 deletions(-) diff --git a/doc/website/getting-started/installation.md b/doc/website/getting-started/installation.md index 642c23ad18..b0a9365d50 100644 --- a/doc/website/getting-started/installation.md +++ b/doc/website/getting-started/installation.md @@ -7,11 +7,11 @@ _iceoryx_utils_ and _iceoryx_posh_ are deployed as independent CMake packages. _ ### Dependencies - 64-bit hardware (e.g. x86_64 or aarch64; 32-bit hardware might work, but is not supported) -- [cmake](https://cmake.org), 3.5 or later +- [CMake](https://cmake.org), 3.5 or later - One of the following compilers: - - [gcc](https://gcc.gnu.org), 7.4 or later (5.4 currently supported too) - - [clang](https://clang.llvm.org), 9.0 or later - - [msvc](https://visualstudio.microsoft.com/de/), part of Visual Studio 2019 or later + - [GCC](https://gcc.gnu.org), 7.4 or later (5.4 currently supported too) + - [Clang](https://clang.llvm.org), 9.0 or later + - [MSVC](https://visualstudio.microsoft.com/de/), part of Visual Studio 2019 or later - [libacl](http://download.savannah.gnu.org/releases/acl/), 2.2 or later. Only for Linux & QNX. - optional, [ncurses](https://invisible-island.net/ncurses/), 6.2 or later. Required by introspection tool. diff --git a/iceoryx_examples/callbacks_in_c/CMakeLists.txt b/iceoryx_examples/callbacks_in_c/CMakeLists.txt index 41de7eb03e..eb1e620149 100644 --- a/iceoryx_examples/callbacks_in_c/CMakeLists.txt +++ b/iceoryx_examples/callbacks_in_c/CMakeLists.txt @@ -27,9 +27,6 @@ if ( NOT ICEORYX_CXX_STANDARD ) include(IceoryxPlatform) endif () -# compiler flag not supported on C -list(REMOVE_ITEM ICEORYX_WARNINGS "-Wno-noexcept-type") - add_executable(iox-ex-c-callbacks-publisher ./ice_c_callbacks_publisher.c) set_source_files_properties(./ice_c_callbacks_publisher.c PROPERTIES LANGUAGE C) target_link_libraries(iox-ex-c-callbacks-publisher diff --git a/iceoryx_examples/icedelivery_in_c/CMakeLists.txt b/iceoryx_examples/icedelivery_in_c/CMakeLists.txt index 3c006078dc..acb0b410a6 100644 --- a/iceoryx_examples/icedelivery_in_c/CMakeLists.txt +++ b/iceoryx_examples/icedelivery_in_c/CMakeLists.txt @@ -28,9 +28,6 @@ if ( NOT ICEORYX_CXX_STANDARD ) include(IceoryxPlatform) endif () -# compiler flag not supported on C -list(REMOVE_ITEM ICEORYX_WARNINGS "-Wno-noexcept-type") - add_executable(iox-c-publisher ./ice_c_publisher.c) set_source_files_properties(./ice_c_publisher.c PROPERTIES LANGUAGE C) target_link_libraries(iox-c-publisher diff --git a/iceoryx_examples/waitset_in_c/CMakeLists.txt b/iceoryx_examples/waitset_in_c/CMakeLists.txt index fd95d182c7..32a822838a 100644 --- a/iceoryx_examples/waitset_in_c/CMakeLists.txt +++ b/iceoryx_examples/waitset_in_c/CMakeLists.txt @@ -26,9 +26,6 @@ if ( NOT ICEORYX_CXX_STANDARD ) include(IceoryxPlatform) endif () -# compiler flag not supported on C -list(REMOVE_ITEM ICEORYX_WARNINGS "-Wno-noexcept-type") - add_executable(iox-ex-c-waitset-publisher ./ice_c_waitset_publisher.c) target_link_libraries(iox-ex-c-waitset-publisher iceoryx_binding_c::iceoryx_binding_c diff --git a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp index 27dbd4401c..28e5302941 100644 --- a/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp +++ b/iceoryx_utils/include/iceoryx_utils/posix_wrapper/file_lock.hpp @@ -35,7 +35,7 @@ enum class FileLockError INVALID_CHARACTERS_IN_FILE_NAME, SYSTEM_LIMIT, PROCESS_LIMIT, - NO_SUCH_FILE, + NO_SUCH_DIRECTORY, SPECIAL_FILE, FILE_TOO_LARGE, FILE_IN_USE, diff --git a/iceoryx_utils/source/posix_wrapper/file_lock.cpp b/iceoryx_utils/source/posix_wrapper/file_lock.cpp index d5983d1775..7bfc57738d 100644 --- a/iceoryx_utils/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_utils/source/posix_wrapper/file_lock.cpp @@ -194,7 +194,7 @@ FileLockError FileLock::convertErrnoToFileLockError(const int32_t errnum) const std::cerr << "directory \"" << PATH_PREFIX << "\"" << " does not exist. Please create it as described in the filesystem hierarchy standard." << std::endl; - return FileLockError::NO_SUCH_FILE; + return FileLockError::NO_SUCH_DIRECTORY; } case ENOMEM: { diff --git a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp index ccf847d7c1..22e34e4bfb 100644 --- a/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp +++ b/iceoryx_utils/test/moduletests/test_posix_file_lock.cpp @@ -67,7 +67,7 @@ TEST_F(FileLock_test, EmptyNameLeadsToError) TEST_F(FileLock_test, MaxStringWorks) { - FileLock::FileName_t maxString{ + const FileLock::FileName_t maxString{ "OeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPalo" "emaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlancaOeLaPaloemaBlanc" "aOeLaPaloemaBlancaOeLaPaloemaB"}; From c71382ce365407d77b3231edf2a1d9eb999f4f46 Mon Sep 17 00:00:00 2001 From: Jimmy Belloche Date: Thu, 18 Mar 2021 11:21:32 +0100 Subject: [PATCH 72/89] iox-#454 add override to teardown method Signed-off-by: Jimmy Belloche --- iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index b7bd737b4b..79bf53864f 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -107,7 +107,7 @@ class IceoryxRoudiApp_test : public Test outBuffer.clear(); } - void TearDown() + void TearDown() override { // Reset optind to be able to parse again optind = 0; From 7aabbe9fe08d57dbb1d6897b0f1ed4825b374ce3 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 18 Mar 2021 13:44:35 +0100 Subject: [PATCH 73/89] iox-#14 clarify the overlapping of payloadOffset and back-offset in the ChunkHeader for the most simple case Signed-off-by: Mathias Kraus --- doc/design/chunk_header.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/design/chunk_header.md b/doc/design/chunk_header.md index f6d55e1a41..a9caa17ef9 100644 --- a/doc/design/chunk_header.md +++ b/doc/design/chunk_header.md @@ -12,7 +12,7 @@ Chunks are the transport capsules in iceoryx. They store data from a publisher a | Chunk Header | contains meta information related to the chunk | | Custom Header | contains custom meta information, e.g. timestamps | | Payload | the user data | -| Back-Offset | offset stored in front of the payload to calculate back to the chunk header | +| Back-Offset | offset stored in front of the payload to calculate back to the chunk header (for the most simple case it will overlap with the payload offset stored in the Chunk Header) | ## Design @@ -62,13 +62,15 @@ For back calculation from the payload pointer to the `ChunkHeader` pointer, the |------------------>|--------------------->| | | | +===================+======================+==================================+ -| ChunkHeader ¦ | Payload | Padding | +| ChunkHeader ¦ * | Payload | Padding | +===================+======================+==================================+ | | | | payloadOffset | | |------------------>| | | chunkSize | |---------------------------------------------------------------------------->| + +*) payloadOffset from ChunkHeader and back-offset are overlapping ``` 2. No custom header and alignment exceeds the `ChunkHeader` alignment From 45c17eaf91720a9f86352fea352c679b8ef82fd0 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 18 Mar 2021 19:50:45 +0100 Subject: [PATCH 74/89] iox-#14 additional tests for mepoo::MemoryManager Signed-off-by: Mathias Kraus --- iceoryx_posh/source/mepoo/memory_manager.cpp | 4 + .../moduletests/test_mepoo_memory_manager.cpp | 80 +++++++++++++++---- 2 files changed, 69 insertions(+), 15 deletions(-) diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index f7010d7639..b5cb005d52 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -97,8 +97,12 @@ uint32_t MemoryManager::requiredChunkSize(const uint32_t payloadSize, const uint32_t customHeaderAlignment) noexcept { /// @todo iox-#14: return cxx::expected instead of using cxx::Expects/Ensures + cxx::Expects(payloadAlignment > 0U && "The payload alignment must be larger than 0!"); + cxx::Expects(customHeaderAlignment > 0U && "The custom header alignment must be larger than 0!"); cxx::Expects(customHeaderAlignment <= alignof(ChunkHeader) && "The alignment of the custom header must not exceed the alignment of the ChunkHeader!"); + cxx::Expects(customHeaderSize % customHeaderAlignment == 0U + && "The size of the custom header must be a multiple of its alignment!"); // have a look at »Required Chunk Size Calculation« in chunk_header.md for more details regarding the calculation if (customHeaderSize == 0) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 6f239b3930..25d8649110 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -335,12 +335,12 @@ TEST_F(MemoryManager_test, addMemPoolWithChunkCountZeroShouldFail) EXPECT_DEATH({ sut->configureMemoryManager(mempoolconf, allocator, allocator); }, ".*"); } -TEST_F(MemoryManager_test, requiredChunkSizeWithAllZeroAsParameterResultsInSizeOfChunkHeader) +TEST_F(MemoryManager_test, requiredChunkSize_AllParameterMinimal_ResultsIn_SizeOfChunkHeader) { constexpr uint32_t PAYLOAD_SIZE{0U}; - constexpr uint32_t PAYLOAD_ALIGNMENT{0U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{1U}; constexpr uint32_t CUSTOM_HEADER_SIZE{0U}; - constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{0U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader)}; @@ -350,7 +350,7 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithAllZeroAsParameterResultsInSizeO EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, requiredChunkSizeWithZeroPayloadAndDefaultValuesResultsInSizeOfChunkHeader) +TEST_F(MemoryManager_test, requiredChunkSize_ZeroPayloadAndDefaultValues_ResultsIn_SizeOfChunkHeader) { constexpr uint32_t PAYLOAD_SIZE{0U}; constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; @@ -365,7 +365,7 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithZeroPayloadAndDefaultValuesResul EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, requiredChunkSizeWithPayloadAlignmentLessThanChunkHeaderAlignmentResultsInAdjacentPayload) +TEST_F(MemoryManager_test, requiredChunkSize_PayloadAlignment_LessThan_ChunkHeaderAlignment_ResultsIn_AdjacentPayload) { constexpr uint32_t PAYLOAD_SIZE{42U}; constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) / 2}; @@ -380,7 +380,7 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithPayloadAlignmentLessThanChunkHea EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, requiredChunkSizeWithPayloadAlignmentEqualToChunkHeaderAlignmentResultsInAdjacentPayload) +TEST_F(MemoryManager_test, requiredChunkSize_PayloadAlignment_EqualTo_ChunkHeaderAlignment_ResultsIn_AdjacentPayload) { constexpr uint32_t PAYLOAD_SIZE{73U}; constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader)}; @@ -395,7 +395,8 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithPayloadAlignmentEqualToChunkHead EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, requiredChunkSizeWithPayloadAlignmentGreaterThanChunkHeaderAlignmentAddsPaddingBytes) +TEST_F(MemoryManager_test, + requiredChunkSize_PayloadAlignment_GreaterThan_ChunkHeaderAlignment_ResultsIn_AddingPaddingBytes) { constexpr uint32_t PAYLOAD_SIZE{37U}; constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; @@ -412,7 +413,8 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithPayloadAlignmentGreaterThanChunk EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentLessThanChunkHeaderAlignmentAndAdjacentPayload) +TEST_F(MemoryManager_test, + requiredChunkSize_CustomHeaderAlignment_LessThan_ChunkHeaderAlignment_AdjacentPayload_ResultsIn_NoPaddingBytes) { constexpr uint32_t PAYLOAD_SIZE{42U}; constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; @@ -429,7 +431,9 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentLessThanChu EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentLessThanChunkHeaderAlignmentAddsPaddingBytes) +TEST_F( + MemoryManager_test, + requiredChunkSize_CustomHeaderAlignment_LessThan_ChunkHeaderAlignment_NonAdjacentPayload_ResultsIn_AddingPaddingBytes) { constexpr uint32_t PAYLOAD_SIZE{42U}; constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; @@ -448,7 +452,8 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentLessThanChu EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentEqualToChunkHeaderAlignmentAddsPaddingBytes) +TEST_F(MemoryManager_test, + requiredChunkSize_CustomHeaderAlignment_EqualTo_ChunkHeaderAlignment_ResultsIn_NonAdjacentPayload) { constexpr uint32_t PAYLOAD_SIZE{42U}; constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; @@ -466,7 +471,7 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentEqualToChun EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAndPayloadAlignmentAddsPaddingBytes) +TEST_F(MemoryManager_test, requiredChunkSize_CustomHeaderAndPayloadAlignment_ResultsIn_AddingPaddingBytes) { constexpr uint32_t PAYLOAD_SIZE{42U}; constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; @@ -484,7 +489,7 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAndPayloadAlignmentA EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, requiredChunkSizeWithoutCustomPayloadAlignmentAndTooLargePayloadFails) +TEST_F(MemoryManager_test, requiredChunkSize_WithoutCustomPayloadAlignmentAndTooLargePayload_Fails) { constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; @@ -499,7 +504,7 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithoutCustomPayloadAlignmentAndTooL ".*"); } -TEST_F(MemoryManager_test, requiredChunkSizeWithCustomPayloadAlignmentAndTooLargePayloadFails) +TEST_F(MemoryManager_test, requiredChunkSize_WithCustomPayloadAlignmentAndTooLargePayload_Fails) { constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; @@ -514,7 +519,7 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithCustomPayloadAlignmentAndTooLarg ".*"); } -TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAndTooLargePayloadFails) +TEST_F(MemoryManager_test, requiredChunkSize_WithCustomHeaderAndTooLargePayload_Fails) { constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; @@ -529,7 +534,37 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAndTooLargePayloadFa ".*"); } -TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentLargerThanChunkHeaderAlignmentFails) +TEST_F(MemoryManager_test, requiredChunkSize_WithPayloadAlignmentOfZero_Fails) +{ + constexpr uint32_t PAYLOAD_SIZE{0U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{0U}; + constexpr uint32_t CUSTOM_HEADER_SIZE{0U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; + + EXPECT_DEATH( + { + iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + }, + ".*"); +} + +TEST_F(MemoryManager_test, requiredChunkSize_WithCustomHeaderAlignmentOfZero_Fails) +{ + constexpr uint32_t PAYLOAD_SIZE{0U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{1U}; + constexpr uint32_t CUSTOM_HEADER_SIZE{0U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{0U}; + + EXPECT_DEATH( + { + iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + }, + ".*"); +} + +TEST_F(MemoryManager_test, requiredChunkSize_WithCustomHeaderAlignmentLargerThanChunkHeaderAlignment_Fails) { constexpr uint32_t PAYLOAD_SIZE{0U}; constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; @@ -543,3 +578,18 @@ TEST_F(MemoryManager_test, requiredChunkSizeWithCustomHeaderAlignmentLargerThanC }, ".*"); } + +TEST_F(MemoryManager_test, requiredChunkSize_WithCustomHeaderSizeNotMultipleOfAlignment_Fails) +{ + constexpr uint32_t PAYLOAD_SIZE{0U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; + constexpr uint32_t CUSTOM_HEADER_SIZE{12U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{8U}; + + EXPECT_DEATH( + { + iox::mepoo::MemoryManager::requiredChunkSize( + PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + }, + ".*"); +} From dfbd3bd13057969e5c58bf3272fd1a586b127a8d Mon Sep 17 00:00:00 2001 From: "Hintz Martin (XC-AD/ESB5)" Date: Fri, 19 Mar 2021 09:13:51 +0100 Subject: [PATCH 75/89] iox-#609 Remove cxx_std_17 from toolchain Signed-off-by: Hintz Martin (XC-AD/ESB5) --- tools/toolchains/qnx/qnx_sdp70_common.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/toolchains/qnx/qnx_sdp70_common.cmake b/tools/toolchains/qnx/qnx_sdp70_common.cmake index cdfc07ffd2..493690f6a7 100644 --- a/tools/toolchains/qnx/qnx_sdp70_common.cmake +++ b/tools/toolchains/qnx/qnx_sdp70_common.cmake @@ -54,7 +54,7 @@ add_compile_options("-D_QNX_SOURCE=1") # The file with the detected compile features is then in the build directory named CMakeCXXCompiler.cmake # A similar bug was reported for Android, see: https://bugreports.qt.io/browse/QTBUG-54666 -set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17") +set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates") set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters") set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates") set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates") From 2e6955c321e53b50a59de159c5360d160f8a65af Mon Sep 17 00:00:00 2001 From: "Hintz Martin (XC-AD/ESB5)" Date: Fri, 19 Mar 2021 09:15:04 +0100 Subject: [PATCH 76/89] iox-#609 Add copyright header Signed-off-by: Hintz Martin (XC-AD/ESB5) --- tools/toolchains/qnx/qnx_sdp70_aarch64le.cmake | 15 +++++++++++++++ tools/toolchains/qnx/qnx_sdp70_common.cmake | 15 +++++++++++++++ tools/toolchains/qnx/qnx_sdp70_x86_64.cmake | 15 +++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/tools/toolchains/qnx/qnx_sdp70_aarch64le.cmake b/tools/toolchains/qnx/qnx_sdp70_aarch64le.cmake index 07ee7dc1db..27fc51b6ff 100644 --- a/tools/toolchains/qnx/qnx_sdp70_aarch64le.cmake +++ b/tools/toolchains/qnx/qnx_sdp70_aarch64le.cmake @@ -1,3 +1,18 @@ +# Copyright (c) 2021 by Robert Bosch GmbH. 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 SET(CMAKE_SYSTEM_PROCESSOR aarch64) SET(arch gcc_ntoaarch64le) diff --git a/tools/toolchains/qnx/qnx_sdp70_common.cmake b/tools/toolchains/qnx/qnx_sdp70_common.cmake index 493690f6a7..5a281b2b13 100644 --- a/tools/toolchains/qnx/qnx_sdp70_common.cmake +++ b/tools/toolchains/qnx/qnx_sdp70_common.cmake @@ -1,3 +1,18 @@ +# Copyright (c) 2021 by Robert Bosch GmbH. 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 SET(CMAKE_SYSTEM_NAME QNX) SET(TOOLCHAIN QNX) diff --git a/tools/toolchains/qnx/qnx_sdp70_x86_64.cmake b/tools/toolchains/qnx/qnx_sdp70_x86_64.cmake index 6ca24e37fb..b32d308802 100644 --- a/tools/toolchains/qnx/qnx_sdp70_x86_64.cmake +++ b/tools/toolchains/qnx/qnx_sdp70_x86_64.cmake @@ -1,3 +1,18 @@ +# Copyright (c) 2021 by Robert Bosch GmbH. 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 SET(CMAKE_SYSTEM_PROCESSOR x86_64) SET(arch gcc_ntox86_64) From ffba13eef71a479efe2d1fdfaa2376e42dc48705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietrich=20Kr=C3=B6nke?= Date: Fri, 19 Mar 2021 10:30:23 +0100 Subject: [PATCH 77/89] iox-#521 disable temporaly PR comments for codecov MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dietrich Krönke --- .codecov.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index e75759e86f..f888a7b804 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,5 +1,5 @@ # codecov yaml -comment: +comment: false layout: "reach, diff, flags, files" behavior: default require_changes: yes @@ -13,12 +13,12 @@ coverage: project: default: enabled: yes - target: 70% + target: auto threshold: 2% # allow coverage to drop maximum by a defined value patch: default: enabled: yes - target: 70% + target: auto changes: no parsers: From 294a2e1ae0eb5986c1571ca9f0d74e6020408fae Mon Sep 17 00:00:00 2001 From: "Hintz Martin (XC-AD/ESB5)" Date: Fri, 19 Mar 2021 13:01:23 +0100 Subject: [PATCH 78/89] iox-#609 Add toolchain examples with supplied qnx files Signed-off-by: Hintz Martin (XC-AD/ESB5) --- doc/website/getting-started/installation.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/website/getting-started/installation.md b/doc/website/getting-started/installation.md index 32f7487306..f1751b15ad 100644 --- a/doc/website/getting-started/installation.md +++ b/doc/website/getting-started/installation.md @@ -58,10 +58,10 @@ Additionally, there is an optional dependency to the MIT licensed [cpptoml](http QNX SDP 7.0 and 7.1 are supported (shipping with gcc 5.4 and gcc 8.3 respectively). Easiest way to build iceoryx on QNX is using the build script and providing a toolchain file.
-Example: -``` -./tools/iceoryx_build_test.sh -t /home/user/toolchains/qnx/qcc_x86_64_toolchain.cmake -``` +We provide generic QNX SDP 7.0 toolchain files for ARM_64 and X86_64 in `./tools/toolchains/qnx` ([Direct Link](https://github.com/eclipse-iceoryx/iceoryx/tree/master/tools/toolchains/qnx)). + +ARM_64: `./tools/iceoryx_build_test.sh -t /home/user/toolchains/qnx/qnx_sdp70_aarch64le.cmake`
+X86_64: `./tools/iceoryx_build_test.sh -t /home/user/toolchains/qnx/qnx_sdp70_x86_64.cmake` ## Build with CMake From 3297cb13a7d97da9e2b91b12dfb744134fb256c1 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 19 Mar 2021 14:32:20 +0100 Subject: [PATCH 79/89] iox-#14 refactor tests for mepoo::MemoryManager::requiredChunkSize Signed-off-by: Mathias Kraus --- .../moduletests/test_mepoo_memory_manager.cpp | 434 ++++++++++++------ 1 file changed, 306 insertions(+), 128 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 25d8649110..b401af4388 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -20,8 +20,13 @@ #include "iceoryx_utils/internal/posix_wrapper/shared_memory_object/allocator.hpp" #include "test.hpp" +namespace +{ using namespace ::testing; +using iox::mepoo::ChunkHeader; +using PayloadOffset_t = iox::mepoo::ChunkHeader::PayloadOffset_t; + class MemoryManager_test : public Test { public: @@ -342,7 +347,7 @@ TEST_F(MemoryManager_test, requiredChunkSize_AllParameterMinimal_ResultsIn_SizeO constexpr uint32_t CUSTOM_HEADER_SIZE{0U}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; - constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader)}; + constexpr uint32_t EXPECTED_SIZE{sizeof(ChunkHeader)}; auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -357,37 +362,7 @@ TEST_F(MemoryManager_test, requiredChunkSize_ZeroPayloadAndDefaultValues_Results constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; - constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader)}; - - auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( - PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - - EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); -} - -TEST_F(MemoryManager_test, requiredChunkSize_PayloadAlignment_LessThan_ChunkHeaderAlignment_ResultsIn_AdjacentPayload) -{ - constexpr uint32_t PAYLOAD_SIZE{42U}; - constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) / 2}; - constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; - constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; - - constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + PAYLOAD_SIZE}; - - auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( - PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - - EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); -} - -TEST_F(MemoryManager_test, requiredChunkSize_PayloadAlignment_EqualTo_ChunkHeaderAlignment_ResultsIn_AdjacentPayload) -{ - constexpr uint32_t PAYLOAD_SIZE{73U}; - constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader)}; - constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; - constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; - - constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + PAYLOAD_SIZE}; + constexpr uint32_t EXPECTED_SIZE{sizeof(ChunkHeader)}; auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -395,99 +370,7 @@ TEST_F(MemoryManager_test, requiredChunkSize_PayloadAlignment_EqualTo_ChunkHeade EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); } -TEST_F(MemoryManager_test, - requiredChunkSize_PayloadAlignment_GreaterThan_ChunkHeaderAlignment_ResultsIn_AddingPaddingBytes) -{ - constexpr uint32_t PAYLOAD_SIZE{37U}; - constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; - constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; - constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; - constexpr uint32_t PADDING_BYTES{PAYLOAD_ALIGNMENT}; - - constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) - alignof(iox::mepoo::ChunkHeader) + PADDING_BYTES - + PAYLOAD_SIZE}; - - auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( - PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - - EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); -} - -TEST_F(MemoryManager_test, - requiredChunkSize_CustomHeaderAlignment_LessThan_ChunkHeaderAlignment_AdjacentPayload_ResultsIn_NoPaddingBytes) -{ - constexpr uint32_t PAYLOAD_SIZE{42U}; - constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; - constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; - constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; - constexpr uint32_t BACK_OFFSET{sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; - - constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + CUSTOM_HEADER_SIZE + BACK_OFFSET + PAYLOAD_SIZE}; - - auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( - PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - - EXPECT_THAT(alignof(iox::mepoo::ChunkHeader::PayloadOffset_t), Lt(alignof(iox::mepoo::ChunkHeader))); - EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); -} - -TEST_F( - MemoryManager_test, - requiredChunkSize_CustomHeaderAlignment_LessThan_ChunkHeaderAlignment_NonAdjacentPayload_ResultsIn_AddingPaddingBytes) -{ - constexpr uint32_t PAYLOAD_SIZE{42U}; - constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; - constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; - constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(iox::mepoo::ChunkHeader::PayloadOffset_t)}; - constexpr uint32_t PADDING_BYTES{PAYLOAD_ALIGNMENT}; - - constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + CUSTOM_HEADER_SIZE + PADDING_BYTES - + PAYLOAD_SIZE}; - - auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( - PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - - EXPECT_THAT(alignof(iox::mepoo::ChunkHeader::PayloadOffset_t), Lt(alignof(iox::mepoo::ChunkHeader))); - EXPECT_THAT(PADDING_BYTES, Ge(sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t))); - EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); -} - -TEST_F(MemoryManager_test, - requiredChunkSize_CustomHeaderAlignment_EqualTo_ChunkHeaderAlignment_ResultsIn_NonAdjacentPayload) -{ - constexpr uint32_t PAYLOAD_SIZE{42U}; - constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; - constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(iox::mepoo::ChunkHeader)}; - constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(iox::mepoo::ChunkHeader)}; - constexpr uint32_t PADDING_BYTES{PAYLOAD_ALIGNMENT}; - - constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + CUSTOM_HEADER_SIZE + PADDING_BYTES - + PAYLOAD_SIZE}; - - auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( - PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - - EXPECT_THAT(PADDING_BYTES, Ge(sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t))); - EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); -} - -TEST_F(MemoryManager_test, requiredChunkSize_CustomHeaderAndPayloadAlignment_ResultsIn_AddingPaddingBytes) -{ - constexpr uint32_t PAYLOAD_SIZE{42U}; - constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; - constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(iox::mepoo::ChunkHeader)}; - constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(iox::mepoo::ChunkHeader)}; - constexpr uint32_t PADDING_BYTES{PAYLOAD_ALIGNMENT}; - - constexpr uint32_t EXPECTED_SIZE{sizeof(iox::mepoo::ChunkHeader) + CUSTOM_HEADER_SIZE + PADDING_BYTES - + PAYLOAD_SIZE}; - - auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( - PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); - - EXPECT_THAT(PADDING_BYTES, Ge(sizeof(iox::mepoo::ChunkHeader::PayloadOffset_t))); - EXPECT_THAT(chunkSize, Eq(EXPECTED_SIZE)); -} +// BEGIN EXCEEDING CHUNK SIZE TESTS TEST_F(MemoryManager_test, requiredChunkSize_WithoutCustomPayloadAlignmentAndTooLargePayload_Fails) { @@ -507,7 +390,7 @@ TEST_F(MemoryManager_test, requiredChunkSize_WithoutCustomPayloadAlignmentAndToo TEST_F(MemoryManager_test, requiredChunkSize_WithCustomPayloadAlignmentAndTooLargePayload_Fails) { constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; - constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; + constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(ChunkHeader) * 2}; constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; @@ -522,7 +405,7 @@ TEST_F(MemoryManager_test, requiredChunkSize_WithCustomPayloadAlignmentAndTooLar TEST_F(MemoryManager_test, requiredChunkSize_WithCustomHeaderAndTooLargePayload_Fails) { constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; - constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(iox::mepoo::ChunkHeader) * 2}; + constexpr uint32_t PAYLOAD_ALIGNMENT{alignof(ChunkHeader) * 2}; constexpr uint32_t CUSTOM_HEADER_SIZE{8U}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{8U}; @@ -534,6 +417,10 @@ TEST_F(MemoryManager_test, requiredChunkSize_WithCustomHeaderAndTooLargePayload_ ".*"); } +// END EXCEEDING CHUNK SIZE TESTS + +// BEGIN INVALID CUSTOM HEADER AND PAYLOAD ALIGNMENT TESTS + TEST_F(MemoryManager_test, requiredChunkSize_WithPayloadAlignmentOfZero_Fails) { constexpr uint32_t PAYLOAD_SIZE{0U}; @@ -569,7 +456,7 @@ TEST_F(MemoryManager_test, requiredChunkSize_WithCustomHeaderAlignmentLargerThan constexpr uint32_t PAYLOAD_SIZE{0U}; constexpr uint32_t PAYLOAD_ALIGNMENT{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; constexpr uint32_t CUSTOM_HEADER_SIZE{8U}; - constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{2 * alignof(iox::mepoo::ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{2 * alignof(ChunkHeader)}; EXPECT_DEATH( { @@ -593,3 +480,294 @@ TEST_F(MemoryManager_test, requiredChunkSize_WithCustomHeaderSizeNotMultipleOfAl }, ".*"); } + +// END INVALID CUSTOM HEADER AND PAYLOAD ALIGNMENT TESTS + +// BEGIN PARAMETERIZED TESTS FOR REQUIRED CHUNK SIZE + +struct PayloadParams +{ + uint32_t size{0U}; + uint32_t alignment{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; +}; + +class MemoryManager_AlteringPayloadWithoutCustomHeader : public ::testing::TestWithParam +{ +}; + +// without a custom header, the payload is located right after the ChunkHeader, therefore the payload size and alignment +// parameters are made dependant on the ChunkHeader +INSTANTIATE_TEST_CASE_P(MemoryManager_test, + MemoryManager_AlteringPayloadWithoutCustomHeader, + ::testing::Values( + // alignment = 1 + PayloadParams{.size = 0U, .alignment = 1U}, + PayloadParams{.size = 1U, .alignment = 1U}, + PayloadParams{.size = sizeof(ChunkHeader), .alignment = 1U}, + PayloadParams{.size = sizeof(ChunkHeader) * 42U, .alignment = 1U}, + // alignment = alignof(ChunkHeader) / 2 + PayloadParams{.size = 0U, .alignment = alignof(ChunkHeader) / 2}, + PayloadParams{.size = 1U, .alignment = alignof(ChunkHeader) / 2}, + PayloadParams{.size = sizeof(ChunkHeader), .alignment = alignof(ChunkHeader) / 2}, + PayloadParams{.size = sizeof(ChunkHeader) * 42U, .alignment = alignof(ChunkHeader) / 2}, + // alignment = alignof(ChunkHeader) + PayloadParams{.size = 0U, .alignment = alignof(ChunkHeader)}, + PayloadParams{.size = 1U, .alignment = alignof(ChunkHeader)}, + PayloadParams{.size = sizeof(ChunkHeader), .alignment = alignof(ChunkHeader)}, + PayloadParams{.size = sizeof(ChunkHeader) * 42U, .alignment = alignof(ChunkHeader)}, + // alignment = alignof(ChunkHeader) * 2 + PayloadParams{.size = 0U, .alignment = alignof(ChunkHeader) * 2}, + PayloadParams{.size = 1U, .alignment = alignof(ChunkHeader) * 2}, + PayloadParams{.size = sizeof(ChunkHeader), .alignment = alignof(ChunkHeader) * 2}, + PayloadParams{.size = sizeof(ChunkHeader) * 42U, .alignment = alignof(ChunkHeader) * 2})); + +TEST_P(MemoryManager_AlteringPayloadWithoutCustomHeader, requiredChunkSizeIsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + + const uint32_t expectedSize = [&payload] { + if (payload.alignment <= alignof(ChunkHeader)) + { + // payload is always adjacent + return static_cast(sizeof(ChunkHeader)) + payload.size; + } + else + { + // payload is not necessarily adjacent + auto prePayloadAlignmentOverhangOfChunkHeder = sizeof(ChunkHeader) - alignof(ChunkHeader); + return static_cast(prePayloadAlignmentOverhangOfChunkHeder) + payload.alignment + payload.size; + } + }(); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +class MemoryManager_AlteringPayloadWithCustomHeader : public ::testing::TestWithParam +{ + protected: +}; + +// with a custom header, the payload is located right after the ChunkHeader, therefore the payload size and alignment +// parameters are made dependant on the ChunkHeader +INSTANTIATE_TEST_CASE_P( + MemoryManager_test, + MemoryManager_AlteringPayloadWithCustomHeader, + ::testing::Values( + // alignment = 1 + PayloadParams{.size = 0U, .alignment = 1U}, + PayloadParams{.size = 1U, .alignment = 1U}, + PayloadParams{.size = sizeof(PayloadOffset_t), .alignment = 1U}, + PayloadParams{.size = sizeof(PayloadOffset_t) * 42U, .alignment = 1U}, + // alignment = alignof(PayloadOffset_t) / 2 + PayloadParams{.size = 0U, .alignment = alignof(PayloadOffset_t) / 2}, + PayloadParams{.size = 1U, .alignment = alignof(PayloadOffset_t) / 2}, + PayloadParams{.size = sizeof(PayloadOffset_t), .alignment = alignof(PayloadOffset_t) / 2}, + PayloadParams{.size = sizeof(PayloadOffset_t) * 42U, .alignment = alignof(PayloadOffset_t) / 2}, + // alignment = alignof(PayloadOffset_t) + PayloadParams{.size = 0U, .alignment = alignof(PayloadOffset_t)}, + PayloadParams{.size = 1U, .alignment = alignof(PayloadOffset_t)}, + PayloadParams{.size = sizeof(PayloadOffset_t), .alignment = alignof(PayloadOffset_t)}, + PayloadParams{.size = sizeof(PayloadOffset_t) * 42U, .alignment = alignof(PayloadOffset_t)}, + // alignment = alignof(PayloadOffset_t) * 2 + PayloadParams{.size = 0U, .alignment = alignof(PayloadOffset_t) * 2}, + PayloadParams{.size = 1U, .alignment = alignof(PayloadOffset_t) * 2}, + PayloadParams{.size = sizeof(PayloadOffset_t), .alignment = alignof(PayloadOffset_t) * 2}, + PayloadParams{.size = sizeof(PayloadOffset_t) * 42U, .alignment = alignof(PayloadOffset_t) * 2})); + +uint32_t expectedChunkSizeWithCustomHeader(const PayloadParams& payload, + uint32_t customHeaderSize, + uint32_t customHeaderAlignment) +{ + const uint32_t customHeaderSizeAndPaddingToBackOffset = + iox::algorithm::max(customHeaderSize, customHeaderAlignment, static_cast(alignof(PayloadOffset_t))); + + if (payload.alignment <= alignof(PayloadOffset_t)) + { + // back-offset is always adjacent to the custom header + constexpr uint32_t BACK_OFFSET_SIZE{sizeof(PayloadOffset_t)}; + return static_cast(sizeof(ChunkHeader)) + customHeaderSizeAndPaddingToBackOffset + BACK_OFFSET_SIZE + + payload.size; + } + else + { + // back-offset is not necessarily adjacent to the custom header + const uint32_t backOffsetSizeAndPaddingBytes = payload.alignment; + return static_cast(sizeof(ChunkHeader)) + customHeaderSizeAndPaddingToBackOffset + + backOffsetSizeAndPaddingBytes + payload.size; + } +} + +// BEGIN ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT EQUAL TO ONE + +TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, + requiredChunkSize_CustomHeader_SizeEqualsToOne_AlignmentEqualsToOne_IsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{1U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; + + const uint32_t expectedSize = + expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, + requiredChunkSize_CustomHeader_SizeLessThanChunkHeader_AlignmentEqualsToOne_IsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) / 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; + + const uint32_t expectedSize = + expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, + requiredChunkSize_CustomHeader_SizeEqualsToChunkHeader_AlignmentEqualsToOne_IsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; + + const uint32_t expectedSize = + expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, + requiredChunkSize_CustomHeader_SizeGreaterThanChunkHeader_AlignmentEqualsToOne_IsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) * 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; + + const uint32_t expectedSize = + expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +// END ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT EQUAL TO ONE + +// BEGIN ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT LESS THAN ChunkHeader ALIGNMENT + +TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, + requiredChunkSize_CustomHeader_SizeLessThanChunkHeader_AlignmentLessThanChunkHeaderAlignment_IsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) / 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader) / 2U}; + + const uint32_t expectedSize = + expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, + requiredChunkSize_CustomHeader_SizeEqualsToChunkHeader_AlignmentLessThanChunkHeaderAlignment_IsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader) / 2U}; + + const uint32_t expectedSize = + expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, + requiredChunkSize_CustomHeader_SizeGreaterThanChunkHeader_AlignmentLessThanChunkHeaderAlignment_IsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) * 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader) / 2U}; + + const uint32_t expectedSize = + expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +// END ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT LESS THAN ChunkHeader ALIGNMENT + +// BEGIN ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT EQUAL TO ChunkHeader ALIGNMENT + +TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, + requiredChunkSize_CustomHeader_SizeEqualsToChunkHeader_AlignmentEqualToChunkHeaderAlignment_IsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader)}; + + const uint32_t expectedSize = + expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, + requiredChunkSize_CustomHeader_SizeGreaterThanChunkHeader_AlignmentEqualToChunkHeaderAlignment_IsCorrect) +{ + const auto payload = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) * 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader)}; + + const uint32_t expectedSize = + expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( + payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + + EXPECT_THAT(chunkSize, Eq(expectedSize)); +} + +// END ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT EQUAL TO ChunkHeader ALIGNMENT + +// END PARAMETERIZED TESTS FOR REQUIRED CHUNK SIZE + +} // namespace From 2ac255e9a7a615bb01548f6b2e4b52c6922b114b Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 19 Mar 2021 14:43:07 +0100 Subject: [PATCH 80/89] iox-#14 additional tests for mepoo::MemoryManager::requiredChunkSize Signed-off-by: Mathias Kraus --- .../moduletests/test_mepoo_memory_manager.cpp | 91 +++++++++++-------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index b401af4388..ff811fac69 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -489,6 +489,8 @@ struct PayloadParams { uint32_t size{0U}; uint32_t alignment{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; + + static constexpr uint32_t MAX_ALIGNMENT{1ULL << 31}; }; class MemoryManager_AlteringPayloadWithoutCustomHeader : public ::testing::TestWithParam @@ -501,25 +503,30 @@ INSTANTIATE_TEST_CASE_P(MemoryManager_test, MemoryManager_AlteringPayloadWithoutCustomHeader, ::testing::Values( // alignment = 1 - PayloadParams{.size = 0U, .alignment = 1U}, - PayloadParams{.size = 1U, .alignment = 1U}, - PayloadParams{.size = sizeof(ChunkHeader), .alignment = 1U}, - PayloadParams{.size = sizeof(ChunkHeader) * 42U, .alignment = 1U}, + PayloadParams{0U, 1U}, + PayloadParams{1U, 1U}, + PayloadParams{sizeof(ChunkHeader), 1U}, + PayloadParams{sizeof(ChunkHeader) * 42U, 1U}, // alignment = alignof(ChunkHeader) / 2 - PayloadParams{.size = 0U, .alignment = alignof(ChunkHeader) / 2}, - PayloadParams{.size = 1U, .alignment = alignof(ChunkHeader) / 2}, - PayloadParams{.size = sizeof(ChunkHeader), .alignment = alignof(ChunkHeader) / 2}, - PayloadParams{.size = sizeof(ChunkHeader) * 42U, .alignment = alignof(ChunkHeader) / 2}, + PayloadParams{0U, alignof(ChunkHeader) / 2}, + PayloadParams{1U, alignof(ChunkHeader) / 2}, + PayloadParams{sizeof(ChunkHeader), alignof(ChunkHeader) / 2}, + PayloadParams{sizeof(ChunkHeader) * 42U, alignof(ChunkHeader) / 2}, // alignment = alignof(ChunkHeader) - PayloadParams{.size = 0U, .alignment = alignof(ChunkHeader)}, - PayloadParams{.size = 1U, .alignment = alignof(ChunkHeader)}, - PayloadParams{.size = sizeof(ChunkHeader), .alignment = alignof(ChunkHeader)}, - PayloadParams{.size = sizeof(ChunkHeader) * 42U, .alignment = alignof(ChunkHeader)}, + PayloadParams{0U, alignof(ChunkHeader)}, + PayloadParams{1U, alignof(ChunkHeader)}, + PayloadParams{sizeof(ChunkHeader), alignof(ChunkHeader)}, + PayloadParams{sizeof(ChunkHeader) * 42U, alignof(ChunkHeader)}, // alignment = alignof(ChunkHeader) * 2 - PayloadParams{.size = 0U, .alignment = alignof(ChunkHeader) * 2}, - PayloadParams{.size = 1U, .alignment = alignof(ChunkHeader) * 2}, - PayloadParams{.size = sizeof(ChunkHeader), .alignment = alignof(ChunkHeader) * 2}, - PayloadParams{.size = sizeof(ChunkHeader) * 42U, .alignment = alignof(ChunkHeader) * 2})); + PayloadParams{0U, alignof(ChunkHeader) * 2}, + PayloadParams{1U, alignof(ChunkHeader) * 2}, + PayloadParams{sizeof(ChunkHeader), alignof(ChunkHeader) * 2}, + PayloadParams{sizeof(ChunkHeader) * 42U, alignof(ChunkHeader) * 2}, + // alignment = PayloadParams::MAX_ALIGNMENT + PayloadParams{0U, PayloadParams::MAX_ALIGNMENT}, + PayloadParams{1U, PayloadParams::MAX_ALIGNMENT}, + PayloadParams{sizeof(ChunkHeader), PayloadParams::MAX_ALIGNMENT}, + PayloadParams{sizeof(ChunkHeader) * 42U, PayloadParams::MAX_ALIGNMENT})); TEST_P(MemoryManager_AlteringPayloadWithoutCustomHeader, requiredChunkSizeIsCorrect) { @@ -555,30 +562,34 @@ class MemoryManager_AlteringPayloadWithCustomHeader : public ::testing::TestWith // with a custom header, the payload is located right after the ChunkHeader, therefore the payload size and alignment // parameters are made dependant on the ChunkHeader -INSTANTIATE_TEST_CASE_P( - MemoryManager_test, - MemoryManager_AlteringPayloadWithCustomHeader, - ::testing::Values( - // alignment = 1 - PayloadParams{.size = 0U, .alignment = 1U}, - PayloadParams{.size = 1U, .alignment = 1U}, - PayloadParams{.size = sizeof(PayloadOffset_t), .alignment = 1U}, - PayloadParams{.size = sizeof(PayloadOffset_t) * 42U, .alignment = 1U}, - // alignment = alignof(PayloadOffset_t) / 2 - PayloadParams{.size = 0U, .alignment = alignof(PayloadOffset_t) / 2}, - PayloadParams{.size = 1U, .alignment = alignof(PayloadOffset_t) / 2}, - PayloadParams{.size = sizeof(PayloadOffset_t), .alignment = alignof(PayloadOffset_t) / 2}, - PayloadParams{.size = sizeof(PayloadOffset_t) * 42U, .alignment = alignof(PayloadOffset_t) / 2}, - // alignment = alignof(PayloadOffset_t) - PayloadParams{.size = 0U, .alignment = alignof(PayloadOffset_t)}, - PayloadParams{.size = 1U, .alignment = alignof(PayloadOffset_t)}, - PayloadParams{.size = sizeof(PayloadOffset_t), .alignment = alignof(PayloadOffset_t)}, - PayloadParams{.size = sizeof(PayloadOffset_t) * 42U, .alignment = alignof(PayloadOffset_t)}, - // alignment = alignof(PayloadOffset_t) * 2 - PayloadParams{.size = 0U, .alignment = alignof(PayloadOffset_t) * 2}, - PayloadParams{.size = 1U, .alignment = alignof(PayloadOffset_t) * 2}, - PayloadParams{.size = sizeof(PayloadOffset_t), .alignment = alignof(PayloadOffset_t) * 2}, - PayloadParams{.size = sizeof(PayloadOffset_t) * 42U, .alignment = alignof(PayloadOffset_t) * 2})); +INSTANTIATE_TEST_CASE_P(MemoryManager_test, + MemoryManager_AlteringPayloadWithCustomHeader, + ::testing::Values( + // alignment = 1 + PayloadParams{0U, 1U}, + PayloadParams{1U, 1U}, + PayloadParams{sizeof(PayloadOffset_t), 1U}, + PayloadParams{sizeof(PayloadOffset_t) * 42U, 1U}, + // alignment = alignof(PayloadOffset_t) / 2 + PayloadParams{0U, alignof(PayloadOffset_t) / 2}, + PayloadParams{1U, alignof(PayloadOffset_t) / 2}, + PayloadParams{sizeof(PayloadOffset_t), alignof(PayloadOffset_t) / 2}, + PayloadParams{sizeof(PayloadOffset_t) * 42U, alignof(PayloadOffset_t) / 2}, + // alignment = alignof(PayloadOffset_t) + PayloadParams{0U, alignof(PayloadOffset_t)}, + PayloadParams{1U, alignof(PayloadOffset_t)}, + PayloadParams{sizeof(PayloadOffset_t), alignof(PayloadOffset_t)}, + PayloadParams{sizeof(PayloadOffset_t) * 42U, alignof(PayloadOffset_t)}, + // alignment = alignof(PayloadOffset_t) * 2 + PayloadParams{0U, alignof(PayloadOffset_t) * 2}, + PayloadParams{1U, alignof(PayloadOffset_t) * 2}, + PayloadParams{sizeof(PayloadOffset_t), alignof(PayloadOffset_t) * 2}, + PayloadParams{sizeof(PayloadOffset_t) * 42U, alignof(PayloadOffset_t) * 2}, + // alignment = PayloadParams::MAX_ALIGNMENT + PayloadParams{0U, PayloadParams::MAX_ALIGNMENT}, + PayloadParams{1U, PayloadParams::MAX_ALIGNMENT}, + PayloadParams{sizeof(PayloadOffset_t), PayloadParams::MAX_ALIGNMENT}, + PayloadParams{sizeof(PayloadOffset_t) * 42U, PayloadParams::MAX_ALIGNMENT})); uint32_t expectedChunkSizeWithCustomHeader(const PayloadParams& payload, uint32_t customHeaderSize, From cda0dd9c1670eb7e1cd7d12abe265e73c1cbbd1f Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 19 Mar 2021 21:13:31 +0100 Subject: [PATCH 81/89] iox-#14 ensure the used size of the chunk doesn't exceed the actual chunk size Signed-off-by: Mathias Kraus --- .../include/iceoryx_posh/mepoo/chunk_header.hpp | 5 ++++- iceoryx_posh/source/mepoo/chunk_header.cpp | 14 +++++++++----- .../test/moduletests/test_mepoo_shared_chunk.cpp | 13 +++++++------ .../moduletests/test_mepoo_shared_pointer.cpp | 12 ++++++------ .../moduletests/test_popo_chunk_distributor.cpp | 16 ++++++++-------- .../test/moduletests/test_popo_chunk_queue.cpp | 7 ++++--- 6 files changed, 38 insertions(+), 29 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp index 5eb80a3aff..ad087a160a 100644 --- a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp +++ b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp @@ -108,7 +108,10 @@ struct alignas(32) ChunkHeader /// @brief Calculates the used size of the chunk with the ChunkHeader, custom heander and payload /// @return the used size of the chunk - uint32_t usedSizeOfChunk(); + uint32_t usedSizeOfChunk() const noexcept; + + private: + uint64_t overflowSafeUsedSizeOfChunk() const noexcept; // END methods }; diff --git a/iceoryx_posh/source/mepoo/chunk_header.cpp b/iceoryx_posh/source/mepoo/chunk_header.cpp index 9e39bb3a27..ab46b053e9 100644 --- a/iceoryx_posh/source/mepoo/chunk_header.cpp +++ b/iceoryx_posh/source/mepoo/chunk_header.cpp @@ -90,6 +90,9 @@ ChunkHeader::ChunkHeader(const uint32_t chunkSize, auto backOffset = reinterpret_cast(addressOfBackOffset); *backOffset = payloadOffset; } + + cxx::Ensures(overflowSafeUsedSizeOfChunk() <= chunkSize + && "Used size of chunk would exceed the actual chunk size!"); } void* ChunkHeader::payload() const noexcept @@ -111,13 +114,14 @@ ChunkHeader* ChunkHeader::fromPayload(const void* const payload) noexcept return reinterpret_cast(payloadAddress - *payloadOffset); } -uint32_t ChunkHeader::usedSizeOfChunk() +uint32_t ChunkHeader::usedSizeOfChunk() const noexcept { - auto usedSizeOfChunk = static_cast(payloadOffset) + static_cast(payloadSize); - - cxx::Expects(usedSizeOfChunk <= chunkSize); + return static_cast(overflowSafeUsedSizeOfChunk()); +} - return static_cast(usedSizeOfChunk); +uint64_t ChunkHeader::overflowSafeUsedSizeOfChunk() const noexcept +{ + return static_cast(payloadOffset) + static_cast(payloadSize); } } // namespace mepoo diff --git a/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp b/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp index 864df7be16..251f695c57 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_shared_chunk.cpp @@ -38,21 +38,22 @@ class SharedChunk_Test : public Test ChunkManagement* GetChunkManagement(void* memoryChunk) { ChunkManagement* v = static_cast(chunkMgmtPool.getChunk()); - ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(chunkMgmtPool.getChunkSize(), + ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(mempool.getChunkSize(), PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); + new (v) ChunkManagement{chunkHeader, &mempool, &chunkMgmtPool}; return v; } - static constexpr uint32_t PAYLOAD_SIZE{64}; + static constexpr uint32_t PAYLOAD_SIZE{64U}; - char memory[4096]; - iox::posix::Allocator allocator{memory, 4096}; - MemPool mempool{64, 10, &allocator, &allocator}; - MemPool chunkMgmtPool{64, 10, &allocator, &allocator}; + char memory[4096U]; + iox::posix::Allocator allocator{memory, 4096U}; + MemPool mempool{sizeof(ChunkHeader) + PAYLOAD_SIZE, 10U, &allocator, &allocator}; + MemPool chunkMgmtPool{64U, 10U, &allocator, &allocator}; void* memoryChunk{mempool.getChunk()}; ChunkManagement* chunkManagement = GetChunkManagement(memoryChunk); iox::mepoo::SharedChunk sut{chunkManagement}; diff --git a/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp b/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp index 0b25addaa6..fbb999ab45 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_shared_pointer.cpp @@ -113,7 +113,7 @@ class SharedPointer_Test : public Test ChunkManagement* GetChunkManagement(void* memoryChunk) { ChunkManagement* v = static_cast(chunkMgmtPool.getChunk()); - ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(chunkMgmtPool.getChunkSize(), + ChunkHeader* chunkHeader = new (memoryChunk) ChunkHeader(mempool.getChunkSize(), PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, @@ -130,12 +130,12 @@ class SharedPointer_Test : public Test int resetCounter = ResetCounter(); - static constexpr uint32_t PAYLOAD_SIZE{64}; + static constexpr uint32_t PAYLOAD_SIZE{64U}; - char memory[4096]; - iox::posix::Allocator allocator{memory, 4096}; - MemPool mempool{PAYLOAD_SIZE, 10, &allocator, &allocator}; - MemPool chunkMgmtPool{PAYLOAD_SIZE, 10, &allocator, &allocator}; + char memory[4096U]; + iox::posix::Allocator allocator{memory, 4096U}; + MemPool mempool{sizeof(ChunkHeader) + PAYLOAD_SIZE, 10U, &allocator, &allocator}; + MemPool chunkMgmtPool{64U, 10U, &allocator, &allocator}; void* memoryChunk{mempool.getChunk()}; ChunkManagement* chunkManagement = GetChunkManagement(memoryChunk); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index 61add4e614..71bceed284 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -49,7 +49,7 @@ class ChunkDistributor_test : public Test { ChunkManagement* chunkMgmt = static_cast(chunkMgmtPool.getChunk()); auto chunk = mempool.getChunk(); - ChunkHeader* chunkHeader = new (chunk) ChunkHeader(chunkMgmtPool.getChunkSize(), + ChunkHeader* chunkHeader = new (chunk) ChunkHeader(mempool.getChunkSize(), PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, @@ -63,15 +63,15 @@ class ChunkDistributor_test : public Test return *static_cast(chunk.getPayload()); } - static constexpr uint32_t PAYLOAD_SIZE{128}; - static constexpr size_t MEGABYTE = 1 << 20; - static constexpr size_t MEMORY_SIZE = 1 * MEGABYTE; - const uint64_t HISTORY_SIZE = 16; - static constexpr uint32_t MAX_NUMBER_QUEUES = 128; + static constexpr uint32_t PAYLOAD_SIZE{128U}; + static constexpr size_t MEGABYTE = 1U << 20U; + static constexpr size_t MEMORY_SIZE = 1U * MEGABYTE; + const uint64_t HISTORY_SIZE = 16U; + static constexpr uint32_t MAX_NUMBER_QUEUES = 128U; char memory[MEMORY_SIZE]; iox::posix::Allocator allocator{memory, MEMORY_SIZE}; - MemPool mempool{PAYLOAD_SIZE, 20, &allocator, &allocator}; - MemPool chunkMgmtPool{PAYLOAD_SIZE, 20, &allocator, &allocator}; + MemPool mempool{sizeof(ChunkHeader) + PAYLOAD_SIZE, 20U, &allocator, &allocator}; + MemPool chunkMgmtPool{128U, 20U, &allocator, &allocator}; struct ChunkDistributorConfig { diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp index 94bcc563ed..bad1bcd5ca 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp @@ -42,7 +42,7 @@ class ChunkQueue_testBase { ChunkManagement* chunkMgmt = static_cast(chunkMgmtPool.getChunk()); auto chunk = mempool.getChunk(); - ChunkHeader* chunkHeader = new (chunk) ChunkHeader(chunkMgmtPool.getChunkSize(), + ChunkHeader* chunkHeader = new (chunk) ChunkHeader(mempool.getChunkSize(), PAYLOAD_SIZE, iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, iox::CHUNK_NO_CUSTOM_HEADER_SIZE, @@ -56,8 +56,9 @@ class ChunkQueue_testBase static constexpr size_t MEMORY_SIZE = 4U * MEGABYTE; std::unique_ptr memory{new char[MEMORY_SIZE]}; iox::posix::Allocator allocator{memory.get(), MEMORY_SIZE}; - MemPool mempool{PAYLOAD_SIZE, 2U * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; - MemPool chunkMgmtPool{PAYLOAD_SIZE, 2U * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; + MemPool mempool{ + sizeof(ChunkHeader) + PAYLOAD_SIZE, 2U * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; + MemPool chunkMgmtPool{128U, 2U * iox::MAX_SUBSCRIBER_QUEUE_CAPACITY, &allocator, &allocator}; static constexpr uint32_t RESIZED_CAPACITY{5U}; }; From 56a056013aafad0d304dbf73f9b4d2ffc306d4ff Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 19 Mar 2021 21:34:44 +0100 Subject: [PATCH 82/89] iox-#14 add tests to check integrity of ChunkHeader Signed-off-by: Mathias Kraus --- .../moduletests/test_mepoo_chunk_header.cpp | 441 +++++++++++++++--- .../moduletests/test_mepoo_memory_manager.cpp | 39 +- 2 files changed, 395 insertions(+), 85 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 7e58da85e5..ae1d315a39 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -15,33 +15,17 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" +#include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "test.hpp" +namespace +{ using namespace ::testing; using namespace iox::mepoo; -template -struct alignas(32) ChunkWithPayload -{ - ChunkHeader m_chunkHeader{sizeof(ChunkWithPayload), - PayloadSize, - alignof(uint8_t), - iox::CHUNK_NO_CUSTOM_HEADER_SIZE, - iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; - uint8_t m_payload[PayloadSize]; -}; - -template -struct alignas(32) ChunkWithCustomHeaderAndPayload -{ - ChunkHeader m_chunkHeader{ - sizeof(ChunkWithCustomHeaderAndPayload), PayloadSize, alignof(uint8_t), sizeof(uint64_t), alignof(uint64_t)}; - uint64_t m_customHeader; - ChunkHeader::PayloadOffset_t m_backOffset; - uint8_t m_payload[PayloadSize]; -}; +using PayloadOffset_t = ChunkHeader::PayloadOffset_t; class ChunkHeader_test : public Test { @@ -51,7 +35,7 @@ class ChunkHeader_test : public Test TEST_F(ChunkHeader_test, ChunkHeaderHasInitializedMembers) { - constexpr uint32_t CHUNK_SIZE{32U}; + constexpr uint32_t CHUNK_SIZE{753U}; constexpr uint32_t PAYLOAD_SIZE{8U}; ChunkHeader sut{CHUNK_SIZE, PAYLOAD_SIZE, @@ -77,40 +61,16 @@ TEST_F(ChunkHeader_test, ChunkHeaderHasInitializedMembers) EXPECT_THAT(sut.payloadOffset, Eq(sizeof(ChunkHeader))); } -TEST_F(ChunkHeader_test, ChunkHeaderPayloadSizeIsLargeEnoughForMempoolChunk) +TEST_F(ChunkHeader_test, ChunkHeaderPayloadSizeTypeIsLargeEnoughForMempoolChunk) { using ChunkSize_t = std::result_of::type; - auto maxChunkSize = std::numeric_limits::max(); - auto maxPayloadSize = std::numeric_limits::max(); + auto maxOfChunkSizeType = std::numeric_limits::max(); + auto maxOfPayloadSizeType = std::numeric_limits::max(); // the payload will never be larger than the chunk // if the payload can hold at least the maximum chunk size there will never be an overflow - EXPECT_THAT(maxPayloadSize, Ge(maxChunkSize)); -} - -TEST_F(ChunkHeader_test, CustomHeaderMethodReturnsCorrectCustomHeaderPointer) -{ - constexpr uint32_t PAYLOAD_SIZE{128U}; - ChunkWithCustomHeaderAndPayload chunk; - - EXPECT_THAT(chunk.m_chunkHeader.customHeader(), Eq(&chunk.m_customHeader)); -} - -TEST_F(ChunkHeader_test, PayloadMethodReturnsCorrectPayloadPointer) -{ - constexpr uint32_t PAYLOAD_SIZE{128U}; - ChunkWithPayload chunk; - - EXPECT_THAT(chunk.m_chunkHeader.payload(), Eq(chunk.m_payload)); -} - -TEST_F(ChunkHeader_test, FromPayloadFunctionReturnsCorrectChunkHeaderPointer) -{ - constexpr uint32_t PAYLOAD_SIZE{128U}; - ChunkWithPayload chunk; - - EXPECT_THAT(ChunkHeader::fromPayload(chunk.m_payload), Eq(&chunk.m_chunkHeader)); + EXPECT_THAT(maxOfPayloadSizeType, Ge(maxOfChunkSizeType)); } TEST_F(ChunkHeader_test, FromPayloadFunctionCalledWithNullptrReturnsNullptr) @@ -134,7 +94,7 @@ TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderWhenPayloadIsZero) TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderPlusOneWhenPayloadIsOne) { - constexpr uint32_t CHUNK_SIZE{32U}; + constexpr uint32_t CHUNK_SIZE{128U}; constexpr uint32_t PAYLOAD_SIZE{1U}; ChunkHeader sut{CHUNK_SIZE, PAYLOAD_SIZE, @@ -146,17 +106,378 @@ TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderPlusOneWhenPayloadIsOne EXPECT_THAT(sut.usedSizeOfChunk(), Eq(sizeof(ChunkHeader) + PAYLOAD_SIZE)); } -TEST_F(ChunkHeader_test, usedChunkSizeTerminatesWhenPayloadSizeExceedsChunkSize) +TEST_F(ChunkHeader_test, ChunkHeaderConstructorTerminatesWhenPayloadSizeExceedsChunkSize) { - constexpr uint32_t CHUNK_SIZE{32U}; - constexpr uint32_t PAYLOAD_SIZE{std::numeric_limits::max()}; - ChunkHeader sut{CHUNK_SIZE, - PAYLOAD_SIZE, - iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, - iox::CHUNK_NO_CUSTOM_HEADER_SIZE, - iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + constexpr uint32_t CHUNK_SIZE{128U}; + constexpr uint32_t PAYLOAD_SIZE{2U * CHUNK_SIZE}; + EXPECT_DEATH( + { + ChunkHeader sut(CHUNK_SIZE, + PAYLOAD_SIZE, + iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT, + iox::CHUNK_NO_CUSTOM_HEADER_SIZE, + iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT); + }, + ".*"); +} - sut.chunkSize = 2 * sizeof(ChunkHeader); +// BEGIN PARAMETERIZED TESTS FOR CHUNK HEADER + +struct PayloadParams +{ + uint32_t size{0U}; + uint32_t alignment{iox::CHUNK_DEFAULT_PAYLOAD_ALIGNMENT}; +}; + + +void createChunksOnMultipleAddresses(const PayloadParams& payloadParams, + const uint32_t customHeaderSize, + const uint32_t customHeaderAlignment, + const std::function testHook) +{ + ASSERT_TRUE(testHook); + + constexpr size_t MAX_PAYLOAD_ALIGNMENT_FOR_TEST{512U}; + ASSERT_THAT(MAX_PAYLOAD_ALIGNMENT_FOR_TEST, Gt(alignof(ChunkHeader))); + + constexpr size_t STORAGE_ALIGNMENT{2 * MAX_PAYLOAD_ALIGNMENT_FOR_TEST}; + alignas(STORAGE_ALIGNMENT) static uint8_t storage[1024 * 1024]; + ASSERT_THAT(reinterpret_cast(storage) % STORAGE_ALIGNMENT, Eq(0U)); + + // storage alignment boundaries -> ⊥ ⊥ ⊥ ⊥ ⊥ + // max payload alignment for test boundaries -> ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ + // ChunkHeader alignment boundaries -> ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ ⊥ + + // the test creates ChunkHeader on multiple address boundaries in order to have all possible scenarios up to a + // payload boundary of 512; this boundary is more than large enough since a payload alignment of 2 times the + // ChunkHeader alignment would already be sufficient to test all corner cases + for (auto alignedChunkAddress = alignof(ChunkHeader); alignedChunkAddress <= MAX_PAYLOAD_ALIGNMENT_FOR_TEST; + alignedChunkAddress += alignof(ChunkHeader)) + { + SCOPED_TRACE(std::string("Chunk on address ") + std::to_string(alignedChunkAddress)); - EXPECT_DEATH(sut.usedSizeOfChunk(), ".*"); + auto requiredChunkSize = MemoryManager::requiredChunkSize( + payloadParams.size, payloadParams.alignment, customHeaderSize, customHeaderAlignment); + auto chunkHeader = new (&storage[alignedChunkAddress]) ChunkHeader( + requiredChunkSize, payloadParams.size, payloadParams.alignment, customHeaderSize, customHeaderAlignment); + + testHook(*chunkHeader); + + chunkHeader->~ChunkHeader(); + } } + +void checkPayloadNotOverlappingWithChunkHeader(const ChunkHeader& sut) +{ + SCOPED_TRACE(std::string("Check payload not overlapping with ChunkHeader")); + const uint64_t chunkStartAddress{reinterpret_cast(&sut)}; + const uint64_t payloadStartAddress{reinterpret_cast(sut.payload())}; + + EXPECT_THAT(payloadStartAddress - chunkStartAddress, Ge(sizeof(ChunkHeader))); +} + +void checkPayloadNotOverlappingWithCustomHeader(const ChunkHeader& sut, const uint32_t customHeaderSize) +{ + SCOPED_TRACE(std::string("Check payload not overlapping with custom header")); + const uint64_t chunkStartAddress{reinterpret_cast(&sut)}; + const uint64_t payloadStartAddress{reinterpret_cast(sut.payload())}; + const uint64_t customHeaderSizeAndPadding{ + iox::algorithm::max(customHeaderSize, static_cast(alignof(PayloadOffset_t)))}; + constexpr uint64_t BACK_OFFSET_SIZE{sizeof(PayloadOffset_t)}; + const uint64_t expectedRequiredSpace{sizeof(ChunkHeader) + customHeaderSizeAndPadding + BACK_OFFSET_SIZE}; + + EXPECT_THAT(payloadStartAddress - chunkStartAddress, Ge(expectedRequiredSpace)); +} + +void checkCustomHeaderIsAdjacentToChunkHeader(const ChunkHeader& sut) +{ + SCOPED_TRACE(std::string("Check custom header is adjacent to ChunkHeader")); + const uint64_t chunkStartAddress{reinterpret_cast(&sut)}; + const uint64_t customHeaderStartAddress{reinterpret_cast(sut.customHeader())}; + + EXPECT_EQ(customHeaderStartAddress - chunkStartAddress, sizeof(ChunkHeader)); +} + +void checkPayloadSize(const ChunkHeader& sut, const PayloadParams& payloadParams) +{ + SCOPED_TRACE(std::string("Check payload size")); + EXPECT_EQ(sut.payloadSize, payloadParams.size); +} + +void checkPayloadAlignment(const ChunkHeader& sut, const PayloadParams& payloadParams) +{ + SCOPED_TRACE(std::string("Check payload alignment")); + EXPECT_EQ(reinterpret_cast(sut.payload()) % payloadParams.alignment, 0U); +} + +void checkUsedSizeOfChunk(const ChunkHeader& sut, const PayloadParams& payloadParams) +{ + SCOPED_TRACE(std::string("Check used size of chunk")); + const uint64_t chunkStartAddress{reinterpret_cast(&sut)}; + const uint64_t payloadStartAddress{reinterpret_cast(sut.payload())}; + const uint64_t expectedUsedSizeOfChunk{payloadStartAddress + payloadParams.size - chunkStartAddress}; + + EXPECT_EQ(sut.usedSizeOfChunk(), expectedUsedSizeOfChunk); + EXPECT_THAT(sut.usedSizeOfChunk(), Le(sut.chunkSize)); +} + +void checkConversionOfPayloadPointerToChunkHeader(const ChunkHeader& sut) +{ + SCOPED_TRACE(std::string("Check conversion of payload pointer to ChunkHeader pointer")); + const auto payload = sut.payload(); + EXPECT_EQ(ChunkHeader::fromPayload(payload), &sut); +} + +class ChunkHeader_AlteringPayloadWithoutCustomHeader : public ::testing::TestWithParam +{ +}; + +// without a custom header, the payload is located right after the ChunkHeader, therefore the payload size and alignment +// parameters are made dependant on the ChunkHeader +INSTANTIATE_TEST_CASE_P(ChunkHeader_test, + ChunkHeader_AlteringPayloadWithoutCustomHeader, + ::testing::Values( + // alignment = 1 + PayloadParams{0U, 1U}, + PayloadParams{1U, 1U}, + PayloadParams{sizeof(ChunkHeader), 1U}, + PayloadParams{sizeof(ChunkHeader) * 42U, 1U}, + // alignment = alignof(ChunkHeader) / 2 + PayloadParams{0U, alignof(ChunkHeader) / 2}, + PayloadParams{1U, alignof(ChunkHeader) / 2}, + PayloadParams{sizeof(ChunkHeader), alignof(ChunkHeader) / 2}, + PayloadParams{sizeof(ChunkHeader) * 42U, alignof(ChunkHeader) / 2}, + // alignment = alignof(ChunkHeader) + PayloadParams{0U, alignof(ChunkHeader)}, + PayloadParams{1U, alignof(ChunkHeader)}, + PayloadParams{sizeof(ChunkHeader), alignof(ChunkHeader)}, + PayloadParams{sizeof(ChunkHeader) * 42U, alignof(ChunkHeader)}, + // alignment = alignof(ChunkHeader) * 2 + PayloadParams{0U, alignof(ChunkHeader) * 2}, + PayloadParams{1U, alignof(ChunkHeader) * 2}, + PayloadParams{sizeof(ChunkHeader), alignof(ChunkHeader) * 2}, + PayloadParams{sizeof(ChunkHeader) * 42U, alignof(ChunkHeader) * 2})); + +TEST_P(ChunkHeader_AlteringPayloadWithoutCustomHeader, checkIntegrityOfChunkHeaderWithoutCustomHeader) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{iox::CHUNK_NO_CUSTOM_HEADER_SIZE}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkPayloadNotOverlappingWithChunkHeader(sut); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +class ChunkHeader_AlteringPayloadWithCustomHeader : public ::testing::TestWithParam +{ +}; + +// without a custom header, the payload is located right after the ChunkHeader, therefore the payload size and alignment +// parameters are made dependant on the ChunkHeader +INSTANTIATE_TEST_CASE_P(ChunkHeader_test, + ChunkHeader_AlteringPayloadWithCustomHeader, + ::testing::Values( + // alignment = 1 + PayloadParams{0U, 1U}, + PayloadParams{1U, 1U}, + PayloadParams{sizeof(PayloadOffset_t), 1U}, + PayloadParams{sizeof(PayloadOffset_t) * 42U, 1U}, + // alignment = alignof(PayloadOffset_t) / 2 + PayloadParams{0U, alignof(PayloadOffset_t) / 2}, + PayloadParams{1U, alignof(PayloadOffset_t) / 2}, + PayloadParams{sizeof(PayloadOffset_t), alignof(PayloadOffset_t) / 2}, + PayloadParams{sizeof(PayloadOffset_t) * 42U, alignof(PayloadOffset_t) / 2}, + // alignment = alignof(PayloadOffset_t) + PayloadParams{0U, alignof(PayloadOffset_t)}, + PayloadParams{1U, alignof(PayloadOffset_t)}, + PayloadParams{sizeof(PayloadOffset_t), alignof(PayloadOffset_t)}, + PayloadParams{sizeof(PayloadOffset_t) * 42U, alignof(PayloadOffset_t)}, + // alignment = alignof(PayloadOffset_t) * 2 + PayloadParams{0U, alignof(PayloadOffset_t) * 2}, + PayloadParams{1U, alignof(PayloadOffset_t) * 2}, + PayloadParams{sizeof(PayloadOffset_t), alignof(PayloadOffset_t) * 2}, + PayloadParams{sizeof(PayloadOffset_t) * 42U, alignof(PayloadOffset_t) * 2})); + +// BEGIN ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT EQUAL TO ONE + +TEST_P(ChunkHeader_AlteringPayloadWithCustomHeader, + checkIntegrityOfChunkHeader_CustomHeader_SizeEqualsToOne_AlignmentEqualsToOne) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{1U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkCustomHeaderIsAdjacentToChunkHeader(sut); + checkPayloadNotOverlappingWithCustomHeader(sut, CUSTOM_HEADER_SIZE); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +TEST_P(ChunkHeader_AlteringPayloadWithCustomHeader, + checkIntegrityOfChunkHeader_CustomHeader_SizeLessThanChunkHeader_AlignmentEqualsToOne) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) / 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkCustomHeaderIsAdjacentToChunkHeader(sut); + checkPayloadNotOverlappingWithCustomHeader(sut, CUSTOM_HEADER_SIZE); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +TEST_P(ChunkHeader_AlteringPayloadWithCustomHeader, + checkIntegrityOfChunkHeader_CustomHeader_SizeEqualsToChunkHeader_AlignmentEqualsToOne) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkCustomHeaderIsAdjacentToChunkHeader(sut); + checkPayloadNotOverlappingWithCustomHeader(sut, CUSTOM_HEADER_SIZE); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +TEST_P(ChunkHeader_AlteringPayloadWithCustomHeader, + checkIntegrityOfChunkHeader_CustomHeader_SizeGreaterThanChunkHeader_AlignmentEqualsToOne) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) * 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkCustomHeaderIsAdjacentToChunkHeader(sut); + checkPayloadNotOverlappingWithCustomHeader(sut, CUSTOM_HEADER_SIZE); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +// END ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT EQUAL TO ONE + +// BEGIN ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT LESS THAN ChunkHeader ALIGNMENT + +TEST_P(ChunkHeader_AlteringPayloadWithCustomHeader, + checkIntegrityOfChunkHeader_CustomHeader_SizeLessThanChunkHeader_AlignmentLessThanChunkHeaderAlignment) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) / 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(ChunkHeader) / 2U}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkCustomHeaderIsAdjacentToChunkHeader(sut); + checkPayloadNotOverlappingWithCustomHeader(sut, CUSTOM_HEADER_SIZE); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +TEST_P(ChunkHeader_AlteringPayloadWithCustomHeader, + checkIntegrityOfChunkHeader_CustomHeader_SizeEqualsToChunkHeader_AlignmentLessThanChunkHeaderAlignment) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(ChunkHeader) / 2U}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkCustomHeaderIsAdjacentToChunkHeader(sut); + checkPayloadNotOverlappingWithCustomHeader(sut, CUSTOM_HEADER_SIZE); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +TEST_P(ChunkHeader_AlteringPayloadWithCustomHeader, + checkIntegrityOfChunkHeader_CustomHeader_SizeGreaterThanChunkHeader_AlignmentLessThanChunkHeaderAlignment) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) * 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(ChunkHeader) / 2U}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkCustomHeaderIsAdjacentToChunkHeader(sut); + checkPayloadNotOverlappingWithCustomHeader(sut, CUSTOM_HEADER_SIZE); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +// END ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT LESS THAN ChunkHeader ALIGNMENT + +// BEGIN ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT EQUAL TO ChunkHeader ALIGNMENT + +TEST_P(ChunkHeader_AlteringPayloadWithCustomHeader, + checkIntegrityOfChunkHeader_CustomHeader_SizeEqualsToChunkHeader_AlignmentEqualsToChunkHeaderAlignment) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader)}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(ChunkHeader)}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkCustomHeaderIsAdjacentToChunkHeader(sut); + checkPayloadNotOverlappingWithCustomHeader(sut, CUSTOM_HEADER_SIZE); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +TEST_P(ChunkHeader_AlteringPayloadWithCustomHeader, + checkIntegrityOfChunkHeader_CustomHeader_SizeGreaterThanChunkHeader_AlignmentEqualsToChunkHeaderAlignment) +{ + const auto payloadParams = GetParam(); + + constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) * 2U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(ChunkHeader)}; + + createChunksOnMultipleAddresses(payloadParams, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT, [&](ChunkHeader& sut) { + checkCustomHeaderIsAdjacentToChunkHeader(sut); + checkPayloadNotOverlappingWithCustomHeader(sut, CUSTOM_HEADER_SIZE); + checkPayloadSize(sut, payloadParams); + checkPayloadAlignment(sut, payloadParams); + checkUsedSizeOfChunk(sut, payloadParams); + checkConversionOfPayloadPointerToChunkHeader(sut); + }); +} + +// END ALTERING CUSTOM HEADER SIZE WITH ALIGNMENT EQUAL TO ChunkHeader ALIGNMENT + +// END PARAMETERIZED TESTS FOR CHUNK HEADER + +} // namespace diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index ff811fac69..57200fe851 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -591,16 +591,14 @@ INSTANTIATE_TEST_CASE_P(MemoryManager_test, PayloadParams{sizeof(PayloadOffset_t), PayloadParams::MAX_ALIGNMENT}, PayloadParams{sizeof(PayloadOffset_t) * 42U, PayloadParams::MAX_ALIGNMENT})); -uint32_t expectedChunkSizeWithCustomHeader(const PayloadParams& payload, - uint32_t customHeaderSize, - uint32_t customHeaderAlignment) +uint32_t expectedChunkSizeWithCustomHeader(const PayloadParams& payload, uint32_t customHeaderSize) { const uint32_t customHeaderSizeAndPaddingToBackOffset = - iox::algorithm::max(customHeaderSize, customHeaderAlignment, static_cast(alignof(PayloadOffset_t))); + iox::algorithm::max(customHeaderSize, static_cast(alignof(PayloadOffset_t))); if (payload.alignment <= alignof(PayloadOffset_t)) { - // back-offset is always adjacent to the custom header + // back-offset is always adjacent to the custom header (as much as possible with the alignment constraints) constexpr uint32_t BACK_OFFSET_SIZE{sizeof(PayloadOffset_t)}; return static_cast(sizeof(ChunkHeader)) + customHeaderSizeAndPaddingToBackOffset + BACK_OFFSET_SIZE + payload.size; @@ -608,9 +606,9 @@ uint32_t expectedChunkSizeWithCustomHeader(const PayloadParams& payload, else { // back-offset is not necessarily adjacent to the custom header - const uint32_t backOffsetSizeAndPaddingBytes = payload.alignment; + const uint32_t paddingBytesAndBackOffsetSize = payload.alignment; return static_cast(sizeof(ChunkHeader)) + customHeaderSizeAndPaddingToBackOffset - + backOffsetSizeAndPaddingBytes + payload.size; + + paddingBytesAndBackOffsetSize + payload.size; } } @@ -624,8 +622,7 @@ TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, constexpr uint32_t CUSTOM_HEADER_SIZE{1U}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; - const uint32_t expectedSize = - expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + const uint32_t expectedSize = expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE); auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -641,8 +638,7 @@ TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) / 2U}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; - const uint32_t expectedSize = - expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + const uint32_t expectedSize = expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE); auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -658,8 +654,7 @@ TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader)}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; - const uint32_t expectedSize = - expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + const uint32_t expectedSize = expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE); auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -675,8 +670,7 @@ TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) * 2U}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{1U}; - const uint32_t expectedSize = - expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + const uint32_t expectedSize = expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE); auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -696,8 +690,7 @@ TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) / 2U}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader) / 2U}; - const uint32_t expectedSize = - expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + const uint32_t expectedSize = expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE); auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -713,8 +706,7 @@ TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader)}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader) / 2U}; - const uint32_t expectedSize = - expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + const uint32_t expectedSize = expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE); auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -730,8 +722,7 @@ TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) * 2U}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader) / 2U}; - const uint32_t expectedSize = - expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + const uint32_t expectedSize = expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE); auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -751,8 +742,7 @@ TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader)}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader)}; - const uint32_t expectedSize = - expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + const uint32_t expectedSize = expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE); auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); @@ -768,8 +758,7 @@ TEST_P(MemoryManager_AlteringPayloadWithCustomHeader, constexpr uint32_t CUSTOM_HEADER_SIZE{sizeof(ChunkHeader) * 2U}; constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{sizeof(ChunkHeader)}; - const uint32_t expectedSize = - expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); + const uint32_t expectedSize = expectedChunkSizeWithCustomHeader(payload, CUSTOM_HEADER_SIZE); auto chunkSize = iox::mepoo::MemoryManager::requiredChunkSize( payload.size, payload.alignment, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); From a8d8f7590db7136a9c28def3e8be3fd49bfb8858 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 19 Mar 2021 21:49:19 +0100 Subject: [PATCH 83/89] iox-#14 add death test to ChunkHeader Signed-off-by: Mathias Kraus --- .../test/moduletests/test_mepoo_chunk_header.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index ae1d315a39..753cbb5362 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -106,7 +106,7 @@ TEST_F(ChunkHeader_test, usedChunkSizeIsSizeOfChunkHeaderPlusOneWhenPayloadIsOne EXPECT_THAT(sut.usedSizeOfChunk(), Eq(sizeof(ChunkHeader) + PAYLOAD_SIZE)); } -TEST_F(ChunkHeader_test, ChunkHeaderConstructorTerminatesWhenPayloadSizeExceedsChunkSize) +TEST_F(ChunkHeader_test, ConstructorTerminatesWhenPayloadSizeExceedsChunkSize) { constexpr uint32_t CHUNK_SIZE{128U}; constexpr uint32_t PAYLOAD_SIZE{2U * CHUNK_SIZE}; @@ -121,6 +121,18 @@ TEST_F(ChunkHeader_test, ChunkHeaderConstructorTerminatesWhenPayloadSizeExceedsC ".*"); } +TEST_F(ChunkHeader_test, ConstructorTerminatesWhenCustomHeaderAlignmentExceedsChunkHeaderAlignment) +{ + constexpr uint32_t CHUNK_SIZE{1024U}; + constexpr uint32_t PAYLOAD_SIZE{8U}; + constexpr uint32_t PAYLOAD_ALIGNMENT{1U}; + constexpr uint32_t CUSTOM_HEADER_SIZE{128U}; + constexpr uint32_t CUSTOM_HEADER_ALIGNMENT{alignof(ChunkHeader) * 2U}; + EXPECT_DEATH( + { ChunkHeader sut(CHUNK_SIZE, PAYLOAD_SIZE, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT); }, + ".*"); +} + // BEGIN PARAMETERIZED TESTS FOR CHUNK HEADER struct PayloadParams From 36221ccbeec75af4b5e20e07220ee8867c053ad4 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 19 Mar 2021 21:55:49 +0100 Subject: [PATCH 84/89] iox-#14 refactor asserts for overflow in ChunkHeader Signed-off-by: Mathias Kraus --- iceoryx_posh/source/mepoo/chunk_header.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/iceoryx_posh/source/mepoo/chunk_header.cpp b/iceoryx_posh/source/mepoo/chunk_header.cpp index ab46b053e9..7cf56f04ad 100644 --- a/iceoryx_posh/source/mepoo/chunk_header.cpp +++ b/iceoryx_posh/source/mepoo/chunk_header.cpp @@ -30,6 +30,9 @@ ChunkHeader::ChunkHeader(const uint32_t chunkSize, { static_assert(alignof(ChunkHeader) >= 8U, "All the calculations expect the ChunkHeader alignment to be at least 8!"); + static_assert(std::is_same::type>::value, + "PayloadOffset_t and payloadAlignment must have same type in order to prevent an overflow for the " + "payload offset calculation for extremely large alignments"); cxx::Expects(customHeaderAlignment <= alignof(ChunkHeader) && "The alignment of the custom header must not exceed the alignment of the ChunkHeader!"); @@ -52,8 +55,8 @@ ChunkHeader::ChunkHeader(const uint32_t chunkSize, uint64_t headerEndAddress = addressOfChunkHeader + sizeof(ChunkHeader); uint64_t alignedPayloadAddress = iox::cxx::align(headerEndAddress, static_cast(payloadAlignment)); uint64_t offsetToPayload = alignedPayloadAddress - addressOfChunkHeader; - cxx::Ensures(offsetToPayload <= std::numeric_limits::max() - && "Payload offset too large for chunk!"); + // the cast is safe since payloadOffset and payloadAlignment have the same type and since the alignment must + // be a power of 2, the max alignment is about half of the max value the type can hold payloadOffset = static_cast(offsetToPayload); // this is safe since the alignment of the payload is larger than the one from the ChunkHeader @@ -76,8 +79,8 @@ ChunkHeader::ChunkHeader(const uint32_t chunkSize, uint64_t alignedPayloadAddress = iox::cxx::align(potentialPayloadAddress, static_cast(payloadAlignment)); uint64_t offsetToPayload = alignedPayloadAddress - addressOfChunkHeader; - cxx::Ensures(offsetToPayload <= std::numeric_limits::max() - && "Payload offset too large for chunk!"); + // the cast is safe since payloadOffset and payloadAlignment have the same type and since the alignment must + // be a power of 2, the max alignment is about half of the max value the type can hold payloadOffset = static_cast(offsetToPayload); // this always works if the alignment of PayloadOffset_t and payloadAlignment are equal, From 8389f896768a071b85008abb0a705be2d1247e57 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 20 Mar 2021 17:59:20 +0100 Subject: [PATCH 85/89] iox-#14 update doxygen Signed-off-by: Mathias Kraus --- .../iceoryx_posh/internal/mepoo/memory_manager.hpp | 8 ++++++++ .../internal/popo/building_blocks/chunk_sender.hpp | 11 ++++++++--- .../internal/popo/ports/publisher_port_user.hpp | 8 ++++++-- .../include/iceoryx_posh/mepoo/chunk_header.hpp | 6 ++++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp index db98d6cd2f..70cc1c97cc 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/memory_manager.hpp @@ -61,6 +61,14 @@ class MemoryManager MemPoolInfo getMemPoolInfo(uint32_t f_index) const noexcept; + /// @brief calculates the required chunk size regarding the constraints on payload and custom header + /// @param[in] payloadSize is the size of the user payload without additional headers + /// @param[in] payloadAlignment is the alignment of the user payload + /// @param[in] customHeaderSize is the size of the custom user header; use iox::CHUNK_NO_CUSTOM_HEADER_SIZE to omit + /// a custom header + /// @param[in] customHeaderAlignment is the alignment of the custom user header; use + /// iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT to omit a custom header + /// @return the minimum chunk size required to hold the user payload with the custom header static uint32_t requiredChunkSize(const uint32_t payloadSize, const uint32_t payloadAlignment, const uint32_t customHeaderSize, diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp index db37c6a838..51bef95d79 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp @@ -60,10 +60,15 @@ class ChunkSender : public ChunkDistributor tryAllocate(const UniquePortId originId, diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_user.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_user.hpp index 1b26c46d03..b49e7bfd18 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_user.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_user.hpp @@ -48,9 +48,13 @@ class PublisherPortUser : public BasePort PublisherPortUser& operator=(PublisherPortUser&& rhs) = default; ~PublisherPortUser() = default; - /// @brief Allocate a chunk, the ownerhip of the SharedChunk remains in the PublisherPortUser for being able to + /// @brief Allocate a chunk, the ownership of the SharedChunk remains in the PublisherPortUser for being able to /// cleanup if the user process disappears - /// @param[in] payloadSize, size of the user paylaod without additional headers + /// @param[in] payloadSize, size of the user payload without additional headers + /// @param[in] payloadAlignment, alignment of the user payload + /// @param[in] customHeaderSize, size of the custom user header; use iox::CHUNK_NO_CUSTOM_HEADER_SIZE to omit a custom header + /// @param[in] customHeaderAlignment, alignment of the custom user header; use iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT + /// to omit a custom header /// @return on success pointer to a ChunkHeader which can be used to access the payload and header fields, error if /// not cxx::expected diff --git a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp index ad087a160a..beef5a9849 100644 --- a/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp +++ b/iceoryx_posh/include/iceoryx_posh/mepoo/chunk_header.hpp @@ -41,8 +41,10 @@ struct alignas(32) ChunkHeader /// @param[in] chunkSize is the size of the chunk the ChunkHeader is constructed /// @param[in] payloadSize is the size of the payload /// @param[in] payloadAlignment is the alignment of the payload - /// @param[in] customHeaderSize is the size of the custom header; if no custom header is used, use 0 - /// @param[in] customHeaderAlignment is the alignment for the custom header; if no custom header is used, use 1 + /// @param[in] customHeaderSize is the size of the custom header; use iox::CHUNK_NO_CUSTOM_HEADER_SIZE to omit a + /// custom header + /// @param[in] customHeaderAlignment is the alignment for the custom header; use + /// iox::CHUNK_NO_CUSTOM_HEADER_ALIGNMENT to omit a custom header ChunkHeader(const uint32_t chunkSize, const uint32_t payloadSize, const uint32_t payloadAlignment, From 7cfcd11f5d235cfa59c59763c5aa249bc2b81032 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 20 Mar 2021 18:30:01 +0100 Subject: [PATCH 86/89] iox-#14 add MemoryManager test to check for not using wrong MemPool when the fitting one is empty Signed-off-by: Mathias Kraus --- .../moduletests/test_mepoo_memory_manager.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 57200fe851..1b38134242 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -272,6 +272,30 @@ TEST_F(MemoryManager_test, getChunkMultiMemPoolTooMuchChunks) EXPECT_THAT(sut->getChunk(256U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT), Eq(false)); } +TEST_F(MemoryManager_test, emptyMemPoolDoesNotResultInAcquiringChunksFromOtherMemPools) +{ + constexpr uint32_t ChunkCount{100}; + + mempoolconf.addMemPool({32, ChunkCount}); + mempoolconf.addMemPool({64, ChunkCount}); + mempoolconf.addMemPool({128, ChunkCount}); + mempoolconf.addMemPool({256, ChunkCount}); + sut->configureMemoryManager(mempoolconf, allocator, allocator); + + std::vector chunkStore; + for (size_t i = 0; i < ChunkCount; i++) + { + chunkStore.push_back(sut->getChunk(64U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT)); + } + + EXPECT_THAT(sut->getChunk(64U, PAYLOAD_ALIGNMENT, CUSTOM_HEADER_SIZE, CUSTOM_HEADER_ALIGNMENT), Eq(false)); + + EXPECT_THAT(sut->getMemPoolInfo(0).m_usedChunks, Eq(0U)); + EXPECT_THAT(sut->getMemPoolInfo(1).m_usedChunks, Eq(ChunkCount)); + EXPECT_THAT(sut->getMemPoolInfo(2).m_usedChunks, Eq(0U)); + EXPECT_THAT(sut->getMemPoolInfo(3).m_usedChunks, Eq(0U)); +} + TEST_F(MemoryManager_test, freeChunkMultiMemPoolFullToEmptyToFull) { constexpr uint32_t ChunkCount{100}; From 6753debab9aebf7c0299d0b0e142c9bad2eaaaae Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 20 Mar 2021 18:42:44 +0100 Subject: [PATCH 87/89] iox-#14 fix wrong comments in tests Signed-off-by: Mathias Kraus --- iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp | 4 ++-- iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 753cbb5362..a3340f1925 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -290,8 +290,8 @@ class ChunkHeader_AlteringPayloadWithCustomHeader : public ::testing::TestWithPa { }; -// without a custom header, the payload is located right after the ChunkHeader, therefore the payload size and alignment -// parameters are made dependant on the ChunkHeader +// with a custom header, the payload is located right after the PayloadOffset_t, therefore the payload size and +// alignment parameters are made dependant on the PayloadOffset_t INSTANTIATE_TEST_CASE_P(ChunkHeader_test, ChunkHeader_AlteringPayloadWithCustomHeader, ::testing::Values( diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 1b38134242..0fb958abdb 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -584,8 +584,8 @@ class MemoryManager_AlteringPayloadWithCustomHeader : public ::testing::TestWith protected: }; -// with a custom header, the payload is located right after the ChunkHeader, therefore the payload size and alignment -// parameters are made dependant on the ChunkHeader +// with a custom header, the payload is located right after the PayloadOffset_t, therefore the payload size and +// alignment parameters are made dependant on the PayloadOffset_t INSTANTIATE_TEST_CASE_P(MemoryManager_test, MemoryManager_AlteringPayloadWithCustomHeader, ::testing::Values( From 7ac9679b34a0772ab6f38c33900a973d4c27f46c Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 22 Mar 2021 12:37:56 +0100 Subject: [PATCH 88/89] iox-#14 prevent possible invalid memory access in MemPoolIntrospection Signed-off-by: Mathias Kraus --- .../internal/roudi/introspection/mempool_introspection.inl | 1 + 1 file changed, 1 insertion(+) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl index e130fa43e7..f2b690005a 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl @@ -94,6 +94,7 @@ inline void MemPoolIntrospection:: { LogWarn() << "Cannot allocate chunk for mempool introspection!"; errorHandler(Error::kMEPOO__CANNOT_ALLOCATE_CHUNK, nullptr, ErrorLevel::MODERATE); + return; } auto sample = static_cast(maybeChunkHeader.value()->payload()); From a855bb40d54feec501717af95c02653fb9056484 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 22 Mar 2021 17:14:26 +0100 Subject: [PATCH 89/89] iox-#14 rename some local variables Signed-off-by: Mathias Kraus --- doc/design/chunk_header.md | 12 ++++++------ iceoryx_posh/source/mepoo/chunk_header.cpp | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/design/chunk_header.md b/doc/design/chunk_header.md index a9caa17ef9..b3bb7bf057 100644 --- a/doc/design/chunk_header.md +++ b/doc/design/chunk_header.md @@ -121,18 +121,18 @@ payloadOffset = sizeof(ChunkHeader); ``` headerEndAddress = addressof(chunkHeader) + sizeof(chunkHeader); -payloadAddress = align(headerEndAddress, payloadAlignment); -payloadOffset = payloadAddress - addressof(chunkHeader); +alignedPayloadAddress = align(headerEndAddress, payloadAlignment); +payloadOffset = alignedPayloadAddress - addressof(chunkHeader); ``` 3. Custom header is used ``` headerEndAddress = addressof(chunkHeader) + sizeof(chunkHeader) + sizeof(customHeader); -potentialBackOffsetAddress = align(headerEndAddress, alignof(payloadOffset)); -potentialPayloadAddress = potentialBackOffsetAddress + sizeof(payloadOffset); -payloadAddress = align(potentialPayloadAddress, payloadAlignment); -payloadOffset = payloadAddress - addressof(chunkHeader); +anticipatedBackOffsetAddress = align(headerEndAddress, alignof(payloadOffset)); +unalignedPayloadAddress = anticipatedBackOffsetAddress + sizeof(payloadOffset); +alignedPayloadAddress = align(unalignedPayloadAddress, payloadAlignment); +payloadOffset = alignedPayloadAddress - addressof(chunkHeader); ``` #### Required Chunk Size Calculation diff --git a/iceoryx_posh/source/mepoo/chunk_header.cpp b/iceoryx_posh/source/mepoo/chunk_header.cpp index 7cf56f04ad..e039cc4aae 100644 --- a/iceoryx_posh/source/mepoo/chunk_header.cpp +++ b/iceoryx_posh/source/mepoo/chunk_header.cpp @@ -73,11 +73,11 @@ ChunkHeader::ChunkHeader(const uint32_t chunkSize, // the most complex case with a custom header auto addressOfChunkHeader = reinterpret_cast(this); uint64_t headerEndAddress = addressOfChunkHeader + sizeof(ChunkHeader) + customHeaderSize; - uint64_t potentialBackOffsetAddress = + uint64_t anticipatedBackOffsetAddress = iox::cxx::align(headerEndAddress, static_cast(alignof(PayloadOffset_t))); - uint64_t potentialPayloadAddress = potentialBackOffsetAddress + sizeof(PayloadOffset_t); + uint64_t unalignedPayloadAddress = anticipatedBackOffsetAddress + sizeof(PayloadOffset_t); uint64_t alignedPayloadAddress = - iox::cxx::align(potentialPayloadAddress, static_cast(payloadAlignment)); + iox::cxx::align(unalignedPayloadAddress, static_cast(payloadAlignment)); uint64_t offsetToPayload = alignedPayloadAddress - addressOfChunkHeader; // the cast is safe since payloadOffset and payloadAlignment have the same type and since the alignment must // be a power of 2, the max alignment is about half of the max value the type can hold @@ -89,8 +89,8 @@ ChunkHeader::ChunkHeader(const uint32_t chunkSize, // -> the payload is adjacent to the back-offset and therefore this also works // - or the alignment of the PayloadOffset_t is smaller than payloadAlignment // -> the back-offset can be put adjacent to to the Topic since the smaller alignment always fits - auto addressOfBackOffset = alignedPayloadAddress - sizeof(PayloadOffset_t); - auto backOffset = reinterpret_cast(addressOfBackOffset); + auto backOffsetAddress = alignedPayloadAddress - sizeof(PayloadOffset_t); + auto backOffset = reinterpret_cast(backOffsetAddress); *backOffset = payloadOffset; }