From 23c4bcc79ef9c86c97c5624b31169a6a5883821f Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sat, 28 Oct 2023 15:03:24 +0800 Subject: [PATCH 01/85] iox-#2052 Implement copy/move ctors and assignments Signed-off-by: Dennis Liu The `FixedPositionContainer` was enhanced with copy and move constructors as well as assignment operations. For both copy and move operations, member variables like `m_size`, `m_begin_free`, `m_begin_used`, `m_status`, and `m_next` are handled using copy assignments. The primary distinction between copy and move is in how `m_data` is handled. Specifically, after a move operation: - The original container's `m_size`, `m_begin_free`, and `m_begin_used` are reset. - However, `m_data`, `m_status`, and `m_next` of the original container remain unchanged. Header declarations have been updated to align with these modifications. --- .../iox/detail/fixed_position_container.inl | 78 +++++++++++++++++++ .../include/iox/fixed_position_container.hpp | 8 +- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index 96beac3765..46e4c76061 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -51,6 +51,84 @@ inline FixedPositionContainer::~FixedPositionContainer() noexcept } } +template +FixedPositionContainer::FixedPositionContainer(const FixedPositionContainer& other) noexcept +{ + m_size = other.m_size; + m_begin_free = other.m_begin_free; + m_begin_used = other.m_begin_used; + + for (IndexType i = 0; i < CAPACITY; ++i) + { + m_data[i] = T{other.m_data[i]}; + m_status[i] = other.m_status[i]; + m_next[i] = other.m_next[i]; + } +} + +template +FixedPositionContainer::FixedPositionContainer(FixedPositionContainer&& other) noexcept +{ + m_size = other.m_size; + m_begin_free = other.m_begin_free; + m_begin_used = other.m_begin_used; + + for (IndexType i = 0; i < CAPACITY; ++i) + { + m_data[i] = T{std::move(other.m_data[i])}; + m_status[i] = other.m_status[i]; + m_next[i] = other.m_next[i]; + } + + other.m_size = 0; + other.m_begin_free = Index::FIRST; + other.m_begin_used = Index::INVALID; +} + +template +FixedPositionContainer& +FixedPositionContainer::operator=(const FixedPositionContainer& other) noexcept +{ + if (this != &other) + { + m_size = other.m_size; + m_begin_free = other.m_begin_free; + m_begin_used = other.m_begin_used; + + for (IndexType i = 0; i < CAPACITY; ++i) + { + m_data[i] = other.m_data[i]; + m_status[i] = other.m_status[i]; + m_next[i] = other.m_next[i]; + } + } + return *this; +} + +template +FixedPositionContainer& +FixedPositionContainer::operator=(FixedPositionContainer&& other) noexcept +{ + if (this != &other) + { + m_size = other.m_size; + m_begin_free = other.m_begin_free; + m_begin_used = other.m_begin_used; + + for (IndexType i = 0; i < CAPACITY; ++i) + { + m_data[i] = std::move(other.m_data[i]); + m_status[i] = other.m_status[i]; + m_next[i] = other.m_next[i]; + } + + other.m_size = 0; + other.m_begin_free = Index::FIRST; + other.m_begin_used = Index::INVALID; + } + return *this; +} + template inline void FixedPositionContainer::clear() noexcept { diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index 6f2c9c9491..d90f676813 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -65,11 +65,11 @@ class FixedPositionContainer final FixedPositionContainer() noexcept; ~FixedPositionContainer() noexcept; - FixedPositionContainer(const FixedPositionContainer&) noexcept = delete; - FixedPositionContainer(FixedPositionContainer&&) noexcept = delete; + FixedPositionContainer(const FixedPositionContainer&) noexcept; + FixedPositionContainer(FixedPositionContainer&&) noexcept; - FixedPositionContainer& operator=(const FixedPositionContainer&) noexcept = delete; - FixedPositionContainer& operator=(FixedPositionContainer&&) noexcept = delete; + FixedPositionContainer& operator=(const FixedPositionContainer&) noexcept; + FixedPositionContainer& operator=(FixedPositionContainer&&) noexcept; /// @brief Clears the container and calls the destructor on all contained elements void clear() noexcept; From 9addce91109201326c26512584eedd6b8c7cf35b Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sat, 28 Oct 2023 15:49:37 +0800 Subject: [PATCH 02/85] iox-#2052 Extend `FixedPositionContainer` test Signed-off-by: Dennis Liu Added unit tests to validate both copy and move semantics for the `FixedPositionContainer`. Run `dust/test/dust_moduletests` to view result. --- ...est_container_fixed_position_container.cpp | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index 42670ea32c..cb17b7e710 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -74,6 +74,7 @@ struct FixedPositionContainer_test : public Test TEST_F(FixedPositionContainer_test, ContainerIsNotMovable) { + GTEST_SKIP() << "@deprecated iox-#2052 Add moveable feature"; ::testing::Test::RecordProperty("TEST_ID", "5c05f240-9822-427b-9eb5-69fd43f1ac28"); EXPECT_FALSE(std::is_move_constructible::value); EXPECT_FALSE(std::is_move_assignable::value); @@ -81,6 +82,7 @@ TEST_F(FixedPositionContainer_test, ContainerIsNotMovable) TEST_F(FixedPositionContainer_test, ContainerIsNotCopyable) { + GTEST_SKIP() << "@deprecated iox-#2052 Add copyable feature"; ::testing::Test::RecordProperty("TEST_ID", "1b421af5-d014-4f9b-98ed-fbfdf5a9beb8"); EXPECT_FALSE(std::is_copy_constructible::value); EXPECT_FALSE(std::is_copy_assignable::value); @@ -92,6 +94,224 @@ TEST_F(FixedPositionContainer_test, Capacity) EXPECT_THAT(sut.capacity(), Eq(CAPACITY)); } +// BEGIN test copy constructor + +TEST_F(FixedPositionContainer_test, SimpleContainerCopyConstructor) +{ + ::testing::Test::RecordProperty("TEST_ID", "89d40e19-a838-42fb-aebd-95492c690f98"); + + fillSut(); + + const Sut sut_copy_ctor{sut}; + auto it = sut.begin(); + for (const auto& item : sut_copy_ctor) + { + EXPECT_EQ(item, *it); + EXPECT_NE(&item, &(*it)); + it++; + } + + EXPECT_EQ(sut.size(), sut_copy_ctor.size()); +} + +TEST_F(FixedPositionContainer_test, ComplexContainerCopyConstructor) +{ + ::testing::Test::RecordProperty("TEST_ID", "b3c84ca9-0e24-4331-beca-efd53a5c8818"); + + fillSutComplex(); + + // reset copyCtor counter + SetUp(); + + const SutComplex sut_complex_copy_ctor{sut_complex}; + auto it = sut_complex_copy_ctor.begin(); + for (const auto& item : sut_complex) + { + EXPECT_EQ(item, *it); + EXPECT_NE(&item, &(*it)); + ++it; + } + + EXPECT_EQ(sut_complex.size(), sut_complex_copy_ctor.size()); + EXPECT_EQ(sut_complex_copy_ctor.begin()->stats.copyCTor, sut_complex.size()); +} + +// END test copy constructor + +// BEGIN test move constructor + +TEST_F(FixedPositionContainer_test, SimpleContainerMoveConstructor) +{ + ::testing::Test::RecordProperty("TEST_ID", "869ff262-0157-496b-94ed-da682505cb77"); + + fillSut(); + + std::vector data; + for (const auto& item : sut) + { + data.push_back(item); + } + + const Sut sut_move_ctor{std::move(sut)}; + + std::size_t index{0}; + for (const auto& item : sut_move_ctor) + { + EXPECT_EQ(item, data[index]); + index++; + } + + // sut should be reset (move ctor) + EXPECT_TRUE(sut.empty()); + EXPECT_EQ(sut_move_ctor.size(), data.size()); +} + +TEST_F(FixedPositionContainer_test, ComplexContainerMoveConstructor) +{ + ::testing::Test::RecordProperty("TEST_ID", "55084310-88db-4972-a0d1-01dc75e440be"); + + fillSutComplex(); + + std::vector data; + for (const auto& item : sut_complex) + { + data.push_back(item); + } + + // reset moveCtor counter + SetUp(); + + const SutComplex sut_complex_move_ctor{std::move(sut_complex)}; + + std::size_t index{0}; + for (const auto& item : sut_complex_move_ctor) + { + EXPECT_EQ(item.value, data[index].value); + index++; + } + + // sut_complex should be reset (move ctor) + EXPECT_EQ(sut_complex.empty(), true); + EXPECT_EQ(sut_complex_move_ctor.size(), data.size()); + EXPECT_EQ(sut_complex_move_ctor.begin()->stats.moveCTor, data.size()); +} + +// END test move constructor + +// BEGIN test copy assignment + +TEST_F(FixedPositionContainer_test, SimpleContainerCopyAssignment) +{ + ::testing::Test::RecordProperty("TEST_ID", "e099d78a-4a6c-4c5f-99d5-84431ee24000"); + + fillSut(); + + Sut sut_copy_assignment; + sut_copy_assignment = sut; + + auto it = sut.begin(); + for (const auto& item : sut_copy_assignment) + { + EXPECT_EQ(item, *it); + EXPECT_NE(&item, &(*it)); + ++it; + } + + EXPECT_EQ(sut.size(), sut_copy_assignment.size()); +} + +TEST_F(FixedPositionContainer_test, ComplexContainerCopyAssignment) +{ + ::testing::Test::RecordProperty("TEST_ID", "93dd1e09-69d3-47dc-a021-c2a311b83b86"); + + fillSutComplex(); + + // reset copyAssignment counter + SetUp(); + + SutComplex sut_complex_copy_assignment; + sut_complex_copy_assignment = sut_complex; + + auto it = sut_complex.begin(); + for (const auto& item : sut_complex_copy_assignment) + { + EXPECT_EQ(item, *it); + EXPECT_NE(&item, &(*it)); + ++it; + } + + EXPECT_EQ(sut_complex_copy_assignment.begin()->stats.copyAssignment, sut_complex.size()); + EXPECT_EQ(sut_complex.size(), sut_complex_copy_assignment.size()); +} + +// END test copy assignment + +// BEGIN test move assignment + +TEST_F(FixedPositionContainer_test, SimpleContainerMoveAssignment) +{ + ::testing::Test::RecordProperty("TEST_ID", "6455982d-20f7-4304-a4b1-5947727e3f83"); + + fillSut(); + + Sut sut_move_assignment; + std::vector data; + for (const auto& item : sut) + { + data.push_back(item); + } + + sut_move_assignment = std::move(sut); + + std::size_t index{0}; + for (const auto& item : sut_move_assignment) + { + EXPECT_EQ(item, data[index]); + index++; + } + + // sut should be reset (move assignment) + EXPECT_TRUE(sut.empty()); + EXPECT_EQ(sut_move_assignment.size(), data.size()); +} + +TEST_F(FixedPositionContainer_test, ComplexContainerMoveAssignment) +{ + ::testing::Test::RecordProperty("TEST_ID", "5eb677a3-a54d-462d-9597-70dce86c9701"); + + fillSutComplex(); + + std::vector data; + for (const auto& item : sut_complex) + { + data.push_back(item); + } + + // reset moveAssignment counter + SetUp(); + + SutComplex sut_complex_move_assignment; + sut_complex_move_assignment = std::move(sut_complex); + + std::size_t index{0}; + for (const auto& item : sut_complex_move_assignment) + { + EXPECT_EQ(item, data[index]); + index++; + } + + // sut_complex should be reset (move assignment) + EXPECT_TRUE(sut_complex.empty()); + EXPECT_EQ(sut_complex_move_assignment.begin()->stats.moveAssignment, data.size()); + EXPECT_EQ(sut_complex_move_assignment.size(), data.size()); + + // sut_complex should can be assigned value again + sut_complex.emplace(42UL); + EXPECT_EQ(sut_complex.begin()->value, 42UL); +} + +// END test move assignment + // BEGIN test empty TEST_F(FixedPositionContainer_test, NewlyCreatedContainerIsEmpty) From 27b0eac95227531511e57b76d378678dd4a75ab2 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sun, 29 Oct 2023 02:26:54 +0800 Subject: [PATCH 03/85] iox-#2052 Refactor ctors and assignments Signed-off-by: Dennis Liu Refactor the copy and move constructors of FixedPositionContainer to leverage the functionality of the respective assignment operators. This reduces code duplication and ensures consistent behavior across constructors and assignment operations. Update tests to reflect the changes in behavior. --- .../iox/detail/fixed_position_container.inl | 132 +++++++++++------- ...est_container_fixed_position_container.cpp | 6 +- 2 files changed, 87 insertions(+), 51 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index 46e4c76061..a969b3743b 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -52,79 +52,113 @@ inline FixedPositionContainer::~FixedPositionContainer() noexcept } template -FixedPositionContainer::FixedPositionContainer(const FixedPositionContainer& other) noexcept +inline FixedPositionContainer::FixedPositionContainer(const FixedPositionContainer& rhs) noexcept { - m_size = other.m_size; - m_begin_free = other.m_begin_free; - m_begin_used = other.m_begin_used; - - for (IndexType i = 0; i < CAPACITY; ++i) - { - m_data[i] = T{other.m_data[i]}; - m_status[i] = other.m_status[i]; - m_next[i] = other.m_next[i]; - } + *this = rhs; } template -FixedPositionContainer::FixedPositionContainer(FixedPositionContainer&& other) noexcept +inline FixedPositionContainer::FixedPositionContainer(FixedPositionContainer&& rhs) noexcept { - m_size = other.m_size; - m_begin_free = other.m_begin_free; - m_begin_used = other.m_begin_used; - - for (IndexType i = 0; i < CAPACITY; ++i) - { - m_data[i] = T{std::move(other.m_data[i])}; - m_status[i] = other.m_status[i]; - m_next[i] = other.m_next[i]; - } - - other.m_size = 0; - other.m_begin_free = Index::FIRST; - other.m_begin_used = Index::INVALID; + *this = std::move(rhs); } template -FixedPositionContainer& -FixedPositionContainer::operator=(const FixedPositionContainer& other) noexcept +inline FixedPositionContainer& +FixedPositionContainer::operator=(const FixedPositionContainer& rhs) noexcept { - if (this != &other) + if (this != &rhs) { - m_size = other.m_size; - m_begin_free = other.m_begin_free; - m_begin_used = other.m_begin_used; + IndexType i = 0U; + auto lhsSize = size(); + auto minSize = algorithm::minVal(lhsSize, rhs.size()); + + // copy using copy assignment + for (; i < minSize; ++i) + { + m_data[i] = rhs.m_data[i]; + m_status[i] = rhs.m_status[i]; + m_next[i] = rhs.m_next[i]; + } + + // with rhs.size bigger than this.size: copy further elements from rhs to this + for (; i < rhs.size(); ++i) + { + m_data[i] = rhs.m_data[i]; + m_status[i] = rhs.m_status[i]; + m_next[i] = rhs.m_next[i]; + } - for (IndexType i = 0; i < CAPACITY; ++i) + // with rhs.size smaller than this.size: delete remaining elements of this (erase) + for (; i < lhsSize; ++i) { - m_data[i] = other.m_data[i]; - m_status[i] = other.m_status[i]; - m_next[i] = other.m_next[i]; + erase(i); } + + // init rest status to avoid garbage value + for (; i < CAPACITY; ++i) + { + m_status[i] = SlotStatus::FREE; + m_next[i] = static_cast(i + 1U); + } + m_next[Index::LAST] = Index::INVALID; + + // member update + m_begin_free = rhs.m_begin_free; + m_begin_used = rhs.m_begin_used; + m_size = rhs.m_size; } + return *this; } template -FixedPositionContainer& -FixedPositionContainer::operator=(FixedPositionContainer&& other) noexcept +inline FixedPositionContainer& +FixedPositionContainer::operator=(FixedPositionContainer&& rhs) noexcept { - if (this != &other) + if (this != &rhs) { - m_size = other.m_size; - m_begin_free = other.m_begin_free; - m_begin_used = other.m_begin_used; + IndexType i = 0U; + auto lhsSize = size(); + auto minSize = algorithm::minVal(lhsSize, rhs.size()); + + // move using move assignment + for (; i < minSize; ++i) + { + m_data[i] = std::move(rhs.m_data[i]); + m_status[i] = rhs.m_status[i]; + m_next[i] = rhs.m_next[i]; + } - for (IndexType i = 0; i < CAPACITY; ++i) + // with rhs.size bigger than this.size: move further elements from rhs to this + for (; i < rhs.size(); ++i) { - m_data[i] = std::move(other.m_data[i]); - m_status[i] = other.m_status[i]; - m_next[i] = other.m_next[i]; + m_data[i] = std::move(rhs.m_data[i]); + m_status[i] = rhs.m_status[i]; + m_next[i] = rhs.m_next[i]; } - other.m_size = 0; - other.m_begin_free = Index::FIRST; - other.m_begin_used = Index::INVALID; + // with rhs.size smaller than this.size: delete remaining elements of this (erase) + for (; i < lhsSize; ++i) + { + erase(i); + } + + // init rest status to avoid garbage value + for (; i < CAPACITY; ++i) + { + m_status[i] = SlotStatus::FREE; + m_next[i] = static_cast(i + 1U); + } + m_next[Index::LAST] = Index::INVALID; + + // member update + m_begin_free = rhs.m_begin_free; + m_begin_used = rhs.m_begin_used; + m_size = rhs.m_size; + + // clear rhs to avoid garbage value + rhs.clear(); } return *this; } diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index cb17b7e710..876c4bf92d 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -133,7 +133,8 @@ TEST_F(FixedPositionContainer_test, ComplexContainerCopyConstructor) } EXPECT_EQ(sut_complex.size(), sut_complex_copy_ctor.size()); - EXPECT_EQ(sut_complex_copy_ctor.begin()->stats.copyCTor, sut_complex.size()); + // FixedPositionContainer copyCtor will call copyAssignment + EXPECT_EQ(sut_complex_copy_ctor.begin()->stats.copyAssignment, sut_complex.size()); } // END test copy constructor @@ -193,7 +194,8 @@ TEST_F(FixedPositionContainer_test, ComplexContainerMoveConstructor) // sut_complex should be reset (move ctor) EXPECT_EQ(sut_complex.empty(), true); EXPECT_EQ(sut_complex_move_ctor.size(), data.size()); - EXPECT_EQ(sut_complex_move_ctor.begin()->stats.moveCTor, data.size()); + // FixedPositionContainer copyCtor will call copyAssignment + EXPECT_EQ(sut_complex_move_ctor.begin()->stats.moveAssignment, data.size()); } // END test move constructor From 642ddd5629bc81b412c4e42f6a16a8a5617460ce Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sun, 29 Oct 2023 15:59:05 +0800 Subject: [PATCH 04/85] iox-#2052 Refine test cases Signed-off-by: Dennis Liu The changes involved renaming the tests and ensuring the test content better aligns with the ZOMBIE criteria. The primary object under test is `SutComplex`. For each constructor or assignment, tests were conducted on empty containers, single element containers, multiple elements containers, and full capacity containers. In the case of moves, additional checks were made to see if the `DTor` of `SutComplex` was called (from `FixedPositionContainer::clear()`). --- ...est_container_fixed_position_container.cpp | 342 +++++++++++------- 1 file changed, 221 insertions(+), 121 deletions(-) diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index 876c4bf92d..b1c40e7f58 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -96,220 +96,320 @@ TEST_F(FixedPositionContainer_test, Capacity) // BEGIN test copy constructor -TEST_F(FixedPositionContainer_test, SimpleContainerCopyConstructor) +TEST_F(FixedPositionContainer_test, UsingCopyCtorEmptyContainerResultsInEmptyContainer) { - ::testing::Test::RecordProperty("TEST_ID", "89d40e19-a838-42fb-aebd-95492c690f98"); + ::testing::Test::RecordProperty("TEST_ID", "6c528ef3-9c2d-4eb2-93a9-2d998d0db380"); - fillSut(); + SutComplex copy_sut_complex{sut_complex}; - const Sut sut_copy_ctor{sut}; - auto it = sut.begin(); - for (const auto& item : sut_copy_ctor) + EXPECT_THAT(copy_sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingCopyCtorSingleElementContainerPreservesElement) +{ + ::testing::Test::RecordProperty("TEST_ID", "f3aaf452-77fa-4535-bf0b-37bedefc2bf6"); + + constexpr DataType EXPECTED_VALUE{42U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{1U}; + + sut_complex.emplace(EXPECTED_VALUE); + SutComplex copy_sut_complex{sut_complex}; + + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + + // actually call copyAssignment + EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(copy_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); +} + +TEST_F(FixedPositionContainer_test, UsingCopyCtorMultipleElementsContainerPreservesAllElements) +{ + ::testing::Test::RecordProperty("TEST_ID", "6261f53e-8089-4b9b-9b2d-9da0016a2f1e"); + + constexpr SutComplex::IndexType EXPECTED_SIZE{4U}; + std::vector EXPECTED_VALUE = {0U, 1U, 2U, 3U}; + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { - EXPECT_EQ(item, *it); - EXPECT_NE(&item, &(*it)); - it++; + sut_complex.emplace(EXPECTED_VALUE[i]); } - EXPECT_EQ(sut.size(), sut_copy_ctor.size()); + SutComplex copy_sut_complex{sut_complex}; + + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + + // actually call copyAssignment + EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(EXPECTED_SIZE)); + for (Sut::IndexType i = 0; i < EXPECTED_SIZE; ++i) + { + EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); + } } -TEST_F(FixedPositionContainer_test, ComplexContainerCopyConstructor) +TEST_F(FixedPositionContainer_test, UsingCopyCtorFullCapacityContainerPreservesAllElements) { - ::testing::Test::RecordProperty("TEST_ID", "b3c84ca9-0e24-4331-beca-efd53a5c8818"); + ::testing::Test::RecordProperty("TEST_ID", "028704df-b2f3-4133-9c16-b9d2c6a79916"); fillSutComplex(); + constexpr SutComplex::IndexType EXPECTED_SIZE{CAPACITY}; - // reset copyCtor counter - SetUp(); + SutComplex copy_sut_complex{sut_complex}; - const SutComplex sut_complex_copy_ctor{sut_complex}; - auto it = sut_complex_copy_ctor.begin(); - for (const auto& item : sut_complex) + EXPECT_THAT(copy_sut_complex.full(), Eq(true)); + + // actually call copyAssignment + EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(EXPECTED_SIZE)); + for (Sut::IndexType i = 0; i < EXPECTED_SIZE; ++i) { - EXPECT_EQ(item, *it); - EXPECT_NE(&item, &(*it)); - ++it; + EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(sut_complex.iter_from_index(i)->value)); + EXPECT_THAT(copy_sut_complex.iter_from_index(i), Ne(sut_complex.iter_from_index(i))); } - - EXPECT_EQ(sut_complex.size(), sut_complex_copy_ctor.size()); - // FixedPositionContainer copyCtor will call copyAssignment - EXPECT_EQ(sut_complex_copy_ctor.begin()->stats.copyAssignment, sut_complex.size()); } // END test copy constructor // BEGIN test move constructor -TEST_F(FixedPositionContainer_test, SimpleContainerMoveConstructor) +TEST_F(FixedPositionContainer_test, UsingMoveCtorFromEmptyContainerResultsInEmptyContainer) { - ::testing::Test::RecordProperty("TEST_ID", "869ff262-0157-496b-94ed-da682505cb77"); + ::testing::Test::RecordProperty("TEST_ID", "af8958fb-9a09-4987-b290-ce41abdc2354"); - fillSut(); + SutComplex move_sut_complex{std::move(sut_complex)}; + + EXPECT_THAT(move_sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveCtorFromSingleElementContainerClearsOriginal) +{ + ::testing::Test::RecordProperty("TEST_ID", "df6c1884-43c6-4d1e-b889-6cbf4b9ee726"); + + constexpr DataType EXPECTED_VALUE{42U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{1U}; + sut_complex.emplace(EXPECTED_VALUE); + + SutComplex move_sut_complex{std::move(sut_complex)}; + + ASSERT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); - std::vector data; - for (const auto& item : sut) + // actually call moveAssignment + EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); + + // make sure clear() been called + EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(sut_complex.empty(), Eq(true)); + EXPECT_THAT(move_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveCtorFromMultipleElementsContainerClearsOriginal) +{ + ::testing::Test::RecordProperty("TEST_ID", "b9d929ae-23c8-4b5b-ba82-e5af12cdace4"); + + std::vector EXPECTED_VALUE{0U, 1U, 2U, 3U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{4U}; + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { - data.push_back(item); + sut_complex.emplace(EXPECTED_VALUE[i]); } - const Sut sut_move_ctor{std::move(sut)}; + SutComplex move_sut_complex{std::move(sut_complex)}; - std::size_t index{0}; - for (const auto& item : sut_move_ctor) + ASSERT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + + // actually call moveAssignment + EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); + + // make sure clear() been called + EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(sut_complex.empty(), Eq(true)); + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { - EXPECT_EQ(item, data[index]); - index++; + EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } - - // sut should be reset (move ctor) - EXPECT_TRUE(sut.empty()); - EXPECT_EQ(sut_move_ctor.size(), data.size()); } -TEST_F(FixedPositionContainer_test, ComplexContainerMoveConstructor) +TEST_F(FixedPositionContainer_test, UsingMoveCtorFromFullCapacityContainerClearsOriginal) { - ::testing::Test::RecordProperty("TEST_ID", "55084310-88db-4972-a0d1-01dc75e440be"); + ::testing::Test::RecordProperty("TEST_ID", "8a9ca6d1-5ac3-4e31-9cb9-0476176531e1"); fillSutComplex(); - - std::vector data; + constexpr SutComplex::IndexType EXPECTED_SIZE{CAPACITY}; + std::vector EXPECTED_VALUE; for (const auto& item : sut_complex) { - data.push_back(item); + EXPECTED_VALUE.emplace_back(item.value); } - // reset moveCtor counter - SetUp(); + SutComplex move_sut_complex{std::move(sut_complex)}; - const SutComplex sut_complex_move_ctor{std::move(sut_complex)}; + EXPECT_THAT(sut_complex.empty(), Eq(true)); + ASSERT_THAT(move_sut_complex.full(), Eq(true)); - std::size_t index{0}; - for (const auto& item : sut_complex_move_ctor) + // actually call moveAssignment + EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { - EXPECT_EQ(item.value, data[index].value); - index++; + EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } - - // sut_complex should be reset (move ctor) - EXPECT_EQ(sut_complex.empty(), true); - EXPECT_EQ(sut_complex_move_ctor.size(), data.size()); - // FixedPositionContainer copyCtor will call copyAssignment - EXPECT_EQ(sut_complex_move_ctor.begin()->stats.moveAssignment, data.size()); } // END test move constructor // BEGIN test copy assignment -TEST_F(FixedPositionContainer_test, SimpleContainerCopyAssignment) +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromEmptyContainerResultsInEmptyContainer) { - ::testing::Test::RecordProperty("TEST_ID", "e099d78a-4a6c-4c5f-99d5-84431ee24000"); + ::testing::Test::RecordProperty("TEST_ID", "013338e3-4330-49b4-8aa4-9b66517bb3bc"); - fillSut(); + SutComplex copy_sut_complex; + copy_sut_complex = sut_complex; - Sut sut_copy_assignment; - sut_copy_assignment = sut; + EXPECT_THAT(copy_sut_complex.empty(), Eq(true)); +} - auto it = sut.begin(); - for (const auto& item : sut_copy_assignment) +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromSingleElementContainerClearsOriginal) +{ + ::testing::Test::RecordProperty("TEST_ID", "6cf9e9d1-91a9-4403-a25a-52b64dd523be"); + + constexpr DataType EXPECTED_VALUE{42U}; + sut_complex.emplace(EXPECTED_VALUE); + + SutComplex copy_sut_complex; + copy_sut_complex = sut_complex; + + ASSERT_THAT(copy_sut_complex.size(), Eq(sut_complex.size())); + EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(sut_complex.size())); + EXPECT_THAT(copy_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); +} + +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromMultipleElementsContainerClearsOriginal) +{ + ::testing::Test::RecordProperty("TEST_ID", "262ad71a-0ee2-4661-b2c8-a3cca9c1cf5e"); + + std::vector EXPECTED_VALUE{0U, 1U, 2U, 3U}; + for (SutComplex::IndexType i = 0; i < EXPECTED_VALUE.size(); ++i) { - EXPECT_EQ(item, *it); - EXPECT_NE(&item, &(*it)); - ++it; + sut_complex.emplace(EXPECTED_VALUE[i]); } - EXPECT_EQ(sut.size(), sut_copy_assignment.size()); + SutComplex copy_sut_complex; + copy_sut_complex = sut_complex; + + ASSERT_THAT(copy_sut_complex.size(), Eq(sut_complex.size())); + EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(sut_complex.size())); + for (SutComplex::IndexType i = 0; i < sut_complex.size(); ++i) + { + EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(sut_complex.iter_from_index(i)->value)); + } } -TEST_F(FixedPositionContainer_test, ComplexContainerCopyAssignment) +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromFullCapacityContainerClearsOriginal) { - ::testing::Test::RecordProperty("TEST_ID", "93dd1e09-69d3-47dc-a021-c2a311b83b86"); + ::testing::Test::RecordProperty("TEST_ID", "b46d0be7-5977-467e-adc4-2e9adc554fdd"); fillSutComplex(); + constexpr SutComplex::IndexType EXPECTED_SIZE{CAPACITY}; + std::vector EXPECTED_VALUE; + for (const auto& item : sut_complex) + { + EXPECTED_VALUE.emplace_back(item.value); + } - // reset copyAssignment counter - SetUp(); - - SutComplex sut_complex_copy_assignment; - sut_complex_copy_assignment = sut_complex; + SutComplex copy_sut_complex; + copy_sut_complex = sut_complex; - auto it = sut_complex.begin(); - for (const auto& item : sut_complex_copy_assignment) + ASSERT_THAT(copy_sut_complex.full(), Eq(true)); + EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(EXPECTED_SIZE)); + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { - EXPECT_EQ(item, *it); - EXPECT_NE(&item, &(*it)); - ++it; + EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } - - EXPECT_EQ(sut_complex_copy_assignment.begin()->stats.copyAssignment, sut_complex.size()); - EXPECT_EQ(sut_complex.size(), sut_complex_copy_assignment.size()); } // END test copy assignment // BEGIN test move assignment -TEST_F(FixedPositionContainer_test, SimpleContainerMoveAssignment) +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromEmptyContainerResultsInEmptyContainer) { - ::testing::Test::RecordProperty("TEST_ID", "6455982d-20f7-4304-a4b1-5947727e3f83"); + ::testing::Test::RecordProperty("TEST_ID", "711ced12-4b93-47d1-af37-cace03fac2c1"); - fillSut(); + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromSingleElementContainerClearsOriginal) +{ + ::testing::Test::RecordProperty("TEST_ID", "a3902afc-5eba-4e10-8412-f09b7b5d17b8"); + + constexpr DataType EXPECTED_VALUE{42U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{1U}; + sut_complex.emplace(EXPECTED_VALUE); + + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + ASSERT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); - Sut sut_move_assignment; - std::vector data; - for (const auto& item : sut) + // make sure clear() been called + EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(sut_complex.empty(), Eq(true)); + EXPECT_THAT(move_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromMultipleElementsContainerClearsOriginal) +{ + ::testing::Test::RecordProperty("TEST_ID", "c44da583-1ed8-4c83-b5bb-dba5d64b21d9"); + + std::vector EXPECTED_VALUE{0U, 1U, 2U, 3U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{4U}; + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { - data.push_back(item); + sut_complex.emplace(EXPECTED_VALUE[i]); } - sut_move_assignment = std::move(sut); + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + ASSERT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); - std::size_t index{0}; - for (const auto& item : sut_move_assignment) + // make sure clear() been called + EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(sut_complex.empty(), Eq(true)); + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { - EXPECT_EQ(item, data[index]); - index++; + EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } - - // sut should be reset (move assignment) - EXPECT_TRUE(sut.empty()); - EXPECT_EQ(sut_move_assignment.size(), data.size()); } -TEST_F(FixedPositionContainer_test, ComplexContainerMoveAssignment) +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromFullCapacityContainerClearsOriginal) { - ::testing::Test::RecordProperty("TEST_ID", "5eb677a3-a54d-462d-9597-70dce86c9701"); + ::testing::Test::RecordProperty("TEST_ID", "3196b101-f03a-4029-abb8-77106f0b45d8"); fillSutComplex(); - - std::vector data; + constexpr SutComplex::IndexType EXPECTED_SIZE{CAPACITY}; + std::vector EXPECTED_VALUE; for (const auto& item : sut_complex) { - data.push_back(item); + EXPECTED_VALUE.emplace_back(item.value); } - // reset moveAssignment counter - SetUp(); + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); - SutComplex sut_complex_move_assignment; - sut_complex_move_assignment = std::move(sut_complex); + ASSERT_THAT(move_sut_complex.full(), Eq(true)); + EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); - std::size_t index{0}; - for (const auto& item : sut_complex_move_assignment) + // make sure clear() been called + EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(sut_complex.empty(), Eq(true)); + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { - EXPECT_EQ(item, data[index]); - index++; + EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } - - // sut_complex should be reset (move assignment) - EXPECT_TRUE(sut_complex.empty()); - EXPECT_EQ(sut_complex_move_assignment.begin()->stats.moveAssignment, data.size()); - EXPECT_EQ(sut_complex_move_assignment.size(), data.size()); - - // sut_complex should can be assigned value again - sut_complex.emplace(42UL); - EXPECT_EQ(sut_complex.begin()->value, 42UL); } // END test move assignment From 7c8b4c77600a324bc7819ed203d142605fa35fdd Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sun, 29 Oct 2023 16:12:18 +0800 Subject: [PATCH 05/85] iox-#2052 Update unreleased document Signed-off-by: Dennis Liu Add issue 2052 into unreleased document in feature section. --- doc/website/release-notes/iceoryx-unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 148920cbd7..03dd0a5f3f 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -99,6 +99,7 @@ - ServiceDiscovery uses instrospection MemPools [#1359](https://github.com/eclipse-iceoryx/iceoryx/issues/1359) - LockFreeQueue fails to support move-only types [\#2067](https://github.com/eclipse-iceoryx/iceoryx/issues/2067) - Fix musl libc compile (missing sys/stat.h include in mqueue.h for mode_t definition) [\#2072](https://github.com/eclipse-iceoryx/iceoryx/issues/2072) +- Implement move/copy constructor and assignment for `FixedPositionContainer`. [#2052](https://github.com/eclipse-iceoryx/iceoryx/issues/2052) **Refactoring:** From 566c487e394f867f114182863942654fb2cb9a0e Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Tue, 31 Oct 2023 00:15:58 +0800 Subject: [PATCH 06/85] iox-#2052 Fix nitpick suggestion Signed-off-by: Dennis Liu Fix nitpick mentioned in PR. Including: - Replace index value `0U` by `IndexType::First`. - Change variable to snake_case. --- .../iox/detail/fixed_position_container.inl | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index a969b3743b..cb8c6f25c3 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -1,4 +1,5 @@ // Copyright (c) 2023 by Mathias Kraus . All rights reserved. +// Copyright (c) 2023 by Dennis Liu . 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. @@ -69,12 +70,12 @@ FixedPositionContainer::operator=(const FixedPositionContainer& rhs { if (this != &rhs) { - IndexType i = 0U; - auto lhsSize = size(); - auto minSize = algorithm::minVal(lhsSize, rhs.size()); + IndexType i = Index::FIRST; + auto lhs_size = size(); + auto min_size = algorithm::minVal(lhs_size, rhs.size()); // copy using copy assignment - for (; i < minSize; ++i) + for (; i < min_size; ++i) { m_data[i] = rhs.m_data[i]; m_status[i] = rhs.m_status[i]; @@ -90,7 +91,7 @@ FixedPositionContainer::operator=(const FixedPositionContainer& rhs } // with rhs.size smaller than this.size: delete remaining elements of this (erase) - for (; i < lhsSize; ++i) + for (; i < lhs_size; ++i) { erase(i); } @@ -118,12 +119,12 @@ FixedPositionContainer::operator=(FixedPositionContainer&& rhs) noe { if (this != &rhs) { - IndexType i = 0U; - auto lhsSize = size(); - auto minSize = algorithm::minVal(lhsSize, rhs.size()); + IndexType i = Index::FIRST; + auto lhs_size = size(); + auto min_size = algorithm::minVal(lhs_size, rhs.size()); // move using move assignment - for (; i < minSize; ++i) + for (; i < min_size; ++i) { m_data[i] = std::move(rhs.m_data[i]); m_status[i] = rhs.m_status[i]; @@ -139,7 +140,7 @@ FixedPositionContainer::operator=(FixedPositionContainer&& rhs) noe } // with rhs.size smaller than this.size: delete remaining elements of this (erase) - for (; i < lhsSize; ++i) + for (; i < lhs_size; ++i) { erase(i); } From d97b10e70538ac3c36d25bf0170f662b160c4981 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Tue, 31 Oct 2023 00:19:22 +0800 Subject: [PATCH 07/85] iox-#2052 Refine and rearrange existing test Signed-off-by: Dennis Liu Add more strict check(e.g., check full, size, empty) and rearrange the test code. --- ...est_container_fixed_position_container.cpp | 171 +++++++++++++----- 1 file changed, 121 insertions(+), 50 deletions(-) diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index b1c40e7f58..771205bd7d 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2023 by Mathias Kraus . All rights reserved. +// Copyright (c) 2023 by Dennis Liu . 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. @@ -102,7 +103,9 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorEmptyContainerResultsInEmptyCon SutComplex copy_sut_complex{sut_complex}; + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(true)); + EXPECT_THAT(copy_sut_complex.size(), Eq(0)); } TEST_F(FixedPositionContainer_test, UsingCopyCtorSingleElementContainerPreservesElement) @@ -115,11 +118,14 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorSingleElementContainerPreserves sut_complex.emplace(EXPECTED_VALUE); SutComplex copy_sut_complex{sut_complex}; + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + EXPECT_THAT(copy_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); // actually call copyAssignment - EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(EXPECTED_SIZE)); - EXPECT_THAT(copy_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); + EXPECT_THAT(stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); } TEST_F(FixedPositionContainer_test, UsingCopyCtorMultipleElementsContainerPreservesAllElements) @@ -135,14 +141,18 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorMultipleElementsContainerPreser SutComplex copy_sut_complex{sut_complex}; + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - - // actually call copyAssignment - EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(EXPECTED_SIZE)); for (Sut::IndexType i = 0; i < EXPECTED_SIZE; ++i) { EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); + EXPECT_THAT(copy_sut_complex.iter_from_index(i), Ne(sut_complex.iter_from_index(i))); } + + // actually call copyAssignment + EXPECT_THAT(stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); } TEST_F(FixedPositionContainer_test, UsingCopyCtorFullCapacityContainerPreservesAllElements) @@ -155,14 +165,25 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorFullCapacityContainerPreservesA SutComplex copy_sut_complex{sut_complex}; EXPECT_THAT(copy_sut_complex.full(), Eq(true)); - - // actually call copyAssignment - EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(CAPACITY)); for (Sut::IndexType i = 0; i < EXPECTED_SIZE; ++i) { EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(sut_complex.iter_from_index(i)->value)); EXPECT_THAT(copy_sut_complex.iter_from_index(i), Ne(sut_complex.iter_from_index(i))); } + + // actually call copyAssignment + EXPECT_THAT(stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); +} + +TEST_F(FixedPositionContainer_test, UsingCopyCtorFromNonEmptyContainerCopyToEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "f7e142f3-e236-46f7-82df-52624cb95094"); + + constexpr DataType EXPECTED_VALUE{42U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{1U}; } // END test copy constructor @@ -175,7 +196,11 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromEmptyContainerResultsInEmpt SutComplex move_sut_complex{std::move(sut_complex)}; + EXPECT_THAT(move_sut_complex.full(), Eq(false)); EXPECT_THAT(move_sut_complex.empty(), Eq(true)); + EXPECT_THAT(move_sut_complex.size(), Eq(0)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); } TEST_F(FixedPositionContainer_test, UsingMoveCtorFromSingleElementContainerClearsOriginal) @@ -188,15 +213,21 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromSingleElementContainerClear SutComplex move_sut_complex{std::move(sut_complex)}; - ASSERT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); // actually call moveAssignment - EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); - + EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); // make sure clear() been called - EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + + // Note: It is sufficient to do it only once for "sut_complex" + EXPECT_THAT(sut_complex.full(), Eq(false)); EXPECT_THAT(sut_complex.empty(), Eq(true)); - EXPECT_THAT(move_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); + EXPECT_THAT(sut_complex.size(), Eq(0)); } TEST_F(FixedPositionContainer_test, UsingMoveCtorFromMultipleElementsContainerClearsOriginal) @@ -212,18 +243,21 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromMultipleElementsContainerCl SutComplex move_sut_complex{std::move(sut_complex)}; - ASSERT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); - - // actually call moveAssignment - EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); - - // make sure clear() been called - EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); - EXPECT_THAT(sut_complex.empty(), Eq(true)); + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } + + // actually call moveAssignment + EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); + // make sure clear() been called + EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); } TEST_F(FixedPositionContainer_test, UsingMoveCtorFromFullCapacityContainerClearsOriginal) @@ -240,16 +274,21 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromFullCapacityContainerClears SutComplex move_sut_complex{std::move(sut_complex)}; - EXPECT_THAT(sut_complex.empty(), Eq(true)); - ASSERT_THAT(move_sut_complex.full(), Eq(true)); - - // actually call moveAssignment - EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); - EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.full(), Eq(true)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } + + // actually call moveAssignment + EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); + // make sure clear() been called + EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); } // END test move constructor @@ -263,7 +302,9 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromEmptyContainerResults SutComplex copy_sut_complex; copy_sut_complex = sut_complex; + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(true)); + EXPECT_THAT(copy_sut_complex.size(), Eq(0)); } TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromSingleElementContainerClearsOriginal) @@ -276,8 +317,12 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromSingleElementContaine SutComplex copy_sut_complex; copy_sut_complex = sut_complex; - ASSERT_THAT(copy_sut_complex.size(), Eq(sut_complex.size())); - EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(sut_complex.size())); + EXPECT_THAT(stats.copyAssignment, Eq(sut_complex.size())); + EXPECT_THAT(stats.moveAssignment, Eq(0)); + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(sut_complex.size())); EXPECT_THAT(copy_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); } @@ -294,11 +339,16 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromMultipleElementsConta SutComplex copy_sut_complex; copy_sut_complex = sut_complex; - ASSERT_THAT(copy_sut_complex.size(), Eq(sut_complex.size())); - EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(sut_complex.size())); + EXPECT_THAT(stats.copyAssignment, Eq(sut_complex.size())); + EXPECT_THAT(stats.moveAssignment, Eq(0)); + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(sut_complex.size())); for (SutComplex::IndexType i = 0; i < sut_complex.size(); ++i) { - EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(sut_complex.iter_from_index(i)->value)); + EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); + EXPECT_THAT(copy_sut_complex.iter_from_index(i), Ne(sut_complex.iter_from_index(i))); } } @@ -317,11 +367,16 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromFullCapacityContainer SutComplex copy_sut_complex; copy_sut_complex = sut_complex; - ASSERT_THAT(copy_sut_complex.full(), Eq(true)); - EXPECT_THAT(copy_sut_complex.begin()->stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); + EXPECT_THAT(copy_sut_complex.iter_from_index(i), Ne(sut_complex.iter_from_index(i))); } } @@ -336,7 +391,11 @@ TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromEmptyContainerResults SutComplex move_sut_complex; move_sut_complex = std::move(sut_complex); + EXPECT_THAT(move_sut_complex.full(), Eq(false)); EXPECT_THAT(move_sut_complex.empty(), Eq(true)); + EXPECT_THAT(move_sut_complex.size(), Eq(0)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); } TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromSingleElementContainerClearsOriginal) @@ -350,13 +409,17 @@ TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromSingleElementContaine SutComplex move_sut_complex; move_sut_complex = std::move(sut_complex); - ASSERT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); - EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); + EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); // make sure clear() been called - EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(sut_complex.empty(), Eq(true)); - EXPECT_THAT(move_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); } TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromMultipleElementsContainerClearsOriginal) @@ -373,16 +436,20 @@ TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromMultipleElementsConta SutComplex move_sut_complex; move_sut_complex = std::move(sut_complex); - ASSERT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); - EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); - - // make sure clear() been called - EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); - EXPECT_THAT(sut_complex.empty(), Eq(true)); + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } + + EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); + // make sure clear() been called + EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); } TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromFullCapacityContainerClearsOriginal) @@ -400,16 +467,20 @@ TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromFullCapacityContainer SutComplex move_sut_complex; move_sut_complex = std::move(sut_complex); - ASSERT_THAT(move_sut_complex.full(), Eq(true)); - EXPECT_THAT(move_sut_complex.begin()->stats.moveAssignment, Eq(EXPECTED_SIZE)); - - // make sure clear() been called - EXPECT_THAT(move_sut_complex.begin()->stats.dTor, Eq(EXPECTED_SIZE)); - EXPECT_THAT(sut_complex.empty(), Eq(true)); + EXPECT_THAT(move_sut_complex.full(), Eq(true)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } + + EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); + // make sure clear() been called + EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); } // END test move assignment From 2f2847029a9f7315a5a1cebcf574c5f74185749e Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Tue, 31 Oct 2023 19:03:05 +0800 Subject: [PATCH 08/85] iox-#2052 Fix expected result typo Signed-off-by: Dennis Liu Fix typo in test case b46d0be7-5977-467e-adc4-2e9adc554fdd. The result should be true. --- .../moduletests/test_container_fixed_position_container.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index 771205bd7d..bd5d799a3c 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -370,7 +370,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromFullCapacityContainer EXPECT_THAT(stats.copyAssignment, Eq(EXPECTED_SIZE)); EXPECT_THAT(stats.moveAssignment, Eq(0)); - EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.full(), Eq(true)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) From 76e54bcd5a72fdc12d0081c2cc372cb0072c5fa0 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Tue, 31 Oct 2023 20:00:10 +0800 Subject: [PATCH 09/85] iox-#2052 Fix ctor and assignment Signed-off-by: Dennis Liu According to PR discussion, I used the latter method to implement both ctor and assignment. --- .../iox/detail/fixed_position_container.inl | 112 ++++++++++-------- 1 file changed, 62 insertions(+), 50 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index cb8c6f25c3..dbeda0d48a 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -71,45 +71,51 @@ FixedPositionContainer::operator=(const FixedPositionContainer& rhs if (this != &rhs) { IndexType i = Index::FIRST; - auto lhs_size = size(); - auto min_size = algorithm::minVal(lhs_size, rhs.size()); + ConstIterator rhs_it = rhs.begin(); - // copy using copy assignment - for (; i < min_size; ++i) + // copy using copy assignment util rhs iter becomes invalid + for (; rhs_it.to_index() != Index::INVALID; i++, rhs_it++) { - m_data[i] = rhs.m_data[i]; - m_status[i] = rhs.m_status[i]; - m_next[i] = rhs.m_next[i]; + if (m_status[i] == SlotStatus::USED) + { + // clean original data by it's dtor + erase(i); + } + m_data[i] = *rhs_it; + m_status[i] = SlotStatus::USED; + // can this line be removed? + m_next[i] = static_cast(i + 1U); } - // with rhs.size bigger than this.size: copy further elements from rhs to this - for (; i < rhs.size(); ++i) - { - m_data[i] = rhs.m_data[i]; - m_status[i] = rhs.m_status[i]; - m_next[i] = rhs.m_next[i]; - } + // correct next + m_next[i] = Index::INVALID; - // with rhs.size smaller than this.size: delete remaining elements of this (erase) - for (; i < lhs_size; ++i) + // erase rest USED element in rhs, m_next and m_status will be also modified by erase() + while (i < Index::INVALID) { - erase(i); + if (m_status[i] == SlotStatus::USED) + { + break; + } + + i++; } - // init rest status to avoid garbage value - for (; i < CAPACITY; ++i) + // if rest USED slot found + if (i != Index::INVALID) { - m_status[i] = SlotStatus::FREE; - m_next[i] = static_cast(i + 1U); + for (Iterator lhs_it = this->iter_from_index(i); lhs_it.to_index() != Index::INVALID; lhs_it++) + { + erase(lhs_it); + } } - m_next[Index::LAST] = Index::INVALID; // member update - m_begin_free = rhs.m_begin_free; - m_begin_used = rhs.m_begin_used; + // may this cause problem when size == capacity? + m_begin_free = static_cast(rhs.size()); + m_begin_used = Index::FIRST; m_size = rhs.m_size; } - return *this; } @@ -120,45 +126,51 @@ FixedPositionContainer::operator=(FixedPositionContainer&& rhs) noe if (this != &rhs) { IndexType i = Index::FIRST; - auto lhs_size = size(); - auto min_size = algorithm::minVal(lhs_size, rhs.size()); + Iterator rhs_it = rhs.begin(); - // move using move assignment - for (; i < min_size; ++i) + // copy using copy assignment util rhs iter becomes invalid + for (; rhs_it.to_index() != Index::INVALID; i++, rhs_it++) { - m_data[i] = std::move(rhs.m_data[i]); - m_status[i] = rhs.m_status[i]; - m_next[i] = rhs.m_next[i]; + if (m_status[i] == SlotStatus::USED) + { + // clean original data by it's dtor + erase(i); + } + m_data[i] = std::move(*rhs_it); + m_status[i] = SlotStatus::USED; + // can this line be removed? + m_next[i] = static_cast(i + 1U); } - // with rhs.size bigger than this.size: move further elements from rhs to this - for (; i < rhs.size(); ++i) - { - m_data[i] = std::move(rhs.m_data[i]); - m_status[i] = rhs.m_status[i]; - m_next[i] = rhs.m_next[i]; - } + // correct next + m_next[i] = Index::INVALID; - // with rhs.size smaller than this.size: delete remaining elements of this (erase) - for (; i < lhs_size; ++i) + // erase rest USED element in rhs, m_next and m_status will be also modified by erase() + while (i < Index::INVALID) { - erase(i); + if (m_status[i] == SlotStatus::USED) + { + break; + } + i++; } - // init rest status to avoid garbage value - for (; i < CAPACITY; ++i) + // if rest USED slot found + if (i != Index::INVALID) { - m_status[i] = SlotStatus::FREE; - m_next[i] = static_cast(i + 1U); + for (Iterator lhs_it = this->iter_from_index(i); lhs_it.to_index() != Index::INVALID; lhs_it++) + { + erase(lhs_it); + } } - m_next[Index::LAST] = Index::INVALID; // member update - m_begin_free = rhs.m_begin_free; - m_begin_used = rhs.m_begin_used; + // may this cause problem when size == capacity? + m_begin_free = static_cast(rhs.size()); + m_begin_used = Index::FIRST; m_size = rhs.m_size; - // clear rhs to avoid garbage value + // clear rhs rhs.clear(); } return *this; From 7c0b2e4536e703e661bf929eb8a43d06a2aed4c4 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Tue, 31 Oct 2023 22:59:00 +0800 Subject: [PATCH 10/85] iox-#2052 Add init() to reduce code duplication Signed-off-by: Dennis Liu Add a private function init() to reduce code duplication. Also, fix the issues mentioned after commit `b0929dd96287f46d519c634522f2700d0a646221`. --- .../iox/detail/fixed_position_container.inl | 139 ++++++++---------- .../include/iox/fixed_position_container.hpp | 3 + 2 files changed, 62 insertions(+), 80 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index dbeda0d48a..db13340981 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -70,51 +70,7 @@ FixedPositionContainer::operator=(const FixedPositionContainer& rhs { if (this != &rhs) { - IndexType i = Index::FIRST; - ConstIterator rhs_it = rhs.begin(); - - // copy using copy assignment util rhs iter becomes invalid - for (; rhs_it.to_index() != Index::INVALID; i++, rhs_it++) - { - if (m_status[i] == SlotStatus::USED) - { - // clean original data by it's dtor - erase(i); - } - m_data[i] = *rhs_it; - m_status[i] = SlotStatus::USED; - // can this line be removed? - m_next[i] = static_cast(i + 1U); - } - - // correct next - m_next[i] = Index::INVALID; - - // erase rest USED element in rhs, m_next and m_status will be also modified by erase() - while (i < Index::INVALID) - { - if (m_status[i] == SlotStatus::USED) - { - break; - } - - i++; - } - - // if rest USED slot found - if (i != Index::INVALID) - { - for (Iterator lhs_it = this->iter_from_index(i); lhs_it.to_index() != Index::INVALID; lhs_it++) - { - erase(lhs_it); - } - } - - // member update - // may this cause problem when size == capacity? - m_begin_free = static_cast(rhs.size()); - m_begin_used = Index::FIRST; - m_size = rhs.m_size; + init(rhs); } return *this; } @@ -125,55 +81,78 @@ FixedPositionContainer::operator=(FixedPositionContainer&& rhs) noe { if (this != &rhs) { - IndexType i = Index::FIRST; - Iterator rhs_it = rhs.begin(); + init(std::move(rhs)); - // copy using copy assignment util rhs iter becomes invalid - for (; rhs_it.to_index() != Index::INVALID; i++, rhs_it++) - { - if (m_status[i] == SlotStatus::USED) - { - // clean original data by it's dtor - erase(i); - } - m_data[i] = std::move(*rhs_it); - m_status[i] = SlotStatus::USED; - // can this line be removed? - m_next[i] = static_cast(i + 1U); - } + // clear rhs + rhs.clear(); + } + return *this; +} - // correct next - m_next[i] = Index::INVALID; +template +template +inline void FixedPositionContainer::init(RhsType&& rhs) noexcept +{ + static_assert(std::is_rvalue_reference::value + || (std::is_lvalue_reference::value + && std::is_const>::value), + "RhsType must be const lvalue reference or rvalue reference"); - // erase rest USED element in rhs, m_next and m_status will be also modified by erase() - while (i < Index::INVALID) + IndexType i = Index::FIRST; + auto rhs_it = (std::forward(rhs)).begin(); + bool is_move = std::is_rvalue_reference::value; + + // transfer src data to destination + for (; rhs_it.to_index() != Index::INVALID; ++i, ++rhs_it) + { + if (m_status[i] == SlotStatus::USED) { - if (m_status[i] == SlotStatus::USED) + if (is_move) { - break; + m_data[i] = std::move(*rhs_it); + } + else + { + m_data[i] = *rhs_it; } - i++; } - - // if rest USED slot found - if (i != Index::INVALID) + else { - for (Iterator lhs_it = this->iter_from_index(i); lhs_it.to_index() != Index::INVALID; lhs_it++) + // use ctor to avoid UB for non-initialized free slots + if (is_move) { - erase(lhs_it); + new (&m_data[i]) T(std::move(*rhs_it)); + } + else + { + new (&m_data[i]) T(*rhs_it); } } - // member update - // may this cause problem when size == capacity? - m_begin_free = static_cast(rhs.size()); - m_begin_used = Index::FIRST; - m_size = rhs.m_size; + m_status[i] = SlotStatus::USED; + m_next[i] = static_cast(i + 1U); + } - // clear rhs - rhs.clear(); + // correct next + m_next[i] = Index::INVALID; + + // erase rest USED element in rhs, also update m_next for free slots + for (; i < Index::INVALID; ++i) + { + if (m_status[i] == SlotStatus::USED) + { + erase(i); + } + else + { + m_next[i] = static_cast(i + 1U); + } } - return *this; + + // member update + m_begin_free = static_cast(rhs.m_size); + m_begin_used = Index::FIRST; + m_size = rhs.m_size; } template diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index d90f676813..690f4aaf9a 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -324,6 +324,9 @@ class FixedPositionContainer final IndexType m_size{0}; IndexType m_begin_free{Index::FIRST}; IndexType m_begin_used{Index::INVALID}; + + template + void init(RhsType&& rhs) noexcept; }; } // namespace iox From 878f1fd1699296bdca12f1966e11cb6da79c4a29 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Wed, 1 Nov 2023 00:25:56 +0800 Subject: [PATCH 11/85] iox-#2052 Fix same values used in two consecutive tests Signed-off-by: Dennis Liu We use same test data(e.g., {0U, 1U, 2U, 3U} or `fillSut()` or `fillSutComplex()` function in two consecutive tests) in `FixPositionContainer` ctor or assignment related tests. {56U, 57U, 58U, 59U} replace {0U, 1U, 2U, 3U} in multiple values tests. --- .../test_container_fixed_position_container.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index bd5d799a3c..0ff8575827 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -133,7 +133,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorMultipleElementsContainerPreser ::testing::Test::RecordProperty("TEST_ID", "6261f53e-8089-4b9b-9b2d-9da0016a2f1e"); constexpr SutComplex::IndexType EXPECTED_SIZE{4U}; - std::vector EXPECTED_VALUE = {0U, 1U, 2U, 3U}; + std::vector EXPECTED_VALUE = {56U, 57U, 58U, 59U}; for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { sut_complex.emplace(EXPECTED_VALUE[i]); @@ -234,7 +234,7 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromMultipleElementsContainerCl { ::testing::Test::RecordProperty("TEST_ID", "b9d929ae-23c8-4b5b-ba82-e5af12cdace4"); - std::vector EXPECTED_VALUE{0U, 1U, 2U, 3U}; + std::vector EXPECTED_VALUE{56U, 57U, 58U, 59U}; constexpr SutComplex::IndexType EXPECTED_SIZE{4U}; for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { @@ -330,7 +330,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromMultipleElementsConta { ::testing::Test::RecordProperty("TEST_ID", "262ad71a-0ee2-4661-b2c8-a3cca9c1cf5e"); - std::vector EXPECTED_VALUE{0U, 1U, 2U, 3U}; + std::vector EXPECTED_VALUE{56U, 57U, 58U, 59U}; for (SutComplex::IndexType i = 0; i < EXPECTED_VALUE.size(); ++i) { sut_complex.emplace(EXPECTED_VALUE[i]); @@ -426,7 +426,7 @@ TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromMultipleElementsConta { ::testing::Test::RecordProperty("TEST_ID", "c44da583-1ed8-4c83-b5bb-dba5d64b21d9"); - std::vector EXPECTED_VALUE{0U, 1U, 2U, 3U}; + std::vector EXPECTED_VALUE{56U, 57U, 58U, 59U}; constexpr SutComplex::IndexType EXPECTED_SIZE{4U}; for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) { From 5be9987f76bea7cc78ca855c1ce49c211ca5e42e Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Thu, 2 Nov 2023 00:20:04 +0800 Subject: [PATCH 12/85] iox-#2052 Rename init() to copy_and_move_impl() Signed-off-by: Dennis Liu Rename `init` to `copy_and_move_impl` to clear the function purpose. Also, move up the declaration of `copy_and_move_impl`. --- .../include/iox/detail/fixed_position_container.inl | 6 +++--- .../container/include/iox/fixed_position_container.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index db13340981..5a1561fb57 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -70,7 +70,7 @@ FixedPositionContainer::operator=(const FixedPositionContainer& rhs { if (this != &rhs) { - init(rhs); + copy_and_move_impl(rhs); } return *this; } @@ -81,7 +81,7 @@ FixedPositionContainer::operator=(FixedPositionContainer&& rhs) noe { if (this != &rhs) { - init(std::move(rhs)); + copy_and_move_impl(std::move(rhs)); // clear rhs rhs.clear(); @@ -91,7 +91,7 @@ FixedPositionContainer::operator=(FixedPositionContainer&& rhs) noe template template -inline void FixedPositionContainer::init(RhsType&& rhs) noexcept +inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rhs) noexcept { static_assert(std::is_rvalue_reference::value || (std::is_lvalue_reference::value diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index 690f4aaf9a..9cded3d32f 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -317,6 +317,9 @@ class FixedPositionContainer final IndexType m_index; }; + template + void copy_and_move_impl(RhsType&& rhs) noexcept; + private: UninitializedArray m_data; UninitializedArray m_status; @@ -324,9 +327,6 @@ class FixedPositionContainer final IndexType m_size{0}; IndexType m_begin_free{Index::FIRST}; IndexType m_begin_used{Index::INVALID}; - - template - void init(RhsType&& rhs) noexcept; }; } // namespace iox From 6ea61c93cfc7ce757716cae7b94c602475c0f446 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sat, 4 Nov 2023 18:02:55 +0800 Subject: [PATCH 13/85] iox-#2052 Fix non-copyable class compile error Signed-off-by: Dennis Liu With the previous implementation of `copy_and_move_impl`, non-copyable classes would encounter compilation failures due to non-compile-time if-else branching. The compiler would check the deleted copy constructor and assignment in the `else` branch, even though they would never be called. To address this, several helper structs have been implemented to change runtime if-else branching to compile-time if-else branching for C++14. If C++17 is used, we can simply employ `if constexpr` to make the branching compile-time. The test case `e1cc7c9f-c1b5-4047-811b-004302af5c00` (UsingMoveCtorAtNonCopyableTypeShouldCompile) verifies that the implementation works for both C++14 and C++17. The assignment portion will be added in a subsequent commit. --- .../iox/detail/fixed_position_container.inl | 24 +++++-- .../include/iox/fixed_position_container.hpp | 71 +++++++++++++++++++ ...est_container_fixed_position_container.cpp | 49 +++++++++++++ 3 files changed, 140 insertions(+), 4 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index 5a1561fb57..418339df9b 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -93,6 +93,8 @@ template template inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rhs) noexcept { + // we already make sure rhs is always passed by std::move() for move case, therefore + // the result of "decltype(rhs)" is same as "decltype(std::forward(rhs))" static_assert(std::is_rvalue_reference::value || (std::is_lvalue_reference::value && std::is_const>::value), @@ -100,14 +102,15 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh IndexType i = Index::FIRST; auto rhs_it = (std::forward(rhs)).begin(); - bool is_move = std::is_rvalue_reference::value; + constexpr bool is_move = std::is_rvalue_reference::value; // transfer src data to destination for (; rhs_it.to_index() != Index::INVALID; ++i, ++rhs_it) { if (m_status[i] == SlotStatus::USED) { - if (is_move) +#if __cplusplus >= 201703L + if constexpr (is_move) { m_data[i] = std::move(*rhs_it); } @@ -115,11 +118,20 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh { m_data[i] = *rhs_it; } +#else + // We introduce a helper struct primarily due to the test case + // e1cc7c9f-c1b5-4047-811b-004302af5c00. It demands compile-time if-else branching + // for classes that are either non-copyable or non-moveable. + // Note: With C++17's 'if constexpr', the need for these helper structs (labeled "C++ 14 feature" + // in fixed_position_container.hpp) can be eliminated. + AssignmentHelper::assign(m_data[i], MoveHelper::move_or_copy(rhs_it)); +#endif } else { - // use ctor to avoid UB for non-initialized free slots - if (is_move) +// use ctor to avoid UB for non-initialized free slots +#if __cplusplus >= 201703L + if constexpr (is_move) { new (&m_data[i]) T(std::move(*rhs_it)); } @@ -127,6 +139,10 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh { new (&m_data[i]) T(*rhs_it); } +#else + // Same as above + CtorHelper::construct(m_data[i], MoveHelper::move_or_copy(rhs_it)); +#endif } m_status[i] = SlotStatus::USED; diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index 9cded3d32f..4b7dbe9fc5 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -317,6 +317,77 @@ class FixedPositionContainer final IndexType m_index; }; +#if __cplusplus < 201703L + private: + // C++ 14 feature + template + struct AssignmentHelper; + + template <> + struct AssignmentHelper + { + static void assign(T& dest, T&& src) + { + dest = std::forward(src); + } + }; + + template <> + struct AssignmentHelper + { + static void assign(T& dest, const T& src) + { + dest = src; + } + }; + + // C++ 14 feature + template + struct CtorHelper; + + template <> + struct CtorHelper + { + static void construct(T& dest, T&& src) + { + new (&dest) T(std::forward(src)); + } + }; + + template <> + struct CtorHelper + { + static void construct(T& dest, const T& src) + { + new (&dest) T(src); + } + }; + + // C++ 14 feature + template + struct MoveHelper; + + template <> + struct MoveHelper + { + template + static auto move_or_copy(Iterator& it) -> decltype(std::move(*it)) + { + return std::move(*it); + } + }; + + template <> + struct MoveHelper + { + template + static auto move_or_copy(Iterator& it) -> decltype(*it) + { + return *it; + } + }; +#endif + template void copy_and_move_impl(RhsType&& rhs) noexcept; diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index 0ff8575827..115d628040 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -29,6 +29,38 @@ using namespace ::testing; using namespace iox; using namespace iox::testing; +// should this places in other file? +template +class MovableButNonCopyableTestClass +{ + public: + // moveable only class requires this + MovableButNonCopyableTestClass(const T value) + : value(value) + { + } + + MovableButNonCopyableTestClass(const MovableButNonCopyableTestClass& rhs) = delete; + MovableButNonCopyableTestClass& operator=(const MovableButNonCopyableTestClass& rhs) = delete; + + MovableButNonCopyableTestClass(MovableButNonCopyableTestClass&& rhs) + { + value = rhs.value; + } + + MovableButNonCopyableTestClass& operator=(MovableButNonCopyableTestClass&& rhs) + { + if (this != &rhs) + { + value = std::move(rhs.value); + } + return *this; + } + + public: + T value; +}; + struct FixedPositionContainer_test : public Test { using DataType = uint64_t; @@ -37,7 +69,10 @@ struct FixedPositionContainer_test : public Test using Sut = FixedPositionContainer; using ComplexType = LifetimeAndAssignmentTracker; + using NonCopyType = MovableButNonCopyableTestClass; + using SutComplex = FixedPositionContainer; + using SutNonCopy = FixedPositionContainer; void SetUp() override { @@ -69,6 +104,7 @@ struct FixedPositionContainer_test : public Test Sut sut; SutComplex sut_complex; + SutNonCopy sut_noncopy; ComplexType::Statistics& stats = ComplexType::stats; }; @@ -291,6 +327,19 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromFullCapacityContainerClears EXPECT_THAT(sut_complex.empty(), Eq(true)); } +TEST_F(FixedPositionContainer_test, UsingMoveCtorAtNonCopyableTypeShouldCompile) +{ + ::testing::Test::RecordProperty("TEST_ID", "e1cc7c9f-c1b5-4047-811b-004302af5c00"); + + constexpr uint64_t EXPECTED_SIZE{2U}; + sut_noncopy.emplace(7U); + sut_noncopy.emplace(8U); + + SutNonCopy move_sut_noncopy{std::move(sut_noncopy)}; + + EXPECT_THAT(move_sut_noncopy.size(), Eq(EXPECTED_SIZE)); +} + // END test move constructor // BEGIN test copy assignment From 0fd8af5d8f6fa3a6f164df43eada68866b80d4ca Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sun, 5 Nov 2023 01:23:19 +0800 Subject: [PATCH 14/85] iox-#2052 Add missing tests Signed-off-by: Dennis Liu Based on the discussion at [https://github.com/eclipse-iceoryx/iceoryx/pull/2069#discussion_r1375494670], additional tests have been incorporated. Furthermore, some statistical results have been updated due to modifications in the `copy_and_move_impl`. For instance, when a non-empty container is moved to an empty container using the move assignment, the `MoveCtor` is the function that is invoked, not the `operator=`. This is because if the slot was previously free, we utilize placement new to ensure proper functionality. Consequently, it is the `MoveCtor` that gets called." --- ...est_container_fixed_position_container.cpp | 1321 +++++++++++++++-- 1 file changed, 1228 insertions(+), 93 deletions(-) diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index 115d628040..643ac4bd00 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -159,8 +159,9 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorSingleElementContainerPreserves EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); EXPECT_THAT(copy_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); - // actually call copyAssignment - EXPECT_THAT(stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveCTor, Eq(0)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); EXPECT_THAT(stats.moveAssignment, Eq(0)); } @@ -186,8 +187,9 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorMultipleElementsContainerPreser EXPECT_THAT(copy_sut_complex.iter_from_index(i), Ne(sut_complex.iter_from_index(i))); } - // actually call copyAssignment - EXPECT_THAT(stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveCTor, Eq(0)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); EXPECT_THAT(stats.moveAssignment, Eq(0)); } @@ -209,17 +211,79 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorFullCapacityContainerPreservesA EXPECT_THAT(copy_sut_complex.iter_from_index(i), Ne(sut_complex.iter_from_index(i))); } - // actually call copyAssignment - EXPECT_THAT(stats.copyAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveCTor, Eq(0)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); EXPECT_THAT(stats.moveAssignment, Eq(0)); } -TEST_F(FixedPositionContainer_test, UsingCopyCtorFromNonEmptyContainerCopyToEmptyContainer) +TEST_F(FixedPositionContainer_test, UsingCopyCtorFromNonEmptyWithFirstIndexErasedToEmptyContainer) { - ::testing::Test::RecordProperty("TEST_ID", "f7e142f3-e236-46f7-82df-52624cb95094"); + ::testing::Test::RecordProperty("TEST_ID", "acd52957-1d8a-4bd8-a960-e9c040d919c2"); - constexpr DataType EXPECTED_VALUE{42U}; - constexpr SutComplex::IndexType EXPECTED_SIZE{1U}; + std::vector EXPECTED_VALUE = {63U, 64U, 65U, 66U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{3U}; + + for (const auto& value : EXPECTED_VALUE) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + + SutComplex copy_sut_complex{sut_complex}; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_EQ(copy_sut_complex.size(), EXPECTED_SIZE); + EXPECT_EQ(copy_sut_complex.begin()->value, 64U); +} + +TEST_F(FixedPositionContainer_test, UsingCopyCtorFromNonEmptyWithFirstAndMiddleAndLastErasedToEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "f21ff6d9-f50a-499f-912a-923bd4273b07"); + + std::vector EXPECTED_VALUE = {1U, 2U, 3U, 5U, 6U, 7U, 8U}; + + fillSutComplex(); + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST); + sut_complex.erase(SutComplex::Index::LAST / 2); + + SutComplex copy_sut_complex{sut_complex}; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(CAPACITY - 3U)); + + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } +} + +TEST_F(FixedPositionContainer_test, UsingCopyCtorWillNotChangeSourceContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "8d60e04b-341f-4da1-8f3e-2736529d7843"); + + std::vector EXPECTED_VALUE = {63U, 64U, 65U, 66U}; + constexpr uint64_t EXPECTED_SIZE{4U}; + for (const auto& value : EXPECTED_VALUE) + { + sut_complex.emplace(value); + } + + SutComplex copy_sut_complex{sut_complex}; + + EXPECT_THAT(sut_complex.size(), Eq(EXPECTED_SIZE)); + + auto it = sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } } // END test copy constructor @@ -239,7 +303,7 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromEmptyContainerResultsInEmpt EXPECT_THAT(sut_complex.empty(), Eq(true)); } -TEST_F(FixedPositionContainer_test, UsingMoveCtorFromSingleElementContainerClearsOriginal) +TEST_F(FixedPositionContainer_test, UsingMoveCtorFromSingleElementToEmptyContainerClearsOriginal) { ::testing::Test::RecordProperty("TEST_ID", "df6c1884-43c6-4d1e-b889-6cbf4b9ee726"); @@ -254,8 +318,9 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromSingleElementContainerClear EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); EXPECT_THAT(move_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); - // actually call moveAssignment - EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyCTor, Eq(0)); + EXPECT_THAT(stats.moveCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); EXPECT_THAT(stats.copyAssignment, Eq(0)); // make sure clear() been called EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); @@ -287,8 +352,9 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromMultipleElementsContainerCl EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } - // actually call moveAssignment - EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyCTor, Eq(0)); + EXPECT_THAT(stats.moveCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); EXPECT_THAT(stats.copyAssignment, Eq(0)); // make sure clear() been called EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); @@ -318,8 +384,9 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromFullCapacityContainerClears EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); } - // actually call moveAssignment - EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.copyCTor, Eq(0)); + EXPECT_THAT(stats.moveCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); EXPECT_THAT(stats.copyAssignment, Eq(0)); // make sure clear() been called EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); @@ -327,6 +394,56 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromFullCapacityContainerClears EXPECT_THAT(sut_complex.empty(), Eq(true)); } +TEST_F(FixedPositionContainer_test, UsingMoveCtorFromNonEmptyWithFirstIndexErasedToEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "de0eaa3c-bf30-4899-95ec-6c23bbd53a24"); + + std::vector EXPECTED_VALUE = {63U, 64U, 65U, 66U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{3U}; + + for (const auto& value : EXPECTED_VALUE) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + + SutComplex move_sut_complex{std::move(sut_complex)}; + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.begin()->value, Eq(64U)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveCtorFromNonEmptyWithFirstAndMiddleAndLastErasedToEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "073e3bc6-1e33-46b8-860b-c35d1f599d11"); + + std::vector EXPECTED_VALUE = {1U, 2U, 3U, 5U, 6U, 7U, 8U}; + + fillSutComplex(); + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST); + sut_complex.erase(SutComplex::Index::LAST / 2); + + SutComplex copy_sut_complex{std::move(sut_complex)}; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(CAPACITY - 3U)); + + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + TEST_F(FixedPositionContainer_test, UsingMoveCtorAtNonCopyableTypeShouldCompile) { ::testing::Test::RecordProperty("TEST_ID", "e1cc7c9f-c1b5-4047-811b-004302af5c00"); @@ -356,30 +473,34 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromEmptyContainerResults EXPECT_THAT(copy_sut_complex.size(), Eq(0)); } -TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromSingleElementContainerClearsOriginal) +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromSingleElementContainer) { ::testing::Test::RecordProperty("TEST_ID", "6cf9e9d1-91a9-4403-a25a-52b64dd523be"); constexpr DataType EXPECTED_VALUE{42U}; + constexpr uint64_t EXPECTED_SIZE{1U}; sut_complex.emplace(EXPECTED_VALUE); SutComplex copy_sut_complex; copy_sut_complex = sut_complex; - EXPECT_THAT(stats.copyAssignment, Eq(sut_complex.size())); - EXPECT_THAT(stats.moveAssignment, Eq(0)); - EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(sut_complex.size())); EXPECT_THAT(copy_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); + + EXPECT_THAT(stats.copyCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveCTor, Eq(0)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); } -TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromMultipleElementsContainerClearsOriginal) +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromMultipleElementsContainer) { ::testing::Test::RecordProperty("TEST_ID", "262ad71a-0ee2-4661-b2c8-a3cca9c1cf5e"); std::vector EXPECTED_VALUE{56U, 57U, 58U, 59U}; + constexpr uint64_t EXPECTED_SIZE{4U}; for (SutComplex::IndexType i = 0; i < EXPECTED_VALUE.size(); ++i) { sut_complex.emplace(EXPECTED_VALUE[i]); @@ -388,9 +509,6 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromMultipleElementsConta SutComplex copy_sut_complex; copy_sut_complex = sut_complex; - EXPECT_THAT(stats.copyAssignment, Eq(sut_complex.size())); - EXPECT_THAT(stats.moveAssignment, Eq(0)); - EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(sut_complex.size())); @@ -399,9 +517,14 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromMultipleElementsConta EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); EXPECT_THAT(copy_sut_complex.iter_from_index(i), Ne(sut_complex.iter_from_index(i))); } + + EXPECT_THAT(stats.copyCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveCTor, Eq(0)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); } -TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromFullCapacityContainerClearsOriginal) +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromFullCapacityContainer) { ::testing::Test::RecordProperty("TEST_ID", "b46d0be7-5977-467e-adc4-2e9adc554fdd"); @@ -416,9 +539,6 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromFullCapacityContainer SutComplex copy_sut_complex; copy_sut_complex = sut_complex; - EXPECT_THAT(stats.copyAssignment, Eq(EXPECTED_SIZE)); - EXPECT_THAT(stats.moveAssignment, Eq(0)); - EXPECT_THAT(copy_sut_complex.full(), Eq(true)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); @@ -427,111 +547,1126 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromFullCapacityContainer EXPECT_THAT(copy_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); EXPECT_THAT(copy_sut_complex.iter_from_index(i), Ne(sut_complex.iter_from_index(i))); } + + EXPECT_THAT(stats.copyCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveCTor, Eq(0)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); } -// END test copy assignment +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromEmptyToNonEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "5d906d20-aacc-4536-86e7-bd4aafcdc2f7"); -// BEGIN test move assignment + std::vector EXPECTED_VALUE = {12U, 13U, 14U, 15U, 16U}; + SutComplex copy_sut_complex; + for (const auto& value : EXPECTED_VALUE) + { + copy_sut_complex.emplace(value); + } -TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromEmptyContainerResultsInEmptyContainer) + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(0)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(true)); + EXPECT_THAT(copy_sut_complex.size(), Eq(0)); +} + +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromLargerSizeToSmallerSizeContainer) { - ::testing::Test::RecordProperty("TEST_ID", "711ced12-4b93-47d1-af37-cace03fac2c1"); + ::testing::Test::RecordProperty("TEST_ID", "cce5bca5-7bfd-4909-bd60-acfffbb1611e"); - SutComplex move_sut_complex; - move_sut_complex = std::move(sut_complex); + std::vector EXPECTED_VALUE = {21U, 22U, 23U, 24U, 25U}; + std::vector DUMMY_VALUE = {94U, 95U, 96U}; + constexpr uint64_t EXPECTED_SIZE{5U}; - EXPECT_THAT(move_sut_complex.full(), Eq(false)); - EXPECT_THAT(move_sut_complex.empty(), Eq(true)); - EXPECT_THAT(move_sut_complex.size(), Eq(0)); + SutComplex copy_sut_complex; + for (const auto& value : EXPECTED_VALUE) + { + sut_complex.emplace(value); + } + for (const auto& value : DUMMY_VALUE) + { + copy_sut_complex.emplace(value); + } - EXPECT_THAT(sut_complex.empty(), Eq(true)); + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } } -TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromSingleElementContainerClearsOriginal) +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentBetweenContainersOfEqalSize) { - ::testing::Test::RecordProperty("TEST_ID", "a3902afc-5eba-4e10-8412-f09b7b5d17b8"); + ::testing::Test::RecordProperty("TEST_ID", "bd1b1c4b-20a4-464a-b036-8ce4764f3ac5"); - constexpr DataType EXPECTED_VALUE{42U}; - constexpr SutComplex::IndexType EXPECTED_SIZE{1U}; - sut_complex.emplace(EXPECTED_VALUE); - - SutComplex move_sut_complex; - move_sut_complex = std::move(sut_complex); + std::vector EXPECTED_VALUE = {29U, 28U, 27U, 26U}; + std::vector DUMMY_VALUE = {37U, 38U, 39U, 40U}; + constexpr uint64_t EXPECTED_SIZE{4U}; - EXPECT_THAT(move_sut_complex.full(), Eq(false)); - EXPECT_THAT(move_sut_complex.empty(), Eq(false)); - EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); - EXPECT_THAT(move_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); + SutComplex copy_sut_complex; + for (const auto& value : EXPECTED_VALUE) + { + sut_complex.emplace(value); + } + for (const auto& value : DUMMY_VALUE) + { + copy_sut_complex.emplace(value); + } - EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); - EXPECT_THAT(stats.copyAssignment, Eq(0)); - // make sure clear() been called - EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + copy_sut_complex = sut_complex; - EXPECT_THAT(sut_complex.empty(), Eq(true)); + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } } -TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromMultipleElementsContainerClearsOriginal) +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromSmallerSizeToLargerSizeContainer) { - ::testing::Test::RecordProperty("TEST_ID", "c44da583-1ed8-4c83-b5bb-dba5d64b21d9"); + ::testing::Test::RecordProperty("TEST_ID", "412b4439-66dd-4e5c-93f7-511e1e965b78"); - std::vector EXPECTED_VALUE{56U, 57U, 58U, 59U}; - constexpr SutComplex::IndexType EXPECTED_SIZE{4U}; - for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) + std::vector EXPECTED_VALUE = {1U, 2U, 3U, 4U}; + std::vector DUMMY_VALUE = {31U, 32U, 33U, 34U, 35U, 36U, 37U}; + constexpr uint64_t EXPECTED_SIZE{4U}; + + SutComplex copy_sut_complex; + for (const auto& value : EXPECTED_VALUE) { - sut_complex.emplace(EXPECTED_VALUE[i]); + sut_complex.emplace(value); + } + for (const auto& value : DUMMY_VALUE) + { + copy_sut_complex.emplace(value); } - SutComplex move_sut_complex; - move_sut_complex = std::move(sut_complex); + copy_sut_complex = sut_complex; - EXPECT_THAT(move_sut_complex.full(), Eq(false)); - EXPECT_THAT(move_sut_complex.empty(), Eq(false)); - EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); - for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) { - EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); + EXPECT_THAT(it->value, Eq(value)); + ++it; } +} - EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); - EXPECT_THAT(stats.copyAssignment, Eq(0)); - // make sure clear() been called - EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithFirstIndexErasedToEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "929e7bae-f276-4ae5-b559-7bb518198e63"); - EXPECT_THAT(sut_complex.empty(), Eq(true)); + std::vector DUMMY_VALUE = {12U, 32U, 23U, 14U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE.begin() + 1, DUMMY_VALUE.end()); + constexpr uint64_t EXPECTED_SIZE{3U}; + + for (const auto& value : DUMMY_VALUE) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + + SutComplex copy_sut_complex; + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } } -TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromFullCapacityContainerClearsOriginal) +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithFirstIndexErasedToNonEmptyContainer) { - ::testing::Test::RecordProperty("TEST_ID", "3196b101-f03a-4029-abb8-77106f0b45d8"); + ::testing::Test::RecordProperty("TEST_ID", "cd882c6e-1e46-495c-b2cf-24056c144d85"); - fillSutComplex(); - constexpr SutComplex::IndexType EXPECTED_SIZE{CAPACITY}; - std::vector EXPECTED_VALUE; - for (const auto& item : sut_complex) + std::vector DUMMY_VALUE_SRC = {65U, 66U, 23U, 7U, 12U}; + std::vector DUMMY_VALUE_DEST = {1U, 3U, 5U, 16U, 18U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE_SRC.begin() + 1, DUMMY_VALUE_SRC.end()); + constexpr uint64_t EXPECTED_SIZE{4U}; + + for (const auto& value : DUMMY_VALUE_SRC) { - EXPECTED_VALUE.emplace_back(item.value); + sut_complex.emplace(value); } + sut_complex.erase(SutComplex::Index::FIRST); - SutComplex move_sut_complex; - move_sut_complex = std::move(sut_complex); + SutComplex copy_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + copy_sut_complex.emplace(value); + } - EXPECT_THAT(move_sut_complex.full(), Eq(true)); - EXPECT_THAT(move_sut_complex.empty(), Eq(false)); - EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); - for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) { - EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); + EXPECT_THAT(it->value, Eq(value)); + ++it; } +} - EXPECT_THAT(stats.moveAssignment, Eq(EXPECTED_SIZE)); - EXPECT_THAT(stats.copyAssignment, Eq(0)); - // make sure clear() been called - EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyToNonEmptyContainerWithBothFirstIndexErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "ad3d96da-e64a-4252-950c-a36f5333e42a"); - EXPECT_THAT(sut_complex.empty(), Eq(true)); + std::vector DUMMY_VALUE_SRC = {98U, 99U, 100U, 101U, 102U, 103U}; + std::vector DUMMY_VALUE_DEST = {12U, 33U, 544U, 162U, 182U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE_SRC.begin() + 1, DUMMY_VALUE_SRC.end()); + constexpr uint64_t EXPECTED_SIZE{5U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + + SutComplex copy_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + copy_sut_complex.emplace(value); + } + copy_sut_complex.erase(SutComplex::Index::FIRST); + + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } } +TEST_F(FixedPositionContainer_test, + UsingCopyAssignmentFromNonEmptyWithFirstErasedToNonEmptyContainerWithFirstAndSecondErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "a3ac8e6d-795e-4e41-bad3-aba39483d6d5"); + + std::vector DUMMY_VALUE_SRC = {56U, 54U, 55U, 33U, 12U, 34U}; + std::vector DUMMY_VALUE_DEST = {18U, 22U, 42U, 323U, 216U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE_SRC.begin() + 1, DUMMY_VALUE_SRC.end()); + constexpr uint64_t EXPECTED_SIZE{5U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + + SutComplex copy_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + copy_sut_complex.emplace(value); + } + copy_sut_complex.erase(SutComplex::Index::FIRST); + copy_sut_complex.erase(SutComplex::Index::FIRST + 1); + + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } +} + +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithFirstAndMiddleAndLastErasedToEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "0c6138ce-861e-42d8-b7f2-ecd4ac01537e"); + + std::vector DUMMY_VALUE = {17U, 26U, 32U, 357U, 30U, 21U, 18U, 100U, 67U, 79U}; + std::vector EXPECTED_VALUE = {26U, 32U, 357U, 21U, 18U, 100U, 67U}; + constexpr uint64_t EXPECTED_SIZE{7U}; + + for (const auto& value : DUMMY_VALUE) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST / 2); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex copy_sut_complex; + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } +} + +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithFirstAndMiddleAndLastErasedToNonEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "4127ad54-f272-4f61-9737-e41b92d7cf60"); + + std::vector DUMMY_VALUE_SRC = {111U, 112U, 113U, 114U, 115U, 116U, 117U, 118U, 119U, 120U}; + std::vector DUMMY_VALUE_DEST = {189U, 112U, 124U, 1735U, 10U, 11U, 14U, 164U, 123U, 12U}; + std::vector EXPECTED_VALUE = {112U, 113U, 114U, 116U, 117U, 118U, 119U}; + constexpr uint64_t EXPECTED_SIZE{7U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST / 2); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex copy_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + copy_sut_complex.emplace(value); + } + + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } +} + +TEST_F(FixedPositionContainer_test, + UsingCopyAssignmentFromNonEmptyWithFirstAndMiddleAndLastErasedToNonEmptyContainerWithFirstIndexErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "4aea0c73-98c7-45b1-81e0-713c18ea16de"); + + std::vector DUMMY_VALUE_SRC = {101U, 102U, 103U, 104U, 105U, 106U, 107U, 108U, 109U, 110U}; + std::vector DUMMY_VALUE_DEST = {89U, 12U, 24U, 735U, 0U, 1U, 4U, 64U, 23U, 2U}; + std::vector EXPECTED_VALUE = {102U, 103U, 104U, 106U, 107U, 108U, 109U}; + constexpr uint64_t EXPECTED_SIZE{7U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST / 2); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex copy_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + copy_sut_complex.emplace(value); + } + copy_sut_complex.erase(SutComplex::Index::FIRST); + + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } +} + +TEST_F( + FixedPositionContainer_test, + UsingCopyAssignmentFromNonEmptyWithFirstAndMiddleAndLastErasedToNonEmptyContainerWithNeighboringFirstAndOneBeforeMiddleAndOneBeforeLastErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "7e086470-8b0e-4c82-8c5d-7a9c45312729"); + + std::vector DUMMY_VALUE_SRC = {121U, 122U, 123U, 124U, 125U, 126U, 127U, 128U, 129U, 130U}; + std::vector DUMMY_VALUE_DEST = {79U, 2U, 14U, 725U, 40U, 15U, 34U, 54U, 13U, 32U}; + std::vector EXPECTED_VALUE = {122U, 123U, 124U, 126U, 127U, 128U, 129U}; + constexpr uint64_t EXPECTED_SIZE{7U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST / 2); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex copy_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + copy_sut_complex.emplace(value); + } + copy_sut_complex.erase(SutComplex::Index::FIRST + 1); + copy_sut_complex.erase(SutComplex::Index::LAST / 2 + 1); + copy_sut_complex.erase(SutComplex::Index::LAST - 1); + + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } +} + +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithLastErasedToFullContainerWithFirstErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "82e562f9-89fe-4998-870f-c575da5a3f79"); + + std::vector DUMMY_VALUE_SRC = {131U, 132U, 133U, 134U, 135U, 136U, 137U, 138U, 139U, 140U}; + std::vector DUMMY_VALUE_DEST = {23U, 24U, 25U, 26U, 27U, 28U, 29U, 30U, 31U, 32U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE_SRC.begin(), DUMMY_VALUE_SRC.end() - 1); + constexpr uint64_t EXPECTED_SIZE{9U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex copy_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + copy_sut_complex.emplace(value); + } + copy_sut_complex.erase(SutComplex::Index::FIRST); + + copy_sut_complex = sut_complex; + + EXPECT_THAT(copy_sut_complex.full(), Eq(false)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } +} + +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentWillNotChangeSourceContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "22191ca0-2350-4901-b6f3-1786621f6a17"); + + std::vector EXPECTED_VALUE = {63U, 64U, 65U, 66U}; + constexpr uint64_t EXPECTED_SIZE{4U}; + for (const auto& value : EXPECTED_VALUE) + { + sut_complex.emplace(value); + } + + SutComplex copy_sut_complex; + copy_sut_complex = sut_complex; + + EXPECT_THAT(sut_complex.size(), Eq(EXPECTED_SIZE)); + + auto it = sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } +} + +TEST_F(FixedPositionContainer_test, UsingCopyAssignmentInsertionShouldFailWhenCapacityReached) +{ + ::testing::Test::RecordProperty("TEST_ID", "fcbe01f1-b3d4-4794-b291-efeeddd4db7f"); + + std::vector DUMMY_VALUE_SRC = {131U, 132U, 133U, 134U, 135U, 136U, 137U, 138U, 139U, 140U}; + std::vector DUMMY_VALUE_DEST = {23U, 24U, 25U, 26U, 27U, 28U, 29U, 30U, 31U, 32U}; + std::vector EXPECTED_VALUE = {132U, 133U, 134U, 135U, 136U, 137U, 138U, 139U, 77U, 88U}; + constexpr uint64_t EXPECTED_SIZE{CAPACITY}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex copy_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + copy_sut_complex.emplace(value); + } + + copy_sut_complex = sut_complex; + + copy_sut_complex.emplace(77U); + copy_sut_complex.emplace(88U); + + EXPECT_THAT(copy_sut_complex.full(), Eq(true)); + EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); + EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + // should failed + auto failed_it = copy_sut_complex.emplace(1000000U); + EXPECT_THAT(failed_it, Eq(copy_sut_complex.end())); +} + +// END test copy assignment + +// BEGIN test move assignment + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromEmptyContainerResultsInEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "711ced12-4b93-47d1-af37-cace03fac2c1"); + + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(true)); + EXPECT_THAT(move_sut_complex.size(), Eq(0)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromSingleElementContainerClearsOriginal) +{ + ::testing::Test::RecordProperty("TEST_ID", "a3902afc-5eba-4e10-8412-f09b7b5d17b8"); + + constexpr DataType EXPECTED_VALUE{42U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{1U}; + sut_complex.emplace(EXPECTED_VALUE); + + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + EXPECT_THAT(move_sut_complex.begin()->value, Eq(EXPECTED_VALUE)); + + EXPECT_THAT(stats.copyCTor, Eq(0)); + EXPECT_THAT(stats.moveCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); + EXPECT_THAT(stats.copyAssignment, Eq(0)); + // make sure clear() been called + EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromMultipleElementsContainerClearsOriginal) +{ + ::testing::Test::RecordProperty("TEST_ID", "c44da583-1ed8-4c83-b5bb-dba5d64b21d9"); + + std::vector EXPECTED_VALUE{56U, 57U, 58U, 59U}; + constexpr SutComplex::IndexType EXPECTED_SIZE{4U}; + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) + { + sut_complex.emplace(EXPECTED_VALUE[i]); + } + + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) + { + EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); + } + + EXPECT_THAT(stats.copyCTor, Eq(0)); + EXPECT_THAT(stats.moveCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); + // make sure clear() been called + EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromFullCapacityContainerClearsOriginal) +{ + ::testing::Test::RecordProperty("TEST_ID", "3196b101-f03a-4029-abb8-77106f0b45d8"); + + fillSutComplex(); + constexpr SutComplex::IndexType EXPECTED_SIZE{CAPACITY}; + std::vector EXPECTED_VALUE; + for (const auto& item : sut_complex) + { + EXPECTED_VALUE.emplace_back(item.value); + } + + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(true)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + for (SutComplex::IndexType i = 0; i < EXPECTED_SIZE; ++i) + { + EXPECT_THAT(move_sut_complex.iter_from_index(i)->value, Eq(EXPECTED_VALUE[i])); + } + + EXPECT_THAT(stats.copyCTor, Eq(0)); + EXPECT_THAT(stats.moveCTor, Eq(EXPECTED_SIZE)); + EXPECT_THAT(stats.moveAssignment, Eq(0)); + // make sure clear() been called + EXPECT_THAT(stats.dTor, Eq(EXPECTED_SIZE)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromEmptyToNonEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "998e06c0-6879-451e-a493-e3e26944feff"); + + std::vector EXPECTED_VALUE = {12U, 13U, 14U, 15U, 16U}; + SutComplex move_sut_complex; + for (const auto& value : EXPECTED_VALUE) + { + move_sut_complex.emplace(value); + } + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(0)); + EXPECT_THAT(move_sut_complex.empty(), Eq(true)); + EXPECT_THAT(move_sut_complex.size(), Eq(0)); + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromLargerSizeToSmallerSizeContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "c4b5b538-740f-4543-b493-5ea87e0ea8cc"); + + std::vector EXPECTED_VALUE = {21U, 22U, 23U, 24U, 25U}; + std::vector DUMMY_VALUE = {94U, 95U, 96U}; + constexpr uint64_t EXPECTED_SIZE{5U}; + + SutComplex move_sut_complex; + for (const auto& value : EXPECTED_VALUE) + { + sut_complex.emplace(value); + } + for (const auto& value : DUMMY_VALUE) + { + move_sut_complex.emplace(value); + } + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentBetweenContainersOfEqalSize) +{ + ::testing::Test::RecordProperty("TEST_ID", "50030f15-aefc-4086-aca0-02c1d5e032a1"); + + std::vector EXPECTED_VALUE = {29U, 28U, 27U, 26U}; + std::vector DUMMY_VALUE = {37U, 38U, 39U, 40U}; + constexpr uint64_t EXPECTED_SIZE{4U}; + + SutComplex move_sut_complex; + for (const auto& value : EXPECTED_VALUE) + { + sut_complex.emplace(value); + } + for (const auto& value : DUMMY_VALUE) + { + move_sut_complex.emplace(value); + } + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromSmallerSizeToLargerSizeContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "6759de7f-5555-4251-89a2-dbcc3c2f2efb"); + + std::vector EXPECTED_VALUE = {1U, 2U, 3U, 4U}; + std::vector DUMMY_VALUE = {31U, 32U, 33U, 34U, 35U, 36U, 37U}; + constexpr uint64_t EXPECTED_SIZE{4U}; + + SutComplex move_sut_complex; + for (const auto& value : EXPECTED_VALUE) + { + sut_complex.emplace(value); + } + for (const auto& value : DUMMY_VALUE) + { + move_sut_complex.emplace(value); + } + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromNonEmptyWithFirstIndexErasedToEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "95c1839b-0755-458c-908b-89b59a914fb5"); + + std::vector DUMMY_VALUE = {12U, 32U, 23U, 14U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE.begin() + 1, DUMMY_VALUE.end()); + constexpr uint64_t EXPECTED_SIZE{3U}; + + for (const auto& value : DUMMY_VALUE) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromNonEmptyWithFirstIndexErasedToNonEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "db50dd57-6e56-4343-981b-debb4780d403"); + + std::vector DUMMY_VALUE_SRC = {65U, 66U, 23U, 7U, 12U}; + std::vector DUMMY_VALUE_DEST = {1U, 3U, 5U, 16U, 18U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE_SRC.begin() + 1, DUMMY_VALUE_SRC.end()); + constexpr uint64_t EXPECTED_SIZE{4U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + + SutComplex move_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + move_sut_complex.emplace(value); + } + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromNonEmptyToNonEmptyContainerWithBothFirstIndexErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "2655d41e-06d9-4e85-a356-a0ba256b35ee"); + + std::vector DUMMY_VALUE_SRC = {98U, 99U, 100U, 101U, 102U, 103U}; + std::vector DUMMY_VALUE_DEST = {12U, 33U, 544U, 162U, 182U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE_SRC.begin() + 1, DUMMY_VALUE_SRC.end()); + constexpr uint64_t EXPECTED_SIZE{5U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + + SutComplex move_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + move_sut_complex.emplace(value); + } + move_sut_complex.erase(SutComplex::Index::FIRST); + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, + UsingMoveAssignmentFromNonEmptyWithFirstErasedToNonEmptyContainerWithFirstAndSecondErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "8aa4a221-ed52-49e9-91c3-81d45d70edc5"); + + std::vector DUMMY_VALUE_SRC = {56U, 54U, 55U, 33U, 12U, 34U}; + std::vector DUMMY_VALUE_DEST = {18U, 22U, 42U, 323U, 216U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE_SRC.begin() + 1, DUMMY_VALUE_SRC.end()); + constexpr uint64_t EXPECTED_SIZE{5U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + + SutComplex move_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + move_sut_complex.emplace(value); + } + move_sut_complex.erase(SutComplex::Index::FIRST); + move_sut_complex.erase(SutComplex::Index::FIRST + 1); + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromNonEmptyWithFirstAndMiddleAndLastErasedToEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "646d08e5-d26a-4efe-96e1-fa79ef1549b7"); + + std::vector DUMMY_VALUE = {17U, 26U, 32U, 357U, 30U, 21U, 18U, 100U, 67U, 79U}; + std::vector EXPECTED_VALUE = {26U, 32U, 357U, 21U, 18U, 100U, 67U}; + constexpr uint64_t EXPECTED_SIZE{7U}; + + for (const auto& value : DUMMY_VALUE) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST / 2); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromNonEmptyWithFirstAndMiddleAndLastErasedToNonEmptyContainer) +{ + ::testing::Test::RecordProperty("TEST_ID", "62367ed3-a97a-4dae-82f3-e7bacd432b9b"); + + std::vector DUMMY_VALUE_SRC = {111U, 112U, 113U, 114U, 115U, 116U, 117U, 118U, 119U, 120U}; + std::vector DUMMY_VALUE_DEST = {189U, 112U, 124U, 1735U, 10U, 11U, 14U, 164U, 123U, 12U}; + std::vector EXPECTED_VALUE = {112U, 113U, 114U, 116U, 117U, 118U, 119U}; + constexpr uint64_t EXPECTED_SIZE{7U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST / 2); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex move_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + move_sut_complex.emplace(value); + } + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, + UsingMoveAssignmentFromNonEmptyWithFirstAndMiddleAndLastErasedToNonEmptyContainerWithFirstIndexErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "3b57f4cc-7a79-4a0a-a1f2-0a2f1e943fdf"); + + std::vector DUMMY_VALUE_SRC = {101U, 102U, 103U, 104U, 105U, 106U, 107U, 108U, 109U, 110U}; + std::vector DUMMY_VALUE_DEST = {89U, 12U, 24U, 735U, 0U, 1U, 4U, 64U, 23U, 2U}; + std::vector EXPECTED_VALUE = {102U, 103U, 104U, 106U, 107U, 108U, 109U}; + constexpr uint64_t EXPECTED_SIZE{7U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST / 2); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex move_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + move_sut_complex.emplace(value); + } + move_sut_complex.erase(SutComplex::Index::FIRST); + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F( + FixedPositionContainer_test, + UsingMoveAssignmentFromNonEmptyWithFirstAndMiddleAndLastErasedToNonEmptyContainerWithNeighboringFirstAndOneBeforeMiddleAndOneBeforeLastErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "74cf9827-99ea-45a8-884d-e8efff9b1290"); + + std::vector DUMMY_VALUE_SRC = {121U, 122U, 123U, 124U, 125U, 126U, 127U, 128U, 129U, 130U}; + std::vector DUMMY_VALUE_DEST = {79U, 2U, 14U, 725U, 40U, 15U, 34U, 54U, 13U, 32U}; + std::vector EXPECTED_VALUE = {122U, 123U, 124U, 126U, 127U, 128U, 129U}; + constexpr uint64_t EXPECTED_SIZE{7U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST / 2); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex move_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + move_sut_complex.emplace(value); + } + move_sut_complex.erase(SutComplex::Index::FIRST + 1); + move_sut_complex.erase(SutComplex::Index::LAST / 2 + 1); + move_sut_complex.erase(SutComplex::Index::LAST - 1); + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromNonEmptyWithLastErasedToFullContainerWithFirstErased) +{ + ::testing::Test::RecordProperty("TEST_ID", "ca8b489c-c24d-478e-8720-f265687209ea"); + + std::vector DUMMY_VALUE_SRC = {131U, 132U, 133U, 134U, 135U, 136U, 137U, 138U, 139U, 140U}; + std::vector DUMMY_VALUE_DEST = {23U, 24U, 25U, 26U, 27U, 28U, 29U, 30U, 31U, 32U}; + std::vector EXPECTED_VALUE(DUMMY_VALUE_SRC.begin(), DUMMY_VALUE_SRC.end() - 1); + constexpr uint64_t EXPECTED_SIZE{9U}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex move_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + move_sut_complex.emplace(value); + } + move_sut_complex.erase(SutComplex::Index::FIRST); + + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(move_sut_complex.full(), Eq(false)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentInsertionShouldFailWhenCapacityReached) +{ + ::testing::Test::RecordProperty("TEST_ID", "ad438f8a-2b9e-45d3-8d89-feefbccf3f03"); + + std::vector DUMMY_VALUE_SRC = {131U, 132U, 133U, 134U, 135U, 136U, 137U, 138U, 139U, 140U}; + std::vector DUMMY_VALUE_DEST = {23U, 24U, 25U, 26U, 27U, 28U, 29U, 30U, 31U, 32U}; + std::vector EXPECTED_VALUE = {132U, 133U, 134U, 135U, 136U, 137U, 138U, 139U, 77U, 88U}; + constexpr uint64_t EXPECTED_SIZE{CAPACITY}; + + for (const auto& value : DUMMY_VALUE_SRC) + { + sut_complex.emplace(value); + } + sut_complex.erase(SutComplex::Index::FIRST); + sut_complex.erase(SutComplex::Index::LAST); + + SutComplex move_sut_complex; + for (const auto& value : DUMMY_VALUE_DEST) + { + move_sut_complex.emplace(value); + } + + move_sut_complex = std::move(sut_complex); + + move_sut_complex.emplace(77U); + move_sut_complex.emplace(88U); + + EXPECT_THAT(move_sut_complex.full(), Eq(true)); + EXPECT_THAT(move_sut_complex.empty(), Eq(false)); + EXPECT_THAT(move_sut_complex.size(), Eq(EXPECTED_SIZE)); + auto it = move_sut_complex.iter_from_index(SutComplex::Index::FIRST); + for (const auto& value : EXPECTED_VALUE) + { + EXPECT_THAT(it->value, Eq(value)); + ++it; + } + + EXPECT_THAT(sut_complex.empty(), Eq(true)); + + // should failed + auto failed_it = move_sut_complex.emplace(1000000U); + EXPECT_THAT(failed_it, Eq(move_sut_complex.end())); +} + +TEST_F(FixedPositionContainer_test, UsingMoveAssignmentAtNonCopyableTypeShouldCompile) +{ + ::testing::Test::RecordProperty("TEST_ID", "d4876d02-d855-4bcc-af39-3d2dc388c40d"); + + constexpr uint64_t EXPECTED_SIZE{2U}; + sut_noncopy.emplace(7U); + sut_noncopy.emplace(8U); + + SutNonCopy move_sut_noncopy; + move_sut_noncopy = std::move(sut_noncopy); + + EXPECT_THAT(move_sut_noncopy.size(), Eq(EXPECTED_SIZE)); +} + +///////////////////////////////////////////////////////// + // END test move assignment // BEGIN test empty From 461bf5c4b12045ec002f29ba4b69b8805ea77a77 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sun, 5 Nov 2023 01:37:06 +0800 Subject: [PATCH 15/85] iox-#2052 Fix member variable update logic Signed-off-by: Dennis Liu This commit aims to fix that incorrect member such as `m_begin_free` and `m_begin_used` might cause unexpected erase error (usually terminate at line 515). Hence, the member will be updated after all data are moved or copied into `this` container, ensuring free list and used list return to normal status(not broke by copy or move). Then, `erase` can be called safely. Finally, the correct information from rhs will be assigned to member at the bottom of `copy_and_move_impl`. --- .../iox/detail/fixed_position_container.inl | 51 ++++++++++++++++--- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index 418339df9b..f890fefc6d 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -100,10 +100,19 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh && std::is_const>::value), "RhsType must be const lvalue reference or rvalue reference"); - IndexType i = Index::FIRST; - auto rhs_it = (std::forward(rhs)).begin(); constexpr bool is_move = std::is_rvalue_reference::value; + IndexType i{Index::FIRST}; + + // this can update member faster + IndexType next_used_cache{Index::INVALID}; + IndexType next_free_cache{Index::INVALID}; + bool overwrite_used_slot{false}; + bool overwrite_free_slot{true}; + + auto rhs_it = (std::forward(rhs)).begin(); + + // transfer src data to destination for (; rhs_it.to_index() != Index::INVALID; ++i, ++rhs_it) { @@ -126,10 +135,13 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh // in fixed_position_container.hpp) can be eliminated. AssignmentHelper::assign(m_data[i], MoveHelper::move_or_copy(rhs_it)); #endif + // update next used cache + next_used_cache = static_cast(m_next[i]); + overwrite_used_slot = true; } + // use ctor to avoid UB for non-initialized free slots else { -// use ctor to avoid UB for non-initialized free slots #if __cplusplus >= 201703L if constexpr (is_move) { @@ -143,14 +155,38 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh // Same as above CtorHelper::construct(m_data[i], MoveHelper::move_or_copy(rhs_it)); #endif + + // update next free cache + next_free_cache = static_cast(m_next[i]); + overwrite_free_slot = true; } m_status[i] = SlotStatus::USED; m_next[i] = static_cast(i + 1U); } - // correct next - m_next[i] = Index::INVALID; + // update the member only if rhs is not empty to ensure that erase() functions correctly. + if (!rhs.empty()) + { + // if there is overwriting of free slots with source data, + // update m_begin_free; otherwise, keep m_begin_free unchanged. + if (overwrite_free_slot) + { + m_begin_free = next_free_cache; + } + + if (overwrite_used_slot) + { + m_next[i - 1] = next_used_cache; + } + else + { + m_next[i - 1] = m_begin_used; + } + + // cause rhs.m_size != 0, so it's ok to use FIRST + m_begin_used = Index::FIRST; + } // erase rest USED element in rhs, also update m_next for free slots for (; i < Index::INVALID; ++i) @@ -165,9 +201,10 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh } } - // member update + // update member to correct information m_begin_free = static_cast(rhs.m_size); - m_begin_used = Index::FIRST; + m_begin_used = rhs.empty() ? Index::INVALID : Index::FIRST; + m_next[rhs.m_size - 1] = Index::INVALID; m_size = rhs.m_size; } From fdaea90be1b3b857ac3cd5542e6442279bbc148b Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Sun, 5 Nov 2023 02:19:55 +0800 Subject: [PATCH 16/85] iox-#2052 Remove unneccessary symbol Signed-off-by: Dennis Liu Removed the division symbol '\'. Additionally, a new line has been added between different test sections. --- .../test_container_fixed_position_container.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index 643ac4bd00..8f5000dd7e 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -288,6 +288,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorWillNotChangeSourceContainer) // END test copy constructor + // BEGIN test move constructor TEST_F(FixedPositionContainer_test, UsingMoveCtorFromEmptyContainerResultsInEmptyContainer) @@ -459,6 +460,7 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorAtNonCopyableTypeShouldCompile) // END test move constructor + // BEGIN test copy assignment TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromEmptyContainerResultsInEmptyContainer) @@ -1047,6 +1049,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentInsertionShouldFailWhenCa // END test copy assignment + // BEGIN test move assignment TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromEmptyContainerResultsInEmptyContainer) @@ -1152,10 +1155,6 @@ TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromFullCapacityContainer EXPECT_THAT(sut_complex.empty(), Eq(true)); } -///////////////////////////////////////////////////////// -///////////////////////////////////////////////////////// -///////////////////////////////////////////////////////// - TEST_F(FixedPositionContainer_test, UsingMoveAssignmentFromEmptyToNonEmptyContainer) { ::testing::Test::RecordProperty("TEST_ID", "998e06c0-6879-451e-a493-e3e26944feff"); @@ -1665,10 +1664,9 @@ TEST_F(FixedPositionContainer_test, UsingMoveAssignmentAtNonCopyableTypeShouldCo EXPECT_THAT(move_sut_noncopy.size(), Eq(EXPECTED_SIZE)); } -///////////////////////////////////////////////////////// - // END test move assignment + // BEGIN test empty TEST_F(FixedPositionContainer_test, NewlyCreatedContainerIsEmpty) From 19e0901716b84d0c4ea815ba8d0e25a768f66c5f Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Tue, 7 Nov 2023 11:53:00 +0800 Subject: [PATCH 17/85] iox-#2052 Isolate helper for compiler compatibility Signed-off-by: Dennis Liu This commit extracts C++14 template structures from `FixedPositionContainer` to a new header `detail/fixed_position_container_helper.hpp`, resolving compile-time differences between g++-8.4 and g++-11.4, and ensuring adherence to the C++ standard. In g++-8.4, nested template deduction and usage were problematic, causing original implementation failures. Conversely, g++-11.4 processed the same structures correctly, though reasons are not fully clear. After this refactor, unit tests for `FixedPositionContainer` remain successful, and the code compiles error-free on both g++-8.4 and g++-11.4. --- .../fixed_position_container_helper.hpp | 94 +++++++++++++++++++ .../include/iox/fixed_position_container.hpp | 75 +-------------- 2 files changed, 98 insertions(+), 71 deletions(-) create mode 100644 iceoryx_dust/container/include/iox/detail/fixed_position_container_helper.hpp diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container_helper.hpp b/iceoryx_dust/container/include/iox/detail/fixed_position_container_helper.hpp new file mode 100644 index 0000000000..914e1b0306 --- /dev/null +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container_helper.hpp @@ -0,0 +1,94 @@ +// Copyright (c) 2023 by Dennis Liu . All rights reserved. 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_DUST_CONTAINER_DETAIL_FIXED_POSITION_CONTAINER_HELPER_HPP +#define IOX_DUST_CONTAINER_DETAIL_FIXED_POSITION_CONTAINER_HELPER_HPP + +#include + +namespace iox +{ +template +struct AssignmentHelper; + +template <> +struct AssignmentHelper +{ + template + static void assign(T& dest, T&& src) + { + dest = std::forward(src); + } +}; + +template <> +struct AssignmentHelper +{ + template + static void assign(T& dest, const T& src) + { + dest = src; + } +}; + +template +struct CtorHelper; + +template <> +struct CtorHelper +{ + template + static void construct(T& dest, T&& src) + { + new (&dest) T(std::forward(src)); + } +}; + +template <> +struct CtorHelper +{ + template + static void construct(T& dest, const T& src) + { + new (&dest) T(src); + } +}; + +template +struct MoveHelper; + +template <> +struct MoveHelper +{ + template + static auto move_or_copy(Iterator& it) -> decltype(std::move(*it)) + { + return std::move(*it); + } +}; + +template <> +struct MoveHelper +{ + template + static auto move_or_copy(Iterator& it) -> decltype(*it) + { + return *it; + } +}; + +#endif +} diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index 4b7dbe9fc5..cfb3a7da82 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -21,6 +21,10 @@ #include "iox/algorithm.hpp" #include "iox/uninitialized_array.hpp" +#if __cplusplus < 201703L +#include "iox/detail/fixed_position_container_helper.hpp" +#endif + #include #include #include @@ -317,77 +321,6 @@ class FixedPositionContainer final IndexType m_index; }; -#if __cplusplus < 201703L - private: - // C++ 14 feature - template - struct AssignmentHelper; - - template <> - struct AssignmentHelper - { - static void assign(T& dest, T&& src) - { - dest = std::forward(src); - } - }; - - template <> - struct AssignmentHelper - { - static void assign(T& dest, const T& src) - { - dest = src; - } - }; - - // C++ 14 feature - template - struct CtorHelper; - - template <> - struct CtorHelper - { - static void construct(T& dest, T&& src) - { - new (&dest) T(std::forward(src)); - } - }; - - template <> - struct CtorHelper - { - static void construct(T& dest, const T& src) - { - new (&dest) T(src); - } - }; - - // C++ 14 feature - template - struct MoveHelper; - - template <> - struct MoveHelper - { - template - static auto move_or_copy(Iterator& it) -> decltype(std::move(*it)) - { - return std::move(*it); - } - }; - - template <> - struct MoveHelper - { - template - static auto move_or_copy(Iterator& it) -> decltype(*it) - { - return *it; - } - }; -#endif - template void copy_and_move_impl(RhsType&& rhs) noexcept; From 46b1df536d8e34d8673142c9e486358d8214cfe6 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Tue, 7 Nov 2023 12:29:33 +0800 Subject: [PATCH 18/85] iox-#2052 Move include to .inl file Signed-off-by: Dennis Liu Move iclude "iox/detail/fixed_position_container_helper.hpp" from `fixed_position_container.hpp` to `fixed_position_container.inl`. --- .../container/include/iox/detail/fixed_position_container.inl | 3 +++ .../container/include/iox/fixed_position_container.hpp | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index f890fefc6d..5b639ca262 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -19,6 +19,9 @@ #define IOX_DUST_CONTAINER_DETAIL_FIXED_POSITION_CONTAINER_INL #include "iox/fixed_position_container.hpp" +#if __cplusplus < 201703L +#include "iox/detail/fixed_position_container_helper.hpp" +#endif namespace iox { diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index cfb3a7da82..9cded3d32f 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -21,10 +21,6 @@ #include "iox/algorithm.hpp" #include "iox/uninitialized_array.hpp" -#if __cplusplus < 201703L -#include "iox/detail/fixed_position_container_helper.hpp" -#endif - #include #include #include From 2f6787fd851bb1164452a66aea8f2a4ca3415043 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Tue, 7 Nov 2023 23:52:17 +0800 Subject: [PATCH 19/85] iox-#2052 Fix array out of bounds of m_next Signed-off-by: Dennis Liu Zero size rhs container isn't considered. Therefore, test failed in build-test-ubuntu-with-address-sanitizer-clang-latest. --- .../include/iox/detail/fixed_position_container.inl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index 5b639ca262..0fecf92c28 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -207,8 +207,12 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh // update member to correct information m_begin_free = static_cast(rhs.m_size); m_begin_used = rhs.empty() ? Index::INVALID : Index::FIRST; - m_next[rhs.m_size - 1] = Index::INVALID; m_size = rhs.m_size; + + if (!rhs.empty()) + { + m_next[rhs.m_size - 1] = Index::INVALID; + } } template From 9eff9ce9c6b7ada863cf513773d0c6d0cfa09631 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Wed, 8 Nov 2023 12:23:37 +0800 Subject: [PATCH 20/85] iox-#2052 Simplify copy_and_move_impl Signed-off-by: Dennis Liu Simplify `copy_and_move_impl` according to `clear`. Also, add sub namespace `detail` to helper struct. --- .../iox/detail/fixed_position_container.inl | 64 ++++--------------- .../fixed_position_container_helper.hpp | 3 + 2 files changed, 15 insertions(+), 52 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index 0fecf92c28..7826756709 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -106,16 +106,8 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh constexpr bool is_move = std::is_rvalue_reference::value; IndexType i{Index::FIRST}; - - // this can update member faster - IndexType next_used_cache{Index::INVALID}; - IndexType next_free_cache{Index::INVALID}; - bool overwrite_used_slot{false}; - bool overwrite_free_slot{true}; - auto rhs_it = (std::forward(rhs)).begin(); - // transfer src data to destination for (; rhs_it.to_index() != Index::INVALID; ++i, ++rhs_it) { @@ -134,13 +126,9 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh // We introduce a helper struct primarily due to the test case // e1cc7c9f-c1b5-4047-811b-004302af5c00. It demands compile-time if-else branching // for classes that are either non-copyable or non-moveable. - // Note: With C++17's 'if constexpr', the need for these helper structs (labeled "C++ 14 feature" - // in fixed_position_container.hpp) can be eliminated. - AssignmentHelper::assign(m_data[i], MoveHelper::move_or_copy(rhs_it)); + // Note: With C++17's 'if constexpr', the need for these helper structs can be eliminated. + detail::AssignmentHelper::assign(m_data[i], detail::MoveHelper::move_or_copy(rhs_it)); #endif - // update next used cache - next_used_cache = static_cast(m_next[i]); - overwrite_used_slot = true; } // use ctor to avoid UB for non-initialized free slots else @@ -156,63 +144,35 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh } #else // Same as above - CtorHelper::construct(m_data[i], MoveHelper::move_or_copy(rhs_it)); + detail::CtorHelper::construct(m_data[i], detail::MoveHelper::move_or_copy(rhs_it)); #endif - - // update next free cache - next_free_cache = static_cast(m_next[i]); - overwrite_free_slot = true; } - m_status[i] = SlotStatus::USED; m_next[i] = static_cast(i + 1U); } - // update the member only if rhs is not empty to ensure that erase() functions correctly. - if (!rhs.empty()) + for (; i < CAPACITY; ++i) { - // if there is overwriting of free slots with source data, - // update m_begin_free; otherwise, keep m_begin_free unchanged. - if (overwrite_free_slot) + if (m_status[i] == SlotStatus::USED) { - m_begin_free = next_free_cache; + m_data[i].~T(); } - if (overwrite_used_slot) - { - m_next[i - 1] = next_used_cache; - } - else - { - m_next[i - 1] = m_begin_used; - } + m_status[i] = SlotStatus::FREE; - // cause rhs.m_size != 0, so it's ok to use FIRST - m_begin_used = Index::FIRST; + IndexType next = static_cast(i + 1U); + m_next[i] = next; } - // erase rest USED element in rhs, also update m_next for free slots - for (; i < Index::INVALID; ++i) + m_next[Index::LAST] = Index::INVALID; + if (!rhs.empty()) { - if (m_status[i] == SlotStatus::USED) - { - erase(i); - } - else - { - m_next[i] = static_cast(i + 1U); - } + m_next[rhs.m_size - 1] = Index::INVALID; } - // update member to correct information m_begin_free = static_cast(rhs.m_size); m_begin_used = rhs.empty() ? Index::INVALID : Index::FIRST; m_size = rhs.m_size; - - if (!rhs.empty()) - { - m_next[rhs.m_size - 1] = Index::INVALID; - } } template diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container_helper.hpp b/iceoryx_dust/container/include/iox/detail/fixed_position_container_helper.hpp index 914e1b0306..ad1c12cb08 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container_helper.hpp +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container_helper.hpp @@ -21,6 +21,8 @@ namespace iox { +namespace detail +{ template struct AssignmentHelper; @@ -92,3 +94,4 @@ struct MoveHelper #endif } +} From 35bc62c1717662f96f87ba00412906cb1a3be54b Mon Sep 17 00:00:00 2001 From: Simon Hoinkis Date: Wed, 8 Nov 2023 15:59:56 +0100 Subject: [PATCH 21/85] iox-#2078 Adapt PR template to reduced number of reviewers Signed-off-by: Simon Hoinkis --- .github/PULL_REQUEST_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 0f177d2391..7ddbe3c4f9 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,6 @@ ## Pre-Review Checklist for the PR Author +1. [ ] Add a second reviewer for complex new features or larger refactorings 1. [ ] Code follows the coding style of [CONTRIBUTING.md][contributing] 1. [ ] Tests follow the [best practice for testing][testing] 1. [ ] Changelog updated [in the unreleased section][changelog] including API breaking changes From 24c53138b3a54da185aa1f07b4e261634890341c Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Thu, 9 Nov 2023 10:40:55 +0800 Subject: [PATCH 22/85] iox-#2052 Add `IteratorsAfterMoveWorkAsExpected` Signed-off-by: Dennis Liu Add a new test case `IteratorsAfterMoveWorkAsExpected`. Remove previous test cases `ContainerIsNotMovable` and `ContainerIsNotCopyable`. --- ...est_container_fixed_position_container.cpp | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index 8f5000dd7e..31a48ddb49 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -109,22 +109,6 @@ struct FixedPositionContainer_test : public Test ComplexType::Statistics& stats = ComplexType::stats; }; -TEST_F(FixedPositionContainer_test, ContainerIsNotMovable) -{ - GTEST_SKIP() << "@deprecated iox-#2052 Add moveable feature"; - ::testing::Test::RecordProperty("TEST_ID", "5c05f240-9822-427b-9eb5-69fd43f1ac28"); - EXPECT_FALSE(std::is_move_constructible::value); - EXPECT_FALSE(std::is_move_assignable::value); -} - -TEST_F(FixedPositionContainer_test, ContainerIsNotCopyable) -{ - GTEST_SKIP() << "@deprecated iox-#2052 Add copyable feature"; - ::testing::Test::RecordProperty("TEST_ID", "1b421af5-d014-4f9b-98ed-fbfdf5a9beb8"); - EXPECT_FALSE(std::is_copy_constructible::value); - EXPECT_FALSE(std::is_copy_assignable::value); -} - TEST_F(FixedPositionContainer_test, Capacity) { ::testing::Test::RecordProperty("TEST_ID", "17669b2f-d53b-4ac9-8190-b1c32f8ec4ba"); @@ -255,7 +239,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyCtorFromNonEmptyWithFirstAndMiddleA EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(CAPACITY - 3U)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -435,7 +419,7 @@ TEST_F(FixedPositionContainer_test, UsingMoveCtorFromNonEmptyWithFirstAndMiddleA EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(CAPACITY - 3U)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -572,6 +556,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromEmptyToNonEmptyContai EXPECT_THAT(copy_sut_complex.full(), Eq(0)); EXPECT_THAT(copy_sut_complex.empty(), Eq(true)); EXPECT_THAT(copy_sut_complex.size(), Eq(0)); + EXPECT_THAT(copy_sut_complex.begin(), Eq(copy_sut_complex.end())); } TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromLargerSizeToSmallerSizeContainer) @@ -597,7 +582,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromLargerSizeToSmallerSi EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -628,7 +613,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentBetweenContainersOfEqalSi EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -659,7 +644,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromSmallerSizeToLargerSi EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -687,7 +672,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithFirstInde EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -721,7 +706,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithFirstInde EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -756,7 +741,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyToNonEmptyCon EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -793,7 +778,7 @@ TEST_F(FixedPositionContainer_test, EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -823,7 +808,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithFirstAndM EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -859,7 +844,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithFirstAndM EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -897,7 +882,7 @@ TEST_F(FixedPositionContainer_test, EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -938,7 +923,7 @@ TEST_F( EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -973,7 +958,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentFromNonEmptyWithLastErase EXPECT_THAT(copy_sut_complex.full(), Eq(false)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -1035,7 +1020,7 @@ TEST_F(FixedPositionContainer_test, UsingCopyAssignmentInsertionShouldFailWhenCa EXPECT_THAT(copy_sut_complex.full(), Eq(true)); EXPECT_THAT(copy_sut_complex.empty(), Eq(false)); EXPECT_THAT(copy_sut_complex.size(), Eq(EXPECTED_SIZE)); - auto it = copy_sut_complex.iter_from_index(SutComplex::Index::FIRST); + auto it = copy_sut_complex.begin(); for (const auto& value : EXPECTED_VALUE) { EXPECT_THAT(it->value, Eq(value)); @@ -1664,6 +1649,25 @@ TEST_F(FixedPositionContainer_test, UsingMoveAssignmentAtNonCopyableTypeShouldCo EXPECT_THAT(move_sut_noncopy.size(), Eq(EXPECTED_SIZE)); } +TEST_F(FixedPositionContainer_test, IteratorsAfterMoveWorkAsExpected) +{ + ::testing::Test::RecordProperty("TEST_ID", "17b91183-9f1e-4ab4-ab27-e34f096674d8"); + + std::vector EXPECTED_VALUE = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 9U}; + + fillSutComplex(); + + SutComplex move_sut_complex; + move_sut_complex = std::move(sut_complex); + + EXPECT_THAT(sut_complex.begin(), Eq(sut_complex.end())); + auto it = move_sut_complex.begin(); + for (SutComplex::IndexType i = 0U; it != move_sut_complex.end(); ++it, ++i) + { + EXPECT_THAT(it->value, Eq(EXPECTED_VALUE[i])); + } +} + // END test move assignment From 57b1845bdbdc365ce2a4460f34567921ec3b9f73 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 26 Oct 2023 00:26:55 +0200 Subject: [PATCH 23/85] iox-#1391 Move 'message_queue' to 'posix/ipc' --- .../release-notes/iceoryx-unreleased.md | 2 +- iceoryx_dust/BUILD.bazel | 4 +- iceoryx_dust/CMakeLists.txt | 4 +- .../ipc/include/iox}/message_queue.hpp | 50 +++++++++---------- .../ipc/source}/message_queue.cpp | 35 ++++++------- iceoryx_hoofs/cmake/IceoryxPlatform.cmake | 4 +- .../internal/runtime/ipc_interface_base.hpp | 2 +- .../source/runtime/ipc_interface_base.cpp | 2 +- .../test_mq_interface_startup_race.cpp | 2 +- .../test_runtime_ipc_interface.cpp | 2 +- 10 files changed, 56 insertions(+), 51 deletions(-) rename iceoryx_dust/{include/iceoryx_dust/posix_wrapper => posix/ipc/include/iox}/message_queue.hpp (72%) rename iceoryx_dust/{source/posix_wrapper => posix/ipc/source}/message_queue.cpp (90%) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 730228d136..2c0e379f79 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -998,7 +998,7 @@ #include "iceoryx_hoofs/posix_wrapper/internal/message_queue.hpp" // after - #include "iceoryx_dust/posix_wrapper/message_queue.hpp" + #include "iox/message_queue.hpp" ``` ```cpp diff --git a/iceoryx_dust/BUILD.bazel b/iceoryx_dust/BUILD.bazel index a8ad11ef32..5374b4573f 100644 --- a/iceoryx_dust/BUILD.bazel +++ b/iceoryx_dust/BUILD.bazel @@ -32,10 +32,11 @@ cc_library( srcs = glob([ "cli/source/**/*.cpp", "filesystem/source/**/*.cpp", + "posix/ipc/source/**/*.cpp", "source/**/*.cpp", "source/**/*.hpp", ]), - hdrs = glob(["include/**"]) + glob(["cli/**"]) + glob(["container/**"]) + glob(["filesystem/**"]) + glob(["memory/**"]) + glob(["utility/**"]) + glob(["vocabulary/**"]) + [ + hdrs = glob(["include/**"]) + glob(["cli/**"]) + glob(["container/**"]) + glob(["filesystem/**"]) + glob(["memory/**"]) + glob(["utility/**"]) + glob(["posix/ipc/**"]) + glob(["vocabulary/**"]) + [ ":iceoryx_dust_deployment_hpp", ], includes = [ @@ -44,6 +45,7 @@ cc_library( "filesystem/include/", "include", "memory/include/", + "posix/ipc/include/", "utility/include/", "vocabulary/include/", ], diff --git a/iceoryx_dust/CMakeLists.txt b/iceoryx_dust/CMakeLists.txt index 0333330f49..d5014da80a 100644 --- a/iceoryx_dust/CMakeLists.txt +++ b/iceoryx_dust/CMakeLists.txt @@ -51,6 +51,7 @@ iox_add_library( ${PROJECT_SOURCE_DIR}/container/include ${PROJECT_SOURCE_DIR}/filesystem/include ${PROJECT_SOURCE_DIR}/memory/include + ${PROJECT_SOURCE_DIR}/posix/ipc/include ${PROJECT_SOURCE_DIR}/utility/include ${PROJECT_SOURCE_DIR}/vocabulary/include ${CMAKE_BINARY_DIR}/generated/iceoryx_dust/include @@ -60,6 +61,7 @@ iox_add_library( container/include/ filesystem/include/ memory/include/ + posix/ipc/include/ utility/include/ vocabulary/include/ FILES @@ -71,7 +73,7 @@ iox_add_library( filesystem/source/file_reader.cpp source/posix_wrapper/named_pipe.cpp source/posix_wrapper/signal_watcher.cpp - source/posix_wrapper/message_queue.cpp + posix/ipc/source/message_queue.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/iceoryx_dust_deployment.hpp.in" diff --git a/iceoryx_dust/include/iceoryx_dust/posix_wrapper/message_queue.hpp b/iceoryx_dust/posix/ipc/include/iox/message_queue.hpp similarity index 72% rename from iceoryx_dust/include/iceoryx_dust/posix_wrapper/message_queue.hpp rename to iceoryx_dust/posix/ipc/include/iox/message_queue.hpp index 6c57c2593f..2c2f7a965e 100644 --- a/iceoryx_dust/include/iceoryx_dust/posix_wrapper/message_queue.hpp +++ b/iceoryx_dust/posix/ipc/include/iox/message_queue.hpp @@ -15,8 +15,9 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#ifndef IOX_DUST_POSIX_WRAPPER_MESSAGE_QUEUE_HPP -#define IOX_DUST_POSIX_WRAPPER_MESSAGE_QUEUE_HPP + +#ifndef IOX_DUST_POSIX_IPC_MESSAGE_QUEUE_HPP +#define IOX_DUST_POSIX_IPC_MESSAGE_QUEUE_HPP #include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp" #include "iceoryx_platform/fcntl.hpp" @@ -29,14 +30,12 @@ namespace iox { -namespace posix -{ class MessageQueueBuilder; /// @brief Wrapper class for posix message queue /// /// @code -/// auto mq = iox::posix::MessageQueueBuilder() +/// auto mq = iox::MessageQueueBuilder() /// .name("/MqName123") /// .channelSide(iox::posix::IpcChannelSide::CLIENT) /// .create(); @@ -68,27 +67,28 @@ class MessageQueue ~MessageQueue() noexcept; - static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; + static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; /// @brief send a message to queue using std::string. /// @return true if sent without errors, false otherwise - expected send(const std::string& msg) const noexcept; + expected send(const std::string& msg) const noexcept; /// @todo iox-#1693 zero copy receive with receive(iox::string&); iox::string would be the buffer for mq_receive /// @brief receive message from queue using std::string. /// @return number of characters received. In case of an error, returns -1 and msg is empty. - expected receive() const noexcept; + expected receive() const noexcept; /// @brief try to receive message from queue for a given timeout duration using std::string. Only defined /// for NON_BLOCKING == false. /// @return optional containing the received string. In case of an error, nullopt type is returned. - expected timedReceive(const units::Duration& timeout) const noexcept; + expected timedReceive(const units::Duration& timeout) const noexcept; /// @brief try to send a message to the queue for a given timeout duration using std::string - expected timedSend(const std::string& msg, const units::Duration& timeout) const noexcept; + expected timedSend(const std::string& msg, + const units::Duration& timeout) const noexcept; - static expected isOutdated() noexcept; + static expected isOutdated() noexcept; private: friend class MessageQueueBuilder; @@ -96,23 +96,24 @@ class MessageQueue MessageQueue(const IpcChannelName_t& name, const mq_attr attributes, mqd_t mqDescriptor, - const IpcChannelSide channelSide) noexcept; + const posix::IpcChannelSide channelSide) noexcept; - static expected - open(const IpcChannelName_t& name, mq_attr& attributes, const IpcChannelSide channelSide) noexcept; + static expected + open(const IpcChannelName_t& name, mq_attr& attributes, const posix::IpcChannelSide channelSide) noexcept; - expected close() noexcept; - expected unlink() noexcept; - IpcChannelError errnoToEnum(const int32_t errnum) const noexcept; - static IpcChannelError errnoToEnum(const IpcChannelName_t& name, const int32_t errnum) noexcept; - static expected sanitizeIpcChannelName(const IpcChannelName_t& name) noexcept; - expected destroy() noexcept; + expected close() noexcept; + expected unlink() noexcept; + posix::IpcChannelError errnoToEnum(const int32_t errnum) const noexcept; + static posix::IpcChannelError errnoToEnum(const IpcChannelName_t& name, const int32_t errnum) noexcept; + static expected + sanitizeIpcChannelName(const IpcChannelName_t& name) noexcept; + expected destroy() noexcept; private: IpcChannelName_t m_name; mq_attr m_attributes{}; mqd_t m_mqDescriptor = INVALID_DESCRIPTOR; - IpcChannelSide m_channelSide = IpcChannelSide::CLIENT; + posix::IpcChannelSide m_channelSide = posix::IpcChannelSide::CLIENT; #ifdef __QNX__ static constexpr int TIMEOUT_ERRNO = EINTR; @@ -132,7 +133,7 @@ class MessageQueueBuilder IOX_BUILDER_PARAMETER(IpcChannelName_t, name, "") /// @brief Defines how the message queue is opened, i.e. as client or server - IOX_BUILDER_PARAMETER(IpcChannelSide, channelSide, IpcChannelSide::CLIENT) + IOX_BUILDER_PARAMETER(posix::IpcChannelSide, channelSide, posix::IpcChannelSide::CLIENT) /// @brief Defines the max message size of the message queue IOX_BUILDER_PARAMETER(uint64_t, maxMsgSize, MessageQueue::MAX_MESSAGE_SIZE) @@ -143,10 +144,9 @@ class MessageQueueBuilder public: /// @brief create a message queue /// @return On success a 'MessageQueue' is returned and on failure an 'IpcChannelError'. - expected create() const noexcept; + expected create() const noexcept; }; -} // namespace posix } // namespace iox -#endif // IOX_DUST_POSIX_WRAPPER_MESSAGE_QUEUE_HPP +#endif // IOX_DUST_POSIX_IPC_MESSAGE_QUEUE_HPP diff --git a/iceoryx_dust/source/posix_wrapper/message_queue.cpp b/iceoryx_dust/posix/ipc/source/message_queue.cpp similarity index 90% rename from iceoryx_dust/source/posix_wrapper/message_queue.cpp rename to iceoryx_dust/posix/ipc/source/message_queue.cpp index a1e0f3395f..5cae8a7b6e 100644 --- a/iceoryx_dust/source/posix_wrapper/message_queue.cpp +++ b/iceoryx_dust/posix/ipc/source/message_queue.cpp @@ -16,7 +16,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/message_queue.hpp" +#include "iox/message_queue.hpp" #include "iceoryx_hoofs/posix_wrapper/posix_call.hpp" #include "iceoryx_platform/fcntl.hpp" #include "iceoryx_platform/platform_correction.hpp" @@ -28,8 +28,8 @@ namespace iox { -namespace posix -{ +using namespace iox::posix; + expected MessageQueueBuilder::create() const noexcept { auto sanitzedNameResult = MessageQueue::sanitizeIpcChannelName(m_name); @@ -47,7 +47,7 @@ expected MessageQueueBuilder::create() const noex if (m_channelSide == IpcChannelSide::SERVER) { - posixCall(mq_unlink)(sanitizedName.c_str()) + posix::posixCall(mq_unlink)(sanitizedName.c_str()) .failureReturnValue(MessageQueue::ERROR_CODE) .ignoreErrnos(ENOENT) .evaluate() @@ -134,7 +134,7 @@ expected MessageQueue::unlinkIfExists(const IpcChannelNam } - auto mqCall = posixCall(mq_unlink)(sanitizedIpcChannelName->c_str()) + auto mqCall = posix::posixCall(mq_unlink)(sanitizedIpcChannelName->c_str()) .failureReturnValue(ERROR_CODE) .ignoreErrnos(ENOENT) .evaluate(); @@ -176,8 +176,9 @@ expected MessageQueue::send(const std::string& msg) const return err(IpcChannelError::MESSAGE_TOO_LONG); } - auto mqCall = - posixCall(mq_send)(m_mqDescriptor, msg.c_str(), messageSize, 1U).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = posix::posixCall(mq_send)(m_mqDescriptor, msg.c_str(), messageSize, 1U) + .failureReturnValue(ERROR_CODE) + .evaluate(); if (mqCall.has_error()) { @@ -193,7 +194,7 @@ expected MessageQueue::receive() const noexcept /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) char message[MAX_MESSAGE_SIZE]; - auto mqCall = posixCall(mq_receive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr) + auto mqCall = posix::posixCall(mq_receive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr) .failureReturnValue(ERROR_CODE) .evaluate(); @@ -227,10 +228,11 @@ MessageQueue::open(const IpcChannelName_t& name, mq_attr& attributes, const IpcC // the mask will be applied to the permissions, therefore we need to set it to 0 mode_t umaskSaved = umask(0); - auto mqCall = posixCall(iox_mq_open4)(sanitizedName.c_str(), openFlags, MessageQueue::FILE_MODE, &attributes) - .failureReturnValue(MessageQueue::INVALID_DESCRIPTOR) - .suppressErrorMessagesForErrnos(ENOENT) - .evaluate(); + auto mqCall = + posix::posixCall(iox_mq_open4)(sanitizedName.c_str(), openFlags, MessageQueue::FILE_MODE, &attributes) + .failureReturnValue(MessageQueue::INVALID_DESCRIPTOR) + .suppressErrorMessagesForErrnos(ENOENT) + .evaluate(); umask(umaskSaved); @@ -245,7 +247,7 @@ MessageQueue::open(const IpcChannelName_t& name, mq_attr& attributes, const IpcC expected MessageQueue::close() noexcept { - auto mqCall = posixCall(mq_close)(m_mqDescriptor).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = posix::posixCall(mq_close)(m_mqDescriptor).failureReturnValue(ERROR_CODE).evaluate(); if (mqCall.has_error()) { @@ -262,7 +264,7 @@ expected MessageQueue::unlink() noexcept return ok(); } - auto mqCall = posixCall(mq_unlink)(m_name.c_str()).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = posix::posixCall(mq_unlink)(m_name.c_str()).failureReturnValue(ERROR_CODE).evaluate(); if (mqCall.has_error()) { return err(errnoToEnum(mqCall.error().errnum)); @@ -278,7 +280,7 @@ expected MessageQueue::timedReceive(const units::D /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) char message[MAX_MESSAGE_SIZE]; - auto mqCall = posixCall(mq_timedreceive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr, &timeOut) + auto mqCall = posix::posixCall(mq_timedreceive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr, &timeOut) .failureReturnValue(ERROR_CODE) // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT .ignoreErrnos(TIMEOUT_ERRNO) @@ -310,7 +312,7 @@ expected MessageQueue::timedSend(const std::string& msg, timespec timeOut = timeout.timespec(units::TimeSpecReference::Epoch); - auto mqCall = posixCall(mq_timedsend)(m_mqDescriptor, msg.c_str(), messageSize, 1U, &timeOut) + auto mqCall = posix::posixCall(mq_timedsend)(m_mqDescriptor, msg.c_str(), messageSize, 1U, &timeOut) .failureReturnValue(ERROR_CODE) // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT .ignoreErrnos(TIMEOUT_ERRNO) @@ -406,5 +408,4 @@ expected MessageQueue::sanitizeIpcChannelName return ok(name); } -} // namespace posix } // namespace iox diff --git a/iceoryx_hoofs/cmake/IceoryxPlatform.cmake b/iceoryx_hoofs/cmake/IceoryxPlatform.cmake index 27f9dd7ae0..5f143d95ef 100644 --- a/iceoryx_hoofs/cmake/IceoryxPlatform.cmake +++ b/iceoryx_hoofs/cmake/IceoryxPlatform.cmake @@ -80,7 +80,7 @@ function(iox_create_lsan_runtime_blacklist BLACKLIST_FILE_PATH) # count bytes template # 8 642 libacl.so.1 # 1 24 iox::posix::UnixDomainSocket::timedReceive - # 1 24 iox::posix::MessageQueue::receive + # 1 24 iox::MessageQueue::receive if(NOT EXISTS ${BLACKLIST_FILE_PATH}) file(WRITE ${BLACKLIST_FILE_PATH} "# This file is auto-generated from iceoryx_hoofs/cmake/IceoryxPlatform.cmake\n") file(APPEND ${BLACKLIST_FILE_PATH} "#leak:libacl.so.1\n") @@ -131,7 +131,7 @@ if(ADDRESS_SANITIZER OR THREAD_SANITIZER) elseif(THREAD_SANITIZER) set(ICEORYX_SANITIZER_FLAGS ${ICEORYX_SANITIZER_COMMON_FLAGS} ${ICEORYX_THREAD_SANITIZER_FLAGS} CACHE INTERNAL "") endif() - + # unset local variables , to avoid polluting global space unset(ICEORYX_SANITIZER_BLACKLIST) unset(ICEORYX_SANITIZER_COMMON_FLAGS) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp b/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp index 22dd383396..b73d34bbd0 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp @@ -32,9 +32,9 @@ #include "iox/optional.hpp" #include "iox/relative_pointer.hpp" -#include "iceoryx_dust/posix_wrapper/message_queue.hpp" #include "iceoryx_dust/posix_wrapper/named_pipe.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp" +#include "iox/message_queue.hpp" #include #include diff --git a/iceoryx_posh/source/runtime/ipc_interface_base.cpp b/iceoryx_posh/source/runtime/ipc_interface_base.cpp index bb11b7f6e4..8485720ef7 100644 --- a/iceoryx_posh/source/runtime/ipc_interface_base.cpp +++ b/iceoryx_posh/source/runtime/ipc_interface_base.cpp @@ -264,7 +264,7 @@ void IpcInterface::cleanupOutdatedIpcChannel(const RuntimeName_t template class IpcInterface; template class IpcInterface; -template class IpcInterface; +template class IpcInterface; } // namespace runtime } // namespace iox diff --git a/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp b/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp index c2d3145351..f8e71c48bc 100644 --- a/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp +++ b/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp @@ -18,11 +18,11 @@ #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "test.hpp" -#include "iceoryx_dust/posix_wrapper/message_queue.hpp" #include "iceoryx_hoofs/posix_wrapper/posix_call.hpp" #include "iceoryx_posh/internal/runtime/ipc_message.hpp" #include "iceoryx_posh/internal/runtime/ipc_runtime_interface.hpp" #include "iox/duration.hpp" +#include "iox/message_queue.hpp" #include "iox/std_string_support.hpp" diff --git a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp index cc0082b298..271e8de44c 100644 --- a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp +++ b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp @@ -15,11 +15,11 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/message_queue.hpp" #include "iceoryx_dust/posix_wrapper/named_pipe.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp" #include "iceoryx_platform/platform_settings.hpp" #include "iceoryx_posh/internal/runtime/ipc_interface_base.hpp" +#include "iox/message_queue.hpp" #include "iox/std_chrono_support.hpp" #include "test.hpp" From b779af592be14054c3076420667955f8a6e8866b Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 26 Oct 2023 00:48:09 +0200 Subject: [PATCH 24/85] iox-#1391 Move 'named_pipe' to 'posix/ipc' --- .../release-notes/iceoryx-unreleased.md | 2 +- iceoryx_dust/CMakeLists.txt | 4 +- .../ipc/include/iox}/named_pipe.hpp | 46 +++++++++---------- .../ipc/source}/named_pipe.cpp | 7 ++- .../internal/runtime/ipc_interface_base.hpp | 6 +-- .../source/runtime/ipc_interface_base.cpp | 4 +- .../test_runtime_ipc_interface.cpp | 2 +- 7 files changed, 34 insertions(+), 37 deletions(-) rename iceoryx_dust/{include/iceoryx_dust/posix_wrapper => posix/ipc/include/iox}/named_pipe.hpp (80%) rename iceoryx_dust/{source/posix_wrapper => posix/ipc/source}/named_pipe.cpp (99%) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 2c0e379f79..147a14741a 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -1006,7 +1006,7 @@ #include "iceoryx_hoofs/posix_wrapper/named_pipe.hpp" // after - #include "iceoryx_dust/posix_wrapper/named_pipe.hpp" + #include "iox/named_pipe.hpp" ``` ```cpp diff --git a/iceoryx_dust/CMakeLists.txt b/iceoryx_dust/CMakeLists.txt index d5014da80a..3f6a43aa1e 100644 --- a/iceoryx_dust/CMakeLists.txt +++ b/iceoryx_dust/CMakeLists.txt @@ -71,9 +71,9 @@ iox_add_library( cli/source/option_definition.cpp cli/source/option_manager.cpp filesystem/source/file_reader.cpp - source/posix_wrapper/named_pipe.cpp - source/posix_wrapper/signal_watcher.cpp posix/ipc/source/message_queue.cpp + posix/ipc/source/named_pipe.cpp + source/posix_wrapper/signal_watcher.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/iceoryx_dust_deployment.hpp.in" diff --git a/iceoryx_dust/include/iceoryx_dust/posix_wrapper/named_pipe.hpp b/iceoryx_dust/posix/ipc/include/iox/named_pipe.hpp similarity index 80% rename from iceoryx_dust/include/iceoryx_dust/posix_wrapper/named_pipe.hpp rename to iceoryx_dust/posix/ipc/include/iox/named_pipe.hpp index 5286e2c083..c227a7360e 100644 --- a/iceoryx_dust/include/iceoryx_dust/posix_wrapper/named_pipe.hpp +++ b/iceoryx_dust/posix/ipc/include/iox/named_pipe.hpp @@ -14,8 +14,9 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#ifndef IOX_DUST_POSIX_WRAPPER_NAMED_PIPE_HPP -#define IOX_DUST_POSIX_WRAPPER_NAMED_PIPE_HPP + +#ifndef IOX_DUST_POSIX_IPC_NAMED_PIPE_HPP +#define IOX_DUST_POSIX_IPC_NAMED_PIPE_HPP #include "iceoryx_hoofs/concurrent/lockfree_queue.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp" @@ -34,8 +35,6 @@ namespace iox { -namespace posix -{ class NamedPipeBuilder; class NamedPipe @@ -71,51 +70,51 @@ class NamedPipe /// @brief removes a named pipe artifact from the system /// @return true if the artifact was removed, false when no artifact was found and /// IpcChannelError::INTERNAL_LOGIC_ERROR when shm_unlink failed - static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; + static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; /// @brief tries to send a message via the named pipe. if the pipe is full IpcChannelError::TIMEOUT is returned /// @return on failure an error which describes the failure - expected trySend(const std::string& message) const noexcept; + expected trySend(const std::string& message) const noexcept; /// @brief sends a message via the named pipe. if the pipe is full this call is blocking until the message could be /// delivered /// @param[in] message the message which should be sent, is not allowed to be longer then MAX_MESSAGE_SIZE /// @return success when message was sent otherwise an error which describes the failure - expected send(const std::string& message) const noexcept; + expected send(const std::string& message) const noexcept; /// @brief sends a message via the named pipe. /// @param[in] message the message which should be sent, is not allowed to be longer then MAX_MESSAGE_SIZE /// @param[in] timeout the timeout on how long this method should retry to send the message /// @return success when message was sent otherwise an error which describes the failure - expected timedSend(const std::string& message, - const units::Duration& timeout) const noexcept; + expected timedSend(const std::string& message, + const units::Duration& timeout) const noexcept; /// @brief tries to receive a message via the named pipe. if the pipe is empty IpcChannelError::TIMEOUT is returned /// @return on success a string containing the message, otherwise an error which describes the failure - expected tryReceive() const noexcept; + expected tryReceive() const noexcept; /// @brief receives a message via the named pipe. if the pipe is empty this call is blocking until a message was /// received /// @return on success a string containing the message, otherwise an error which describes the failure - expected receive() const noexcept; + expected receive() const noexcept; /// @brief receives a message via the named pipe. /// @param[in] timeout the timeout on how long this method should retry to receive a message /// @return on success a string containing the message, otherwise an error which describes the failure - expected timedReceive(const units::Duration& timeout) const noexcept; + expected timedReceive(const units::Duration& timeout) const noexcept; private: friend class NamedPipeBuilder; class NamedPipeData; - NamedPipe(SharedMemoryObject&& sharedMemory, NamedPipeData* data) noexcept; + NamedPipe(posix::SharedMemoryObject&& sharedMemory, NamedPipeData* data) noexcept; template static IpcChannelName_t mapToSharedMemoryName(const Prefix& p, const IpcChannelName_t& name) noexcept; /// @brief destroys an initialized named pipe. /// @return is always successful - expected destroy() noexcept; + expected destroy() noexcept; class NamedPipeData { @@ -128,10 +127,10 @@ class NamedPipe NamedPipeData& operator=(NamedPipeData&& rhs) = delete; ~NamedPipeData() = default; - UnnamedSemaphore& sendSemaphore() noexcept; - UnnamedSemaphore& receiveSemaphore() noexcept; + posix::UnnamedSemaphore& sendSemaphore() noexcept; + posix::UnnamedSemaphore& receiveSemaphore() noexcept; - expected initialize(const uint32_t maxMsgNumber) noexcept; + expected initialize(const uint32_t maxMsgNumber) noexcept; bool waitForInitialization() const noexcept; bool hasValidState() const noexcept; @@ -145,12 +144,12 @@ class NamedPipe static constexpr units::Duration WAIT_FOR_INIT_SLEEP_TIME = units::Duration::fromMilliseconds(1); std::atomic initializationGuard{INVALID_DATA}; - optional m_sendSemaphore; - optional m_receiveSemaphore; + optional m_sendSemaphore; + optional m_receiveSemaphore; }; private: - SharedMemoryObject m_sharedMemory; + posix::SharedMemoryObject m_sharedMemory; NamedPipeData* m_data = nullptr; }; @@ -160,7 +159,7 @@ class NamedPipeBuilder IOX_BUILDER_PARAMETER(IpcChannelName_t, name, "") /// @brief Defines how the named pipe is opened, i.e. as client or server - IOX_BUILDER_PARAMETER(IpcChannelSide, channelSide, IpcChannelSide::CLIENT) + IOX_BUILDER_PARAMETER(posix::IpcChannelSide, channelSide, posix::IpcChannelSide::CLIENT) /// @brief Defines the max message size of the named pipe IOX_BUILDER_PARAMETER(size_t, maxMsgSize, NamedPipe::MAX_MESSAGE_SIZE) @@ -171,10 +170,9 @@ class NamedPipeBuilder public: /// @brief create a named pipe /// @return On success a 'NamedPipe' is returned and on failure an 'IpcChannelError'. - expected create() const noexcept; + expected create() const noexcept; }; -} // namespace posix } // namespace iox -#endif +#endif // IOX_DUST_POSIX_IPC_NAMED_PIPE_HPP diff --git a/iceoryx_dust/source/posix_wrapper/named_pipe.cpp b/iceoryx_dust/posix/ipc/source/named_pipe.cpp similarity index 99% rename from iceoryx_dust/source/posix_wrapper/named_pipe.cpp rename to iceoryx_dust/posix/ipc/source/named_pipe.cpp index 710c437fee..20663e93d6 100644 --- a/iceoryx_dust/source/posix_wrapper/named_pipe.cpp +++ b/iceoryx_dust/posix/ipc/source/named_pipe.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/named_pipe.hpp" +#include "iox/named_pipe.hpp" #include "iox/bump_allocator.hpp" #include "iox/deadline_timer.hpp" #include "iox/filesystem.hpp" @@ -27,8 +27,8 @@ namespace iox { -namespace posix -{ +using namespace iox::posix; + /// NOLINTJUSTIFICATION see declaration in header /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) constexpr const char NamedPipe::NAMED_PIPE_PREFIX[]; @@ -361,5 +361,4 @@ bool NamedPipe::NamedPipeData::hasValidState() const noexcept return initializationGuard.load() == VALID_DATA; } -} // namespace posix } // namespace iox diff --git a/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp b/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp index b73d34bbd0..b0ce97c127 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp @@ -32,9 +32,9 @@ #include "iox/optional.hpp" #include "iox/relative_pointer.hpp" -#include "iceoryx_dust/posix_wrapper/named_pipe.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp" #include "iox/message_queue.hpp" +#include "iox/named_pipe.hpp" #include #include @@ -50,9 +50,9 @@ namespace iox namespace platform { #if defined(_WIN32) -using IoxIpcChannelType = iox::posix::NamedPipe; +using IoxIpcChannelType = iox::NamedPipe; #elif defined(__FREERTOS__) -using IoxIpcChannelType = iox::posix::NamedPipe; +using IoxIpcChannelType = iox::NamedPipe; #else using IoxIpcChannelType = iox::posix::UnixDomainSocket; #endif diff --git a/iceoryx_posh/source/runtime/ipc_interface_base.cpp b/iceoryx_posh/source/runtime/ipc_interface_base.cpp index 8485720ef7..7c505907ea 100644 --- a/iceoryx_posh/source/runtime/ipc_interface_base.cpp +++ b/iceoryx_posh/source/runtime/ipc_interface_base.cpp @@ -242,7 +242,7 @@ bool IpcInterface::ipcChannelMapsToFile() noexcept } template <> -bool IpcInterface::ipcChannelMapsToFile() noexcept +bool IpcInterface::ipcChannelMapsToFile() noexcept { return true; } @@ -263,7 +263,7 @@ void IpcInterface::cleanupOutdatedIpcChannel(const RuntimeName_t } template class IpcInterface; -template class IpcInterface; +template class IpcInterface; template class IpcInterface; } // namespace runtime diff --git a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp index 271e8de44c..5ab99b5b22 100644 --- a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp +++ b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp @@ -15,11 +15,11 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/named_pipe.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp" #include "iceoryx_platform/platform_settings.hpp" #include "iceoryx_posh/internal/runtime/ipc_interface_base.hpp" #include "iox/message_queue.hpp" +#include "iox/named_pipe.hpp" #include "iox/std_chrono_support.hpp" #include "test.hpp" From 99945155f4a6f2b32103d28ad0c22996378e791b Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 26 Oct 2023 01:14:18 +0200 Subject: [PATCH 25/85] iox-#1391 Move 'signal_watcher' to 'posix/sync' --- iceoryx_dust/BUILD.bazel | 7 +++---- iceoryx_dust/CMakeLists.txt | 10 +++++----- .../sync/include/iox}/signal_watcher.hpp | 13 +++++-------- .../sync/source}/signal_watcher.cpp | 13 ++++++------- ...tcher.cpp => test_posix_sync_signal_watcher.cpp} | 3 ++- .../ice_callbacks_listener_as_class_member.cpp | 4 ++-- .../callbacks/ice_callbacks_publisher.cpp | 4 ++-- .../callbacks/ice_callbacks_subscriber.cpp | 6 +++--- .../complexdata/iox_publisher_complexdata.cpp | 4 ++-- .../complexdata/iox_publisher_vector.cpp | 4 ++-- .../complexdata/iox_subscriber_complexdata.cpp | 4 ++-- .../complexdata/iox_subscriber_vector.cpp | 4 ++-- .../ice_access_control/iox_display_app.cpp | 4 ++-- .../ice_access_control/iox_radar_app.cpp | 4 ++-- iceoryx_examples/icedelivery/iox_publisher.cpp | 4 ++-- .../icedelivery/iox_publisher_untyped.cpp | 4 ++-- iceoryx_examples/icedelivery/iox_subscriber.cpp | 4 ++-- .../icedelivery/iox_subscriber_untyped.cpp | 4 ++-- .../icediscovery/iox_discovery_monitor.cpp | 4 ++-- iceoryx_examples/icediscovery/iox_find_service.cpp | 4 ++-- iceoryx_examples/icediscovery/iox_offer_service.cpp | 4 ++-- .../icediscovery/iox_wait_for_service.cpp | 2 +- .../icehello/iox_publisher_helloworld.cpp | 4 ++-- .../icehello/iox_subscriber_helloworld.cpp | 4 ++-- .../iceoptions/iox_publisher_with_options.cpp | 6 +++--- .../iceoptions/iox_subscriber_with_options.cpp | 4 ++-- .../request_response/client_cxx_basic.cpp | 4 ++-- .../request_response/client_cxx_untyped.cpp | 4 ++-- .../request_response/client_cxx_waitset.cpp | 2 +- .../request_response/server_cxx_basic.cpp | 4 ++-- .../request_response/server_cxx_listener.cpp | 4 ++-- .../request_response/server_cxx_untyped.cpp | 4 ++-- iceoryx_examples/singleprocess/single_process.cpp | 8 ++++---- iceoryx_examples/user_header/publisher_cxx_api.cpp | 4 ++-- .../user_header/publisher_untyped_cxx_api.cpp | 4 ++-- iceoryx_examples/user_header/subscriber_cxx_api.cpp | 4 ++-- .../user_header/subscriber_untyped_cxx_api.cpp | 4 ++-- iceoryx_examples/waitset/ice_waitset_publisher.cpp | 4 ++-- .../include/iceoryx_posh/roudi/roudi_app.hpp | 2 +- .../source/roudi/application/iceoryx_roudi_app.cpp | 4 ++-- iceoryx_posh/source/roudi/application/roudi_app.cpp | 4 ++-- 41 files changed, 94 insertions(+), 98 deletions(-) rename iceoryx_dust/{include/iceoryx_dust/posix_wrapper => posix/sync/include/iox}/signal_watcher.hpp (91%) rename iceoryx_dust/{source/posix_wrapper => posix/sync/source}/signal_watcher.cpp (88%) rename iceoryx_dust/test/moduletests/{test_posix_signal_watcher.cpp => test_posix_sync_signal_watcher.cpp} (98%) diff --git a/iceoryx_dust/BUILD.bazel b/iceoryx_dust/BUILD.bazel index 5374b4573f..578ff24f80 100644 --- a/iceoryx_dust/BUILD.bazel +++ b/iceoryx_dust/BUILD.bazel @@ -33,19 +33,18 @@ cc_library( "cli/source/**/*.cpp", "filesystem/source/**/*.cpp", "posix/ipc/source/**/*.cpp", - "source/**/*.cpp", - "source/**/*.hpp", + "posix/sync/source/**/*.cpp", ]), - hdrs = glob(["include/**"]) + glob(["cli/**"]) + glob(["container/**"]) + glob(["filesystem/**"]) + glob(["memory/**"]) + glob(["utility/**"]) + glob(["posix/ipc/**"]) + glob(["vocabulary/**"]) + [ + hdrs = glob(["cli/**"]) + glob(["container/**"]) + glob(["filesystem/**"]) + glob(["memory/**"]) + glob(["utility/**"]) + glob(["posix/ipc/**"]) + glob(["posix/sync/**"]) + glob(["vocabulary/**"]) + [ ":iceoryx_dust_deployment_hpp", ], includes = [ "cli/include/", "container/include/", "filesystem/include/", - "include", "memory/include/", "posix/ipc/include/", + "posix/sync/include/", "utility/include/", "vocabulary/include/", ], diff --git a/iceoryx_dust/CMakeLists.txt b/iceoryx_dust/CMakeLists.txt index 3f6a43aa1e..f059e2a5ea 100644 --- a/iceoryx_dust/CMakeLists.txt +++ b/iceoryx_dust/CMakeLists.txt @@ -46,22 +46,22 @@ iox_add_library( PRIVATE_LIBS ${ICEORYX_SANITIZER_FLAGS} PRIVATE_LIBS_LINUX ${CODE_COVERAGE_LIBS} PUBLIC_LIBS iceoryx_hoofs::iceoryx_hoofs - BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/include - ${PROJECT_SOURCE_DIR}/cli/include + BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/cli/include ${PROJECT_SOURCE_DIR}/container/include ${PROJECT_SOURCE_DIR}/filesystem/include ${PROJECT_SOURCE_DIR}/memory/include ${PROJECT_SOURCE_DIR}/posix/ipc/include + ${PROJECT_SOURCE_DIR}/posix/sync/include ${PROJECT_SOURCE_DIR}/utility/include ${PROJECT_SOURCE_DIR}/vocabulary/include ${CMAKE_BINARY_DIR}/generated/iceoryx_dust/include INSTALL_INTERFACE include/${PREFIX} - EXPORT_INCLUDE_DIRS include/ - cli/include/ + EXPORT_INCLUDE_DIRS cli/include/ container/include/ filesystem/include/ memory/include/ posix/ipc/include/ + posix/sync/include/ utility/include/ vocabulary/include/ FILES @@ -73,7 +73,7 @@ iox_add_library( filesystem/source/file_reader.cpp posix/ipc/source/message_queue.cpp posix/ipc/source/named_pipe.cpp - source/posix_wrapper/signal_watcher.cpp + posix/sync/source/signal_watcher.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/iceoryx_dust_deployment.hpp.in" diff --git a/iceoryx_dust/include/iceoryx_dust/posix_wrapper/signal_watcher.hpp b/iceoryx_dust/posix/sync/include/iox/signal_watcher.hpp similarity index 91% rename from iceoryx_dust/include/iceoryx_dust/posix_wrapper/signal_watcher.hpp rename to iceoryx_dust/posix/sync/include/iox/signal_watcher.hpp index 5afc615b2d..2923f94d5c 100644 --- a/iceoryx_dust/include/iceoryx_dust/posix_wrapper/signal_watcher.hpp +++ b/iceoryx_dust/posix/sync/include/iox/signal_watcher.hpp @@ -24,8 +24,6 @@ namespace iox { -namespace posix -{ /// @brief The SignalWatcher waits for SIGINT and SIGTERM. One can wait until the /// signal has occurred or ask the watcher if it has occurred. /// @code @@ -33,7 +31,7 @@ namespace posix /// #include /// void loopUntilTerminationRequested() /// { -/// while(!iox::posix::hasTerminationRequested()) +/// while(!iox::hasTerminationRequested()) /// { /// // your algorithm /// } @@ -42,7 +40,7 @@ namespace posix /// // another possibility is to block until SIGINT or SIGTERM has occurred /// void blockUntilCtrlC() { /// // your objects which spawn threads -/// iox::posix::waitForTerminationRequest(); +/// iox::waitForTerminationRequest(); /// } /// @endcode class SignalWatcher @@ -70,11 +68,11 @@ class SignalWatcher private: friend void internalSignalHandler(int) noexcept; mutable std::atomic m_numberOfWaiters{0U}; - mutable optional m_semaphore; + mutable optional m_semaphore; std::atomic_bool m_hasSignalOccurred{false}; - SignalGuard m_sigTermGuard; - SignalGuard m_sigIntGuard; + posix::SignalGuard m_sigTermGuard; + posix::SignalGuard m_sigIntGuard; }; /// @brief convenience function, calls SignalWatcher::getInstance().waitForSignal(); @@ -82,7 +80,6 @@ void waitForTerminationRequest() noexcept; /// @brief convenience function, calls SignalWatcher::getInstance().wasSignalTriggered(); bool hasTerminationRequested() noexcept; -} // namespace posix } // namespace iox #endif diff --git a/iceoryx_dust/source/posix_wrapper/signal_watcher.cpp b/iceoryx_dust/posix/sync/source/signal_watcher.cpp similarity index 88% rename from iceoryx_dust/source/posix_wrapper/signal_watcher.cpp rename to iceoryx_dust/posix/sync/source/signal_watcher.cpp index 9427e3a1b9..73a3d71251 100644 --- a/iceoryx_dust/source/posix_wrapper/signal_watcher.cpp +++ b/iceoryx_dust/posix/sync/source/signal_watcher.cpp @@ -13,13 +13,12 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" + +#include "iox/signal_watcher.hpp" #include "iceoryx_platform/unistd.hpp" namespace iox { -namespace posix -{ void internalSignalHandler(int) noexcept { auto& instance = SignalWatcher::getInstance(); @@ -44,10 +43,11 @@ void internalSignalHandler(int) noexcept SignalWatcher::SignalWatcher() noexcept : m_sigTermGuard( - registerSignalHandler(Signal::TERM, internalSignalHandler).expect("Unable to register Signal::TERM")) - , m_sigIntGuard(registerSignalHandler(Signal::INT, internalSignalHandler).expect("Unable to register Signal::INT")) + registerSignalHandler(posix::Signal::TERM, internalSignalHandler).expect("Unable to register Signal::TERM")) + , m_sigIntGuard( + registerSignalHandler(posix::Signal::INT, internalSignalHandler).expect("Unable to register Signal::INT")) { - UnnamedSemaphoreBuilder() + posix::UnnamedSemaphoreBuilder() .isInterProcessCapable(false) .create(m_semaphore) @@ -88,5 +88,4 @@ bool hasTerminationRequested() noexcept { return SignalWatcher::getInstance().wasSignalTriggered(); } -} // namespace posix } // namespace iox diff --git a/iceoryx_dust/test/moduletests/test_posix_signal_watcher.cpp b/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp similarity index 98% rename from iceoryx_dust/test/moduletests/test_posix_signal_watcher.cpp rename to iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp index 89ea8d3eb2..bd543864f3 100644 --- a/iceoryx_dust/test/moduletests/test_posix_signal_watcher.cpp +++ b/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp @@ -14,15 +14,16 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_hoofs/testing/barrier.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" +#include "iox/signal_watcher.hpp" #include "test.hpp" #include namespace { using namespace ::testing; +using namespace iox; using namespace iox::posix; class SignalWatcherTester : public SignalWatcher diff --git a/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp b/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp index d5048ab7a9..b5209fb006 100644 --- a/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp +++ b/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp @@ -14,12 +14,12 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/listener.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iox/optional.hpp" +#include "iox/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -112,7 +112,7 @@ int main() CounterService counterService; - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); //! [init] return (EXIT_SUCCESS); diff --git a/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp b/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp index 8034ef6df9..29ba9d8085 100644 --- a/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp +++ b/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp @@ -14,9 +14,9 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -32,7 +32,7 @@ void sending() iox::popo::Publisher myPublisherLeft({"Radar", "FrontLeft", "Counter"}); iox::popo::Publisher myPublisherRight({"Radar", "FrontRight", "Counter"}); - for (uint32_t counter = 0U; !iox::posix::hasTerminationRequested(); ++counter) + for (uint32_t counter = 0U; !iox::hasTerminationRequested(); ++counter) { if (counter % 3 == 0) { diff --git a/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp b/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp index e16d147cde..e25cc58569 100644 --- a/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp +++ b/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp @@ -14,12 +14,12 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/listener.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iox/optional.hpp" +#include "iox/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -91,7 +91,7 @@ int main() // send a heartbeat every 4 seconds //! [create heartbeat] std::thread heartbeatThread([&] { - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { heartbeat.trigger(); std::this_thread::sleep_for(std::chrono::seconds(4)); @@ -131,7 +131,7 @@ int main() // wait until someone presses CTRL+C //! [wait for sigterm] - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); //! [wait for sigterm] // optional detachEvent, but not required. diff --git a/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp b/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp index b0bc7d3cb9..8d515a4e41 100644 --- a/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp +++ b/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp @@ -16,9 +16,9 @@ #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" constexpr char APP_NAME[] = "iox-cpp-publisher-complexdata"; @@ -46,7 +46,7 @@ int main() uint64_t ct = 0; // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; publisher.loan() diff --git a/iceoryx_examples/complexdata/iox_publisher_vector.cpp b/iceoryx_examples/complexdata/iox_publisher_vector.cpp index 8be0bad5ec..f1834ac29a 100644 --- a/iceoryx_examples/complexdata/iox_publisher_vector.cpp +++ b/iceoryx_examples/complexdata/iox_publisher_vector.cpp @@ -16,9 +16,9 @@ #include "iox/vector.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" constexpr char APP_NAME[] = "iox-cpp-publisher-vector"; @@ -34,7 +34,7 @@ int main() uint64_t ct = 0; // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { publisher.loan() .and_then([&](auto& sample) { diff --git a/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp b/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp index 5cefb1fea6..35f75181af 100644 --- a/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp +++ b/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp @@ -16,9 +16,9 @@ #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include "iox/string.hpp" constexpr char APP_NAME[] = "iox-cpp-subscriber-complexdata"; @@ -32,7 +32,7 @@ int main() iox::popo::Subscriber subscriber({"Group", "Instance", "ComplexDataTopic"}); // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber.take() .and_then([](auto& sample) { diff --git a/iceoryx_examples/complexdata/iox_subscriber_vector.cpp b/iceoryx_examples/complexdata/iox_subscriber_vector.cpp index c167e23835..90a8779c6b 100644 --- a/iceoryx_examples/complexdata/iox_subscriber_vector.cpp +++ b/iceoryx_examples/complexdata/iox_subscriber_vector.cpp @@ -14,9 +14,9 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include "iox/string.hpp" #include "iox/vector.hpp" @@ -31,7 +31,7 @@ int main() iox::popo::Subscriber> subscriber({"Radar", "FrontRight", "VectorData"}); // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber.take() .and_then([](auto& sample) { diff --git a/iceoryx_examples/ice_access_control/iox_display_app.cpp b/iceoryx_examples/ice_access_control/iox_display_app.cpp index 79cd6f7312..0ce9133e2b 100644 --- a/iceoryx_examples/ice_access_control/iox_display_app.cpp +++ b/iceoryx_examples/ice_access_control/iox_display_app.cpp @@ -16,10 +16,10 @@ #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include @@ -35,7 +35,7 @@ int main() iox::popo::Publisher publisher({"Radar", "HMI-Display", "Object"}); // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { auto takeResult = subscriber.take(); diff --git a/iceoryx_examples/ice_access_control/iox_radar_app.cpp b/iceoryx_examples/ice_access_control/iox_radar_app.cpp index 72b2f2fb6d..36c61ebaac 100644 --- a/iceoryx_examples/ice_access_control/iox_radar_app.cpp +++ b/iceoryx_examples/ice_access_control/iox_radar_app.cpp @@ -16,9 +16,9 @@ #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include @@ -32,7 +32,7 @@ int main() iox::popo::Publisher publisher({"Radar", "FrontLeft", "Object"}); double ct = 0.0; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; diff --git a/iceoryx_examples/icedelivery/iox_publisher.cpp b/iceoryx_examples/icedelivery/iox_publisher.cpp index 6d32a94a2d..0b1ae0d7c4 100644 --- a/iceoryx_examples/icedelivery/iox_publisher.cpp +++ b/iceoryx_examples/icedelivery/iox_publisher.cpp @@ -20,8 +20,8 @@ //! [include publisher] #include "iceoryx_posh/popo/publisher.hpp" //! [include publisher] -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include @@ -41,7 +41,7 @@ int main() //! [create publisher] double ct = 0.0; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; double sampleValue1 = ct + 89; diff --git a/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp b/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp index 735da37808..57ad1a46df 100644 --- a/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp +++ b/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp @@ -20,9 +20,9 @@ //! [include topic data] //! [includes] -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/untyped_publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [includes] #include @@ -39,7 +39,7 @@ int main() //! [create untyped publisher] double ct = 0.0; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; diff --git a/iceoryx_examples/icedelivery/iox_subscriber.cpp b/iceoryx_examples/icedelivery/iox_subscriber.cpp index 8c79034f53..267b61bcb3 100644 --- a/iceoryx_examples/icedelivery/iox_subscriber.cpp +++ b/iceoryx_examples/icedelivery/iox_subscriber.cpp @@ -20,8 +20,8 @@ //! [include subscriber] #include "iceoryx_posh/popo/subscriber.hpp" //! [include subscriber] -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include @@ -37,7 +37,7 @@ int main() //! [create subscriber] // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber .take() diff --git a/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp b/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp index b667027406..a940c738aa 100644 --- a/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp +++ b/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp @@ -18,9 +18,9 @@ //! [includes] #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/untyped_subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [includes] #include @@ -38,7 +38,7 @@ int main() // run until interrupted by Ctrl-C //! [loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber .take() diff --git a/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp b/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp index 88fbbdb939..c182523884 100644 --- a/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp +++ b/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp @@ -18,8 +18,8 @@ #include "discovery_monitor.hpp" //! [include custom discovery] -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include @@ -76,7 +76,7 @@ int main() discovery.registerCallback(callback); //! [register callback] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { // here the app would run its functional code while the // service availability is monitored in the background diff --git a/iceoryx_examples/icediscovery/iox_find_service.cpp b/iceoryx_examples/icediscovery/iox_find_service.cpp index dea81f9550..7f3a42e463 100644 --- a/iceoryx_examples/icediscovery/iox_find_service.cpp +++ b/iceoryx_examples/icediscovery/iox_find_service.cpp @@ -14,8 +14,8 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [include ServiceDiscovery] #include "iceoryx_posh/runtime/service_discovery.hpp" //! [include ServiceDiscovery] @@ -39,7 +39,7 @@ int main() iox::runtime::ServiceDiscovery serviceDiscovery; //! [create ServiceDiscovery object] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { std::cout << "\n=========================================" << std::endl; diff --git a/iceoryx_examples/icediscovery/iox_offer_service.cpp b/iceoryx_examples/icediscovery/iox_offer_service.cpp index 0477015cd6..c05b5a9ac2 100644 --- a/iceoryx_examples/icediscovery/iox_offer_service.cpp +++ b/iceoryx_examples/icediscovery/iox_offer_service.cpp @@ -14,9 +14,9 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" constexpr char APP_NAME[] = "iox-offer-service"; @@ -37,7 +37,7 @@ int main() cameraPublishers.emplace_back(iox::capro::ServiceDescription{"Camera", "BackLeft", "Image"}); bool offer = false; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { if (offer) { diff --git a/iceoryx_examples/icediscovery/iox_wait_for_service.cpp b/iceoryx_examples/icediscovery/iox_wait_for_service.cpp index adde0acfa7..cbdf8e80e8 100644 --- a/iceoryx_examples/icediscovery/iox_wait_for_service.cpp +++ b/iceoryx_examples/icediscovery/iox_wait_for_service.cpp @@ -18,8 +18,8 @@ #include "discovery_blocking.hpp" //! [include custom discovery] -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include diff --git a/iceoryx_examples/icehello/iox_publisher_helloworld.cpp b/iceoryx_examples/icehello/iox_publisher_helloworld.cpp index 160f8d7d91..5394fba6ee 100644 --- a/iceoryx_examples/icehello/iox_publisher_helloworld.cpp +++ b/iceoryx_examples/icehello/iox_publisher_helloworld.cpp @@ -19,7 +19,7 @@ //! [include topic] //! [include sig watcher] -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [include sig watcher] //! [include] @@ -43,7 +43,7 @@ int main() double ct = 0.0; //! [wait for term] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) //! [wait for term] { ++ct; diff --git a/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp b/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp index 68a6c87050..af2f4ba1e1 100644 --- a/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp +++ b/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp @@ -17,9 +17,9 @@ //! [include] #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [include] #include @@ -36,7 +36,7 @@ int main() //! [initialize subscriber] // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [receive] auto takeResult = subscriber.take(); diff --git a/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp b/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp index 357f7692ee..8b898a3416 100644 --- a/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp +++ b/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp @@ -16,9 +16,9 @@ #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include @@ -63,7 +63,7 @@ int main() double ct = 0.0; std::thread publishData([&]() { - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; @@ -76,7 +76,7 @@ int main() } }); - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); // this is optional, but since the iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER option is used, // a slow subscriber might block the shutdown and this call unblocks the publisher diff --git a/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp b/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp index f33931b915..566e396514 100644 --- a/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp +++ b/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp @@ -16,9 +16,9 @@ #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include @@ -76,7 +76,7 @@ int main() //! [subscribe] // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber.take().and_then( [](auto& sample) { std::cout << APP_NAME << " got value: " << sample->x << std::endl; }); diff --git a/iceoryx_examples/request_response/client_cxx_basic.cpp b/iceoryx_examples/request_response/client_cxx_basic.cpp index 7cbbfb2ff3..7e5fd88ec7 100644 --- a/iceoryx_examples/request_response/client_cxx_basic.cpp +++ b/iceoryx_examples/request_response/client_cxx_basic.cpp @@ -17,9 +17,9 @@ //! [iceoryx includes] #include "request_and_response_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/client.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -40,7 +40,7 @@ int main() uint64_t fibonacciCurrent = 1; int64_t requestSequenceId = 0; int64_t expectedResponseSequenceId = requestSequenceId; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [send request] client.loan() diff --git a/iceoryx_examples/request_response/client_cxx_untyped.cpp b/iceoryx_examples/request_response/client_cxx_untyped.cpp index 811d376d70..96793ae311 100644 --- a/iceoryx_examples/request_response/client_cxx_untyped.cpp +++ b/iceoryx_examples/request_response/client_cxx_untyped.cpp @@ -17,9 +17,9 @@ //! [iceoryx includes] #include "request_and_response_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/untyped_client.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -40,7 +40,7 @@ int main() uint64_t fibonacciCurrent = 1; int64_t requestSequenceId = 0; int64_t expectedResponseSequenceId = requestSequenceId; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [send request] client.loan(sizeof(AddRequest), alignof(AddRequest)) diff --git a/iceoryx_examples/request_response/client_cxx_waitset.cpp b/iceoryx_examples/request_response/client_cxx_waitset.cpp index 1490699007..8088b4901f 100644 --- a/iceoryx_examples/request_response/client_cxx_waitset.cpp +++ b/iceoryx_examples/request_response/client_cxx_waitset.cpp @@ -17,11 +17,11 @@ //! [iceoryx includes] #include "request_and_response_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_hoofs/posix_wrapper/signal_handler.hpp" #include "iceoryx_posh/popo/client.hpp" #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include diff --git a/iceoryx_examples/request_response/server_cxx_basic.cpp b/iceoryx_examples/request_response/server_cxx_basic.cpp index 02c5e600a6..3772ce86ef 100644 --- a/iceoryx_examples/request_response/server_cxx_basic.cpp +++ b/iceoryx_examples/request_response/server_cxx_basic.cpp @@ -17,9 +17,9 @@ //! [iceoryx includes] #include "request_and_response_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -36,7 +36,7 @@ int main() //! [create server] //! [process requests in a loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [take request] server.take().and_then([&](const auto& request) { diff --git a/iceoryx_examples/request_response/server_cxx_listener.cpp b/iceoryx_examples/request_response/server_cxx_listener.cpp index 45842cba3e..62ca9d492f 100644 --- a/iceoryx_examples/request_response/server_cxx_listener.cpp +++ b/iceoryx_examples/request_response/server_cxx_listener.cpp @@ -17,10 +17,10 @@ //! [iceoryx includes] #include "request_and_response_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/listener.hpp" #include "iceoryx_posh/popo/server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -76,7 +76,7 @@ int main() //! [attach listener] //! [wait for termination] - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); //! [wait for termination] //! [cleanup] diff --git a/iceoryx_examples/request_response/server_cxx_untyped.cpp b/iceoryx_examples/request_response/server_cxx_untyped.cpp index 3fd6a6debb..651a30a659 100644 --- a/iceoryx_examples/request_response/server_cxx_untyped.cpp +++ b/iceoryx_examples/request_response/server_cxx_untyped.cpp @@ -17,9 +17,9 @@ //! [iceoryx includes] #include "request_and_response_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/untyped_server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -36,7 +36,7 @@ int main() //! [create server] //! [process requests in a loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [take request] server.take().and_then([&](auto& requestPayload) { diff --git a/iceoryx_examples/singleprocess/single_process.cpp b/iceoryx_examples/singleprocess/single_process.cpp index 0a338bb641..f4ae89f5fb 100644 --- a/iceoryx_examples/singleprocess/single_process.cpp +++ b/iceoryx_examples/singleprocess/single_process.cpp @@ -15,7 +15,6 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/iceoryx_posh_config.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/roudi/roudi.hpp" @@ -25,6 +24,7 @@ #include "iceoryx_posh/runtime/posh_runtime_single_process.hpp" #include "iox/detail/convert.hpp" #include "iox/logging.hpp" +#include "iox/signal_watcher.hpp" #include #include @@ -59,7 +59,7 @@ void publisher() //! [send] uint64_t counter{0}; constexpr const char GREEN_RIGHT_ARROW[] = "\033[32m->\033[m "; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { publisher.loan().and_then([&](auto& sample) { sample->counter = counter++; @@ -83,7 +83,7 @@ void subscriber() //! [receive] constexpr const char ORANGE_LEFT_ARROW[] = "\033[33m<-\033[m "; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { if (iox::SubscribeState::SUBSCRIBED == subscriber.getSubscriptionState()) { @@ -136,7 +136,7 @@ int main() //! [run] std::thread publisherThread(publisher), subscriberThread(subscriber); - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); publisherThread.join(); subscriberThread.join(); diff --git a/iceoryx_examples/user_header/publisher_cxx_api.cpp b/iceoryx_examples/user_header/publisher_cxx_api.cpp index e3dfb7b728..78599083af 100644 --- a/iceoryx_examples/user_header/publisher_cxx_api.cpp +++ b/iceoryx_examples/user_header/publisher_cxx_api.cpp @@ -17,9 +17,9 @@ //! [iceoryx includes] #include "user_header_and_payload_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -40,7 +40,7 @@ int main() uint64_t timestamp = 42; uint64_t fibonacciLast = 0; uint64_t fibonacciCurrent = 1; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { auto fibonacciNext = fibonacciCurrent + fibonacciLast; fibonacciLast = fibonacciCurrent; diff --git a/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp b/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp index c52d7cc3a7..02c4116daf 100644 --- a/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp +++ b/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp @@ -17,7 +17,7 @@ //! [iceoryx includes] #include "user_header_and_payload_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [include differs from typed C++ API] #include "iceoryx_posh/popo/untyped_publisher.hpp" //! [include differs from typed C++ API] @@ -42,7 +42,7 @@ int main() uint64_t timestamp = 73; uint64_t fibonacciLast = 0; uint64_t fibonacciCurrent = 1; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { auto fibonacciNext = fibonacciCurrent + fibonacciLast; fibonacciLast = fibonacciCurrent; diff --git a/iceoryx_examples/user_header/subscriber_cxx_api.cpp b/iceoryx_examples/user_header/subscriber_cxx_api.cpp index 4737620610..74bb00d22b 100644 --- a/iceoryx_examples/user_header/subscriber_cxx_api.cpp +++ b/iceoryx_examples/user_header/subscriber_cxx_api.cpp @@ -17,9 +17,9 @@ //! [iceoryx includes] #include "user_header_and_payload_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -37,7 +37,7 @@ int main() //! [create subscriber] //! [poll subscriber for samples in a loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [take sample] subscriber.take().and_then([&](auto& sample) { diff --git a/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp b/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp index ee176ce48a..9272a3671f 100644 --- a/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp +++ b/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp @@ -17,9 +17,9 @@ //! [iceoryx includes] #include "user_header_and_payload_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/untyped_subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -37,7 +37,7 @@ int main() //! [create subscriber] //! [poll subscriber for samples in a loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [take chunk] subscriber.take().and_then([&](auto& userPayload) { diff --git a/iceoryx_examples/waitset/ice_waitset_publisher.cpp b/iceoryx_examples/waitset/ice_waitset_publisher.cpp index 9a692d41db..4fcc03ac35 100644 --- a/iceoryx_examples/waitset/ice_waitset_publisher.cpp +++ b/iceoryx_examples/waitset/ice_waitset_publisher.cpp @@ -14,9 +14,9 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -27,7 +27,7 @@ void sending() iox::runtime::PoshRuntime::initRuntime("iox-cpp-publisher-waitset"); iox::popo::Publisher myPublisher({"Radar", "FrontLeft", "Counter"}); - for (uint32_t counter = 0U; !iox::posix::hasTerminationRequested(); ++counter) + for (uint32_t counter = 0U; !iox::hasTerminationRequested(); ++counter) { myPublisher.publishCopyOf(CounterTopic{counter}) .and_then([&] { std::cout << "Sending: " << counter << std::endl; }) diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp index f7b27751a8..f309e8af47 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp @@ -48,7 +48,7 @@ class RouDiApp protected: /// @brief waits for the next signal to RouDi daemon [[deprecated("in 3.0, removed in 4.0, use iox::posix::waitForTerminationRequest() from " - "'iceoryx_dust/posix_wrapper/signal_watcher.hpp'")]] bool + "'iox/signal_watcher.hpp'")]] bool waitForSignal() noexcept; iox::log::LogLevel m_logLevel{iox::log::LogLevel::WARN}; diff --git a/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp b/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp index 19cd9d183f..55d4a7a2c3 100644 --- a/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp +++ b/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp @@ -17,11 +17,11 @@ #include "iceoryx_posh/roudi/iceoryx_roudi_app.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/internal/roudi/roudi.hpp" #include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp" #include "iox/optional.hpp" #include "iox/scoped_static.hpp" +#include "iox/signal_watcher.hpp" namespace iox { @@ -50,7 +50,7 @@ uint8_t IceOryxRouDiApp::run() noexcept m_compatibilityCheckLevel, m_processKillDelay, m_processTeminationDelay}); - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); } return EXIT_SUCCESS; } diff --git a/iceoryx_posh/source/roudi/application/roudi_app.cpp b/iceoryx_posh/source/roudi/application/roudi_app.cpp index a7ed7fff71..7a3987720e 100644 --- a/iceoryx_posh/source/roudi/application/roudi_app.cpp +++ b/iceoryx_posh/source/roudi/application/roudi_app.cpp @@ -17,7 +17,6 @@ #include "iceoryx_posh/roudi/roudi_app.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_platform/getopt.hpp" #include "iceoryx_platform/resource.hpp" #include "iceoryx_platform/semaphore.hpp" @@ -26,6 +25,7 @@ #include "iceoryx_posh/roudi/cmd_line_args.hpp" #include "iox/logging.hpp" #include "iox/optional.hpp" +#include "iox/signal_watcher.hpp" namespace iox { @@ -79,7 +79,7 @@ bool RouDiApp::checkAndOptimizeConfig(const RouDiConfig_t& config) noexcept bool RouDiApp::waitForSignal() noexcept { - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); return true; } From ccd74bb7246c667e7c22d6b9780c037609f206d6 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 26 Oct 2023 03:31:03 +0200 Subject: [PATCH 26/85] iox-#1391 Fix bazel build --- iceoryx_dust/BUILD.bazel | 3 ++- iceoryx_hoofs/BUILD.bazel | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/iceoryx_dust/BUILD.bazel b/iceoryx_dust/BUILD.bazel index 578ff24f80..fd6f6a8699 100644 --- a/iceoryx_dust/BUILD.bazel +++ b/iceoryx_dust/BUILD.bazel @@ -20,7 +20,7 @@ load("//bazel:configure_file.bzl", "configure_file") configure_file( name = "iceoryx_dust_deployment_hpp", src = "cmake/iceoryx_dust_deployment.hpp.in", - out = "include/iox/iceoryx_dust_deployment.hpp", + out = "generated/include/iox/iceoryx_dust_deployment.hpp", config = { "IOX_MAX_NAMED_PIPE_MESSAGE_SIZE": "4096", "IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES": "10", @@ -42,6 +42,7 @@ cc_library( "cli/include/", "container/include/", "filesystem/include/", + "generated/include/", "memory/include/", "posix/ipc/include/", "posix/sync/include/", diff --git a/iceoryx_hoofs/BUILD.bazel b/iceoryx_hoofs/BUILD.bazel index 9de62f34d6..fb1d1d2bbf 100644 --- a/iceoryx_hoofs/BUILD.bazel +++ b/iceoryx_hoofs/BUILD.bazel @@ -21,7 +21,7 @@ load("//bazel:configure_version.bzl", "configure_version") configure_file( name = "iceoryx_hoofs_deployment_hpp", src = "cmake/iceoryx_hoofs_deployment.hpp.in", - out = "include/iox/iceoryx_hoofs_deployment.hpp", + out = "generated/include/iox/iceoryx_hoofs_deployment.hpp", config = { # FIXME: for values see "iceoryx_hoofs/cmake/IceoryxHoofsDeployment.cmake" ... for now some nice defaults "IOX_MINIMAL_LOG_LEVEL": "TRACE", @@ -31,7 +31,7 @@ configure_file( configure_version( name = "iceoryx_versions_h", src = "cmake/iceoryx_versions.h.in", - out = "include/iceoryx_versions.h", + out = "generated/include/iceoryx_versions.h", version_from = "//:VERSION", ) @@ -62,6 +62,7 @@ cc_library( "design/include", "filesystem/include", "functional/include", + "generated/include", "include/", "legacy/include/", "memory/include/", From b85eebe8b071d6bab0be74ff1e44d50f6f63e3bb Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 26 Oct 2023 15:11:09 +0200 Subject: [PATCH 27/85] iox-#1391 Fix Windows build --- iceoryx_dust/posix/ipc/source/message_queue.cpp | 3 ++- iceoryx_dust/posix/ipc/source/named_pipe.cpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/iceoryx_dust/posix/ipc/source/message_queue.cpp b/iceoryx_dust/posix/ipc/source/message_queue.cpp index 5cae8a7b6e..00a4f1d607 100644 --- a/iceoryx_dust/posix/ipc/source/message_queue.cpp +++ b/iceoryx_dust/posix/ipc/source/message_queue.cpp @@ -28,7 +28,8 @@ namespace iox { -using namespace iox::posix; +using posix::IpcChannelError; +using posix::IpcChannelSide; expected MessageQueueBuilder::create() const noexcept { diff --git a/iceoryx_dust/posix/ipc/source/named_pipe.cpp b/iceoryx_dust/posix/ipc/source/named_pipe.cpp index 20663e93d6..87fc817c91 100644 --- a/iceoryx_dust/posix/ipc/source/named_pipe.cpp +++ b/iceoryx_dust/posix/ipc/source/named_pipe.cpp @@ -27,7 +27,16 @@ namespace iox { -using namespace iox::posix; +using posix::AccessMode; +using posix::IpcChannelError; +using posix::IpcChannelSide; +using posix::OpenMode; +using posix::SemaphoreWaitState; +using posix::SharedMemory; +using posix::SharedMemoryObject; +using posix::SharedMemoryObjectBuilder; +using posix::UnnamedSemaphore; +using posix::UnnamedSemaphoreBuilder; /// NOLINTJUSTIFICATION see declaration in header /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) From 7f2d939a12b89c03663621fbe9db115c03ffe5da Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 6 Nov 2023 16:35:02 +0100 Subject: [PATCH 28/85] iox-#1391 Fix race in PortUser_IntegrationTest --- .../test_popo_port_user_building_blocks.cpp | 87 ++++++++++--------- 1 file changed, 45 insertions(+), 42 deletions(-) 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 44c7a08e75..a0176e15b1 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 @@ -111,9 +111,9 @@ class PortUser_IntegrationTest : public Test Watchdog m_deadlockWatchdog{DEADLOCK_TIMEOUT}; - uint64_t m_receiveCounter{0U}; + std::atomic m_receiveCounter{0U}; std::atomic m_sendCounter{0U}; - std::atomic m_publisherRunFinished{0U}; + std::atomic m_publisherRunFinished{false}; // Memory objects iox::BumpAllocator m_memoryAllocator{g_memory, MEMORY_SIZE}; @@ -178,9 +178,7 @@ class PortUser_IntegrationTest : public Test } template - void subscriberThread(uint32_t numberOfPublishers, - SubscriberPortType& subscriberPortRouDi, - SubscriberPortUser& subscriberPortUser) + void subscriberThread(SubscriberPortType& subscriberPortRouDi, SubscriberPortUser& subscriberPortUser) { bool finished{false}; @@ -213,17 +211,14 @@ class PortUser_IntegrationTest : public Test // Try to receive chunk subscriberPortUser.tryGetChunk() .and_then([&](auto& chunkHeader) { - m_receiveCounter++; + m_receiveCounter.fetch_add(1, std::memory_order_relaxed); subscriberPortUser.releaseChunk(chunkHeader); }) .or_else([&](auto& result) { if (result == ChunkReceiveResult::NO_CHUNK_AVAILABLE) { // Nothing received -> check if publisher(s) still running - if (m_publisherRunFinished.load(std::memory_order_relaxed) == numberOfPublishers) - { - finished = true; - } + finished = m_publisherRunFinished.load(std::memory_order_relaxed); } else { @@ -298,8 +293,17 @@ class PortUser_IntegrationTest : public Test } // Subscriber is ready to receive -> start sending samples - for (size_t i = 0U; i < ITERATIONS; i++) + size_t i = 0U; + while (i < ITERATIONS) { + // slow down to ensure there is no overflow + auto receiveCounter = m_receiveCounter.load(std::memory_order_relaxed); + auto sendCounter = m_sendCounter.load(std::memory_order_seq_cst); + if (sendCounter - receiveCounter > 100) + { + std::this_thread::yield(); + continue; + } publisherPortUser .tryAllocateChunk(sizeof(DummySample), alignof(DummySample), @@ -310,56 +314,54 @@ class PortUser_IntegrationTest : public Test new (sample) DummySample(); static_cast(sample)->m_dummy = i; publisherPortUser.sendChunk(chunkHeader); - m_sendCounter++; + m_sendCounter.fetch_add(1, std::memory_order_relaxed); }) .or_else([](auto error) { // Errors shall never occur GTEST_FAIL() << "Error in tryAllocateChunk(): " << static_cast(error); }); + ++i; + /// Add some jitter to make thread breathe - std::this_thread::sleep_for(std::chrono::milliseconds(rand() % 4)); + std::this_thread::sleep_for(std::chrono::microseconds(100 + rand() % 50)); } - - // Signal the subscriber thread we're done - m_publisherRunFinished++; } }; -TIMING_TEST_F(PortUser_IntegrationTest, SingleProducer, Repeat(5), [&] { +TEST_F(PortUser_IntegrationTest, SingleProducer) +{ ::testing::Test::RecordProperty("TEST_ID", "bb62ac02-2b7d-4d1c-8699-9f5ba4d9bd5a"); - std::thread subscribingThread([this] { - constexpr uint32_t NUMBER_OF_PUBLISHERS_SINGLE_PRODUCER = 1U; - subscriberThread(NUMBER_OF_PUBLISHERS_SINGLE_PRODUCER, - m_subscriberPortRouDiSingleProducer, - m_subscriberPortUserSingleProducer); - }); + std::thread subscribingThread( + [this] { subscriberThread(m_subscriberPortRouDiSingleProducer, m_subscriberPortUserSingleProducer); }); std::thread publishingThread([this] { constexpr uint32_t INDEX_OF_PUBLISHER_SINGLE_PRODUCER = 0U; publisherThread( INDEX_OF_PUBLISHER_SINGLE_PRODUCER, m_publisherPortRouDiVector.front(), m_publisherPortUserVector.front()); }); - if (subscribingThread.joinable()) + if (publishingThread.joinable()) { - subscribingThread.join(); + publishingThread.join(); } + m_publisherRunFinished.store(true, std::memory_order_relaxed); - if (publishingThread.joinable()) + if (subscribingThread.joinable()) { - publishingThread.join(); + subscribingThread.join(); } - TIMING_TEST_EXPECT_TRUE(m_sendCounter.load(std::memory_order_relaxed) == m_receiveCounter); - TIMING_TEST_EXPECT_FALSE(PortUser_IntegrationTest::m_subscriberPortUserMultiProducer.hasLostChunksSinceLastCall()); -}) + EXPECT_THAT(m_receiveCounter.load(std::memory_order_relaxed), Eq(m_sendCounter.load(std::memory_order_relaxed))); + EXPECT_FALSE(PortUser_IntegrationTest::m_subscriberPortUserMultiProducer.hasLostChunksSinceLastCall()); +} -TIMING_TEST_F(PortUser_IntegrationTest, MultiProducer, Repeat(5), [&] { +TEST_F(PortUser_IntegrationTest, MultiProducer) +{ ::testing::Test::RecordProperty("TEST_ID", "d27279d3-26c0-4489-9208-bd361120525a"); - std::thread subscribingThread([this] { - subscriberThread(NUMBER_OF_PUBLISHERS, m_subscriberPortRouDiMultiProducer, m_subscriberPortUserMultiProducer); - }); + + std::thread subscribingThread( + [this] { subscriberThread(m_subscriberPortRouDiMultiProducer, m_subscriberPortUserMultiProducer); }); for (uint32_t i = 0U; i < NUMBER_OF_PUBLISHERS; i++) { @@ -367,11 +369,6 @@ TIMING_TEST_F(PortUser_IntegrationTest, MultiProducer, Repeat(5), [&] { [i, this] { publisherThread(i, m_publisherPortRouDiVector[i], m_publisherPortUserVector[i]); }); } - if (subscribingThread.joinable()) - { - subscribingThread.join(); - } - for (uint32_t i = 0U; i < NUMBER_OF_PUBLISHERS; i++) { if (m_publisherThreadVector[i].joinable()) @@ -379,9 +376,15 @@ TIMING_TEST_F(PortUser_IntegrationTest, MultiProducer, Repeat(5), [&] { m_publisherThreadVector[i].join(); } } + m_publisherRunFinished.store(true, std::memory_order_relaxed); + + if (subscribingThread.joinable()) + { + subscribingThread.join(); + } - TIMING_TEST_EXPECT_TRUE(m_sendCounter.load(std::memory_order_relaxed) == m_receiveCounter); - TIMING_TEST_EXPECT_FALSE(PortUser_IntegrationTest::m_subscriberPortUserMultiProducer.hasLostChunksSinceLastCall()); -}) + EXPECT_THAT(m_receiveCounter.load(std::memory_order_relaxed), Eq(m_sendCounter.load(std::memory_order_relaxed))); + EXPECT_FALSE(PortUser_IntegrationTest::m_subscriberPortUserMultiProducer.hasLostChunksSinceLastCall()); +} } // namespace From bfa9a9ef15a7b900ddf8eef39987fe9adc4f8b81 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 9 Nov 2023 17:02:34 +0100 Subject: [PATCH 29/85] iox-#1391 Use IOX_EXPECTS_WITH_MSG where appropriate --- iceoryx_binding_c/source/c_runtime.cpp | 6 +++--- .../container/include/iox/detail/forward_list.inl | 10 +++++----- .../container/include/iox/detail/list.inl | 14 +++++++------- iceoryx_hoofs/source/concurrent/loffli.cpp | 8 ++++---- .../roudi_env/source/runtime_test_interface.cpp | 6 +++--- .../source/popo/ports/client_port_roudi.cpp | 2 +- .../testing/mocks/posh_runtime_mock.hpp | 13 +++++++------ 7 files changed, 30 insertions(+), 29 deletions(-) diff --git a/iceoryx_binding_c/source/c_runtime.cpp b/iceoryx_binding_c/source/c_runtime.cpp index 56174e846b..99a2a1ab47 100644 --- a/iceoryx_binding_c/source/c_runtime.cpp +++ b/iceoryx_binding_c/source/c_runtime.cpp @@ -27,9 +27,9 @@ extern "C" { void iox_runtime_init(const char* const name) { - IOX_EXPECTS(name != nullptr && "Runtime name is a nullptr!"); - IOX_EXPECTS(strnlen(name, iox::MAX_RUNTIME_NAME_LENGTH + 1) <= MAX_RUNTIME_NAME_LENGTH - && "Runtime name has more than 100 characters!"); + IOX_EXPECTS_WITH_MSG(name != nullptr, "Runtime name is a nullptr!"); + IOX_EXPECTS_WITH_MSG(strnlen(name, iox::MAX_RUNTIME_NAME_LENGTH + 1) <= MAX_RUNTIME_NAME_LENGTH, + "Runtime name has more than 100 characters!"); PoshRuntime::initRuntime(RuntimeName_t(iox::TruncateToCapacity, name)); } diff --git a/iceoryx_dust/container/include/iox/detail/forward_list.inl b/iceoryx_dust/container/include/iox/detail/forward_list.inl index a92807e42a..1da79860ea 100644 --- a/iceoryx_dust/container/include/iox/detail/forward_list.inl +++ b/iceoryx_dust/container/include/iox/detail/forward_list.inl @@ -329,7 +329,7 @@ template inline T& forward_list::front() noexcept { auto iter = begin(); - IOX_EXPECTS(isValidElementIdx(iter.m_iterListNodeIdx) && "Invalid list element"); + IOX_EXPECTS_WITH_MSG(isValidElementIdx(iter.m_iterListNodeIdx), "Invalid list element"); return *iter; } @@ -337,7 +337,7 @@ template inline const T& forward_list::front() const noexcept { auto citer = cbegin(); - IOX_EXPECTS(isValidElementIdx(citer.m_iterListNodeIdx) && "Invalid list element"); + IOX_EXPECTS_WITH_MSG(isValidElementIdx(citer.m_iterListNodeIdx), "Invalid list element"); return *citer; } @@ -556,7 +556,7 @@ inline void forward_list::setNextIdx(const size_type idx, const siz template inline const T* forward_list::getDataPtrFromIdx(const size_type idx) const noexcept { - IOX_EXPECTS(isValidElementIdx(idx) && "Invalid list element"); + IOX_EXPECTS_WITH_MSG(isValidElementIdx(idx), "Invalid list element"); // safe since m_data entries are aligned to T // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) @@ -597,14 +597,14 @@ inline bool forward_list::isInvalidIterator(const const_iterator& i { // iterator's member m_iterListNodeIdx and nextIndex are not checked here to be <= END_INDEX as this // should (can) never happen though normal list operations. - IOX_EXPECTS(!isInvalidElement(iter.m_iterListNodeIdx) && "invalidated iterator"); + IOX_EXPECTS_WITH_MSG(!isInvalidElement(iter.m_iterListNodeIdx), "invalidated iterator"); return false; } template inline bool forward_list::isInvalidIterOrDifferentLists(const const_iterator& iter) const noexcept { - IOX_EXPECTS((this == iter.m_list) && "iterator of other list can't be used"); + IOX_EXPECTS_WITH_MSG((this == iter.m_list), "iterator of other list can't be used"); return isInvalidIterator(iter); } diff --git a/iceoryx_hoofs/container/include/iox/detail/list.inl b/iceoryx_hoofs/container/include/iox/detail/list.inl index 8c51c82d76..a46db49325 100644 --- a/iceoryx_hoofs/container/include/iox/detail/list.inl +++ b/iceoryx_hoofs/container/include/iox/detail/list.inl @@ -330,7 +330,7 @@ template inline T& list::front() noexcept { auto iter = begin(); - IOX_EXPECTS(isValidElementIdx(iter.m_iterListNodeIdx) && "invalid list element"); + IOX_EXPECTS_WITH_MSG(isValidElementIdx(iter.m_iterListNodeIdx), "invalid list element"); return *iter; } @@ -338,7 +338,7 @@ template inline const T& list::front() const noexcept { auto citer = cbegin(); - IOX_EXPECTS(isValidElementIdx(citer.m_iterListNodeIdx) && "invalid list element"); + IOX_EXPECTS_WITH_MSG(isValidElementIdx(citer.m_iterListNodeIdx), "invalid list element"); return *citer; } @@ -346,7 +346,7 @@ template inline T& list::back() noexcept { auto iter = end(); - IOX_EXPECTS(isValidElementIdx((--iter).m_iterListNodeIdx) && "invalid list element"); + IOX_EXPECTS_WITH_MSG(isValidElementIdx((--iter).m_iterListNodeIdx), "invalid list element"); return *iter; } @@ -354,7 +354,7 @@ template inline const T& list::back() const noexcept { auto citer = cend(); - IOX_EXPECTS(isValidElementIdx((--citer).m_iterListNodeIdx) && "invalid list element"); + IOX_EXPECTS_WITH_MSG(isValidElementIdx((--citer).m_iterListNodeIdx), "invalid list element"); return *citer; } @@ -653,7 +653,7 @@ inline void list::setNextIdx(const size_type idx, const size_type n template inline const T* list::getDataPtrFromIdx(const size_type idx) const noexcept { - IOX_EXPECTS(isValidElementIdx(idx) && "invalid list element"); + IOX_EXPECTS_WITH_MSG(isValidElementIdx(idx), "invalid list element"); /// @NOLINTJUSTIFICATION provide type safe access to the encapsulated untyped m_data array /// @NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) @@ -684,14 +684,14 @@ inline bool list::isInvalidIterator(const const_iterator& iter) con // freeList / invalid elements will have the prevIdx set to INVALID_INDEX // additional check on e.g. nextIdx or m_iterListNodeIdx ( inline bool list::isInvalidIterOrDifferentLists(const const_iterator& iter) const noexcept { - IOX_EXPECTS((this == iter.m_list) && "iterator of other list can't be used"); + IOX_EXPECTS_WITH_MSG((this == iter.m_list), "iterator of other list can't be used"); return isInvalidIterator(iter); } diff --git a/iceoryx_hoofs/source/concurrent/loffli.cpp b/iceoryx_hoofs/source/concurrent/loffli.cpp index 30b2fda26a..b0128cb0dd 100644 --- a/iceoryx_hoofs/source/concurrent/loffli.cpp +++ b/iceoryx_hoofs/source/concurrent/loffli.cpp @@ -25,11 +25,11 @@ namespace concurrent { void LoFFLi::init(not_null freeIndicesMemory, const uint32_t capacity) noexcept { - IOX_EXPECTS(capacity > 0 && "A capacity of 0 is not supported!"); + IOX_EXPECTS_WITH_MSG(capacity > 0, "A capacity of 0 is not supported!"); constexpr uint32_t INTERNALLY_RESERVED_INDICES{1U}; - IOX_EXPECTS(capacity < (std::numeric_limits::max() - INTERNALLY_RESERVED_INDICES) - && "Requested capacity exceeds limits!"); - IOX_EXPECTS(m_head.is_lock_free() && "std::atomic must be lock-free!"); + IOX_EXPECTS_WITH_MSG(capacity < (std::numeric_limits::max() - INTERNALLY_RESERVED_INDICES), + "Requested capacity exceeds limits!"); + IOX_EXPECTS_WITH_MSG(m_head.is_lock_free(), "std::atomic must be lock-free!"); m_nextFreeIndex = freeIndicesMemory; m_size = capacity; diff --git a/iceoryx_posh/roudi_env/source/runtime_test_interface.cpp b/iceoryx_posh/roudi_env/source/runtime_test_interface.cpp index 84dfd87ca6..de0845c1de 100644 --- a/iceoryx_posh/roudi_env/source/runtime_test_interface.cpp +++ b/iceoryx_posh/roudi_env/source/runtime_test_interface.cpp @@ -36,9 +36,9 @@ RuntimeTestInterface::RuntimeTestInterface() { std::lock_guard lock(RuntimeTestInterface::s_runtimeAccessMutex); - IOX_EXPECTS(PoshRuntime::getRuntimeFactory() == PoshRuntime::defaultRuntimeFactory - && "The RuntimeTestInterface can only be used in combination with the " - "PoshRuntime::defaultRuntimeFactory! Someone else already switched the factory!"); + IOX_EXPECTS_WITH_MSG(PoshRuntime::getRuntimeFactory() == PoshRuntime::defaultRuntimeFactory, + "The RuntimeTestInterface can only be used in combination with the " + "PoshRuntime::defaultRuntimeFactory! Someone else already switched the factory!"); PoshRuntime::setRuntimeFactory(RuntimeTestInterface::runtimeFactoryGetInstance); } diff --git a/iceoryx_posh/source/popo/ports/client_port_roudi.cpp b/iceoryx_posh/source/popo/ports/client_port_roudi.cpp index e7677bedd7..dc3d0e76bd 100644 --- a/iceoryx_posh/source/popo/ports/client_port_roudi.cpp +++ b/iceoryx_posh/source/popo/ports/client_port_roudi.cpp @@ -150,7 +150,7 @@ ClientPortRouDi::handleCaProMessageForStateConnectRequested(const capro::CaproMe switch (caProMessage.m_type) { case capro::CaproMessageType::ACK: - IOX_EXPECTS(caProMessage.m_chunkQueueData != nullptr && "Invalid request queue passed to client"); + IOX_EXPECTS_WITH_MSG(caProMessage.m_chunkQueueData != nullptr, "Invalid request queue passed to client"); IOX_EXPECTS(!m_chunkSender .tryAddQueue(static_cast(caProMessage.m_chunkQueueData), caProMessage.m_historyCapacity) diff --git a/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/posh_runtime_mock.hpp b/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/posh_runtime_mock.hpp index 92c919de2d..889147f84a 100644 --- a/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/posh_runtime_mock.hpp +++ b/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/posh_runtime_mock.hpp @@ -28,10 +28,10 @@ class PoshRuntimeMock : public iox::runtime::PoshRuntime static std::unique_ptr create(const iox::RuntimeName_t& name) { auto& runtime = mockRuntime(); - IOX_EXPECTS(!runtime.has_value() && "Using multiple PoshRuntimeMock in parallel is not supported!"); - IOX_EXPECTS(PoshRuntime::getRuntimeFactory() == PoshRuntime::defaultRuntimeFactory - && "The PoshRuntimeMock can only be used in combination with the " - "PoshRuntime::defaultRuntimeFactory! Someone else already switched the factory!"); + IOX_EXPECTS_WITH_MSG(!runtime.has_value(), "Using multiple PoshRuntimeMock in parallel is not supported!"); + IOX_EXPECTS_WITH_MSG(PoshRuntime::getRuntimeFactory() == PoshRuntime::defaultRuntimeFactory, + "The PoshRuntimeMock can only be used in combination with the " + "PoshRuntime::defaultRuntimeFactory! Someone else already switched the factory!"); runtime = new PoshRuntimeMock(name); PoshRuntime::setRuntimeFactory(mockRuntimeFactory); @@ -95,8 +95,9 @@ class PoshRuntimeMock : public iox::runtime::PoshRuntime static PoshRuntime& mockRuntimeFactory(iox::optional name) noexcept { auto& runtime = mockRuntime(); - IOX_EXPECTS(!name.has_value() && "PoshRuntime::initRuntime must not be used with a PoshRuntimeMock!"); - IOX_EXPECTS(runtime.has_value() && "This should never happen! If you see this, something went horribly wrong!"); + IOX_EXPECTS_WITH_MSG(!name.has_value(), "PoshRuntime::initRuntime must not be used with a PoshRuntimeMock!"); + IOX_EXPECTS_WITH_MSG(runtime.has_value(), + "This should never happen! If you see this, something went horribly wrong!"); return *runtime.value(); } From bd1bdcb1c434ea19ed8e5831c76000b5319ea3de Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 9 Nov 2023 17:46:06 +0100 Subject: [PATCH 30/85] iox-#1391 Re-add posix namespace --- .../release-notes/iceoryx-unreleased.md | 6 +-- .../include/iox/{ => posix}/message_queue.hpp | 43 ++++++++++--------- .../include/iox/{ => posix}/named_pipe.hpp | 39 +++++++++-------- .../posix/ipc/source/message_queue.cpp | 36 ++++++++-------- iceoryx_dust/posix/ipc/source/named_pipe.cpp | 16 ++----- .../iox/{ => posix}/signal_watcher.hpp | 20 +++++---- .../posix/sync/source/signal_watcher.cpp | 12 +++--- .../test_posix_sync_signal_watcher.cpp | 3 +- ...ice_callbacks_listener_as_class_member.cpp | 4 +- .../callbacks/ice_callbacks_publisher.cpp | 4 +- .../callbacks/ice_callbacks_subscriber.cpp | 6 +-- .../complexdata/iox_publisher_complexdata.cpp | 4 +- .../complexdata/iox_publisher_vector.cpp | 4 +- .../iox_subscriber_complexdata.cpp | 4 +- .../complexdata/iox_subscriber_vector.cpp | 4 +- .../ice_access_control/iox_display_app.cpp | 4 +- .../ice_access_control/iox_radar_app.cpp | 4 +- .../icedelivery/iox_publisher.cpp | 4 +- .../icedelivery/iox_publisher_untyped.cpp | 4 +- .../icedelivery/iox_subscriber.cpp | 4 +- .../icedelivery/iox_subscriber_untyped.cpp | 4 +- .../icediscovery/iox_discovery_monitor.cpp | 4 +- .../icediscovery/iox_find_service.cpp | 4 +- .../icediscovery/iox_offer_service.cpp | 4 +- .../icediscovery/iox_wait_for_service.cpp | 2 +- .../icehello/iox_publisher_helloworld.cpp | 4 +- .../icehello/iox_subscriber_helloworld.cpp | 4 +- .../iceoptions/iox_publisher_with_options.cpp | 6 +-- .../iox_subscriber_with_options.cpp | 4 +- .../request_response/client_cxx_basic.cpp | 4 +- .../request_response/client_cxx_untyped.cpp | 4 +- .../request_response/client_cxx_waitset.cpp | 2 +- .../request_response/server_cxx_basic.cpp | 4 +- .../request_response/server_cxx_listener.cpp | 4 +- .../request_response/server_cxx_untyped.cpp | 4 +- .../singleprocess/single_process.cpp | 8 ++-- .../user_header/publisher_cxx_api.cpp | 4 +- .../user_header/publisher_untyped_cxx_api.cpp | 4 +- .../user_header/subscriber_cxx_api.cpp | 4 +- .../subscriber_untyped_cxx_api.cpp | 4 +- .../waitset/ice_waitset_publisher.cpp | 4 +- iceoryx_hoofs/cmake/IceoryxPlatform.cmake | 2 +- .../internal/runtime/ipc_interface_base.hpp | 8 ++-- .../include/iceoryx_posh/roudi/roudi_app.hpp | 2 +- .../roudi/application/iceoryx_roudi_app.cpp | 4 +- .../source/roudi/application/roudi_app.cpp | 4 +- .../source/runtime/ipc_interface_base.cpp | 6 +-- .../test_mq_interface_startup_race.cpp | 2 +- .../test_runtime_ipc_interface.cpp | 4 +- 49 files changed, 171 insertions(+), 172 deletions(-) rename iceoryx_dust/posix/ipc/include/iox/{ => posix}/message_queue.hpp (74%) rename iceoryx_dust/posix/ipc/include/iox/{ => posix}/named_pipe.hpp (82%) rename iceoryx_dust/posix/sync/include/iox/{ => posix}/signal_watcher.hpp (86%) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 147a14741a..fec31c8b56 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -998,7 +998,7 @@ #include "iceoryx_hoofs/posix_wrapper/internal/message_queue.hpp" // after - #include "iox/message_queue.hpp" + #include "iox/posix/message_queue.hpp" ``` ```cpp @@ -1006,7 +1006,7 @@ #include "iceoryx_hoofs/posix_wrapper/named_pipe.hpp" // after - #include "iox/named_pipe.hpp" + #include "iox/posix/named_pipe.hpp" ``` ```cpp @@ -1014,7 +1014,7 @@ #include "iceoryx_hoofs/posix_wrapper/signal_watcher.hpp" // after - #include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" + #include "iox/posix/signal_watcher.hpp" ``` ```cpp diff --git a/iceoryx_dust/posix/ipc/include/iox/message_queue.hpp b/iceoryx_dust/posix/ipc/include/iox/posix/message_queue.hpp similarity index 74% rename from iceoryx_dust/posix/ipc/include/iox/message_queue.hpp rename to iceoryx_dust/posix/ipc/include/iox/posix/message_queue.hpp index 2c2f7a965e..1a48f93d65 100644 --- a/iceoryx_dust/posix/ipc/include/iox/message_queue.hpp +++ b/iceoryx_dust/posix/ipc/include/iox/posix/message_queue.hpp @@ -30,12 +30,14 @@ namespace iox { +namespace posix +{ class MessageQueueBuilder; /// @brief Wrapper class for posix message queue /// /// @code -/// auto mq = iox::MessageQueueBuilder() +/// auto mq = iox::posix::MessageQueueBuilder() /// .name("/MqName123") /// .channelSide(iox::posix::IpcChannelSide::CLIENT) /// .create(); @@ -67,28 +69,27 @@ class MessageQueue ~MessageQueue() noexcept; - static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; + static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; /// @brief send a message to queue using std::string. /// @return true if sent without errors, false otherwise - expected send(const std::string& msg) const noexcept; + expected send(const std::string& msg) const noexcept; /// @todo iox-#1693 zero copy receive with receive(iox::string&); iox::string would be the buffer for mq_receive /// @brief receive message from queue using std::string. /// @return number of characters received. In case of an error, returns -1 and msg is empty. - expected receive() const noexcept; + expected receive() const noexcept; /// @brief try to receive message from queue for a given timeout duration using std::string. Only defined /// for NON_BLOCKING == false. /// @return optional containing the received string. In case of an error, nullopt type is returned. - expected timedReceive(const units::Duration& timeout) const noexcept; + expected timedReceive(const units::Duration& timeout) const noexcept; /// @brief try to send a message to the queue for a given timeout duration using std::string - expected timedSend(const std::string& msg, - const units::Duration& timeout) const noexcept; + expected timedSend(const std::string& msg, const units::Duration& timeout) const noexcept; - static expected isOutdated() noexcept; + static expected isOutdated() noexcept; private: friend class MessageQueueBuilder; @@ -96,24 +97,23 @@ class MessageQueue MessageQueue(const IpcChannelName_t& name, const mq_attr attributes, mqd_t mqDescriptor, - const posix::IpcChannelSide channelSide) noexcept; + const IpcChannelSide channelSide) noexcept; - static expected - open(const IpcChannelName_t& name, mq_attr& attributes, const posix::IpcChannelSide channelSide) noexcept; + static expected + open(const IpcChannelName_t& name, mq_attr& attributes, const IpcChannelSide channelSide) noexcept; - expected close() noexcept; - expected unlink() noexcept; - posix::IpcChannelError errnoToEnum(const int32_t errnum) const noexcept; - static posix::IpcChannelError errnoToEnum(const IpcChannelName_t& name, const int32_t errnum) noexcept; - static expected - sanitizeIpcChannelName(const IpcChannelName_t& name) noexcept; - expected destroy() noexcept; + expected close() noexcept; + expected unlink() noexcept; + IpcChannelError errnoToEnum(const int32_t errnum) const noexcept; + static IpcChannelError errnoToEnum(const IpcChannelName_t& name, const int32_t errnum) noexcept; + static expected sanitizeIpcChannelName(const IpcChannelName_t& name) noexcept; + expected destroy() noexcept; private: IpcChannelName_t m_name; mq_attr m_attributes{}; mqd_t m_mqDescriptor = INVALID_DESCRIPTOR; - posix::IpcChannelSide m_channelSide = posix::IpcChannelSide::CLIENT; + IpcChannelSide m_channelSide = IpcChannelSide::CLIENT; #ifdef __QNX__ static constexpr int TIMEOUT_ERRNO = EINTR; @@ -133,7 +133,7 @@ class MessageQueueBuilder IOX_BUILDER_PARAMETER(IpcChannelName_t, name, "") /// @brief Defines how the message queue is opened, i.e. as client or server - IOX_BUILDER_PARAMETER(posix::IpcChannelSide, channelSide, posix::IpcChannelSide::CLIENT) + IOX_BUILDER_PARAMETER(IpcChannelSide, channelSide, IpcChannelSide::CLIENT) /// @brief Defines the max message size of the message queue IOX_BUILDER_PARAMETER(uint64_t, maxMsgSize, MessageQueue::MAX_MESSAGE_SIZE) @@ -144,9 +144,10 @@ class MessageQueueBuilder public: /// @brief create a message queue /// @return On success a 'MessageQueue' is returned and on failure an 'IpcChannelError'. - expected create() const noexcept; + expected create() const noexcept; }; +} // namespace posix } // namespace iox #endif // IOX_DUST_POSIX_IPC_MESSAGE_QUEUE_HPP diff --git a/iceoryx_dust/posix/ipc/include/iox/named_pipe.hpp b/iceoryx_dust/posix/ipc/include/iox/posix/named_pipe.hpp similarity index 82% rename from iceoryx_dust/posix/ipc/include/iox/named_pipe.hpp rename to iceoryx_dust/posix/ipc/include/iox/posix/named_pipe.hpp index c227a7360e..f259ce4f64 100644 --- a/iceoryx_dust/posix/ipc/include/iox/named_pipe.hpp +++ b/iceoryx_dust/posix/ipc/include/iox/posix/named_pipe.hpp @@ -35,6 +35,8 @@ namespace iox { +namespace posix +{ class NamedPipeBuilder; class NamedPipe @@ -70,51 +72,51 @@ class NamedPipe /// @brief removes a named pipe artifact from the system /// @return true if the artifact was removed, false when no artifact was found and /// IpcChannelError::INTERNAL_LOGIC_ERROR when shm_unlink failed - static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; + static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; /// @brief tries to send a message via the named pipe. if the pipe is full IpcChannelError::TIMEOUT is returned /// @return on failure an error which describes the failure - expected trySend(const std::string& message) const noexcept; + expected trySend(const std::string& message) const noexcept; /// @brief sends a message via the named pipe. if the pipe is full this call is blocking until the message could be /// delivered /// @param[in] message the message which should be sent, is not allowed to be longer then MAX_MESSAGE_SIZE /// @return success when message was sent otherwise an error which describes the failure - expected send(const std::string& message) const noexcept; + expected send(const std::string& message) const noexcept; /// @brief sends a message via the named pipe. /// @param[in] message the message which should be sent, is not allowed to be longer then MAX_MESSAGE_SIZE /// @param[in] timeout the timeout on how long this method should retry to send the message /// @return success when message was sent otherwise an error which describes the failure - expected timedSend(const std::string& message, - const units::Duration& timeout) const noexcept; + expected timedSend(const std::string& message, + const units::Duration& timeout) const noexcept; /// @brief tries to receive a message via the named pipe. if the pipe is empty IpcChannelError::TIMEOUT is returned /// @return on success a string containing the message, otherwise an error which describes the failure - expected tryReceive() const noexcept; + expected tryReceive() const noexcept; /// @brief receives a message via the named pipe. if the pipe is empty this call is blocking until a message was /// received /// @return on success a string containing the message, otherwise an error which describes the failure - expected receive() const noexcept; + expected receive() const noexcept; /// @brief receives a message via the named pipe. /// @param[in] timeout the timeout on how long this method should retry to receive a message /// @return on success a string containing the message, otherwise an error which describes the failure - expected timedReceive(const units::Duration& timeout) const noexcept; + expected timedReceive(const units::Duration& timeout) const noexcept; private: friend class NamedPipeBuilder; class NamedPipeData; - NamedPipe(posix::SharedMemoryObject&& sharedMemory, NamedPipeData* data) noexcept; + NamedPipe(SharedMemoryObject&& sharedMemory, NamedPipeData* data) noexcept; template static IpcChannelName_t mapToSharedMemoryName(const Prefix& p, const IpcChannelName_t& name) noexcept; /// @brief destroys an initialized named pipe. /// @return is always successful - expected destroy() noexcept; + expected destroy() noexcept; class NamedPipeData { @@ -127,10 +129,10 @@ class NamedPipe NamedPipeData& operator=(NamedPipeData&& rhs) = delete; ~NamedPipeData() = default; - posix::UnnamedSemaphore& sendSemaphore() noexcept; - posix::UnnamedSemaphore& receiveSemaphore() noexcept; + UnnamedSemaphore& sendSemaphore() noexcept; + UnnamedSemaphore& receiveSemaphore() noexcept; - expected initialize(const uint32_t maxMsgNumber) noexcept; + expected initialize(const uint32_t maxMsgNumber) noexcept; bool waitForInitialization() const noexcept; bool hasValidState() const noexcept; @@ -144,12 +146,12 @@ class NamedPipe static constexpr units::Duration WAIT_FOR_INIT_SLEEP_TIME = units::Duration::fromMilliseconds(1); std::atomic initializationGuard{INVALID_DATA}; - optional m_sendSemaphore; - optional m_receiveSemaphore; + optional m_sendSemaphore; + optional m_receiveSemaphore; }; private: - posix::SharedMemoryObject m_sharedMemory; + SharedMemoryObject m_sharedMemory; NamedPipeData* m_data = nullptr; }; @@ -159,7 +161,7 @@ class NamedPipeBuilder IOX_BUILDER_PARAMETER(IpcChannelName_t, name, "") /// @brief Defines how the named pipe is opened, i.e. as client or server - IOX_BUILDER_PARAMETER(posix::IpcChannelSide, channelSide, posix::IpcChannelSide::CLIENT) + IOX_BUILDER_PARAMETER(IpcChannelSide, channelSide, IpcChannelSide::CLIENT) /// @brief Defines the max message size of the named pipe IOX_BUILDER_PARAMETER(size_t, maxMsgSize, NamedPipe::MAX_MESSAGE_SIZE) @@ -170,9 +172,10 @@ class NamedPipeBuilder public: /// @brief create a named pipe /// @return On success a 'NamedPipe' is returned and on failure an 'IpcChannelError'. - expected create() const noexcept; + expected create() const noexcept; }; +} // namespace posix } // namespace iox #endif // IOX_DUST_POSIX_IPC_NAMED_PIPE_HPP diff --git a/iceoryx_dust/posix/ipc/source/message_queue.cpp b/iceoryx_dust/posix/ipc/source/message_queue.cpp index 00a4f1d607..e9336e8c85 100644 --- a/iceoryx_dust/posix/ipc/source/message_queue.cpp +++ b/iceoryx_dust/posix/ipc/source/message_queue.cpp @@ -16,7 +16,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/message_queue.hpp" +#include "iox/posix/message_queue.hpp" #include "iceoryx_hoofs/posix_wrapper/posix_call.hpp" #include "iceoryx_platform/fcntl.hpp" #include "iceoryx_platform/platform_correction.hpp" @@ -28,9 +28,8 @@ namespace iox { -using posix::IpcChannelError; -using posix::IpcChannelSide; - +namespace posix +{ expected MessageQueueBuilder::create() const noexcept { auto sanitzedNameResult = MessageQueue::sanitizeIpcChannelName(m_name); @@ -48,7 +47,7 @@ expected MessageQueueBuilder::create() const noex if (m_channelSide == IpcChannelSide::SERVER) { - posix::posixCall(mq_unlink)(sanitizedName.c_str()) + posixCall(mq_unlink)(sanitizedName.c_str()) .failureReturnValue(MessageQueue::ERROR_CODE) .ignoreErrnos(ENOENT) .evaluate() @@ -135,7 +134,7 @@ expected MessageQueue::unlinkIfExists(const IpcChannelNam } - auto mqCall = posix::posixCall(mq_unlink)(sanitizedIpcChannelName->c_str()) + auto mqCall = posixCall(mq_unlink)(sanitizedIpcChannelName->c_str()) .failureReturnValue(ERROR_CODE) .ignoreErrnos(ENOENT) .evaluate(); @@ -177,9 +176,8 @@ expected MessageQueue::send(const std::string& msg) const return err(IpcChannelError::MESSAGE_TOO_LONG); } - auto mqCall = posix::posixCall(mq_send)(m_mqDescriptor, msg.c_str(), messageSize, 1U) - .failureReturnValue(ERROR_CODE) - .evaluate(); + auto mqCall = + posixCall(mq_send)(m_mqDescriptor, msg.c_str(), messageSize, 1U).failureReturnValue(ERROR_CODE).evaluate(); if (mqCall.has_error()) { @@ -195,7 +193,7 @@ expected MessageQueue::receive() const noexcept /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) char message[MAX_MESSAGE_SIZE]; - auto mqCall = posix::posixCall(mq_receive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr) + auto mqCall = posixCall(mq_receive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr) .failureReturnValue(ERROR_CODE) .evaluate(); @@ -229,11 +227,10 @@ MessageQueue::open(const IpcChannelName_t& name, mq_attr& attributes, const IpcC // the mask will be applied to the permissions, therefore we need to set it to 0 mode_t umaskSaved = umask(0); - auto mqCall = - posix::posixCall(iox_mq_open4)(sanitizedName.c_str(), openFlags, MessageQueue::FILE_MODE, &attributes) - .failureReturnValue(MessageQueue::INVALID_DESCRIPTOR) - .suppressErrorMessagesForErrnos(ENOENT) - .evaluate(); + auto mqCall = posixCall(iox_mq_open4)(sanitizedName.c_str(), openFlags, MessageQueue::FILE_MODE, &attributes) + .failureReturnValue(MessageQueue::INVALID_DESCRIPTOR) + .suppressErrorMessagesForErrnos(ENOENT) + .evaluate(); umask(umaskSaved); @@ -248,7 +245,7 @@ MessageQueue::open(const IpcChannelName_t& name, mq_attr& attributes, const IpcC expected MessageQueue::close() noexcept { - auto mqCall = posix::posixCall(mq_close)(m_mqDescriptor).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = posixCall(mq_close)(m_mqDescriptor).failureReturnValue(ERROR_CODE).evaluate(); if (mqCall.has_error()) { @@ -265,7 +262,7 @@ expected MessageQueue::unlink() noexcept return ok(); } - auto mqCall = posix::posixCall(mq_unlink)(m_name.c_str()).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = posixCall(mq_unlink)(m_name.c_str()).failureReturnValue(ERROR_CODE).evaluate(); if (mqCall.has_error()) { return err(errnoToEnum(mqCall.error().errnum)); @@ -281,7 +278,7 @@ expected MessageQueue::timedReceive(const units::D /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) char message[MAX_MESSAGE_SIZE]; - auto mqCall = posix::posixCall(mq_timedreceive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr, &timeOut) + auto mqCall = posixCall(mq_timedreceive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr, &timeOut) .failureReturnValue(ERROR_CODE) // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT .ignoreErrnos(TIMEOUT_ERRNO) @@ -313,7 +310,7 @@ expected MessageQueue::timedSend(const std::string& msg, timespec timeOut = timeout.timespec(units::TimeSpecReference::Epoch); - auto mqCall = posix::posixCall(mq_timedsend)(m_mqDescriptor, msg.c_str(), messageSize, 1U, &timeOut) + auto mqCall = posixCall(mq_timedsend)(m_mqDescriptor, msg.c_str(), messageSize, 1U, &timeOut) .failureReturnValue(ERROR_CODE) // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT .ignoreErrnos(TIMEOUT_ERRNO) @@ -409,4 +406,5 @@ expected MessageQueue::sanitizeIpcChannelName return ok(name); } +} // namespace posix } // namespace iox diff --git a/iceoryx_dust/posix/ipc/source/named_pipe.cpp b/iceoryx_dust/posix/ipc/source/named_pipe.cpp index 87fc817c91..b112cbcc1b 100644 --- a/iceoryx_dust/posix/ipc/source/named_pipe.cpp +++ b/iceoryx_dust/posix/ipc/source/named_pipe.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/named_pipe.hpp" +#include "iox/posix/named_pipe.hpp" #include "iox/bump_allocator.hpp" #include "iox/deadline_timer.hpp" #include "iox/filesystem.hpp" @@ -27,17 +27,8 @@ namespace iox { -using posix::AccessMode; -using posix::IpcChannelError; -using posix::IpcChannelSide; -using posix::OpenMode; -using posix::SemaphoreWaitState; -using posix::SharedMemory; -using posix::SharedMemoryObject; -using posix::SharedMemoryObjectBuilder; -using posix::UnnamedSemaphore; -using posix::UnnamedSemaphoreBuilder; - +namespace posix +{ /// NOLINTJUSTIFICATION see declaration in header /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) constexpr const char NamedPipe::NAMED_PIPE_PREFIX[]; @@ -370,4 +361,5 @@ bool NamedPipe::NamedPipeData::hasValidState() const noexcept return initializationGuard.load() == VALID_DATA; } +} // namespace posix } // namespace iox diff --git a/iceoryx_dust/posix/sync/include/iox/signal_watcher.hpp b/iceoryx_dust/posix/sync/include/iox/posix/signal_watcher.hpp similarity index 86% rename from iceoryx_dust/posix/sync/include/iox/signal_watcher.hpp rename to iceoryx_dust/posix/sync/include/iox/posix/signal_watcher.hpp index 2923f94d5c..1108f9f3ca 100644 --- a/iceoryx_dust/posix/sync/include/iox/signal_watcher.hpp +++ b/iceoryx_dust/posix/sync/include/iox/posix/signal_watcher.hpp @@ -13,8 +13,9 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#ifndef IOX_DUST_POSIX_WRAPPER_SIGNAL_WATCHER_HPP -#define IOX_DUST_POSIX_WRAPPER_SIGNAL_WATCHER_HPP + +#ifndef IOX_DUST_POSIX_SYNC_SIGNAL_WATCHER_HPP +#define IOX_DUST_POSIX_SYNC_SIGNAL_WATCHER_HPP #include "iceoryx_hoofs/posix_wrapper/signal_handler.hpp" #include "iceoryx_hoofs/posix_wrapper/unnamed_semaphore.hpp" @@ -24,6 +25,8 @@ namespace iox { +namespace posix +{ /// @brief The SignalWatcher waits for SIGINT and SIGTERM. One can wait until the /// signal has occurred or ask the watcher if it has occurred. /// @code @@ -31,7 +34,7 @@ namespace iox /// #include /// void loopUntilTerminationRequested() /// { -/// while(!iox::hasTerminationRequested()) +/// while(!iox::posix::hasTerminationRequested()) /// { /// // your algorithm /// } @@ -40,7 +43,7 @@ namespace iox /// // another possibility is to block until SIGINT or SIGTERM has occurred /// void blockUntilCtrlC() { /// // your objects which spawn threads -/// iox::waitForTerminationRequest(); +/// iox::posix::waitForTerminationRequest(); /// } /// @endcode class SignalWatcher @@ -68,11 +71,11 @@ class SignalWatcher private: friend void internalSignalHandler(int) noexcept; mutable std::atomic m_numberOfWaiters{0U}; - mutable optional m_semaphore; + mutable optional m_semaphore; std::atomic_bool m_hasSignalOccurred{false}; - posix::SignalGuard m_sigTermGuard; - posix::SignalGuard m_sigIntGuard; + SignalGuard m_sigTermGuard; + SignalGuard m_sigIntGuard; }; /// @brief convenience function, calls SignalWatcher::getInstance().waitForSignal(); @@ -80,6 +83,7 @@ void waitForTerminationRequest() noexcept; /// @brief convenience function, calls SignalWatcher::getInstance().wasSignalTriggered(); bool hasTerminationRequested() noexcept; +} // namespace posix } // namespace iox -#endif +#endif // IOX_DUST_POSIX_SYNC_SIGNAL_WATCHER_HPP diff --git a/iceoryx_dust/posix/sync/source/signal_watcher.cpp b/iceoryx_dust/posix/sync/source/signal_watcher.cpp index 73a3d71251..c83472a521 100644 --- a/iceoryx_dust/posix/sync/source/signal_watcher.cpp +++ b/iceoryx_dust/posix/sync/source/signal_watcher.cpp @@ -14,11 +14,13 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include "iceoryx_platform/unistd.hpp" namespace iox { +namespace posix +{ void internalSignalHandler(int) noexcept { auto& instance = SignalWatcher::getInstance(); @@ -43,11 +45,10 @@ void internalSignalHandler(int) noexcept SignalWatcher::SignalWatcher() noexcept : m_sigTermGuard( - registerSignalHandler(posix::Signal::TERM, internalSignalHandler).expect("Unable to register Signal::TERM")) - , m_sigIntGuard( - registerSignalHandler(posix::Signal::INT, internalSignalHandler).expect("Unable to register Signal::INT")) + registerSignalHandler(Signal::TERM, internalSignalHandler).expect("Unable to register Signal::TERM")) + , m_sigIntGuard(registerSignalHandler(Signal::INT, internalSignalHandler).expect("Unable to register Signal::INT")) { - posix::UnnamedSemaphoreBuilder() + UnnamedSemaphoreBuilder() .isInterProcessCapable(false) .create(m_semaphore) @@ -88,4 +89,5 @@ bool hasTerminationRequested() noexcept { return SignalWatcher::getInstance().wasSignalTriggered(); } +} // namespace posix } // namespace iox diff --git a/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp b/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp index bd543864f3..f4c820a67e 100644 --- a/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp +++ b/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp @@ -16,14 +16,13 @@ #include "iceoryx_hoofs/testing/barrier.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include "test.hpp" #include namespace { using namespace ::testing; -using namespace iox; using namespace iox::posix; class SignalWatcherTester : public SignalWatcher diff --git a/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp b/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp index b5209fb006..0ca9b26cb6 100644 --- a/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp +++ b/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iox/optional.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -112,7 +112,7 @@ int main() CounterService counterService; - iox::waitForTerminationRequest(); + iox::posix::waitForTerminationRequest(); //! [init] return (EXIT_SUCCESS); diff --git a/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp b/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp index 29ba9d8085..8ebc494f07 100644 --- a/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp +++ b/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp @@ -16,7 +16,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -32,7 +32,7 @@ void sending() iox::popo::Publisher myPublisherLeft({"Radar", "FrontLeft", "Counter"}); iox::popo::Publisher myPublisherRight({"Radar", "FrontRight", "Counter"}); - for (uint32_t counter = 0U; !iox::hasTerminationRequested(); ++counter) + for (uint32_t counter = 0U; !iox::posix::hasTerminationRequested(); ++counter) { if (counter % 3 == 0) { diff --git a/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp b/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp index e25cc58569..c80e713b09 100644 --- a/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp +++ b/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iox/optional.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -91,7 +91,7 @@ int main() // send a heartbeat every 4 seconds //! [create heartbeat] std::thread heartbeatThread([&] { - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { heartbeat.trigger(); std::this_thread::sleep_for(std::chrono::seconds(4)); @@ -131,7 +131,7 @@ int main() // wait until someone presses CTRL+C //! [wait for sigterm] - iox::waitForTerminationRequest(); + iox::posix::waitForTerminationRequest(); //! [wait for sigterm] // optional detachEvent, but not required. diff --git a/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp b/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp index 8d515a4e41..9ccf54ee4b 100644 --- a/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp +++ b/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" constexpr char APP_NAME[] = "iox-cpp-publisher-complexdata"; @@ -46,7 +46,7 @@ int main() uint64_t ct = 0; // run until interrupted by Ctrl-C - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { ++ct; publisher.loan() diff --git a/iceoryx_examples/complexdata/iox_publisher_vector.cpp b/iceoryx_examples/complexdata/iox_publisher_vector.cpp index f1834ac29a..2e271d2e1e 100644 --- a/iceoryx_examples/complexdata/iox_publisher_vector.cpp +++ b/iceoryx_examples/complexdata/iox_publisher_vector.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" constexpr char APP_NAME[] = "iox-cpp-publisher-vector"; @@ -34,7 +34,7 @@ int main() uint64_t ct = 0; // run until interrupted by Ctrl-C - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { publisher.loan() .and_then([&](auto& sample) { diff --git a/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp b/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp index 35f75181af..0ca1156fc2 100644 --- a/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp +++ b/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include "iox/string.hpp" constexpr char APP_NAME[] = "iox-cpp-subscriber-complexdata"; @@ -32,7 +32,7 @@ int main() iox::popo::Subscriber subscriber({"Group", "Instance", "ComplexDataTopic"}); // run until interrupted by Ctrl-C - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { subscriber.take() .and_then([](auto& sample) { diff --git a/iceoryx_examples/complexdata/iox_subscriber_vector.cpp b/iceoryx_examples/complexdata/iox_subscriber_vector.cpp index 90a8779c6b..ba2bb825e9 100644 --- a/iceoryx_examples/complexdata/iox_subscriber_vector.cpp +++ b/iceoryx_examples/complexdata/iox_subscriber_vector.cpp @@ -16,7 +16,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include "iox/string.hpp" #include "iox/vector.hpp" @@ -31,7 +31,7 @@ int main() iox::popo::Subscriber> subscriber({"Radar", "FrontRight", "VectorData"}); // run until interrupted by Ctrl-C - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { subscriber.take() .and_then([](auto& sample) { diff --git a/iceoryx_examples/ice_access_control/iox_display_app.cpp b/iceoryx_examples/ice_access_control/iox_display_app.cpp index 0ce9133e2b..bba273145f 100644 --- a/iceoryx_examples/ice_access_control/iox_display_app.cpp +++ b/iceoryx_examples/ice_access_control/iox_display_app.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include @@ -35,7 +35,7 @@ int main() iox::popo::Publisher publisher({"Radar", "HMI-Display", "Object"}); // run until interrupted by Ctrl-C - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { auto takeResult = subscriber.take(); diff --git a/iceoryx_examples/ice_access_control/iox_radar_app.cpp b/iceoryx_examples/ice_access_control/iox_radar_app.cpp index 36c61ebaac..8222c840b0 100644 --- a/iceoryx_examples/ice_access_control/iox_radar_app.cpp +++ b/iceoryx_examples/ice_access_control/iox_radar_app.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include @@ -32,7 +32,7 @@ int main() iox::popo::Publisher publisher({"Radar", "FrontLeft", "Object"}); double ct = 0.0; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { ++ct; diff --git a/iceoryx_examples/icedelivery/iox_publisher.cpp b/iceoryx_examples/icedelivery/iox_publisher.cpp index 0b1ae0d7c4..6f50237688 100644 --- a/iceoryx_examples/icedelivery/iox_publisher.cpp +++ b/iceoryx_examples/icedelivery/iox_publisher.cpp @@ -21,7 +21,7 @@ #include "iceoryx_posh/popo/publisher.hpp" //! [include publisher] #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include @@ -41,7 +41,7 @@ int main() //! [create publisher] double ct = 0.0; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { ++ct; double sampleValue1 = ct + 89; diff --git a/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp b/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp index 57ad1a46df..f5ce53fdf2 100644 --- a/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp +++ b/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp @@ -22,7 +22,7 @@ //! [includes] #include "iceoryx_posh/popo/untyped_publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [includes] #include @@ -39,7 +39,7 @@ int main() //! [create untyped publisher] double ct = 0.0; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { ++ct; diff --git a/iceoryx_examples/icedelivery/iox_subscriber.cpp b/iceoryx_examples/icedelivery/iox_subscriber.cpp index 267b61bcb3..4477fd0b37 100644 --- a/iceoryx_examples/icedelivery/iox_subscriber.cpp +++ b/iceoryx_examples/icedelivery/iox_subscriber.cpp @@ -21,7 +21,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" //! [include subscriber] #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include @@ -37,7 +37,7 @@ int main() //! [create subscriber] // run until interrupted by Ctrl-C - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { subscriber .take() diff --git a/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp b/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp index a940c738aa..10b82b9f6f 100644 --- a/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp +++ b/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp @@ -20,7 +20,7 @@ #include "iceoryx_posh/popo/untyped_subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [includes] #include @@ -38,7 +38,7 @@ int main() // run until interrupted by Ctrl-C //! [loop] - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { subscriber .take() diff --git a/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp b/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp index c182523884..daf68248d6 100644 --- a/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp +++ b/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp @@ -19,7 +19,7 @@ //! [include custom discovery] #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include @@ -76,7 +76,7 @@ int main() discovery.registerCallback(callback); //! [register callback] - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { // here the app would run its functional code while the // service availability is monitored in the background diff --git a/iceoryx_examples/icediscovery/iox_find_service.cpp b/iceoryx_examples/icediscovery/iox_find_service.cpp index 7f3a42e463..0b3769d05d 100644 --- a/iceoryx_examples/icediscovery/iox_find_service.cpp +++ b/iceoryx_examples/icediscovery/iox_find_service.cpp @@ -15,7 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [include ServiceDiscovery] #include "iceoryx_posh/runtime/service_discovery.hpp" //! [include ServiceDiscovery] @@ -39,7 +39,7 @@ int main() iox::runtime::ServiceDiscovery serviceDiscovery; //! [create ServiceDiscovery object] - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { std::cout << "\n=========================================" << std::endl; diff --git a/iceoryx_examples/icediscovery/iox_offer_service.cpp b/iceoryx_examples/icediscovery/iox_offer_service.cpp index c05b5a9ac2..3643011a6a 100644 --- a/iceoryx_examples/icediscovery/iox_offer_service.cpp +++ b/iceoryx_examples/icediscovery/iox_offer_service.cpp @@ -16,7 +16,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" constexpr char APP_NAME[] = "iox-offer-service"; @@ -37,7 +37,7 @@ int main() cameraPublishers.emplace_back(iox::capro::ServiceDescription{"Camera", "BackLeft", "Image"}); bool offer = false; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { if (offer) { diff --git a/iceoryx_examples/icediscovery/iox_wait_for_service.cpp b/iceoryx_examples/icediscovery/iox_wait_for_service.cpp index cbdf8e80e8..12f5928923 100644 --- a/iceoryx_examples/icediscovery/iox_wait_for_service.cpp +++ b/iceoryx_examples/icediscovery/iox_wait_for_service.cpp @@ -19,7 +19,7 @@ //! [include custom discovery] #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include diff --git a/iceoryx_examples/icehello/iox_publisher_helloworld.cpp b/iceoryx_examples/icehello/iox_publisher_helloworld.cpp index 5394fba6ee..134057c1af 100644 --- a/iceoryx_examples/icehello/iox_publisher_helloworld.cpp +++ b/iceoryx_examples/icehello/iox_publisher_helloworld.cpp @@ -19,7 +19,7 @@ //! [include topic] //! [include sig watcher] -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [include sig watcher] //! [include] @@ -43,7 +43,7 @@ int main() double ct = 0.0; //! [wait for term] - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) //! [wait for term] { ++ct; diff --git a/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp b/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp index af2f4ba1e1..1e850d58d0 100644 --- a/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp +++ b/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [include] #include @@ -36,7 +36,7 @@ int main() //! [initialize subscriber] // run until interrupted by Ctrl-C - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { //! [receive] auto takeResult = subscriber.take(); diff --git a/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp b/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp index 8b898a3416..0e4da4d37e 100644 --- a/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp +++ b/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include @@ -63,7 +63,7 @@ int main() double ct = 0.0; std::thread publishData([&]() { - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { ++ct; @@ -76,7 +76,7 @@ int main() } }); - iox::waitForTerminationRequest(); + iox::posix::waitForTerminationRequest(); // this is optional, but since the iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER option is used, // a slow subscriber might block the shutdown and this call unblocks the publisher diff --git a/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp b/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp index 566e396514..b5d7204054 100644 --- a/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp +++ b/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include @@ -76,7 +76,7 @@ int main() //! [subscribe] // run until interrupted by Ctrl-C - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { subscriber.take().and_then( [](auto& sample) { std::cout << APP_NAME << " got value: " << sample->x << std::endl; }); diff --git a/iceoryx_examples/request_response/client_cxx_basic.cpp b/iceoryx_examples/request_response/client_cxx_basic.cpp index 7e5fd88ec7..66dea43202 100644 --- a/iceoryx_examples/request_response/client_cxx_basic.cpp +++ b/iceoryx_examples/request_response/client_cxx_basic.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/client.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [iceoryx includes] #include @@ -40,7 +40,7 @@ int main() uint64_t fibonacciCurrent = 1; int64_t requestSequenceId = 0; int64_t expectedResponseSequenceId = requestSequenceId; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { //! [send request] client.loan() diff --git a/iceoryx_examples/request_response/client_cxx_untyped.cpp b/iceoryx_examples/request_response/client_cxx_untyped.cpp index 96793ae311..70d657ea1d 100644 --- a/iceoryx_examples/request_response/client_cxx_untyped.cpp +++ b/iceoryx_examples/request_response/client_cxx_untyped.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/untyped_client.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [iceoryx includes] #include @@ -40,7 +40,7 @@ int main() uint64_t fibonacciCurrent = 1; int64_t requestSequenceId = 0; int64_t expectedResponseSequenceId = requestSequenceId; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { //! [send request] client.loan(sizeof(AddRequest), alignof(AddRequest)) diff --git a/iceoryx_examples/request_response/client_cxx_waitset.cpp b/iceoryx_examples/request_response/client_cxx_waitset.cpp index 8088b4901f..040485f7eb 100644 --- a/iceoryx_examples/request_response/client_cxx_waitset.cpp +++ b/iceoryx_examples/request_response/client_cxx_waitset.cpp @@ -21,7 +21,7 @@ #include "iceoryx_posh/popo/client.hpp" #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [iceoryx includes] #include diff --git a/iceoryx_examples/request_response/server_cxx_basic.cpp b/iceoryx_examples/request_response/server_cxx_basic.cpp index 3772ce86ef..322a63a886 100644 --- a/iceoryx_examples/request_response/server_cxx_basic.cpp +++ b/iceoryx_examples/request_response/server_cxx_basic.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [iceoryx includes] #include @@ -36,7 +36,7 @@ int main() //! [create server] //! [process requests in a loop] - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { //! [take request] server.take().and_then([&](const auto& request) { diff --git a/iceoryx_examples/request_response/server_cxx_listener.cpp b/iceoryx_examples/request_response/server_cxx_listener.cpp index 62ca9d492f..96d87ab025 100644 --- a/iceoryx_examples/request_response/server_cxx_listener.cpp +++ b/iceoryx_examples/request_response/server_cxx_listener.cpp @@ -20,7 +20,7 @@ #include "iceoryx_posh/popo/listener.hpp" #include "iceoryx_posh/popo/server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [iceoryx includes] #include @@ -76,7 +76,7 @@ int main() //! [attach listener] //! [wait for termination] - iox::waitForTerminationRequest(); + iox::posix::waitForTerminationRequest(); //! [wait for termination] //! [cleanup] diff --git a/iceoryx_examples/request_response/server_cxx_untyped.cpp b/iceoryx_examples/request_response/server_cxx_untyped.cpp index 651a30a659..577a1ce8c6 100644 --- a/iceoryx_examples/request_response/server_cxx_untyped.cpp +++ b/iceoryx_examples/request_response/server_cxx_untyped.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/untyped_server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [iceoryx includes] #include @@ -36,7 +36,7 @@ int main() //! [create server] //! [process requests in a loop] - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { //! [take request] server.take().and_then([&](auto& requestPayload) { diff --git a/iceoryx_examples/singleprocess/single_process.cpp b/iceoryx_examples/singleprocess/single_process.cpp index f4ae89f5fb..626821e1b2 100644 --- a/iceoryx_examples/singleprocess/single_process.cpp +++ b/iceoryx_examples/singleprocess/single_process.cpp @@ -24,7 +24,7 @@ #include "iceoryx_posh/runtime/posh_runtime_single_process.hpp" #include "iox/detail/convert.hpp" #include "iox/logging.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include #include @@ -59,7 +59,7 @@ void publisher() //! [send] uint64_t counter{0}; constexpr const char GREEN_RIGHT_ARROW[] = "\033[32m->\033[m "; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { publisher.loan().and_then([&](auto& sample) { sample->counter = counter++; @@ -83,7 +83,7 @@ void subscriber() //! [receive] constexpr const char ORANGE_LEFT_ARROW[] = "\033[33m<-\033[m "; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { if (iox::SubscribeState::SUBSCRIBED == subscriber.getSubscriptionState()) { @@ -136,7 +136,7 @@ int main() //! [run] std::thread publisherThread(publisher), subscriberThread(subscriber); - iox::waitForTerminationRequest(); + iox::posix::waitForTerminationRequest(); publisherThread.join(); subscriberThread.join(); diff --git a/iceoryx_examples/user_header/publisher_cxx_api.cpp b/iceoryx_examples/user_header/publisher_cxx_api.cpp index 78599083af..6543a08d11 100644 --- a/iceoryx_examples/user_header/publisher_cxx_api.cpp +++ b/iceoryx_examples/user_header/publisher_cxx_api.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [iceoryx includes] #include @@ -40,7 +40,7 @@ int main() uint64_t timestamp = 42; uint64_t fibonacciLast = 0; uint64_t fibonacciCurrent = 1; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { auto fibonacciNext = fibonacciCurrent + fibonacciLast; fibonacciLast = fibonacciCurrent; diff --git a/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp b/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp index 02c4116daf..8aa4e66d95 100644 --- a/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp +++ b/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp @@ -17,7 +17,7 @@ //! [iceoryx includes] #include "user_header_and_payload_types.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [include differs from typed C++ API] #include "iceoryx_posh/popo/untyped_publisher.hpp" //! [include differs from typed C++ API] @@ -42,7 +42,7 @@ int main() uint64_t timestamp = 73; uint64_t fibonacciLast = 0; uint64_t fibonacciCurrent = 1; - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { auto fibonacciNext = fibonacciCurrent + fibonacciLast; fibonacciLast = fibonacciCurrent; diff --git a/iceoryx_examples/user_header/subscriber_cxx_api.cpp b/iceoryx_examples/user_header/subscriber_cxx_api.cpp index 74bb00d22b..886ce16806 100644 --- a/iceoryx_examples/user_header/subscriber_cxx_api.cpp +++ b/iceoryx_examples/user_header/subscriber_cxx_api.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [iceoryx includes] #include @@ -37,7 +37,7 @@ int main() //! [create subscriber] //! [poll subscriber for samples in a loop] - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { //! [take sample] subscriber.take().and_then([&](auto& sample) { diff --git a/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp b/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp index 9272a3671f..51e41838c3 100644 --- a/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp +++ b/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/untyped_subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" //! [iceoryx includes] #include @@ -37,7 +37,7 @@ int main() //! [create subscriber] //! [poll subscriber for samples in a loop] - while (!iox::hasTerminationRequested()) + while (!iox::posix::hasTerminationRequested()) { //! [take chunk] subscriber.take().and_then([&](auto& userPayload) { diff --git a/iceoryx_examples/waitset/ice_waitset_publisher.cpp b/iceoryx_examples/waitset/ice_waitset_publisher.cpp index 4fcc03ac35..968e06163f 100644 --- a/iceoryx_examples/waitset/ice_waitset_publisher.cpp +++ b/iceoryx_examples/waitset/ice_waitset_publisher.cpp @@ -16,7 +16,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -27,7 +27,7 @@ void sending() iox::runtime::PoshRuntime::initRuntime("iox-cpp-publisher-waitset"); iox::popo::Publisher myPublisher({"Radar", "FrontLeft", "Counter"}); - for (uint32_t counter = 0U; !iox::hasTerminationRequested(); ++counter) + for (uint32_t counter = 0U; !iox::posix::hasTerminationRequested(); ++counter) { myPublisher.publishCopyOf(CounterTopic{counter}) .and_then([&] { std::cout << "Sending: " << counter << std::endl; }) diff --git a/iceoryx_hoofs/cmake/IceoryxPlatform.cmake b/iceoryx_hoofs/cmake/IceoryxPlatform.cmake index 5f143d95ef..293920bb46 100644 --- a/iceoryx_hoofs/cmake/IceoryxPlatform.cmake +++ b/iceoryx_hoofs/cmake/IceoryxPlatform.cmake @@ -80,7 +80,7 @@ function(iox_create_lsan_runtime_blacklist BLACKLIST_FILE_PATH) # count bytes template # 8 642 libacl.so.1 # 1 24 iox::posix::UnixDomainSocket::timedReceive - # 1 24 iox::MessageQueue::receive + # 1 24 iox::posix::MessageQueue::receive if(NOT EXISTS ${BLACKLIST_FILE_PATH}) file(WRITE ${BLACKLIST_FILE_PATH} "# This file is auto-generated from iceoryx_hoofs/cmake/IceoryxPlatform.cmake\n") file(APPEND ${BLACKLIST_FILE_PATH} "#leak:libacl.so.1\n") diff --git a/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp b/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp index b0ce97c127..461b1a417b 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp @@ -33,8 +33,8 @@ #include "iox/relative_pointer.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp" -#include "iox/message_queue.hpp" -#include "iox/named_pipe.hpp" +#include "iox/posix/message_queue.hpp" +#include "iox/posix/named_pipe.hpp" #include #include @@ -50,9 +50,9 @@ namespace iox namespace platform { #if defined(_WIN32) -using IoxIpcChannelType = iox::NamedPipe; +using IoxIpcChannelType = iox::posix::NamedPipe; #elif defined(__FREERTOS__) -using IoxIpcChannelType = iox::NamedPipe; +using IoxIpcChannelType = iox::posix::NamedPipe; #else using IoxIpcChannelType = iox::posix::UnixDomainSocket; #endif diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp index f309e8af47..e5e32bfe08 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp @@ -48,7 +48,7 @@ class RouDiApp protected: /// @brief waits for the next signal to RouDi daemon [[deprecated("in 3.0, removed in 4.0, use iox::posix::waitForTerminationRequest() from " - "'iox/signal_watcher.hpp'")]] bool + "'iox/posix/signal_watcher.hpp'")]] bool waitForSignal() noexcept; iox::log::LogLevel m_logLevel{iox::log::LogLevel::WARN}; diff --git a/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp b/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp index 55d4a7a2c3..5841e2eff8 100644 --- a/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp +++ b/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp @@ -20,8 +20,8 @@ #include "iceoryx_posh/internal/roudi/roudi.hpp" #include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp" #include "iox/optional.hpp" +#include "iox/posix/signal_watcher.hpp" #include "iox/scoped_static.hpp" -#include "iox/signal_watcher.hpp" namespace iox { @@ -50,7 +50,7 @@ uint8_t IceOryxRouDiApp::run() noexcept m_compatibilityCheckLevel, m_processKillDelay, m_processTeminationDelay}); - iox::waitForTerminationRequest(); + iox::posix::waitForTerminationRequest(); } return EXIT_SUCCESS; } diff --git a/iceoryx_posh/source/roudi/application/roudi_app.cpp b/iceoryx_posh/source/roudi/application/roudi_app.cpp index 7a3987720e..9fd29f0e6f 100644 --- a/iceoryx_posh/source/roudi/application/roudi_app.cpp +++ b/iceoryx_posh/source/roudi/application/roudi_app.cpp @@ -25,7 +25,7 @@ #include "iceoryx_posh/roudi/cmd_line_args.hpp" #include "iox/logging.hpp" #include "iox/optional.hpp" -#include "iox/signal_watcher.hpp" +#include "iox/posix/signal_watcher.hpp" namespace iox { @@ -79,7 +79,7 @@ bool RouDiApp::checkAndOptimizeConfig(const RouDiConfig_t& config) noexcept bool RouDiApp::waitForSignal() noexcept { - iox::waitForTerminationRequest(); + iox::posix::waitForTerminationRequest(); return true; } diff --git a/iceoryx_posh/source/runtime/ipc_interface_base.cpp b/iceoryx_posh/source/runtime/ipc_interface_base.cpp index 7c505907ea..bb11b7f6e4 100644 --- a/iceoryx_posh/source/runtime/ipc_interface_base.cpp +++ b/iceoryx_posh/source/runtime/ipc_interface_base.cpp @@ -242,7 +242,7 @@ bool IpcInterface::ipcChannelMapsToFile() noexcept } template <> -bool IpcInterface::ipcChannelMapsToFile() noexcept +bool IpcInterface::ipcChannelMapsToFile() noexcept { return true; } @@ -263,8 +263,8 @@ void IpcInterface::cleanupOutdatedIpcChannel(const RuntimeName_t } template class IpcInterface; -template class IpcInterface; -template class IpcInterface; +template class IpcInterface; +template class IpcInterface; } // namespace runtime } // namespace iox diff --git a/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp b/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp index f8e71c48bc..24aa9d59e4 100644 --- a/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp +++ b/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp @@ -22,7 +22,7 @@ #include "iceoryx_posh/internal/runtime/ipc_message.hpp" #include "iceoryx_posh/internal/runtime/ipc_runtime_interface.hpp" #include "iox/duration.hpp" -#include "iox/message_queue.hpp" +#include "iox/posix/message_queue.hpp" #include "iox/std_string_support.hpp" diff --git a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp index 5ab99b5b22..77bbf6efed 100644 --- a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp +++ b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp @@ -18,8 +18,8 @@ #include "iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp" #include "iceoryx_platform/platform_settings.hpp" #include "iceoryx_posh/internal/runtime/ipc_interface_base.hpp" -#include "iox/message_queue.hpp" -#include "iox/named_pipe.hpp" +#include "iox/posix/message_queue.hpp" +#include "iox/posix/named_pipe.hpp" #include "iox/std_chrono_support.hpp" #include "test.hpp" From 7b5cd753ec4fe1c3dd86642cf238bcea53fc7ed5 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 9 Nov 2023 17:56:40 +0100 Subject: [PATCH 31/85] iox-#1391 Use IOX_DEPRECATED_SINCE where appropriate --- iceoryx_hoofs/vocabulary/include/iox/expected.hpp | 7 ++++--- .../include/iceoryx_posh/roudi/roudi_app.hpp | 6 +++--- .../roudi_environment/roudi_environment.hpp | 15 +++++++-------- .../include/iceoryx_posh/testing/roudi_gtest.hpp | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/iceoryx_hoofs/vocabulary/include/iox/expected.hpp b/iceoryx_hoofs/vocabulary/include/iox/expected.hpp index 12f4a529b4..f4d026070b 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/expected.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/expected.hpp @@ -18,6 +18,7 @@ #define IOX_HOOFS_VOCABULARY_EXPECTED_HPP #include "iox/attributes.hpp" +#include "iox/detail/deprecation_marker.hpp" #include "iox/detail/expected_helper.hpp" #include "iox/functional_interface.hpp" #include "iox/optional.hpp" @@ -243,15 +244,15 @@ class IOX_NO_DISCARD expected final : public FunctionalInterface @@ -47,9 +48,8 @@ class RouDiApp protected: /// @brief waits for the next signal to RouDi daemon - [[deprecated("in 3.0, removed in 4.0, use iox::posix::waitForTerminationRequest() from " - "'iox/posix/signal_watcher.hpp'")]] bool - waitForSignal() noexcept; + IOX_DEPRECATED_SINCE(3, "Please use iox::posix::waitForTerminationRequest() from 'iox/posix/signal_watcher.hpp'") + bool waitForSignal() noexcept; iox::log::LogLevel m_logLevel{iox::log::LogLevel::WARN}; roudi::MonitoringMode m_monitoringMode{roudi::MonitoringMode::ON}; diff --git a/iceoryx_posh/testing/include/iceoryx_posh/testing/roudi_environment/roudi_environment.hpp b/iceoryx_posh/testing/include/iceoryx_posh/testing/roudi_environment/roudi_environment.hpp index 142081490c..594842ec98 100644 --- a/iceoryx_posh/testing/include/iceoryx_posh/testing/roudi_environment/roudi_environment.hpp +++ b/iceoryx_posh/testing/include/iceoryx_posh/testing/roudi_environment/roudi_environment.hpp @@ -19,6 +19,7 @@ #define IOX_POSH_ROUDI_ENVIRONMENT_ROUDI_ENVIRONMENT_HPP #include "iceoryx_posh/roudi_env/roudi_env.hpp" +#include "iox/detail/deprecation_marker.hpp" #include @@ -27,8 +28,7 @@ namespace iox namespace roudi { /// @deprecated Deprecated in 3.0, removed in 4.0, please port to 'iox::roudi_env::RouDiEnv' -class [[deprecated("Deprecated in 3.0, removed in 4.0, please port to 'iox::roudi_env::RouDiEnv'")]] RouDiEnvironment - : public roudi_env::RouDiEnv +class IOX_DEPRECATED_SINCE(3, "Please port to 'iox::roudi_env::RouDiEnv'") RouDiEnvironment : public roudi_env::RouDiEnv { public: using ParentType = roudi_env::RouDiEnv; @@ -36,22 +36,21 @@ class [[deprecated("Deprecated in 3.0, removed in 4.0, please port to 'iox::roud using ParentType::operator=; /// @deprecated Deprecated in 3.0, removed in 4.0, please port to 'setDiscoveryLoopWaitToFinishTimeout' - [[deprecated("Deprecated in 3.0, removed in 4.0, please port to 'setDiscoveryLoopWaitToFinishTimeout'")]] void - SetInterOpWaitingTime(const std::chrono::milliseconds& v) noexcept + IOX_DEPRECATED_SINCE(3, "Please port to 'setDiscoveryLoopWaitToFinishTimeout'") + void SetInterOpWaitingTime(const std::chrono::milliseconds& v) noexcept { setDiscoveryLoopWaitToFinishTimeout(units::Duration::fromMilliseconds(v.count())); } /// @deprecated Deprecated in 3.0, removed in 4.0, please port to 'triggerDiscoveryLoopAndWaitToFinish' - [[deprecated("Deprecated in 3.0, removed in 4.0, please port to 'triggerDiscoveryLoopAndWaitToFinish'")]] void - InterOpWait() noexcept + IOX_DEPRECATED_SINCE(3, "Please port to 'triggerDiscoveryLoopAndWaitToFinish'") void InterOpWait() noexcept { triggerDiscoveryLoopAndWaitToFinish(); } /// @deprecated Deprecated in 3.0, removed in 4.0, please port to 'cleanupAppResources' - [[deprecated("Deprecated in 3.0, removed in 4.0, please port to 'cleanupAppResources'")]] void CleanupAppResources( - const RuntimeName_t& name) noexcept + IOX_DEPRECATED_SINCE(3, "Please port to 'cleanupAppResources'") + void CleanupAppResources(const RuntimeName_t& name) noexcept { cleanupAppResources(name); } diff --git a/iceoryx_posh/testing/include/iceoryx_posh/testing/roudi_gtest.hpp b/iceoryx_posh/testing/include/iceoryx_posh/testing/roudi_gtest.hpp index 50a6dea74a..ccf8dd5bef 100644 --- a/iceoryx_posh/testing/include/iceoryx_posh/testing/roudi_gtest.hpp +++ b/iceoryx_posh/testing/include/iceoryx_posh/testing/roudi_gtest.hpp @@ -18,6 +18,7 @@ #define IOX_POSH_TESTUTILS_ROUDI_GTEST_HPP #include "iceoryx_posh/roudi_env/roudi_env.hpp" +#include "iox/detail/deprecation_marker.hpp" #include #include @@ -33,16 +34,15 @@ class RouDi_GTest : public iox::roudi_env::RouDiEnv, public ::testing::Test RouDi_GTest(const iox::RouDiConfig_t& roudiConfig) noexcept; /// @deprecated Deprecated in 3.0, removed in 4.0, please port to 'setDiscoveryLoopWaitToFinishTimeout' - [[deprecated("Deprecated in 3.0, removed in 4.0, please port to 'setDiscoveryLoopWaitToFinishTimeout'")]] void - SetInterOpWaitingTime(const std::chrono::milliseconds& v) noexcept; + IOX_DEPRECATED_SINCE(3, "Please port to 'setDiscoveryLoopWaitToFinishTimeout'") + void SetInterOpWaitingTime(const std::chrono::milliseconds& v) noexcept; /// @deprecated Deprecated in 3.0, removed in 4.0, please port to 'triggerDiscoveryLoopAndWaitToFinish' - [[deprecated("Deprecated in 3.0, removed in 4.0, please port to 'triggerDiscoveryLoopAndWaitToFinish'")]] void - InterOpWait() noexcept; + IOX_DEPRECATED_SINCE(3, "Please port to 'triggerDiscoveryLoopAndWaitToFinish'") void InterOpWait() noexcept; /// @deprecated Deprecated in 3.0, removed in 4.0, please port to 'cleanupAppResources' - [[deprecated("Deprecated in 3.0, removed in 4.0, please port to 'cleanupAppResources'")]] void - CleanupAppResources(const RuntimeName_t& name) noexcept; + IOX_DEPRECATED_SINCE(3, "Please port to 'cleanupAppResources'") + void CleanupAppResources(const RuntimeName_t& name) noexcept; }; } // namespace testing From 4c83ae8663a27acd8931a21d9d5a1515716bf201 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 9 Nov 2023 18:12:20 +0100 Subject: [PATCH 32/85] iox-#2011 Restrict cirrus-ci to specific branches --- .cirrus.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.cirrus.yaml b/.cirrus.yaml index cd896d4982..06d8fc96fe 100644 --- a/.cirrus.yaml +++ b/.cirrus.yaml @@ -12,6 +12,18 @@ --- +# +# Filter to run the CI only on the master and release branches or for pull request to the master, release* and iox-* branches +# + +only_if: $CIRRUS_BRANCH == 'master' + || $CIRRUS_BRANCH == 'release*' + || ($CIRRUS_PR != '' && ($CIRRUS_BASE_BRANCH == 'master' + || $CIRRUS_BASE_BRANCH == 'release*' + || $CIRRUS_BASE_BRANCH == 'iox-*' + ) + ) + # # Templates # From 19b7623563ce32aef2bcd211be941becc06a49d0 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 9 Nov 2023 18:32:15 +0100 Subject: [PATCH 33/85] iox-#1391 Add misra.org.uk to the link checker ignore list It seems cloudfare introduced some checks which make the link checker fail --- .lycheeignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.lycheeignore b/.lycheeignore index 89eb9f4b0e..fba2101f45 100644 --- a/.lycheeignore +++ b/.lycheeignore @@ -1,4 +1,5 @@ https://github.com/eclipse-iceoryx/iceoryx/compare/vx.x.x...vx.x.x https://github.com/eclipse-iceoryx/iceoryx/tree/vx.x.x +https://www.misra.org.uk/ iceoryx-dev@eclipse.org From 6f6a714c6b48a78fa6c9d58cb1268e144c3bc4e8 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 9 Nov 2023 20:54:40 +0100 Subject: [PATCH 34/85] iox-#1391 Fix 'PortUser_IntegrationTest' timeout on Windows --- .../test_popo_port_user_building_blocks.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 a0176e15b1..31fcf6c8ca 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 @@ -324,7 +324,12 @@ class PortUser_IntegrationTest : public Test ++i; /// Add some jitter to make thread breathe - std::this_thread::sleep_for(std::chrono::microseconds(100 + rand() % 50)); + /// On Windows even when asked for short sleeps the OS suspends the execution for multiple milliseconds; + /// therefore lets sleep only every second iteration + if (i % 2 == 0) + { + std::this_thread::sleep_for(std::chrono::microseconds(100 + rand() % 50)); + } } } }; From 4c78838583f530da0aef3f747f1caa8024a436ee Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Fri, 10 Nov 2023 15:28:11 +0800 Subject: [PATCH 35/85] iox-#2052 Add function `reset_member` Signed-off-by: Dennis Liu When we constrcut `FixedPositionContainer`. We need to make sure that internal status `m_status` be initialized correctly. Note that when the constructor (default / copy / move) is called, the lhs member(`m_status`, `m_next`) are all undefined. Therefore, `reset_member` should be used in every ctor. --- .../iox/detail/fixed_position_container.inl | 32 ++++++++++++------- .../include/iox/fixed_position_container.hpp | 4 +++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index 6a16fe6874..6a9864608a 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -29,18 +29,7 @@ namespace iox template inline FixedPositionContainer::FixedPositionContainer() noexcept { - for (IndexType i = 0; i < CAPACITY;) - { - m_status[i] = SlotStatus::FREE; - - IndexType next = static_cast(i + 1U); - m_next[i] = next; - i = next; - } - m_next[Index::LAST] = Index::INVALID; - - m_begin_free = Index::FIRST; - m_begin_used = Index::INVALID; + reset_member(); } template @@ -58,12 +47,14 @@ inline FixedPositionContainer::~FixedPositionContainer() noexcept template inline FixedPositionContainer::FixedPositionContainer(const FixedPositionContainer& rhs) noexcept { + reset_member(); *this = rhs; } template inline FixedPositionContainer::FixedPositionContainer(FixedPositionContainer&& rhs) noexcept { + reset_member(); *this = std::move(rhs); } @@ -175,6 +166,23 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh m_size = rhs.m_size; } +template +inline void FixedPositionContainer::reset_member() noexcept +{ + for (IndexType i = 0; i < CAPACITY;) + { + m_status[i] = SlotStatus::FREE; + + IndexType next = static_cast(i + 1U); + m_next[i] = next; + i = next; + } + m_next[Index::LAST] = Index::INVALID; + + m_begin_free = Index::FIRST; + m_begin_used = Index::INVALID; +} + template inline void FixedPositionContainer::clear() noexcept { diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index eb4c52672e..ddb7337dd5 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -317,6 +317,10 @@ class FixedPositionContainer final IndexType m_index; }; + private: + /// @brief Initialize member variables to prevent undefined or erroneous values. + void reset_member() noexcept; + template void copy_and_move_impl(RhsType&& rhs) noexcept; From 5ee7097bf3a332a2c725cbfc1be1f54c093f9bc3 Mon Sep 17 00:00:00 2001 From: Dennis Liu Date: Fri, 10 Nov 2023 16:18:12 +0800 Subject: [PATCH 36/85] iox-#2052 Remove reset_member Signed-off-by: Dennis Liu It's can be simply replaced by a `for` loop to set m_status to FREE in copyCtor and assignmentCtor. Therefore, no need to add a new function. --- .../iox/detail/fixed_position_container.inl | 42 ++++++++++--------- .../include/iox/fixed_position_container.hpp | 3 -- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl index 6a9864608a..613ea1aca6 100644 --- a/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_dust/container/include/iox/detail/fixed_position_container.inl @@ -29,7 +29,18 @@ namespace iox template inline FixedPositionContainer::FixedPositionContainer() noexcept { - reset_member(); + for (IndexType i = 0; i < CAPACITY;) + { + m_status[i] = SlotStatus::FREE; + + IndexType next = static_cast(i + 1U); + m_next[i] = next; + i = next; + } + m_next[Index::LAST] = Index::INVALID; + + m_begin_free = Index::FIRST; + m_begin_used = Index::INVALID; } template @@ -47,14 +58,22 @@ inline FixedPositionContainer::~FixedPositionContainer() noexcept template inline FixedPositionContainer::FixedPositionContainer(const FixedPositionContainer& rhs) noexcept { - reset_member(); + for (IndexType i = 0; i < CAPACITY; ++i) + { + m_status[i] = SlotStatus::FREE; + } + *this = rhs; } template inline FixedPositionContainer::FixedPositionContainer(FixedPositionContainer&& rhs) noexcept { - reset_member(); + for (IndexType i = 0; i < CAPACITY; ++i) + { + m_status[i] = SlotStatus::FREE; + } + *this = std::move(rhs); } @@ -166,23 +185,6 @@ inline void FixedPositionContainer::copy_and_move_impl(RhsType&& rh m_size = rhs.m_size; } -template -inline void FixedPositionContainer::reset_member() noexcept -{ - for (IndexType i = 0; i < CAPACITY;) - { - m_status[i] = SlotStatus::FREE; - - IndexType next = static_cast(i + 1U); - m_next[i] = next; - i = next; - } - m_next[Index::LAST] = Index::INVALID; - - m_begin_free = Index::FIRST; - m_begin_used = Index::INVALID; -} - template inline void FixedPositionContainer::clear() noexcept { diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index ddb7337dd5..1b5b458340 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -318,9 +318,6 @@ class FixedPositionContainer final }; private: - /// @brief Initialize member variables to prevent undefined or erroneous values. - void reset_member() noexcept; - template void copy_and_move_impl(RhsType&& rhs) noexcept; From 025fc007b893acc3ac224c78d15c3ac2a03defc9 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 11 Nov 2023 17:55:27 +0100 Subject: [PATCH 37/85] iox-#2047 Fix 'stringop-overflow' warning in 'string.inl' --- .../vocabulary/include/iox/detail/string.inl | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl index d3becd9a12..5726ca4c98 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl +++ b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl @@ -1,5 +1,6 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2021 - 2023 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2023 by Mathias Kraus . 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. @@ -164,17 +165,35 @@ inline string& string::operator=(const char (&rhs)[N]) noexc return *this; } - std::memcpy(m_rawstring, rhs, N); + const auto sourceRawStringSize = static_cast(strnlen(&rhs[0], N)); + if (sourceRawStringSize <= Capacity) + { + m_rawstringSize = sourceRawStringSize; + } + else + { + m_rawstringSize = Capacity; + + IOX_LOG( + WARN, + "iox::string: Assignment of array which is not zero-terminated! Last value of array overwritten with 0!"); + } + + // AXIVION DISABLE STYLE AutosarC++19_03-A16.0.1: pre-processor is required for setting gcc diagnostics, since gcc 8 incorrectly warns here about out of bounds array access + // AXIVION DISABLE STYLE AutosarC++19_03-A16.7.1: see rule 'A16.0.1' above +#if (defined(__GNUC__) && (__GNUC__ == 8)) && (__GNUC_MINOR__ >= 3) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif + std::memcpy(m_rawstring, rhs, m_rawstringSize); +#if (defined(__GNUC__) && (__GNUC__ == 8)) && (__GNUC_MINOR__ >= 3) +#pragma GCC diagnostic pop +#endif + // AXIVION ENABLE STYLE AutosarC++19_03-A16.7.1 + // AXIVION ENABLE STYLE AutosarC++19_03-A16.0.1 - m_rawstringSize = std::min(Capacity, static_cast(strnlen(&rhs[0], N))); m_rawstring[m_rawstringSize] = '\0'; - if (rhs[m_rawstringSize] != '\0') - { - IOX_LOG(WARN, - "iox::string: Assignment of array which is not zero-terminated! Last value of array " - "overwritten with 0!"); - } return *this; } From d88ab623b29096766b191578170d1df203fff7bd Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 11 Nov 2023 17:55:51 +0100 Subject: [PATCH 38/85] iox-#2047 Fix 'self-move' warning in string tests --- iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp index 78d06b9e49..a6b6b6bd27 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp @@ -186,7 +186,14 @@ TYPED_TEST(stringTyped_test, SelfMoveAssignmentExcluded) { ::testing::Test::RecordProperty("TEST_ID", "0ad45975-b68b-465a-b8c5-83dd8d8290d5"); this->testSubject = "M"; +#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wself-move" +#endif this->testSubject = std::move(this->testSubject); +#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#pragma GCC diagnostic pop +#endif EXPECT_THAT(this->testSubject.size(), Eq(1U)); EXPECT_THAT(this->testSubject.c_str(), StrEq("M")); } From 825e2bb8813049744e8fd70f2148928584a66c07 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 11 Nov 2023 18:52:27 +0100 Subject: [PATCH 39/85] iox-#2047 Fix 'stringop-overflow' warning in variant queue --- .../iceoryx_hoofs/cxx/variant_queue.hpp | 2 +- .../internal/cxx/variant_queue.inl | 132 ++++++++++-------- .../vocabulary/include/iox/detail/variant.inl | 20 +++ .../vocabulary/include/iox/variant.hpp | 20 +++ 4 files changed, 114 insertions(+), 60 deletions(-) diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/variant_queue.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/variant_queue.hpp index cf0ef1afec..3c821a0987 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/variant_queue.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/variant_queue.hpp @@ -113,7 +113,7 @@ class VariantQueue uint64_t capacity() const noexcept; private: - VariantQueueTypes m_type; + const VariantQueueTypes m_type; fifo_t m_fifo; }; } // namespace cxx diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant_queue.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant_queue.inl index 1c92ea561f..0c838de273 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant_queue.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant_queue.inl @@ -1,5 +1,6 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2023 by Mathias Kraus . 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. @@ -56,34 +57,38 @@ optional VariantQueue::push(const ValueType& val { case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: { - auto hadSpace = - m_fifo.template get_at_index(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() - ->push(value); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); + auto hadSpace = queue->push(value); return (hadSpace) ? nullopt : make_optional(value); } case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: { ValueType overriddenValue; - auto hadSpace = - m_fifo.template get_at_index(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() - ->push(value, overriddenValue); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); + auto hadSpace = queue->push(value, overriddenValue); return (hadSpace) ? nullopt : make_optional(overriddenValue); } case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: { - auto hadSpace = - m_fifo.template get_at_index(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() - ->tryPush(value); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); + auto hadSpace = queue->tryPush(value); return (hadSpace) ? nullopt : make_optional(value); } case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() - ->push(value); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); + return queue->push(value); } } @@ -97,25 +102,28 @@ inline optional VariantQueue::pop() noexcept { case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() - ->pop(); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); + return queue->pop(); } case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: { ValueType returnType; - auto hasReturnType = - m_fifo.template get_at_index(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() - ->pop(returnType); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); + auto hasReturnType = queue->pop(returnType); return (hasReturnType) ? make_optional(returnType) : nullopt; } case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() - ->pop(); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); + return queue->pop(); } } @@ -129,22 +137,25 @@ inline bool VariantQueue::empty() const noexcept { case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() - ->empty(); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); + return queue->empty(); } case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() - ->empty(); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); + return queue->empty(); } case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() - ->empty(); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); + return queue->empty(); } } @@ -158,25 +169,25 @@ inline uint64_t VariantQueue::size() noexcept { case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() - ->size(); - break; + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); + return queue->size(); } case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() - ->size(); - break; + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); + return queue->size(); } case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() - ->size(); - break; + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); + return queue->size(); } } @@ -197,17 +208,20 @@ inline bool VariantQueue::setCapacity(const uint64_t newCap } case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: { - m_fifo.template get_at_index(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() - ->setCapacity(newCapacity); + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); + queue->setCapacity(newCapacity); return true; } case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: { + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); // we may discard elements in the queue if the size is reduced and the fifo contains too many elements - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() - ->setCapacity(newCapacity); + return queue->setCapacity(newCapacity); } } return false; @@ -220,25 +234,25 @@ inline uint64_t VariantQueue::capacity() const noexcept { case VariantQueueTypes::FiFo_SingleProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>() - ->capacity(); - break; + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_SingleProducerSingleConsumer)>(); + return queue->capacity(); } case VariantQueueTypes::SoFi_SingleProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>() - ->capacity(); - break; + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::SoFi_SingleProducerSingleConsumer)>(); + return queue->capacity(); } case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: { - return m_fifo - .template get_at_index(VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>() - ->capacity(); - break; + // SAFETY: 'm_type' ist 'const' and does not change after construction + auto* queue = m_fifo.template unsafe_get_at_index_unchecked( + VariantQueueTypes::FiFo_MultiProducerSingleConsumer)>(); + return queue->capacity(); } } diff --git a/iceoryx_hoofs/vocabulary/include/iox/detail/variant.inl b/iceoryx_hoofs/vocabulary/include/iox/detail/variant.inl index 4c7c40e00b..3cde2ce018 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/detail/variant.inl +++ b/iceoryx_hoofs/vocabulary/include/iox/detail/variant.inl @@ -1,6 +1,7 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. // Copyright (c) 2021 by Perforce All rights reserved. +// Copyright (c) 2023 by Mathias Kraus . 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. @@ -204,6 +205,14 @@ inline typename internal::get_type_at_index<0, TypeIndex, Types...>::type* varia return nullptr; } + return unsafe_get_at_index_unchecked(); +} + +template +template +inline typename internal::get_type_at_index<0, TypeIndex, Types...>::type* +variant::unsafe_get_at_index_unchecked() noexcept +{ using T = typename internal::get_type_at_index<0, TypeIndex, Types...>::type; // AXIVION Next Construct AutosarC++19_03-M5.2.8 : conversion to typed pointer is intentional, it is correctly aligned and points to sufficient memory for a T by design @@ -221,6 +230,17 @@ variant::get_at_index() const noexcept return const_cast(const_cast(this)->template get_at_index()); } +template +template +inline const typename internal::get_type_at_index<0, TypeIndex, Types...>::type* +variant::unsafe_get_at_index_unchecked() const noexcept +{ + using T = typename internal::get_type_at_index<0, TypeIndex, Types...>::type; + // AXIVION Next Construct AutosarC++19_03-A5.2.3 : avoid code duplication + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) + return const_cast(const_cast(this)->template unsafe_get_at_index_unchecked()); +} + template template inline const T* variant::get() const noexcept diff --git a/iceoryx_hoofs/vocabulary/include/iox/variant.hpp b/iceoryx_hoofs/vocabulary/include/iox/variant.hpp index f142659539..c445568a61 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/variant.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/variant.hpp @@ -1,5 +1,6 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2023 by Mathias Kraus . All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -212,6 +213,15 @@ class variant final template typename internal::get_type_at_index<0, TypeIndex, Types...>::type* get_at_index() noexcept; + /// @brief returns a pointer to the type stored at index TypeIndex. (not stl compliant) + /// @tparam[in] TypeIndex index of the stored type + /// @return a pointer to the type at index + /// @attention this function is unsafe and does not check if the type at the index is the current active one; only + /// use this function when it is ensured that the type at index is indeed the current active one; it is undefined + /// behavior to call this on an index which is not the active type + template + typename internal::get_type_at_index<0, TypeIndex, Types...>::type* unsafe_get_at_index_unchecked() noexcept; + /// @brief returns a pointer to the type stored at index TypeIndex. (not stl compliant) /// @tparam[in] TypeIndex index of the stored type /// @return if the variant does contain the type at index TypeIndex it returns a valid @@ -224,6 +234,16 @@ class variant final template const typename internal::get_type_at_index<0, TypeIndex, Types...>::type* get_at_index() const noexcept; + /// @brief returns a pointer to the type stored at index TypeIndex. (not stl compliant) + /// @tparam[in] TypeIndex index of the stored type + /// @return a const pointer to the type at index + /// @attention this function is unsafe and does not check if the type at the index is the current active one; only + /// use this function when it is ensured that the type at index is indeed the current active one; it is undefined + /// behavior to call this on an index which is not the active type + template + const typename internal::get_type_at_index<0, TypeIndex, Types...>::type* + unsafe_get_at_index_unchecked() const noexcept; + /// @brief returns a pointer to the type T stored in the variant. (not stl compliant) /// @tparam[in] T type of the returned pointer /// @return if the variant does contain the type T it returns a valid pointer otherwise From 4aadeb53840502591bd4476d82b1d783c55082d5 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 11 Nov 2023 18:54:58 +0100 Subject: [PATCH 40/85] iox-#2047 Fix 'array-bounds' warning in chunk distributor --- .../building_blocks/chunk_distributor.hpp | 2 + .../building_blocks/chunk_distributor.inl | 51 +++++++++++-------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp index 9e7e35f3b8..f193c6205b 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp @@ -24,6 +24,8 @@ #include "iox/detail/unique_id.hpp" #include "iox/not_null.hpp" +#include +#include #include namespace iox diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.inl index 2db654d8dc..f4dda63afd 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.inl @@ -1,5 +1,6 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2023 by Mathias Kraus . All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -140,7 +141,8 @@ template inline uint64_t ChunkDistributor::deliverToAllStoredQueues(mepoo::SharedChunk chunk) noexcept { uint64_t numberOfQueuesTheChunkWasDeliveredTo{0U}; - typename ChunkDistributorDataType::QueueContainer_t remainingQueues; + using QueueContainer = decltype(getMembers()->m_queues); + QueueContainer fullQueuesAwaitingDelivery; { typename MemberType_t::LockGuard_t lock(*getMembers()); @@ -158,7 +160,7 @@ inline uint64_t ChunkDistributor::deliverToAllStoredQu { if (isBlockingQueue) { - remainingQueues.emplace_back(queue); + fullQueuesAwaitingDelivery.emplace_back(queue); } else { @@ -171,43 +173,48 @@ inline uint64_t ChunkDistributor::deliverToAllStoredQu // busy waiting until every queue is served iox::detail::adaptive_wait adaptiveWait; - while (!remainingQueues.empty()) + while (!fullQueuesAwaitingDelivery.empty()) { adaptiveWait.wait(); { - // create intersection of current queues and remainingQueues + // create intersection of current queues and fullQueuesAwaitingDelivery // reason: it is possible that since the last iteration some subscriber have already unsubscribed // and without this intersection we would deliver to dead queues typename MemberType_t::LockGuard_t lock(*getMembers()); - typename ChunkDistributorDataType::QueueContainer_t queueIntersection(remainingQueues.size()); - auto greaterThan = [](RelativePointer& a, RelativePointer& b) -> bool { + QueueContainer remainingQueues; + using QueueContainerValue = typename QueueContainer::value_type; + auto greaterThan = [](QueueContainerValue& a, QueueContainerValue& b) -> bool { return reinterpret_cast(a.get()) > reinterpret_cast(b.get()); }; std::sort(getMembers()->m_queues.begin(), getMembers()->m_queues.end(), greaterThan); - std::sort(remainingQueues.begin(), remainingQueues.end(), greaterThan); - auto iter = std::set_intersection(getMembers()->m_queues.begin(), - getMembers()->m_queues.end(), - remainingQueues.begin(), - remainingQueues.end(), - queueIntersection.begin(), - greaterThan); - queueIntersection.resize(static_cast(iter - queueIntersection.begin())); - remainingQueues = queueIntersection; +#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif + std::sort(fullQueuesAwaitingDelivery.begin(), fullQueuesAwaitingDelivery.end(), greaterThan); +#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#pragma GCC diagnostic pop +#endif + + std::set_intersection(getMembers()->m_queues.begin(), + getMembers()->m_queues.end(), + fullQueuesAwaitingDelivery.begin(), + fullQueuesAwaitingDelivery.end(), + std::back_inserter(remainingQueues), + greaterThan); + fullQueuesAwaitingDelivery.clear(); // deliver to remaining queues - for (uint64_t i = remainingQueues.size() - 1U; !remainingQueues.empty(); --i) + for (auto& queue : remainingQueues) { - if (pushToQueue(remainingQueues[i].get(), chunk)) + if (pushToQueue(queue.get(), chunk)) { - remainingQueues.erase(remainingQueues.begin() + i); ++numberOfQueuesTheChunkWasDeliveredTo; } - - // don't move this up since the for loop counts downwards and the algorithm would break - if (i == 0U) + else { - break; + fullQueuesAwaitingDelivery.push_back(queue); } } } From d3266b283dd103a922a4091ad5dc32f1cd4ea540 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sun, 12 Nov 2023 14:29:14 +0100 Subject: [PATCH 41/85] iox-#2047 Fix 'stringop-overflow' warning in shm safe unmagenged chunk --- iceoryx_posh/source/mepoo/shm_safe_unmanaged_chunk.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iceoryx_posh/source/mepoo/shm_safe_unmanaged_chunk.cpp b/iceoryx_posh/source/mepoo/shm_safe_unmanaged_chunk.cpp index ebad953c4d..69173df233 100644 --- a/iceoryx_posh/source/mepoo/shm_safe_unmanaged_chunk.cpp +++ b/iceoryx_posh/source/mepoo/shm_safe_unmanaged_chunk.cpp @@ -71,7 +71,14 @@ SharedChunk ShmSafeUnmanagedChunk::cloneToSharedChunk() noexcept } auto chunkMgmt = RelativePointer(m_chunkManagement.offset(), segment_id_t{m_chunkManagement.id()}); +#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif chunkMgmt->m_referenceCounter.fetch_add(1U, std::memory_order_relaxed); +#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#pragma GCC diagnostic pop +#endif return SharedChunk(chunkMgmt.get()); } From 11b454d57c37576a30031db2b7c00ad9470022eb Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sun, 12 Nov 2023 14:32:55 +0100 Subject: [PATCH 42/85] iox-#2047 Use GCC on Arch Linux --- .cirrus.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.cirrus.yaml b/.cirrus.yaml index cd896d4982..7171c175e6 100644 --- a/.cirrus.yaml +++ b/.cirrus.yaml @@ -132,10 +132,6 @@ arch_linux_x64_build_task: folder: iox-tests-bin reupload_on_changes: true fingerprint_key: $CIRRUS_OS_archlinux_x64_test_binaries_cache - env: - # use clang on Arch Linux since GCC triggers some compiler warnings which abort the job - CC: clang - CXX: clang++ build_script: <<: *IOX_POSIX_CLEAN_BUILD_WITH_ADDITIONAL_USER populate_test_binary_folder_script: From 4af8674ba0b78891e093b155331729204cdc37d9 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 13 Nov 2023 15:22:45 +0100 Subject: [PATCH 43/85] iox-#1663 Update to gTest v1.14.0 --- .../0001-remove-werror-from-build-flags.patch | 18 ------------------ cmake/googletest/CMakeLists.txt | 11 ----------- cmake/googletest/googletest.cmake.in | 2 +- 3 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 cmake/googletest/0001-remove-werror-from-build-flags.patch diff --git a/cmake/googletest/0001-remove-werror-from-build-flags.patch b/cmake/googletest/0001-remove-werror-from-build-flags.patch deleted file mode 100644 index 2a08f5390e..0000000000 --- a/cmake/googletest/0001-remove-werror-from-build-flags.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- /googletest/cmake/internal_utils.cmake -+++ /googletest/cmake/internal_utils.cmake.new -@@ -82,13 +82,13 @@ macro(config_compiler_and_linker) - # http://stackoverflow.com/questions/3232669 explains the issue. - set(cxx_base_flags "${cxx_base_flags} -wd4702") - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") -- set(cxx_base_flags "-Wall -Wshadow -Werror -Wconversion") -+ set(cxx_base_flags "-Wall -Wshadow -Wconversion") - set(cxx_exception_flags "-fexceptions") - set(cxx_no_exception_flags "-fno-exceptions") - set(cxx_strict_flags "-W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls") - set(cxx_no_rtti_flags "-fno-rtti") - elseif (CMAKE_COMPILER_IS_GNUCXX) -- set(cxx_base_flags "-Wall -Wshadow -Werror") -+ set(cxx_base_flags "-Wall -Wshadow") - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0) - set(cxx_base_flags "${cxx_base_flags} -Wno-error=dangling-else") - endif() diff --git a/cmake/googletest/CMakeLists.txt b/cmake/googletest/CMakeLists.txt index 1ef447e34a..0786e3af50 100644 --- a/cmake/googletest/CMakeLists.txt +++ b/cmake/googletest/CMakeLists.txt @@ -76,17 +76,6 @@ if(BUILD_TEST AND NOT GTest_DIR) file(MAKE_DIRECTORY ${BUILD_DIR}) - if(NOT WIN32) - execute_process( - COMMAND git apply -p1 --ignore-space-change --whitespace=nowarn - INPUT_FILE "${CMAKE_CURRENT_LIST_DIR}/0001-remove-werror-from-build-flags.patch" - WORKING_DIRECTORY "${SOURCE_DIR}" - RESULT_VARIABLE result) - if(result) - message(WARNING "CMake step [patch] for googletest failed: ${result}! Build of gtest might fail") - endif() - endif() - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${GTEST_BUILD_ARGS} "${SOURCE_DIR}" RESULT_VARIABLE result WORKING_DIRECTORY ${BUILD_DIR} ) diff --git a/cmake/googletest/googletest.cmake.in b/cmake/googletest/googletest.cmake.in index c639caf4d4..07d1aa7597 100644 --- a/cmake/googletest/googletest.cmake.in +++ b/cmake/googletest/googletest.cmake.in @@ -21,7 +21,7 @@ project(googletest-download NONE) include(ExternalProject) ExternalProject_Add(googletest GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.10.0 + GIT_TAG v1.14.0 SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/googletest/src" BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/googletest/build" CONFIGURE_COMMAND "" From 351cb16c26dd37672e0d4c4a680dbc847af392b4 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 13 Nov 2023 15:57:13 +0100 Subject: [PATCH 44/85] iox-#1663 Remove suppresions warnings with old gTest --- iceoryx_posh/test/mocks/base_port_mock.hpp | 7 ------- iceoryx_posh/test/mocks/client_mock.hpp | 14 ------------- .../test/mocks/roudi_memory_block_mock.hpp | 7 ------- .../test/mocks/roudi_memory_provider_mock.hpp | 14 ------------- iceoryx_posh/test/mocks/server_mock.hpp | 14 ------------- .../test/mocks/trigger_handle_mock.hpp | 14 ------------- .../test_popo_smart_chunk_common.hpp | 21 ------------------- .../testing/mocks/posh_runtime_mock.hpp | 7 ------- 8 files changed, 98 deletions(-) diff --git a/iceoryx_posh/test/mocks/base_port_mock.hpp b/iceoryx_posh/test/mocks/base_port_mock.hpp index cc98076a34..5541569f1d 100644 --- a/iceoryx_posh/test/mocks/base_port_mock.hpp +++ b/iceoryx_posh/test/mocks/base_port_mock.hpp @@ -44,19 +44,12 @@ class MockBasePort return *this; } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(const iox::capro::ServiceDescription&, getCaProServiceDescription, (), (const, noexcept)); MOCK_METHOD(const iox::RuntimeName_t&, getRuntimeName, (), (const, noexcept)); MOCK_METHOD(iox::popo::UniquePortId, getUniqueID, (), (const, noexcept)); MOCK_METHOD(const iox::NodeName_t&, getNodeName, (), (const, noexcept)); MOCK_METHOD(void, destroy, (), (noexcept)); MOCK_METHOD(bool, toBeDestroyed, (), (const, noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif explicit operator bool() const { diff --git a/iceoryx_posh/test/mocks/client_mock.hpp b/iceoryx_posh/test/mocks/client_mock.hpp index dada3e9fd4..b5997ee78e 100644 --- a/iceoryx_posh/test/mocks/client_mock.hpp +++ b/iceoryx_posh/test/mocks/client_mock.hpp @@ -46,10 +46,6 @@ class MockClientPortUser : public MockBasePort return *this; } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD((iox::expected), allocateRequest, (const uint32_t, const uint32_t), @@ -73,9 +69,6 @@ class MockClientPortUser : public MockBasePort MOCK_METHOD(void, setConditionVariable, (iox::popo::ConditionVariableData&, const uint64_t), (noexcept)); MOCK_METHOD(void, unsetConditionVariable, (), (noexcept)); MOCK_METHOD(bool, isConditionVariableSet, (), (const, noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif }; class MockBaseClient @@ -89,10 +82,6 @@ class MockBaseClient { } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(iox::popo::uid_t, getUid, (), (const, noexcept)); MOCK_METHOD(const iox::capro::ServiceDescription&, getServiceDescription, (), (const, noexcept)); MOCK_METHOD(void, connect, (), (noexcept)); @@ -111,9 +100,6 @@ class MockBaseClient MOCK_METHOD(void, disableState, (const iox::popo::ClientState), (noexcept)); MOCK_METHOD(void, enableEvent, (iox::popo::TriggerHandle&&, const iox::popo::ClientEvent), (noexcept)); MOCK_METHOD(void, disableEvent, (const iox::popo::ClientEvent), (noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif const PortType& port() const noexcept diff --git a/iceoryx_posh/test/mocks/roudi_memory_block_mock.hpp b/iceoryx_posh/test/mocks/roudi_memory_block_mock.hpp index e64f0ea4c9..254596627f 100644 --- a/iceoryx_posh/test/mocks/roudi_memory_block_mock.hpp +++ b/iceoryx_posh/test/mocks/roudi_memory_block_mock.hpp @@ -25,17 +25,10 @@ class MemoryBlockMock final : public iox::roudi::MemoryBlock { public: -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(uint64_t, size, (), (const, noexcept, override)); MOCK_METHOD(uint64_t, alignment, (), (const, noexcept, override)); MOCK_METHOD(void, onMemoryAvailable, (iox::not_null), (noexcept, override)); MOCK_METHOD(void, destroy, (), (noexcept, override)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif }; #endif // IOX_POSH_MOCKS_ROUDI_MEMORY_BLOCK_MOCK_HPP diff --git a/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp b/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp index 57af67165a..cc4caea58e 100644 --- a/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp +++ b/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp @@ -49,14 +49,7 @@ class MemoryProviderTestImpl : public iox::roudi::MemoryProvider dummyMemory = iox::alignedAlloc(alignment, size); return iox::ok(dummyMemory); } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(void, createMemoryMock, (uint64_t, uint64_t), (noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif iox::expected destroyMemory() noexcept override { @@ -70,14 +63,7 @@ class MemoryProviderTestImpl : public iox::roudi::MemoryProvider return iox::ok(); } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(void, destroyMemoryMock, (), (noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif void* dummyMemory{nullptr}; diff --git a/iceoryx_posh/test/mocks/server_mock.hpp b/iceoryx_posh/test/mocks/server_mock.hpp index 2f3198e0fd..a8c519aafa 100644 --- a/iceoryx_posh/test/mocks/server_mock.hpp +++ b/iceoryx_posh/test/mocks/server_mock.hpp @@ -46,10 +46,6 @@ class MockServerPortUser : public MockBasePort return *this; } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD((iox::expected), getRequest, (), @@ -74,9 +70,6 @@ class MockServerPortUser : public MockBasePort MOCK_METHOD(void, setConditionVariable, (iox::popo::ConditionVariableData&, const uint64_t), (noexcept)); MOCK_METHOD(void, unsetConditionVariable, (), (noexcept)); MOCK_METHOD(bool, isConditionVariableSet, (), (const, noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif }; class MockBaseServer @@ -90,10 +83,6 @@ class MockBaseServer { } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(iox::popo::uid_t, getUid, (), (const, noexcept)); MOCK_METHOD(const iox::capro::ServiceDescription&, getServiceDescription, (), (const, noexcept)); MOCK_METHOD(void, offer, (), (noexcept)); @@ -113,9 +102,6 @@ class MockBaseServer MOCK_METHOD(void, disableState, (const iox::popo::ServerState), (noexcept)); MOCK_METHOD(void, enableEvent, (iox::popo::TriggerHandle&&, const iox::popo::ServerEvent), (noexcept)); MOCK_METHOD(void, disableEvent, (const iox::popo::ServerEvent), (noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif const PortType& port() const noexcept diff --git a/iceoryx_posh/test/mocks/trigger_handle_mock.hpp b/iceoryx_posh/test/mocks/trigger_handle_mock.hpp index 7ee5b36ef0..bfd5124157 100644 --- a/iceoryx_posh/test/mocks/trigger_handle_mock.hpp +++ b/iceoryx_posh/test/mocks/trigger_handle_mock.hpp @@ -47,10 +47,6 @@ class MockTriggeHandle return *this; } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(bool, isValid, (), (const, noexcept)); MOCK_METHOD(bool, wasTriggered, (), (const, noexcept)); MOCK_METHOD(void, trigger, (), (noexcept)); @@ -58,23 +54,13 @@ class MockTriggeHandle MOCK_METHOD(void, invalidate, (), (noexcept)); MOCK_METHOD(uint64_t, getUniqueId, (), (const, noexcept)); MOCK_METHOD(iox::popo::ConditionVariableData*, getConditionVariableData, (), (noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif explicit operator bool() const { return operatorBoolMock(); } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(bool, operatorBoolMock, (), (const)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif uint64_t triggerId{0}; }; diff --git a/iceoryx_posh/test/moduletests/test_popo_smart_chunk_common.hpp b/iceoryx_posh/test/moduletests/test_popo_smart_chunk_common.hpp index f9371cc8c6..a2d0210bb7 100644 --- a/iceoryx_posh/test/moduletests/test_popo_smart_chunk_common.hpp +++ b/iceoryx_posh/test/moduletests/test_popo_smart_chunk_common.hpp @@ -55,14 +55,7 @@ class MockPublisherInterface : public PublisherInterface return mockSend(std::move(s)); } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(void, mockSend, (SampleProducerType &&), (noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif }; struct SampleTestCase @@ -99,14 +92,7 @@ class MockRequestInterface : public RpcInterface), mockSend, (RequestProducerType &&), (noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif }; class RequestTestCase @@ -144,14 +130,7 @@ class MockResponseInterface : public RpcInterface), mockSend, (ResponseProducerType &&), (noexcept)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif }; class ResponseTestCase diff --git a/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/posh_runtime_mock.hpp b/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/posh_runtime_mock.hpp index 92c919de2d..881957d3de 100644 --- a/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/posh_runtime_mock.hpp +++ b/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/posh_runtime_mock.hpp @@ -44,10 +44,6 @@ class PoshRuntimeMock : public iox::runtime::PoshRuntime mockRuntime().reset(); } -#ifdef __clang__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#endif MOCK_METHOD(iox::PublisherPortUserType::MemberType_t*, getMiddlewarePublisher, (const iox::capro::ServiceDescription&, @@ -82,9 +78,6 @@ class PoshRuntimeMock : public iox::runtime::PoshRuntime sendRequestToRouDi, (const iox::runtime::IpcMessage&, iox::runtime::IpcMessage&), (noexcept, override)); -#ifdef __clang__ -#pragma GCC diagnostic pop -#endif private: PoshRuntimeMock(const iox::RuntimeName_t& name) From db7ec5eb5f09da0a58254cd605792c5cd844c156 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 13 Nov 2023 15:57:40 +0100 Subject: [PATCH 45/85] iox-#1663 Remove pragma once from discovery example --- iceoryx_examples/icediscovery/include/discovery_blocking.hpp | 5 ++++- iceoryx_examples/icediscovery/include/discovery_monitor.hpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/iceoryx_examples/icediscovery/include/discovery_blocking.hpp b/iceoryx_examples/icediscovery/include/discovery_blocking.hpp index 8e8b866b7a..ceff302495 100644 --- a/iceoryx_examples/icediscovery/include/discovery_blocking.hpp +++ b/iceoryx_examples/icediscovery/include/discovery_blocking.hpp @@ -14,7 +14,8 @@ // // SPDX-License-Identifier: Apache-2.0 -#pragma once +#ifndef IOX_EXAMPLES_DISCOVERY_BLOCKING_HPP +#define IOX_EXAMPLES_DISCOVERY_BLOCKING_HPP #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/service_discovery.hpp" @@ -97,3 +98,5 @@ bool Discovery::waitUntil(const Condition& condition) //! [wait until condition] } // namespace discovery + +#endif // IOX_EXAMPLES_DISCOVERY_BLOCKING_HPP diff --git a/iceoryx_examples/icediscovery/include/discovery_monitor.hpp b/iceoryx_examples/icediscovery/include/discovery_monitor.hpp index fac0101a0d..154c839468 100644 --- a/iceoryx_examples/icediscovery/include/discovery_monitor.hpp +++ b/iceoryx_examples/icediscovery/include/discovery_monitor.hpp @@ -14,7 +14,8 @@ // // SPDX-License-Identifier: Apache-2.0 -#pragma once +#ifndef IOX_EXAMPLES_DISCOVERY_MONITORING_HPP +#define IOX_EXAMPLES_DISCOVERY_MONITORING_HPP #include "iceoryx_posh/popo/listener.hpp" #include "iceoryx_posh/runtime/service_discovery.hpp" @@ -88,3 +89,5 @@ void Discovery::registerCallback(const Callback& callback) } } // namespace discovery + +#endif // IOX_EXAMPLES_DISCOVERY_BLOCKING_HPP From 62043855ad2971dd7bd022eef602f62cc02e2aca Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 10 Nov 2023 19:24:18 +0100 Subject: [PATCH 46/85] iox-#2084 Fix QNX build --- .../container/include/iox/fixed_position_container.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index 1b5b458340..45da5de095 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -194,9 +194,6 @@ class FixedPositionContainer final friend class FixedPositionContainer; - template - friend class IteratorBase; - /// @brief Construct a const iterator from an iterator // NOLINTJUSTIFICATION conversion from non const iterator to const iterator follows the STL behavior // NOLINTNEXTLINE(hicpp-explicit-conversions) From b64c12eb5d319c909460cf7c87d4e420294d96c2 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 10 Nov 2023 19:41:54 +0100 Subject: [PATCH 47/85] iox-#2084 Add gcc8.3 to Arch Linux docker image --- tools/ci/docker/archlinux-base-devel | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/ci/docker/archlinux-base-devel b/tools/ci/docker/archlinux-base-devel index 8c8f791d96..3951f10bbe 100644 --- a/tools/ci/docker/archlinux-base-devel +++ b/tools/ci/docker/archlinux-base-devel @@ -9,11 +9,15 @@ ARG DEBIAN_FRONTEND=noninteractive # Minimize the number of layers (RUN, COPY and ADD create layers) # https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#minimize-the-number-of-layers # Install additional packages -RUN pacman -Syu --noconfirm \ - clang \ - cmake \ - git \ - ncurses \ +RUN \ + pacman -Syu --noconfirm \ + clang \ + cmake \ + git \ + ncurses \ + && pacman -U --noconfirm \ + https://archive.archlinux.org/packages/g/gcc8-libs/gcc8-libs-8.3.0-4-x86_64.pkg.tar.xz \ + https://archive.archlinux.org/packages/g/gcc8/gcc8-8.3.0-4-x86_64.pkg.tar.xz \ && pacman -Scc --noconfirm \ && useradd iox_roudi_test1 \ && useradd iox_roudi_test2 \ From 37faf0aa8701b1bd33b4a42570e30c84e530006e Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 10 Nov 2023 20:14:12 +0100 Subject: [PATCH 48/85] iox-#2084 Add gcc8.3 CI build --- .cirrus.yaml | 78 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/.cirrus.yaml b/.cirrus.yaml index 7171c175e6..44fdc2a429 100644 --- a/.cirrus.yaml +++ b/.cirrus.yaml @@ -31,23 +31,39 @@ iox_common_cpu_and_memory_config_for_tests_template: &IOX_COMMON_CPU_AND_MEMORY_ # Build and Test -iox_posix_clean_build_script_template: &IOX_POSIX_CLEAN_BUILD +iox_posix_pre_cmake_config_script_template: &IOX_POSIX_PRE_CMAKE_CONFIG - echo "#### Deleting build and iox-tests-bin dir" - if [[ -d "build" ]]; then rm -rf build; fi - if [[ -d "iox-tests-bin" ]]; then rm -rf iox-tests-vin; fi - echo "#### Running cmake to configure build" - - cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=ON -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DCMAKE_INSTALL_PREFIX=build/install + +iox_posix_post_cmake_config_script_template: &IOX_POSIX_POST_CMAKE_CONFIG - echo "#### Running cmake to build with CIRRUS_CPU = " $CIRRUS_CPU - cmake --build build --target install -j $CIRRUS_CPU -iox_posix_clean_build_with_additional_user_template: &IOX_POSIX_CLEAN_BUILD_WITH_ADDITIONAL_USER - - echo "#### Deleting build and iox-tests-bin dir" - - if [[ -d "build" ]]; then rm -rf build; fi - - if [[ -d "iox-tests-bin" ]]; then rm -rf iox-tests-vin; fi - - echo "#### Running cmake to configure build" +iox_posix_cmake_config_strict_with_no_additional_user_script_template: &IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_NO_ADDITIONAL_USER + - cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=ON -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DTEST_ADD_USER=OFF -DCMAKE_INSTALL_PREFIX=build/install + +iox_posix_cmake_config_strict_with_additional_user_script_template: &IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_ADDITIONAL_USER - cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=ON -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DTEST_ADD_USER=ON -DCMAKE_INSTALL_PREFIX=build/install - - echo "#### Running cmake to build with CIRRUS_CPU = " $CIRRUS_CPU - - cmake --build build --target install -j $CIRRUS_CPU + +iox_posix_cmake_config_no_strict_with_additional_user_script_template: &IOX_POSIX_CMAKE_CONFIG_NO_STRICT_WITH_ADDITIONAL_USER + - cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=OFF -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DTEST_ADD_USER=ON -DCMAKE_INSTALL_PREFIX=build/install + +iox_posix_clean_build_strict_with_no_additional_user_script_template: &IOX_POSIX_CLEAN_BUILD_STRICT_WITH_NO_ADDITIONAL_USER + <<: *IOX_POSIX_PRE_CMAKE_CONFIG + <<: *IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_NO_ADDITIONAL_USER + <<: *IOX_POSIX_POST_CMAKE_CONFIG + +iox_posix_clean_build_strict_with_additional_user_template: &IOX_POSIX_CLEAN_BUILD_STRICT_WITH_ADDITIONAL_USER + <<: *IOX_POSIX_PRE_CMAKE_CONFIG + <<: *IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_ADDITIONAL_USER + <<: *IOX_POSIX_POST_CMAKE_CONFIG + +iox_posix_clean_build_no_strict_with_additional_user_allow_warnings_template: &IOX_POSIX_CLEAN_BUILD_NO_STRICT_WITH_ADDITIONAL_USER_ALLOW_WARNING + <<: *IOX_POSIX_PRE_CMAKE_CONFIG + <<: *IOX_POSIX_CMAKE_CONFIG_NO_STRICT_WITH_ADDITIONAL_USER + <<: *IOX_POSIX_POST_CMAKE_CONFIG iox_prepare_test_binaries_for_cache_template: &IOX_PREPARE_TEST_BINARIES_FOR_CACHE - mkdir -p iox-tests-bin @@ -101,7 +117,7 @@ ubuntu_22_04_aarch64_build_task: reupload_on_changes: true fingerprint_key: $CIRRUS_OS_ubuntu_22_04_aarch64_test_binaries_cache build_script: - <<: *IOX_POSIX_CLEAN_BUILD_WITH_ADDITIONAL_USER + <<: *IOX_POSIX_CLEAN_BUILD_STRICT_WITH_ADDITIONAL_USER populate_test_binary_folder_script: <<: *IOX_PREPARE_TEST_BINARIES_FOR_CACHE @@ -118,6 +134,42 @@ ubuntu_22_04_aarch64_test_task: test_script: <<: *IOX_RUN_TESTS +# +# Arch Linux x64 gcc 8.3 aka QNX canary build +# + +arch_linux_x64_gcc_8_3_aka_qnx_canary_build_task: + depends_on: preflight_check + container: + dockerfile: tools/ci/docker/archlinux-base-devel + <<: *IOX_COMMON_CPU_AND_MEMORY_CONFIG_FOR_BUILDS + <<: *IOX_TASK_TIMEOUT + test_binaries_cache: + folder: iox-tests-bin + reupload_on_changes: true + fingerprint_key: $CIRRUS_OS_archlinux_x64_gcc_8_3_aka_qnx_canary_test_binaries_cache + env: + # use GCC 8.3 which corresponds to QCC 8.3 on QNX 7.1 + CC: gcc-8 + CXX: g++-8 + build_script: + <<: *IOX_POSIX_CLEAN_BUILD_NO_STRICT_WITH_ADDITIONAL_USER_ALLOW_WARNING + populate_test_binary_folder_script: + <<: *IOX_PREPARE_TEST_BINARIES_FOR_CACHE + +arch_linux_x64_gcc_8_3_aka_qnx_canary_test_task: + depends_on: arch_linux_x64_gcc_8_3_aka_qnx_canary_build + container: + dockerfile: tools/ci/docker/archlinux-base-devel + <<: *IOX_COMMON_CPU_AND_MEMORY_CONFIG_FOR_TESTS + <<: *IOX_TASK_TIMEOUT + test_binaries_cache: + folder: iox-tests-bin + reupload_on_changes: false + fingerprint_key: $CIRRUS_OS_archlinux_x64_gcc_8_3_aka_qnx_canary_test_binaries_cache + test_script: + <<: *IOX_RUN_TESTS + # # Arch Linux x64 # @@ -133,7 +185,7 @@ arch_linux_x64_build_task: reupload_on_changes: true fingerprint_key: $CIRRUS_OS_archlinux_x64_test_binaries_cache build_script: - <<: *IOX_POSIX_CLEAN_BUILD_WITH_ADDITIONAL_USER + <<: *IOX_POSIX_CLEAN_BUILD_STRICT_WITH_ADDITIONAL_USER populate_test_binary_folder_script: <<: *IOX_PREPARE_TEST_BINARIES_FOR_CACHE @@ -168,7 +220,7 @@ freebsd_x64_build_task: - pkg install -y cmake git ncurses bash wget - ln -s /usr/local/bin/bash /bin/bash build_script: - <<: *IOX_POSIX_CLEAN_BUILD + <<: *IOX_POSIX_CLEAN_BUILD_STRICT_WITH_NO_ADDITIONAL_USER populate_test_binary_folder_script: <<: *IOX_PREPARE_TEST_BINARIES_FOR_CACHE @@ -202,7 +254,7 @@ macos_aarch64_build_task: setup_script: - brew install ncurses build_script: - <<: *IOX_POSIX_CLEAN_BUILD + <<: *IOX_POSIX_CLEAN_BUILD_STRICT_WITH_NO_ADDITIONAL_USER populate_test_binary_folder_script: <<: *IOX_PREPARE_TEST_BINARIES_FOR_CACHE From 4597253b8e63bed45bfefd05033fc747821630a4 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 9 Nov 2023 18:12:20 +0100 Subject: [PATCH 49/85] iox-#2011 Restrict cirrus-ci to specific branches --- .cirrus.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.cirrus.yaml b/.cirrus.yaml index 44fdc2a429..493b28a839 100644 --- a/.cirrus.yaml +++ b/.cirrus.yaml @@ -12,6 +12,18 @@ --- +# +# Filter to run the CI only on the master and release branches or for pull request to the master, release* and iox-* branches +# + +only_if: $CIRRUS_BRANCH == 'master' + || $CIRRUS_BRANCH == 'release*' + || ($CIRRUS_PR != '' && ($CIRRUS_BASE_BRANCH == 'master' + || $CIRRUS_BASE_BRANCH == 'release*' + || $CIRRUS_BASE_BRANCH == 'iox-*' + ) + ) + # # Templates # From 426a78e9f72aad9133a4f8c3a1406db3e66faa6e Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 10 Nov 2023 20:24:43 +0100 Subject: [PATCH 50/85] iox-#2084 Update release notes --- doc/website/release-notes/iceoryx-unreleased.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 0c935d2e01..b00ed585c7 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -101,7 +101,7 @@ - Fix musl libc compile (missing sys/stat.h include in mqueue.h for mode_t definition) [\#2072](https://github.com/eclipse-iceoryx/iceoryx/issues/2072) - cxx::Expects macro conflicts with Microsoft GSL Expects macro [#2080](https://github.com/eclipse-iceoryx/iceoryx/issues/2080) - Implement move/copy constructor and assignment for `FixedPositionContainer` [#2052](https://github.com/eclipse-iceoryx/iceoryx/issues/2052) - +- FixedPositionContainer fails to compile on QNX QCC [#2084](https://github.com/eclipse-iceoryx/iceoryx/issues/2084) **Refactoring:** From 03c632ffda786e57e092bfc6f61fe850babafeb3 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 10 Nov 2023 20:43:01 +0100 Subject: [PATCH 51/85] iox-#2084 Fix cirrus-ci config --- .cirrus.yaml | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/.cirrus.yaml b/.cirrus.yaml index 493b28a839..4b7cd5f739 100644 --- a/.cirrus.yaml +++ b/.cirrus.yaml @@ -44,38 +44,40 @@ iox_common_cpu_and_memory_config_for_tests_template: &IOX_COMMON_CPU_AND_MEMORY_ # Build and Test iox_posix_pre_cmake_config_script_template: &IOX_POSIX_PRE_CMAKE_CONFIG - - echo "#### Deleting build and iox-tests-bin dir" - - if [[ -d "build" ]]; then rm -rf build; fi - - if [[ -d "iox-tests-bin" ]]; then rm -rf iox-tests-vin; fi - - echo "#### Running cmake to configure build" + echo "#### Deleting build and iox-tests-bin dir" + && if [[ -d "build" ]]; then rm -rf build; fi + && if [[ -d "iox-tests-bin" ]]; then rm -rf iox-tests-vin; fi iox_posix_post_cmake_config_script_template: &IOX_POSIX_POST_CMAKE_CONFIG - - echo "#### Running cmake to build with CIRRUS_CPU = " $CIRRUS_CPU - - cmake --build build --target install -j $CIRRUS_CPU + echo "#### Running cmake to build with CIRRUS_CPU = " $CIRRUS_CPU + && cmake --build build --target install -j $CIRRUS_CPU iox_posix_cmake_config_strict_with_no_additional_user_script_template: &IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_NO_ADDITIONAL_USER - - cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=ON -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DTEST_ADD_USER=OFF -DCMAKE_INSTALL_PREFIX=build/install + echo "#### Running cmake to configure build" + && cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=ON -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DTEST_ADD_USER=OFF -DCMAKE_INSTALL_PREFIX=build/install iox_posix_cmake_config_strict_with_additional_user_script_template: &IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_ADDITIONAL_USER - - cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=ON -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DTEST_ADD_USER=ON -DCMAKE_INSTALL_PREFIX=build/install + echo "#### Running cmake to configure build" + && cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=ON -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DTEST_ADD_USER=ON -DCMAKE_INSTALL_PREFIX=build/install iox_posix_cmake_config_no_strict_with_additional_user_script_template: &IOX_POSIX_CMAKE_CONFIG_NO_STRICT_WITH_ADDITIONAL_USER - - cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=OFF -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DTEST_ADD_USER=ON -DCMAKE_INSTALL_PREFIX=build/install + echo "#### Running cmake to configure build" + && cmake -Bbuild -Hiceoryx_meta -DBUILD_STRICT=OFF -DBINDING_C=ON -DINTROSPECTION=ON -DEXAMPLES=ON -DBUILD_TEST=ON -DTEST_ADD_USER=ON -DCMAKE_INSTALL_PREFIX=build/install -iox_posix_clean_build_strict_with_no_additional_user_script_template: &IOX_POSIX_CLEAN_BUILD_STRICT_WITH_NO_ADDITIONAL_USER - <<: *IOX_POSIX_PRE_CMAKE_CONFIG - <<: *IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_NO_ADDITIONAL_USER - <<: *IOX_POSIX_POST_CMAKE_CONFIG +iox_posix_clean_build_strict_with_no_additional_user_template: &IOX_POSIX_CLEAN_BUILD_STRICT_WITH_NO_ADDITIONAL_USER + - *IOX_POSIX_PRE_CMAKE_CONFIG + - *IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_NO_ADDITIONAL_USER + - *IOX_POSIX_POST_CMAKE_CONFIG iox_posix_clean_build_strict_with_additional_user_template: &IOX_POSIX_CLEAN_BUILD_STRICT_WITH_ADDITIONAL_USER - <<: *IOX_POSIX_PRE_CMAKE_CONFIG - <<: *IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_ADDITIONAL_USER - <<: *IOX_POSIX_POST_CMAKE_CONFIG + - *IOX_POSIX_PRE_CMAKE_CONFIG + - *IOX_POSIX_CMAKE_CONFIG_STRICT_WITH_ADDITIONAL_USER + - *IOX_POSIX_POST_CMAKE_CONFIG -iox_posix_clean_build_no_strict_with_additional_user_allow_warnings_template: &IOX_POSIX_CLEAN_BUILD_NO_STRICT_WITH_ADDITIONAL_USER_ALLOW_WARNING - <<: *IOX_POSIX_PRE_CMAKE_CONFIG - <<: *IOX_POSIX_CMAKE_CONFIG_NO_STRICT_WITH_ADDITIONAL_USER - <<: *IOX_POSIX_POST_CMAKE_CONFIG +iox_posix_clean_build_no_strict_with_additional_user_template: &IOX_POSIX_CLEAN_BUILD_NO_STRICT_WITH_ADDITIONAL_USER + - *IOX_POSIX_PRE_CMAKE_CONFIG + - *IOX_POSIX_CMAKE_CONFIG_NO_STRICT_WITH_ADDITIONAL_USER + - *IOX_POSIX_POST_CMAKE_CONFIG iox_prepare_test_binaries_for_cache_template: &IOX_PREPARE_TEST_BINARIES_FOR_CACHE - mkdir -p iox-tests-bin @@ -165,7 +167,7 @@ arch_linux_x64_gcc_8_3_aka_qnx_canary_build_task: CC: gcc-8 CXX: g++-8 build_script: - <<: *IOX_POSIX_CLEAN_BUILD_NO_STRICT_WITH_ADDITIONAL_USER_ALLOW_WARNING + <<: *IOX_POSIX_CLEAN_BUILD_STRICT_WITH_ADDITIONAL_USER populate_test_binary_folder_script: <<: *IOX_PREPARE_TEST_BINARIES_FOR_CACHE From 603d4d8e183f34f3b311f27d43cfc18980adf6bb Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 11 Nov 2023 16:30:34 +0100 Subject: [PATCH 52/85] iox-#2087 Fix allocation for chunks with an offset larger than 4GB --- iceoryx_posh/source/mepoo/mem_pool.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iceoryx_posh/source/mepoo/mem_pool.cpp b/iceoryx_posh/source/mepoo/mem_pool.cpp index 7e8e93d287..a194332327 100644 --- a/iceoryx_posh/source/mepoo/mem_pool.cpp +++ b/iceoryx_posh/source/mepoo/mem_pool.cpp @@ -83,8 +83,8 @@ void MemPool::adjustMinFree() noexcept void* MemPool::getChunk() noexcept { - uint32_t l_index{0U}; - if (!m_freeIndices.pop(l_index)) + uint32_t index{0U}; + if (!m_freeIndices.pop(index)) { IOX_LOG(WARN, "Mempool [m_chunkSize = " << m_chunkSize << ", numberOfChunks = " << m_numberOfChunks @@ -97,7 +97,7 @@ void* MemPool::getChunk() noexcept m_usedChunks.fetch_add(1U, std::memory_order_relaxed); adjustMinFree(); - return m_rawMemory.get() + l_index * m_chunkSize; + return m_rawMemory.get() + static_cast(index) * m_chunkSize; } void MemPool::freeChunk(const void* chunk) noexcept From a1e7a43e75c07767e5cb8b41e6aec5a625d8bc6c Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 11 Nov 2023 17:08:55 +0100 Subject: [PATCH 53/85] iox-#2087 Move index to ptr conversion to static functions --- .../iceoryx_posh/internal/mepoo/mem_pool.hpp | 18 +++++++++++- iceoryx_posh/source/mepoo/mem_pool.cpp | 29 ++++++++++++++----- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mem_pool.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mem_pool.hpp index 1cb175f3a0..3856feb930 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mem_pool.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mem_pool.hpp @@ -1,5 +1,6 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2023 by Mathias Kraus . 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. @@ -69,11 +70,26 @@ class MemPool void freeChunk(const void* chunk) noexcept; + /// @brief Converts an index to a chunk in the MemPool to a pointer + /// @param[in] index of the chunk + /// @param[in] chunkSize is the size of the chunk + /// @param[in] rawMemoryBase it the pointer to the raw memory of the MemPool + /// @return the pointer to the chunk + static void* indexToPointer(const uint32_t index, const uint32_t chunkSize, void* const rawMemoryBase) noexcept; + + /// @brief Converts a pointer to a chunk in the MemPool to an index + /// @param[in] chunk is the pointer to the chunk + /// @param[in] chunkSize is the size of the chunk + /// @param[in] rawMemoryBase it the pointer to the raw memory of the MemPool + /// @return the index to the chunk + static uint32_t + pointerToIndex(const void* const chunk, const uint32_t chunkSize, const void* const rawMemoryBase) noexcept; + private: void adjustMinFree() noexcept; bool isMultipleOfAlignment(const uint32_t value) const noexcept; - RelativePointer m_rawMemory; + RelativePointer m_rawMemory; uint32_t m_chunkSize{0U}; /// needs to be 32 bit since loffli supports only 32 bit numbers diff --git a/iceoryx_posh/source/mepoo/mem_pool.cpp b/iceoryx_posh/source/mepoo/mem_pool.cpp index a194332327..df98185046 100644 --- a/iceoryx_posh/source/mepoo/mem_pool.cpp +++ b/iceoryx_posh/source/mepoo/mem_pool.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2023 by Mathias Kraus . All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -97,18 +98,32 @@ void* MemPool::getChunk() noexcept m_usedChunks.fetch_add(1U, std::memory_order_relaxed); adjustMinFree(); - return m_rawMemory.get() + static_cast(index) * m_chunkSize; + return indexToPointer(index, m_chunkSize, m_rawMemory.get()); } -void MemPool::freeChunk(const void* chunk) noexcept +void* MemPool::indexToPointer(uint32_t index, uint32_t chunkSize, void* const rawMemoryBase) noexcept +{ + const auto offset = static_cast(index) * chunkSize; + return static_cast(rawMemoryBase) + offset; +} + +uint32_t +MemPool::pointerToIndex(const void* const chunk, const uint32_t chunkSize, const void* const rawMemoryBase) noexcept { - IOX_EXPECTS(m_rawMemory.get() <= chunk - && chunk <= m_rawMemory.get() + (static_cast(m_chunkSize) * (m_numberOfChunks - 1U))); + const auto offset = + static_cast(static_cast(chunk) - static_cast(rawMemoryBase)); + IOX_EXPECTS(offset % chunkSize == 0); - auto offset = static_cast(chunk) - m_rawMemory.get(); - IOX_EXPECTS(offset % m_chunkSize == 0); + const auto index = static_cast(offset / chunkSize); + return index; +} + +void MemPool::freeChunk(const void* chunk) noexcept +{ + const auto offsetToLastChunk = static_cast(m_chunkSize) * (m_numberOfChunks - 1U); + IOX_EXPECTS(m_rawMemory.get() <= chunk && chunk <= static_cast(m_rawMemory.get()) + offsetToLastChunk); - uint32_t index = static_cast(offset / m_chunkSize); + const auto index = pointerToIndex(chunk, m_chunkSize, m_rawMemory.get()); if (!m_freeIndices.push(index)) { From 64acc092e11db2b241bb1285576c8c63b5e7ae2b Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 11 Nov 2023 17:45:58 +0100 Subject: [PATCH 54/85] iox-#2087 Add tests for index to pointer conversion --- .../test/moduletests/test_mepoo_mempool.cpp | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp index 7fa3e8eeeb..c2a7b16ac3 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2019, 2021 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2023 by Mathias Kraus . 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. @@ -54,6 +55,96 @@ class MemPool_test : public Test MemPool sut; }; +TEST_F(MemPool_test, MempoolIndexToPointerConversionForIndexZeroWorks) +{ + ::testing::Test::RecordProperty("TEST_ID", "107222a6-7a48-44f1-93c5-9a1f56f3d319"); + + constexpr uint32_t INDEX{0}; + constexpr uint32_t CHUNK_SIZE{128}; + uint8_t* const RAW_MEMORY_BASE{reinterpret_cast(0x7f60d90c5000ULL)}; + uint8_t* const EXPECTED_CHUNK_PTR{RAW_MEMORY_BASE}; + + const auto* chunk = MemPool::indexToPointer(INDEX, CHUNK_SIZE, RAW_MEMORY_BASE); + + EXPECT_THAT(chunk, Eq(EXPECTED_CHUNK_PTR)); +} + +TEST_F(MemPool_test, MempoolIndexToPointerConversionForIndexOneWorks) +{ + ::testing::Test::RecordProperty("TEST_ID", "fda231af-87a9-4292-be1e-e443aa7cff63"); + + constexpr uint32_t INDEX{1}; + constexpr uint32_t CHUNK_SIZE{128}; + uint8_t* const RAW_MEMORY_BASE{reinterpret_cast(0x7f60d90c5000ULL)}; + uint8_t* const EXPECTED_CHUNK_PTR{RAW_MEMORY_BASE + CHUNK_SIZE}; + + const auto* chunk = MemPool::indexToPointer(INDEX, CHUNK_SIZE, RAW_MEMORY_BASE); + + EXPECT_THAT(chunk, Eq(EXPECTED_CHUNK_PTR)); +} + +TEST_F(MemPool_test, MempoolIndexToPointerConversionForMemoryOffsetsLargerThan4GBWorks) +{ + ::testing::Test::RecordProperty("TEST_ID", "2112326a-5ec3-4bc8-9aa3-500ffef202fd"); + + constexpr uint32_t INDEX{42}; + constexpr uint32_t MB{1UL << 20}; + constexpr uint64_t GB{1ULL << 30}; + constexpr uint32_t CHUNK_SIZE{128 * MB}; + uint8_t* const RAW_MEMORY_BASE{reinterpret_cast(0x7f60d90c5000ULL)}; + uint8_t* const EXPECTED_CHUNK_PTR{RAW_MEMORY_BASE + static_cast(INDEX) * CHUNK_SIZE}; + + const auto* chunk = MemPool::indexToPointer(INDEX, CHUNK_SIZE, RAW_MEMORY_BASE); + + EXPECT_THAT(chunk, Eq(EXPECTED_CHUNK_PTR)); + EXPECT_THAT(static_cast(chunk) - RAW_MEMORY_BASE, Gt(5 * GB)); +} + +TEST_F(MemPool_test, MempoolPointerToIndexConversionForIndexZeroWorks) +{ + ::testing::Test::RecordProperty("TEST_ID", "37b23350-b562-4e89-a452-2f3d328bc016"); + + constexpr uint32_t CHUNK_SIZE{128}; + uint8_t* const RAW_MEMORY_BASE{reinterpret_cast(0x7f60d90c5000ULL)}; + uint8_t* const CHUNK_PTR{RAW_MEMORY_BASE}; + constexpr uint32_t EXPECTED_INDEX{0}; + + const auto index = MemPool::pointerToIndex(CHUNK_PTR, CHUNK_SIZE, RAW_MEMORY_BASE); + + EXPECT_THAT(index, Eq(EXPECTED_INDEX)); +} + +TEST_F(MemPool_test, MempoolPointerToIndexConversionForIndexOneWorks) +{ + ::testing::Test::RecordProperty("TEST_ID", "64349d9a-1a97-4ba0-a04f-07c929befe38"); + + constexpr uint32_t CHUNK_SIZE{128}; + uint8_t* const RAW_MEMORY_BASE{reinterpret_cast(0x7f60d90c5000ULL)}; + uint8_t* const CHUNK_PTR{RAW_MEMORY_BASE + CHUNK_SIZE}; + constexpr uint32_t EXPECTED_INDEX{1}; + + const auto index = MemPool::pointerToIndex(CHUNK_PTR, CHUNK_SIZE, RAW_MEMORY_BASE); + + EXPECT_THAT(index, Eq(EXPECTED_INDEX)); +} + +TEST_F(MemPool_test, MempoolPointeToIndexConversionForMemoryOffsetsLargerThan4GBWorks) +{ + ::testing::Test::RecordProperty("TEST_ID", "45e09ada-97b9-435d-a59a-d377d4e4fb69"); + + constexpr uint32_t MB{1UL << 20}; + constexpr uint64_t GB{1ULL << 30}; + constexpr uint32_t CHUNK_SIZE{128 * MB}; + uint8_t* const RAW_MEMORY_BASE{reinterpret_cast(0x7f60d90c5000ULL)}; + constexpr uint32_t EXPECTED_INDEX{42}; + uint8_t* const CHUNK_PTR{RAW_MEMORY_BASE + static_cast(EXPECTED_INDEX) * CHUNK_SIZE}; + + const auto index = MemPool::pointerToIndex(CHUNK_PTR, CHUNK_SIZE, RAW_MEMORY_BASE); + + EXPECT_THAT(index, Eq(EXPECTED_INDEX)); + EXPECT_THAT(static_cast(CHUNK_PTR) - RAW_MEMORY_BASE, Gt(5 * GB)); +} + TEST_F(MemPool_test, MempoolCtorInitialisesTheObjectWithValuesPassedToTheCtor) { ::testing::Test::RecordProperty("TEST_ID", "b15b0da5-74e0-481b-87b6-53888b8a9890"); From a7bad60be1bf492a6f5e2eaf93ed77d2c84860c4 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 11 Nov 2023 17:47:33 +0100 Subject: [PATCH 55/85] iox-#2087 Update release notes --- doc/website/release-notes/iceoryx-unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 330da581d4..27145781f8 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -102,6 +102,7 @@ - cxx::Expects macro conflicts with Microsoft GSL Expects macro [#2080](https://github.com/eclipse-iceoryx/iceoryx/issues/2080) - Implement move/copy constructor and assignment for `FixedPositionContainer` [#2052](https://github.com/eclipse-iceoryx/iceoryx/issues/2052) - FixedPositionContainer fails to compile on QNX QCC [#2084](https://github.com/eclipse-iceoryx/iceoryx/issues/2084) +- Chunk fails to be released when more than 4 GiB of chunks have been allocated [#2087](https://github.com/eclipse-iceoryx/iceoryx/issues/2087) **Refactoring:** From a7abab41b5fcb7c94ef74d5d7fca9a72f315e7e9 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 13 Nov 2023 15:59:34 +0100 Subject: [PATCH 56/85] iox-#2087 Explicitly cast to 'void*' --- iceoryx_posh/source/mepoo/mem_pool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_posh/source/mepoo/mem_pool.cpp b/iceoryx_posh/source/mepoo/mem_pool.cpp index df98185046..589137f766 100644 --- a/iceoryx_posh/source/mepoo/mem_pool.cpp +++ b/iceoryx_posh/source/mepoo/mem_pool.cpp @@ -104,7 +104,7 @@ void* MemPool::getChunk() noexcept void* MemPool::indexToPointer(uint32_t index, uint32_t chunkSize, void* const rawMemoryBase) noexcept { const auto offset = static_cast(index) * chunkSize; - return static_cast(rawMemoryBase) + offset; + return static_cast(static_cast(rawMemoryBase) + offset); } uint32_t From 2f7fc40c6507eb084e142ff364f63f4f071712d8 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 16 Nov 2023 19:26:32 +0100 Subject: [PATCH 57/85] iox-#2066 Switch to C++17 --- iceoryx_platform/linux/IceoryxPlatformSettings.cmake | 2 +- iceoryx_platform/qnx/IceoryxPlatformSettings.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iceoryx_platform/linux/IceoryxPlatformSettings.cmake b/iceoryx_platform/linux/IceoryxPlatformSettings.cmake index 4b7427b0b7..61343796eb 100644 --- a/iceoryx_platform/linux/IceoryxPlatformSettings.cmake +++ b/iceoryx_platform/linux/IceoryxPlatformSettings.cmake @@ -14,7 +14,7 @@ # # SPDX-License-Identifier: Apache-2.0 -set_global(VAR ICEORYX_CXX_STANDARD VALUE 14) +set_global(VAR ICEORYX_CXX_STANDARD VALUE 17) set_global(VAR ICEORYX_PLATFORM_STRING VALUE "Linux") set_global(VAR ICEORYX_C_FLAGS VALUE ) diff --git a/iceoryx_platform/qnx/IceoryxPlatformSettings.cmake b/iceoryx_platform/qnx/IceoryxPlatformSettings.cmake index dfe11914f3..6440019655 100644 --- a/iceoryx_platform/qnx/IceoryxPlatformSettings.cmake +++ b/iceoryx_platform/qnx/IceoryxPlatformSettings.cmake @@ -15,7 +15,7 @@ # SPDX-License-Identifier: Apache-2.0 set_global(VAR ICEORYX_PLATFORM_STRING VALUE "QNX") -set_global(VAR ICEORYX_CXX_STANDARD VALUE 14) +set_global(VAR ICEORYX_CXX_STANDARD VALUE 17) set_global(VAR ICEORYX_C_FLAGS VALUE ) set_global(VAR ICEORYX_CXX_FLAGS VALUE ) From a09a370039f442d4f8f77da4d53643924f51db62 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 16 Nov 2023 19:28:59 +0100 Subject: [PATCH 58/85] iox-#2066 Update release notes --- doc/website/release-notes/iceoryx-unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 330da581d4..783a9df286 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -51,6 +51,7 @@ - Extend 'iceperf' with 'WaitSet' [#2003](https://github.com/eclipse-iceoryx/iceoryx/issues/2003) - Create iceoryx version header for the C-binding [#1014](https://github.com/eclipse-iceoryx/iceoryx/issues/1014) - Create macros to deprecate header and code constructs [#2057](https://github.com/eclipse-iceoryx/iceoryx/issues/2057) +- Switch to C++17 on all platforms [#2066](https://github.com/eclipse-iceoryx/iceoryx/issues/2066) **Bugfixes:** From c1aa03a4b3e71414c2b303aa8748f4daf5877651 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 16 Nov 2023 19:34:11 +0100 Subject: [PATCH 59/85] iox-#2066 Update documentation --- .clang-tidy | 2 +- CONTRIBUTING.md | 2 +- iceoryx_hoofs/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index f7f384c32d..9a65c1ad1b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -98,7 +98,7 @@ hicpp-*, # void bar(Foo& foo) {...} # # * rule: readability-use-anyofallof -# justification: requires C++20 and std::ranges but we only use C++14 +# justification: requires C++20 and std::ranges but we only use C++17 # # * rule: cppcoreguidelines-non-private-member-variables-in-classes # justification: Sometimes it makes sense to have protected members to extend the base class. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9afd0b0cad..0cfb84e658 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -104,7 +104,7 @@ codebase follows these rules, things are work in progress. without heap) 2) **No exceptions are allowed**, all function and methods need to have `noexcept` in their signature 3) **No undefined behavior**, zero-cost abstract is not feasible in high safety environments -4) **Use C++14** +4) **Use C++17** 5) **[Rule of Five](https://en.cppreference.com/w/cpp/language/rule_of_three)**, if there is a non-default destructor needed, the rule of five has to be applied 6) **Keep the [STL](https://en.wikipedia.org/wiki/Standard_Template_Library) dependencies to a minimum**, diff --git a/iceoryx_hoofs/README.md b/iceoryx_hoofs/README.md index 71cdb73c9f..dc456552c1 100644 --- a/iceoryx_hoofs/README.md +++ b/iceoryx_hoofs/README.md @@ -11,7 +11,7 @@ The following sections have a column labeled `internal` to indicate that the API is not stable and can change anytime. You should never rely on it and there is no support if it is used and breaks your code after an update. -Some modules contain STL constructs which are not part of the C++14 standard as well as convenience +Some modules contain STL constructs which are not part of the C++17 standard as well as convenience constructs like the `NewType`. Since the classes re-implements some STL constructs, the C++ STL coding guidelines are used for all files in this module, to help the user to have a painless transition from the official STL types to ours. From af804b446764e4aa8bf56fb901b3827030fd97d2 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 16 Nov 2023 20:50:01 +0100 Subject: [PATCH 60/85] iox-#2066 Fix warning for useless cast --- iceoryx_dust/test/moduletests/test_cli_command_line_common.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_dust/test/moduletests/test_cli_command_line_common.hpp b/iceoryx_dust/test/moduletests/test_cli_command_line_common.hpp index c8c7a09026..f2eb16d372 100644 --- a/iceoryx_dust/test/moduletests/test_cli_command_line_common.hpp +++ b/iceoryx_dust/test/moduletests/test_cli_command_line_common.hpp @@ -35,7 +35,7 @@ struct CmdArgs contents = std::make_unique>(arguments); for (uint64_t i = 0; i < static_cast(argc); ++i) { - argv[i] = const_cast((*contents)[i].data()); + argv[i] = (*contents)[i].data(); } } From 5413fe39783bd7c5202f0619d7d320a7b13118bd Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 16 Nov 2023 21:20:24 +0100 Subject: [PATCH 61/85] iox-#1391 Remove posix from include path and namespace in dust --- .../release-notes/iceoryx-unreleased.md | 6 +-- .../include/iox/{posix => }/message_queue.hpp | 43 +++++++++---------- .../include/iox/{posix => }/named_pipe.hpp | 39 ++++++++--------- .../posix/ipc/source/message_queue.cpp | 36 ++++++++-------- iceoryx_dust/posix/ipc/source/named_pipe.cpp | 16 +++++-- .../iox/{posix => }/signal_watcher.hpp | 20 ++++----- .../posix/sync/source/signal_watcher.cpp | 12 +++--- .../test_posix_sync_signal_watcher.cpp | 3 +- iceoryx_examples/callbacks/README.md | 6 +-- ...ice_callbacks_listener_as_class_member.cpp | 4 +- .../callbacks/ice_callbacks_publisher.cpp | 4 +- .../callbacks/ice_callbacks_subscriber.cpp | 6 +-- .../complexdata/iox_publisher_complexdata.cpp | 4 +- .../complexdata/iox_publisher_vector.cpp | 4 +- .../iox_subscriber_complexdata.cpp | 4 +- .../complexdata/iox_subscriber_vector.cpp | 4 +- .../ice_access_control/iox_display_app.cpp | 4 +- .../ice_access_control/iox_radar_app.cpp | 4 +- iceoryx_examples/icedelivery/README.md | 6 +-- .../icedelivery/iox_publisher.cpp | 4 +- .../icedelivery/iox_publisher_untyped.cpp | 4 +- .../icedelivery/iox_subscriber.cpp | 4 +- .../icedelivery/iox_subscriber_untyped.cpp | 4 +- .../icediscovery/iox_discovery_monitor.cpp | 4 +- .../icediscovery/iox_find_service.cpp | 4 +- .../icediscovery/iox_offer_service.cpp | 4 +- .../icediscovery/iox_wait_for_service.cpp | 2 +- iceoryx_examples/icehello/README.md | 6 +-- .../icehello/iox_publisher_helloworld.cpp | 4 +- .../icehello/iox_subscriber_helloworld.cpp | 4 +- .../iceoptions/iox_publisher_with_options.cpp | 6 +-- .../iox_subscriber_with_options.cpp | 4 +- iceoryx_examples/request_response/README.md | 6 +-- .../request_response/client_cxx_basic.cpp | 4 +- .../request_response/client_cxx_untyped.cpp | 4 +- .../request_response/client_cxx_waitset.cpp | 2 +- .../request_response/server_cxx_basic.cpp | 4 +- .../request_response/server_cxx_listener.cpp | 4 +- .../request_response/server_cxx_untyped.cpp | 4 +- iceoryx_examples/singleprocess/README.md | 6 +-- .../singleprocess/single_process.cpp | 8 ++-- iceoryx_examples/user_header/README.md | 6 +-- .../user_header/publisher_cxx_api.cpp | 4 +- .../user_header/publisher_untyped_cxx_api.cpp | 4 +- .../user_header/subscriber_cxx_api.cpp | 4 +- .../subscriber_untyped_cxx_api.cpp | 4 +- .../waitset/ice_waitset_publisher.cpp | 4 +- iceoryx_hoofs/cmake/IceoryxPlatform.cmake | 2 +- .../internal/runtime/ipc_interface_base.hpp | 8 ++-- .../include/iceoryx_posh/roudi/roudi_app.hpp | 2 +- .../roudi/application/iceoryx_roudi_app.cpp | 4 +- .../source/roudi/application/roudi_app.cpp | 4 +- .../source/runtime/ipc_interface_base.cpp | 6 +-- .../test_mq_interface_startup_race.cpp | 2 +- .../test_runtime_ipc_interface.cpp | 4 +- 55 files changed, 190 insertions(+), 189 deletions(-) rename iceoryx_dust/posix/ipc/include/iox/{posix => }/message_queue.hpp (74%) rename iceoryx_dust/posix/ipc/include/iox/{posix => }/named_pipe.hpp (82%) rename iceoryx_dust/posix/sync/include/iox/{posix => }/signal_watcher.hpp (86%) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 330da581d4..87733c0b8b 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -1000,7 +1000,7 @@ #include "iceoryx_hoofs/posix_wrapper/internal/message_queue.hpp" // after - #include "iox/posix/message_queue.hpp" + #include "iox/message_queue.hpp" ``` ```cpp @@ -1008,7 +1008,7 @@ #include "iceoryx_hoofs/posix_wrapper/named_pipe.hpp" // after - #include "iox/posix/named_pipe.hpp" + #include "iox/named_pipe.hpp" ``` ```cpp @@ -1016,7 +1016,7 @@ #include "iceoryx_hoofs/posix_wrapper/signal_watcher.hpp" // after - #include "iox/posix/signal_watcher.hpp" + #include "iox/signal_watcher.hpp" ``` ```cpp diff --git a/iceoryx_dust/posix/ipc/include/iox/posix/message_queue.hpp b/iceoryx_dust/posix/ipc/include/iox/message_queue.hpp similarity index 74% rename from iceoryx_dust/posix/ipc/include/iox/posix/message_queue.hpp rename to iceoryx_dust/posix/ipc/include/iox/message_queue.hpp index 1a48f93d65..2c2f7a965e 100644 --- a/iceoryx_dust/posix/ipc/include/iox/posix/message_queue.hpp +++ b/iceoryx_dust/posix/ipc/include/iox/message_queue.hpp @@ -30,14 +30,12 @@ namespace iox { -namespace posix -{ class MessageQueueBuilder; /// @brief Wrapper class for posix message queue /// /// @code -/// auto mq = iox::posix::MessageQueueBuilder() +/// auto mq = iox::MessageQueueBuilder() /// .name("/MqName123") /// .channelSide(iox::posix::IpcChannelSide::CLIENT) /// .create(); @@ -69,27 +67,28 @@ class MessageQueue ~MessageQueue() noexcept; - static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; + static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; /// @brief send a message to queue using std::string. /// @return true if sent without errors, false otherwise - expected send(const std::string& msg) const noexcept; + expected send(const std::string& msg) const noexcept; /// @todo iox-#1693 zero copy receive with receive(iox::string&); iox::string would be the buffer for mq_receive /// @brief receive message from queue using std::string. /// @return number of characters received. In case of an error, returns -1 and msg is empty. - expected receive() const noexcept; + expected receive() const noexcept; /// @brief try to receive message from queue for a given timeout duration using std::string. Only defined /// for NON_BLOCKING == false. /// @return optional containing the received string. In case of an error, nullopt type is returned. - expected timedReceive(const units::Duration& timeout) const noexcept; + expected timedReceive(const units::Duration& timeout) const noexcept; /// @brief try to send a message to the queue for a given timeout duration using std::string - expected timedSend(const std::string& msg, const units::Duration& timeout) const noexcept; + expected timedSend(const std::string& msg, + const units::Duration& timeout) const noexcept; - static expected isOutdated() noexcept; + static expected isOutdated() noexcept; private: friend class MessageQueueBuilder; @@ -97,23 +96,24 @@ class MessageQueue MessageQueue(const IpcChannelName_t& name, const mq_attr attributes, mqd_t mqDescriptor, - const IpcChannelSide channelSide) noexcept; + const posix::IpcChannelSide channelSide) noexcept; - static expected - open(const IpcChannelName_t& name, mq_attr& attributes, const IpcChannelSide channelSide) noexcept; + static expected + open(const IpcChannelName_t& name, mq_attr& attributes, const posix::IpcChannelSide channelSide) noexcept; - expected close() noexcept; - expected unlink() noexcept; - IpcChannelError errnoToEnum(const int32_t errnum) const noexcept; - static IpcChannelError errnoToEnum(const IpcChannelName_t& name, const int32_t errnum) noexcept; - static expected sanitizeIpcChannelName(const IpcChannelName_t& name) noexcept; - expected destroy() noexcept; + expected close() noexcept; + expected unlink() noexcept; + posix::IpcChannelError errnoToEnum(const int32_t errnum) const noexcept; + static posix::IpcChannelError errnoToEnum(const IpcChannelName_t& name, const int32_t errnum) noexcept; + static expected + sanitizeIpcChannelName(const IpcChannelName_t& name) noexcept; + expected destroy() noexcept; private: IpcChannelName_t m_name; mq_attr m_attributes{}; mqd_t m_mqDescriptor = INVALID_DESCRIPTOR; - IpcChannelSide m_channelSide = IpcChannelSide::CLIENT; + posix::IpcChannelSide m_channelSide = posix::IpcChannelSide::CLIENT; #ifdef __QNX__ static constexpr int TIMEOUT_ERRNO = EINTR; @@ -133,7 +133,7 @@ class MessageQueueBuilder IOX_BUILDER_PARAMETER(IpcChannelName_t, name, "") /// @brief Defines how the message queue is opened, i.e. as client or server - IOX_BUILDER_PARAMETER(IpcChannelSide, channelSide, IpcChannelSide::CLIENT) + IOX_BUILDER_PARAMETER(posix::IpcChannelSide, channelSide, posix::IpcChannelSide::CLIENT) /// @brief Defines the max message size of the message queue IOX_BUILDER_PARAMETER(uint64_t, maxMsgSize, MessageQueue::MAX_MESSAGE_SIZE) @@ -144,10 +144,9 @@ class MessageQueueBuilder public: /// @brief create a message queue /// @return On success a 'MessageQueue' is returned and on failure an 'IpcChannelError'. - expected create() const noexcept; + expected create() const noexcept; }; -} // namespace posix } // namespace iox #endif // IOX_DUST_POSIX_IPC_MESSAGE_QUEUE_HPP diff --git a/iceoryx_dust/posix/ipc/include/iox/posix/named_pipe.hpp b/iceoryx_dust/posix/ipc/include/iox/named_pipe.hpp similarity index 82% rename from iceoryx_dust/posix/ipc/include/iox/posix/named_pipe.hpp rename to iceoryx_dust/posix/ipc/include/iox/named_pipe.hpp index f259ce4f64..c227a7360e 100644 --- a/iceoryx_dust/posix/ipc/include/iox/posix/named_pipe.hpp +++ b/iceoryx_dust/posix/ipc/include/iox/named_pipe.hpp @@ -35,8 +35,6 @@ namespace iox { -namespace posix -{ class NamedPipeBuilder; class NamedPipe @@ -72,51 +70,51 @@ class NamedPipe /// @brief removes a named pipe artifact from the system /// @return true if the artifact was removed, false when no artifact was found and /// IpcChannelError::INTERNAL_LOGIC_ERROR when shm_unlink failed - static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; + static expected unlinkIfExists(const IpcChannelName_t& name) noexcept; /// @brief tries to send a message via the named pipe. if the pipe is full IpcChannelError::TIMEOUT is returned /// @return on failure an error which describes the failure - expected trySend(const std::string& message) const noexcept; + expected trySend(const std::string& message) const noexcept; /// @brief sends a message via the named pipe. if the pipe is full this call is blocking until the message could be /// delivered /// @param[in] message the message which should be sent, is not allowed to be longer then MAX_MESSAGE_SIZE /// @return success when message was sent otherwise an error which describes the failure - expected send(const std::string& message) const noexcept; + expected send(const std::string& message) const noexcept; /// @brief sends a message via the named pipe. /// @param[in] message the message which should be sent, is not allowed to be longer then MAX_MESSAGE_SIZE /// @param[in] timeout the timeout on how long this method should retry to send the message /// @return success when message was sent otherwise an error which describes the failure - expected timedSend(const std::string& message, - const units::Duration& timeout) const noexcept; + expected timedSend(const std::string& message, + const units::Duration& timeout) const noexcept; /// @brief tries to receive a message via the named pipe. if the pipe is empty IpcChannelError::TIMEOUT is returned /// @return on success a string containing the message, otherwise an error which describes the failure - expected tryReceive() const noexcept; + expected tryReceive() const noexcept; /// @brief receives a message via the named pipe. if the pipe is empty this call is blocking until a message was /// received /// @return on success a string containing the message, otherwise an error which describes the failure - expected receive() const noexcept; + expected receive() const noexcept; /// @brief receives a message via the named pipe. /// @param[in] timeout the timeout on how long this method should retry to receive a message /// @return on success a string containing the message, otherwise an error which describes the failure - expected timedReceive(const units::Duration& timeout) const noexcept; + expected timedReceive(const units::Duration& timeout) const noexcept; private: friend class NamedPipeBuilder; class NamedPipeData; - NamedPipe(SharedMemoryObject&& sharedMemory, NamedPipeData* data) noexcept; + NamedPipe(posix::SharedMemoryObject&& sharedMemory, NamedPipeData* data) noexcept; template static IpcChannelName_t mapToSharedMemoryName(const Prefix& p, const IpcChannelName_t& name) noexcept; /// @brief destroys an initialized named pipe. /// @return is always successful - expected destroy() noexcept; + expected destroy() noexcept; class NamedPipeData { @@ -129,10 +127,10 @@ class NamedPipe NamedPipeData& operator=(NamedPipeData&& rhs) = delete; ~NamedPipeData() = default; - UnnamedSemaphore& sendSemaphore() noexcept; - UnnamedSemaphore& receiveSemaphore() noexcept; + posix::UnnamedSemaphore& sendSemaphore() noexcept; + posix::UnnamedSemaphore& receiveSemaphore() noexcept; - expected initialize(const uint32_t maxMsgNumber) noexcept; + expected initialize(const uint32_t maxMsgNumber) noexcept; bool waitForInitialization() const noexcept; bool hasValidState() const noexcept; @@ -146,12 +144,12 @@ class NamedPipe static constexpr units::Duration WAIT_FOR_INIT_SLEEP_TIME = units::Duration::fromMilliseconds(1); std::atomic initializationGuard{INVALID_DATA}; - optional m_sendSemaphore; - optional m_receiveSemaphore; + optional m_sendSemaphore; + optional m_receiveSemaphore; }; private: - SharedMemoryObject m_sharedMemory; + posix::SharedMemoryObject m_sharedMemory; NamedPipeData* m_data = nullptr; }; @@ -161,7 +159,7 @@ class NamedPipeBuilder IOX_BUILDER_PARAMETER(IpcChannelName_t, name, "") /// @brief Defines how the named pipe is opened, i.e. as client or server - IOX_BUILDER_PARAMETER(IpcChannelSide, channelSide, IpcChannelSide::CLIENT) + IOX_BUILDER_PARAMETER(posix::IpcChannelSide, channelSide, posix::IpcChannelSide::CLIENT) /// @brief Defines the max message size of the named pipe IOX_BUILDER_PARAMETER(size_t, maxMsgSize, NamedPipe::MAX_MESSAGE_SIZE) @@ -172,10 +170,9 @@ class NamedPipeBuilder public: /// @brief create a named pipe /// @return On success a 'NamedPipe' is returned and on failure an 'IpcChannelError'. - expected create() const noexcept; + expected create() const noexcept; }; -} // namespace posix } // namespace iox #endif // IOX_DUST_POSIX_IPC_NAMED_PIPE_HPP diff --git a/iceoryx_dust/posix/ipc/source/message_queue.cpp b/iceoryx_dust/posix/ipc/source/message_queue.cpp index e9336e8c85..00a4f1d607 100644 --- a/iceoryx_dust/posix/ipc/source/message_queue.cpp +++ b/iceoryx_dust/posix/ipc/source/message_queue.cpp @@ -16,7 +16,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/posix/message_queue.hpp" +#include "iox/message_queue.hpp" #include "iceoryx_hoofs/posix_wrapper/posix_call.hpp" #include "iceoryx_platform/fcntl.hpp" #include "iceoryx_platform/platform_correction.hpp" @@ -28,8 +28,9 @@ namespace iox { -namespace posix -{ +using posix::IpcChannelError; +using posix::IpcChannelSide; + expected MessageQueueBuilder::create() const noexcept { auto sanitzedNameResult = MessageQueue::sanitizeIpcChannelName(m_name); @@ -47,7 +48,7 @@ expected MessageQueueBuilder::create() const noex if (m_channelSide == IpcChannelSide::SERVER) { - posixCall(mq_unlink)(sanitizedName.c_str()) + posix::posixCall(mq_unlink)(sanitizedName.c_str()) .failureReturnValue(MessageQueue::ERROR_CODE) .ignoreErrnos(ENOENT) .evaluate() @@ -134,7 +135,7 @@ expected MessageQueue::unlinkIfExists(const IpcChannelNam } - auto mqCall = posixCall(mq_unlink)(sanitizedIpcChannelName->c_str()) + auto mqCall = posix::posixCall(mq_unlink)(sanitizedIpcChannelName->c_str()) .failureReturnValue(ERROR_CODE) .ignoreErrnos(ENOENT) .evaluate(); @@ -176,8 +177,9 @@ expected MessageQueue::send(const std::string& msg) const return err(IpcChannelError::MESSAGE_TOO_LONG); } - auto mqCall = - posixCall(mq_send)(m_mqDescriptor, msg.c_str(), messageSize, 1U).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = posix::posixCall(mq_send)(m_mqDescriptor, msg.c_str(), messageSize, 1U) + .failureReturnValue(ERROR_CODE) + .evaluate(); if (mqCall.has_error()) { @@ -193,7 +195,7 @@ expected MessageQueue::receive() const noexcept /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) char message[MAX_MESSAGE_SIZE]; - auto mqCall = posixCall(mq_receive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr) + auto mqCall = posix::posixCall(mq_receive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr) .failureReturnValue(ERROR_CODE) .evaluate(); @@ -227,10 +229,11 @@ MessageQueue::open(const IpcChannelName_t& name, mq_attr& attributes, const IpcC // the mask will be applied to the permissions, therefore we need to set it to 0 mode_t umaskSaved = umask(0); - auto mqCall = posixCall(iox_mq_open4)(sanitizedName.c_str(), openFlags, MessageQueue::FILE_MODE, &attributes) - .failureReturnValue(MessageQueue::INVALID_DESCRIPTOR) - .suppressErrorMessagesForErrnos(ENOENT) - .evaluate(); + auto mqCall = + posix::posixCall(iox_mq_open4)(sanitizedName.c_str(), openFlags, MessageQueue::FILE_MODE, &attributes) + .failureReturnValue(MessageQueue::INVALID_DESCRIPTOR) + .suppressErrorMessagesForErrnos(ENOENT) + .evaluate(); umask(umaskSaved); @@ -245,7 +248,7 @@ MessageQueue::open(const IpcChannelName_t& name, mq_attr& attributes, const IpcC expected MessageQueue::close() noexcept { - auto mqCall = posixCall(mq_close)(m_mqDescriptor).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = posix::posixCall(mq_close)(m_mqDescriptor).failureReturnValue(ERROR_CODE).evaluate(); if (mqCall.has_error()) { @@ -262,7 +265,7 @@ expected MessageQueue::unlink() noexcept return ok(); } - auto mqCall = posixCall(mq_unlink)(m_name.c_str()).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = posix::posixCall(mq_unlink)(m_name.c_str()).failureReturnValue(ERROR_CODE).evaluate(); if (mqCall.has_error()) { return err(errnoToEnum(mqCall.error().errnum)); @@ -278,7 +281,7 @@ expected MessageQueue::timedReceive(const units::D /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) char message[MAX_MESSAGE_SIZE]; - auto mqCall = posixCall(mq_timedreceive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr, &timeOut) + auto mqCall = posix::posixCall(mq_timedreceive)(m_mqDescriptor, &message[0], MAX_MESSAGE_SIZE, nullptr, &timeOut) .failureReturnValue(ERROR_CODE) // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT .ignoreErrnos(TIMEOUT_ERRNO) @@ -310,7 +313,7 @@ expected MessageQueue::timedSend(const std::string& msg, timespec timeOut = timeout.timespec(units::TimeSpecReference::Epoch); - auto mqCall = posixCall(mq_timedsend)(m_mqDescriptor, msg.c_str(), messageSize, 1U, &timeOut) + auto mqCall = posix::posixCall(mq_timedsend)(m_mqDescriptor, msg.c_str(), messageSize, 1U, &timeOut) .failureReturnValue(ERROR_CODE) // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT .ignoreErrnos(TIMEOUT_ERRNO) @@ -406,5 +409,4 @@ expected MessageQueue::sanitizeIpcChannelName return ok(name); } -} // namespace posix } // namespace iox diff --git a/iceoryx_dust/posix/ipc/source/named_pipe.cpp b/iceoryx_dust/posix/ipc/source/named_pipe.cpp index b112cbcc1b..87fc817c91 100644 --- a/iceoryx_dust/posix/ipc/source/named_pipe.cpp +++ b/iceoryx_dust/posix/ipc/source/named_pipe.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/posix/named_pipe.hpp" +#include "iox/named_pipe.hpp" #include "iox/bump_allocator.hpp" #include "iox/deadline_timer.hpp" #include "iox/filesystem.hpp" @@ -27,8 +27,17 @@ namespace iox { -namespace posix -{ +using posix::AccessMode; +using posix::IpcChannelError; +using posix::IpcChannelSide; +using posix::OpenMode; +using posix::SemaphoreWaitState; +using posix::SharedMemory; +using posix::SharedMemoryObject; +using posix::SharedMemoryObjectBuilder; +using posix::UnnamedSemaphore; +using posix::UnnamedSemaphoreBuilder; + /// NOLINTJUSTIFICATION see declaration in header /// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) constexpr const char NamedPipe::NAMED_PIPE_PREFIX[]; @@ -361,5 +370,4 @@ bool NamedPipe::NamedPipeData::hasValidState() const noexcept return initializationGuard.load() == VALID_DATA; } -} // namespace posix } // namespace iox diff --git a/iceoryx_dust/posix/sync/include/iox/posix/signal_watcher.hpp b/iceoryx_dust/posix/sync/include/iox/signal_watcher.hpp similarity index 86% rename from iceoryx_dust/posix/sync/include/iox/posix/signal_watcher.hpp rename to iceoryx_dust/posix/sync/include/iox/signal_watcher.hpp index 1108f9f3ca..2923f94d5c 100644 --- a/iceoryx_dust/posix/sync/include/iox/posix/signal_watcher.hpp +++ b/iceoryx_dust/posix/sync/include/iox/signal_watcher.hpp @@ -13,9 +13,8 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 - -#ifndef IOX_DUST_POSIX_SYNC_SIGNAL_WATCHER_HPP -#define IOX_DUST_POSIX_SYNC_SIGNAL_WATCHER_HPP +#ifndef IOX_DUST_POSIX_WRAPPER_SIGNAL_WATCHER_HPP +#define IOX_DUST_POSIX_WRAPPER_SIGNAL_WATCHER_HPP #include "iceoryx_hoofs/posix_wrapper/signal_handler.hpp" #include "iceoryx_hoofs/posix_wrapper/unnamed_semaphore.hpp" @@ -25,8 +24,6 @@ namespace iox { -namespace posix -{ /// @brief The SignalWatcher waits for SIGINT and SIGTERM. One can wait until the /// signal has occurred or ask the watcher if it has occurred. /// @code @@ -34,7 +31,7 @@ namespace posix /// #include /// void loopUntilTerminationRequested() /// { -/// while(!iox::posix::hasTerminationRequested()) +/// while(!iox::hasTerminationRequested()) /// { /// // your algorithm /// } @@ -43,7 +40,7 @@ namespace posix /// // another possibility is to block until SIGINT or SIGTERM has occurred /// void blockUntilCtrlC() { /// // your objects which spawn threads -/// iox::posix::waitForTerminationRequest(); +/// iox::waitForTerminationRequest(); /// } /// @endcode class SignalWatcher @@ -71,11 +68,11 @@ class SignalWatcher private: friend void internalSignalHandler(int) noexcept; mutable std::atomic m_numberOfWaiters{0U}; - mutable optional m_semaphore; + mutable optional m_semaphore; std::atomic_bool m_hasSignalOccurred{false}; - SignalGuard m_sigTermGuard; - SignalGuard m_sigIntGuard; + posix::SignalGuard m_sigTermGuard; + posix::SignalGuard m_sigIntGuard; }; /// @brief convenience function, calls SignalWatcher::getInstance().waitForSignal(); @@ -83,7 +80,6 @@ void waitForTerminationRequest() noexcept; /// @brief convenience function, calls SignalWatcher::getInstance().wasSignalTriggered(); bool hasTerminationRequested() noexcept; -} // namespace posix } // namespace iox -#endif // IOX_DUST_POSIX_SYNC_SIGNAL_WATCHER_HPP +#endif diff --git a/iceoryx_dust/posix/sync/source/signal_watcher.cpp b/iceoryx_dust/posix/sync/source/signal_watcher.cpp index c83472a521..73a3d71251 100644 --- a/iceoryx_dust/posix/sync/source/signal_watcher.cpp +++ b/iceoryx_dust/posix/sync/source/signal_watcher.cpp @@ -14,13 +14,11 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include "iceoryx_platform/unistd.hpp" namespace iox { -namespace posix -{ void internalSignalHandler(int) noexcept { auto& instance = SignalWatcher::getInstance(); @@ -45,10 +43,11 @@ void internalSignalHandler(int) noexcept SignalWatcher::SignalWatcher() noexcept : m_sigTermGuard( - registerSignalHandler(Signal::TERM, internalSignalHandler).expect("Unable to register Signal::TERM")) - , m_sigIntGuard(registerSignalHandler(Signal::INT, internalSignalHandler).expect("Unable to register Signal::INT")) + registerSignalHandler(posix::Signal::TERM, internalSignalHandler).expect("Unable to register Signal::TERM")) + , m_sigIntGuard( + registerSignalHandler(posix::Signal::INT, internalSignalHandler).expect("Unable to register Signal::INT")) { - UnnamedSemaphoreBuilder() + posix::UnnamedSemaphoreBuilder() .isInterProcessCapable(false) .create(m_semaphore) @@ -89,5 +88,4 @@ bool hasTerminationRequested() noexcept { return SignalWatcher::getInstance().wasSignalTriggered(); } -} // namespace posix } // namespace iox diff --git a/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp b/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp index f4c820a67e..bd543864f3 100644 --- a/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp +++ b/iceoryx_dust/test/moduletests/test_posix_sync_signal_watcher.cpp @@ -16,13 +16,14 @@ #include "iceoryx_hoofs/testing/barrier.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include "test.hpp" #include namespace { using namespace ::testing; +using namespace iox; using namespace iox::posix; class SignalWatcherTester : public SignalWatcher diff --git a/iceoryx_examples/callbacks/README.md b/iceoryx_examples/callbacks/README.md index 4e1d7c0aaa..3acf24e281 100644 --- a/iceoryx_examples/callbacks/README.md +++ b/iceoryx_examples/callbacks/README.md @@ -74,7 +74,7 @@ Next thing is a `heartbeatThread` which will trigger our heartbeat trigger every ```cpp std::thread heartbeatThread([&] { - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { heartbeat.trigger(); std::this_thread::sleep_for(std::chrono::seconds(4)); @@ -133,7 +133,7 @@ was signaled. ```cpp -iox::posix::waitForTerminationRequest(); +iox::waitForTerminationRequest(); ``` When `waitForTerminationRequest` unblocks we clean up all resources and terminate the process @@ -238,7 +238,7 @@ iox::runtime::PoshRuntime::initRuntime(APP_NAME); CounterService counterService; -iox::posix::waitForTerminationRequest(); +iox::waitForTerminationRequest(); ``` Our `CounterService` has the following members: diff --git a/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp b/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp index 0ca9b26cb6..b5209fb006 100644 --- a/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp +++ b/iceoryx_examples/callbacks/ice_callbacks_listener_as_class_member.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iox/optional.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -112,7 +112,7 @@ int main() CounterService counterService; - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); //! [init] return (EXIT_SUCCESS); diff --git a/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp b/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp index 8ebc494f07..29ba9d8085 100644 --- a/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp +++ b/iceoryx_examples/callbacks/ice_callbacks_publisher.cpp @@ -16,7 +16,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -32,7 +32,7 @@ void sending() iox::popo::Publisher myPublisherLeft({"Radar", "FrontLeft", "Counter"}); iox::popo::Publisher myPublisherRight({"Radar", "FrontRight", "Counter"}); - for (uint32_t counter = 0U; !iox::posix::hasTerminationRequested(); ++counter) + for (uint32_t counter = 0U; !iox::hasTerminationRequested(); ++counter) { if (counter % 3 == 0) { diff --git a/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp b/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp index c80e713b09..e25cc58569 100644 --- a/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp +++ b/iceoryx_examples/callbacks/ice_callbacks_subscriber.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iox/optional.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -91,7 +91,7 @@ int main() // send a heartbeat every 4 seconds //! [create heartbeat] std::thread heartbeatThread([&] { - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { heartbeat.trigger(); std::this_thread::sleep_for(std::chrono::seconds(4)); @@ -131,7 +131,7 @@ int main() // wait until someone presses CTRL+C //! [wait for sigterm] - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); //! [wait for sigterm] // optional detachEvent, but not required. diff --git a/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp b/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp index 9ccf54ee4b..8d515a4e41 100644 --- a/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp +++ b/iceoryx_examples/complexdata/iox_publisher_complexdata.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" constexpr char APP_NAME[] = "iox-cpp-publisher-complexdata"; @@ -46,7 +46,7 @@ int main() uint64_t ct = 0; // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; publisher.loan() diff --git a/iceoryx_examples/complexdata/iox_publisher_vector.cpp b/iceoryx_examples/complexdata/iox_publisher_vector.cpp index 2e271d2e1e..f1834ac29a 100644 --- a/iceoryx_examples/complexdata/iox_publisher_vector.cpp +++ b/iceoryx_examples/complexdata/iox_publisher_vector.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" constexpr char APP_NAME[] = "iox-cpp-publisher-vector"; @@ -34,7 +34,7 @@ int main() uint64_t ct = 0; // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { publisher.loan() .and_then([&](auto& sample) { diff --git a/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp b/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp index 0ca1156fc2..35f75181af 100644 --- a/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp +++ b/iceoryx_examples/complexdata/iox_subscriber_complexdata.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include "iox/string.hpp" constexpr char APP_NAME[] = "iox-cpp-subscriber-complexdata"; @@ -32,7 +32,7 @@ int main() iox::popo::Subscriber subscriber({"Group", "Instance", "ComplexDataTopic"}); // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber.take() .and_then([](auto& sample) { diff --git a/iceoryx_examples/complexdata/iox_subscriber_vector.cpp b/iceoryx_examples/complexdata/iox_subscriber_vector.cpp index ba2bb825e9..90a8779c6b 100644 --- a/iceoryx_examples/complexdata/iox_subscriber_vector.cpp +++ b/iceoryx_examples/complexdata/iox_subscriber_vector.cpp @@ -16,7 +16,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include "iox/string.hpp" #include "iox/vector.hpp" @@ -31,7 +31,7 @@ int main() iox::popo::Subscriber> subscriber({"Radar", "FrontRight", "VectorData"}); // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber.take() .and_then([](auto& sample) { diff --git a/iceoryx_examples/ice_access_control/iox_display_app.cpp b/iceoryx_examples/ice_access_control/iox_display_app.cpp index bba273145f..0ce9133e2b 100644 --- a/iceoryx_examples/ice_access_control/iox_display_app.cpp +++ b/iceoryx_examples/ice_access_control/iox_display_app.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include @@ -35,7 +35,7 @@ int main() iox::popo::Publisher publisher({"Radar", "HMI-Display", "Object"}); // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { auto takeResult = subscriber.take(); diff --git a/iceoryx_examples/ice_access_control/iox_radar_app.cpp b/iceoryx_examples/ice_access_control/iox_radar_app.cpp index 8222c840b0..36c61ebaac 100644 --- a/iceoryx_examples/ice_access_control/iox_radar_app.cpp +++ b/iceoryx_examples/ice_access_control/iox_radar_app.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include @@ -32,7 +32,7 @@ int main() iox::popo::Publisher publisher({"Radar", "FrontLeft", "Object"}); double ct = 0.0; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; diff --git a/iceoryx_examples/icedelivery/README.md b/iceoryx_examples/icedelivery/README.md index 72325a65b6..9a9efd3ea1 100644 --- a/iceoryx_examples/icedelivery/README.md +++ b/iceoryx_examples/icedelivery/README.md @@ -23,9 +23,9 @@ First off, let's include the publisher, the runtime and the signal handler: ```cpp -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/untyped_publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" ``` You might be wondering what the publisher application is sending? It's this struct. @@ -130,9 +130,9 @@ Similar to the publisher, we include the topic data, the subscriber, the runtime ```cpp #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/untyped_subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" ``` To make RouDi aware of the subscriber a runtime object is created, once again with a unique identifier string: @@ -155,7 +155,7 @@ Again in a while-loop we do the following: ```cpp -while (!iox::posix::hasTerminationRequested()) +while (!iox::hasTerminationRequested()) { subscriber .take() diff --git a/iceoryx_examples/icedelivery/iox_publisher.cpp b/iceoryx_examples/icedelivery/iox_publisher.cpp index 6f50237688..0b1ae0d7c4 100644 --- a/iceoryx_examples/icedelivery/iox_publisher.cpp +++ b/iceoryx_examples/icedelivery/iox_publisher.cpp @@ -21,7 +21,7 @@ #include "iceoryx_posh/popo/publisher.hpp" //! [include publisher] #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include @@ -41,7 +41,7 @@ int main() //! [create publisher] double ct = 0.0; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; double sampleValue1 = ct + 89; diff --git a/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp b/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp index f5ce53fdf2..57ad1a46df 100644 --- a/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp +++ b/iceoryx_examples/icedelivery/iox_publisher_untyped.cpp @@ -22,7 +22,7 @@ //! [includes] #include "iceoryx_posh/popo/untyped_publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [includes] #include @@ -39,7 +39,7 @@ int main() //! [create untyped publisher] double ct = 0.0; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; diff --git a/iceoryx_examples/icedelivery/iox_subscriber.cpp b/iceoryx_examples/icedelivery/iox_subscriber.cpp index 4477fd0b37..267b61bcb3 100644 --- a/iceoryx_examples/icedelivery/iox_subscriber.cpp +++ b/iceoryx_examples/icedelivery/iox_subscriber.cpp @@ -21,7 +21,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" //! [include subscriber] #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include @@ -37,7 +37,7 @@ int main() //! [create subscriber] // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber .take() diff --git a/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp b/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp index 10b82b9f6f..a940c738aa 100644 --- a/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp +++ b/iceoryx_examples/icedelivery/iox_subscriber_untyped.cpp @@ -20,7 +20,7 @@ #include "iceoryx_posh/popo/untyped_subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [includes] #include @@ -38,7 +38,7 @@ int main() // run until interrupted by Ctrl-C //! [loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber .take() diff --git a/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp b/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp index daf68248d6..c182523884 100644 --- a/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp +++ b/iceoryx_examples/icediscovery/iox_discovery_monitor.cpp @@ -19,7 +19,7 @@ //! [include custom discovery] #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include @@ -76,7 +76,7 @@ int main() discovery.registerCallback(callback); //! [register callback] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { // here the app would run its functional code while the // service availability is monitored in the background diff --git a/iceoryx_examples/icediscovery/iox_find_service.cpp b/iceoryx_examples/icediscovery/iox_find_service.cpp index 0b3769d05d..7f3a42e463 100644 --- a/iceoryx_examples/icediscovery/iox_find_service.cpp +++ b/iceoryx_examples/icediscovery/iox_find_service.cpp @@ -15,7 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [include ServiceDiscovery] #include "iceoryx_posh/runtime/service_discovery.hpp" //! [include ServiceDiscovery] @@ -39,7 +39,7 @@ int main() iox::runtime::ServiceDiscovery serviceDiscovery; //! [create ServiceDiscovery object] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { std::cout << "\n=========================================" << std::endl; diff --git a/iceoryx_examples/icediscovery/iox_offer_service.cpp b/iceoryx_examples/icediscovery/iox_offer_service.cpp index 3643011a6a..c05b5a9ac2 100644 --- a/iceoryx_examples/icediscovery/iox_offer_service.cpp +++ b/iceoryx_examples/icediscovery/iox_offer_service.cpp @@ -16,7 +16,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" constexpr char APP_NAME[] = "iox-offer-service"; @@ -37,7 +37,7 @@ int main() cameraPublishers.emplace_back(iox::capro::ServiceDescription{"Camera", "BackLeft", "Image"}); bool offer = false; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { if (offer) { diff --git a/iceoryx_examples/icediscovery/iox_wait_for_service.cpp b/iceoryx_examples/icediscovery/iox_wait_for_service.cpp index 12f5928923..cbdf8e80e8 100644 --- a/iceoryx_examples/icediscovery/iox_wait_for_service.cpp +++ b/iceoryx_examples/icediscovery/iox_wait_for_service.cpp @@ -19,7 +19,7 @@ //! [include custom discovery] #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include diff --git a/iceoryx_examples/icehello/README.md b/iceoryx_examples/icehello/README.md index 54290161a3..8444f590b0 100644 --- a/iceoryx_examples/icehello/README.md +++ b/iceoryx_examples/icehello/README.md @@ -65,14 +65,14 @@ In iceoryx, a publisher and a subscriber are connected only if all three IDs mat For exiting on Ctrl+C, we use the `SignalWatcher` ```cpp -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" ``` and loop in our `while` loop until it states that `SIGINT` or `SIGTERM` was sent via the function `hasTerminationRequested`. ```cpp -while (!iox::posix::hasTerminationRequested()) +while (!iox::hasTerminationRequested()) ``` In order to send our sample, we loan some shared memory inside the `while` loop: @@ -125,9 +125,9 @@ The subscriber needs to have similar includes, but unlike the publisher `subscri ```cpp #include "topic_data.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" ``` As well as the publisher, the subscriber needs to register with the daemon RouDi: diff --git a/iceoryx_examples/icehello/iox_publisher_helloworld.cpp b/iceoryx_examples/icehello/iox_publisher_helloworld.cpp index 134057c1af..5394fba6ee 100644 --- a/iceoryx_examples/icehello/iox_publisher_helloworld.cpp +++ b/iceoryx_examples/icehello/iox_publisher_helloworld.cpp @@ -19,7 +19,7 @@ //! [include topic] //! [include sig watcher] -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [include sig watcher] //! [include] @@ -43,7 +43,7 @@ int main() double ct = 0.0; //! [wait for term] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) //! [wait for term] { ++ct; diff --git a/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp b/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp index 1e850d58d0..af2f4ba1e1 100644 --- a/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp +++ b/iceoryx_examples/icehello/iox_subscriber_helloworld.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [include] #include @@ -36,7 +36,7 @@ int main() //! [initialize subscriber] // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [receive] auto takeResult = subscriber.take(); diff --git a/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp b/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp index 0e4da4d37e..8b898a3416 100644 --- a/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp +++ b/iceoryx_examples/iceoptions/iox_publisher_with_options.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include @@ -63,7 +63,7 @@ int main() double ct = 0.0; std::thread publishData([&]() { - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { ++ct; @@ -76,7 +76,7 @@ int main() } }); - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); // this is optional, but since the iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER option is used, // a slow subscriber might block the shutdown and this call unblocks the publisher diff --git a/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp b/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp index b5d7204054..566e396514 100644 --- a/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp +++ b/iceoryx_examples/iceoptions/iox_subscriber_with_options.cpp @@ -18,7 +18,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include @@ -76,7 +76,7 @@ int main() //! [subscribe] // run until interrupted by Ctrl-C - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { subscriber.take().and_then( [](auto& sample) { std::cout << APP_NAME << " got value: " << sample->x << std::endl; }); diff --git a/iceoryx_examples/request_response/README.md b/iceoryx_examples/request_response/README.md index 4924738a24..fd8036ca31 100644 --- a/iceoryx_examples/request_response/README.md +++ b/iceoryx_examples/request_response/README.md @@ -35,11 +35,11 @@ At first, the includes for the client port, request-response types, WaitSet, and ```cpp #include "request_and_response_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_hoofs/posix_wrapper/signal_handler.hpp" #include "iceoryx_posh/popo/client.hpp" #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" ``` Afterwards we prepare some `ContextData` where we can store the Fibonacci numbers @@ -177,10 +177,10 @@ At first, the includes for the server port, Listener, request-response types and ```cpp #include "request_and_response_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/listener.hpp" #include "iceoryx_posh/popo/server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" ``` Then a callback is created that shall be called when the server receives a request. @@ -246,7 +246,7 @@ With that the preparation is done and the main thread can just sleep or do other ```cpp -iox::posix::waitForTerminationRequest(); +iox::waitForTerminationRequest(); ``` Once the user wants to shutdown the server, the server event is detached from the listener: diff --git a/iceoryx_examples/request_response/client_cxx_basic.cpp b/iceoryx_examples/request_response/client_cxx_basic.cpp index 66dea43202..7e5fd88ec7 100644 --- a/iceoryx_examples/request_response/client_cxx_basic.cpp +++ b/iceoryx_examples/request_response/client_cxx_basic.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/client.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -40,7 +40,7 @@ int main() uint64_t fibonacciCurrent = 1; int64_t requestSequenceId = 0; int64_t expectedResponseSequenceId = requestSequenceId; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [send request] client.loan() diff --git a/iceoryx_examples/request_response/client_cxx_untyped.cpp b/iceoryx_examples/request_response/client_cxx_untyped.cpp index 70d657ea1d..96793ae311 100644 --- a/iceoryx_examples/request_response/client_cxx_untyped.cpp +++ b/iceoryx_examples/request_response/client_cxx_untyped.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/untyped_client.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -40,7 +40,7 @@ int main() uint64_t fibonacciCurrent = 1; int64_t requestSequenceId = 0; int64_t expectedResponseSequenceId = requestSequenceId; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [send request] client.loan(sizeof(AddRequest), alignof(AddRequest)) diff --git a/iceoryx_examples/request_response/client_cxx_waitset.cpp b/iceoryx_examples/request_response/client_cxx_waitset.cpp index 040485f7eb..8088b4901f 100644 --- a/iceoryx_examples/request_response/client_cxx_waitset.cpp +++ b/iceoryx_examples/request_response/client_cxx_waitset.cpp @@ -21,7 +21,7 @@ #include "iceoryx_posh/popo/client.hpp" #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include diff --git a/iceoryx_examples/request_response/server_cxx_basic.cpp b/iceoryx_examples/request_response/server_cxx_basic.cpp index 322a63a886..3772ce86ef 100644 --- a/iceoryx_examples/request_response/server_cxx_basic.cpp +++ b/iceoryx_examples/request_response/server_cxx_basic.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -36,7 +36,7 @@ int main() //! [create server] //! [process requests in a loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [take request] server.take().and_then([&](const auto& request) { diff --git a/iceoryx_examples/request_response/server_cxx_listener.cpp b/iceoryx_examples/request_response/server_cxx_listener.cpp index 96d87ab025..62ca9d492f 100644 --- a/iceoryx_examples/request_response/server_cxx_listener.cpp +++ b/iceoryx_examples/request_response/server_cxx_listener.cpp @@ -20,7 +20,7 @@ #include "iceoryx_posh/popo/listener.hpp" #include "iceoryx_posh/popo/server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -76,7 +76,7 @@ int main() //! [attach listener] //! [wait for termination] - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); //! [wait for termination] //! [cleanup] diff --git a/iceoryx_examples/request_response/server_cxx_untyped.cpp b/iceoryx_examples/request_response/server_cxx_untyped.cpp index 577a1ce8c6..651a30a659 100644 --- a/iceoryx_examples/request_response/server_cxx_untyped.cpp +++ b/iceoryx_examples/request_response/server_cxx_untyped.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/untyped_server.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -36,7 +36,7 @@ int main() //! [create server] //! [process requests in a loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [take request] server.take().and_then([&](auto& requestPayload) { diff --git a/iceoryx_examples/singleprocess/README.md b/iceoryx_examples/singleprocess/README.md index c3569780eb..b58305e967 100644 --- a/iceoryx_examples/singleprocess/README.md +++ b/iceoryx_examples/singleprocess/README.md @@ -72,7 +72,7 @@ iox::runtime::PoshRuntimeSingleProcess runtime("singleProcessDemo"); ```cpp std::thread publisherThread(publisher), subscriberThread(subscriber); -iox::posix::waitForTerminationRequest(); +iox::waitForTerminationRequest(); publisherThread.join(); subscriberThread.join(); @@ -105,7 +105,7 @@ After that, we are sending numbers in ascending order with a 100ms interval in a ```cpp uint64_t counter{0}; constexpr const char GREEN_RIGHT_ARROW[] = "\033[32m->\033[m "; -while (!iox::posix::hasTerminationRequested()) +while (!iox::hasTerminationRequested()) { publisher.loan().and_then([&](auto& sample) { sample->counter = counter++; @@ -136,7 +136,7 @@ until someone terminates the application. ```cpp constexpr const char ORANGE_LEFT_ARROW[] = "\033[33m<-\033[m "; -while (!iox::posix::hasTerminationRequested()) +while (!iox::hasTerminationRequested()) { if (iox::SubscribeState::SUBSCRIBED == subscriber.getSubscriptionState()) { diff --git a/iceoryx_examples/singleprocess/single_process.cpp b/iceoryx_examples/singleprocess/single_process.cpp index 626821e1b2..f4ae89f5fb 100644 --- a/iceoryx_examples/singleprocess/single_process.cpp +++ b/iceoryx_examples/singleprocess/single_process.cpp @@ -24,7 +24,7 @@ #include "iceoryx_posh/runtime/posh_runtime_single_process.hpp" #include "iox/detail/convert.hpp" #include "iox/logging.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include #include @@ -59,7 +59,7 @@ void publisher() //! [send] uint64_t counter{0}; constexpr const char GREEN_RIGHT_ARROW[] = "\033[32m->\033[m "; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { publisher.loan().and_then([&](auto& sample) { sample->counter = counter++; @@ -83,7 +83,7 @@ void subscriber() //! [receive] constexpr const char ORANGE_LEFT_ARROW[] = "\033[33m<-\033[m "; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { if (iox::SubscribeState::SUBSCRIBED == subscriber.getSubscriptionState()) { @@ -136,7 +136,7 @@ int main() //! [run] std::thread publisherThread(publisher), subscriberThread(subscriber); - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); publisherThread.join(); subscriberThread.join(); diff --git a/iceoryx_examples/user_header/README.md b/iceoryx_examples/user_header/README.md index aa781a0012..36c2643e58 100644 --- a/iceoryx_examples/user_header/README.md +++ b/iceoryx_examples/user_header/README.md @@ -58,9 +58,9 @@ and the iceoryx includes for publisher and runtime. ```cpp #include "user_header_and_payload_types.hpp" -#include "iceoryx_dust/posix_wrapper/signal_watcher.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/signal_watcher.hpp" ``` Next, the iceoryx runtime is initialized. With this call, the application will be registered at `RouDi`, @@ -87,7 +87,7 @@ if you prefer a more traditional approach. uint64_t timestamp = 42; uint64_t fibonacciLast = 0; uint64_t fibonacciCurrent = 1; -while (!iox::posix::hasTerminationRequested()) +while (!iox::hasTerminationRequested()) { auto fibonacciNext = fibonacciCurrent + fibonacciLast; fibonacciLast = fibonacciCurrent; @@ -231,7 +231,7 @@ The main loop is quite simple. The publisher is periodically polled and the data Again, the user-header is accessed by the `getUserHeader` method of the sample. ```cpp -while (!iox::posix::hasTerminationRequested()) +while (!iox::hasTerminationRequested()) { subscriber.take().and_then([&](auto& sample) { std::cout << APP_NAME << " got value: " << sample->fibonacci << " with timestamp " diff --git a/iceoryx_examples/user_header/publisher_cxx_api.cpp b/iceoryx_examples/user_header/publisher_cxx_api.cpp index 6543a08d11..78599083af 100644 --- a/iceoryx_examples/user_header/publisher_cxx_api.cpp +++ b/iceoryx_examples/user_header/publisher_cxx_api.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -40,7 +40,7 @@ int main() uint64_t timestamp = 42; uint64_t fibonacciLast = 0; uint64_t fibonacciCurrent = 1; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { auto fibonacciNext = fibonacciCurrent + fibonacciLast; fibonacciLast = fibonacciCurrent; diff --git a/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp b/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp index 8aa4e66d95..02c4116daf 100644 --- a/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp +++ b/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp @@ -17,7 +17,7 @@ //! [iceoryx includes] #include "user_header_and_payload_types.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [include differs from typed C++ API] #include "iceoryx_posh/popo/untyped_publisher.hpp" //! [include differs from typed C++ API] @@ -42,7 +42,7 @@ int main() uint64_t timestamp = 73; uint64_t fibonacciLast = 0; uint64_t fibonacciCurrent = 1; - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { auto fibonacciNext = fibonacciCurrent + fibonacciLast; fibonacciLast = fibonacciCurrent; diff --git a/iceoryx_examples/user_header/subscriber_cxx_api.cpp b/iceoryx_examples/user_header/subscriber_cxx_api.cpp index 886ce16806..74bb00d22b 100644 --- a/iceoryx_examples/user_header/subscriber_cxx_api.cpp +++ b/iceoryx_examples/user_header/subscriber_cxx_api.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -37,7 +37,7 @@ int main() //! [create subscriber] //! [poll subscriber for samples in a loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [take sample] subscriber.take().and_then([&](auto& sample) { diff --git a/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp b/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp index 51e41838c3..9272a3671f 100644 --- a/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp +++ b/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/popo/untyped_subscriber.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" //! [iceoryx includes] #include @@ -37,7 +37,7 @@ int main() //! [create subscriber] //! [poll subscriber for samples in a loop] - while (!iox::posix::hasTerminationRequested()) + while (!iox::hasTerminationRequested()) { //! [take chunk] subscriber.take().and_then([&](auto& userPayload) { diff --git a/iceoryx_examples/waitset/ice_waitset_publisher.cpp b/iceoryx_examples/waitset/ice_waitset_publisher.cpp index 968e06163f..4fcc03ac35 100644 --- a/iceoryx_examples/waitset/ice_waitset_publisher.cpp +++ b/iceoryx_examples/waitset/ice_waitset_publisher.cpp @@ -16,7 +16,7 @@ #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" #include "topic_data.hpp" #include @@ -27,7 +27,7 @@ void sending() iox::runtime::PoshRuntime::initRuntime("iox-cpp-publisher-waitset"); iox::popo::Publisher myPublisher({"Radar", "FrontLeft", "Counter"}); - for (uint32_t counter = 0U; !iox::posix::hasTerminationRequested(); ++counter) + for (uint32_t counter = 0U; !iox::hasTerminationRequested(); ++counter) { myPublisher.publishCopyOf(CounterTopic{counter}) .and_then([&] { std::cout << "Sending: " << counter << std::endl; }) diff --git a/iceoryx_hoofs/cmake/IceoryxPlatform.cmake b/iceoryx_hoofs/cmake/IceoryxPlatform.cmake index 293920bb46..5f143d95ef 100644 --- a/iceoryx_hoofs/cmake/IceoryxPlatform.cmake +++ b/iceoryx_hoofs/cmake/IceoryxPlatform.cmake @@ -80,7 +80,7 @@ function(iox_create_lsan_runtime_blacklist BLACKLIST_FILE_PATH) # count bytes template # 8 642 libacl.so.1 # 1 24 iox::posix::UnixDomainSocket::timedReceive - # 1 24 iox::posix::MessageQueue::receive + # 1 24 iox::MessageQueue::receive if(NOT EXISTS ${BLACKLIST_FILE_PATH}) file(WRITE ${BLACKLIST_FILE_PATH} "# This file is auto-generated from iceoryx_hoofs/cmake/IceoryxPlatform.cmake\n") file(APPEND ${BLACKLIST_FILE_PATH} "#leak:libacl.so.1\n") diff --git a/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp b/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp index 461b1a417b..b0ce97c127 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/runtime/ipc_interface_base.hpp @@ -33,8 +33,8 @@ #include "iox/relative_pointer.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp" -#include "iox/posix/message_queue.hpp" -#include "iox/posix/named_pipe.hpp" +#include "iox/message_queue.hpp" +#include "iox/named_pipe.hpp" #include #include @@ -50,9 +50,9 @@ namespace iox namespace platform { #if defined(_WIN32) -using IoxIpcChannelType = iox::posix::NamedPipe; +using IoxIpcChannelType = iox::NamedPipe; #elif defined(__FREERTOS__) -using IoxIpcChannelType = iox::posix::NamedPipe; +using IoxIpcChannelType = iox::NamedPipe; #else using IoxIpcChannelType = iox::posix::UnixDomainSocket; #endif diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp index dafe078176..c5d3e03c7b 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp @@ -48,7 +48,7 @@ class RouDiApp protected: /// @brief waits for the next signal to RouDi daemon - IOX_DEPRECATED_SINCE(3, "Please use iox::posix::waitForTerminationRequest() from 'iox/posix/signal_watcher.hpp'") + IOX_DEPRECATED_SINCE(3, "Please use iox::posix::waitForTerminationRequest() from 'iox/signal_watcher.hpp'") bool waitForSignal() noexcept; iox::log::LogLevel m_logLevel{iox::log::LogLevel::WARN}; diff --git a/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp b/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp index 5841e2eff8..55d4a7a2c3 100644 --- a/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp +++ b/iceoryx_posh/source/roudi/application/iceoryx_roudi_app.cpp @@ -20,8 +20,8 @@ #include "iceoryx_posh/internal/roudi/roudi.hpp" #include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp" #include "iox/optional.hpp" -#include "iox/posix/signal_watcher.hpp" #include "iox/scoped_static.hpp" +#include "iox/signal_watcher.hpp" namespace iox { @@ -50,7 +50,7 @@ uint8_t IceOryxRouDiApp::run() noexcept m_compatibilityCheckLevel, m_processKillDelay, m_processTeminationDelay}); - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); } return EXIT_SUCCESS; } diff --git a/iceoryx_posh/source/roudi/application/roudi_app.cpp b/iceoryx_posh/source/roudi/application/roudi_app.cpp index 9fd29f0e6f..7a3987720e 100644 --- a/iceoryx_posh/source/roudi/application/roudi_app.cpp +++ b/iceoryx_posh/source/roudi/application/roudi_app.cpp @@ -25,7 +25,7 @@ #include "iceoryx_posh/roudi/cmd_line_args.hpp" #include "iox/logging.hpp" #include "iox/optional.hpp" -#include "iox/posix/signal_watcher.hpp" +#include "iox/signal_watcher.hpp" namespace iox { @@ -79,7 +79,7 @@ bool RouDiApp::checkAndOptimizeConfig(const RouDiConfig_t& config) noexcept bool RouDiApp::waitForSignal() noexcept { - iox::posix::waitForTerminationRequest(); + iox::waitForTerminationRequest(); return true; } diff --git a/iceoryx_posh/source/runtime/ipc_interface_base.cpp b/iceoryx_posh/source/runtime/ipc_interface_base.cpp index bb11b7f6e4..7c505907ea 100644 --- a/iceoryx_posh/source/runtime/ipc_interface_base.cpp +++ b/iceoryx_posh/source/runtime/ipc_interface_base.cpp @@ -242,7 +242,7 @@ bool IpcInterface::ipcChannelMapsToFile() noexcept } template <> -bool IpcInterface::ipcChannelMapsToFile() noexcept +bool IpcInterface::ipcChannelMapsToFile() noexcept { return true; } @@ -263,8 +263,8 @@ void IpcInterface::cleanupOutdatedIpcChannel(const RuntimeName_t } template class IpcInterface; -template class IpcInterface; -template class IpcInterface; +template class IpcInterface; +template class IpcInterface; } // namespace runtime } // namespace iox diff --git a/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp b/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp index 24aa9d59e4..f8e71c48bc 100644 --- a/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp +++ b/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp @@ -22,7 +22,7 @@ #include "iceoryx_posh/internal/runtime/ipc_message.hpp" #include "iceoryx_posh/internal/runtime/ipc_runtime_interface.hpp" #include "iox/duration.hpp" -#include "iox/posix/message_queue.hpp" +#include "iox/message_queue.hpp" #include "iox/std_string_support.hpp" diff --git a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp index 77bbf6efed..5ab99b5b22 100644 --- a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp +++ b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface.cpp @@ -18,8 +18,8 @@ #include "iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp" #include "iceoryx_platform/platform_settings.hpp" #include "iceoryx_posh/internal/runtime/ipc_interface_base.hpp" -#include "iox/posix/message_queue.hpp" -#include "iox/posix/named_pipe.hpp" +#include "iox/message_queue.hpp" +#include "iox/named_pipe.hpp" #include "iox/std_chrono_support.hpp" #include "test.hpp" From f7ad923d05b30983cba8306c4b834911a3c506fc Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 16 Nov 2023 21:33:26 +0100 Subject: [PATCH 62/85] iox-#2066 Make bazel build with C++17 --- .bazelrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index 3069ddafe9..89373b7217 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,4 +1,4 @@ -build --cxxopt="-std=c++14" +build --cxxopt="-std=c++17" # For using clang build:clang --action_env=BAZEL_COMPILER=clang From 622f9b596e37cd0a97bb6de496354c3a0b4c5f98 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 16 Nov 2023 23:26:22 +0100 Subject: [PATCH 63/85] iox-#2066 Fix GCC 8 build --- iceoryx_posh/test/CMakeLists.txt | 2 +- .../moduletests/test_popo_toml_gateway_config_parser.cpp | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/iceoryx_posh/test/CMakeLists.txt b/iceoryx_posh/test/CMakeLists.txt index f79e324c00..7e936913bb 100644 --- a/iceoryx_posh/test/CMakeLists.txt +++ b/iceoryx_posh/test/CMakeLists.txt @@ -57,7 +57,7 @@ iox_add_executable( TARGET ${PROJECT_PREFIX}_moduletests INCLUDE_DIRECTORIES . ${CMAKE_BINARY_DIR}/generated LIBS ${TEST_LINK_LIBS} - LIBS_LINUX dl + LIBS_LINUX dl stdc++fs STACK_SIZE ${ICEORYX_POSH_TEST_STACK_SIZE} FILES ${MODULETESTS_SRC} diff --git a/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp b/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp index 7fd706fcbe..df71ee2a3c 100644 --- a/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp @@ -26,9 +26,7 @@ #include #include // workaround for missing include in cpptoml.h -#if __cplusplus >= 201703L #include -#endif #include #include @@ -54,9 +52,6 @@ TEST_F(TomlGatewayConfigParserTest, ParsingFileIsSuccessful) { ::testing::Test::RecordProperty("TEST_ID", "78b50f73-f17f-45e2-a091-aaad6c536c3a"); -#if __cplusplus < 201703L - GTEST_SKIP() << "The test uses std::filesystem which is only available with C++17"; -#else auto tempFilePath = std::filesystem::temp_directory_path(); tempFilePath.append("test_gateway_config.toml"); @@ -77,7 +72,6 @@ TEST_F(TomlGatewayConfigParserTest, ParsingFileIsSuccessful) GTEST_FAIL() << "Expected a config but got error: " << iox::config::TOML_GATEWAY_CONFIG_FILE_PARSE_ERROR_STRINGS[static_cast(error)]; }); -#endif } class TomlGatewayConfigParserSuiteTest : public TestWithParam From e900856a8d4bbf24c48649bd40f07bbd1bc8bf62 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 00:05:33 +0100 Subject: [PATCH 64/85] iox-#2066 Fix Windows build --- .../test/moduletests/test_popo_toml_gateway_config_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp b/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp index df71ee2a3c..2e7e13998f 100644 --- a/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp @@ -64,7 +64,7 @@ TEST_F(TomlGatewayConfigParserTest, ParsingFileIsSuccessful) )"; tempFile.close(); - iox::roudi::ConfigFilePathString_t configFilePath{iox::TruncateToCapacity, tempFilePath.c_str()}; + iox::roudi::ConfigFilePathString_t configFilePath{iox::TruncateToCapacity, tempFilePath.u8string().c_str()}; TomlGatewayConfigParser::parse(configFilePath) .and_then([](const auto&) { GTEST_SUCCEED() << "We got a config!"; }) From 5ed523149f45f6678ec599df80b59f1f2006d42d Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 00:10:02 +0100 Subject: [PATCH 65/85] iox-#2066 Make 'PortUser_IntegrationTest' more robust --- .../integrationtests/test_popo_port_user_building_blocks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 31fcf6c8ca..c05f2b1db8 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 @@ -206,7 +206,7 @@ class PortUser_IntegrationTest : public Test static_cast(subscriberPortRouDi.dispatchCaProMessageAndGetPossibleResponse(caproMessage)); // Subscription done and ready to receive samples - while (!finished) + while (!finished || subscriberPortUser.hasNewChunks()) { // Try to receive chunk subscriberPortUser.tryGetChunk() From 16999d423e0ad38caa7c4c367ac90d55f10b10d0 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 02:20:26 +0100 Subject: [PATCH 66/85] iox-#2066 Deactivate additional 'TomlGatewayConfigParser' test on Windows --- tools/ci/build-test-windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci/build-test-windows.ps1 b/tools/ci/build-test-windows.ps1 index e7cc891703..8883c41ea5 100755 --- a/tools/ci/build-test-windows.ps1 +++ b/tools/ci/build-test-windows.ps1 @@ -34,7 +34,7 @@ if ($?) { build\hoofs\test\Debug\hoofs_moduletests.exe --gtest_filter="-*TimingT if ($?) { build\hoofs\test\Debug\hoofs_mocktests.exe } if ($?) { build\hoofs\test\Debug\hoofs_integrationtests.exe } if ($?) { build\binding_c\test\Debug\binding_c_moduletests.exe --gtest_filter="-BindingC_Runtime_test.RuntimeNameLengthIsOutOfLimit:BindingC_Runtime_test.RuntimeNameIsNullptr:*TimingTest*" } -if ($?) { build\posh\test\Debug\posh_moduletests.exe --gtest_filter="-ChunkHeader_test.ChunkHeaderBinaryCompatibilityCheck:TomlGatewayConfigParserSuiteTest*:IceoryxRoudiApp_test.ConstructorCalledWithArgUniqueIdTwoTimesReturnError:IceoryxRoudiApp_test.ConstructorCalledWithArgVersionSetRunVariableToFalse:ValidTest*:ParseAllMalformedInput*:*TimingTest*:MePooSegment_test.SharedMemoryFileHandleRightsAfterConstructor" } +if ($?) { build\posh\test\Debug\posh_moduletests.exe --gtest_filter="-ChunkHeader_test.ChunkHeaderBinaryCompatibilityCheck:TomlGatewayConfigParser*:IceoryxRoudiApp_test.ConstructorCalledWithArgUniqueIdTwoTimesReturnError:IceoryxRoudiApp_test.ConstructorCalledWithArgVersionSetRunVariableToFalse:ValidTest*:ParseAllMalformedInput*:*TimingTest*:MePooSegment_test.SharedMemoryFileHandleRightsAfterConstructor" } if ($?) { build\posh\test\Debug\posh_integrationtests.exe --gtest_filter="-ChunkBuildingBlocks_IntegrationTest.TwoHopsThreeThreadsNoSoFi:*TimingTest*" } exit $LASTEXITCODE From 7bc5a16d913251af2d4c37d04db54009fba2744e Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 00:44:18 +0100 Subject: [PATCH 67/85] iox-#2060 Pass 'function_ref' by value instead of by reference --- iceoryx_hoofs/memory/include/iox/detail/scope_guard.inl | 2 +- iceoryx_hoofs/memory/include/iox/scope_guard.hpp | 2 +- iceoryx_hoofs/posix/time/include/iox/detail/adaptive_wait.hpp | 2 +- iceoryx_hoofs/posix/time/source/adaptive_wait.cpp | 2 +- .../internal/popo/building_blocks/condition_listener.hpp | 2 +- .../include/iceoryx_posh/runtime/service_discovery.hpp | 2 +- .../source/popo/building_blocks/condition_listener.cpp | 2 +- iceoryx_posh/source/runtime/service_discovery.cpp | 2 +- .../test/moduletests/test_popo_condition_variable.cpp | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/iceoryx_hoofs/memory/include/iox/detail/scope_guard.inl b/iceoryx_hoofs/memory/include/iox/detail/scope_guard.inl index da57afa6ab..33fe4adf74 100644 --- a/iceoryx_hoofs/memory/include/iox/detail/scope_guard.inl +++ b/iceoryx_hoofs/memory/include/iox/detail/scope_guard.inl @@ -31,7 +31,7 @@ inline ScopeGuardWithVariableCapacity::ScopeGuardWithVariableCa template inline ScopeGuardWithVariableCapacity::ScopeGuardWithVariableCapacity( - const function_ref& initFunction, const function& cleanupFunction) noexcept + const function_ref initFunction, const function& cleanupFunction) noexcept : ScopeGuardWithVariableCapacity(cleanupFunction) { initFunction(); diff --git a/iceoryx_hoofs/memory/include/iox/scope_guard.hpp b/iceoryx_hoofs/memory/include/iox/scope_guard.hpp index 3fe672d2fe..08b4a9b823 100644 --- a/iceoryx_hoofs/memory/include/iox/scope_guard.hpp +++ b/iceoryx_hoofs/memory/include/iox/scope_guard.hpp @@ -53,7 +53,7 @@ class ScopeGuardWithVariableCapacity final /// called in the destructor /// @param[in] initFunction callable which will be called in the constructor /// @param[in] cleanupFunction callable which will be called in the destructor - ScopeGuardWithVariableCapacity(const function_ref& initFunction, + ScopeGuardWithVariableCapacity(const function_ref initFunction, const function& cleanupFunction) noexcept; /// @brief calls m_cleanupFunction callable if it was set in the constructor diff --git a/iceoryx_hoofs/posix/time/include/iox/detail/adaptive_wait.hpp b/iceoryx_hoofs/posix/time/include/iox/detail/adaptive_wait.hpp index f23aa2d7c9..64f12141a4 100644 --- a/iceoryx_hoofs/posix/time/include/iox/detail/adaptive_wait.hpp +++ b/iceoryx_hoofs/posix/time/include/iox/detail/adaptive_wait.hpp @@ -54,7 +54,7 @@ class adaptive_wait /// @brief Waits in a loop in a smart wait until continueToWait returns false. /// @param[in] continueToWait callable which returns if the wait should continue - void wait_loop(const function_ref& continueToWait) noexcept; + void wait_loop(const function_ref continueToWait) noexcept; protected: /// @note All numbers are not accurate and are just rough estimates diff --git a/iceoryx_hoofs/posix/time/source/adaptive_wait.cpp b/iceoryx_hoofs/posix/time/source/adaptive_wait.cpp index 4ef9f87c9d..d7a0211af1 100644 --- a/iceoryx_hoofs/posix/time/source/adaptive_wait.cpp +++ b/iceoryx_hoofs/posix/time/source/adaptive_wait.cpp @@ -45,7 +45,7 @@ void adaptive_wait::wait() noexcept } } -void adaptive_wait::wait_loop(const function_ref& continueToWait) noexcept +void adaptive_wait::wait_loop(const function_ref continueToWait) noexcept { while (continueToWait()) { diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp index 1b78cfd3d5..c3f570ab21 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp @@ -72,7 +72,7 @@ class ConditionListener void resetUnchecked(const uint64_t index) noexcept; void resetSemaphore() noexcept; - NotificationVector_t waitImpl(const function_ref& waitCall) noexcept; + NotificationVector_t waitImpl(const function_ref waitCall) noexcept; private: ConditionVariableData* m_condVarDataPtr{nullptr}; diff --git a/iceoryx_posh/include/iceoryx_posh/runtime/service_discovery.hpp b/iceoryx_posh/include/iceoryx_posh/runtime/service_discovery.hpp index 7aa4e92721..cf8f401aed 100644 --- a/iceoryx_posh/include/iceoryx_posh/runtime/service_discovery.hpp +++ b/iceoryx_posh/include/iceoryx_posh/runtime/service_discovery.hpp @@ -62,7 +62,7 @@ class ServiceDiscovery void findService(const optional& service, const optional& instance, const optional& event, - const function_ref& callableForEach, + const function_ref callableForEach, const popo::MessagingPattern pattern) noexcept; friend iox::popo::NotificationAttorney; diff --git a/iceoryx_posh/source/popo/building_blocks/condition_listener.cpp b/iceoryx_posh/source/popo/building_blocks/condition_listener.cpp index 5a37ff224e..2d62ab2d40 100644 --- a/iceoryx_posh/source/popo/building_blocks/condition_listener.cpp +++ b/iceoryx_posh/source/popo/building_blocks/condition_listener.cpp @@ -79,7 +79,7 @@ ConditionListener::NotificationVector_t ConditionListener::timedWait(const units }); } -ConditionListener::NotificationVector_t ConditionListener::waitImpl(const function_ref& waitCall) noexcept +ConditionListener::NotificationVector_t ConditionListener::waitImpl(const function_ref waitCall) noexcept { using Type_t = iox::BestFittingType_t; NotificationVector_t activeNotifications; diff --git a/iceoryx_posh/source/runtime/service_discovery.cpp b/iceoryx_posh/source/runtime/service_discovery.cpp index f0217d0ab4..6380b37ac4 100644 --- a/iceoryx_posh/source/runtime/service_discovery.cpp +++ b/iceoryx_posh/source/runtime/service_discovery.cpp @@ -37,7 +37,7 @@ void ServiceDiscovery::update() void ServiceDiscovery::findService(const optional& service, const optional& instance, const optional& event, - const function_ref& callableForEach, + const function_ref callableForEach, const popo::MessagingPattern pattern) noexcept { update(); diff --git a/iceoryx_posh/test/moduletests/test_popo_condition_variable.cpp b/iceoryx_posh/test/moduletests/test_popo_condition_variable.cpp index f67b2cf568..88aa65e544 100644 --- a/iceoryx_posh/test/moduletests/test_popo_condition_variable.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_condition_variable.cpp @@ -437,7 +437,7 @@ TIMING_TEST_F(ConditionVariable_test, SecondWaitBlocksUntilNewNotification, Repe }) void waitReturnsSortedListWhenTriggeredInOrder(ConditionVariable_test& test, - const iox::function_ref& wait) + const iox::function_ref wait) { for (uint64_t i = 0U; i < test.m_notifiers.size(); ++i) { @@ -466,7 +466,7 @@ TEST_F(ConditionVariable_test, TimedWaitReturnsSortedListWhenTriggeredInOrder) } void waitReturnsSortedListWhenTriggeredInReverseOrder( - ConditionVariable_test& test, const iox::function_ref& wait) + ConditionVariable_test& test, const iox::function_ref wait) { for (uint64_t i = 0U; i < test.m_notifiers.size(); ++i) { From d73e518238dfde9ed679d53387e5e728d9aafe3a Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 00:48:34 +0100 Subject: [PATCH 68/85] iox-#2060 Give static code analyer a better hint for the 'nullptr' check in 'function_ref' --- .../functional/include/iox/detail/function_ref.inl | 11 ++++++----- .../test/moduletests/test_functional_function_ref.cpp | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/iceoryx_hoofs/functional/include/iox/detail/function_ref.inl b/iceoryx_hoofs/functional/include/iox/detail/function_ref.inl index 88106fcf1e..0e2f04bb0f 100644 --- a/iceoryx_hoofs/functional/include/iox/detail/function_ref.inl +++ b/iceoryx_hoofs/functional/include/iox/detail/function_ref.inl @@ -18,7 +18,7 @@ #ifndef IOX_HOOFS_FUNCTIONAL_FUNCTION_REF_INL #define IOX_HOOFS_FUNCTIONAL_FUNCTION_REF_INL -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iceoryx_hoofs/error_reporting/error_reporting_macros.hpp" #include "iox/function_ref.hpp" #include @@ -94,10 +94,11 @@ template // AXIVION Next Construct AutosarC++19_03-A15.4.2, AutosarC++19_03-A15.5.3, FaultDetection-NoexceptViolations : Intentional behavior. The library itself does not throw and on the implementation side a try-catch block can be used inline ReturnType function_ref::operator()(ArgTypes... args) const noexcept { - // Expect that a callable was assigned beforehand - IOX_EXPECTS_WITH_MSG((m_pointerToCallable != nullptr) && (m_functionPointer != nullptr), - "Empty function_ref invoked"); - // AXIVION Next Line AutosarC++19_03-M0.3.1, FaultDetection-NullPointerDereference : 'nullptr' check is done above + auto wasCallableAssignedBeforehand = (m_pointerToCallable != nullptr) && (m_functionPointer != nullptr); + if (!wasCallableAssignedBeforehand) + { + IOX_PANIC("Empty function_ref invoked"); + } return m_functionPointer(m_pointerToCallable, std::forward(args)...); } diff --git a/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp b/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp index 3cc5ee0fac..ef46e90440 100644 --- a/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp +++ b/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/error_handling/error_handling.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "iox/attributes.hpp" #include "iox/function_ref.hpp" #include "test.hpp" @@ -171,8 +171,10 @@ TEST_F(function_refDeathTest, CallMovedFromLeadsToTermination) // NOLINTJUSTIFICATION Use after move is tested here // NOLINTBEGIN(bugprone-use-after-move, hicpp-invalid-access-moved) - IOX_EXPECT_FATAL_FAILURE([&] { sut1(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); + runInTestThread([&] { sut1(); }); // NOLINTEND(bugprone-use-after-move, hicpp-invalid-access-moved) + + IOX_TESTING_EXPECT_PANIC(); } TEST_F(function_refTest, CreateValidAndSwapResultEqual) From 40456943ed8af342594172b6d8e5c45546d19811 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 01:00:05 +0100 Subject: [PATCH 69/85] iox-#2060 Update release notes --- doc/website/release-notes/iceoryx-unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index e295e1bae5..f9e93266f3 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -104,6 +104,7 @@ - Implement move/copy constructor and assignment for `FixedPositionContainer` [#2052](https://github.com/eclipse-iceoryx/iceoryx/issues/2052) - FixedPositionContainer fails to compile on QNX QCC [#2084](https://github.com/eclipse-iceoryx/iceoryx/issues/2084) - Chunk fails to be released when more than 4 GiB of chunks have been allocated [#2087](https://github.com/eclipse-iceoryx/iceoryx/issues/2087) +- Fix clang-tidy errors from full-scan nightly build [#2060](https://github.com/eclipse-iceoryx/iceoryx/issues/2060) **Refactoring:** From 16ce3b3880c6d6a5720c617357d468854d88101e Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 14:59:17 +0100 Subject: [PATCH 70/85] iox-#2060 Fix another false positive clang-tidy warning --- .../test/moduletests/test_container_list.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/iceoryx_hoofs/test/moduletests/test_container_list.cpp b/iceoryx_hoofs/test/moduletests/test_container_list.cpp index f87322451d..f225146187 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_list.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_list.cpp @@ -548,7 +548,7 @@ TEST_F(list_test, EmplaceBackWithOneElements) for (uint64_t i = 0U; i < ELEMENT_COUNT; ++i) { - EXPECT_THAT(sut1.emplace_back(cnt), Eq(TestListElement{cnt})); + EXPECT_THAT(sut1.emplace_back(cnt).value, Eq(cnt)); ++cnt; } @@ -561,7 +561,7 @@ TEST_F(list_test, EmplaceBackWithOneElements) EXPECT_THAT(sut1.size(), Eq(ELEMENT_COUNT)); EXPECT_THAT(stats.cTor, Eq(0U)); - EXPECT_THAT(stats.customCTor, Eq(ELEMENT_COUNT * 2U)); + EXPECT_THAT(stats.customCTor, Eq(ELEMENT_COUNT)); } TEST_F(list_test, EmplaceBackWithSomeElements) @@ -577,7 +577,7 @@ TEST_F(list_test, EmplaceBackWithSomeElements) for (uint64_t i = 0U; i < ELEMENT_COUNT; ++i) { - EXPECT_THAT(sut1.emplace_back(cnt), Eq(TestListElement{cnt})); + EXPECT_THAT(sut1.emplace_back(cnt).value, Eq(cnt)); ++cnt; } @@ -590,7 +590,7 @@ TEST_F(list_test, EmplaceBackWithSomeElements) EXPECT_THAT(sut1.size(), Eq(ELEMENT_COUNT)); EXPECT_THAT(stats.cTor, Eq(0U)); - EXPECT_THAT(stats.customCTor, Eq(ELEMENT_COUNT * 2U)); + EXPECT_THAT(stats.customCTor, Eq(ELEMENT_COUNT)); } TEST_F(list_test, EmplaceBackWithCapacityElements) @@ -603,7 +603,7 @@ TEST_F(list_test, EmplaceBackWithCapacityElements) for (uint64_t i = 0U; i < ELEMENT_COUNT; ++i) { - EXPECT_THAT(sut1.emplace_back(cnt), Eq(TestListElement{cnt})); + EXPECT_THAT(sut1.emplace_back(cnt).value, Eq(cnt)); ++cnt; } @@ -616,7 +616,7 @@ TEST_F(list_test, EmplaceBackWithCapacityElements) EXPECT_THAT(sut1.size(), Eq(ELEMENT_COUNT)); EXPECT_THAT(stats.cTor, Eq(0U)); - EXPECT_THAT(stats.customCTor, Eq(ELEMENT_COUNT * 2U)); + EXPECT_THAT(stats.customCTor, Eq(ELEMENT_COUNT)); } TEST_F(list_test, EmplaceBackWithMoreThanCapacityElements) @@ -631,7 +631,7 @@ TEST_F(list_test, EmplaceBackWithMoreThanCapacityElements) { if (i < CAPACITY) { - EXPECT_THAT(sut1.emplace_back(cnt), Eq(TestListElement{cnt})); + EXPECT_THAT(sut1.emplace_back(cnt).value, Eq(cnt)); } else { @@ -650,7 +650,7 @@ TEST_F(list_test, EmplaceBackWithMoreThanCapacityElements) EXPECT_THAT(sut1.size(), Eq(CAPACITY)); EXPECT_THAT(stats.cTor, Eq(0U)); - EXPECT_THAT(stats.customCTor, Eq(CAPACITY * 2U)); + EXPECT_THAT(stats.customCTor, Eq(CAPACITY)); } TEST_F(list_test, EmplaceWithWrongListIterator) @@ -1485,7 +1485,7 @@ TEST_F(list_test, IteratorTraitsGetValueType) TEST_F(list_test, IteratorTraitsCheckIteratorCategoryOnConstIterator) { ::testing::Test::RecordProperty("TEST_ID", "295e6406-93bc-4a12-9b03-33e5d494b2c2"); - auto iter = sut.cbegin(); + auto iter [[maybe_unused]] = sut.cbegin(); ASSERT_NE(typeid(std::iterator_traits::iterator_category), typeid(std::random_access_iterator_tag)); EXPECT_EQ(typeid(std::iterator_traits::iterator_category), typeid(std::bidirectional_iterator_tag)); } From ec9041ff646857e45af56016d9b08c16b870cef6 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 18:29:14 +0100 Subject: [PATCH 71/85] iox-#2007 Update developer meetup info --- GOVERNANCE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GOVERNANCE.md b/GOVERNANCE.md index 6c620dd2c1..8bb61c7810 100644 --- a/GOVERNANCE.md +++ b/GOVERNANCE.md @@ -9,9 +9,9 @@ An up to date list of the maintainers can be found at the [Eclipse project page] ## Monthly meetup -The developer meetup is held monthly on the first Thursday from 17:00 - 18:00 CET. Everyone is welcome to join. +The developer meetup is held monthly on the first Tuesday from 17:00 - 18:00 CET. Everyone is welcome to join. -You can join by using this Zoom link: https://eclipse.zoom.us/j/95918504483?pwd=RWM5Y1pkeStKVDZsU09EY1hnclREUT09 +You can join by using this link: https://app.element.io/jitsi.html#conferenceDomain=meet.element.io&conferenceId=JitsiVtfrqukadefbqiqfxryxabai&userId=&roomId=!AooDAAwkyNWwkMElpt%3Agitter.im&roomName=eclipse%2Ficeoryx&startWithAudioMuted=true&startWithVideoMuted=true&language=en For a calendar event, you can subscribe to the [ROS calendar](https://calendar.google.com/calendar/u/0/embed?src=agf3kajirket8khktupm9go748@group.calendar.google.com&ctz=America/Los_Angeles). @@ -49,7 +49,7 @@ If you have points that you want to discuss, please send your points to the [mai **Time:** 17:00 CET -**Link:** https://eclipse.zoom.us/j/95918504483?pwd=RWM5Y1pkeStKVDZsU09EY1hnclREUT09 +**Link:** https://app.element.io/jitsi.html#conferenceDomain=meet.element.io&conferenceId=JitsiVtfrqukadefbqiqfxryxabai&userId=&roomId=!AooDAAwkyNWwkMElpt%3Agitter.im&roomName=eclipse%2Ficeoryx&startWithAudioMuted=true&startWithVideoMuted=true&language=en ## Attendees From 581fb81b0318489995dddc427aa45a9cb2b3090b Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 18 Nov 2023 10:02:23 +0100 Subject: [PATCH 72/85] iox-#2060 Add CI check to make developer aware of failed nightly workflow --- .github/workflows/build-test.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 77c82578b8..7f8899357c 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -23,6 +23,31 @@ jobs: - run: ./tools/scripts/check_invalid_characters.sh - run: ./tools/ci/cmake-linter.sh + check-status-of-nightly-action: + runs-on: ubuntu-latest + needs: pre-flight-check + steps: + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y jq + - name: Check nightly action status + run: | + COLOR_OFF='\033[0m' + COLOR_RED='\033[1;31m' + COLOR_GREEN='\033[1;32m' + COLOR_YELLOW='\033[1;33m' + LAST_RUN_STATUS=$(curl -s "https://api.github.com/repos/eclipse-iceoryx/iceoryx/actions/workflows/nightly.yml/runs" | jq -r '.workflow_runs[0].conclusion') + if [[ "${LAST_RUN_STATUS}" == "success" ]]; then + echo -e "Last nightly run status: ${COLOR_GREEN}${LAST_RUN_STATUS}${COLOR_OFF}" + else + echo -e "Last nightly run status: ${COLOR_RED}${LAST_RUN_STATUS}${COLOR_OFF}" + echo -e "${COLOR_RED}Error! The nightly workflow failed on the last run. Please check and fix the nightly workflow before merging this PR.${COLOR_OFF}" + echo -e "${COLOR_YELLOW}You can trigger the nightly workflow manually from 'https://github.com/eclipse-iceoryx/iceoryx/actions/workflows/nightly.yml'.${COLOR_OFF}" + echo -e "${COLOR_YELLOW}Just look for the 'Run workflow' button. The branch where the workflow shall run can also be selected.${COLOR_OFF}" + exit 1 + fi + build-test-ubuntu: # prevent stuck jobs consuming runners for 6 hours timeout-minutes: 60 From 79cd9896ef1a1b611e7d391c2d36cca0122edfdc Mon Sep 17 00:00:00 2001 From: Luca Bartoli Date: Sun, 19 Nov 2023 21:37:10 +0100 Subject: [PATCH 73/85] iox-#1431: Add unsafe_raw_access to iox::string Implement a method that provides direct access to the string's underlying pointer. This allows data to be written directly to the string, eliminating the need for copies. The string's length is checked on each call to ensure the null terminator is in the correct position. Signed-off-by: Luca Bartoli --- .../release-notes/iceoryx-unreleased.md | 1 + .../buffer/include/iox/buffer_info.hpp | 32 ++++++++ .../moduletests/test_vocabulary_string.cpp | 76 +++++++++++++++++++ .../vocabulary/include/iox/detail/string.inl | 15 ++++ .../vocabulary/include/iox/string.hpp | 17 +++++ 5 files changed, 141 insertions(+) create mode 100644 iceoryx_hoofs/buffer/include/iox/buffer_info.hpp diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index e295e1bae5..8d48e9d46d 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -52,6 +52,7 @@ - Create iceoryx version header for the C-binding [#1014](https://github.com/eclipse-iceoryx/iceoryx/issues/1014) - Create macros to deprecate header and code constructs [#2057](https://github.com/eclipse-iceoryx/iceoryx/issues/2057) - Switch to C++17 on all platforms [#2066](https://github.com/eclipse-iceoryx/iceoryx/issues/2066) +- Implement `unsafe_raw_access` in `iox::string` and add `BufferInfo` struct [#1431](https://github.com/eclipse-iceoryx/iceoryx/issues/1431) **Bugfixes:** diff --git a/iceoryx_hoofs/buffer/include/iox/buffer_info.hpp b/iceoryx_hoofs/buffer/include/iox/buffer_info.hpp new file mode 100644 index 0000000000..49c448d910 --- /dev/null +++ b/iceoryx_hoofs/buffer/include/iox/buffer_info.hpp @@ -0,0 +1,32 @@ +// Copyright 2023, Eclipse Foundation and the iceoryx contributors. 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_HOOFS_BUFFER_BUFFER_INFO_HPP +#define IOX_HOOFS_BUFFER_BUFFER_INFO_HPP + +#include + +namespace iox +{ +/// @brief struct used to define the used size and total size of a buffer +struct BufferInfo +{ + uint64_t used_size{0}; + uint64_t total_size{0}; +}; + +} // namespace iox + +#endif \ No newline at end of file diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp index a6b6b6bd27..4d5e98fb70 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp @@ -19,6 +19,7 @@ #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iox/string.hpp" #include "test.hpp" +#include namespace { @@ -643,6 +644,81 @@ TYPED_TEST(stringTyped_test, UnsafeAssignOfNullptrFails) EXPECT_THAT(this->testSubject.unsafe_assign(nullptr), Eq(false)); } +/// @note void unsafe_raw_access(const std::function& func) noexcept +TYPED_TEST(stringTyped_test, UnsafeRawAccessOfCStringOfSize0ResultsInSize0) +{ + ::testing::Test::RecordProperty("TEST_ID", "43e10399-445d-42af-80b1-25071590de0a"); + this->testSubject.unsafe_raw_access([this](char* str, const auto info) -> uint64_t { + //NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors) + strcpy(str, ""); + EXPECT_THAT(info.used_size, this->testSubject.size()); + using MyString = typename TestFixture::stringType; + EXPECT_THAT(info.total_size, MyString::capacity() + 1); // real buffer size + return 0U; + }); + EXPECT_THAT(this->testSubject.size(), Eq(0U)); + EXPECT_THAT(this->testSubject.c_str(), StrEq("")); +} + +TYPED_TEST(stringTyped_test, UnsafeRawAccessOfCStringOfSize1ResultsInSize1) +{ + ::testing::Test::RecordProperty("TEST_ID", "a3a3395e-2b69-400c-876a-1fdf70cf2d4a"); + this->testSubject.unsafe_raw_access([this](char* str, const auto info) -> uint64_t { + //NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors) + strcpy(str, "M"); + EXPECT_THAT(info.used_size, this->testSubject.size()); + using MyString = typename TestFixture::stringType; + EXPECT_THAT(info.total_size, MyString::capacity() + 1); // real buffer size + return 1U; + }); + EXPECT_THAT(this->testSubject.size(), Eq(1U)); + EXPECT_THAT(this->testSubject.c_str(), StrEq("M")); +} + +TYPED_TEST(stringTyped_test, UnsafeRawAccessCStringOfSizeCapaResultsInSizeCapa) +{ + ::testing::Test::RecordProperty("TEST_ID", "49faad68-52fa-4024-993c-49b05e7cb971"); + using MyString = typename TestFixture::stringType; + constexpr auto STRINGCAP = MyString::capacity(); + std::vector testCharstring(STRINGCAP, 'M'); + testCharstring.emplace_back('\0'); + this->testSubject.unsafe_raw_access([&](char* str, const auto) -> uint64_t { + //NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors) + strcpy(str, testCharstring.data()); + return STRINGCAP; + }); + EXPECT_THAT(this->testSubject.unsafe_assign(testCharstring.data()), Eq(true)); + EXPECT_THAT(this->testSubject.size(), Eq(STRINGCAP)); +} + +TYPED_TEST(stringTyped_test, UnsafeRawAccessCStringOutOfBoundFail) +{ + ::testing::Test::RecordProperty("TEST_ID", "b25c35db-1c0d-4f0e-b4bc-b9430a6696f1"); + IOX_EXPECT_FATAL_FAILURE( + [this] { + this->testSubject.unsafe_raw_access([](char* str, const auto info) -> uint64_t { + //NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors) + strcpy(str, "M"); + return info.total_size + 1U; + }); + }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); +} + +TYPED_TEST(stringTyped_test, UnsafeRawAccessCStringWrongLenghtFail) +{ + ::testing::Test::RecordProperty("TEST_ID", "411f5db1-18b8-45c3-9ad6-3c886fb12a26"); + IOX_EXPECT_FATAL_FAILURE( + [this] { + this->testSubject.unsafe_raw_access([](char* str, const auto) -> uint64_t { + //NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors) + strcpy(str, "M"); + return 0U; + }); + }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); +} + /// @note template /// int64_t compare(const string& other) const noexcept TYPED_TEST(stringTyped_test, CompareEqStringsResultsInZero) diff --git a/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl index 5726ca4c98..aa473123f6 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl +++ b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl @@ -238,6 +238,21 @@ inline bool string::unsafe_assign(const char* const str) noexcept return true; } +template +inline void +string::unsafe_raw_access(const iox::function_ref& func) noexcept +{ + iox::BufferInfo info{m_rawstringSize, Capacity + 1}; + uint64_t len = func(m_rawstring, info); + + IOX_EXPECTS_WITH_MSG(Capacity >= len, + "unsafe_auto_raw_access failed. Data wrote outside the maximun string capacity of " + << Capacity); + IOX_EXPECTS_WITH_MSG(m_rawstring[len] == '\0', "String does not have the terminator at the returned size"); + m_rawstringSize = len; +} + + template template inline IsStringOrCharArray string::compare(const T& other) const noexcept diff --git a/iceoryx_hoofs/vocabulary/include/iox/string.hpp b/iceoryx_hoofs/vocabulary/include/iox/string.hpp index 16f2327cae..3142bffbcf 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/string.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/string.hpp @@ -17,8 +17,10 @@ #ifndef IOX_HOOFS_VOCABULARY_STRING_HPP #define IOX_HOOFS_VOCABULARY_STRING_HPP +#include "iox/buffer_info.hpp" #include "iox/detail/string_internal.hpp" #include "iox/detail/string_type_traits.hpp" +#include "iox/function.hpp" #include "iox/log/logstream.hpp" #include "iox/optional.hpp" #include "iox/type_traits.hpp" @@ -423,6 +425,21 @@ class string final template IsStringOrCharArrayOrChar unsafe_append(const T& str) noexcept; + /// @brief direct access to the string's raw pointer. The access resizes the data with the value returned by the + /// passed function. If the data written has not the terminator at the returned size, a FATAL error occurs. + /// + /// @param [in] function func is a function composed by the raw data pointer and the BufferInfo with current size + /// and total size, including the space for the zero termination. The return value is the string length. + /// + /// @code + /// iox::string<100> s; + /// s.unsafe_raw_access([] (auto* str, const auto info) { + /// strncpy(str, "Hello World", info.total_size); + /// return strlen("Hello World"); + /// }); + /// @endcode + void unsafe_raw_access(const iox::function_ref& func) noexcept; + /// @brief inserts a iox::string or char array in the range [str[0], str[count]) at position pos. The insertion /// fails if the string capacity would be exceeded or pos is greater than the string size or count is greater than /// the string to be inserted. From 2da57d56fd2fa33325c85c5f5ac23b2397dcd3a3 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 19:55:43 +0100 Subject: [PATCH 74/85] iox-#2066 Remove compliler switch from toml config file parser --- .../moduletests/test_roudi_config_toml_file_provider.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_roudi_config_toml_file_provider.cpp b/iceoryx_posh/test/moduletests/test_roudi_config_toml_file_provider.cpp index 4c65fabd89..f1a1093dac 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_config_toml_file_provider.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_config_toml_file_provider.cpp @@ -21,9 +21,7 @@ #include "test.hpp" -#if __cplusplus >= 201703L #include -#endif #include #include @@ -73,9 +71,6 @@ TEST_F(RoudiConfigTomlFileProvider_test, ParsingFileIsSuccessful) { ::testing::Test::RecordProperty("TEST_ID", "37f5a397-a289-4bc1-86a7-d95851a5ab47"); -#if __cplusplus < 201703L - GTEST_SKIP() << "The test uses std::filesystem which is only available with C++17"; -#else auto tempFilePath = std::filesystem::temp_directory_path(); tempFilePath.append("test_roudi_config.toml"); @@ -92,7 +87,8 @@ TEST_F(RoudiConfigTomlFileProvider_test, ParsingFileIsSuccessful) )"; tempFile.close(); - cmdLineArgs.configFilePath = iox::roudi::ConfigFilePathString_t(iox::TruncateToCapacity, tempFilePath.c_str()); + cmdLineArgs.configFilePath = + iox::roudi::ConfigFilePathString_t(iox::TruncateToCapacity, tempFilePath.u8string().c_str()); iox::config::TomlRouDiConfigFileProvider sut(cmdLineArgs); @@ -100,7 +96,6 @@ TEST_F(RoudiConfigTomlFileProvider_test, ParsingFileIsSuccessful) GTEST_FAIL() << "Expected a config but got error: " << iox::roudi::ROUDI_CONFIG_FILE_PARSE_ERROR_STRINGS[static_cast(error)]; }); -#endif } constexpr const char* CONFIG_NO_GENERAL_SECTION = R"( From 49486b68f453754e22764a9967eec2ab74ca8f5e Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 20:10:23 +0100 Subject: [PATCH 75/85] iox-#2066 Use 'std::invoke_result' instead of alias --- iceoryx_hoofs/primitives/include/iox/type_traits.hpp | 8 +++----- .../include/iceoryx_platform/platform_settings.hpp | 4 ---- .../include/iceoryx_platform/platform_settings.hpp | 9 --------- .../mac/include/iceoryx_platform/platform_settings.hpp | 10 ---------- .../qnx/include/iceoryx_platform/platform_settings.hpp | 9 --------- .../include/iceoryx_platform/platform_settings.hpp | 9 --------- .../win/include/iceoryx_platform/platform_settings.hpp | 9 --------- .../test/moduletests/test_mepoo_chunk_header.cpp | 2 +- 8 files changed, 4 insertions(+), 56 deletions(-) diff --git a/iceoryx_hoofs/primitives/include/iox/type_traits.hpp b/iceoryx_hoofs/primitives/include/iox/type_traits.hpp index 004f91c480..986e4f1481 100644 --- a/iceoryx_hoofs/primitives/include/iox/type_traits.hpp +++ b/iceoryx_hoofs/primitives/include/iox/type_traits.hpp @@ -64,9 +64,8 @@ template struct is_invocable { // This variant is chosen when Callable(ArgTypes) successfully resolves to a valid type, i.e. is invocable. - /// @note result_of is deprecated, switch to invoke_result in C++17 template - static constexpr std::true_type test(typename platform::invoke_result::type*) noexcept + static constexpr std::true_type test(typename std::invoke_result::type*) noexcept { return {}; } @@ -95,9 +94,8 @@ template struct is_invocable_r { template - static constexpr std::true_type - test(std::enable_if_t< - std::is_convertible::type, ReturnType>::value>*) noexcept + static constexpr std::true_type test( + std::enable_if_t::type, ReturnType>::value>*) noexcept { return {}; } diff --git a/iceoryx_platform/freertos/include/iceoryx_platform/platform_settings.hpp b/iceoryx_platform/freertos/include/iceoryx_platform/platform_settings.hpp index c6c8126202..e40a5b2032 100644 --- a/iceoryx_platform/freertos/include/iceoryx_platform/platform_settings.hpp +++ b/iceoryx_platform/freertos/include/iceoryx_platform/platform_settings.hpp @@ -22,7 +22,6 @@ #include #include -#include #ifndef PATH_MAX #define PATH_MAX (2 * NAME_MAX) @@ -53,9 +52,6 @@ constexpr const char IOX_LOCK_FILE_PATH_PREFIX[] = "/tmp/"; constexpr uint64_t MAX_USER_NAME_LENGTH = 32; constexpr uint64_t MAX_GROUP_NAME_LENGTH = 16; - -template -using invoke_result = std::result_of; } // namespace platform } // namespace iox diff --git a/iceoryx_platform/linux/include/iceoryx_platform/platform_settings.hpp b/iceoryx_platform/linux/include/iceoryx_platform/platform_settings.hpp index dbe087264b..97ec965926 100644 --- a/iceoryx_platform/linux/include/iceoryx_platform/platform_settings.hpp +++ b/iceoryx_platform/linux/include/iceoryx_platform/platform_settings.hpp @@ -18,7 +18,6 @@ #include #include -#include namespace iox { @@ -41,14 +40,6 @@ constexpr const char IOX_TEMP_DIR[] = "/tmp/"; constexpr uint64_t MAX_USER_NAME_LENGTH = 32; constexpr uint64_t MAX_GROUP_NAME_LENGTH = 32; - -#if __cplusplus >= 201703L -template -using invoke_result = std::invoke_result; -#else -template -using invoke_result = std::result_of; -#endif } // namespace platform } // namespace iox diff --git a/iceoryx_platform/mac/include/iceoryx_platform/platform_settings.hpp b/iceoryx_platform/mac/include/iceoryx_platform/platform_settings.hpp index 52426e4fc8..d470c276a0 100644 --- a/iceoryx_platform/mac/include/iceoryx_platform/platform_settings.hpp +++ b/iceoryx_platform/mac/include/iceoryx_platform/platform_settings.hpp @@ -17,7 +17,6 @@ #define IOX_HOOFS_MAC_PLATFORM_PLATFORM_SETTINGS_HPP #include -#include namespace iox { @@ -42,15 +41,6 @@ constexpr const char IOX_TEMP_DIR[] = "/tmp/"; constexpr uint64_t MAX_USER_NAME_LENGTH = 32; constexpr uint64_t MAX_GROUP_NAME_LENGTH = 16; - -#if __cplusplus >= 201703L -template -using invoke_result = std::invoke_result; -#else -template -using invoke_result = std::result_of; -#endif - } // namespace platform } // namespace iox diff --git a/iceoryx_platform/qnx/include/iceoryx_platform/platform_settings.hpp b/iceoryx_platform/qnx/include/iceoryx_platform/platform_settings.hpp index 49ac5ed24b..900e81cdd6 100644 --- a/iceoryx_platform/qnx/include/iceoryx_platform/platform_settings.hpp +++ b/iceoryx_platform/qnx/include/iceoryx_platform/platform_settings.hpp @@ -17,7 +17,6 @@ #define IOX_HOOFS_QNX_PLATFORM_PLATFORM_SETTINGS_HPP #include -#include namespace iox { @@ -40,14 +39,6 @@ constexpr const char IOX_TEMP_DIR[] = "/tmp/"; constexpr uint64_t MAX_USER_NAME_LENGTH = 32; constexpr uint64_t MAX_GROUP_NAME_LENGTH = 16; - -#if __cplusplus >= 201703L -template -using invoke_result = std::invoke_result; -#else -template -using invoke_result = std::result_of; -#endif } // namespace platform } // namespace iox diff --git a/iceoryx_platform/unix/include/iceoryx_platform/platform_settings.hpp b/iceoryx_platform/unix/include/iceoryx_platform/platform_settings.hpp index 9e2a3c6e6e..c00258042c 100644 --- a/iceoryx_platform/unix/include/iceoryx_platform/platform_settings.hpp +++ b/iceoryx_platform/unix/include/iceoryx_platform/platform_settings.hpp @@ -18,7 +18,6 @@ #include #include -#include namespace iox { @@ -42,14 +41,6 @@ constexpr const char IOX_TEMP_DIR[] = "/tmp/"; constexpr uint64_t MAX_USER_NAME_LENGTH = 32; constexpr uint64_t MAX_GROUP_NAME_LENGTH = 16; -#if __cplusplus >= 201703L -template -using invoke_result = std::invoke_result; -#else -template -using invoke_result = std::result_of; -#endif - } // namespace platform } // namespace iox diff --git a/iceoryx_platform/win/include/iceoryx_platform/platform_settings.hpp b/iceoryx_platform/win/include/iceoryx_platform/platform_settings.hpp index 67b529667c..a0d4ce943a 100644 --- a/iceoryx_platform/win/include/iceoryx_platform/platform_settings.hpp +++ b/iceoryx_platform/win/include/iceoryx_platform/platform_settings.hpp @@ -17,7 +17,6 @@ #define IOX_HOOFS_WIN_PLATFORM_PLATFORM_SETTINGS_HPP #include -#include namespace iox { @@ -44,14 +43,6 @@ constexpr uint64_t IOX_MAX_PATH_LENGTH = 255U; constexpr uint64_t MAX_USER_NAME_LENGTH = 32; constexpr uint64_t MAX_GROUP_NAME_LENGTH = 16; -#if __cplusplus >= 201703L -template -using invoke_result = std::invoke_result; -#else -template -using invoke_result = std::result_of; -#endif - namespace win32 { // just increase this number to increase the maximum shared memory size supported diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 0b82124923..d9094728a2 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -145,7 +145,7 @@ TEST(ChunkHeader_test, ChunkHeaderBinaryCompatibilityCheck) TEST(ChunkHeader_test, ChunkHeaderUserPayloadSizeTypeIsLargeEnoughForMempoolChunk) { ::testing::Test::RecordProperty("TEST_ID", "540e2e95-0890-4522-ae7f-c6d867679e0b"); - using ChunkSize_t = iox::platform::invoke_result::type; + using ChunkSize_t = std::invoke_result::type; auto maxOfChunkSizeType = std::numeric_limits::max(); auto maxOfUserPayloadSizeType = std::numeric_limits().userPayloadSize())>::max(); From b7ad3606c8961d5de1f06af5226f9de9099e8594 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 20:21:06 +0100 Subject: [PATCH 76/85] iox-#2066 Remove iceoryx_platform/attributes.hpp --- .../include/iceoryx_hoofs/cxx/attributes.hpp | 7 +++ .../posix/filesystem/source/file.cpp | 2 +- .../primitives/include/iox/attributes.hpp | 8 ++- .../include/iceoryx_platform/attributes.hpp | 52 ------------------- .../include/iceoryx_platform/attributes.hpp | 51 ------------------ .../include/iceoryx_platform/attributes.hpp | 26 ---------- .../include/iceoryx_platform/attributes.hpp | 39 -------------- .../include/iceoryx_platform/attributes.hpp | 26 ---------- .../include/iceoryx_platform/attributes.hpp | 26 ---------- 9 files changed, 14 insertions(+), 223 deletions(-) delete mode 100644 iceoryx_platform/freertos/include/iceoryx_platform/attributes.hpp delete mode 100644 iceoryx_platform/linux/include/iceoryx_platform/attributes.hpp delete mode 100644 iceoryx_platform/mac/include/iceoryx_platform/attributes.hpp delete mode 100644 iceoryx_platform/qnx/include/iceoryx_platform/attributes.hpp delete mode 100644 iceoryx_platform/unix/include/iceoryx_platform/attributes.hpp delete mode 100644 iceoryx_platform/win/include/iceoryx_platform/attributes.hpp diff --git a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp index 95ce32b80a..b070ba5c89 100644 --- a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp +++ b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp @@ -33,6 +33,13 @@ namespace internal /// @deprecated use 'iox::internal::IOX_DISCARD_RESULT_IMPL' instead of 'iox::cxx::internal::IOX_DISCARD_RESULT_IMPL' using iox::internal::IOX_DISCARD_RESULT_IMPL; } // namespace internal + +// #define IOX_NO_DISCARD [[nodiscard]] + +// #define IOX_FALLTHROUGH [[fallthrough]] + +// #define IOX_MAYBE_UNUSED [[maybe_unused]] + } // namespace cxx } // namespace iox diff --git a/iceoryx_hoofs/posix/filesystem/source/file.cpp b/iceoryx_hoofs/posix/filesystem/source/file.cpp index 74baedc1a7..763789c0ff 100644 --- a/iceoryx_hoofs/posix/filesystem/source/file.cpp +++ b/iceoryx_hoofs/posix/filesystem/source/file.cpp @@ -16,10 +16,10 @@ #include "iox/file.hpp" #include "iceoryx_hoofs/posix_wrapper/posix_call.hpp" -#include "iceoryx_platform/attributes.hpp" #include "iceoryx_platform/errno.hpp" #include "iceoryx_platform/fcntl.hpp" #include "iceoryx_platform/stdio.hpp" +#include "iox/attributes.hpp" #include "iox/filesystem.hpp" namespace iox diff --git a/iceoryx_hoofs/primitives/include/iox/attributes.hpp b/iceoryx_hoofs/primitives/include/iox/attributes.hpp index a07c385e32..6f65c35af9 100644 --- a/iceoryx_hoofs/primitives/include/iox/attributes.hpp +++ b/iceoryx_hoofs/primitives/include/iox/attributes.hpp @@ -17,8 +17,6 @@ #ifndef IOX_HOOFS_PRIMITIVES_ATTRIBUTES_HPP #define IOX_HOOFS_PRIMITIVES_ATTRIBUTES_HPP -#include "iceoryx_platform/attributes.hpp" - namespace iox { namespace internal @@ -47,6 +45,12 @@ inline void IOX_DISCARD_RESULT_IMPL(T&&) noexcept /// @endcode #define IOX_DISCARD_RESULT(expr) ::iox::internal::IOX_DISCARD_RESULT_IMPL(expr) +#define IOX_NO_DISCARD [[nodiscard]] + +#define IOX_FALLTHROUGH [[fallthrough]] + +#define IOX_MAYBE_UNUSED [[maybe_unused]] + // NOLINTEND(cppcoreguidelines-macro-usage) #endif diff --git a/iceoryx_platform/freertos/include/iceoryx_platform/attributes.hpp b/iceoryx_platform/freertos/include/iceoryx_platform/attributes.hpp deleted file mode 100644 index caf07c44a0..0000000000 --- a/iceoryx_platform/freertos/include/iceoryx_platform/attributes.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. -// Copyright (c) 2023 NXP. 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_HOOFS_FREERTOS_PLATFORM_ATTRIBUTES_HPP -#define IOX_HOOFS_FREERTOS_PLATFORM_ATTRIBUTES_HPP - -/// @brief IOX_NO_DISCARD adds the [[nodiscard]] keyword if it is available for the current compiler. - -#if __cplusplus >= 201703L -#define IOX_NO_DISCARD [[nodiscard]] -#else -#define IOX_NO_DISCARD -#endif - -/// @brief IOX_FALLTHROUGH adds the [[fallthrough]] keyword when it is available for the current compiler. -/// @note -// [[fallthrough]] supported since gcc 7 (https://gcc.gnu.org/projects/cxx-status.html) -/// [[fallthrough]] supported since clang 3.9 (https://clang.llvm.org/cxx_status.html) -/// activate keywords for gcc>=7 or clang>=4 - -#if __cplusplus >= 201703L -// clang prints a warning therefore we exclude it here -#define IOX_FALLTHROUGH [[fallthrough]] -#elif (defined(__GNUC__) && (__GNUC__ >= 7)) && !defined(__clang__) -#define IOX_FALLTHROUGH [[gnu::fallthrough]] -#else -#define IOX_FALLTHROUGH -#endif - -/// @brief IOX_MAYBE_UNUSED adds the [[gnu::unused]] attribute when it is available for the current -/// compiler or uses C++17's 'maybe_unused'. -#if __cplusplus >= 201703L -#define IOX_MAYBE_UNUSED [[maybe_unused]] -#else -#define IOX_MAYBE_UNUSED [[gnu::unused]] -#endif - -#endif // IOX_HOOFS_FREERTOS_PLATFORM_ATTRIBUTES_HPP diff --git a/iceoryx_platform/linux/include/iceoryx_platform/attributes.hpp b/iceoryx_platform/linux/include/iceoryx_platform/attributes.hpp deleted file mode 100644 index 9c1d09821b..0000000000 --- a/iceoryx_platform/linux/include/iceoryx_platform/attributes.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2021 - 2022 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_HOOFS_LINUX_PLATFORM_ATTRIBUTES_HPP -#define IOX_HOOFS_LINUX_PLATFORM_ATTRIBUTES_HPP - -/// @brief IOX_NO_DISCARD adds the [[nodiscard]] keyword if it is available for the current compiler. - -#if __cplusplus >= 201703L -#define IOX_NO_DISCARD [[nodiscard]] -#else -#define IOX_NO_DISCARD -#endif - -/// @brief IOX_FALLTHROUGH adds the [[fallthrough]] keyword when it is available for the current compiler. -/// @note -// [[fallthrough]] supported since gcc 7 (https://gcc.gnu.org/projects/cxx-status.html) -/// [[fallthrough]] supported since clang 3.9 (https://clang.llvm.org/cxx_status.html) -/// activate keywords for gcc>=7 or clang>=4 - -#if __cplusplus >= 201703L -// clang prints a warning therefore we exclude it here -#define IOX_FALLTHROUGH [[fallthrough]] -#elif (defined(__GNUC__) && (__GNUC__ >= 7)) && !defined(__clang__) -#define IOX_FALLTHROUGH [[gnu::fallthrough]] -#else -#define IOX_FALLTHROUGH -#endif - -/// @brief IOX_MAYBE_UNUSED adds the [[gnu::unused]] attribute when it is available for the current -/// compiler or uses C++17's 'maybe_unused'. -#if __cplusplus >= 201703L -#define IOX_MAYBE_UNUSED [[maybe_unused]] -#else -#define IOX_MAYBE_UNUSED [[gnu::unused]] -#endif - -#endif // IOX_HOOFS_LINUX_PLATFORM_ATTRIBUTES_HPP diff --git a/iceoryx_platform/mac/include/iceoryx_platform/attributes.hpp b/iceoryx_platform/mac/include/iceoryx_platform/attributes.hpp deleted file mode 100644 index 056b9cad7d..0000000000 --- a/iceoryx_platform/mac/include/iceoryx_platform/attributes.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2021 - 2022 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_HOOFS_MAC_PLATFORM_ATTRIBUTES_HPP -#define IOX_HOOFS_MAC_PLATFORM_ATTRIBUTES_HPP - -#define IOX_NO_DISCARD [[nodiscard]] - -#define IOX_FALLTHROUGH [[fallthrough]] - -#define IOX_MAYBE_UNUSED [[maybe_unused]] - -#endif // IOX_HOOFS_MAC_PLATFORM_ATTRIBUTES_HPP diff --git a/iceoryx_platform/qnx/include/iceoryx_platform/attributes.hpp b/iceoryx_platform/qnx/include/iceoryx_platform/attributes.hpp deleted file mode 100644 index 6129d10ccf..0000000000 --- a/iceoryx_platform/qnx/include/iceoryx_platform/attributes.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2021 - 2022 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_HOOFS_QNX_PLATFORM_ATTRIBUTES_HPP -#define IOX_HOOFS_QNX_PLATFORM_ATTRIBUTES_HPP - -/// @todo iox-#638 Are any of the below flags available with C++14 on QCC? -#if __cplusplus >= 201703L -#define IOX_NO_DISCARD [[nodiscard]] -#else -#define IOX_NO_DISCARD -#endif - -#if __cplusplus >= 201703L -#define IOX_FALLTHROUGH [[fallthrough]] -#else -#define IOX_FALLTHROUGH -#endif - -#if __cplusplus >= 201703L -#define IOX_MAYBE_UNUSED [[maybe_unused]] -#else -#define IOX_MAYBE_UNUSED [[gnu::unused]] -#endif - -#endif // IOX_HOOFS_QNX_PLATFORM_ATTRIBUTES_HPP diff --git a/iceoryx_platform/unix/include/iceoryx_platform/attributes.hpp b/iceoryx_platform/unix/include/iceoryx_platform/attributes.hpp deleted file mode 100644 index 1e011f6442..0000000000 --- a/iceoryx_platform/unix/include/iceoryx_platform/attributes.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2021 - 2022 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_HOOFS_UNIX_PLATFORM_ATTRIBUTES_HPP -#define IOX_HOOFS_UNIX_PLATFORM_ATTRIBUTES_HPP - -#define IOX_NO_DISCARD [[nodiscard]] - -#define IOX_FALLTHROUGH [[fallthrough]] - -#define IOX_MAYBE_UNUSED [[maybe_unused]] - -#endif // IOX_HOOFS_UNIX_PLATFORM_ATTRIBUTES_HPP diff --git a/iceoryx_platform/win/include/iceoryx_platform/attributes.hpp b/iceoryx_platform/win/include/iceoryx_platform/attributes.hpp deleted file mode 100644 index 681b82f6e1..0000000000 --- a/iceoryx_platform/win/include/iceoryx_platform/attributes.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2021 - 2022 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_HOOFS_WIN_PLATFORM_ATTRIBUTES_HPP -#define IOX_HOOFS_WIN_PLATFORM_ATTRIBUTES_HPP - -#define IOX_NO_DISCARD [[nodiscard]] - -#define IOX_FALLTHROUGH [[fallthrough]] - -#define IOX_MAYBE_UNUSED [[maybe_unused]] - -#endif // IOX_HOOFS_WIN_PLATFORM_ATTRIBUTES_HPP From fa267d271bd909668f7ca0fe839057c2da7e6cee Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 21:07:58 +0100 Subject: [PATCH 77/85] iox-#2066 Replace 'IOX_MAYBE_UNUSED' with '[[maybe_unused]]' --- doc/design/logging.md | 6 +++--- .../test/moduletests/test_notification_info.cpp | 2 +- iceoryx_dust/posix/ipc/source/message_queue.cpp | 4 ++-- .../test_container_fixed_position_container.cpp | 16 ++++++++-------- .../moduletests/test_container_forward_list.cpp | 2 +- .../moduletests/test_utility_serialization.cpp | 2 +- .../test/moduletests/test_vocabulary_span.cpp | 4 ++-- .../request_response/client_cxx_waitset.cpp | 2 +- iceoryx_examples/waitset/README.md | 2 +- iceoryx_examples/waitset/ice_waitset_basic.cpp | 2 +- iceoryx_examples/waitset/ice_waitset_gateway.cpp | 2 +- .../waitset/ice_waitset_grouping.cpp | 2 +- .../waitset/ice_waitset_individual.cpp | 2 +- .../ice_waitset_timer_driven_execution.cpp | 2 +- .../internal/posix_wrapper/posix_call.inl | 4 ++-- .../include/iceoryx_hoofs/cxx/attributes.hpp | 2 +- .../test/moduletests/test_container_list.cpp | 8 ++++---- .../test_design_functional_interface_expect.cpp | 2 +- ...test_design_functional_interface_value_or.cpp | 4 ++-- .../moduletests/test_functional_function.cpp | 4 ++-- .../moduletests/test_functional_function_ref.cpp | 2 +- .../moduletests/test_posix_signal_handler.cpp | 4 ++-- .../test/moduletests/test_time_unit_duration.cpp | 12 ++++++------ .../test/moduletests/test_utility_unique_id.cpp | 4 ++-- .../internal/popo/base_subscriber.inl | 2 +- .../popo/building_blocks/chunk_distributor.inl | 2 +- .../internal/popo/notification_callback.inl | 2 +- .../roudi/introspection/port_introspection.inl | 5 +++-- .../iceoryx_posh/internal/roudi/port_manager.hpp | 4 ++-- .../source/roudi/memory/memory_block.cpp | 2 +- .../test_popo_pub_sub_listener.cpp | 4 ++-- iceoryx_posh/test/mocks/publisher_mock.hpp | 8 ++++---- .../test_mepoo_segment_management.cpp | 10 +++++----- .../moduletests/test_popo_server_port_user.cpp | 2 +- .../moduletests/test_roudi_memory_provider.cpp | 4 ++-- .../test/moduletests/test_roudi_portmanager.cpp | 2 +- 36 files changed, 72 insertions(+), 71 deletions(-) diff --git a/doc/design/logging.md b/doc/design/logging.md index 01e897c938..efba75140b 100644 --- a/doc/design/logging.md +++ b/doc/design/logging.md @@ -360,9 +360,9 @@ class MyLogger : public iox::log::Logger private: void createLogMessageHeader( - const char* file IOX_MAYBE_UNUSED, - const int line IOX_MAYBE_UNUSED, - const char* function IOX_MAYBE_UNUSED, + const char* file [[maybe_unused]], + const int line [[maybe_unused]], + const char* function [[maybe_unused]], iox::log::LogLevel logLevel) noexcept override { switch(logLevel) { diff --git a/iceoryx_binding_c/test/moduletests/test_notification_info.cpp b/iceoryx_binding_c/test/moduletests/test_notification_info.cpp index a1764a4e76..d2c499ae2c 100644 --- a/iceoryx_binding_c/test/moduletests/test_notification_info.cpp +++ b/iceoryx_binding_c/test/moduletests/test_notification_info.cpp @@ -97,7 +97,7 @@ class iox_notification_info_test : public Test return getChunkResult.value(); } - static void triggerCallback(iox_sub_t sub IOX_MAYBE_UNUSED) + static void triggerCallback(iox_sub_t sub [[maybe_unused]]) { } diff --git a/iceoryx_dust/posix/ipc/source/message_queue.cpp b/iceoryx_dust/posix/ipc/source/message_queue.cpp index 00a4f1d607..a7925d0b1a 100644 --- a/iceoryx_dust/posix/ipc/source/message_queue.cpp +++ b/iceoryx_dust/posix/ipc/source/message_queue.cpp @@ -39,7 +39,7 @@ expected MessageQueueBuilder::create() const noex return err(IpcChannelError::INVALID_CHANNEL_NAME); } auto& sanitizedName = sanitzedNameResult.value(); - IOX_MAYBE_UNUSED std::false_type m_name; // m_name shall not be used anymore but only sanitizedName + [[maybe_unused]] std::false_type m_name; // m_name shall not be used anymore but only sanitizedName if (m_maxMsgSize > MessageQueue::MAX_MESSAGE_SIZE) { @@ -217,7 +217,7 @@ MessageQueue::open(const IpcChannelName_t& name, mq_attr& attributes, const IpcC } const auto& sanitizedName = sanitizedNameResult.value(); { - IOX_MAYBE_UNUSED std::false_type name; // name shall not be used anymore but only sanitizedName + [[maybe_unused]] std::false_type name; // name shall not be used anymore but only sanitizedName int32_t openFlags = O_RDWR; if (channelSide == IpcChannelSide::SERVER) diff --git a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp index 31a48ddb49..4d6fa9d684 100644 --- a/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_dust/test/moduletests/test_container_fixed_position_container.cpp @@ -2988,10 +2988,10 @@ TEST_F(FixedPositionContainer_test, DereferencingEndIteratorCallsErrorHandler) { ::testing::Test::RecordProperty("TEST_ID", "f2ccf248-97f8-4265-9bb4-9c8e7cb79e67"); - IOX_EXPECT_FATAL_FAILURE([&] { auto _ IOX_MAYBE_UNUSED = *sut.end(); }, + IOX_EXPECT_FATAL_FAILURE([&] { auto _ [[maybe_unused]] = *sut.end(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); - IOX_EXPECT_FATAL_FAILURE([&] { auto _ IOX_MAYBE_UNUSED = *sut.cend(); }, + IOX_EXPECT_FATAL_FAILURE([&] { auto _ [[maybe_unused]] = *sut.cend(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } @@ -3002,7 +3002,7 @@ TEST_F(FixedPositionContainer_test, DereferencingInvalidIteratorCallsErrorHandle auto it = sut.emplace(135U); sut.erase(it); - IOX_EXPECT_FATAL_FAILURE([&] { auto _ IOX_MAYBE_UNUSED = *it; }, + IOX_EXPECT_FATAL_FAILURE([&] { auto _ [[maybe_unused]] = *it; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } @@ -3122,10 +3122,10 @@ TEST_F(FixedPositionContainer_test, ToPtrOnEndIteratorCallsErrorHandler) { ::testing::Test::RecordProperty("TEST_ID", "51b76d04-6c8c-486e-88c9-8b6b760c41d4"); - IOX_EXPECT_FATAL_FAILURE([&] { auto _ IOX_MAYBE_UNUSED = sut.end().to_ptr(); }, + IOX_EXPECT_FATAL_FAILURE([&] { auto _ [[maybe_unused]] = sut.end().to_ptr(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); - IOX_EXPECT_FATAL_FAILURE([&] { auto _ IOX_MAYBE_UNUSED = sut.cend().to_ptr(); }, + IOX_EXPECT_FATAL_FAILURE([&] { auto _ [[maybe_unused]] = sut.cend().to_ptr(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } @@ -3136,7 +3136,7 @@ TEST_F(FixedPositionContainer_test, ToPtrOnInvalidIteratorCallsErrorHandler) auto it = sut.emplace(135U); sut.erase(it); - IOX_EXPECT_FATAL_FAILURE([&] { auto _ IOX_MAYBE_UNUSED = it.to_ptr(); }, + IOX_EXPECT_FATAL_FAILURE([&] { auto _ [[maybe_unused]] = it.to_ptr(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } @@ -3275,8 +3275,8 @@ TEST_F(FixedPositionContainer_test, IteratorDestructorDoesNotDestroyObjectItPoin fillSutComplex(); { - auto it IOX_MAYBE_UNUSED = sut_complex.begin(); - auto cit IOX_MAYBE_UNUSED = sut_complex.cbegin(); + auto it [[maybe_unused]] = sut_complex.begin(); + auto cit [[maybe_unused]] = sut_complex.cbegin(); } EXPECT_THAT(stats.dTor, Eq(0)); diff --git a/iceoryx_dust/test/moduletests/test_container_forward_list.cpp b/iceoryx_dust/test/moduletests/test_container_forward_list.cpp index fe4b0669e9..7cc33d047a 100644 --- a/iceoryx_dust/test/moduletests/test_container_forward_list.cpp +++ b/iceoryx_dust/test/moduletests/test_container_forward_list.cpp @@ -876,7 +876,7 @@ TEST_F(forward_list_test, InsertAfterSomeElementsListLValue) } sut.insert_after(iter, a); - for (auto& x IOX_MAYBE_UNUSED : sut) + for (auto& x [[maybe_unused]] : sut) { ++loopCounter; } diff --git a/iceoryx_dust/test/moduletests/test_utility_serialization.cpp b/iceoryx_dust/test/moduletests/test_utility_serialization.cpp index aff5305a3f..52fd894e7f 100644 --- a/iceoryx_dust/test/moduletests/test_utility_serialization.cpp +++ b/iceoryx_dust/test/moduletests/test_utility_serialization.cpp @@ -152,7 +152,7 @@ TEST_F(Serialization_test, SerializeSerializableClass) struct A { A() = default; - explicit A(const iox::Serialization& serialized IOX_MAYBE_UNUSED) + explicit A(const iox::Serialization& serialized [[maybe_unused]]) { } // NOLINTNEXTLINE(hicpp-explicit-conversions) required by the Serialization API diff --git a/iceoryx_dust/test/moduletests/test_vocabulary_span.cpp b/iceoryx_dust/test/moduletests/test_vocabulary_span.cpp index 22f379e39f..cf3e4dea3a 100644 --- a/iceoryx_dust/test/moduletests/test_vocabulary_span.cpp +++ b/iceoryx_dust/test/moduletests/test_vocabulary_span.cpp @@ -316,7 +316,7 @@ TEST(span_test, CheckIterOfSpan) { ::testing::Test::RecordProperty("TEST_ID", "4760addf-87f1-46c2-901a-63cf4de3a6ea"); static constexpr int arr[] = {1, 6, 1, 8, 0}; - IOX_MAYBE_UNUSED constexpr span span(arr); + [[maybe_unused]] constexpr span span(arr); EXPECT_TRUE(1 == span.begin()[0]); // First element needs to be '1' EXPECT_TRUE(1 == *(span.begin() += 0)); // First element needs to be '1' @@ -334,7 +334,7 @@ TEST(span_test, CheckConstexprIterOfSpan) "can only be run with clang!"; #else static constexpr int arr[] = {1, 6, 1, 8, 0}; - IOX_MAYBE_UNUSED constexpr span span(arr); + [[maybe_unused]] constexpr span span(arr); // Explicitly not use EXPECT_TRUE here to be able to execute the test case during compile-time static_assert(1 == span.begin()[0], "First element needs to be '1'"); diff --git a/iceoryx_examples/request_response/client_cxx_waitset.cpp b/iceoryx_examples/request_response/client_cxx_waitset.cpp index 8088b4901f..ba5481a5da 100644 --- a/iceoryx_examples/request_response/client_cxx_waitset.cpp +++ b/iceoryx_examples/request_response/client_cxx_waitset.cpp @@ -43,7 +43,7 @@ struct ContextData }; //! [context data to store Fibonacci numbers and sequence ids] -static void signalHandler(int sig IOX_MAYBE_UNUSED) +static void signalHandler(int sig [[maybe_unused]]) { keepRunning = false; if (waitsetSigHandlerAccess) diff --git a/iceoryx_examples/waitset/README.md b/iceoryx_examples/waitset/README.md index 9b2b1f13df..8f32a52cc6 100644 --- a/iceoryx_examples/waitset/README.md +++ b/iceoryx_examples/waitset/README.md @@ -163,7 +163,7 @@ volatile bool keepRunning{true}; using WaitSet = iox::popo::WaitSet<>; volatile WaitSet* waitsetSigHandlerAccess{nullptr}; -static void sigHandler(int sig IOX_MAYBE_UNUSED) +static void sigHandler(int sig [[maybe_unused]]) { keepRunning = false; if (waitsetSigHandlerAccess) diff --git a/iceoryx_examples/waitset/ice_waitset_basic.cpp b/iceoryx_examples/waitset/ice_waitset_basic.cpp index d415d78ee5..a57dc31aec 100644 --- a/iceoryx_examples/waitset/ice_waitset_basic.cpp +++ b/iceoryx_examples/waitset/ice_waitset_basic.cpp @@ -31,7 +31,7 @@ volatile bool keepRunning{true}; using WaitSet = iox::popo::WaitSet<>; volatile WaitSet* waitsetSigHandlerAccess{nullptr}; -static void sigHandler(int sig IOX_MAYBE_UNUSED) +static void sigHandler(int sig [[maybe_unused]]) { keepRunning = false; if (waitsetSigHandlerAccess) diff --git a/iceoryx_examples/waitset/ice_waitset_gateway.cpp b/iceoryx_examples/waitset/ice_waitset_gateway.cpp index ecd233d406..bbfbcf531f 100644 --- a/iceoryx_examples/waitset/ice_waitset_gateway.cpp +++ b/iceoryx_examples/waitset/ice_waitset_gateway.cpp @@ -34,7 +34,7 @@ using WaitSet = iox::popo::WaitSet; volatile WaitSet* waitsetSigHandlerAccess{nullptr}; -static void sigHandler(int f_sig IOX_MAYBE_UNUSED) +static void sigHandler(int f_sig [[maybe_unused]]) { keepRunning = false; if (waitsetSigHandlerAccess) diff --git a/iceoryx_examples/waitset/ice_waitset_grouping.cpp b/iceoryx_examples/waitset/ice_waitset_grouping.cpp index 9ec9b728c4..95fd93b2ed 100644 --- a/iceoryx_examples/waitset/ice_waitset_grouping.cpp +++ b/iceoryx_examples/waitset/ice_waitset_grouping.cpp @@ -31,7 +31,7 @@ using WaitSet = iox::popo::WaitSet; volatile WaitSet* waitsetSigHandlerAccess{nullptr}; -static void sigHandler(int f_sig IOX_MAYBE_UNUSED) +static void sigHandler(int f_sig [[maybe_unused]]) { keepRunning = false; if (waitsetSigHandlerAccess) diff --git a/iceoryx_examples/waitset/ice_waitset_individual.cpp b/iceoryx_examples/waitset/ice_waitset_individual.cpp index c5af2fb084..1d5fcc8f3a 100644 --- a/iceoryx_examples/waitset/ice_waitset_individual.cpp +++ b/iceoryx_examples/waitset/ice_waitset_individual.cpp @@ -29,7 +29,7 @@ std::atomic_bool keepRunning{true}; using WaitSet = iox::popo::WaitSet<>; volatile WaitSet* waitsetSigHandlerAccess{nullptr}; -static void sigHandler(int f_sig IOX_MAYBE_UNUSED) +static void sigHandler(int f_sig [[maybe_unused]]) { keepRunning = false; if (waitsetSigHandlerAccess) diff --git a/iceoryx_examples/waitset/ice_waitset_timer_driven_execution.cpp b/iceoryx_examples/waitset/ice_waitset_timer_driven_execution.cpp index b38924e2fc..c04a038603 100644 --- a/iceoryx_examples/waitset/ice_waitset_timer_driven_execution.cpp +++ b/iceoryx_examples/waitset/ice_waitset_timer_driven_execution.cpp @@ -29,7 +29,7 @@ std::atomic_bool keepRunning{true}; using WaitSet = iox::popo::WaitSet<>; volatile iox::popo::WaitSet<>* waitsetSigHandlerAccess{nullptr}; -static void sigHandler(int f_sig IOX_MAYBE_UNUSED) +static void sigHandler(int f_sig [[maybe_unused]]) { keepRunning = false; if (waitsetSigHandlerAccess) diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/posix_call.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/posix_call.inl index 86c4d8bbc6..db65e3643f 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/posix_call.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/posix_call.inl @@ -59,13 +59,13 @@ inline PosixCallDetails::PosixCallDetails(const char* posixFunctionN /// of "strerror_r", the posix compliant one which returns an int and stores the message in the buffer /// and a gnu version which returns a pointer to the message and sometimes stores the message /// in the buffer -inline string errorLiteralToString(const int returnCode IOX_MAYBE_UNUSED, +inline string errorLiteralToString(const int returnCode [[maybe_unused]], char* const buffer) { return string(TruncateToCapacity, buffer); } -inline string errorLiteralToString(const char* msg, char* const buffer IOX_MAYBE_UNUSED) +inline string errorLiteralToString(const char* msg, char* const buffer [[maybe_unused]]) { return string(TruncateToCapacity, msg); } diff --git a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp index b070ba5c89..e3f1c06e54 100644 --- a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp +++ b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp @@ -38,7 +38,7 @@ using iox::internal::IOX_DISCARD_RESULT_IMPL; // #define IOX_FALLTHROUGH [[fallthrough]] -// #define IOX_MAYBE_UNUSED [[maybe_unused]] +// #define [[maybe_unused]] [[maybe_unused]] } // namespace cxx } // namespace iox diff --git a/iceoryx_hoofs/test/moduletests/test_container_list.cpp b/iceoryx_hoofs/test/moduletests/test_container_list.cpp index f225146187..b81becd0a2 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_list.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_list.cpp @@ -1161,7 +1161,7 @@ TEST_F(list_test, InsertSomeElementsListLValue) } sut.insert(iter, a); - for (auto& x IOX_MAYBE_UNUSED : sut) + for (auto& x [[maybe_unused]] : sut) { ++loopCounter; } @@ -2266,7 +2266,7 @@ TEST_F(list_test, invalidIteratorComparison) auto iter = sut.cbegin(); ++iter; - auto iter2 IOX_MAYBE_UNUSED = sut.erase(iter); + auto iter2 [[maybe_unused]] = sut.erase(iter); IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(sut.cbegin() == iter); }, @@ -2302,7 +2302,7 @@ TEST_F(list_test, invalidIteratorDereferencing) auto iter = sut.cbegin(); ++iter; - auto iter2 IOX_MAYBE_UNUSED = sut.erase(iter); + auto iter2 [[maybe_unused]] = sut.erase(iter); IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT((*iter).value); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); @@ -2319,7 +2319,7 @@ TEST_F(list_test, invalidIteratorAddressOfOperator) auto iter = sut.cbegin(); ++iter; - auto iter2 IOX_MAYBE_UNUSED = sut.erase(iter); + auto iter2 [[maybe_unused]] = sut.erase(iter); IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iter->value == 12U); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); diff --git a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp index 4a36c01752..0a32449034 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp @@ -120,7 +120,7 @@ template <> struct ExpectReturnsValueWhenValid { template - static void performTest(const ExpectCall& callExpect IOX_MAYBE_UNUSED) + static void performTest(const ExpectCall& callExpect [[maybe_unused]]) { } }; diff --git a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_value_or.cpp b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_value_or.cpp index 9be476fc05..2e6fba51da 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_value_or.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_value_or.cpp @@ -42,7 +42,7 @@ template <> struct ValueOrReturnsValueWhenValid { template - static void performTest(const ValueOrCall& callValueOr IOX_MAYBE_UNUSED) + static void performTest(const ValueOrCall& callValueOr [[maybe_unused]]) { } }; @@ -77,7 +77,7 @@ template <> struct ValueOrReturnsArgumentWhenInalid { template - static void performTest(const ValueOrCall& callValueOr IOX_MAYBE_UNUSED) + static void performTest(const ValueOrCall& callValueOr [[maybe_unused]]) { } }; diff --git a/iceoryx_hoofs/test/moduletests/test_functional_function.cpp b/iceoryx_hoofs/test/moduletests/test_functional_function.cpp index 46406c0db7..b995158662 100644 --- a/iceoryx_hoofs/test/moduletests/test_functional_function.cpp +++ b/iceoryx_hoofs/test/moduletests/test_functional_function.cpp @@ -52,13 +52,13 @@ class Counter ++numCreated; } - Counter(const Counter& rhs IOX_MAYBE_UNUSED) + Counter(const Counter& rhs [[maybe_unused]]) { ++numCreated; ++numCopied; } - Counter(Counter&& rhs IOX_MAYBE_UNUSED) noexcept + Counter(Counter&& rhs [[maybe_unused]]) noexcept { ++numMoved; } diff --git a/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp b/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp index ef46e90440..b9249d4883 100644 --- a/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp +++ b/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp @@ -283,7 +283,7 @@ TEST_F(function_refTest, CallOverloadedFunctionResultsInCallOfVoid) TEST_F(function_refTest, CallOverloadedFunctionResultsInCallOfIntInt) { ::testing::Test::RecordProperty("TEST_ID", "b37158b6-8100-4f80-bd62-d2957a7d9c46"); - auto value = SameSignature([](int value1, int value2 IOX_MAYBE_UNUSED) -> int { return value1; }); + auto value = SameSignature([](int value1, int value2 [[maybe_unused]]) -> int { return value1; }); EXPECT_THAT(value, Eq(SAME_SIGNATURE_INT_INT_TEST_VALUE)); } diff --git a/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp b/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp index 6b5102b4e6..6b5dc28871 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp @@ -82,7 +82,7 @@ TYPED_TEST(SignalHandler_test, RegisteringSignalGuardCallbackWorks) { ::testing::Test::RecordProperty("TEST_ID", "7836be02-28ab-43b7-b7a7-7c43c4830eb4"); Signal signalValue = TestFixture::SIGNAL_VALUE; - auto signalGuard IOX_MAYBE_UNUSED = registerSignalHandler(signalValue, this->signalHandler1); + auto signalGuard [[maybe_unused]] = registerSignalHandler(signalValue, this->signalHandler1); ASSERT_EQ(raise(static_cast(signalValue)), 0); @@ -96,7 +96,7 @@ TYPED_TEST(SignalHandler_test, WhenSignalGuardGoesOutOfScopePreviousStateIsResto Signal signalValue = TestFixture::SIGNAL_VALUE; this->registerSignal(static_cast(signalValue), this->signalHandler2); { - auto signalGuard IOX_MAYBE_UNUSED = registerSignalHandler(signalValue, this->signalHandler1); + auto signalGuard [[maybe_unused]] = registerSignalHandler(signalValue, this->signalHandler1); } ASSERT_EQ(raise(static_cast(signalValue)), 0); diff --git a/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp b/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp index 85be0d0db0..9c331f0332 100644 --- a/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp +++ b/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp @@ -1390,10 +1390,10 @@ TEST(Duration_test, AddDurationDoesNotChangeOriginalObject) constexpr Duration EXPECTED_DURATION{13_s + 42_ns}; auto sut1 = EXPECTED_DURATION; - const auto result1 IOX_MAYBE_UNUSED = sut1 + 15_s; + const auto result1 [[maybe_unused]] = sut1 + 15_s; auto sut2 = EXPECTED_DURATION; - const auto result2 IOX_MAYBE_UNUSED = 15_s + sut1; + const auto result2 [[maybe_unused]] = 15_s + sut1; EXPECT_THAT(sut1, Eq(EXPECTED_DURATION)); EXPECT_THAT(sut2, Eq(EXPECTED_DURATION)); @@ -1592,10 +1592,10 @@ TEST(Duration_test, SubtractDurationDoesNotChangeOriginalObject) constexpr Duration EXPECTED_DURATION{13_s + 42_ns}; auto sut1 = EXPECTED_DURATION; - const auto result1 IOX_MAYBE_UNUSED = sut1 - 5_s; + const auto result1 [[maybe_unused]] = sut1 - 5_s; auto sut2 = EXPECTED_DURATION; - const auto result2 IOX_MAYBE_UNUSED = 35_s + sut1; + const auto result2 [[maybe_unused]] = 35_s + sut1; EXPECT_THAT(sut1, Eq(EXPECTED_DURATION)); EXPECT_THAT(sut2, Eq(EXPECTED_DURATION)); @@ -1783,10 +1783,10 @@ TEST(Duration_test, MultiplyDurationDoesNotChangeOriginalObject) constexpr Duration EXPECTED_DURATION{13_s + 42_ns}; auto sut1 = EXPECTED_DURATION; - auto result1 IOX_MAYBE_UNUSED = sut1 * 0; + auto result1 [[maybe_unused]] = sut1 * 0; auto sut2 = EXPECTED_DURATION; - auto result2 IOX_MAYBE_UNUSED = sut2 * 0; + auto result2 [[maybe_unused]] = sut2 * 0; EXPECT_THAT(sut1, Eq(EXPECTED_DURATION)); EXPECT_THAT(sut2, Eq(EXPECTED_DURATION)); diff --git a/iceoryx_hoofs/test/moduletests/test_utility_unique_id.cpp b/iceoryx_hoofs/test/moduletests/test_utility_unique_id.cpp index 27d67282e0..6de8aaa5c4 100644 --- a/iceoryx_hoofs/test/moduletests/test_utility_unique_id.cpp +++ b/iceoryx_hoofs/test/moduletests/test_utility_unique_id.cpp @@ -30,14 +30,14 @@ using namespace iox; TEST(UniqueId_test, ConstructingUniqueIdWorks) { ::testing::Test::RecordProperty("TEST_ID", "e7fb13d3-5c3f-4253-b485-482820aded15"); - auto sut IOX_MAYBE_UNUSED = UniqueId(); + auto sut [[maybe_unused]] = UniqueId(); } TEST(UniqueId_test, ConversionToValueTypeWorks) { ::testing::Test::RecordProperty("TEST_ID", "5f68f612-08ef-4994-b954-1af1d1fb151d"); auto sut = UniqueId(); - auto value IOX_MAYBE_UNUSED = static_cast(sut); + auto value [[maybe_unused]] = static_cast(sut); } TEST(UniqueId_test, TwoConsecutiveCreatedUniqueIdsDifferByOne) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/base_subscriber.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/base_subscriber.inl index 946c5ce8f3..06d1ffc41f 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/base_subscriber.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/base_subscriber.inl @@ -110,7 +110,7 @@ inline void BaseSubscriber::invalidateTrigger(const uint64_t uniqueTrigg template inline void BaseSubscriber::enableState(iox::popo::TriggerHandle&& triggerHandle, - IOX_MAYBE_UNUSED const SubscriberState subscriberState) noexcept + [[maybe_unused]] const SubscriberState subscriberState) noexcept { switch (subscriberState) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.inl index f4dda63afd..fe4d11f7f1 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor.inl @@ -236,7 +236,7 @@ template inline expected ChunkDistributor::deliverToQueue(const UniqueId uniqueQueueId, const uint32_t lastKnownQueueIndex, - mepoo::SharedChunk chunk IOX_MAYBE_UNUSED) noexcept + mepoo::SharedChunk chunk [[maybe_unused]]) noexcept { bool retry{false}; do diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/notification_callback.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/notification_callback.inl index dc22966e58..4c9b486325 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/notification_callback.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/notification_callback.inl @@ -34,7 +34,7 @@ inline void TranslateAndCallTypelessCallback::call(void* con template inline void TranslateAndCallTypelessCallback::call(void* const origin, - void* const userType IOX_MAYBE_UNUSED, + void* const userType [[maybe_unused]], GenericCallbackPtr_t underlyingCallback) noexcept { reinterpret_cast::Ptr_t>(underlyingCallback)(static_cast(origin)); 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 60da4b9f7c..a92f626a62 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 @@ -592,8 +592,9 @@ PortIntrospection::PortData::prepareTopic(PortInt } template -inline void PortIntrospection::PortData::prepareTopic( - PortThroughputIntrospectionTopic& topic IOX_MAYBE_UNUSED) noexcept +inline void +PortIntrospection::PortData::prepareTopic(PortThroughputIntrospectionTopic& topic + [[maybe_unused]]) noexcept { /// @todo iox-#402 re-add port throughput } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_manager.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_manager.hpp index cf5f9e9780..096705f406 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/port_manager.hpp @@ -193,8 +193,8 @@ class PortManager optional doesViolateCommunicationPolicy(const capro::ServiceDescription& service) noexcept; template ::value>* = nullptr> - optional - doesViolateCommunicationPolicy(const capro::ServiceDescription& service IOX_MAYBE_UNUSED) noexcept; + optional doesViolateCommunicationPolicy(const capro::ServiceDescription& service + [[maybe_unused]]) noexcept; bool isInternal(const capro::ServiceDescription& service) const noexcept; diff --git a/iceoryx_posh/source/roudi/memory/memory_block.cpp b/iceoryx_posh/source/roudi/memory/memory_block.cpp index 27333438a8..5cf857c43f 100644 --- a/iceoryx_posh/source/roudi/memory/memory_block.cpp +++ b/iceoryx_posh/source/roudi/memory/memory_block.cpp @@ -22,7 +22,7 @@ namespace iox { namespace roudi { -void MemoryBlock::onMemoryAvailable(not_null memory IOX_MAYBE_UNUSED) noexcept +void MemoryBlock::onMemoryAvailable(not_null memory [[maybe_unused]]) noexcept { // nothing to do in the default implementation } diff --git a/iceoryx_posh/test/integrationtests/test_popo_pub_sub_listener.cpp b/iceoryx_posh/test/integrationtests/test_popo_pub_sub_listener.cpp index e0e4f6f1da..0dbb737364 100644 --- a/iceoryx_posh/test/integrationtests/test_popo_pub_sub_listener.cpp +++ b/iceoryx_posh/test/integrationtests/test_popo_pub_sub_listener.cpp @@ -33,11 +33,11 @@ using namespace iox::runtime; using namespace iox::roudi_env; using namespace iox::testing; -void onSampleReceivedCallback(Subscriber* subscriber IOX_MAYBE_UNUSED) +void onSampleReceivedCallback(Subscriber* subscriber [[maybe_unused]]) { } -void onSampleReceivedCallbackForUntypedSub(UntypedSubscriber* subscriber IOX_MAYBE_UNUSED) +void onSampleReceivedCallbackForUntypedSub(UntypedSubscriber* subscriber [[maybe_unused]]) { } diff --git a/iceoryx_posh/test/mocks/publisher_mock.hpp b/iceoryx_posh/test/mocks/publisher_mock.hpp index 586f406a3c..0a52e954cc 100644 --- a/iceoryx_posh/test/mocks/publisher_mock.hpp +++ b/iceoryx_posh/test/mocks/publisher_mock.hpp @@ -38,13 +38,13 @@ class MockPublisherPortUser } MockPublisherPortUser(MemberType_t*){}; - MockPublisherPortUser(const MockPublisherPortUser& rhs IOX_MAYBE_UNUSED){}; - MockPublisherPortUser(MockPublisherPortUser&& rhs IOX_MAYBE_UNUSED){}; - MockPublisherPortUser& operator=(const MockPublisherPortUser& rhs IOX_MAYBE_UNUSED) + MockPublisherPortUser(const MockPublisherPortUser& rhs [[maybe_unused]]){}; + MockPublisherPortUser(MockPublisherPortUser&& rhs [[maybe_unused]]){}; + MockPublisherPortUser& operator=(const MockPublisherPortUser& rhs [[maybe_unused]]) { return *this; }; - MockPublisherPortUser& operator=(MockPublisherPortUser&& rhs IOX_MAYBE_UNUSED) + MockPublisherPortUser& operator=(MockPublisherPortUser&& rhs [[maybe_unused]]) { return *this; }; diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp index 99a68e4108..3d0fca5b56 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp @@ -36,11 +36,11 @@ using namespace iox::posix; class MePooSegmentMock { public: - MePooSegmentMock(const MePooConfig& mempoolConfig IOX_MAYBE_UNUSED, - iox::BumpAllocator& managementAllocator IOX_MAYBE_UNUSED, - const PosixGroup& readerGroup IOX_MAYBE_UNUSED, - const PosixGroup& writerGroup IOX_MAYBE_UNUSED, - const MemoryInfo& memoryInfo IOX_MAYBE_UNUSED) noexcept + MePooSegmentMock(const MePooConfig& mempoolConfig [[maybe_unused]], + iox::BumpAllocator& managementAllocator [[maybe_unused]], + const PosixGroup& readerGroup [[maybe_unused]], + const PosixGroup& writerGroup [[maybe_unused]], + const MemoryInfo& memoryInfo [[maybe_unused]]) noexcept { } }; diff --git a/iceoryx_posh/test/moduletests/test_popo_server_port_user.cpp b/iceoryx_posh/test/moduletests/test_popo_server_port_user.cpp index e87cb46ff8..745fa6dfb9 100644 --- a/iceoryx_posh/test/moduletests/test_popo_server_port_user.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_server_port_user.cpp @@ -742,7 +742,7 @@ TEST_F(ServerPort_test, SendResponseWithValidClientQueueIdReleasesDeliversToTheC .or_else([&](auto error) { GTEST_FAIL() << "Expected response to be sent but got error: " << error; }); }); - auto maybeChunk IOX_MAYBE_UNUSED = clientResponseQueue.tryPop() + auto maybeChunk [[maybe_unused]] = clientResponseQueue.tryPop() .and_then([&](const auto& chunk) { auto data = *static_cast(chunk.getUserPayload()); EXPECT_THAT(data, Eq(RESPONSE_DATA)); diff --git a/iceoryx_posh/test/moduletests/test_roudi_memory_provider.cpp b/iceoryx_posh/test/moduletests/test_roudi_memory_provider.cpp index b484e0933c..f2c3fe51fd 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_memory_provider.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_memory_provider.cpp @@ -35,8 +35,8 @@ class MemoryProviderFailingCreation : public iox::roudi::MemoryProvider public: using MemoryProvider::getErrorString; - iox::expected createMemory(const uint64_t size IOX_MAYBE_UNUSED, - const uint64_t alignment IOX_MAYBE_UNUSED) noexcept override + iox::expected createMemory(const uint64_t size [[maybe_unused]], + const uint64_t alignment [[maybe_unused]]) noexcept override { return iox::err(MemoryProviderError::MEMORY_CREATION_FAILED); } diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 00437bd1a7..18b83db0a3 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -750,7 +750,7 @@ TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsS // first acquire all possible NodeData acquireMaxNumberOfNodes( - nodeName, runtimeName, [&](auto node, auto newNodeName IOX_MAYBE_UNUSED, auto newProcessName IOX_MAYBE_UNUSED) { + nodeName, runtimeName, [&](auto node, auto newNodeName [[maybe_unused]], auto newProcessName [[maybe_unused]]) { nodeContainer.push_back(node); }); From ae66b5ad3b82ef3f58408a36574974a5645f5478 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 21:19:52 +0100 Subject: [PATCH 78/85] iox-#2066 Replace 'IOX_FALLTHROUGH' with '[[fallthrough]]' --- .../include/iceoryx_hoofs/internal/cxx/variant_queue.inl | 2 +- iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp | 2 +- iceoryx_hoofs/posix/filesystem/source/file.cpp | 4 ++-- iceoryx_posh/source/popo/ports/client_port_roudi.cpp | 4 ++-- iceoryx_posh/source/popo/ports/server_port_roudi.cpp | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant_queue.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant_queue.inl index 0c838de273..a58e071978 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant_queue.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/variant_queue.inl @@ -41,7 +41,7 @@ inline VariantQueue::VariantQueue(const VariantQueueTypes t break; } case VariantQueueTypes::FiFo_MultiProducerSingleConsumer: - IOX_FALLTHROUGH; + [[fallthrough]]; case VariantQueueTypes::SoFi_MultiProducerSingleConsumer: { m_fifo.template emplace>(); diff --git a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp index e3f1c06e54..b070ba5c89 100644 --- a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp +++ b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp @@ -38,7 +38,7 @@ using iox::internal::IOX_DISCARD_RESULT_IMPL; // #define IOX_FALLTHROUGH [[fallthrough]] -// #define [[maybe_unused]] [[maybe_unused]] +// #define IOX_MAYBE_UNUSED [[maybe_unused]] } // namespace cxx } // namespace iox diff --git a/iceoryx_hoofs/posix/filesystem/source/file.cpp b/iceoryx_hoofs/posix/filesystem/source/file.cpp index 763789c0ff..0dfea25d52 100644 --- a/iceoryx_hoofs/posix/filesystem/source/file.cpp +++ b/iceoryx_hoofs/posix/filesystem/source/file.cpp @@ -242,7 +242,7 @@ expected File::remove(const FilePath& file) noexcept case ENOENT: return ok(false); case EPERM: - IOX_FALLTHROUGH; + [[fallthrough]]; case EACCES: IOX_LOG(ERROR, "Unable to remove file due to insufficient permissions."); return err(FileRemoveError::PermissionDenied); @@ -291,7 +291,7 @@ expected File::set_offset(const uint64_t offset) const no switch (result.error().errnum) { case EINVAL: - IOX_FALLTHROUGH; + [[fallthrough]]; case ENXIO: IOX_LOG(ERROR, "Unable to set file offset position since it is beyond the file limits."); return err(FileOffsetError::OffsetBeyondFileLimits); diff --git a/iceoryx_posh/source/popo/ports/client_port_roudi.cpp b/iceoryx_posh/source/popo/ports/client_port_roudi.cpp index dc3d0e76bd..77cef19e44 100644 --- a/iceoryx_posh/source/popo/ports/client_port_roudi.cpp +++ b/iceoryx_posh/source/popo/ports/client_port_roudi.cpp @@ -67,7 +67,7 @@ optional ClientPortRouDi::tryGetCaProMessage() noexcept } break; case ConnectionState::WAIT_FOR_OFFER: - IOX_FALLTHROUGH; + [[fallthrough]]; case ConnectionState::CONNECTED: if (!currentConnectRequest) { @@ -233,7 +233,7 @@ ClientPortRouDi::handleCaProMessageForStateDisconnectRequested(const capro::Capr switch (caProMessage.m_type) { case capro::CaproMessageType::ACK: - IOX_FALLTHROUGH; + [[fallthrough]]; case capro::CaproMessageType::NACK: getMembers()->m_connectionState.store(ConnectionState::NOT_CONNECTED, std::memory_order_relaxed); return nullopt; diff --git a/iceoryx_posh/source/popo/ports/server_port_roudi.cpp b/iceoryx_posh/source/popo/ports/server_port_roudi.cpp index a726c1c02a..5a120b443d 100644 --- a/iceoryx_posh/source/popo/ports/server_port_roudi.cpp +++ b/iceoryx_posh/source/popo/ports/server_port_roudi.cpp @@ -150,9 +150,9 @@ ServerPortRouDi::handleCaProMessageForStateNotOffered(const capro::CaproMessage& getMembers()->m_offered.store(true, std::memory_order_relaxed); return caProMessage; case capro::CaproMessageType::STOP_OFFER: - IOX_FALLTHROUGH; + [[fallthrough]]; case capro::CaproMessageType::CONNECT: - IOX_FALLTHROUGH; + [[fallthrough]]; case capro::CaproMessageType::DISCONNECT: return capro::CaproMessage(capro::CaproMessageType::NACK, this->getCaProServiceDescription()); default: From 03f4aa168f341d344dd4d46ec9a70afdac507e5a Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 21:23:00 +0100 Subject: [PATCH 79/85] iox-#2066 Replace 'IOX_NO_DISCARD' with '[[nodiscard]]' --- .../include/iox/fixed_position_container.hpp | 38 +++++++++---------- .../posix_wrapper/posix_call.hpp | 6 +-- .../vocabulary/include/iox/expected.hpp | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/iceoryx_dust/container/include/iox/fixed_position_container.hpp b/iceoryx_dust/container/include/iox/fixed_position_container.hpp index 45da5de095..f32759f55a 100644 --- a/iceoryx_dust/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_dust/container/include/iox/fixed_position_container.hpp @@ -126,55 +126,55 @@ class FixedPositionContainer final /// @brief Checks if the container is empty /// @return 'true' if the container is empty, 'false' otherwise - IOX_NO_DISCARD bool empty() const noexcept; + [[nodiscard]] bool empty() const noexcept; /// @brief Checks if the container is full /// @return 'true' if the container is full, 'false' otherwise - IOX_NO_DISCARD bool full() const noexcept; + [[nodiscard]] bool full() const noexcept; /// @brief Get the number of used slots in the container /// @return the number of used slots - IOX_NO_DISCARD uint64_t size() const noexcept; + [[nodiscard]] uint64_t size() const noexcept; /// @brief Get the capacity of the container /// @return the number of available slots - IOX_NO_DISCARD constexpr uint64_t capacity() const noexcept; + [[nodiscard]] constexpr uint64_t capacity() const noexcept; /// @brief Get the iterator to the element pointed to by the index /// @param[in] index of the element the for the iterator /// @return iterator pointing to the element at index or end iterator if index was out of bounds or index pointed to /// an empty slot - IOX_NO_DISCARD Iterator iter_from_index(const IndexType index); + [[nodiscard]] Iterator iter_from_index(const IndexType index); /// @brief Get the const iterator to the element pointed to by the index /// @param[in] index of the element the for the iterator /// @return iterator pointing to the element at index or end iterator if index was out of bounds or index pointed to /// an empty slot - IOX_NO_DISCARD ConstIterator iter_from_index(const IndexType index) const; + [[nodiscard]] ConstIterator iter_from_index(const IndexType index) const; /// @brief Get an iterator pointing to the beginning of the container /// @return iterator pointing to the beginning of the container - IOX_NO_DISCARD Iterator begin() noexcept; + [[nodiscard]] Iterator begin() noexcept; /// @brief Get a const iterator pointing to the beginning of the container /// @return const iterator pointing to the beginning of the container - IOX_NO_DISCARD ConstIterator begin() const noexcept; + [[nodiscard]] ConstIterator begin() const noexcept; /// @brief Get a const iterator pointing to the beginning of the container /// @return const iterator pointing to the beginning of the container - IOX_NO_DISCARD ConstIterator cbegin() const noexcept; + [[nodiscard]] ConstIterator cbegin() const noexcept; /// @brief Get an iterator pointing to the end of the container /// @return iterator pointing to the end of the container - IOX_NO_DISCARD Iterator end() noexcept; + [[nodiscard]] Iterator end() noexcept; /// @brief Get a const iterator pointing to the end of the container /// @return const iterator pointing to the end of the container - IOX_NO_DISCARD ConstIterator end() const noexcept; + [[nodiscard]] ConstIterator end() const noexcept; /// @brief Get a const iterator pointing to the end of the container /// @return const iterator pointing to the end of the container - IOX_NO_DISCARD ConstIterator cend() const noexcept; + [[nodiscard]] ConstIterator cend() const noexcept; private: enum class SlotStatus : uint8_t @@ -236,7 +236,7 @@ class FixedPositionContainer final /// @attention aborts if the iterator /// - is an 'end' iterator /// - the slot the iterator point to is not in use - IOX_NO_DISCARD Value& operator*() const + [[nodiscard]] Value& operator*() const { IOX_ENSURES_WITH_MSG(m_index <= Index::LAST, "Access with invalid index!"); IOX_ENSURES_WITH_MSG(m_container.get().m_status[m_index] == SlotStatus::USED, @@ -249,7 +249,7 @@ class FixedPositionContainer final /// @attention aborts if the iterator /// - is an 'end' iterator /// - the slot the iterator point to is not in use - IOX_NO_DISCARD Value* operator->() const + [[nodiscard]] Value* operator->() const { IOX_ENSURES_WITH_MSG(m_index <= Index::LAST, "Access with invalid index!"); IOX_ENSURES_WITH_MSG(m_container.get().m_status[m_index] == SlotStatus::USED, @@ -262,7 +262,7 @@ class FixedPositionContainer final /// @attention aborts if the iterator /// - is an 'end' iterator /// - the slot the iterator point to is not in use - IOX_NO_DISCARD Value* to_ptr() const + [[nodiscard]] Value* to_ptr() const { IOX_ENSURES_WITH_MSG(m_index <= Index::LAST, "Access with invalid index!"); IOX_ENSURES_WITH_MSG(m_container.get().m_status[m_index] == SlotStatus::USED, @@ -273,7 +273,7 @@ class FixedPositionContainer final /// @brief Get the index of the element the iterator points to /// @return index of the element the iterator points to /// @attention this can point out of the container in case of the 'end' iterator - IOX_NO_DISCARD IndexType to_index() const + [[nodiscard]] IndexType to_index() const { return m_index; } @@ -281,7 +281,7 @@ class FixedPositionContainer final /// @brief Check if the iterator origins from the provided container /// @param[in] container to determine the origin of the iterator /// @return 'true' if the iterator origins from the provide container, 'false' otherwise - IOX_NO_DISCARD bool origins_from(const Container& container) const + [[nodiscard]] bool origins_from(const Container& container) const { return &m_container.get() == &container; } @@ -289,7 +289,7 @@ class FixedPositionContainer final /// @brief Compares iterators for equality /// @return 'true' if iterators are the same, 'false' otherwise template - IOX_NO_DISCARD bool operator==(const IteratorBase& rhs) const + [[nodiscard]] bool operator==(const IteratorBase& rhs) const { return origins_from(rhs.m_container.get()) && (m_index == rhs.m_index); } @@ -297,7 +297,7 @@ class FixedPositionContainer final /// @brief Compares iterators for non-equality /// @return 'true' if iterators are not the same, 'false' otherwise template - IOX_NO_DISCARD bool operator!=(const IteratorBase& rhs) const + [[nodiscard]] bool operator!=(const IteratorBase& rhs) const { return !(*this == rhs); } diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_call.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_call.hpp index c516c80aa8..8a84854592 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_call.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_call.hpp @@ -116,7 +116,7 @@ struct PosixCallDetails /// @brief class which is created by the verificator to evaluate the result of a posix call template -class IOX_NO_DISCARD PosixCallEvaluator +class [[nodiscard]] PosixCallEvaluator { public: /// @brief ignore specified errnos from the evaluation @@ -150,7 +150,7 @@ class IOX_NO_DISCARD PosixCallEvaluator /// @brief class which verifies the return value of a posix function call template -class IOX_NO_DISCARD PosixCallVerificator +class [[nodiscard]] PosixCallVerificator { public: /// @brief the posix function call defines success through a single value @@ -180,7 +180,7 @@ class IOX_NO_DISCARD PosixCallVerificator }; template -class IOX_NO_DISCARD PosixCallBuilder +class [[nodiscard]] PosixCallBuilder { public: /// @brief input function type diff --git a/iceoryx_hoofs/vocabulary/include/iox/expected.hpp b/iceoryx_hoofs/vocabulary/include/iox/expected.hpp index f4d026070b..d708d227af 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/expected.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/expected.hpp @@ -126,7 +126,7 @@ detail::err err(Targs&&... args); /// @param ValueType type of the value which can be stored in the expected /// @param ErrorType type of the error which can be stored in the expected template -class IOX_NO_DISCARD expected final : public FunctionalInterface, ValueType, ErrorType> +class [[nodiscard]] expected final : public FunctionalInterface, ValueType, ErrorType> { public: /// @brief default ctor is deleted since you have to clearly state if the From ca59243b2bbd0dbc3eab369e3e0e8dfb08140220 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 21:30:18 +0100 Subject: [PATCH 80/85] iox-#2066 Deprecate 'IOX_MAYBE_UNUSED', 'IOX_FALLTHROUGH' and 'IOX_NO_DISCARD' --- .../legacy/include/iceoryx_hoofs/cxx/attributes.hpp | 9 ++++++--- iceoryx_hoofs/primitives/include/iox/attributes.hpp | 6 ------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp index b070ba5c89..8747fdc4d8 100644 --- a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp +++ b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/attributes.hpp @@ -34,11 +34,14 @@ namespace internal using iox::internal::IOX_DISCARD_RESULT_IMPL; } // namespace internal -// #define IOX_NO_DISCARD [[nodiscard]] +/// @deprecated use '[[nodiscard]]' instead of 'IOX_NO_DISCARD' +#define IOX_NO_DISCARD [[nodiscard, IOX_NO_DISCARD_is_deprecated_use__nodiscard__attribute]] -// #define IOX_FALLTHROUGH [[fallthrough]] +/// @deprecated use '[[fallthrough]]' instead of 'IOX_FALLTHROUGH' +#define IOX_FALLTHROUGH [[fallthrough, IOX_FALLTHROUGH_is_deprecated_use__fallthrough__attribute]] -// #define IOX_MAYBE_UNUSED [[maybe_unused]] +/// @deprecated use '[[maybe_unused]]' instead of 'IOX_MAYBE_UNUSED' +#define IOX_MAYBE_UNUSED [[maybe_unused, IOX_MAYBE_UNUSED_is_deprecated_use__maybe_unused__attribute]] } // namespace cxx } // namespace iox diff --git a/iceoryx_hoofs/primitives/include/iox/attributes.hpp b/iceoryx_hoofs/primitives/include/iox/attributes.hpp index 6f65c35af9..7b9ceefe06 100644 --- a/iceoryx_hoofs/primitives/include/iox/attributes.hpp +++ b/iceoryx_hoofs/primitives/include/iox/attributes.hpp @@ -45,12 +45,6 @@ inline void IOX_DISCARD_RESULT_IMPL(T&&) noexcept /// @endcode #define IOX_DISCARD_RESULT(expr) ::iox::internal::IOX_DISCARD_RESULT_IMPL(expr) -#define IOX_NO_DISCARD [[nodiscard]] - -#define IOX_FALLTHROUGH [[fallthrough]] - -#define IOX_MAYBE_UNUSED [[maybe_unused]] - // NOLINTEND(cppcoreguidelines-macro-usage) #endif From 1ad201188e668338dcdbc588a24cc3d14aa5294c Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 21:39:25 +0100 Subject: [PATCH 81/85] iox-#2066 Update documentation --- doc/website/release-notes/iceoryx-unreleased.md | 5 +++++ iceoryx_hoofs/README.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 2b3becf0a8..70e0c7e148 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -1244,3 +1244,8 @@ IOX_EXPECTS(foo == true); IOX_ENSURES(foo == true); ``` + +55. `IOX_MAYBE_UNUSED`, `IOX_FALLTHROUGH` and `IOX_NO_DISCARD` are deprecated + + With the switch to C++17 `[[maybe_unused]]`, `[[fallthrough]]` and `[[no_discard]]` + are available and should be used instead of the macros. diff --git a/iceoryx_hoofs/README.md b/iceoryx_hoofs/README.md index dc456552c1..cf4f16e860 100644 --- a/iceoryx_hoofs/README.md +++ b/iceoryx_hoofs/README.md @@ -84,7 +84,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an |:---------------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |`type_traits` | | Extended support for evaluating types on compile-time. | |`types` | | Declares essential building block types like `byte`. | -|`attributes` | | C++17 and C++20 attributes are sometimes available through compiler extensions. The attribute macros defined in here (like `IOX_FALLTHROUGH`, `IOX_MAYBE_UNUSED` ... ) make sure that we are able to use them if the compiler supports it. | +|`attributes` | | C++20 and C++23 attributes are sometimes available through compiler extensions. The attribute macros defined in here make sure that we are able to use them if the compiler supports it. | |`algorithm` | | Implements `min` and `max` for an arbitrary number of values of the same type. For instance `min(1,2,3,4,5);` | |`size` | | Helper functions to determine the size in generic ways | From d75f30db95096573365e5fa1369044136fefe267 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 22:20:13 +0100 Subject: [PATCH 82/85] iox-#2066 Use 'std::byte' instead of 'iox::byte' --- doc/website/release-notes/iceoryx-unreleased.md | 5 +++-- iceoryx_hoofs/container/include/iox/uninitialized_array.hpp | 5 +++-- .../functional/include/iox/detail/storable_function.hpp | 3 ++- .../legacy/include/iceoryx_hoofs/iceoryx_hoofs_types.hpp | 4 ++-- iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp | 3 --- iceoryx_hoofs/vocabulary/include/iox/optional.hpp | 3 ++- iceoryx_hoofs/vocabulary/include/iox/variant.hpp | 3 ++- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 70e0c7e148..77e50a03ea 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -178,6 +178,7 @@ - Improve process is alive detection [#1361](https://github.com/eclipse-iceoryx/iceoryx/issues/1361) - only partially - IPC call is replaced with heartbeat via shared memory +- Replace `iox::byte_t` with std::byte [#1900](https://github.com/eclipse-iceoryx/iceoryx/issues/1900) **Workflow:** @@ -1116,14 +1117,14 @@ iox::access_rights foo { iox::perms::owner_all | iox::perms::group_read }; ``` -47. Renaming `byte_t` to `byte` +47. Deprecating `byte_t` in favour of `std::byte` ```cpp // before iox::byte_t m_size; // after - iox::byte m_size; + std::byte m_size; ``` 48. Move conversion methods from `duration.hpp` to `iceoryx_dust` diff --git a/iceoryx_hoofs/container/include/iox/uninitialized_array.hpp b/iceoryx_hoofs/container/include/iox/uninitialized_array.hpp index 71415cc719..c191a422ce 100644 --- a/iceoryx_hoofs/container/include/iox/uninitialized_array.hpp +++ b/iceoryx_hoofs/container/include/iox/uninitialized_array.hpp @@ -20,6 +20,7 @@ #include "iox/iceoryx_hoofs_types.hpp" +#include #include namespace iox @@ -37,7 +38,7 @@ struct ZeroedBuffer // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) - byte data[sizeof(ElementType)]; + std::byte data[sizeof(ElementType)]; }; // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used @@ -57,7 +58,7 @@ struct NonZeroedBuffer // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) - byte data[sizeof(ElementType)]; + std::byte data[sizeof(ElementType)]; }; // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used diff --git a/iceoryx_hoofs/functional/include/iox/detail/storable_function.hpp b/iceoryx_hoofs/functional/include/iox/detail/storable_function.hpp index a462707ef0..836881ab5d 100644 --- a/iceoryx_hoofs/functional/include/iox/detail/storable_function.hpp +++ b/iceoryx_hoofs/functional/include/iox/detail/storable_function.hpp @@ -20,6 +20,7 @@ #include "iox/iceoryx_hoofs_types.hpp" #include "iox/type_traits.hpp" +#include #include #include @@ -154,7 +155,7 @@ class storable_function> final // AXIVION Next Construct AutosarC++19_03-A18.1.1 : safe access is guaranteed since the c-array is wrapped inside the storable_function // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) - byte m_storage[Capacity]; // storage for the callable + std::byte m_storage[Capacity]; // storage for the callable void* m_callable{nullptr}; // pointer to stored type-erased callable ReturnType (*m_invoker)(void*, Args&&...){nullptr}; // indirection to invoke the stored callable, // nullptr if no callable is stored diff --git a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/iceoryx_hoofs_types.hpp b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/iceoryx_hoofs_types.hpp index 5455fce4ac..5e44d89422 100644 --- a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/iceoryx_hoofs_types.hpp +++ b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/iceoryx_hoofs_types.hpp @@ -28,8 +28,8 @@ namespace iox /// namespace IOX_DEPRECATED_SINCE(3, "Please use the 'iox' namespace directly and the corresponding header.") namespace cxx { -/// @deprecated use 'iox::byte' instead of 'iox::cxx::byte_t' -using byte_t IOX_DEPRECATED_SINCE(3, "Please use 'iox::byte' instead.") = byte; +/// @deprecated use 'std::byte' instead of 'iox::cxx::byte_t' +using byte_t IOX_DEPRECATED_SINCE(3, "Please use 'std::byte' instead.") = byte; } // namespace cxx namespace log diff --git a/iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp b/iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp index 1befc87749..2f5171fd85 100644 --- a/iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp +++ b/iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp @@ -24,9 +24,6 @@ namespace iox { -/// @todo iox-#1900 use std::byte with c++17 -using byte = uint8_t; - // AXIVION Next Construct AutosarC++19_03-M2.10.1 : log is a sensible namespace for a logger; furthermore it is in the // iox namespace and when used as function the compiler will complain namespace log diff --git a/iceoryx_hoofs/vocabulary/include/iox/optional.hpp b/iceoryx_hoofs/vocabulary/include/iox/optional.hpp index 887d5fd62f..7fdba52317 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/optional.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/optional.hpp @@ -21,6 +21,7 @@ #include "iox/functional_interface.hpp" #include "iox/iceoryx_hoofs_types.hpp" +#include #include // needed for placement new in the construct_value member function #include @@ -237,7 +238,7 @@ class optional final : public FunctionalInterface, T, void> // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used // NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) - byte data[sizeof(T)]; + std::byte data[sizeof(T)]; }; // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation element_t m_data; diff --git a/iceoryx_hoofs/vocabulary/include/iox/variant.hpp b/iceoryx_hoofs/vocabulary/include/iox/variant.hpp index c445568a61..f768882c33 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/variant.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/variant.hpp @@ -22,6 +22,7 @@ #include "iox/detail/variant_internal.hpp" #include "iox/iceoryx_hoofs_types.hpp" +#include #include #include #include @@ -286,7 +287,7 @@ class variant final // AXIVION Next Construct AutosarC++19_03-M0.1.3 : data provides the actual storage and is accessed via m_storage since &m_storage.data = &m_storage // AXIVION Next Construct AutosarC++19_03-A18.1.1 : safe access is guaranteed since the c-array is wrapped inside the variant class // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays) - iox::byte data[TYPE_SIZE]; + std::byte data[TYPE_SIZE]; }; storage_t m_storage{}; uint64_t m_type_index{INVALID_VARIANT_INDEX}; From 992fef6987129160e6c14b5e56ec0df9e1db4e0e Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 17 Nov 2023 22:23:03 +0100 Subject: [PATCH 83/85] iox-#2066 Update release notes --- doc/website/release-notes/iceoryx-unreleased.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 77e50a03ea..775fa0968b 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -7,6 +7,7 @@ **Notes** - The minimal supported GCC compiler is now 8.3 +- The required C++ standard is now C++17 **Features:** @@ -178,6 +179,7 @@ - Improve process is alive detection [#1361](https://github.com/eclipse-iceoryx/iceoryx/issues/1361) - only partially - IPC call is replaced with heartbeat via shared memory +- Setting IOX_NO_DISCARD in QNX [#638](https://github.com/eclipse-iceoryx/iceoryx/issues/638) - Replace `iox::byte_t` with std::byte [#1900](https://github.com/eclipse-iceoryx/iceoryx/issues/1900) **Workflow:** From 6aeb16c9a342d525691906ca43f4385431712f39 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 20 Nov 2023 13:18:10 +0100 Subject: [PATCH 84/85] iox-#2066 Fix build failure on Arch Linux and aarch64 --- .../moduletests/test_vocabulary_string.cpp | 37 ++++++++++--------- .../vocabulary/include/iox/detail/string.inl | 12 ++++-- .../vocabulary/include/iox/string.hpp | 1 + 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp index 4d5e98fb70..58df325562 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iox/string.hpp" #include "test.hpp" @@ -694,29 +695,29 @@ TYPED_TEST(stringTyped_test, UnsafeRawAccessCStringOfSizeCapaResultsInSizeCapa) TYPED_TEST(stringTyped_test, UnsafeRawAccessCStringOutOfBoundFail) { ::testing::Test::RecordProperty("TEST_ID", "b25c35db-1c0d-4f0e-b4bc-b9430a6696f1"); - IOX_EXPECT_FATAL_FAILURE( - [this] { - this->testSubject.unsafe_raw_access([](char* str, const auto info) -> uint64_t { - //NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors) - strcpy(str, "M"); - return info.total_size + 1U; - }); - }, - iox::HoofsError::EXPECTS_ENSURES_FAILED); + + runInTestThread([this] { + this->testSubject.unsafe_raw_access([](char* str, const auto info) -> uint64_t { + //NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors) + strcpy(str, "M"); + return info.total_size + 1U; + }); + }); + IOX_TESTING_EXPECT_PANIC(); } TYPED_TEST(stringTyped_test, UnsafeRawAccessCStringWrongLenghtFail) { ::testing::Test::RecordProperty("TEST_ID", "411f5db1-18b8-45c3-9ad6-3c886fb12a26"); - IOX_EXPECT_FATAL_FAILURE( - [this] { - this->testSubject.unsafe_raw_access([](char* str, const auto) -> uint64_t { - //NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors) - strcpy(str, "M"); - return 0U; - }); - }, - iox::HoofsError::EXPECTS_ENSURES_FAILED); + + runInTestThread([this] { + this->testSubject.unsafe_raw_access([](char* str, const auto) -> uint64_t { + //NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.strcpy,-warnings-as-errors) + strcpy(str, "M"); + return 0U; + }); + }); + IOX_TESTING_EXPECT_PANIC(); } /// @note template diff --git a/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl index aa473123f6..a0d33431f4 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl +++ b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl @@ -245,10 +245,14 @@ string::unsafe_raw_access(const iox::function_ref= len, - "unsafe_auto_raw_access failed. Data wrote outside the maximun string capacity of " - << Capacity); - IOX_EXPECTS_WITH_MSG(m_rawstring[len] == '\0', "String does not have the terminator at the returned size"); + if (len > Capacity) + { + IOX_PANIC("'unsafe_auto_raw_access' failed. Data wrote outside the maximun string capacity."); + } + else if (m_rawstring[len] != '\0') + { + IOX_PANIC("String does not have the terminator at the returned size"); + } m_rawstringSize = len; } diff --git a/iceoryx_hoofs/vocabulary/include/iox/string.hpp b/iceoryx_hoofs/vocabulary/include/iox/string.hpp index 3142bffbcf..ee95b4dea3 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/string.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/string.hpp @@ -20,6 +20,7 @@ #include "iox/buffer_info.hpp" #include "iox/detail/string_internal.hpp" #include "iox/detail/string_type_traits.hpp" +#include "iceoryx_hoofs/error_reporting/error_reporting_macros.hpp" #include "iox/function.hpp" #include "iox/log/logstream.hpp" #include "iox/optional.hpp" From b0e68f70f28cc11ddbe8d71347f2625f247d3263 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 20 Nov 2023 13:22:17 +0100 Subject: [PATCH 85/85] iox-#2066 Fix pre-flight-check --- iceoryx_hoofs/buffer/include/iox/buffer_info.hpp | 2 +- iceoryx_hoofs/vocabulary/include/iox/string.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iceoryx_hoofs/buffer/include/iox/buffer_info.hpp b/iceoryx_hoofs/buffer/include/iox/buffer_info.hpp index 49c448d910..d36ca324e6 100644 --- a/iceoryx_hoofs/buffer/include/iox/buffer_info.hpp +++ b/iceoryx_hoofs/buffer/include/iox/buffer_info.hpp @@ -29,4 +29,4 @@ struct BufferInfo } // namespace iox -#endif \ No newline at end of file +#endif diff --git a/iceoryx_hoofs/vocabulary/include/iox/string.hpp b/iceoryx_hoofs/vocabulary/include/iox/string.hpp index ee95b4dea3..cf24768b8c 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/string.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/string.hpp @@ -17,10 +17,10 @@ #ifndef IOX_HOOFS_VOCABULARY_STRING_HPP #define IOX_HOOFS_VOCABULARY_STRING_HPP +#include "iceoryx_hoofs/error_reporting/error_reporting_macros.hpp" #include "iox/buffer_info.hpp" #include "iox/detail/string_internal.hpp" #include "iox/detail/string_type_traits.hpp" -#include "iceoryx_hoofs/error_reporting/error_reporting_macros.hpp" #include "iox/function.hpp" #include "iox/log/logstream.hpp" #include "iox/optional.hpp"