From 956191f2fe596d21536328b15dfe719b43275d07 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 28 Dec 2023 00:33:23 +0100 Subject: [PATCH 01/21] iox-#1032 Use 'IOX_ENFORCE' for 'IOX_EXPECTS' --- .clang-tidy-diff-scans.txt | 3 - iceoryx_hoofs/CMakeLists.txt | 1 - .../include/iceoryx_hoofs/cxx/requires.hpp | 32 ++-------- iceoryx_hoofs/source/cxx/.clang-tidy | 1 - iceoryx_hoofs/source/cxx/requires.cpp | 63 ------------------- .../iceoryx_hoofs/testing/fatal_failure.inl | 1 + 6 files changed, 6 insertions(+), 95 deletions(-) delete mode 120000 iceoryx_hoofs/source/cxx/.clang-tidy delete mode 100644 iceoryx_hoofs/source/cxx/requires.cpp diff --git a/.clang-tidy-diff-scans.txt b/.clang-tidy-diff-scans.txt index 0ecf3b7248..507bcafb8b 100644 --- a/.clang-tidy-diff-scans.txt +++ b/.clang-tidy-diff-scans.txt @@ -1,7 +1,4 @@ ./iceoryx_hoofs/include/iceoryx_hoofs/cxx/* -./iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/* -./iceoryx_hoofs/test/moduletests/test_cxx* -./iceoryx_hoofs/source/cxx/* ./iceoryx_hoofs/legacy/**/* diff --git a/iceoryx_hoofs/CMakeLists.txt b/iceoryx_hoofs/CMakeLists.txt index d8b9b6e05b..1d9f4a046a 100644 --- a/iceoryx_hoofs/CMakeLists.txt +++ b/iceoryx_hoofs/CMakeLists.txt @@ -119,7 +119,6 @@ iox_add_library( reporting/source/default_error_handler.cpp reporting/source/console_logger.cpp reporting/source/logger.cpp - source/cxx/requires.cpp source/error_handling/error_handler.cpp source/error_handling/error_handling.cpp time/source/duration.cpp diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/requires.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/requires.hpp index 0bf51cb97f..f92c9cc5cc 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/requires.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/requires.hpp @@ -18,25 +18,7 @@ #define IOX_HOOFS_CXX_REQUIRES_HPP #include "iceoryx_platform/platform_correction.hpp" - -namespace iox -{ -namespace cxx -{ -namespace internal -{ -void Require( - const bool condition, const char* file, const int line, const char* function, const char* conditionString) noexcept; - -void Require(const bool condition, - const char* file, - const int line, - const char* function, - const char* conditionString, - const char* msgString) noexcept; -} // namespace internal -} // namespace cxx -} // namespace iox +#include "iox/assertions.hpp" // implementing C++ Core Guideline, I.6. Prefer Expects // see: @@ -45,8 +27,7 @@ void Require(const bool condition, /// @NOLINTBEGIN(cppcoreguidelines-macro-usage) /// @NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro /// @NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -#define IOX_EXPECTS(condition) \ - iox::cxx::internal::Require(condition, __FILE__, __LINE__, __PRETTY_FUNCTION__, #condition) +#define IOX_EXPECTS(condition) IOX_ENFORCE(condition, "") /// @NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) /// @NOLINTEND(cppcoreguidelines-macro-usage) @@ -54,8 +35,7 @@ void Require(const bool condition, /// @NOLINTBEGIN(cppcoreguidelines-macro-usage) /// @NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro /// @NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -#define IOX_EXPECTS_WITH_MSG(condition, msg) \ - iox::cxx::internal::Require(condition, __FILE__, __LINE__, __PRETTY_FUNCTION__, #condition, #msg) +#define IOX_EXPECTS_WITH_MSG(condition, msg) IOX_ENFORCE(condition, msg) /// @NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) /// @NOLINTEND(cppcoreguidelines-macro-usage) @@ -66,8 +46,7 @@ void Require(const bool condition, /// @NOLINTBEGIN(cppcoreguidelines-macro-usage) /// @NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro /// @NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -#define IOX_ENSURES(condition) \ - iox::cxx::internal::Require(condition, __FILE__, __LINE__, __PRETTY_FUNCTION__, #condition) +#define IOX_ENSURES(condition) IOX_ENFORCE(condition, "") /// @NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) /// @NOLINTEND(cppcoreguidelines-macro-usage) @@ -75,8 +54,7 @@ void Require(const bool condition, /// @NOLINTBEGIN(cppcoreguidelines-macro-usage) /// @NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro /// @NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -#define IOX_ENSURES_WITH_MSG(condition, msg) \ - iox::cxx::internal::Require(condition, __FILE__, __LINE__, __PRETTY_FUNCTION__, #condition, #msg) +#define IOX_ENSURES_WITH_MSG(condition, msg) IOX_ENFORCE(condition, msg) /// @NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) /// @NOLINTEND(cppcoreguidelines-macro-usage) diff --git a/iceoryx_hoofs/source/cxx/.clang-tidy b/iceoryx_hoofs/source/cxx/.clang-tidy deleted file mode 120000 index 4491c1e313..0000000000 --- a/iceoryx_hoofs/source/cxx/.clang-tidy +++ /dev/null @@ -1 +0,0 @@ -../../include/iceoryx_hoofs/cxx/.clang-tidy \ No newline at end of file diff --git a/iceoryx_hoofs/source/cxx/requires.cpp b/iceoryx_hoofs/source/cxx/requires.cpp deleted file mode 100644 index b425f894b5..0000000000 --- a/iceoryx_hoofs/source/cxx/requires.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. -// Copyright (c) 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 - -#include "iceoryx_hoofs/cxx/requires.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" -#include "iox/logging.hpp" - -#include - -namespace iox -{ -namespace cxx -{ -namespace internal -{ -/// @NOLINTJUSTIFICATION @todo iox-#1032 will be obsolete with new error handler -/// @NOLINTNEXTLINE(readability-function-size) -void Require( - const bool condition, const char* file, const int line, const char* function, const char* conditionString) noexcept -{ - if (!condition) - { - IOX_LOG(ERROR, - "Condition: " << conditionString << " in " << function << " is violated. (" << file << ":" << line - << ")"); - errorHandler(HoofsError::EXPECTS_ENSURES_FAILED, ErrorLevel::FATAL); - } -} - -/// @NOLINTJUSTIFICATION @todo iox-#1032 will be obsolete with new error handler -/// @NOLINTNEXTLINE(readability-function-size) -void Require(const bool condition, - const char* file, - const int line, - const char* function, - const char* conditionString, - const char* msgString) noexcept -{ - if (!condition) - { - IOX_LOG(ERROR, - "Condition: " << conditionString << " in " << function << " is violated: " << msgString << ". (" << file - << ":" << line << ")"); - errorHandler(HoofsError::EXPECTS_ENSURES_FAILED, ErrorLevel::FATAL); - } -} -} // namespace internal -} // namespace cxx -} // namespace iox diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl index b35d61686e..cfd2401240 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl @@ -17,6 +17,7 @@ #ifndef IOX_HOOFS_TESTING_FATAL_FAILURE_INL #define IOX_HOOFS_TESTING_FATAL_FAILURE_INL +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" namespace iox From 68d2083d48b82c1e7e83e722e7f7e7684b35c670 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 29 Dec 2023 20:42:10 +0100 Subject: [PATCH 02/21] iox-#1032 Make 'IOX_EXPECT_FATAL_FAILURE' work again --- .../test/moduletests/test_publisher.cpp | 2 +- .../test/moduletests/test_subscriber.cpp | 2 +- .../test/mocktests/test_fatal_failure.cpp | 33 +-------- ...est_design_functional_interface_expect.cpp | 2 +- .../iceoryx_hoofs/testing/fatal_failure.hpp | 23 +------ .../iceoryx_hoofs/testing/fatal_failure.inl | 69 +++---------------- 6 files changed, 17 insertions(+), 114 deletions(-) diff --git a/iceoryx_binding_c/test/moduletests/test_publisher.cpp b/iceoryx_binding_c/test/moduletests/test_publisher.cpp index 90e0baf6f1..7ce4d9deff 100644 --- a/iceoryx_binding_c/test/moduletests/test_publisher.cpp +++ b/iceoryx_binding_c/test/moduletests/test_publisher.cpp @@ -459,7 +459,7 @@ TEST(iox_pub_options_test, publisherOptionInitializationWithNullptrDoesNotCrash) { ::testing::Test::RecordProperty("TEST_ID", "fe415d38-eaaf-466e-b7d8-d220612cb344"); - IOX_EXPECT_NO_FATAL_FAILURE([&] { iox_pub_options_init(nullptr); }); + IOX_EXPECT_NO_FATAL_FAILURE([&] { iox_pub_options_init(nullptr); }); } } // namespace diff --git a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp index 37393c56fa..016ad132cf 100644 --- a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp +++ b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp @@ -558,7 +558,7 @@ TEST(iox_sub_options_test, subscriberOptionInitializationWithNullptrDoesNotCrash { ::testing::Test::RecordProperty("TEST_ID", "4c8eeb6e-5681-4551-865b-11b6a599edf5"); - IOX_EXPECT_NO_FATAL_FAILURE([&] { iox_sub_options_init(nullptr); }); + IOX_EXPECT_NO_FATAL_FAILURE([&] { iox_sub_options_init(nullptr); }); } } // namespace diff --git a/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp index 3ac813352b..82e45fe716 100644 --- a/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp +++ b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp @@ -25,39 +25,12 @@ namespace using namespace ::testing; using namespace ::iox::testing; -TEST(FatalFailure, TriggeringFatalFailureIsDetectedAndDoesNotTerminate) -{ - ::testing::Test::RecordProperty("TEST_ID", "5463f1c9-eb30-4fd1-85ce-351f03c37fe0"); - - auto hasFatalFailure = detail::IOX_FATAL_FAILURE_TEST( - [&] { IOX_EXPECTS(false); }, - [&](const auto error, const auto errorLevel) { - EXPECT_THAT(error, Eq(iox::HoofsError::EXPECTS_ENSURES_FAILED)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::FATAL)); - }, - [&] { GTEST_FAIL() << "This is the non-fatal path and should therefore not be called"; }); - - EXPECT_TRUE(hasFatalFailure); -} - -TEST(FatalFailure, ExpectingFatalFailureWhichDoesNotOccurIsDetected) -{ - ::testing::Test::RecordProperty("TEST_ID", "f6c1d4f2-cafe-45e3-bbb7-c1373b2e15a8"); - - auto hasFatalFailure = detail::IOX_FATAL_FAILURE_TEST( - [&] {}, - [&](const auto, const auto) { GTEST_FAIL() << "This is the fatal path and should therefore not be called"; }, - [&] { GTEST_SUCCEED() << "This is the non-fatal path and should be called"; }); - - EXPECT_FALSE(hasFatalFailure); -} - TEST(FatalFailure, UsingExpectFatalFailureWorks) { ::testing::Test::RecordProperty("TEST_ID", "26393210-9738-462f-9d35-dbd53fbae9d2"); - auto hasFatalFailure = - IOX_EXPECT_FATAL_FAILURE([&] { IOX_EXPECTS(false); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); + auto hasFatalFailure = IOX_EXPECT_FATAL_FAILURE( + [&] { IOX_ENFORCE(false, ""); }, iox::er::ViolationErrorCode::ENFORCE_VIOLATION); EXPECT_TRUE(hasFatalFailure); } @@ -66,7 +39,7 @@ TEST(FatalFailure, UsingExpectNoFatalFailureWorks) { ::testing::Test::RecordProperty("TEST_ID", "80bf8050-bfaa-4482-b69c-d0c80699bd4b"); - auto hasNoFatalFailure = IOX_EXPECT_NO_FATAL_FAILURE([&] {}); + auto hasNoFatalFailure = IOX_EXPECT_NO_FATAL_FAILURE([&] {}); EXPECT_TRUE(hasNoFatalFailure); } 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 0a32449034..5da1bfad0f 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp @@ -41,7 +41,7 @@ void ExpectDoesNotCallTerminateWhenObjectIsValid(const ExpectCall& callExpect) { SutType sut = FactoryType::createValidObject(); - IOX_EXPECT_NO_FATAL_FAILURE([&] { callExpect(sut); }); + IOX_EXPECT_NO_FATAL_FAILURE([&] { callExpect(sut); }); } TYPED_TEST(FunctionalInterface_test, ExpectDoesNotCallTerminateWhenObjectIsValid_LValueCase) diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp index 811e449bea..435c036d64 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp @@ -32,28 +32,13 @@ namespace iox { namespace testing { -namespace detail -{ -/// @brief This function is the base for 'IOX_EXPECT_FATAL_FAILURE' and 'IOX_EXPECT_NO_FATAL_FAILURE' and should not be -/// used by its own. The function only works in combination with the iceoryx error handler. -/// @tparam[in] ErrorType The error type which is expected, e.g. 'iox::HoofsError' -/// @param[in] testFunction This function will be executed as SUT and might call the error handler with a 'FATAL' error -/// level -/// @param[in] onFatalFailurePath This function will be executed on the failure path after the failure was detected -/// @param[in] onNonFatalFailurePath This function will be executed on the non-failure path if no failure was detected -/// @return true if a fatal failure occurs, false otherwise -template -bool IOX_FATAL_FAILURE_TEST(const function_ref testFunction, - const function_ref onFatalFailurePath, - const function_ref onNonFatalFailurePath); -} // namespace detail - /// @brief This function is used in cases a fatal failure is expected. The function only works in combination with the /// iceoryx error handler. /// @code /// TEST(MyTest, valueOnNulloptIsFatal) { /// iox::optional sut; -/// IOX_EXPECT_FATAL_FAILURE([&] { sut.value(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED)); +/// IOX_EXPECT_FATAL_FAILURE( +/// [&] { sut.value(); }, iox::er::ErrorCode::REQUIRED_CONDITION_VIOLATION)); /// } /// @endcode /// @tparam[in] ErrorType The error type which is expected, e.g. 'iox::HoofsError' @@ -68,13 +53,11 @@ bool IOX_EXPECT_FATAL_FAILURE(const function_ref testFunction, const Err /// @code /// TEST(MyTest, valueIsNotFatal) { /// iox::optional sut{false}; -/// IOX_EXPECT_NO_FATAL_FAILURE([&] { sut.value(); }); +/// IOX_EXPECT_NO_FATAL_FAILURE([&] { sut.value(); }); /// } /// @endcode -/// @tparam[in] ErrorType The error type which is expected if the test fails, e.g. 'iox::HoofsError' /// @param[in] testFunction This function will be executed as SUT and is not expected to call the error handler /// @return true if no fatal failure occurs, false otherwise -template bool IOX_EXPECT_NO_FATAL_FAILURE(const function_ref testFunction); } // namespace testing diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl index cfd2401240..5743f3f7e5 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl @@ -24,74 +24,21 @@ namespace iox { namespace testing { -namespace detail -{ template -inline bool IOX_FATAL_FAILURE_TEST(const function_ref testFunction, - const function_ref onFatalFailurePath, - const function_ref onNonFatalFailurePath) +inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref testFunction, + const ErrorType expectedError [[maybe_unused]]) { - std::atomic hasFatalFailure{false}; - auto th = std::thread([&] { - constexpr int JMP_VALUE{1}; - jmp_buf jmpBuffer; - - optional detectedError; - optional detectedErrorLevel; - - auto errorHandlerGuard = - iox::ErrorHandlerMock::setTemporaryErrorHandler([&](const auto error, const auto errorLevel) { - detectedError.emplace(error); - detectedErrorLevel.emplace(errorLevel); - - // NOLINTNEXTLINE(cert-err52-cpp) exception cannot be used and longjmp/setjmp is a working fallback - longjmp(&jmpBuffer[0], JMP_VALUE); - }); - - // NOLINTNEXTLINE(cert-err52-cpp) exception cannot be used and longjmp/setjmp is a working fallback - if (setjmp(&jmpBuffer[0]) == JMP_VALUE) - { - hasFatalFailure = true; - // using value directly is save since this path is only executed if the error handler was called and the - // respective values were set - onFatalFailurePath(detectedError.value(), detectedErrorLevel.value()); - return; - } - - testFunction(); - - onNonFatalFailurePath(); - }); + runInTestThread([&] { testFunction(); }); + IOX_TESTING_EXPECT_PANIC(); - th.join(); - - return hasFatalFailure.load(std::memory_order_relaxed); -} -} // namespace detail - -template -inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref testFunction, const ErrorType expectedError) -{ - return detail::IOX_FATAL_FAILURE_TEST( - testFunction, - [&](const auto error, const auto errorLevel) { - EXPECT_THAT(error, ::testing::Eq(expectedError)); - EXPECT_THAT(errorLevel, ::testing::Eq(iox::ErrorLevel::FATAL)); - }, - [&] { GTEST_FAIL() << "Expected fatal failure but execution continued!"; }); + // return iox::testing::hasError(expectedError); + return iox::testing::hasPanicked(); } -template inline bool IOX_EXPECT_NO_FATAL_FAILURE(const function_ref testFunction) { - return !detail::IOX_FATAL_FAILURE_TEST( - testFunction, - [&](const auto error, const auto errorLevel) { - GTEST_FAIL() << "Expected no fatal failure but execution failed! Error code: " - << static_cast(error) << "; Error level: " << static_cast(errorLevel); - }, - [&] { GTEST_SUCCEED() << "Non-fatal path taken!"; }); - return false; + runInTestThread([&] { testFunction(); }); + return !iox::testing::hasPanicked(); } } // namespace testing From d4a351fab9ba1a00de78efa0a33351a646b10a09 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Tue, 2 Jan 2024 13:39:39 +0100 Subject: [PATCH 03/21] iox-#1032 Make tests work --- .../source/error_handling/error_handler.cpp | 4 ++-- .../test/mocktests/test_fatal_failure.cpp | 4 ++-- .../iceoryx_hoofs/testing/fatal_failure.inl | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/iceoryx_hoofs/source/error_handling/error_handler.cpp b/iceoryx_hoofs/source/error_handling/error_handler.cpp index 731fdef276..4e1e694afe 100644 --- a/iceoryx_hoofs/source/error_handling/error_handler.cpp +++ b/iceoryx_hoofs/source/error_handling/error_handler.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/error_handling/error_handler.hpp" +#include "iox/assertions.hpp" #include @@ -37,8 +38,7 @@ void ErrorHandler::reactOnErrorLevel(const ErrorLevel level, const char* errorNa { case ErrorLevel::FATAL: IOX_LOG(ERROR, ERROR_TEXT << errorName); - assert(false); - std::terminate(); + IOX_PANIC("Fatal error detected!"); break; case ErrorLevel::SEVERE: IOX_LOG(WARN, ERROR_TEXT << errorName); diff --git a/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp index 82e45fe716..086da6081a 100644 --- a/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp +++ b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp @@ -29,8 +29,8 @@ TEST(FatalFailure, UsingExpectFatalFailureWorks) { ::testing::Test::RecordProperty("TEST_ID", "26393210-9738-462f-9d35-dbd53fbae9d2"); - auto hasFatalFailure = IOX_EXPECT_FATAL_FAILURE( - [&] { IOX_ENFORCE(false, ""); }, iox::er::ViolationErrorCode::ENFORCE_VIOLATION); + auto hasFatalFailure = IOX_EXPECT_FATAL_FAILURE([&] { IOX_ENFORCE(false, ""); }, + iox::er::Violation{iox::er::ViolationErrorCode::ENFORCE_VIOLATION}); EXPECT_TRUE(hasFatalFailure); } diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl index 5743f3f7e5..9910110c1d 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl @@ -28,11 +28,22 @@ template inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref testFunction, const ErrorType expectedError [[maybe_unused]]) { + iox::testing::ErrorHandler::instance().reset(); runInTestThread([&] { testFunction(); }); IOX_TESTING_EXPECT_PANIC(); - // return iox::testing::hasError(expectedError); - return iox::testing::hasPanicked(); + if constexpr (std::is_same::value) + { + /// @todo iox-#1032 'hasViolation' should not be necessary + auto hasExpectedError = iox::testing::hasError(expectedError) || iox::testing::hasViolation(); + EXPECT_TRUE(hasExpectedError); + return hasExpectedError; + } + else + { + /// @todo iox-#1032 remove this branch once everything is ported to the new error reporting + return iox::testing::hasPanicked(); + } } inline bool IOX_EXPECT_NO_FATAL_FAILURE(const function_ref testFunction) From 8094558053dbe04fab9d39c2e0a60ff00c023968 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 26 Jan 2024 01:07:24 +0100 Subject: [PATCH 04/21] iox-#1032 Refactor 'setTemporaryErrorHandler' to new error reporting in iceoryx_hoofs --- iceoryx_hoofs/memory/include/iox/unique_ptr.hpp | 4 ++-- .../test/moduletests/test_cli_command_line_parser.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iceoryx_hoofs/memory/include/iox/unique_ptr.hpp b/iceoryx_hoofs/memory/include/iox/unique_ptr.hpp index 5eae9eafa5..7249bf9532 100644 --- a/iceoryx_hoofs/memory/include/iox/unique_ptr.hpp +++ b/iceoryx_hoofs/memory/include/iox/unique_ptr.hpp @@ -90,14 +90,14 @@ class unique_ptr final /// /// @brief get Retrieve the underlying raw pointer. /// @details The unique_ptr retains ownership, therefore the "borrowed" pointer must not be deleted. - /// @return Pointer to managed object or errorHandler call if none owned. + /// @return Pointer to managed object /// T* get() noexcept; /// /// @brief get Retrieve the underlying raw pointer. /// @details The unique_ptr retains ownership, therefore the "borrowed" pointer must not be deleted. - /// @return Const pointer to managed object or errorHandler call if none owned. + /// @return Const pointer to managed object /// const T* get() const noexcept; diff --git a/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp b/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp index 1508567246..75bf6e272a 100644 --- a/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp @@ -22,6 +22,7 @@ #include "iox/std_string_support.hpp" #include "test.hpp" #include "test_cli_command_line_common.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include #include @@ -891,7 +892,6 @@ Arguments SuccessTest(const std::vector& options, CmdArgs args(optionVector); Arguments retVal; - bool wasErrorHandlerCalled = false; { OptionDefinition optionSet(""); for (const auto& o : optionsToRegister) @@ -909,12 +909,12 @@ Arguments SuccessTest(const std::vector& options, } { - auto handle = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::HoofsError, const iox::ErrorLevel) { wasErrorHandlerCalled = true; }); retVal = parseCommandLineArguments(optionSet, args.argc, args.argv, argcOffset); } } - EXPECT_FALSE(wasErrorHandlerCalled); + + IOX_TESTING_EXPECT_OK(); + return retVal; } From f96dc069f32350f0ba530e9345c04ec129e98991 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 26 Jan 2024 02:44:17 +0100 Subject: [PATCH 05/21] iox-#1032 Fix missing namespace in error reporting macros --- .../reporting/include/iox/error_reporting/macros.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp index 72d9515363..8c116aa731 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp @@ -50,7 +50,7 @@ #define IOX_REPORT_FATAL(error) \ do \ { \ - iox::er::forwardFatalError(iox::er::toError(error), FATAL, CURRENT_SOURCE_LOCATION); \ + iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, CURRENT_SOURCE_LOCATION); \ } while (false) /// @brief report error of some non-fatal kind if expr evaluates to true @@ -77,7 +77,7 @@ { \ if (expr) \ { \ - iox::er::forwardFatalError(iox::er::toError(error), FATAL, CURRENT_SOURCE_LOCATION); \ + iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, CURRENT_SOURCE_LOCATION); \ } \ } while (false) From 10786e02795142c816adca05a090afca33617b83 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 26 Jan 2024 02:47:24 +0100 Subject: [PATCH 06/21] iox-#1032 Add 'IOX' prefix to 'CURRENT_SOURCE_LOCATION' --- .../reporting/include/iox/assertions.hpp | 8 ++++---- .../include/iox/error_reporting/macros.hpp | 8 ++++---- .../iox/error_reporting/source_location.hpp | 2 +- .../test_custom_error_reporting.cpp | 16 ++++++++-------- .../test_default_error_handler.cpp | 4 ++-- .../test_testing_error_handler.cpp | 14 +++++++------- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/iceoryx_hoofs/reporting/include/iox/assertions.hpp b/iceoryx_hoofs/reporting/include/iox/assertions.hpp index ce446bccf3..34fd8fcf76 100644 --- a/iceoryx_hoofs/reporting/include/iox/assertions.hpp +++ b/iceoryx_hoofs/reporting/include/iox/assertions.hpp @@ -41,7 +41,7 @@ #define IOX_PANIC(message) \ do \ { \ - iox::er::forwardPanic(CURRENT_SOURCE_LOCATION, message); \ + iox::er::forwardPanic(IOX_CURRENT_SOURCE_LOCATION, message); \ } while (false) //************************************************************************************************ @@ -62,7 +62,7 @@ { \ iox::er::forwardFatalError(iox::er::Violation::createAssertViolation(), \ iox::er::ASSERT_VIOLATION, \ - CURRENT_SOURCE_LOCATION, \ + IOX_CURRENT_SOURCE_LOCATION, \ message); \ } \ } while (false) @@ -78,7 +78,7 @@ { \ iox::er::forwardFatalError(iox::er::Violation::createEnforceViolation(), \ iox::er::ENFORCE_VIOLATION, \ - CURRENT_SOURCE_LOCATION, \ + IOX_CURRENT_SOURCE_LOCATION, \ message); /* @todo iox-#1032 add strigified 'expr' as '#expr' */ \ } \ } while (false) @@ -87,7 +87,7 @@ #define IOX_UNREACHABLE() \ do \ { \ - iox::er::forwardPanic(CURRENT_SOURCE_LOCATION, "Reached code that was supposed to be unreachable."); \ + iox::er::forwardPanic(IOX_CURRENT_SOURCE_LOCATION, "Reached code that was supposed to be unreachable."); \ } while (false) // NOLINTEND(cppcoreguidelines-macro-usage) diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp index 8c116aa731..4a54cbb6e4 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp @@ -42,7 +42,7 @@ #define IOX_REPORT(error, kind) \ do \ { \ - iox::er::forwardNonFatalError(iox::er::toError(error), kind, CURRENT_SOURCE_LOCATION); \ + iox::er::forwardNonFatalError(iox::er::toError(error), kind, IOX_CURRENT_SOURCE_LOCATION); \ } while (false) /// @brief report fatal error @@ -50,7 +50,7 @@ #define IOX_REPORT_FATAL(error) \ do \ { \ - iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, CURRENT_SOURCE_LOCATION); \ + iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, IOX_CURRENT_SOURCE_LOCATION); \ } while (false) /// @brief report error of some non-fatal kind if expr evaluates to true @@ -65,7 +65,7 @@ iox::er::forwardNonFatalError( \ iox::er::toError(error), \ kind, \ - CURRENT_SOURCE_LOCATION); /* @todo iox-#1032 add strigified 'expr' as '#expr' */ \ + IOX_CURRENT_SOURCE_LOCATION); /* @todo iox-#1032 add strigified 'expr' as '#expr' */ \ } \ } while (false) @@ -77,7 +77,7 @@ { \ if (expr) \ { \ - iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, CURRENT_SOURCE_LOCATION); \ + iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, IOX_CURRENT_SOURCE_LOCATION); \ } \ } while (false) diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/source_location.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/source_location.hpp index d6bcd68b56..06eb54b0fb 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/source_location.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/source_location.hpp @@ -39,7 +39,7 @@ struct SourceLocation } // namespace iox /// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) macro is required for use of location intrinsics (__FILE__ etc.) -#define CURRENT_SOURCE_LOCATION \ +#define IOX_CURRENT_SOURCE_LOCATION \ iox::er::SourceLocation \ { \ __FILE__, __LINE__, static_cast(__FUNCTION__) \ diff --git a/iceoryx_hoofs/test/moduletests/error_reporting/test_custom_error_reporting.cpp b/iceoryx_hoofs/test/moduletests/error_reporting/test_custom_error_reporting.cpp index 1c7cf62fd3..adaaa7b261 100644 --- a/iceoryx_hoofs/test/moduletests/error_reporting/test_custom_error_reporting.cpp +++ b/iceoryx_hoofs/test/moduletests/error_reporting/test_custom_error_reporting.cpp @@ -66,7 +66,7 @@ TEST_F(ErrorReporting_test, panicWithLocationWorks) { ::testing::Test::RecordProperty("TEST_ID", "5aca0c31-1c1b-4004-bd41-b4b400258c12"); - auto f = []() { panic(CURRENT_SOURCE_LOCATION); }; + auto f = []() { panic(IOX_CURRENT_SOURCE_LOCATION); }; iox::testing::runInTestThread(f); @@ -77,7 +77,7 @@ TEST_F(ErrorReporting_test, panicWithMessageWorks) { ::testing::Test::RecordProperty("TEST_ID", "f0e44332-ea9b-4041-88f4-8155ccf7538d"); - auto f = []() { panic(CURRENT_SOURCE_LOCATION, "message"); }; + auto f = []() { panic(IOX_CURRENT_SOURCE_LOCATION, "message"); }; iox::testing::runInTestThread(f); @@ -88,7 +88,7 @@ TEST_F(ErrorReporting_test, reportNonFatalErrorWorks) { ::testing::Test::RecordProperty("TEST_ID", "1a1cec1b-5297-487a-bb95-e80af99886b6"); - auto f = []() { report(CURRENT_SOURCE_LOCATION, RUNTIME_ERROR, ERROR); }; + auto f = []() { report(IOX_CURRENT_SOURCE_LOCATION, RUNTIME_ERROR, ERROR); }; iox::testing::runInTestThread(f); @@ -100,7 +100,7 @@ TEST_F(ErrorReporting_test, reportFatalErrorWorks) { ::testing::Test::RecordProperty("TEST_ID", ""); - auto f = []() { report(CURRENT_SOURCE_LOCATION, FATAL, ERROR); }; + auto f = []() { report(IOX_CURRENT_SOURCE_LOCATION, FATAL, ERROR); }; iox::testing::runInTestThread(f); @@ -116,7 +116,7 @@ TEST_F(ErrorReporting_test, reportAssertViolatonWorks) auto f = []() { auto v = Violation::createAssertViolation(); - report(CURRENT_SOURCE_LOCATION, ASSERT_VIOLATION, v); + report(IOX_CURRENT_SOURCE_LOCATION, ASSERT_VIOLATION, v); }; iox::testing::runInTestThread(f); @@ -131,7 +131,7 @@ TEST_F(ErrorReporting_test, reportAssertViolatonWithMessageWorks) auto f = []() { auto v = Violation::createAssertViolation(); - report(CURRENT_SOURCE_LOCATION, ASSERT_VIOLATION, v, "message"); + report(IOX_CURRENT_SOURCE_LOCATION, ASSERT_VIOLATION, v, "message"); }; iox::testing::runInTestThread(f); @@ -145,7 +145,7 @@ TEST_F(ErrorReporting_test, reportEnforceViolatonWorks) auto f = []() { auto v = Violation::createEnforceViolation(); - report(CURRENT_SOURCE_LOCATION, ENFORCE_VIOLATION, v); + report(IOX_CURRENT_SOURCE_LOCATION, ENFORCE_VIOLATION, v); }; iox::testing::runInTestThread(f); @@ -160,7 +160,7 @@ TEST_F(ErrorReporting_test, reportEnforceViolatonWithMessageWorks) auto f = []() { auto v = Violation::createEnforceViolation(); - report(CURRENT_SOURCE_LOCATION, ENFORCE_VIOLATION, v, "message"); + report(IOX_CURRENT_SOURCE_LOCATION, ENFORCE_VIOLATION, v, "message"); }; iox::testing::runInTestThread(f); diff --git a/iceoryx_hoofs/test/moduletests/error_reporting/test_default_error_handler.cpp b/iceoryx_hoofs/test/moduletests/error_reporting/test_default_error_handler.cpp index 5ad4942206..f7e0f22937 100644 --- a/iceoryx_hoofs/test/moduletests/error_reporting/test_default_error_handler.cpp +++ b/iceoryx_hoofs/test/moduletests/error_reporting/test_default_error_handler.cpp @@ -53,8 +53,8 @@ TEST_F(DefaultErrorHandler_test, panicDoesNothing) TEST_F(DefaultErrorHandler_test, reportDoesNothing) { ::testing::Test::RecordProperty("TEST_ID", "9e288318-c756-4666-b779-b944b89ffaf5"); - sut.onReportError(ErrorDescriptor{CURRENT_SOURCE_LOCATION, CODE}); - sut.onReportViolation(ErrorDescriptor{CURRENT_SOURCE_LOCATION, CODE}); + sut.onReportError(ErrorDescriptor{IOX_CURRENT_SOURCE_LOCATION, CODE}); + sut.onReportViolation(ErrorDescriptor{IOX_CURRENT_SOURCE_LOCATION, CODE}); } } // namespace diff --git a/iceoryx_hoofs/test/moduletests/error_reporting/test_testing_error_handler.cpp b/iceoryx_hoofs/test/moduletests/error_reporting/test_testing_error_handler.cpp index 581d7d5766..80fb5f0107 100644 --- a/iceoryx_hoofs/test/moduletests/error_reporting/test_testing_error_handler.cpp +++ b/iceoryx_hoofs/test/moduletests/error_reporting/test_testing_error_handler.cpp @@ -99,7 +99,7 @@ TEST_F(TestingErrorHandler_test, panicWorks) TEST_F(TestingErrorHandler_test, reportErrorWorks) { ::testing::Test::RecordProperty("TEST_ID", "90bd13cf-ece2-4221-8cce-7b2a99568a6a"); - sut.onReportError(ErrorDescriptor{CURRENT_SOURCE_LOCATION, CODE1, MODULE}); + sut.onReportError(ErrorDescriptor{IOX_CURRENT_SOURCE_LOCATION, CODE1, MODULE}); EXPECT_FALSE(sut.hasPanicked()); EXPECT_TRUE(sut.hasError()); EXPECT_TRUE(sut.hasError(CODE1, MODULE)); @@ -112,7 +112,7 @@ TEST_F(TestingErrorHandler_test, reportErrorWorks) TEST_F(TestingErrorHandler_test, reportViolationWorks) { ::testing::Test::RecordProperty("TEST_ID", "5746886e-7309-4435-9e0a-2e6856a318f5"); - sut.onReportViolation(ErrorDescriptor{CURRENT_SOURCE_LOCATION, VIOLATION, MODULE}); + sut.onReportViolation(ErrorDescriptor{IOX_CURRENT_SOURCE_LOCATION, VIOLATION, MODULE}); EXPECT_TRUE(hasViolation()); @@ -123,8 +123,8 @@ TEST_F(TestingErrorHandler_test, reportViolationWorks) TEST_F(TestingErrorHandler_test, hasErrorDetectsOnlyreportErroredErrors) { ::testing::Test::RecordProperty("TEST_ID", "0ee52915-88b7-4041-9f63-93ec5c882e95"); - sut.onReportError(ErrorDescriptor{CURRENT_SOURCE_LOCATION, CODE1, MODULE}); - sut.onReportError(ErrorDescriptor{CURRENT_SOURCE_LOCATION, CODE2, MODULE}); + sut.onReportError(ErrorDescriptor{IOX_CURRENT_SOURCE_LOCATION, CODE1, MODULE}); + sut.onReportError(ErrorDescriptor{IOX_CURRENT_SOURCE_LOCATION, CODE2, MODULE}); EXPECT_FALSE(sut.hasPanicked()); EXPECT_TRUE(sut.hasError(CODE1, MODULE)); @@ -140,9 +140,9 @@ TEST_F(TestingErrorHandler_test, hasErrorDetectsOnlyreportErroredErrors) TEST_F(TestingErrorHandler_test, resettingMultipleErrorsWorks) { ::testing::Test::RecordProperty("TEST_ID", "9715c394-5576-4fd8-a0f6-24560f60c161"); - sut.onReportError(ErrorDescriptor{CURRENT_SOURCE_LOCATION, CODE1, MODULE}); - sut.onReportError(ErrorDescriptor{CURRENT_SOURCE_LOCATION, CODE2, MODULE}); - sut.onReportViolation(ErrorDescriptor{CURRENT_SOURCE_LOCATION, VIOLATION, MODULE}); + sut.onReportError(ErrorDescriptor{IOX_CURRENT_SOURCE_LOCATION, CODE1, MODULE}); + sut.onReportError(ErrorDescriptor{IOX_CURRENT_SOURCE_LOCATION, CODE2, MODULE}); + sut.onReportViolation(ErrorDescriptor{IOX_CURRENT_SOURCE_LOCATION, VIOLATION, MODULE}); sut.onPanic(); From c398c911c39d58c574bd8e7c63010b705fc41732 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 27 Jan 2024 18:52:33 +0100 Subject: [PATCH 07/21] iox-#1032 Enforce strigification or error and module IDs --- .../custom/default/error_reporting_impl.hpp | 8 ++++---- .../include/iox/error_reporting/types.hpp | 8 ++++---- .../include/iox/error_reporting/violation.hpp | 17 +++++++++++++++++ .../test_error_reporting_violation.cpp | 18 ------------------ 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/custom/default/error_reporting_impl.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/custom/default/error_reporting_impl.hpp index 5cc3c64e0b..c4b787301e 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/custom/default/error_reporting_impl.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/custom/default/error_reporting_impl.hpp @@ -80,8 +80,8 @@ inline void report(const SourceLocation& location, Kind, const Error& error) auto errorName = toErrorName(error); IOX_ERROR_INTERNAL_LOG(location, - ": " << errorName << " (code " << code.value << ") in module " << moduleName << " (id " - << module.value << ")"); + "'" << errorName << "' (code " << code.value << ") in module '" << moduleName << "' (id " + << module.value << ")"); auto& h = ErrorHandler::get(); h.onReportError(ErrorDescriptor(location, code, module)); } @@ -100,8 +100,8 @@ inline void report(const SourceLocation& location, iox::er::FatalKind kind, cons auto errorName = toErrorName(error); IOX_ERROR_INTERNAL_LOG_FATAL(location, - ": " << kind.name << " " << errorName << " (code " << code.value << ") in module " - << moduleName << " (id " << module.value << ")"); + "'" << kind.name << "' '" << errorName << "' (code " << code.value << ") in module '" + << moduleName << "' (id " << module.value << ")"); auto& h = ErrorHandler::get(); h.onReportError(ErrorDescriptor(location, code, module)); } diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/types.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/types.hpp index 8f7a3897a2..529025374a 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/types.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/types.hpp @@ -109,15 +109,15 @@ inline ModuleId toModule(const Error& error) } template -inline const char* toModuleName(const Error&) +inline const char* toModuleName(const Error& error) { - return UNKNOWN_MODULE_NAME; + return toError(error).moduleName(); } template -inline const char* toErrorName(const Error&) +inline const char* toErrorName(const Error& error) { - return UNKNOWN_ERROR_NAME; + return toError(error).name(); } } // namespace er diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/violation.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/violation.hpp index 0b4d31857b..5838e2d56c 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/violation.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/violation.hpp @@ -68,6 +68,23 @@ class Violation return m_module; } + const char* name() const + { + switch (static_cast(m_code.value)) + { + case ViolationErrorCode::ASSERT_VIOLATION: + return "ASSERT_VIOLATION"; + case ViolationErrorCode::ENFORCE_VIOLATION: + return "ENFORCE_VIOLATION"; + } + return "unknown error"; + } + + static const char* moduleName() + { + return "ANY"; + } + bool operator==(const Violation& rhs) const { return m_code == rhs.m_code && m_module == rhs.m_module; diff --git a/iceoryx_hoofs/test/moduletests/error_reporting/test_error_reporting_violation.cpp b/iceoryx_hoofs/test/moduletests/error_reporting/test_error_reporting_violation.cpp index 1eb72a4417..02b7a96864 100644 --- a/iceoryx_hoofs/test/moduletests/error_reporting/test_error_reporting_violation.cpp +++ b/iceoryx_hoofs/test/moduletests/error_reporting/test_error_reporting_violation.cpp @@ -220,15 +220,6 @@ TEST(Violation_test, createAssertViolationWorks) EXPECT_EQ(sut, exp); } -TEST(ErrorNameTranslation_test, unknownErrorTranslatesToUnknownErrorString) -{ - ::testing::Test::RecordProperty("TEST_ID", "5abfe6d6-67ca-4373-9779-9c76a13f2718"); - - Unknown error; - const char* result = toErrorName(error); - EXPECT_EQ(result, iox::er::UNKNOWN_ERROR_NAME); -} - TEST(ErrorNameTranslation_test, knownErrorTranslatesToCorrectErrorString) { ::testing::Test::RecordProperty("TEST_ID", "26f3e6bb-2d85-47f6-995b-6ca48425e710"); @@ -248,15 +239,6 @@ TEST(ErrorNameTranslation_test, knownErrorTranslatesToCorrectErrorString) EXPECT_EQ(resultB, errorB.name()); } -TEST(ErrorNameTranslation_test, unknownModuleTranslatesToUnknownModuleString) -{ - ::testing::Test::RecordProperty("TEST_ID", "4769cdc6-dc6f-4f8a-8771-bc74d3a499c9"); - - Unknown module; - const char* result = toModuleName(module); - EXPECT_EQ(result, iox::er::UNKNOWN_MODULE_NAME); -} - TEST(ErrorNameTranslation_test, knownModuleTranslatesToCorrectModuleString) { ::testing::Test::RecordProperty("TEST_ID", "88036900-c9e0-4a07-86fd-411f2273bbf6"); From 340ba4b291cff92dec210dbdea1b996cdd21fd4e Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sun, 28 Jan 2024 17:43:03 +0100 Subject: [PATCH 08/21] iox-#1032 Catch SIGABRT in tests and improve message in signal handler --- iceoryx_hoofs/testing/testing_logger.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/iceoryx_hoofs/testing/testing_logger.cpp b/iceoryx_hoofs/testing/testing_logger.cpp index d1b4c655ea..2952136240 100644 --- a/iceoryx_hoofs/testing/testing_logger.cpp +++ b/iceoryx_hoofs/testing/testing_logger.cpp @@ -15,6 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/testing_logger.hpp" +#include "iox/log/building_blocks/logformat.hpp" #include "iox/log/logger.hpp" #include @@ -125,20 +126,36 @@ jmp_buf exitJmpBuffer; static void sigHandler(int sig, siginfo_t*, void*) { + constexpr const char* COLOR_RESET{"\033[m"}; + + std::cout << iox::log::logLevelDisplayColor(iox::log::LogLevel::WARN) + << "Catched signal: " << iox::log::logLevelDisplayColor(iox::log::LogLevel::FATAL); switch (sig) { case SIGSEGV: - std::cout << "SIGSEGV\n" << std::flush; + std::cout << "SIGSEGV" << std::flush; break; case SIGFPE: - std::cout << "SIGFPE\n" << std::flush; + std::cout << "SIGFPE" << std::flush; + break; + case SIGABRT: + std::cout << "SIGABRT" << std::flush; break; default: - std::cout << "signal: " << sig << "\n" << std::flush; + std::cout << sig; break; } + + std::cout << COLOR_RESET << "\n\n" << std::flush; + dynamic_cast(log::Logger::get()).printLogBuffer(); + std::cout << "\n" + << iox::log::logLevelDisplayColor(iox::log::LogLevel::WARN) + << "Aborting execution by causing a SIGSEV with 'longjmp' to prevent triggering the signal handler again!" + << COLOR_RESET << "\n" + << std::flush; + constexpr int JMP_VALUE{1}; // NOLINTNEXTLINE(cert-err52-cpp) exception cannot be used and longjmp/setjmp is a working fallback longjmp(&exitJmpBuffer[0], JMP_VALUE); @@ -166,6 +183,7 @@ void LogPrinter::OnTestStart(const ::testing::TestInfo&) sigaction(SIGSEGV, &action, nullptr); sigaction(SIGFPE, &action, nullptr); + sigaction(SIGABRT, &action, nullptr); #endif } From 266438a65bbf894e2ec9a0eca0635f9b03264b46 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 26 Jan 2024 02:47:55 +0100 Subject: [PATCH 09/21] iox-#1032 Port 'binding_c' to the new error reporting --- iceoryx_binding_c/CMakeLists.txt | 2 +- .../binding_c_error_reporting.hpp} | 77 ++++++++++++++-- ...ling.cpp => binding_c_error_reporting.cpp} | 13 ++- .../source/c2cpp_enum_translation.cpp | 23 +++-- iceoryx_binding_c/source/c_publisher.cpp | 4 +- iceoryx_binding_c/source/c_subscriber.cpp | 4 +- .../test_c2cpp_enum_translation.cpp | 90 +++++++------------ .../test/moduletests/test_publisher.cpp | 2 +- .../test/moduletests/test_subscriber.cpp | 2 +- 9 files changed, 132 insertions(+), 85 deletions(-) rename iceoryx_binding_c/include/iceoryx_binding_c/{error_handling/error_handling.hpp => internal/binding_c_error_reporting.hpp} (53%) rename iceoryx_binding_c/source/{error_handling.cpp => binding_c_error_reporting.cpp} (61%) diff --git a/iceoryx_binding_c/CMakeLists.txt b/iceoryx_binding_c/CMakeLists.txt index db82e7b200..a34aabeb35 100644 --- a/iceoryx_binding_c/CMakeLists.txt +++ b/iceoryx_binding_c/CMakeLists.txt @@ -51,6 +51,7 @@ iox_add_library( PUBLIC_LIBS_APPLE stdc++ pthread PRIVATE_LIBS iceoryx_posh::iceoryx_posh FILES + source/binding_c_error_reporting.cpp source/c_client.cpp source/c_config.cpp source/c_notification_info.cpp @@ -72,7 +73,6 @@ iox_add_library( source/cpp2c_subscriber.cpp source/cpp2c_service_description_translation.cpp source/c_service_discovery.cpp - source/error_handling.cpp ) # diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/error_handling/error_handling.hpp b/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp similarity index 53% rename from iceoryx_binding_c/include/iceoryx_binding_c/error_handling/error_handling.hpp rename to iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp index 87d90e1250..86a0f300f0 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/error_handling/error_handling.hpp +++ b/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp @@ -14,13 +14,29 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#ifndef IOX_BINDING_C_BINDING_ERROR_HANDLING_ERROR_HANDLING_HPP -#define IOX_BINDING_C_BINDING_ERROR_HANDLING_ERROR_HANDLING_HPP +#ifndef IOX_BINDING_C_BINDING_C_ERROR_REPORTING_HPP +#define IOX_BINDING_C_BINDING_C_ERROR_REPORTING_HPP + +// Each module (= some unit with its own errors) must provide the following. + +// 1. Define the errors of the module -> see below + +// 2. Include the custom reporting implementation +#include "iox/error_reporting/custom/error_reporting.hpp" + +// 3. Include the error reporting macro API +#include "iox/error_reporting/macros.hpp" + +// additional includes +#include "iox/error_reporting/types.hpp" + +/// @todo iox-#1032 Remove once C_BINDING_MODULE_IDENTIFIER is moved to 'ModuleId' in 'error_reporting/types.hpp' #include "iceoryx_hoofs/error_handling/error_handler.hpp" namespace iox { + // clang-format off #define C_BINDING_ERRORS(error) \ error(BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY) \ @@ -34,19 +50,68 @@ namespace iox error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE) \ error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE) \ error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE) \ - error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE) + error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE) \ + error(DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER) // keep this always at the end of the error list // clang-format on // DO NOT TOUCH THE ENUM, you can doodle around with the lines above!!! -enum class CBindingError : uint32_t +enum class CBindingError : iox::er::ErrorCode::type { - NO_ERROR = C_BINDING_MODULE_IDENTIFIER << ERROR_ENUM_OFFSET_IN_BITS, C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_ENUM) }; const char* asStringLiteral(const CBindingError error) noexcept; +class CBindingErrorType +{ + public: + explicit CBindingErrorType(CBindingError code) + : m_code(static_cast(code)) + { + } + + static constexpr iox::er::ModuleId module() + { + return MODULE_ID; + } + + iox::er::ErrorCode code() const + { + return m_code; + } + + const char* name() const + { + return asStringLiteral(static_cast(m_code.value)); + } + + static const char* moduleName() + { + return "iceoryx_binding_c"; + } + + static constexpr iox::er::ModuleId MODULE_ID{C_BINDING_MODULE_IDENTIFIER}; + + protected: + iox::er::ErrorCode m_code; +}; + +namespace er +{ + +inline CBindingErrorType toError(CBindingError code) +{ + return CBindingErrorType(code); +} + +inline ModuleId toModule(CBindingError) +{ + return CBindingErrorType::MODULE_ID; +} + +} // namespace er } // namespace iox -#endif // IOX_BINDING_C_ERROR_HANDLING_ERROR_HANDLING_HPP + +#endif // IOX_BINDING_C_BINDING_C_ERROR_REPORTING_HPP diff --git a/iceoryx_binding_c/source/error_handling.cpp b/iceoryx_binding_c/source/binding_c_error_reporting.cpp similarity index 61% rename from iceoryx_binding_c/source/error_handling.cpp rename to iceoryx_binding_c/source/binding_c_error_reporting.cpp index 9835f15713..7a888c7900 100644 --- a/iceoryx_binding_c/source/error_handling.cpp +++ b/iceoryx_binding_c/source/binding_c_error_reporting.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_binding_c/error_handling/error_handling.hpp" +#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" namespace iox { @@ -22,6 +22,15 @@ const char* C_BINDING_ERROR_NAMES[] = {C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_STR const char* asStringLiteral(const CBindingError error) noexcept { - return C_BINDING_ERROR_NAMES[errorToStringIndex(error)]; + auto end = static_cast::type>( + CBindingError::DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER); + auto index = static_cast::type>(error); + if (index >= end) + { + return "Unknown Error Code!"; + } + // NOLINTJUSTIFICATION Bounds are checked and access is safe + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) + return C_BINDING_ERROR_NAMES[index]; } } // namespace iox diff --git a/iceoryx_binding_c/source/c2cpp_enum_translation.cpp b/iceoryx_binding_c/source/c2cpp_enum_translation.cpp index 43a8c7b0e5..2f36ed4c9e 100644 --- a/iceoryx_binding_c/source/c2cpp_enum_translation.cpp +++ b/iceoryx_binding_c/source/c2cpp_enum_translation.cpp @@ -15,7 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp" -#include "iceoryx_binding_c/error_handling/error_handling.hpp" +#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/c2cpp_binding.h" #include "iox/logging.hpp" @@ -31,8 +31,7 @@ iox::popo::ConsumerTooSlowPolicy consumerTooSlowPolicy(const ENUM iox_ConsumerTo return iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA; } - errorHandler(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY, - iox::ErrorLevel::MODERATE); + IOX_REPORT(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY, iox::er::RUNTIME_ERROR); return iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA; } @@ -46,7 +45,7 @@ iox::popo::QueueFullPolicy queueFullPolicy(const ENUM iox_QueueFullPolicy policy return iox::popo::QueueFullPolicy::DISCARD_OLDEST_DATA; } - errorHandler(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY, iox::ErrorLevel::MODERATE); + IOX_REPORT(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY, iox::er::RUNTIME_ERROR); return iox::popo::QueueFullPolicy::DISCARD_OLDEST_DATA; } @@ -59,7 +58,7 @@ iox::popo::SubscriberEvent subscriberEvent(const iox_SubscriberEvent value) noex } IOX_LOG(FATAL, "invalid iox_SubscriberEvent value"); - errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_EVENT_VALUE); + IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_EVENT_VALUE); return iox::popo::SubscriberEvent::DATA_RECEIVED; } @@ -72,7 +71,7 @@ iox::popo::SubscriberState subscriberState(const iox_SubscriberState value) noex } IOX_LOG(FATAL, "invalid iox_SubscriberState value"); - errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_STATE_VALUE); + IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_STATE_VALUE); return iox::popo::SubscriberState::HAS_DATA; } @@ -85,7 +84,7 @@ iox::popo::ClientEvent clientEvent(const iox_ClientEvent value) noexcept } IOX_LOG(FATAL, "invalid iox_ClientEvent value"); - errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_EVENT_VALUE); + IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_EVENT_VALUE); return iox::popo::ClientEvent::RESPONSE_RECEIVED; } @@ -98,7 +97,7 @@ iox::popo::ClientState clientState(const iox_ClientState value) noexcept } IOX_LOG(FATAL, "invalid iox_ClientState value"); - errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_STATE_VALUE); + IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_STATE_VALUE); return iox::popo::ClientState::HAS_RESPONSE; } @@ -111,7 +110,7 @@ iox::popo::ServerEvent serverEvent(const iox_ServerEvent value) noexcept } IOX_LOG(FATAL, "invalid iox_ServerEvent value"); - errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE); + IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE); return iox::popo::ServerEvent::REQUEST_RECEIVED; } @@ -124,7 +123,7 @@ iox::popo::ServerState serverState(const iox_ServerState value) noexcept } IOX_LOG(FATAL, "invalid iox_ServerState value"); - errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE); + IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE); return iox::popo::ServerState::HAS_REQUEST; } @@ -137,7 +136,7 @@ iox::runtime::ServiceDiscoveryEvent serviceDiscoveryEvent(const iox_ServiceDisco } IOX_LOG(FATAL, "invalid iox_ServiceDiscoveryEvent value"); - errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE); + IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE); return iox::runtime::ServiceDiscoveryEvent::SERVICE_REGISTRY_CHANGED; } @@ -152,7 +151,7 @@ iox::popo::MessagingPattern messagingPattern(const iox_MessagingPattern value) n } IOX_LOG(FATAL, "invalid iox_MessagingPattern value"); - errorHandler(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE); + IOX_REPORT_FATAL(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE); return iox::popo::MessagingPattern::PUB_SUB; } diff --git a/iceoryx_binding_c/source/c_publisher.cpp b/iceoryx_binding_c/source/c_publisher.cpp index 5e6b2287e3..86f23380b0 100644 --- a/iceoryx_binding_c/source/c_publisher.cpp +++ b/iceoryx_binding_c/source/c_publisher.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_binding_c/error_handling/error_handling.hpp" +#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_publisher.hpp" @@ -81,7 +81,7 @@ iox_pub_t iox_pub_init(iox_pub_storage_t* self, // note that they may have been initialized but the initCheck // pattern overwritten afterwards, we cannot be sure but it is a misuse IOX_LOG(FATAL, "publisher options may not have been initialized with iox_pub_options_init"); - errorHandler(CBindingError::BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED); + IOX_REPORT_FATAL(CBindingError::BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED); } publisherOptions.historyCapacity = options->historyCapacity; if (options->nodeName != nullptr) diff --git a/iceoryx_binding_c/source/c_subscriber.cpp b/iceoryx_binding_c/source/c_subscriber.cpp index e908549a8b..6962aceb64 100644 --- a/iceoryx_binding_c/source/c_subscriber.cpp +++ b/iceoryx_binding_c/source/c_subscriber.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_binding_c/enums.h" -#include "iceoryx_binding_c/error_handling/error_handling.hpp" +#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_service_description_translation.hpp" @@ -92,7 +92,7 @@ iox_sub_t iox_sub_init(iox_sub_storage_t* self, // note that they may have been initialized but the initCheck // pattern overwritten afterwards, we cannot be sure but it is a misuse IOX_LOG(FATAL, "subscriber options may not have been initialized with iox_sub_init"); - errorHandler(CBindingError::BINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED); + IOX_REPORT_FATAL(CBindingError::BINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED); } subscriberOptions.queueCapacity = options->queueCapacity; subscriberOptions.historyRequest = options->historyRequest; diff --git a/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp b/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp index 17bcd8c7dc..c33aa83e4d 100644 --- a/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp +++ b/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp @@ -15,14 +15,17 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_binding_c/enums.h" -#include "iceoryx_binding_c/error_handling/error_handling.hpp" +#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" namespace { using namespace ::testing; +using namespace ::iox::testing; template struct EnumMapping @@ -55,12 +58,9 @@ TEST(c2cpp_enum_translation_test, SubscriberState) // return the default value DISCARD_OLDEST_DATA always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); - EXPECT_EQ(c2cpp::subscriberState(iox_test_binding_c::maxUnderlyingCEnumValue()), - iox::popo::SubscriberState::HAS_DATA); - EXPECT_THAT(errorValue, Eq(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_STATE_VALUE)); + IOX_EXPECT_FATAL_FAILURE( + [&] { c2cpp::subscriberState(iox_test_binding_c::maxUnderlyingCEnumValue()); }, + iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_STATE_VALUE); #endif } @@ -88,12 +88,9 @@ TEST(c2cpp_enum_translation_test, SubscriberEvent) // return the default value DATA_RECEIVED always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); - EXPECT_EQ(c2cpp::subscriberEvent(iox_test_binding_c::maxUnderlyingCEnumValue()), - iox::popo::SubscriberEvent::DATA_RECEIVED); - EXPECT_THAT(errorValue, Eq(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_EVENT_VALUE)); + IOX_EXPECT_FATAL_FAILURE( + [&] { c2cpp::subscriberEvent(iox_test_binding_c::maxUnderlyingCEnumValue()); }, + iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SUBSCRIBER_EVENT_VALUE); #endif } @@ -125,13 +122,11 @@ TEST(c2cpp_enum_translation_test, ConsumerTooSlowPolicy) // return the default value DISCARD_OLDEST_DATA always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); EXPECT_EQ(c2cpp::consumerTooSlowPolicy(iox_test_binding_c::maxUnderlyingCEnumValue()), iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA); - EXPECT_THAT(errorValue, Eq(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY)); #endif + + IOX_TESTING_EXPECT_ERROR(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY); } TEST(c2cpp_enum_translation_test, QueueFullPolicy) @@ -162,13 +157,11 @@ TEST(c2cpp_enum_translation_test, QueueFullPolicy) // return the default value DISCARD_OLDEST_DATA always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); EXPECT_EQ(c2cpp::queueFullPolicy(iox_test_binding_c::maxUnderlyingCEnumValue()), iox::popo::QueueFullPolicy::DISCARD_OLDEST_DATA); - EXPECT_THAT(errorValue, Eq(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY)); #endif + + IOX_TESTING_EXPECT_ERROR(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY); } TEST(c2cpp_enum_translation_test, ClientState) @@ -195,12 +188,9 @@ TEST(c2cpp_enum_translation_test, ClientState) // return the default value HAS_RESPONSE always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); - EXPECT_EQ(c2cpp::clientState(iox_test_binding_c::maxUnderlyingCEnumValue()), - iox::popo::ClientState::HAS_RESPONSE); - EXPECT_THAT(errorValue, Eq(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_STATE_VALUE)); + IOX_EXPECT_FATAL_FAILURE( + [&] { c2cpp::clientState(iox_test_binding_c::maxUnderlyingCEnumValue()); }, + iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_STATE_VALUE); #endif } @@ -228,12 +218,9 @@ TEST(c2cpp_enum_translation_test, ClientEvent) // return the default value RESPONSE_RECEIVED always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); - EXPECT_EQ(c2cpp::clientEvent(iox_test_binding_c::maxUnderlyingCEnumValue()), - iox::popo::ClientEvent::RESPONSE_RECEIVED); - EXPECT_THAT(errorValue, Eq(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_EVENT_VALUE)); + IOX_EXPECT_FATAL_FAILURE( + [&] { c2cpp::clientEvent(iox_test_binding_c::maxUnderlyingCEnumValue()); }, + iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_CLIENT_EVENT_VALUE); #endif } @@ -261,12 +248,9 @@ TEST(c2cpp_enum_translation_test, ServerState) // return the default value HAS_REQUEST always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); - EXPECT_EQ(c2cpp::serverState(iox_test_binding_c::maxUnderlyingCEnumValue()), - iox::popo::ServerState::HAS_REQUEST); - EXPECT_THAT(errorValue, Eq(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE)); + IOX_EXPECT_FATAL_FAILURE( + [&] { c2cpp::serverState(iox_test_binding_c::maxUnderlyingCEnumValue()); }, + iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE); #endif } @@ -294,12 +278,9 @@ TEST(c2cpp_enum_translation_test, ServerEvent) // return the default value REQUEST_RECEIVED always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); - EXPECT_EQ(c2cpp::serverEvent(iox_test_binding_c::maxUnderlyingCEnumValue()), - iox::popo::ServerEvent::REQUEST_RECEIVED); - EXPECT_THAT(errorValue, Eq(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE)); + IOX_EXPECT_FATAL_FAILURE( + [&] { c2cpp::serverEvent(iox_test_binding_c::maxUnderlyingCEnumValue()); }, + iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE); #endif } @@ -328,13 +309,9 @@ TEST(c2cpp_enum_translation_test, ServiceDiscoveryEvent) // return the default value SERVICE_REGISTRY_CHANGED always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); - EXPECT_EQ(c2cpp::serviceDiscoveryEvent(iox_test_binding_c::maxUnderlyingCEnumValue()), - iox::runtime::ServiceDiscoveryEvent::SERVICE_REGISTRY_CHANGED); - EXPECT_THAT(errorValue, - Eq(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE)); + IOX_EXPECT_FATAL_FAILURE( + [&] { c2cpp::serviceDiscoveryEvent(iox_test_binding_c::maxUnderlyingCEnumValue()); }, + iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE); #endif } @@ -367,12 +344,9 @@ TEST(c2cpp_enum_translation_test, MessagingPattern) // return the default value PUB_SUB always in the undefined behavior case // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) - iox::CBindingError errorValue = iox::CBindingError::NO_ERROR; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto e, const iox::ErrorLevel) { errorValue = e; }); - EXPECT_EQ(c2cpp::messagingPattern(iox_test_binding_c::maxUnderlyingCEnumValue()), - iox::popo::MessagingPattern::PUB_SUB); - EXPECT_THAT(errorValue, Eq(iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE)); + IOX_EXPECT_FATAL_FAILURE( + [&] { c2cpp::messagingPattern(iox_test_binding_c::maxUnderlyingCEnumValue()); }, + iox::CBindingError::BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE); #endif } diff --git a/iceoryx_binding_c/test/moduletests/test_publisher.cpp b/iceoryx_binding_c/test/moduletests/test_publisher.cpp index 7ce4d9deff..15442cc4ff 100644 --- a/iceoryx_binding_c/test/moduletests/test_publisher.cpp +++ b/iceoryx_binding_c/test/moduletests/test_publisher.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_binding_c/error_handling/error_handling.hpp" +#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_publisher.hpp" #include "iceoryx_hoofs/error_handling/error_handling.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp index 016ad132cf..ae7bfbc9a6 100644 --- a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp +++ b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_binding_c/error_handling/error_handling.hpp" +#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp" #include "iceoryx_hoofs/error_handling/error_handling.hpp" From da5e6a87742209ed59058e83e18794c647fad6a5 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 27 Jan 2024 18:56:10 +0100 Subject: [PATCH 10/21] iox-#1032 Port 'posh' to the new error reporting --- iceoryx_posh/CMakeLists.txt | 2 +- .../internal/mepoo/mepoo_segment.inl | 8 +- .../internal/mepoo/segment_manager.inl | 4 +- .../internal/mepoo/typed_mem_pool.hpp | 2 +- .../internal/mepoo/typed_mem_pool.inl | 6 +- .../internal/popo/base_client.inl | 9 +- .../internal/popo/base_server.inl | 9 +- .../internal/popo/base_subscriber.inl | 8 +- .../building_blocks/chunk_distributor.inl | 6 +- .../chunk_distributor_data.hpp | 2 +- .../building_blocks/chunk_queue_popper.inl | 5 +- .../popo/building_blocks/chunk_receiver.inl | 4 +- .../popo/building_blocks/chunk_sender.hpp | 2 +- .../popo/building_blocks/chunk_sender.inl | 5 +- .../condition_variable_data.hpp | 2 +- .../popo/building_blocks/unique_port_id.hpp | 7 +- .../internal/popo/notification_info.inl | 4 +- .../internal/popo/ports/client_port_user.hpp | 2 +- .../internal/popo/ports/server_port_user.hpp | 2 +- .../iceoryx_posh/internal/popo/request.inl | 3 +- .../iceoryx_posh/internal/popo/response.inl | 3 +- .../iceoryx_posh/internal/popo/sample.inl | 3 +- .../posh_error_reporting.hpp} | 77 +++++++++- .../introspection/mempool_introspection.inl | 7 +- .../iceoryx_posh/popo/notification_info.hpp | 3 +- .../memory/iceoryx_roudi_memory_manager.hpp | 37 +++-- .../include/iceoryx_posh/roudi/roudi_app.hpp | 2 +- .../iceoryx_posh/roudi_env/roudi_env.hpp | 4 +- iceoryx_posh/roudi_env/source/roudi_env.cpp | 5 +- iceoryx_posh/source/mepoo/mem_pool.cpp | 6 +- iceoryx_posh/source/mepoo/memory_manager.cpp | 16 +- iceoryx_posh/source/mepoo/mepoo_config.cpp | 4 +- .../building_blocks/condition_listener.cpp | 13 +- .../building_blocks/condition_notifier.cpp | 5 +- .../condition_variable_data.cpp | 3 +- .../popo/building_blocks/locking_policy.cpp | 8 +- .../popo/building_blocks/unique_port_id.cpp | 16 +- .../source/popo/ports/client_port_roudi.cpp | 3 +- .../source/popo/ports/client_port_user.cpp | 7 +- .../source/popo/ports/interface_port.cpp | 4 +- .../popo/ports/publisher_port_roudi.cpp | 3 +- .../source/popo/ports/server_port_roudi.cpp | 5 +- .../source/popo/ports/server_port_user.cpp | 13 +- .../ports/subscriber_port_multi_producer.cpp | 4 +- .../ports/subscriber_port_single_producer.cpp | 8 +- ..._handling.cpp => posh_error_reporting.cpp} | 13 +- .../source/roudi/iceoryx_roudi_components.cpp | 3 +- .../roudi/memory/default_roudi_memory.cpp | 11 +- .../memory/iceoryx_roudi_memory_manager.cpp | 5 +- .../source/roudi/memory/memory_provider.cpp | 4 +- iceoryx_posh/source/roudi/port_manager.cpp | 32 ++-- iceoryx_posh/source/roudi/port_pool.cpp | 15 +- iceoryx_posh/source/roudi/process.cpp | 3 +- iceoryx_posh/source/roudi/process_manager.cpp | 7 +- .../source/runtime/ipc_interface_creator.cpp | 43 +++--- .../source/runtime/ipc_runtime_interface.cpp | 12 +- iceoryx_posh/source/runtime/posh_runtime.cpp | 7 +- .../source/runtime/posh_runtime_impl.cpp | 73 ++++----- .../runtime/posh_runtime_single_process.cpp | 3 +- .../source/runtime/service_discovery.cpp | 7 +- .../source/runtime/shared_memory_user.cpp | 12 +- .../test/integrationtests/test_posh_mepoo.cpp | 19 +-- .../test/moduletests/test_mepoo_config.cpp | 7 +- .../moduletests/test_mepoo_memory_manager.cpp | 62 ++------ .../test/moduletests/test_mepoo_mempool.cpp | 41 ++--- .../test_mepoo_segment_management.cpp | 16 +- .../moduletests/test_popo_base_client.cpp | 48 +++--- .../moduletests/test_popo_base_server.cpp | 48 +++--- .../test_popo_chunk_distributor.cpp | 14 +- .../moduletests/test_popo_chunk_queue.cpp | 11 +- .../moduletests/test_popo_chunk_receiver.cpp | 11 +- .../moduletests/test_popo_chunk_sender.cpp | 42 ++--- .../moduletests/test_popo_client_port.cpp | 55 ++----- .../test_popo_notification_info.cpp | 35 ++--- .../test/moduletests/test_popo_request.cpp | 22 +-- .../test/moduletests/test_popo_response.cpp | 22 +-- .../test/moduletests/test_popo_sample.cpp | 25 +-- .../test_popo_server_port_roudi.cpp | 58 +++---- .../test_popo_server_port_user.cpp | 53 +------ .../moduletests/test_popo_subscriber_port.cpp | 71 ++++----- .../test/moduletests/test_popo_trigger.cpp | 8 +- .../moduletests/test_popo_unique_port_id.cpp | 40 ++--- .../test/moduletests/test_posh_runtime.cpp | 144 ++++-------------- .../test_posh_runtime_single_process.cpp | 21 +-- .../test_roudi_iceoryx_roudi_app.cpp | 43 +++--- .../moduletests/test_roudi_portmanager.cpp | 65 +++----- .../test_roudi_portmanager_client_server.cpp | 22 +-- .../test/moduletests/test_roudi_portpool.cpp | 79 ++-------- .../test/moduletests/test_roudi_process.cpp | 14 +- .../test_runtime_ipc_interface_creator.cpp | 8 +- 90 files changed, 693 insertions(+), 1012 deletions(-) rename iceoryx_posh/include/iceoryx_posh/{error_handling/error_handling.hpp => internal/posh_error_reporting.hpp} (85%) rename iceoryx_posh/source/{error_handling/error_handling.cpp => posh_error_reporting.cpp} (61%) diff --git a/iceoryx_posh/CMakeLists.txt b/iceoryx_posh/CMakeLists.txt index d0d0ffc7af..664d588705 100644 --- a/iceoryx_posh/CMakeLists.txt +++ b/iceoryx_posh/CMakeLists.txt @@ -94,7 +94,6 @@ iox_add_library( FILES source/capro/capro_message.cpp source/capro/service_description.cpp - source/error_handling/error_handling.cpp source/mepoo/chunk_header.cpp source/mepoo/chunk_management.cpp source/mepoo/chunk_settings.cpp @@ -140,6 +139,7 @@ iox_add_library( source/popo/trigger.cpp source/popo/trigger_handle.cpp source/popo/user_trigger.cpp + source/posh_error_reporting.cpp source/version/version_info.cpp source/runtime/heartbeat.cpp source/runtime/ipc_interface_base.cpp diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl index aa71c0699f..d14ada215b 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl @@ -18,8 +18,8 @@ #ifndef IOX_POSH_MEPOO_MEPOO_SEGMENT_INL #define IOX_POSH_MEPOO_MEPOO_SEGMENT_INL -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/mepoo/mepoo_segment.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/memory_info.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iox/bump_allocator.hpp" @@ -58,7 +58,7 @@ inline MePooSegment::MePooSegment( if (!acl.writePermissionsToFile(m_sharedMemoryObject.getFileHandle())) { - errorHandler(PoshError::MEPOO__SEGMENT_COULD_NOT_APPLY_POSIX_RIGHTS_TO_SHARED_MEMORY); + IOX_REPORT_FATAL(PoshError::MEPOO__SEGMENT_COULD_NOT_APPLY_POSIX_RIGHTS_TO_SHARED_MEMORY); } BumpAllocator allocator(m_sharedMemoryObject.getBaseAddress(), @@ -84,7 +84,7 @@ inline SharedMemoryObjectType MePooSegmentm_segmentId = static_cast(maybeSegmentId.value()); this->m_segmentSize = sharedMemoryObject.get_size().expect("Failed to get SHM size."); @@ -94,7 +94,7 @@ inline SharedMemoryObjectType MePooSegment::getSegmentMappings(const PosixUser& user) noexcept } else { - errorHandler(PoshError::MEPOO__USER_WITH_MORE_THAN_ONE_WRITE_SEGMENT); + IOX_REPORT_FATAL(PoshError::MEPOO__USER_WITH_MORE_THAN_ONE_WRITE_SEGMENT); return SegmentManager::SegmentMappingContainer(); } } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.hpp index 9d72f2c161..c85a8fdcf1 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.hpp @@ -17,12 +17,12 @@ #ifndef IOX_POSH_MEPOO_TYPED_MEM_POOL_HPP #define IOX_POSH_MEPOO_TYPED_MEM_POOL_HPP -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/mepoo/chunk_management.hpp" #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/mepoo/shared_pointer.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/algorithm.hpp" #include "iox/bump_allocator.hpp" #include "iox/expected.hpp" diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl index e68d33c503..8546b7320d 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/typed_mem_pool.inl @@ -17,10 +17,10 @@ #ifndef IOX_POSH_MEPOO_TYPED_MEM_POOL_INL #define IOX_POSH_MEPOO_TYPED_MEM_POOL_INL -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/mepoo/chunk_management.hpp" #include "iceoryx_posh/internal/mepoo/typed_mem_pool.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -47,7 +47,7 @@ inline expected TypedMemPool::acquireChu ChunkManagement* chunkManagement = static_cast(m_chunkManagementPool.getChunk()); if (chunkManagement == nullptr) { - errorHandler(PoshError::MEPOO__TYPED_MEMPOOL_HAS_INCONSISTENT_STATE); + IOX_REPORT_FATAL(PoshError::MEPOO__TYPED_MEMPOOL_HAS_INCONSISTENT_STATE); return err(TypedMemPoolError::FatalErrorReachedInconsistentState); } @@ -75,7 +75,7 @@ inline expected, TypedMemPoolError> TypedMemPool::createObje if (newObject.has_error()) { - errorHandler(PoshError::MEPOO__TYPED_MEMPOOL_MANAGEMENT_SEGMENT_IS_BROKEN); + IOX_REPORT_FATAL(PoshError::MEPOO__TYPED_MEMPOOL_MANAGEMENT_SEGMENT_IS_BROKEN); return err(TypedMemPoolError::FatalErrorReachedInconsistentState); } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/base_client.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/base_client.inl index 7fa9545d45..31e9db48d9 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/base_client.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/base_client.inl @@ -19,6 +19,7 @@ #define IOX_POSH_POPO_BASE_CLIENT_INL #include "iceoryx_posh/internal/popo/base_client.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -112,10 +113,10 @@ inline void BaseClient::enableState(TriggerHandleT&& trig "ClientEvent::RESPONSE_RECEIVED to a WaitSet/Listener. Detaching it from previous one and " "attaching it to the new one with ClientState::HAS_RESPONSE. Best practice is to call detach first."); - errorHandler( + IOX_REPORT( PoshError:: POPO__BASE_CLIENT_OVERRIDING_WITH_STATE_SINCE_HAS_RESPONSE_OR_RESPONSE_RECEIVED_ALREADY_ATTACHED, - ErrorLevel::MODERATE); + iox::er::RUNTIME_ERROR); } m_trigger = std::move(triggerHandle); m_port.setConditionVariable(*m_trigger.getConditionVariableData(), m_trigger.getUniqueId()); @@ -161,10 +162,10 @@ inline void BaseClient::enableEvent(TriggerHandleT&& trig "ClientEvent::RESPONSE_RECEIVED to a WaitSet/Listener. Detaching it from previous one and " "attaching it to the new one with ClientEvent::RESPONSE_RECEIVED. Best practice is to call detach " "first."); - errorHandler( + IOX_REPORT( PoshError:: POPO__BASE_CLIENT_OVERRIDING_WITH_EVENT_SINCE_HAS_RESPONSE_OR_RESPONSE_RECEIVED_ALREADY_ATTACHED, - ErrorLevel::MODERATE); + iox::er::RUNTIME_ERROR); } m_trigger = std::move(triggerHandle); m_port.setConditionVariable(*m_trigger.getConditionVariableData(), m_trigger.getUniqueId()); diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/base_server.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/base_server.inl index a777de9378..d271dae8ec 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/base_server.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/base_server.inl @@ -19,6 +19,7 @@ #define IOX_POSH_POPO_BASE_SERVER_INL #include "iceoryx_posh/internal/popo/base_server.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -116,10 +117,10 @@ inline void BaseServer::enableState(TriggerHandleT&& trig "ServerEvent::REQUEST_RECEIVED to a WaitSet/Listener. Detaching it from previous one and " "attaching it to the new one with ServerState::HAS_REQUEST. Best practice is to call detach first."); - errorHandler( + IOX_REPORT( PoshError:: POPO__BASE_SERVER_OVERRIDING_WITH_STATE_SINCE_HAS_REQUEST_OR_REQUEST_RECEIVED_ALREADY_ATTACHED, - ErrorLevel::MODERATE); + iox::er::RUNTIME_ERROR); } m_trigger = std::move(triggerHandle); m_port.setConditionVariable(*m_trigger.getConditionVariableData(), m_trigger.getUniqueId()); @@ -165,10 +166,10 @@ inline void BaseServer::enableEvent(TriggerHandleT&& trig "ServerEvent::REQUEST_RECEIVED to a WaitSet/Listener. Detaching it from previous one and " "attaching it to the new one with ServerEvent::REQUEST_RECEIVED. Best practice is to call detach " "first."); - errorHandler( + IOX_REPORT( PoshError:: POPO__BASE_SERVER_OVERRIDING_WITH_EVENT_SINCE_HAS_REQUEST_OR_REQUEST_RECEIVED_ALREADY_ATTACHED, - ErrorLevel::MODERATE); + iox::er::RUNTIME_ERROR); } m_trigger = std::move(triggerHandle); m_port.setConditionVariable(*m_trigger.getConditionVariableData(), m_trigger.getUniqueId()); 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 06d1ffc41f..f12aa2d456 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/base_subscriber.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/base_subscriber.inl @@ -124,9 +124,9 @@ inline void BaseSubscriber::enableState(iox::popo::TriggerHandle&& trigg "SubscriberEvent::DATA_RECEIVED to a WaitSet/Listener. Detaching it from previous one and " "attaching it to the new one with SubscriberState::HAS_DATA. Best practice is to call detach first."); - errorHandler( + IOX_REPORT( PoshError::POPO__BASE_SUBSCRIBER_OVERRIDING_WITH_STATE_SINCE_HAS_DATA_OR_DATA_RECEIVED_ALREADY_ATTACHED, - ErrorLevel::MODERATE); + iox::er::RUNTIME_ERROR); } m_trigger = std::move(triggerHandle); m_port.setConditionVariable(*m_trigger.getConditionVariableData(), m_trigger.getUniqueId()); @@ -173,9 +173,9 @@ inline void BaseSubscriber::enableEvent(iox::popo::TriggerHandle&& trigg "SubscriberEvent::DATA_RECEIVED to a WaitSet/Listener. Detaching it from previous one and " "attaching it to the new one with SubscriberEvent::DATA_RECEIVED. Best practice is to call detach " "first."); - errorHandler( + IOX_REPORT( PoshError::POPO__BASE_SUBSCRIBER_OVERRIDING_WITH_EVENT_SINCE_HAS_DATA_OR_DATA_RECEIVED_ALREADY_ATTACHED, - ErrorLevel::MODERATE); + iox::er::RUNTIME_ERROR); } m_trigger = std::move(triggerHandle); m_port.setConditionVariable(*m_trigger.getConditionVariableData(), m_trigger.getUniqueId()); 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 fe4d11f7f1..d8f3bb907b 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 @@ -19,6 +19,7 @@ #define IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_DISTRIBUTOR_INL #include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -90,7 +91,7 @@ ChunkDistributor::tryAddQueue(not_null::cleanup() noexcept /// and a sending application dies when having the lock for sending. If the RouDi daemon wants to /// cleanup or does discovery changes we have a deadlock or an exception when destroying the mutex /// As long as we don't have a multi-threaded lock-free ChunkDistributor or another concept we die here - errorHandler(PoshError::POPO__CHUNK_DISTRIBUTOR_CLEANUP_DEADLOCK_BECAUSE_BAD_APPLICATION_TERMINATION, - ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__CHUNK_DISTRIBUTOR_CLEANUP_DEADLOCK_BECAUSE_BAD_APPLICATION_TERMINATION); } } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor_data.hpp index 4395f22f4b..dae31107c7 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_distributor_data.hpp @@ -17,9 +17,9 @@ #ifndef IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_DISTRIBUTOR_DATA_HPP #define IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_DISTRIBUTOR_DATA_HPP -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/mepoo/shm_safe_unmanaged_chunk.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_pusher.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/port_queue_policies.hpp" #include "iox/algorithm.hpp" #include "iox/logging.hpp" diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.inl index f0fff697ef..1e6040199c 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.inl @@ -18,6 +18,7 @@ #define IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_QUEUE_POPPER_INL #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/logging.hpp" namespace iox @@ -61,8 +62,8 @@ inline optional ChunkQueuePopper::tryPop "Received chunk with CHUNK_HEADER_VERSION '" << receivedChunkHeaderVersion << "' but expected '" << mepoo::ChunkHeader::CHUNK_HEADER_VERSION << "'! Dropping chunk!"); - errorHandler(PoshError::POPO__CHUNK_QUEUE_POPPER_CHUNK_WITH_INCOMPATIBLE_CHUNK_HEADER_VERSION, - ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POPO__CHUNK_QUEUE_POPPER_CHUNK_WITH_INCOMPATIBLE_CHUNK_HEADER_VERSION, + iox::er::RUNTIME_ERROR); return nullopt_t(); } return make_optional(chunk); diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_receiver.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_receiver.inl index 47a4c86d4a..eecd62b426 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_receiver.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_receiver.inl @@ -17,8 +17,8 @@ #ifndef IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_RECEIVER_INL #define IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_RECEIVER_INL -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -100,7 +100,7 @@ inline void ChunkReceiver::release(const mepoo::ChunkHead // d'tor of SharedChunk will release the memory, we do not have to touch the returned chunk if (!getMembers()->m_chunksInUse.remove(chunkHeader, chunk)) { - errorHandler(PoshError::POPO__CHUNK_RECEIVER_INVALID_CHUNK_TO_RELEASE_FROM_USER, ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POPO__CHUNK_RECEIVER_INVALID_CHUNK_TO_RELEASE_FROM_USER, iox::er::RUNTIME_ERROR); } } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp index 2456825394..b755797226 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp @@ -17,11 +17,11 @@ #ifndef IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_SENDER_HPP #define IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_SENDER_HPP -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/mepoo/shared_chunk.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender_data.hpp" #include "iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iox/detail/unique_id.hpp" #include "iox/expected.hpp" diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl index 81b7fe4a69..734d2a3da9 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_sender.inl @@ -19,6 +19,7 @@ #define IOX_POSH_POPO_BUILDING_BLOCKS_CHUNK_SENDER_INL #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -172,7 +173,7 @@ inline void ChunkSender::release(const mepoo::ChunkHeader* // d'tor of SharedChunk will release the memory, we do not have to touch the returned chunk if (!getMembers()->m_chunksInUse.remove(chunkHeader, chunk)) { - errorHandler(PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_FREE_FROM_USER, ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_FREE_FROM_USER, iox::er::RUNTIME_ERROR); } } @@ -262,7 +263,7 @@ inline bool ChunkSender::getChunkReadyForSend(const mepoo:: } else { - errorHandler(PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_SEND_FROM_USER, ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_SEND_FROM_USER, iox::er::RUNTIME_ERROR); return false; } } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp index f27e730c98..6483a72316 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp @@ -17,8 +17,8 @@ #ifndef IOX_POSH_POPO_BUILDING_BLOCKS_CONDITION_VARIABLE_DATA_HPP #define IOX_POSH_POPO_BUILDING_BLOCKS_CONDITION_VARIABLE_DATA_HPP -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/unnamed_semaphore.hpp" #include diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp index a6d038aa08..5eb8eed6f7 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp @@ -17,7 +17,7 @@ #ifndef IOX_POSH_POPO_BUILDING_BLOCKS_UNIQUE_PORT_ID_HPP #define IOX_POSH_POPO_BUILDING_BLOCKS_UNIQUE_PORT_ID_HPP -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/newtype.hpp" #include @@ -70,7 +70,7 @@ class UniquePortId : public NewType globalIDCounter; // initialized in cpp file static std::atomic uniqueRouDiId; // initialized in cpp file + static std::atomic uniqueRouDiIdFinalizeFlag; // initialized in cpp file }; } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/notification_info.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/notification_info.inl index 2e072375d7..ad16a3f321 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/notification_info.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/notification_info.inl @@ -17,7 +17,7 @@ #ifndef IOX_POSH_POPO_NOTIFICATION_INFO_INL #define IOX_POSH_POPO_NOTIFICATION_INFO_INL -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/notification_info.hpp" namespace iox @@ -52,7 +52,7 @@ inline T* NotificationInfo::getOrigin() const noexcept { if (m_notificationOriginTypeHash != typeid(T).hash_code()) { - errorHandler(PoshError::POPO__NOTIFICATION_INFO_TYPE_INCONSISTENCY_IN_GET_ORIGIN, iox::ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POPO__NOTIFICATION_INFO_TYPE_INCONSISTENCY_IN_GET_ORIGIN, iox::er::RUNTIME_ERROR); return nullptr; } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/client_port_user.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/client_port_user.hpp index ad4a8989eb..d67ebff147 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/client_port_user.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/client_port_user.hpp @@ -17,11 +17,11 @@ #ifndef IOX_POSH_POPO_PORTS_CLIENT_PORT_USER_HPP #define IOX_POSH_POPO_PORTS_CLIENT_PORT_USER_HPP -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp" #include "iceoryx_posh/internal/popo/ports/base_port.hpp" #include "iceoryx_posh/internal/popo/ports/client_port_data.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/rpc_header.hpp" #include "iox/expected.hpp" #include "iox/optional.hpp" diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/server_port_user.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/server_port_user.hpp index 44aaed17ef..9ace7765fc 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/server_port_user.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/server_port_user.hpp @@ -17,11 +17,11 @@ #ifndef IOX_POSH_POPO_PORTS_SERVER_PORT_USER_HPP #define IOX_POSH_POPO_PORTS_SERVER_PORT_USER_HPP -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp" #include "iceoryx_posh/internal/popo/ports/base_port.hpp" #include "iceoryx_posh/internal/popo/ports/server_port_data.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_posh/popo/rpc_header.hpp" #include "iox/expected.hpp" diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/request.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/request.inl index 0fe47f12ab..bf9f8445cf 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/request.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/request.inl @@ -17,6 +17,7 @@ #ifndef IOX_POSH_POPO_REQUEST_INL #define IOX_POSH_POPO_REQUEST_INL +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/request.hpp" namespace iox @@ -34,7 +35,7 @@ inline expected Request::send() noexcept else { IOX_LOG(ERROR, "Tried to send empty Request! Might be an already sent or moved Request!"); - errorHandler(PoshError::POSH__SENDING_EMPTY_REQUEST, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__SENDING_EMPTY_REQUEST, iox::er::RUNTIME_ERROR); return err(ClientSendError::INVALID_REQUEST); } } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/response.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/response.inl index f3d279725d..828dece13c 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/response.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/response.inl @@ -17,6 +17,7 @@ #ifndef IOX_POSH_POPO_RESPONSE_INL #define IOX_POSH_POPO_RESPONSE_INL +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/response.hpp" namespace iox @@ -34,7 +35,7 @@ inline expected Response::send() noexcept else { IOX_LOG(ERROR, "Tried to send empty Response! Might be an already sent or moved Response!"); - errorHandler(PoshError::POSH__SENDING_EMPTY_RESPONSE, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__SENDING_EMPTY_RESPONSE, iox::er::RUNTIME_ERROR); return err(ServerSendError::INVALID_RESPONSE); } } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/sample.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/sample.inl index 8fd2866348..b5f696e861 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/sample.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/sample.inl @@ -17,6 +17,7 @@ #ifndef IOX_POSH_POPO_SAMPLE_INL #define IOX_POSH_POPO_SAMPLE_INL +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/sample.hpp" namespace iox @@ -34,7 +35,7 @@ void Sample::publish() noexcept else { IOX_LOG(ERROR, "Tried to publish empty Sample! Might be an already published or moved Sample!"); - errorHandler(PoshError::POSH__PUBLISHING_EMPTY_SAMPLE, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__PUBLISHING_EMPTY_SAMPLE, iox::er::RUNTIME_ERROR); } } } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/error_handling/error_handling.hpp b/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp similarity index 85% rename from iceoryx_posh/include/iceoryx_posh/error_handling/error_handling.hpp rename to iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp index 3c9468e123..ca5e337f46 100644 --- a/iceoryx_posh/include/iceoryx_posh/error_handling/error_handling.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp @@ -14,9 +14,24 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#ifndef IOX_POSH_ERROR_HANDLING_ERROR_HANDLING_HPP -#define IOX_POSH_ERROR_HANDLING_ERROR_HANDLING_HPP +#ifndef IOX_POSH_POSH_ERROR_REPORTING_HPP +#define IOX_POSH_POSH_ERROR_REPORTING_HPP + +// Each module (= some unit with its own errors) must provide the following. + +// 1. Define the errors of the module -> see below + +// 2. Include the custom reporting implementation +#include "iox/error_reporting/custom/error_reporting.hpp" + +// 3. Include the error reporting macro API +#include "iox/error_reporting/macros.hpp" + +// additional includes +#include "iox/error_reporting/types.hpp" + +/// @todo iox-#1032 Remove once C_BINDING_MODULE_IDENTIFIER is moved to 'ModuleId' in 'error_reporting/types.hpp' #include "iceoryx_hoofs/error_handling/error_handler.hpp" namespace iox @@ -154,19 +169,69 @@ namespace iox error(IPC_INTERFACE__REG_ACK_INVALIG_NUMBER_OF_PARAMS) \ error(IPC_INTERFACE__REG_ACK_NO_RESPONSE) \ error(IPC_INTERFACE__APP_WITH_SAME_NAME_STILL_RUNNING) \ - error(IPC_INTERFACE__COULD_NOT_ACQUIRE_FILE_LOCK) + error(IPC_INTERFACE__COULD_NOT_ACQUIRE_FILE_LOCK) \ + error(DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER) // keep this always at the end of the error list + // clang-format on // DO NOT TOUCH THE ENUM, you can doodle around with the lines above!!! -enum class PoshError : uint32_t +enum class PoshError : iox::er::ErrorCode::type { - NO_ERROR = POSH_MODULE_IDENTIFIER << ERROR_ENUM_OFFSET_IN_BITS, POSH_ERRORS(CREATE_ICEORYX_ERROR_ENUM) }; const char* asStringLiteral(const PoshError error) noexcept; +class PoshErrorType +{ + public: + explicit PoshErrorType(PoshError code) + : m_code(static_cast(code)) + { + } + + static constexpr iox::er::ModuleId module() + { + return MODULE_ID; + } + + iox::er::ErrorCode code() const + { + return m_code; + } + + const char* name() const + { + return asStringLiteral(static_cast(m_code.value)); + } + + static const char* moduleName() + { + return "iceoryx_posh"; + } + + static constexpr iox::er::ModuleId MODULE_ID{POSH_MODULE_IDENTIFIER}; + + protected: + iox::er::ErrorCode m_code; +}; + +namespace er +{ + +inline PoshErrorType toError(PoshError code) +{ + return PoshErrorType(code); +} + +inline ModuleId toModule(PoshError) +{ + return PoshErrorType::MODULE_ID; +} + +} // namespace er } // namespace iox -#endif // IOX_POSH_ERROR_HANDLING_ERROR_HANDLING_HPP + +#endif // IOX_POSH_POSH_ERROR_REPORTING_HPP diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl index 99ddcfe77e..ce035ff5fd 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl @@ -17,6 +17,7 @@ #ifndef IOX_POSH_ROUDI_INTROSPECTION_MEMPOOL_INTROSPECTION_INL #define IOX_POSH_ROUDI_INTROSPECTION_MEMPOOL_INTROSPECTION_INL +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/thread.hpp" #include "mempool_introspection.hpp" @@ -93,7 +94,7 @@ inline void MemPoolIntrospection:: if (maybeChunkHeader.has_error()) { IOX_LOG(WARN, "Cannot allocate chunk for mempool introspection!"); - errorHandler(PoshError::MEPOO__CANNOT_ALLOCATE_CHUNK, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::MEPOO__CANNOT_ALLOCATE_CHUNK, iox::er::RUNTIME_ERROR); return; } @@ -127,7 +128,7 @@ inline void MemPoolIntrospection:: "Mempool Introspection Container full, Mempool Introspection Data not fully updated! " << (id + 1U) << " of " << m_segmentManager->m_segmentContainer.size() << " memory segments sent."); - errorHandler(PoshError::MEPOO__INTROSPECTION_CONTAINER_FULL, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::MEPOO__INTROSPECTION_CONTAINER_FULL, iox::er::RUNTIME_ERROR); break; } ++id; @@ -139,7 +140,7 @@ inline void MemPoolIntrospection:: "Mempool Introspection Container full, Mempool Introspection Data not fully updated! " << (id + 1U) << " of " << m_segmentManager->m_segmentContainer.size() << " memory segments sent."); - errorHandler(PoshError::MEPOO__INTROSPECTION_CONTAINER_FULL, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::MEPOO__INTROSPECTION_CONTAINER_FULL, iox::er::RUNTIME_ERROR); } m_publisherPort.sendChunk(maybeChunkHeader.value()); diff --git a/iceoryx_posh/include/iceoryx_posh/popo/notification_info.hpp b/iceoryx_posh/include/iceoryx_posh/popo/notification_info.hpp index 690cbb79ea..6cee135e94 100644 --- a/iceoryx_posh/include/iceoryx_posh/popo/notification_info.hpp +++ b/iceoryx_posh/include/iceoryx_posh/popo/notification_info.hpp @@ -60,8 +60,7 @@ class NotificationInfo /// @brief returns the pointer to the notificationOrigin. /// @return If T equals the Triggerable type it returns the notificationOrigin. - /// Otherwise it calls the errorHandler with a moderate error of - /// kPOPO__EVENT_INFO_TYPE_INCONSISTENCY_IN_GET_ORIGIN and returns nullptr. + /// Otherwise it reports a 'POPO__NOTIFICATION_INFO_TYPE_INCONSISTENCY_IN_GET_ORIGIN' and returns nullptr. template T* getOrigin() const noexcept; diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp index eb98647980..cc819f2f7a 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp @@ -62,25 +62,24 @@ class IceOryxRouDiMemoryManager : public RouDiMemoryInterface private: // in order to prevent a second RouDi to cleanup the memory resources of a running RouDi, this resources are // protected by a file lock - FileLock fileLock = std::move( - FileLockBuilder() - .name(ROUDI_LOCK_NAME) - .permission(iox::perms::owner_read | iox::perms::owner_write) - .create() - .or_else([](auto& error) { - if (error == FileLockError::LOCKED_BY_OTHER_PROCESS) - { - IOX_LOG(FATAL, "Could not acquire lock, is RouDi still running?"); - errorHandler(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__ROUDI_STILL_RUNNING, iox::ErrorLevel::FATAL); - } - else - { - IOX_LOG(FATAL, "Error occurred while acquiring file lock named " << ROUDI_LOCK_NAME); - errorHandler(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__COULD_NOT_ACQUIRE_FILE_LOCK, - iox::ErrorLevel::FATAL); - } - }) - .value()); + FileLock fileLock = + std::move(FileLockBuilder() + .name(ROUDI_LOCK_NAME) + .permission(iox::perms::owner_read | iox::perms::owner_write) + .create() + .or_else([](auto& error) { + if (error == FileLockError::LOCKED_BY_OTHER_PROCESS) + { + IOX_LOG(FATAL, "Could not acquire lock, is RouDi still running?"); + IOX_REPORT_FATAL(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__ROUDI_STILL_RUNNING); + } + else + { + IOX_LOG(FATAL, "Error occurred while acquiring file lock named " << ROUDI_LOCK_NAME); + IOX_REPORT_FATAL(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__COULD_NOT_ACQUIRE_FILE_LOCK); + } + }) + .value()); PortPoolMemoryBlock m_portPoolBlock; optional m_portPool; diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp index 609b2287fd..a4efd51b27 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/roudi_app.hpp @@ -17,8 +17,8 @@ #ifndef IOX_POSH_ROUDI_ROUDI_APP_HPP #define IOX_POSH_ROUDI_ROUDI_APP_HPP -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/iceoryx_posh_config.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/roudi/cmd_line_args.hpp" #include "iox/detail/deprecation_marker.hpp" diff --git a/iceoryx_posh/roudi_env/include/iceoryx_posh/roudi_env/roudi_env.hpp b/iceoryx_posh/roudi_env/include/iceoryx_posh/roudi_env/roudi_env.hpp index 224d6319d8..1fb99abb3c 100644 --- a/iceoryx_posh/roudi_env/include/iceoryx_posh/roudi_env/roudi_env.hpp +++ b/iceoryx_posh/roudi_env/include/iceoryx_posh/roudi_env/roudi_env.hpp @@ -40,7 +40,7 @@ class RouDiEnv public: RouDiEnv(const RouDiConfig_t& roudiConfig = RouDiConfig_t().setDefaults(), roudi::MonitoringMode monitoringMode = roudi::MonitoringMode::OFF, - const uint16_t uniqueRouDiId = 0u) noexcept; + const uint16_t uniqueRouDiId = roudi::DEFAULT_UNIQUE_ROUDI_ID) noexcept; virtual ~RouDiEnv() noexcept; RouDiEnv(RouDiEnv&& rhs) noexcept = default; @@ -60,7 +60,7 @@ class RouDiEnv { }; /// @brief for implementations on top of RouDiEnv - RouDiEnv(MainCTor, const uint16_t uniqueRouDiId = 0u) noexcept; + RouDiEnv(MainCTor, const uint16_t uniqueRouDiId = roudi::DEFAULT_UNIQUE_ROUDI_ID) noexcept; void cleanupRuntimes() noexcept; diff --git a/iceoryx_posh/roudi_env/source/roudi_env.cpp b/iceoryx_posh/roudi_env/source/roudi_env.cpp index 425912c359..d24701d376 100644 --- a/iceoryx_posh/roudi_env/source/roudi_env.cpp +++ b/iceoryx_posh/roudi_env/source/roudi_env.cpp @@ -28,7 +28,8 @@ namespace roudi_env { RouDiEnv::RouDiEnv(MainCTor, const uint16_t uniqueRouDiId) noexcept { - popo::UniquePortId::rouDiEnvOverrideUniqueRouDiId(uniqueRouDiId); + popo::UniquePortId::rouDiEnvResetFinalizeUniqueRouDiId(); + popo::UniquePortId::setUniqueRouDiId(uniqueRouDiId); } RouDiEnv::RouDiEnv(const RouDiConfig_t& roudiConfig, @@ -47,7 +48,7 @@ RouDiEnv::~RouDiEnv() noexcept { if (m_runtimes.m_doCleanupOnDestruction) { - popo::UniquePortId::rouDiEnvOverrideUniqueRouDiId(roudi::DEFAULT_UNIQUE_ROUDI_ID); + popo::UniquePortId::rouDiEnvResetFinalizeUniqueRouDiId(); } cleanupRuntimes(); } diff --git a/iceoryx_posh/source/mepoo/mem_pool.cpp b/iceoryx_posh/source/mepoo/mem_pool.cpp index a4bfb2fe56..0d28dc3a89 100644 --- a/iceoryx_posh/source/mepoo/mem_pool.cpp +++ b/iceoryx_posh/source/mepoo/mem_pool.cpp @@ -19,7 +19,7 @@ #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include @@ -68,7 +68,7 @@ MemPool::MemPool(const greater_or_equal chunkS IOX_LOG(FATAL, "Chunk size must be multiple of '" << CHUNK_MEMORY_ALIGNMENT << "'! Requested size is " << chunkSize << " for " << numberOfChunks << " chunks!"); - errorHandler(PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT); + IOX_REPORT_FATAL(PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT); } } @@ -129,7 +129,7 @@ void MemPool::freeChunk(const void* chunk) noexcept if (!m_freeIndices.push(index)) { - errorHandler(PoshError::POSH__MEMPOOL_POSSIBLE_DOUBLE_FREE); + IOX_REPORT_FATAL(PoshError::POSH__MEMPOOL_POSSIBLE_DOUBLE_FREE); } m_usedChunks.fetch_sub(1U, std::memory_order_relaxed); diff --git a/iceoryx_posh/source/mepoo/memory_manager.cpp b/iceoryx_posh/source/mepoo/memory_manager.cpp index 509ad935eb..38a8bbf59c 100644 --- a/iceoryx_posh/source/mepoo/memory_manager.cpp +++ b/iceoryx_posh/source/mepoo/memory_manager.cpp @@ -16,8 +16,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iox/logging.hpp" @@ -47,7 +47,7 @@ void MemoryManager::addMemPool(BumpAllocator& managementAllocator, if (m_denyAddMemPool) { IOX_LOG(FATAL, "After the generation of the chunk management pool you are not allowed to create new mempools."); - errorHandler(iox::PoshError::MEPOO__MEMPOOL_ADDMEMPOOL_AFTER_GENERATECHUNKMANAGEMENTPOOL); + IOX_REPORT_FATAL(iox::PoshError::MEPOO__MEMPOOL_ADDMEMPOOL_AFTER_GENERATECHUNKMANAGEMENTPOOL); } else if (m_memPoolVector.size() > 0 && adjustedChunkSize <= m_memPoolVector.back().getChunkSize()) { @@ -60,7 +60,7 @@ void MemoryManager::addMemPool(BumpAllocator& managementAllocator, "ChunkSize = " << adjustedChunkSize << ", ChunkPayloadSize = " << chunkPayloadSize << ", ChunkCount = " << numberOfChunks << "] breaks that requirement!"); - errorHandler(iox::PoshError::MEPOO__MEMPOOL_CONFIG_MUST_BE_ORDERED_BY_INCREASING_SIZE); + IOX_REPORT_FATAL(iox::PoshError::MEPOO__MEMPOOL_CONFIG_MUST_BE_ORDERED_BY_INCREASING_SIZE); } m_memPoolVector.emplace_back(adjustedChunkSize, numberOfChunks, managementAllocator, chunkMemoryAllocator); @@ -165,22 +165,22 @@ expected MemoryManager::getChunk(const ChunkS if (m_memPoolVector.size() == 0) { - IOX_LOG(FATAL, "There are no mempools available!"); + IOX_LOG(ERROR, "There are no mempools available!"); - errorHandler(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_WITHOUT_MEMPOOL, ErrorLevel::SEVERE); + IOX_REPORT(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_WITHOUT_MEMPOOL, iox::er::RUNTIME_ERROR); return err(Error::NO_MEMPOOLS_AVAILABLE); } else if (memPoolPointer == nullptr) { IOX_LOG( - FATAL, + ERROR, "The following mempools are available:" << [this](auto& log) -> auto& { this->printMemPoolVector(log); return log; } << "Could not find a fitting mempool for a chunk of size " << requiredChunkSize); - errorHandler(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_IS_TOO_LARGE, ErrorLevel::SEVERE); + IOX_REPORT(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_IS_TOO_LARGE, iox::er::RUNTIME_ERROR); return err(Error::NO_MEMPOOL_FOR_REQUESTED_CHUNK_SIZE); } else if (chunk == nullptr) @@ -194,7 +194,7 @@ expected MemoryManager::getChunk(const ChunkS return log; }); - errorHandler(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_POOL_IS_RUNNING_OUT_OF_CHUNKS, ErrorLevel::MODERATE); + IOX_REPORT(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_POOL_IS_RUNNING_OUT_OF_CHUNKS, iox::er::RUNTIME_ERROR); return err(Error::MEMPOOL_OUT_OF_CHUNKS); } else diff --git a/iceoryx_posh/source/mepoo/mepoo_config.cpp b/iceoryx_posh/source/mepoo/mepoo_config.cpp index 090ee26a1d..3d3627dfb4 100644 --- a/iceoryx_posh/source/mepoo/mepoo_config.cpp +++ b/iceoryx_posh/source/mepoo/mepoo_config.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/mepoo/mepoo_config.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/logging.hpp" namespace iox @@ -37,7 +37,7 @@ void MePooConfig::addMemPool(MePooConfig::Entry entry) noexcept else { IOX_LOG(FATAL, "Maxmimum number of mempools reached, no more mempools available"); - errorHandler(PoshError::MEPOO__MAXIMUM_NUMBER_OF_MEMPOOLS_REACHED, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::MEPOO__MAXIMUM_NUMBER_OF_MEMPOOLS_REACHED); } } diff --git a/iceoryx_posh/source/popo/building_blocks/condition_listener.cpp b/iceoryx_posh/source/popo/building_blocks/condition_listener.cpp index eb1c8589e1..fb82639237 100644 --- a/iceoryx_posh/source/popo/building_blocks/condition_listener.cpp +++ b/iceoryx_posh/source/popo/building_blocks/condition_listener.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -35,7 +35,7 @@ void ConditionListener::resetSemaphore() noexcept && getMembers() ->m_semaphore->tryWait() .or_else([&](SemaphoreError) { - errorHandler(PoshError::POPO__CONDITION_LISTENER_SEMAPHORE_CORRUPTED_IN_RESET, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__CONDITION_LISTENER_SEMAPHORE_CORRUPTED_IN_RESET); hasFatalError = true; }) .value()) @@ -46,9 +46,8 @@ void ConditionListener::resetSemaphore() noexcept void ConditionListener::destroy() volatile noexcept { m_toBeDestroyed.store(true, std::memory_order_relaxed); - getMembers()->m_semaphore->post().or_else([](auto) { - errorHandler(PoshError::POPO__CONDITION_LISTENER_SEMAPHORE_CORRUPTED_IN_DESTROY, ErrorLevel::FATAL); - }); + getMembers()->m_semaphore->post().or_else( + [](auto) { IOX_REPORT_FATAL(PoshError::POPO__CONDITION_LISTENER_SEMAPHORE_CORRUPTED_IN_DESTROY); }); } bool ConditionListener::wasNotified() const noexcept @@ -61,7 +60,7 @@ ConditionListener::NotificationVector_t ConditionListener::wait() noexcept return waitImpl([this]() -> bool { if (this->getMembers()->m_semaphore->wait().has_error()) { - errorHandler(PoshError::POPO__CONDITION_LISTENER_SEMAPHORE_CORRUPTED_IN_WAIT, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__CONDITION_LISTENER_SEMAPHORE_CORRUPTED_IN_WAIT); return false; } return true; @@ -73,7 +72,7 @@ ConditionListener::NotificationVector_t ConditionListener::timedWait(const units return waitImpl([this, timeToWait]() -> bool { if (this->getMembers()->m_semaphore->timedWait(timeToWait).has_error()) { - errorHandler(PoshError::POPO__CONDITION_LISTENER_SEMAPHORE_CORRUPTED_IN_TIMED_WAIT, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__CONDITION_LISTENER_SEMAPHORE_CORRUPTED_IN_TIMED_WAIT); } return false; }); diff --git a/iceoryx_posh/source/popo/building_blocks/condition_notifier.cpp b/iceoryx_posh/source/popo/building_blocks/condition_notifier.cpp index 755cf5ecc3..4b1c07d768 100644 --- a/iceoryx_posh/source/popo/building_blocks/condition_notifier.cpp +++ b/iceoryx_posh/source/popo/building_blocks/condition_notifier.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/building_blocks/condition_notifier.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/logging.hpp" namespace iox @@ -31,7 +32,7 @@ ConditionNotifier::ConditionNotifier(ConditionVariableData& condVarDataRef, cons IOX_LOG(FATAL, "The provided index " << index << " is too large. The index has to be in the range of [0, " << MAX_NUMBER_OF_NOTIFIERS << "[."); - errorHandler(PoshError::POPO__CONDITION_NOTIFIER_INDEX_TOO_LARGE, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__CONDITION_NOTIFIER_INDEX_TOO_LARGE); } } @@ -40,7 +41,7 @@ void ConditionNotifier::notify() noexcept getMembers()->m_activeNotifications[m_notificationIndex].store(true, std::memory_order_release); getMembers()->m_wasNotified.store(true, std::memory_order_relaxed); getMembers()->m_semaphore->post().or_else( - [](auto) { errorHandler(PoshError::POPO__CONDITION_NOTIFIER_SEMAPHORE_CORRUPT_IN_NOTIFY, ErrorLevel::FATAL); }); + [](auto) { IOX_REPORT_FATAL(PoshError::POPO__CONDITION_NOTIFIER_SEMAPHORE_CORRUPT_IN_NOTIFY); }); } const ConditionVariableData* ConditionNotifier::getMembers() const noexcept diff --git a/iceoryx_posh/source/popo/building_blocks/condition_variable_data.cpp b/iceoryx_posh/source/popo/building_blocks/condition_variable_data.cpp index a94fa8b2a9..9b786c5399 100644 --- a/iceoryx_posh/source/popo/building_blocks/condition_variable_data.cpp +++ b/iceoryx_posh/source/popo/building_blocks/condition_variable_data.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -30,7 +31,7 @@ ConditionVariableData::ConditionVariableData(const RuntimeName_t& runtimeName) n : m_runtimeName(runtimeName) { UnnamedSemaphoreBuilder().initialValue(0U).isInterProcessCapable(true).create(m_semaphore).or_else([](auto) { - errorHandler(PoshError::POPO__CONDITION_VARIABLE_DATA_FAILED_TO_CREATE_SEMAPHORE, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__CONDITION_VARIABLE_DATA_FAILED_TO_CREATE_SEMAPHORE); }); for (auto& id : m_activeNotifications) diff --git a/iceoryx_posh/source/popo/building_blocks/locking_policy.cpp b/iceoryx_posh/source/popo/building_blocks/locking_policy.cpp index dee11d8718..db1796b422 100644 --- a/iceoryx_posh/source/popo/building_blocks/locking_policy.cpp +++ b/iceoryx_posh/source/popo/building_blocks/locking_policy.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/logging.hpp" namespace iox @@ -39,7 +39,7 @@ void ThreadSafePolicy::lock() const noexcept IOX_LOG(FATAL, "Locking of an inter-process mutex failed! This indicates that the application holding the lock " "was terminated or the resources were cleaned up by RouDi due to an unresponsive application."); - errorHandler(PoshError::POPO__CHUNK_LOCKING_ERROR, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__CHUNK_LOCKING_ERROR); } } @@ -50,7 +50,7 @@ void ThreadSafePolicy::unlock() const noexcept IOX_LOG(FATAL, "Unlocking of an inter-process mutex failed! This indicates that the resources were cleaned up " "by RouDi due to an unresponsive application."); - errorHandler(PoshError::POPO__CHUNK_UNLOCKING_ERROR, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__CHUNK_UNLOCKING_ERROR); } } @@ -59,7 +59,7 @@ bool ThreadSafePolicy::tryLock() const noexcept auto tryLockResult = m_mutex->try_lock(); if (tryLockResult.has_error()) { - errorHandler(PoshError::POPO__CHUNK_TRY_LOCK_ERROR, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__CHUNK_TRY_LOCK_ERROR); } return *tryLockResult == MutexTryLock::LOCK_SUCCEEDED; } diff --git a/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp b/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp index 967c900448..779cc5dd8e 100644 --- a/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp +++ b/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp @@ -17,6 +17,7 @@ #include "iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -27,6 +28,8 @@ std::atomic UniquePortId::uniqueRouDiId{roudi::DEFAULT_UNIQUE_ROUDI_ID // start with 1 to prevent accidentally generating an invalid ID when unique roudi ID is 0 std::atomic UniquePortId::globalIDCounter{1U}; +std::atomic UniquePortId::uniqueRouDiIdFinalizeFlag{false}; + UniquePortId::UniquePortId() noexcept : ThisType(newtype::internal::ProtectedConstructor, (static_cast(getUniqueRouDiId()) << UNIQUE_ID_BIT_LENGTH) @@ -37,7 +40,7 @@ UniquePortId::UniquePortId() noexcept if (globalIDCounter.load() >= (static_cast(1u) << UNIQUE_ID_BIT_LENGTH)) { - errorHandler(PoshError::POPO__TYPED_UNIQUE_ID_OVERFLOW, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::POPO__TYPED_UNIQUE_ID_OVERFLOW); } } @@ -58,22 +61,19 @@ void UniquePortId::setUniqueRouDiId(const uint16_t id) noexcept { if (finalizeSetUniqueRouDiId()) { - errorHandler(PoshError::POPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_CUSTOM_UNIQUE_ID, ErrorLevel::SEVERE); + IOX_REPORT_FATAL(PoshError::POPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_CUSTOM_UNIQUE_ID); } uniqueRouDiId.store(id, std::memory_order_relaxed); } -void UniquePortId::rouDiEnvOverrideUniqueRouDiId(const uint16_t id) noexcept +void UniquePortId::rouDiEnvResetFinalizeUniqueRouDiId() noexcept { - uniqueRouDiId.store(id, std::memory_order_relaxed); + uniqueRouDiIdFinalizeFlag.store(false, std::memory_order_relaxed); } bool UniquePortId::finalizeSetUniqueRouDiId() noexcept { - static bool finalized{false}; - auto oldFinalized = finalized; - finalized = true; - return oldFinalized; + return uniqueRouDiIdFinalizeFlag.exchange(true, std::memory_order::memory_order_relaxed); } uint16_t UniquePortId::getUniqueRouDiId() noexcept diff --git a/iceoryx_posh/source/popo/ports/client_port_roudi.cpp b/iceoryx_posh/source/popo/ports/client_port_roudi.cpp index 77cef19e44..61581c6211 100644 --- a/iceoryx_posh/source/popo/ports/client_port_roudi.cpp +++ b/iceoryx_posh/source/popo/ports/client_port_roudi.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/ports/client_port_roudi.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -114,7 +115,7 @@ void ClientPortRouDi::handleCaProProtocolViolation(const iox::capro::CaproMessag IOX_LOG(FATAL, "CaPro Protocol Violation! Got '" << messageType << "' in '" << getMembers()->m_connectionState.load(std::memory_order_relaxed) << "'"); - errorHandler(PoshError::POPO__CAPRO_PROTOCOL_ERROR, ErrorLevel::SEVERE); + IOX_REPORT_FATAL(PoshError::POPO__CAPRO_PROTOCOL_ERROR); } optional diff --git a/iceoryx_posh/source/popo/ports/client_port_user.cpp b/iceoryx_posh/source/popo/ports/client_port_user.cpp index 055b91b046..1dbdd233fc 100644 --- a/iceoryx_posh/source/popo/ports/client_port_user.cpp +++ b/iceoryx_posh/source/popo/ports/client_port_user.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/ports/client_port_user.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -63,7 +64,7 @@ void ClientPortUser::releaseRequest(const RequestHeader* const requestHeader) no } else { - errorHandler(PoshError::POPO__CLIENT_PORT_INVALID_REQUEST_TO_FREE_FROM_USER, ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POPO__CLIENT_PORT_INVALID_REQUEST_TO_FREE_FROM_USER, iox::er::RUNTIME_ERROR); } } @@ -72,7 +73,7 @@ expected ClientPortUser::sendRequest(RequestHeader* const if (requestHeader == nullptr) { IOX_LOG(ERROR, "Attempted to send a nullptr request!"); - errorHandler(PoshError::POPO__CLIENT_PORT_INVALID_REQUEST_TO_SEND_FROM_USER, ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POPO__CLIENT_PORT_INVALID_REQUEST_TO_SEND_FROM_USER, iox::er::RUNTIME_ERROR); return err(ClientSendError::INVALID_REQUEST); } @@ -135,7 +136,7 @@ void ClientPortUser::releaseResponse(const ResponseHeader* const responseHeader) } else { - errorHandler(PoshError::POPO__CLIENT_PORT_INVALID_RESPONSE_TO_RELEASE_FROM_USER, ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POPO__CLIENT_PORT_INVALID_RESPONSE_TO_RELEASE_FROM_USER, iox::er::RUNTIME_ERROR); } } diff --git a/iceoryx_posh/source/popo/ports/interface_port.cpp b/iceoryx_posh/source/popo/ports/interface_port.cpp index 62113632b1..1f81fb0820 100644 --- a/iceoryx_posh/source/popo/ports/interface_port.cpp +++ b/iceoryx_posh/source/popo/ports/interface_port.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/ports/interface_port.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -48,7 +48,7 @@ void InterfacePort::dispatchCaProMessage(const capro::CaproMessage& caProMessage if (!getMembers()->m_caproMessageFiFo.push(caProMessage)) { // information loss for this interface port - errorHandler(PoshError::POSH__INTERFACEPORT_CAPRO_MESSAGE_DISMISSED, ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POSH__INTERFACEPORT_CAPRO_MESSAGE_DISMISSED, iox::er::RUNTIME_ERROR); } } diff --git a/iceoryx_posh/source/popo/ports/publisher_port_roudi.cpp b/iceoryx_posh/source/popo/ports/publisher_port_roudi.cpp index 3317407a07..943af58120 100644 --- a/iceoryx_posh/source/popo/ports/publisher_port_roudi.cpp +++ b/iceoryx_posh/source/popo/ports/publisher_port_roudi.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/ports/publisher_port_roudi.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -109,7 +110,7 @@ PublisherPortRouDi::dispatchCaProMessageAndGetPossibleResponse(const capro::Capr } else { - errorHandler(PoshError::POPO__CAPRO_PROTOCOL_ERROR, ErrorLevel::SEVERE); + IOX_REPORT_FATAL(PoshError::POPO__CAPRO_PROTOCOL_ERROR); } } diff --git a/iceoryx_posh/source/popo/ports/server_port_roudi.cpp b/iceoryx_posh/source/popo/ports/server_port_roudi.cpp index 5a120b443d..1d91fe5dad 100644 --- a/iceoryx_posh/source/popo/ports/server_port_roudi.cpp +++ b/iceoryx_posh/source/popo/ports/server_port_roudi.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/ports/server_port_roudi.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -94,7 +95,7 @@ void ServerPortRouDi::handleCaProProtocolViolation(const capro::CaproMessageType IOX_LOG(FATAL, "CaPro Protocol Violation! Got '" << messageType << "' with offer state '" << (getMembers()->m_offered ? "OFFERED" : "NOT OFFERED") << "'!"); - errorHandler(PoshError::POPO__CAPRO_PROTOCOL_ERROR, ErrorLevel::SEVERE); + IOX_REPORT_FATAL(PoshError::POPO__CAPRO_PROTOCOL_ERROR); } optional @@ -114,7 +115,7 @@ ServerPortRouDi::handleCaProMessageForStateOffered(const capro::CaproMessage& ca if (caProMessage.m_chunkQueueData == nullptr) { IOX_LOG(WARN, "No client response queue passed to server"); - errorHandler(PoshError::POPO__SERVER_PORT_NO_CLIENT_RESPONSE_QUEUE_TO_CONNECT, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POPO__SERVER_PORT_NO_CLIENT_RESPONSE_QUEUE_TO_CONNECT, iox::er::RUNTIME_ERROR); } else { diff --git a/iceoryx_posh/source/popo/ports/server_port_user.cpp b/iceoryx_posh/source/popo/ports/server_port_user.cpp index 6113d3330c..193935ab1c 100644 --- a/iceoryx_posh/source/popo/ports/server_port_user.cpp +++ b/iceoryx_posh/source/popo/ports/server_port_user.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/ports/server_port_user.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -63,8 +64,8 @@ void ServerPortUser::releaseRequest(const RequestHeader* const requestHeader) no } else { - IOX_LOG(FATAL, "Provided RequestHeader is a nullptr"); - errorHandler(PoshError::POPO__SERVER_PORT_INVALID_REQUEST_TO_RELEASE_FROM_USER, ErrorLevel::SEVERE); + IOX_LOG(ERROR, "Provided RequestHeader is a nullptr"); + IOX_REPORT(PoshError::POPO__SERVER_PORT_INVALID_REQUEST_TO_RELEASE_FROM_USER, iox::er::RUNTIME_ERROR); } } @@ -117,8 +118,8 @@ void ServerPortUser::releaseResponse(const ResponseHeader* const responseHeader) } else { - IOX_LOG(FATAL, "Provided ResponseHeader is a nullptr"); - errorHandler(PoshError::POPO__SERVER_PORT_INVALID_RESPONSE_TO_FREE_FROM_USER, ErrorLevel::SEVERE); + IOX_LOG(ERROR, "Provided ResponseHeader is a nullptr"); + IOX_REPORT(PoshError::POPO__SERVER_PORT_INVALID_RESPONSE_TO_FREE_FROM_USER, iox::er::RUNTIME_ERROR); } } @@ -126,8 +127,8 @@ expected ServerPortUser::sendResponse(ResponseHeader* con { if (responseHeader == nullptr) { - IOX_LOG(FATAL, "Provided ResponseHeader is a nullptr"); - errorHandler(PoshError::POPO__SERVER_PORT_INVALID_RESPONSE_TO_SEND_FROM_USER, ErrorLevel::SEVERE); + IOX_LOG(ERROR, "Provided ResponseHeader is a nullptr"); + IOX_REPORT(PoshError::POPO__SERVER_PORT_INVALID_RESPONSE_TO_SEND_FROM_USER, iox::er::RUNTIME_ERROR); return err(ServerSendError::INVALID_RESPONSE); } diff --git a/iceoryx_posh/source/popo/ports/subscriber_port_multi_producer.cpp b/iceoryx_posh/source/popo/ports/subscriber_port_multi_producer.cpp index 25db2c57f6..ecddb24ea8 100644 --- a/iceoryx_posh/source/popo/ports/subscriber_port_multi_producer.cpp +++ b/iceoryx_posh/source/popo/ports/subscriber_port_multi_producer.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/ports/subscriber_port_multi_producer.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -89,8 +90,7 @@ optional SubscriberPortMultiProducer::dispatchCaProMessageA else { // but others should not be received here - errorHandler(PoshError::POPO__CAPRO_PROTOCOL_ERROR, ErrorLevel::SEVERE); - return nullopt_t(); + IOX_REPORT_FATAL(PoshError::POPO__CAPRO_PROTOCOL_ERROR); } } diff --git a/iceoryx_posh/source/popo/ports/subscriber_port_single_producer.cpp b/iceoryx_posh/source/popo/ports/subscriber_port_single_producer.cpp index ef3c094ff7..5611e1dbe8 100644 --- a/iceoryx_posh/source/popo/ports/subscriber_port_single_producer.cpp +++ b/iceoryx_posh/source/popo/ports/subscriber_port_single_producer.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/ports/subscriber_port_single_producer.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -99,7 +100,7 @@ optional SubscriberPortSingleProducer::dispatchCaProMessage } else { - errorHandler(PoshError::POPO__CAPRO_PROTOCOL_ERROR, ErrorLevel::MODERATE); + IOX_REPORT_FATAL(PoshError::POPO__CAPRO_PROTOCOL_ERROR); } return nullopt_t(); @@ -116,7 +117,7 @@ optional SubscriberPortSingleProducer::dispatchCaProMessage } else { - errorHandler(PoshError::POPO__CAPRO_PROTOCOL_ERROR, ErrorLevel::MODERATE); + IOX_REPORT_FATAL(PoshError::POPO__CAPRO_PROTOCOL_ERROR); } return nullopt_t(); @@ -130,8 +131,7 @@ optional SubscriberPortSingleProducer::dispatchCaProMessage } else { - errorHandler(PoshError::POPO__CAPRO_PROTOCOL_ERROR, ErrorLevel::SEVERE); - return nullopt_t(); + IOX_REPORT_FATAL(PoshError::POPO__CAPRO_PROTOCOL_ERROR); } } diff --git a/iceoryx_posh/source/error_handling/error_handling.cpp b/iceoryx_posh/source/posh_error_reporting.cpp similarity index 61% rename from iceoryx_posh/source/error_handling/error_handling.cpp rename to iceoryx_posh/source/posh_error_reporting.cpp index dd32759fd2..a7e3855085 100644 --- a/iceoryx_posh/source/error_handling/error_handling.cpp +++ b/iceoryx_posh/source/posh_error_reporting.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -22,6 +22,15 @@ const char* POSH_ERROR_NAMES[] = {POSH_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; const char* asStringLiteral(const PoshError error) noexcept { - return POSH_ERROR_NAMES[errorToStringIndex(error)]; + auto end = + static_cast::type>(PoshError::DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER); + auto index = static_cast::type>(error); + if (index >= end) + { + return "Unknown Error Code!"; + } + // NOLINTJUSTIFICATION Bounds are checked and access is safe + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) + return POSH_ERROR_NAMES[index]; } } // namespace iox diff --git a/iceoryx_posh/source/roudi/iceoryx_roudi_components.cpp b/iceoryx_posh/source/roudi/iceoryx_roudi_components.cpp index 0e42e1e773..cc475a6a5d 100644 --- a/iceoryx_posh/source/roudi/iceoryx_roudi_components.cpp +++ b/iceoryx_posh/source/roudi/iceoryx_roudi_components.cpp @@ -15,6 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/roudi/iceoryx_roudi_components.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/internal/runtime/ipc_interface_base.hpp" namespace iox @@ -32,7 +33,7 @@ IceOryxRouDiComponents::IceOryxRouDiComponents(const RouDiConfig_t& roudiConfig) rouDiMemoryManager.createAndAnnounceMemory().or_else([](RouDiMemoryManagerError error) { IOX_LOG(FATAL, "Could not create SharedMemory! Error: " << error); - errorHandler(PoshError::ROUDI_COMPONENTS__SHARED_MEMORY_UNAVAILABLE, iox::ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::ROUDI_COMPONENTS__SHARED_MEMORY_UNAVAILABLE); }); return &rouDiMemoryManager; }()) diff --git a/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp b/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp index 5ffd1cc9d3..320a3c6a61 100644 --- a/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp +++ b/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp @@ -17,6 +17,7 @@ #include "iceoryx_posh/roudi/memory/default_roudi_memory.hpp" #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/internal/roudi/service_registry.hpp" #include "iceoryx_posh/roudi/introspection_types.hpp" #include "iox/memory.hpp" @@ -32,18 +33,16 @@ DefaultRouDiMemory::DefaultRouDiMemory(const RouDiConfig_t& roudiConfig) noexcep , m_managementShm(SHM_NAME, AccessMode::READ_WRITE, OpenMode::PURGE_AND_CREATE) { m_managementShm.addMemoryBlock(&m_introspectionMemPoolBlock).or_else([](auto) { - errorHandler(PoshError::ROUDI__DEFAULT_ROUDI_MEMORY_FAILED_TO_ADD_INTROSPECTION_MEMORY_BLOCK, - ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::ROUDI__DEFAULT_ROUDI_MEMORY_FAILED_TO_ADD_INTROSPECTION_MEMORY_BLOCK); }); m_managementShm.addMemoryBlock(&m_discoveryMemPoolBlock).or_else([](auto) { - errorHandler(PoshError::ROUDI__DEFAULT_ROUDI_MEMORY_FAILED_TO_ADD_DISCOVERY_MEMORY_BLOCK, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::ROUDI__DEFAULT_ROUDI_MEMORY_FAILED_TO_ADD_DISCOVERY_MEMORY_BLOCK); }); m_managementShm.addMemoryBlock(&heartbeatPoolBlock).or_else([](auto) { - errorHandler(PoshError::ROUDI__DEFAULT_ROUDI_MEMORY_FAILED_TO_ADD_HEARTBEAT_MEMORY_BLOCK, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::ROUDI__DEFAULT_ROUDI_MEMORY_FAILED_TO_ADD_HEARTBEAT_MEMORY_BLOCK); }); m_managementShm.addMemoryBlock(&m_segmentManagerBlock).or_else([](auto) { - errorHandler(PoshError::ROUDI__DEFAULT_ROUDI_MEMORY_FAILED_TO_ADD_SEGMENT_MANAGER_MEMORY_BLOCK, - ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::ROUDI__DEFAULT_ROUDI_MEMORY_FAILED_TO_ADD_SEGMENT_MANAGER_MEMORY_BLOCK); }); } diff --git a/iceoryx_posh/source/roudi/memory/iceoryx_roudi_memory_manager.cpp b/iceoryx_posh/source/roudi/memory/iceoryx_roudi_memory_manager.cpp index 263885eceb..6b81e2b1bb 100644 --- a/iceoryx_posh/source/roudi/memory/iceoryx_roudi_memory_manager.cpp +++ b/iceoryx_posh/source/roudi/memory/iceoryx_roudi_memory_manager.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" namespace iox { @@ -25,10 +26,10 @@ IceOryxRouDiMemoryManager::IceOryxRouDiMemoryManager(const RouDiConfig_t& roudiC : m_defaultMemory(roudiConfig) { m_defaultMemory.m_managementShm.addMemoryBlock(&m_portPoolBlock).or_else([](auto) { - errorHandler(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__FAILED_TO_ADD_PORTPOOL_MEMORY_BLOCK, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__FAILED_TO_ADD_PORTPOOL_MEMORY_BLOCK); }); m_memoryManager.addMemoryProvider(&m_defaultMemory.m_managementShm).or_else([](auto) { - errorHandler(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__FAILED_TO_ADD_MANAGEMENT_MEMORY_BLOCK, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__FAILED_TO_ADD_MANAGEMENT_MEMORY_BLOCK); }); } diff --git a/iceoryx_posh/source/roudi/memory/memory_provider.cpp b/iceoryx_posh/source/roudi/memory/memory_provider.cpp index 2c7123efd6..15342fa532 100644 --- a/iceoryx_posh/source/roudi/memory/memory_provider.cpp +++ b/iceoryx_posh/source/roudi/memory/memory_provider.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/roudi/memory/memory_provider.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/roudi/memory/memory_block.hpp" #include "iox/bump_allocator.hpp" #include "iox/logging.hpp" @@ -87,7 +87,7 @@ expected MemoryProvider::create() noexcept if (!maybeSegmentId.has_value()) { - errorHandler(PoshError::MEMORY_PROVIDER__INSUFFICIENT_SEGMENT_IDS); + IOX_REPORT_FATAL(PoshError::MEMORY_PROVIDER__INSUFFICIENT_SEGMENT_IDS); } m_segmentId = maybeSegmentId.value(); diff --git a/iceoryx_posh/source/roudi/port_manager.cpp b/iceoryx_posh/source/roudi/port_manager.cpp index f2751be78e..8f666a14ed 100644 --- a/iceoryx_posh/source/roudi/port_manager.cpp +++ b/iceoryx_posh/source/roudi/port_manager.cpp @@ -16,8 +16,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/roudi/port_manager.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/publisher_options.hpp" #include "iceoryx_posh/roudi/introspection_types.hpp" #include "iox/logging.hpp" @@ -56,7 +56,7 @@ PortManager::PortManager(RouDiMemoryInterface* roudiMemoryInterface) noexcept if (!maybePortPool.has_value()) { IOX_LOG(FATAL, "Could not get PortPool!"); - errorHandler(PoshError::PORT_MANAGER__PORT_POOL_UNAVAILABLE, iox::ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::PORT_MANAGER__PORT_POOL_UNAVAILABLE); } m_portPool = maybePortPool.value(); @@ -64,7 +64,7 @@ PortManager::PortManager(RouDiMemoryInterface* roudiMemoryInterface) noexcept if (!maybeDiscoveryMemoryManager.has_value()) { IOX_LOG(FATAL, "Could not get MemoryManager for discovery!"); - errorHandler(PoshError::PORT_MANAGER__DISCOVERY_MEMORY_MANAGER_UNAVAILABLE, iox::ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::PORT_MANAGER__DISCOVERY_MEMORY_MANAGER_UNAVAILABLE); } auto& discoveryMemoryManager = maybeDiscoveryMemoryManager.value(); @@ -87,7 +87,7 @@ PortManager::PortManager(RouDiMemoryInterface* roudiMemoryInterface) noexcept if (!maybeIntrospectionMemoryManager.has_value()) { IOX_LOG(FATAL, "Could not get MemoryManager for introspection!"); - errorHandler(PoshError::PORT_MANAGER__INTROSPECTION_MEMORY_MANAGER_UNAVAILABLE, iox::ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::PORT_MANAGER__INTROSPECTION_MEMORY_MANAGER_UNAVAILABLE); } auto& introspectionMemoryManager = maybeIntrospectionMemoryManager.value(); @@ -173,8 +173,7 @@ void PortManager::doDiscoveryForPublisherPort(PublisherPortRouDiType& publisherP << publisherPort.getRuntimeName() << "' and with service description '" << publisherPort.getCaProServiceDescription() << "'! Cannot handle CaProMessageType '" << caproMessage.m_type << "'"); - errorHandler(PoshError::PORT_MANAGER__HANDLE_PUBLISHER_PORTS_INVALID_CAPRO_MESSAGE, - iox::ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_MANAGER__HANDLE_PUBLISHER_PORTS_INVALID_CAPRO_MESSAGE, iox::er::RUNTIME_ERROR); return; } @@ -231,8 +230,7 @@ void PortManager::doDiscoveryForSubscriberPort(SubscriberPortType& subscriberPor << subscriberPort.getRuntimeName() << "' and with service description '" << subscriberPort.getCaProServiceDescription() << "'! Cannot handle CaProMessageType '" << caproMessage.m_type << "'"); - errorHandler(PoshError::PORT_MANAGER__HANDLE_SUBSCRIBER_PORTS_INVALID_CAPRO_MESSAGE, - iox::ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_MANAGER__HANDLE_SUBSCRIBER_PORTS_INVALID_CAPRO_MESSAGE, iox::er::RUNTIME_ERROR); return; } }); @@ -314,7 +312,7 @@ void PortManager::doDiscoveryForClientPort(popo::ClientPortRouDi& clientPort) no << clientPort.getRuntimeName() << "' and with service description '" << clientPort.getCaProServiceDescription() << "'! Cannot handle CaProMessageType '" << caproMessage.m_type << "'"); - errorHandler(PoshError::PORT_MANAGER__HANDLE_CLIENT_PORTS_INVALID_CAPRO_MESSAGE, iox::ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_MANAGER__HANDLE_CLIENT_PORTS_INVALID_CAPRO_MESSAGE, iox::er::RUNTIME_ERROR); return; } }); @@ -404,7 +402,7 @@ void PortManager::doDiscoveryForServerPort(popo::ServerPortRouDi& serverPort) no << serverPort.getRuntimeName() << "' and with service description '" << serverPort.getCaProServiceDescription() << "'! Cannot handle CaProMessageType '" << caproMessage.m_type << "'"); - errorHandler(PoshError::PORT_MANAGER__HANDLE_SERVER_PORTS_INVALID_CAPRO_MESSAGE, iox::ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_MANAGER__HANDLE_SERVER_PORTS_INVALID_CAPRO_MESSAGE, iox::er::RUNTIME_ERROR); return; } @@ -954,7 +952,7 @@ PortManager::acquirePublisherPortDataWithoutDiscovery(const capro::ServiceDescri << usedByProcess << "' with service '" << service.operator Serialization().toString() << "'."); })) { - errorHandler(PoshError::POSH__PORT_MANAGER_PUBLISHERPORT_NOT_UNIQUE, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__PORT_MANAGER_PUBLISHERPORT_NOT_UNIQUE, iox::er::RUNTIME_ERROR); return err(PortPoolError::UNIQUE_PUBLISHER_PORT_ALREADY_EXISTS); } @@ -964,7 +962,7 @@ PortManager::acquirePublisherPortDataWithoutDiscovery(const capro::ServiceDescri } else if (isInternal(service)) { - errorHandler(PoshError::POSH__PORT_MANAGER_INTERNAL_SERVICE_DESCRIPTION_IS_FORBIDDEN, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__PORT_MANAGER_INTERNAL_SERVICE_DESCRIPTION_IS_FORBIDDEN, iox::er::RUNTIME_ERROR); return err(PortPoolError::INTERNAL_SERVICE_DESCRIPTION_IS_FORBIDDEN); } @@ -993,7 +991,7 @@ PortManager::acquireInternalPublisherPortData(const capro::ServiceDescription& s service, publisherOptions, IPC_CHANNEL_ROUDI_NAME, payloadDataSegmentMemoryManager, PortConfigInfo()) .or_else([&service](auto&) { IOX_LOG(FATAL, "Could not create PublisherPort for internal service " << service); - errorHandler(PoshError::PORT_MANAGER__NO_PUBLISHER_PORT_FOR_INTERNAL_SERVICE, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::PORT_MANAGER__NO_PUBLISHER_PORT_FOR_INTERNAL_SERVICE); }) .and_then([&](auto publisherPortData) { // now the port to send registry information exists and can be used to publish service registry changes @@ -1012,7 +1010,7 @@ PublisherPortRouDiType::MemberType_t* PortManager::acquireInternalPublisherPortD service, publisherOptions, IPC_CHANNEL_ROUDI_NAME, payloadDataSegmentMemoryManager, PortConfigInfo()) .or_else([&service](auto&) { IOX_LOG(FATAL, "Could not create PublisherPort for internal service " << service); - errorHandler(PoshError::PORT_MANAGER__NO_PUBLISHER_PORT_FOR_INTERNAL_SERVICE, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::PORT_MANAGER__NO_PUBLISHER_PORT_FOR_INTERNAL_SERVICE); }) .value(); } @@ -1088,7 +1086,7 @@ PortManager::acquireServerPortData(const capro::ServiceDescription& service, << "' violates the communication policy by requesting a ServerPort which is already used by '" << currentPort->m_runtimeName << "' with service '" << service.operator Serialization().toString() << "'."); - errorHandler(PoshError::POSH__PORT_MANAGER_SERVERPORT_NOT_UNIQUE, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__PORT_MANAGER_SERVERPORT_NOT_UNIQUE, iox::er::RUNTIME_ERROR); return err(PortPoolError::UNIQUE_SERVER_PORT_ALREADY_EXISTS); } } @@ -1159,7 +1157,7 @@ void PortManager::addPublisherToServiceRegistry(const capro::ServiceDescription& { m_serviceRegistry.addPublisher(service).or_else([&](auto&) { IOX_LOG(WARN, "Could not add publisher with service description '" << service << "' to service registry!"); - errorHandler(PoshError::POSH__PORT_MANAGER_COULD_NOT_ADD_SERVICE_TO_REGISTRY, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__PORT_MANAGER_COULD_NOT_ADD_SERVICE_TO_REGISTRY, iox::er::RUNTIME_ERROR); }); } @@ -1172,7 +1170,7 @@ void PortManager::addServerToServiceRegistry(const capro::ServiceDescription& se { m_serviceRegistry.addServer(service).or_else([&](auto&) { IOX_LOG(WARN, "Could not add server with service description '" << service << "' to service registry!"); - errorHandler(PoshError::POSH__PORT_MANAGER_COULD_NOT_ADD_SERVICE_TO_REGISTRY, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__PORT_MANAGER_COULD_NOT_ADD_SERVICE_TO_REGISTRY, iox::er::RUNTIME_ERROR); }); } diff --git a/iceoryx_posh/source/roudi/port_pool.cpp b/iceoryx_posh/source/roudi/port_pool.cpp index 8aad8ac507..ad3e87f04d 100644 --- a/iceoryx_posh/source/roudi/port_pool.cpp +++ b/iceoryx_posh/source/roudi/port_pool.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/roudi/port_pool.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/internal/roudi/port_pool_data.hpp" namespace iox @@ -49,7 +50,7 @@ expected PortPool::addInterfacePort(con if (interfacePortData == getInterfacePortDataList().end()) { IOX_LOG(WARN, "Out of interface ports! Requested by runtime '" << runtimeName << "'"); - errorHandler(PoshError::PORT_POOL__INTERFACELIST_OVERFLOW, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_POOL__INTERFACELIST_OVERFLOW, iox::er::RUNTIME_ERROR); return err(PortPoolError::INTERFACE_PORT_LIST_FULL); } return ok(interfacePortData.to_ptr()); @@ -64,7 +65,7 @@ expected PortPool::addNodeData(const RuntimeN { IOX_LOG(WARN, "Out of node data! Requested by runtime '" << runtimeName << "' and node name '" << nodeName << "'"); - errorHandler(PoshError::PORT_POOL__NODELIST_OVERFLOW, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_POOL__NODELIST_OVERFLOW, iox::er::RUNTIME_ERROR); return err(PortPoolError::NODE_DATA_LIST_FULL); } return ok(nodeData.to_ptr()); @@ -77,7 +78,7 @@ PortPool::addConditionVariableData(const RuntimeName_t& runtimeName) noexcept if (conditionVariableData == getConditionVariableDataList().end()) { IOX_LOG(WARN, "Out of condition variables! Requested by runtime '" << runtimeName << "'"); - errorHandler(PoshError::PORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW, iox::er::RUNTIME_ERROR); return err(PortPoolError::CONDITION_VARIABLE_LIST_FULL); } return ok(conditionVariableData.to_ptr()); @@ -122,7 +123,7 @@ PortPool::addPublisherPort(const capro::ServiceDescription& serviceDescription, IOX_LOG(WARN, "Out of publisher ports! Requested by runtime '" << runtimeName << "' and with service description '" << serviceDescription << "'"); - errorHandler(PoshError::PORT_POOL__PUBLISHERLIST_OVERFLOW, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_POOL__PUBLISHERLIST_OVERFLOW, iox::er::RUNTIME_ERROR); return err(PortPoolError::PUBLISHER_PORT_LIST_FULL); } return ok(publisherPortData.to_ptr()); @@ -141,7 +142,7 @@ PortPool::addSubscriberPort(const capro::ServiceDescription& serviceDescription, IOX_LOG(WARN, "Out of subscriber ports! Requested by runtime '" << runtimeName << "' and with service description '" << serviceDescription << "'"); - errorHandler(PoshError::PORT_POOL__SUBSCRIBERLIST_OVERFLOW, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_POOL__SUBSCRIBERLIST_OVERFLOW, iox::er::RUNTIME_ERROR); return err(PortPoolError::SUBSCRIBER_PORT_LIST_FULL); } return ok(subscriberPortData); @@ -171,7 +172,7 @@ PortPool::addClientPort(const capro::ServiceDescription& serviceDescription, IOX_LOG(WARN, "Out of client ports! Requested by runtime '" << runtimeName << "' and with service description '" << serviceDescription << "'"); - errorHandler(PoshError::PORT_POOL__CLIENTLIST_OVERFLOW, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_POOL__CLIENTLIST_OVERFLOW, iox::er::RUNTIME_ERROR); return err(PortPoolError::CLIENT_PORT_LIST_FULL); } return ok(clientPortData.to_ptr()); @@ -191,7 +192,7 @@ PortPool::addServerPort(const capro::ServiceDescription& serviceDescription, IOX_LOG(WARN, "Out of server ports! Requested by runtime '" << runtimeName << "' and with service description '" << serviceDescription << "'"); - errorHandler(PoshError::PORT_POOL__SERVERLIST_OVERFLOW, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::PORT_POOL__SERVERLIST_OVERFLOW, iox::er::RUNTIME_ERROR); return err(PortPoolError::SERVER_PORT_LIST_FULL); } return ok(serverPortData.to_ptr()); diff --git a/iceoryx_posh/source/roudi/process.cpp b/iceoryx_posh/source/roudi/process.cpp index b3555a64d1..326adea9c6 100644 --- a/iceoryx_posh/source/roudi/process.cpp +++ b/iceoryx_posh/source/roudi/process.cpp @@ -18,6 +18,7 @@ #include "iceoryx_posh/internal/roudi/process.hpp" #include "iceoryx_platform/types.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/logging.hpp" using namespace iox::units::duration_literals; @@ -54,7 +55,7 @@ void Process::sendViaIpcChannel(const runtime::IpcMessage& data) noexcept if (!sendSuccess) { IOX_LOG(WARN, "Process cannot send message over communication channel"); - errorHandler(PoshError::POSH__ROUDI_PROCESS_SEND_VIA_IPC_CHANNEL_FAILED, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__ROUDI_PROCESS_SEND_VIA_IPC_CHANNEL_FAILED, iox::er::RUNTIME_ERROR); } } diff --git a/iceoryx_posh/source/roudi/process_manager.cpp b/iceoryx_posh/source/roudi/process_manager.cpp index 3b7d121cd6..86c58d9695 100644 --- a/iceoryx_posh/source/roudi/process_manager.cpp +++ b/iceoryx_posh/source/roudi/process_manager.cpp @@ -21,6 +21,7 @@ #include "iceoryx_platform/types.hpp" #include "iceoryx_platform/wait.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/detail/convert.hpp" #include "iox/logging.hpp" #include "iox/posix_call.hpp" @@ -93,7 +94,7 @@ ProcessManager::ProcessManager(RouDiMemoryInterface& roudiMemoryInterface, if (fatalError) { /// @todo iox-#539 Use separate error enums once RouDi is more modular - errorHandler(PoshError::ROUDI__PRECONDITIONS_FOR_PROCESS_MANAGER_NOT_FULFILLED, ErrorLevel::FATAL); + IOX_REPORT_FATAL(PoshError::ROUDI__PRECONDITIONS_FOR_PROCESS_MANAGER_NOT_FULFILLED); } } @@ -204,7 +205,7 @@ void ProcessManager::evaluateKillError(const Process& process, << (shutdownPolicy == ShutdownPolicy::SIG_KILL ? "SIGKILL" : "SIGTERM") << ", because the command failed with the following error: " << errorString << " See manpage for kill(2) or type 'man 2 kill' in console for more information"); - errorHandler(PoshError::POSH__ROUDI_PROCESS_SHUTDOWN_FAILED, ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POSH__ROUDI_PROCESS_SHUTDOWN_FAILED, iox::er::RUNTIME_ERROR); } else { @@ -212,7 +213,7 @@ void ProcessManager::evaluateKillError(const Process& process, "Process ID " << process.getPid() << " named '" << process.getName() << "' could not be killed with" << (shutdownPolicy == ShutdownPolicy::SIG_KILL ? "SIGKILL" : "SIGTERM") << " for unknown reason: '" << errorString << "'"); - errorHandler(PoshError::POSH__ROUDI_PROCESS_SHUTDOWN_FAILED, ErrorLevel::SEVERE); + IOX_REPORT(PoshError::POSH__ROUDI_PROCESS_SHUTDOWN_FAILED, iox::er::RUNTIME_ERROR); } } diff --git a/iceoryx_posh/source/runtime/ipc_interface_creator.cpp b/iceoryx_posh/source/runtime/ipc_interface_creator.cpp index 4b7c4fbde1..8cfa1c8980 100644 --- a/iceoryx_posh/source/runtime/ipc_interface_creator.cpp +++ b/iceoryx_posh/source/runtime/ipc_interface_creator.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/runtime/ipc_interface_creator.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/filesystem.hpp" namespace iox @@ -27,27 +27,26 @@ IpcInterfaceCreator::IpcInterfaceCreator(const RuntimeName_t& runtimeName, const uint64_t maxMessages, const uint64_t messageSize) noexcept : IpcInterfaceBase(runtimeName, maxMessages, messageSize) - , m_fileLock(std::move( - FileLockBuilder() - .name(runtimeName) - .permission(iox::perms::owner_read | iox::perms::owner_write) - .create() - .or_else([&runtimeName](auto& error) { - if (error == FileLockError::LOCKED_BY_OTHER_PROCESS) - { - IOX_LOG(FATAL, - "An application with the name " << runtimeName - << " is still running. Using the " - "same name twice is not supported."); - errorHandler(PoshError::IPC_INTERFACE__APP_WITH_SAME_NAME_STILL_RUNNING, iox::ErrorLevel::FATAL); - } - else - { - IOX_LOG(FATAL, "Error occurred while acquiring file lock named " << runtimeName); - errorHandler(PoshError::IPC_INTERFACE__COULD_NOT_ACQUIRE_FILE_LOCK, iox::ErrorLevel::FATAL); - } - }) - .value())) + , m_fileLock(std::move(FileLockBuilder() + .name(runtimeName) + .permission(iox::perms::owner_read | iox::perms::owner_write) + .create() + .or_else([&runtimeName](auto& error) { + if (error == FileLockError::LOCKED_BY_OTHER_PROCESS) + { + IOX_LOG(FATAL, + "An application with the name " << runtimeName + << " is still running. Using the " + "same name twice is not supported."); + IOX_REPORT_FATAL(PoshError::IPC_INTERFACE__APP_WITH_SAME_NAME_STILL_RUNNING); + } + else + { + IOX_LOG(FATAL, "Error occurred while acquiring file lock named " << runtimeName); + IOX_REPORT_FATAL(PoshError::IPC_INTERFACE__COULD_NOT_ACQUIRE_FILE_LOCK); + } + }) + .value())) { // check if the IPC channel is still there (e.g. because of no proper termination // of the process) diff --git a/iceoryx_posh/source/runtime/ipc_runtime_interface.cpp b/iceoryx_posh/source/runtime/ipc_runtime_interface.cpp index df36b89f6c..b39aafd5aa 100644 --- a/iceoryx_posh/source/runtime/ipc_runtime_interface.cpp +++ b/iceoryx_posh/source/runtime/ipc_runtime_interface.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/runtime/ipc_runtime_interface.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/version/version_info.hpp" #include "iox/detail/convert.hpp" #include "iox/into.hpp" @@ -38,7 +38,7 @@ IpcRuntimeInterface::IpcRuntimeInterface(const RuntimeName_t& roudiName, m_AppIpcInterface.emplace(runtimeName); if (!m_AppIpcInterface->isInitialized()) { - errorHandler(PoshError::IPC_INTERFACE__UNABLE_TO_CREATE_APPLICATION_CHANNEL); + IOX_REPORT_FATAL(PoshError::IPC_INTERFACE__UNABLE_TO_CREATE_APPLICATION_CHANNEL); return; } @@ -131,13 +131,13 @@ IpcRuntimeInterface::IpcRuntimeInterface(const RuntimeName_t& roudiName, { case RegState::WAIT_FOR_ROUDI: IOX_LOG(FATAL, "Timeout registering at RouDi. Is RouDi running?"); - errorHandler(PoshError::IPC_INTERFACE__REG_ROUDI_NOT_AVAILABLE); + IOX_REPORT_FATAL(PoshError::IPC_INTERFACE__REG_ROUDI_NOT_AVAILABLE); break; case RegState::SEND_REGISTER_REQUEST: - errorHandler(PoshError::IPC_INTERFACE__REG_UNABLE_TO_WRITE_TO_ROUDI_CHANNEL); + IOX_REPORT_FATAL(PoshError::IPC_INTERFACE__REG_UNABLE_TO_WRITE_TO_ROUDI_CHANNEL); break; case RegState::WAIT_FOR_REGISTER_ACK: - errorHandler(PoshError::IPC_INTERFACE__REG_ACK_NO_RESPONSE); + IOX_REPORT_FATAL(PoshError::IPC_INTERFACE__REG_ACK_NO_RESPONSE); break; case RegState::FINISHED: // nothing to do, move along @@ -231,7 +231,7 @@ IpcRuntimeInterface::RegAckResult IpcRuntimeInterface::waitForRegAck(int64_t tra constexpr uint32_t REGISTER_ACK_PARAMETERS = 6U; if (receiveBuffer.getNumberOfElements() != REGISTER_ACK_PARAMETERS) { - errorHandler(PoshError::IPC_INTERFACE__REG_ACK_INVALIG_NUMBER_OF_PARAMS); + IOX_REPORT_FATAL(PoshError::IPC_INTERFACE__REG_ACK_INVALIG_NUMBER_OF_PARAMS); } // read out the shared memory base address and save it diff --git a/iceoryx_posh/source/runtime/posh_runtime.cpp b/iceoryx_posh/source/runtime/posh_runtime.cpp index 2f09cf4e6b..877b92bd0a 100644 --- a/iceoryx_posh/source/runtime/posh_runtime.cpp +++ b/iceoryx_posh/source/runtime/posh_runtime.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/internal/runtime/posh_runtime_impl.hpp" #include "iox/detail/system_configuration.hpp" #include "iox/filesystem.hpp" @@ -71,7 +72,7 @@ void PoshRuntime::setRuntimeFactory(const factory_t& factory) noexcept else { IOX_LOG(FATAL, "Cannot set runtime factory. Passed factory must not be empty!"); - errorHandler(PoshError::POSH__RUNTIME_FACTORY_IS_NOT_SET); + IOX_REPORT_FATAL(PoshError::POSH__RUNTIME_FACTORY_IS_NOT_SET); } } @@ -131,14 +132,14 @@ const RuntimeName_t& PoshRuntime::verifyInstanceName(optional& service, default: { IOX_LOG(WARN, "ServiceDiscovery could not perform search due to unknown MessagingPattern!"); - errorHandler(PoshError::POSH__SERVICE_DISCOVERY_UNKNOWN_MESSAGE_PATTERN_PROVIDED, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__SERVICE_DISCOVERY_UNKNOWN_MESSAGE_PATTERN_PROVIDED, iox::er::RUNTIME_ERROR); } } } @@ -86,7 +87,7 @@ void ServiceDiscovery::enableEvent(popo::TriggerHandle&& triggerHandle, const Se default: { IOX_LOG(WARN, "ServiceDiscovery::enableEvent() called with unknown event!"); - errorHandler(PoshError::POSH__SERVICE_DISCOVERY_UNKNOWN_EVENT_PROVIDED, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__SERVICE_DISCOVERY_UNKNOWN_EVENT_PROVIDED, iox::er::RUNTIME_ERROR); } } } @@ -103,7 +104,7 @@ void ServiceDiscovery::disableEvent(const ServiceDiscoveryEvent event) noexcept default: { IOX_LOG(WARN, "ServiceDiscovery::disableEvent() called with unknown event!"); - errorHandler(PoshError::POSH__SERVICE_DISCOVERY_UNKNOWN_EVENT_PROVIDED, ErrorLevel::MODERATE); + IOX_REPORT(PoshError::POSH__SERVICE_DISCOVERY_UNKNOWN_EVENT_PROVIDED, iox::er::RUNTIME_ERROR); } } } diff --git a/iceoryx_posh/source/runtime/shared_memory_user.cpp b/iceoryx_posh/source/runtime/shared_memory_user.cpp index 4f3610ddc1..82bc8c6c06 100644 --- a/iceoryx_posh/source/runtime/shared_memory_user.cpp +++ b/iceoryx_posh/source/runtime/shared_memory_user.cpp @@ -16,8 +16,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/runtime/shared_memory_user.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/mepoo/segment_manager.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/logging.hpp" #include "iox/posix_user.hpp" @@ -46,7 +46,7 @@ SharedMemoryUser::SharedMemoryUser(const size_t topicSize, if (!registeredSuccessfully) { - errorHandler(PoshError::POSH__SHM_APP_COULD_NOT_REGISTER_PTR_WITH_GIVEN_SEGMENT_ID); + IOX_REPORT_FATAL(PoshError::POSH__SHM_APP_COULD_NOT_REGISTER_PTR_WITH_GIVEN_SEGMENT_ID); } IOX_LOG(DEBUG, @@ -59,7 +59,7 @@ SharedMemoryUser::SharedMemoryUser(const size_t topicSize, m_shmObject.emplace(std::move(sharedMemoryObject)); }) - .or_else([](auto&) { errorHandler(PoshError::POSH__SHM_APP_MAPP_ERR); }); + .or_else([](auto&) { IOX_REPORT_FATAL(PoshError::POSH__SHM_APP_MAPP_ERR); }); } void SharedMemoryUser::openDataSegments(const uint64_t segmentId, @@ -82,7 +82,7 @@ void SharedMemoryUser::openDataSegments(const uint64_t segmentId, .and_then([this, &segment](auto& sharedMemoryObject) { if (static_cast(m_dataShmObjects.size()) >= MAX_SHM_SEGMENTS) { - errorHandler(PoshError::POSH__SHM_APP_SEGMENT_COUNT_OVERFLOW); + IOX_REPORT_FATAL(PoshError::POSH__SHM_APP_SEGMENT_COUNT_OVERFLOW); } auto registeredSuccessfully = UntypedRelativePointer::registerPtrWithId( @@ -92,7 +92,7 @@ void SharedMemoryUser::openDataSegments(const uint64_t segmentId, if (!registeredSuccessfully) { - errorHandler(PoshError::POSH__SHM_APP_COULD_NOT_REGISTER_PTR_WITH_GIVEN_SEGMENT_ID); + IOX_REPORT_FATAL(PoshError::POSH__SHM_APP_COULD_NOT_REGISTER_PTR_WITH_GIVEN_SEGMENT_ID); } IOX_LOG(DEBUG, @@ -103,7 +103,7 @@ void SharedMemoryUser::openDataSegments(const uint64_t segmentId, m_dataShmObjects.emplace_back(std::move(sharedMemoryObject)); }) - .or_else([](auto&) { errorHandler(PoshError::POSH__SHM_APP_SEGMENT_MAPP_ERR); }); + .or_else([](auto&) { IOX_REPORT_FATAL(PoshError::POSH__SHM_APP_SEGMENT_MAPP_ERR); }); } } } // namespace runtime diff --git a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp index a5d16a2173..12cf822941 100644 --- a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp +++ b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/timing_test.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/popo/wait_set.hpp" @@ -28,12 +28,13 @@ #include "iox/optional.hpp" #include "iox/std_chrono_support.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" +#include "test.hpp" + #include #include #include -#include "test.hpp" - namespace { using namespace ::testing; @@ -394,14 +395,10 @@ TEST_F(Mepoo_IntegrationTest, WrongSampleSize) SetUp(memPoolTestContainer, testMempoolConfig, configType::CUSTOM); constexpr uint32_t SAMPLE_SIZE = 2048U; constexpr uint32_t REPETITION = 1U; - iox::optional receivedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&receivedError](const iox::PoshError error, const iox::ErrorLevel) { receivedError.emplace(error); }); EXPECT_TRUE(sendReceiveSample(REPETITION, {iox::popo::AllocationError::NO_MEMPOOLS_AVAILABLE})); - ASSERT_TRUE(receivedError.has_value()); - EXPECT_THAT(receivedError.value(), Eq(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_IS_TOO_LARGE)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_IS_TOO_LARGE); } TEST_F(Mepoo_IntegrationTest, SampleOverflow) @@ -412,9 +409,6 @@ TEST_F(Mepoo_IntegrationTest, SampleOverflow) SetUp(memPoolTestContainer, testMempoolConfig, configType::CUSTOM); constexpr uint32_t SAMPLE_SIZE_1 = 200U; constexpr uint32_t REPETITION = 1U; - iox::optional receivedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&receivedError](const iox::PoshError error, const iox::ErrorLevel) { receivedError.emplace(error); }); // make the mempool empty EXPECT_TRUE(sendReceiveSample(DEFAULT_NUMBER_OF_CHUNKS)); @@ -422,8 +416,7 @@ TEST_F(Mepoo_IntegrationTest, SampleOverflow) // trigger out of chunk error EXPECT_TRUE(sendReceiveSample(REPETITION, {iox::popo::AllocationError::RUNNING_OUT_OF_CHUNKS})); - ASSERT_TRUE(receivedError.has_value()); - ASSERT_THAT(receivedError.value(), Eq(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_POOL_IS_RUNNING_OUT_OF_CHUNKS)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_POOL_IS_RUNNING_OUT_OF_CHUNKS); } TIMING_TEST_F(Mepoo_IntegrationTest, MempoolCreationTimeDefaultConfig, Repeat(5), [&] { diff --git a/iceoryx_posh/test/moduletests/test_mepoo_config.cpp b/iceoryx_posh/test/moduletests/test_mepoo_config.cpp index 02b55bdc7f..3b1f6e9e46 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_config.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_config.cpp @@ -14,10 +14,11 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" using namespace ::testing; @@ -61,7 +62,7 @@ TEST_F(MePooConfig_Test, AddingMempoolWhenTheMemPoolConfigContainerIsFullReturns { sut.addMemPool({SIZE, CHUNK_COUNT}); } - IOX_EXPECT_FATAL_FAILURE( + IOX_EXPECT_FATAL_FAILURE( [&] { sut.addMemPool({SIZE, CHUNK_COUNT}); }, diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 87c2cf4156..4f2f2223ba 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -16,11 +16,14 @@ // 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/mocks/logger_mock.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iox/bump_allocator.hpp" + +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" namespace @@ -94,17 +97,9 @@ TEST_F(MemoryManager_test, AddingMempoolNotInTheIncreasingOrderReturnsError) mempoolconf.addMemPool({CHUNK_SIZE_128, CHUNK_COUNT}); mempoolconf.addMemPool({CHUNK_SIZE_256, CHUNK_COUNT}); mempoolconf.addMemPool({CHUNK_SIZE_64, CHUNK_COUNT}); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_EQ(errorLevel, iox::ErrorLevel::FATAL); - }); - sut->configureMemoryManager(mempoolconf, *allocator, *allocator); - - ASSERT_TRUE(detectedError.has_value()); - EXPECT_EQ(detectedError.value(), iox::PoshError::MEPOO__MEMPOOL_CONFIG_MUST_BE_ORDERED_BY_INCREASING_SIZE); + IOX_EXPECT_FATAL_FAILURE([&] { sut->configureMemoryManager(mempoolconf, *allocator, *allocator); }, + iox::PoshError::MEPOO__MEMPOOL_CONFIG_MUST_BE_ORDERED_BY_INCREASING_SIZE); } TEST_F(MemoryManager_test, WrongCallOfConfigureMemoryManagerReturnsError) @@ -114,17 +109,9 @@ TEST_F(MemoryManager_test, WrongCallOfConfigureMemoryManagerReturnsError) mempoolconf.addMemPool({CHUNK_SIZE_32, CHUNK_COUNT}); mempoolconf.addMemPool({CHUNK_SIZE_64, CHUNK_COUNT}); sut->configureMemoryManager(mempoolconf, *allocator, *allocator); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_EQ(errorLevel, iox::ErrorLevel::FATAL); - }); - - sut->configureMemoryManager(mempoolconf, *allocator, *allocator); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_EQ(detectedError.value(), iox::PoshError::MEPOO__MEMPOOL_ADDMEMPOOL_AFTER_GENERATECHUNKMANAGEMENTPOOL); + IOX_EXPECT_FATAL_FAILURE([&] { sut->configureMemoryManager(mempoolconf, *allocator, *allocator); }, + iox::PoshError::MEPOO__MEMPOOL_ADDMEMPOOL_AFTER_GENERATECHUNKMANAGEMENTPOOL); } TEST_F(MemoryManager_test, GetMempoolInfoMethodForOutOfBoundaryMempoolIndexReturnsZeroForAllMempoolAttributes) @@ -160,12 +147,6 @@ TEST_F(MemoryManager_test, GetNumberOfMemPoolsMethodReturnsTheNumberOfMemPools) TEST_F(MemoryManager_test, GetChunkMethodWithNoMemPoolInMemConfigReturnsError) { ::testing::Test::RecordProperty("TEST_ID", "dff31ea2-8ae0-4786-8c97-633af59c287d"); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); - }); constexpr uint64_t USER_PAYLOAD_SIZE{15U}; auto chunkSettingsResult = ChunkSettings::create(USER_PAYLOAD_SIZE, iox::CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT); @@ -178,8 +159,7 @@ TEST_F(MemoryManager_test, GetChunkMethodWithNoMemPoolInMemConfigReturnsError) [&](auto&) { GTEST_FAIL() << "getChunk should fail with '" << EXPECTED_ERROR << "' but did not fail"; }) .or_else([&](const auto& error) { EXPECT_EQ(error, EXPECTED_ERROR); }); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_EQ(detectedError.value(), iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_WITHOUT_MEMPOOL); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_WITHOUT_MEMPOOL); } @@ -192,13 +172,6 @@ TEST_F(MemoryManager_test, GetChunkMethodWithChunkSizeGreaterThanAvailableChunkS mempoolconf.addMemPool({CHUNK_SIZE_128, CHUNK_COUNT}); sut->configureMemoryManager(mempoolconf, *allocator, *allocator); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); - }); - constexpr uint64_t USER_PAYLOAD_SIZE{200U}; auto chunkSettingsResult = ChunkSettings::create(USER_PAYLOAD_SIZE, iox::CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT); ASSERT_FALSE(chunkSettingsResult.has_error()); @@ -210,8 +183,7 @@ TEST_F(MemoryManager_test, GetChunkMethodWithChunkSizeGreaterThanAvailableChunkS [&](auto&) { GTEST_FAIL() << "getChunk should fail with '" << EXPECTED_ERROR << "' but did not fail"; }) .or_else([&](const auto& error) { EXPECT_EQ(error, EXPECTED_ERROR); }); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_EQ(detectedError.value(), iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_IS_TOO_LARGE); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_CHUNK_IS_TOO_LARGE); } TEST_F(MemoryManager_test, GetChunkMethodWhenNoFreeChunksInMemPoolConfigReturnsError) @@ -226,21 +198,13 @@ TEST_F(MemoryManager_test, GetChunkMethodWhenNoFreeChunksInMemPoolConfigReturnsE auto& chunkSettings = chunkSettingsResult.value(); auto chunkStore = getChunksFromSut(CHUNK_COUNT, chunkSettings); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_EQ(errorLevel, iox::ErrorLevel::MODERATE); - }); - constexpr auto EXPECTED_ERROR{iox::mepoo::MemoryManager::Error::MEMPOOL_OUT_OF_CHUNKS}; sut->getChunk(chunkSettings) .and_then( [&](auto&) { GTEST_FAIL() << "getChunk should fail with '" << EXPECTED_ERROR << "' but did not fail"; }) .or_else([&](const auto& error) { EXPECT_EQ(error, EXPECTED_ERROR); }); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_EQ(detectedError.value(), iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_POOL_IS_RUNNING_OUT_OF_CHUNKS); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_POOL_IS_RUNNING_OUT_OF_CHUNKS); } TEST_F(MemoryManager_test, VerifyGetChunkMethodWhenTheRequestedChunkIsAvailableInMemPoolConfig) @@ -476,8 +440,8 @@ TEST_F(MemoryManager_test, addMemPoolWithChunkCountZeroShouldFail) ::testing::Test::RecordProperty("TEST_ID", "be653b65-a2d1-42eb-98b5-d161c6ba7c08"); mempoolconf.addMemPool({32, 0}); - IOX_EXPECT_FATAL_FAILURE([&] { sut->configureMemoryManager(mempoolconf, *allocator, *allocator); }, - iox::HoofsError::EXPECTS_ENSURES_FAILED); + IOX_EXPECT_FATAL_FAILURE([&] { sut->configureMemoryManager(mempoolconf, *allocator, *allocator); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST(MemoryManagerEnumString_test, asStringLiteralConvertsEnumValuesToStrings) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp index 07cf283957..4b6d0d7091 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp @@ -17,10 +17,11 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/error_handling/error_handling.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/bump_allocator.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" namespace @@ -166,18 +167,9 @@ TEST_F(MemPool_test, MempoolCtorWhenChunkSizeIsNotAMultipleOfAlignmentReturnErro iox::BumpAllocator allocator{memory, 100U}; constexpr uint64_t NOT_ALLIGNED_CHUNKED_SIZE{33U}; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::FATAL)); - }); - - iox::mepoo::MemPool sut(NOT_ALLIGNED_CHUNKED_SIZE, NUMBER_OF_CHUNKS, allocator, allocator); - - ASSERT_TRUE(detectedError.has_value()); - EXPECT_THAT(detectedError.value(), - Eq(iox::PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT)); + IOX_EXPECT_FATAL_FAILURE( + [&] { iox::mepoo::MemPool sut(NOT_ALLIGNED_CHUNKED_SIZE, NUMBER_OF_CHUNKS, allocator, allocator); }, + iox::PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT); } TEST_F(MemPool_test, MempoolCtorWhenChunkSizeIsSmallerThanChunkMemoryAlignmentGetsTerminated) @@ -275,17 +267,8 @@ TEST_F(MemPool_test, FreeChunkMethodWhenSameChunkIsTriedToFreeTwiceReturnsError) constexpr uint32_t INDEX{0U}; chunks.push_back(reinterpret_cast(sut.getChunk())); sut.freeChunk(chunks[INDEX]); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::FATAL)); - }); - - sut.freeChunk(chunks[INDEX]); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__MEMPOOL_POSSIBLE_DOUBLE_FREE)); + IOX_EXPECT_FATAL_FAILURE([&] { sut.freeChunk(chunks[INDEX]); }, iox::PoshError::POSH__MEMPOOL_POSSIBLE_DOUBLE_FREE); } TEST_F(MemPool_test, FreeChunkMethodWhenTheChunkIndexIsInvalidReturnsError) @@ -314,18 +297,16 @@ TEST_F(MemPool_test, dieWhenMempoolChunkSizeIsSmallerThan32Bytes) { ::testing::Test::RecordProperty("TEST_ID", "7704246e-42b5-46fd-8827-ebac200390e1"); - IOX_EXPECT_FATAL_FAILURE( - [&] { iox::mepoo::MemPool sut(12, 10, allocator, allocator); }, - iox::PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT); + IOX_EXPECT_FATAL_FAILURE([&] { iox::mepoo::MemPool sut(12, 10, allocator, allocator); }, + iox::PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT); } TEST_F(MemPool_test, dieWhenMempoolChunkSizeIsNotPowerOf32) { ::testing::Test::RecordProperty("TEST_ID", "6a354976-235a-4a94-8af2-2bc872f705f4"); - IOX_EXPECT_FATAL_FAILURE( - [&] { iox::mepoo::MemPool sut(333, 10, allocator, allocator); }, - iox::PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT); + IOX_EXPECT_FATAL_FAILURE([&] { iox::mepoo::MemPool sut(333, 10, allocator, allocator); }, + iox::PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT); } } // namespace diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp index 736cc9bf21..3ff994f239 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp @@ -16,23 +16,25 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/test_definitions.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/mepoo/segment_manager.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/mepoo/segment_config.hpp" #include "iox/bump_allocator.hpp" #include "iox/posix_group.hpp" #include "iox/posix_shared_memory_object.hpp" #include "iox/posix_user.hpp" -#include "test.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "test.hpp" namespace { using namespace ::testing; using namespace iox; using namespace iox::mepoo; +using namespace iox::testing; class MePooSegmentMock { @@ -189,17 +191,9 @@ TEST_F(SegmentManager_test, addingMoreThanOneWriterGroupFails) SegmentConfig segmentConfig = getInvalidSegmentConfig(); SUT sut{segmentConfig, &allocator}; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::FATAL)); - }); - sut.getSegmentMappings(PosixUser("iox_roudi_test1")); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::MEPOO__USER_WITH_MORE_THAN_ONE_WRITE_SEGMENT)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::MEPOO__USER_WITH_MORE_THAN_ONE_WRITE_SEGMENT); } TEST_F(SegmentManager_test, addingMaximumNumberOfSegmentsWorks) diff --git a/iceoryx_posh/test/moduletests/test_popo_base_client.cpp b/iceoryx_posh/test/moduletests/test_popo_base_client.cpp index 625c71deaa..642b6c4f2b 100644 --- a/iceoryx_posh/test/moduletests/test_popo_base_client.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_base_client.cpp @@ -17,11 +17,13 @@ #include "iceoryx_posh/internal/popo/base_client.hpp" #include "iceoryx_posh/internal/popo/client_impl.hpp" #include "iceoryx_posh/internal/popo/untyped_client_impl.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/testing/mocks/posh_runtime_mock.hpp" #include "iox/optional.hpp" #include "mocks/client_mock.hpp" #include "mocks/trigger_handle_mock.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" namespace @@ -250,21 +252,20 @@ TYPED_TEST(BaseClient_test, EnableStateCallsUnderlyingPortAndTriggerHandle) EXPECT_CALL(this->sut->port(), setConditionVariable(Ref(condVar), TRIGGER_ID)).Times(1); - bool errorDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler< - iox::PoshError>([&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT( - error, - Eq(iox::PoshError:: - POPO__BASE_CLIENT_OVERRIDING_WITH_STATE_SINCE_HAS_RESPONSE_OR_RESPONSE_RECEIVED_ALREADY_ATTACHED)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - errorDetected = true; - }); - this->sut->enableState(std::move(triggerHandle), ClientState::HAS_RESPONSE); EXPECT_THAT(this->sut->m_trigger.triggerId, Eq(TRIGGER_ID)); - EXPECT_THAT(errorDetected, Eq(clientAttachedIndicator)); + + if (clientAttachedIndicator) + { + IOX_TESTING_EXPECT_ERROR( + iox::PoshError:: + POPO__BASE_CLIENT_OVERRIDING_WITH_STATE_SINCE_HAS_RESPONSE_OR_RESPONSE_RECEIVED_ALREADY_ATTACHED); + } + else + { + IOX_TESTING_EXPECT_OK(); + } } } @@ -311,21 +312,20 @@ TYPED_TEST(BaseClient_test, EnableEventCallsUnderlyingPortAndTriggerHandle) EXPECT_CALL(this->sut->port(), setConditionVariable(Ref(condVar), TRIGGER_ID)).Times(1); - bool errorDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler< - iox::PoshError>([&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT( - error, - Eq(iox::PoshError:: - POPO__BASE_CLIENT_OVERRIDING_WITH_EVENT_SINCE_HAS_RESPONSE_OR_RESPONSE_RECEIVED_ALREADY_ATTACHED)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - errorDetected = true; - }); - this->sut->enableEvent(std::move(triggerHandle), ClientEvent::RESPONSE_RECEIVED); EXPECT_THAT(this->sut->m_trigger.triggerId, Eq(TRIGGER_ID)); - EXPECT_THAT(errorDetected, Eq(clientAttachedIndicator)); + + if (clientAttachedIndicator) + { + IOX_TESTING_EXPECT_ERROR( + iox::PoshError:: + POPO__BASE_CLIENT_OVERRIDING_WITH_EVENT_SINCE_HAS_RESPONSE_OR_RESPONSE_RECEIVED_ALREADY_ATTACHED); + } + else + { + IOX_TESTING_EXPECT_OK(); + } } } diff --git a/iceoryx_posh/test/moduletests/test_popo_base_server.cpp b/iceoryx_posh/test/moduletests/test_popo_base_server.cpp index 97b620bb59..765fb66d34 100644 --- a/iceoryx_posh/test/moduletests/test_popo_base_server.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_base_server.cpp @@ -17,11 +17,13 @@ #include "iceoryx_posh/internal/popo/base_server.hpp" #include "iceoryx_posh/internal/popo/server_impl.hpp" #include "iceoryx_posh/internal/popo/untyped_server_impl.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/testing/mocks/posh_runtime_mock.hpp" #include "iox/optional.hpp" #include "mocks/server_mock.hpp" #include "mocks/trigger_handle_mock.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" namespace @@ -260,21 +262,20 @@ TYPED_TEST(BaseServer_test, EnableStateCallsUnderlyingPortAndTriggerHandle) EXPECT_CALL(this->sut->port(), setConditionVariable(Ref(condVar), TRIGGER_ID)).Times(1); - bool errorDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler< - iox::PoshError>([&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT( - error, - Eq(iox::PoshError:: - POPO__BASE_SERVER_OVERRIDING_WITH_STATE_SINCE_HAS_REQUEST_OR_REQUEST_RECEIVED_ALREADY_ATTACHED)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - errorDetected = true; - }); - this->sut->enableState(std::move(triggerHandle), ServerState::HAS_REQUEST); EXPECT_THAT(this->sut->m_trigger.triggerId, Eq(TRIGGER_ID)); - EXPECT_THAT(errorDetected, Eq(serverAttachedIndicator)); + + if (serverAttachedIndicator) + { + IOX_TESTING_EXPECT_ERROR( + iox::PoshError:: + POPO__BASE_SERVER_OVERRIDING_WITH_STATE_SINCE_HAS_REQUEST_OR_REQUEST_RECEIVED_ALREADY_ATTACHED); + } + else + { + IOX_TESTING_EXPECT_OK(); + } } } @@ -321,21 +322,20 @@ TYPED_TEST(BaseServer_test, EnableEventCallsUnderlyingPortAndTriggerHandle) EXPECT_CALL(this->sut->port(), setConditionVariable(Ref(condVar), TRIGGER_ID)).Times(1); - bool errorDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler< - iox::PoshError>([&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT( - error, - Eq(iox::PoshError:: - POPO__BASE_SERVER_OVERRIDING_WITH_EVENT_SINCE_HAS_REQUEST_OR_REQUEST_RECEIVED_ALREADY_ATTACHED)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - errorDetected = true; - }); - this->sut->enableEvent(std::move(triggerHandle), ServerEvent::REQUEST_RECEIVED); EXPECT_THAT(this->sut->m_trigger.triggerId, Eq(TRIGGER_ID)); - EXPECT_THAT(errorDetected, Eq(serverAttachedIndicator)); + + if (serverAttachedIndicator) + { + IOX_TESTING_EXPECT_ERROR( + iox::PoshError:: + POPO__BASE_SERVER_OVERRIDING_WITH_EVENT_SINCE_HAS_REQUEST_OR_REQUEST_RECEIVED_ALREADY_ATTACHED); + } + else + { + IOX_TESTING_EXPECT_OK(); + } } } diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index ebab2deefd..7328280065 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -17,7 +17,6 @@ #include "iceoryx_hoofs/error_handling/error_handling.hpp" #include "iceoryx_hoofs/testing/barrier.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/internal/mepoo/shared_chunk.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp" @@ -27,7 +26,11 @@ #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_pusher.hpp" #include "iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp" #include "iceoryx_posh/internal/popo/building_blocks/variant_queue.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" + +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" #include @@ -166,10 +169,6 @@ TYPED_TEST(ChunkDistributor_test, QueueOverflow) auto sutData = this->getChunkDistributorData(); typename TestFixture::ChunkDistributor_t sut(sutData.get()); - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); - for (uint32_t i = 0; i < this->MAX_NUMBER_QUEUES; ++i) { auto queueData = this->getChunkQueueData(); @@ -177,13 +176,14 @@ TYPED_TEST(ChunkDistributor_test, QueueOverflow) queueVector.push_back(queueData); } - EXPECT_FALSE(errorHandlerCalled); + IOX_TESTING_ASSERT_OK(); auto queueData = this->getChunkQueueData(); auto ret = sut.tryAddQueue(queueData.get()); EXPECT_TRUE(ret.has_error()); EXPECT_THAT(ret.error(), Eq(iox::popo::ChunkDistributorError::QUEUE_CONTAINER_OVERFLOW)); - EXPECT_TRUE(errorHandlerCalled); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CHUNK_DISTRIBUTOR_OVERFLOW_OF_QUEUE_CONTAINER); } TYPED_TEST(ChunkDistributor_test, RemovingExistingQueueWorks) diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp index f446337fe4..fc632e5aa0 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp @@ -23,9 +23,11 @@ #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_pusher.hpp" #include "iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp" #include "iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iox/bump_allocator.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" namespace @@ -191,15 +193,8 @@ TYPED_TEST(ChunkQueue_test, PopChunkWithIncompatibleChunkHeaderCallsErrorHandler this->m_pusher.push(chunk); - iox::PoshError receivedError{iox::PoshError::NO_ERROR}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - receivedError = error; - EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); - }); - EXPECT_FALSE(this->m_popper.tryPop().has_value()); - EXPECT_EQ(receivedError, iox::PoshError::POPO__CHUNK_QUEUE_POPPER_CHUNK_WITH_INCOMPATIBLE_CHUNK_HEADER_VERSION); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CHUNK_QUEUE_POPPER_CHUNK_WITH_INCOMPATIBLE_CHUNK_HEADER_VERSION); } TYPED_TEST(ChunkQueue_test, ClearOnEmpty) diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp index 4530b4594a..d9ed3d4c1d 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp @@ -16,16 +16,18 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_pusher.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_receiver_data.hpp" #include "iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" #include "iox/bump_allocator.hpp" + +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" #include @@ -199,14 +201,11 @@ TEST_F(ChunkReceiver_test, releaseInvalidChunk) EXPECT_TRUE(sharedChunk.getUserPayload() == (*maybeChunkHeader)->userPayload()); } - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); - ChunkMock myCrazyChunk; m_chunkReceiver.release(myCrazyChunk.chunkHeader()); - EXPECT_TRUE(errorHandlerCalled); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CHUNK_RECEIVER_INVALID_CHUNK_TO_RELEASE_FROM_USER); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp index 60a1b96fb5..ef51f4d52c 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp @@ -16,7 +16,6 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp" @@ -28,10 +27,13 @@ #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender_data.hpp" #include "iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp" #include "iceoryx_posh/internal/popo/ports/base_port.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" #include "iox/bump_allocator.hpp" #include "iox/scope_guard.hpp" + +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" #include @@ -241,14 +243,11 @@ TEST_F(ChunkSender_test, freeInvalidChunk) EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); - ChunkMock myCrazyChunk; m_chunkSender.release(myCrazyChunk.chunkHeader()); - EXPECT_TRUE(errorHandlerCalled); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_FREE_FROM_USER); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } @@ -417,14 +416,12 @@ TEST_F(ChunkSender_test, sendTillRunningOutOfChunks) } } - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); - auto maybeChunkHeader = m_chunkSender.tryAllocate( UniquePortId(), sizeof(DummySample), alignof(DummySample), USER_HEADER_SIZE, USER_HEADER_ALIGNMENT); EXPECT_TRUE(maybeChunkHeader.has_error()); EXPECT_THAT(maybeChunkHeader.error(), Eq(iox::popo::AllocationError::RUNNING_OUT_OF_CHUNKS)); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::MEPOO__MEMPOOL_GETCHUNK_POOL_IS_RUNNING_OUT_OF_CHUNKS); } TEST_F(ChunkSender_test, sendInvalidChunk) @@ -435,15 +432,12 @@ TEST_F(ChunkSender_test, sendInvalidChunk) EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); - ChunkMock myCrazyChunk; auto numberOfDeliveries = m_chunkSender.send(myCrazyChunk.chunkHeader()); EXPECT_THAT(numberOfDeliveries, Eq(0U)); - EXPECT_TRUE(errorHandlerCalled); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_SEND_FROM_USER); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } @@ -495,20 +489,13 @@ TEST_F(ChunkSender_test, sendToQueueWithInvalidChunkTriggersTheErrorHandler) ASSERT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - errorHandlerCalled = true; - EXPECT_THAT(error, Eq(iox::PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_SEND_FROM_USER)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - }); - ChunkMock myCrazyChunk; constexpr uint32_t EXPECTED_QUEUE_INDEX{0U}; EXPECT_FALSE( m_chunkSender.sendToQueue(myCrazyChunk.chunkHeader(), m_chunkQueueData.m_uniqueId, EXPECTED_QUEUE_INDEX)); - EXPECT_TRUE(errorHandlerCalled); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_SEND_FROM_USER); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } @@ -535,14 +522,11 @@ TEST_F(ChunkSender_test, pushInvalidChunkToHistory) EXPECT_FALSE(maybeChunkHeader.has_error()); EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); - ChunkMock myCrazyChunk; m_chunkSender.pushToHistory(myCrazyChunk.chunkHeader()); - EXPECT_TRUE(errorHandlerCalled); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_SEND_FROM_USER); + EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } diff --git a/iceoryx_posh/test/moduletests/test_popo_client_port.cpp b/iceoryx_posh/test/moduletests/test_popo_client_port.cpp index 5f6d8e7c4b..dde86788db 100644 --- a/iceoryx_posh/test/moduletests/test_popo_client_port.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_client_port.cpp @@ -21,13 +21,17 @@ #include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" namespace { using namespace ::testing; +using namespace iox::testing; using namespace iox::capro; using namespace iox::popo; @@ -259,17 +263,9 @@ TEST_F(ClientPort_test, ReleaseRequestWithNullptrCallsErrorHandler) ::testing::Test::RecordProperty("TEST_ID", "f21bc4ab-4080-4994-b862-5cb8c8738b46"); auto& sut = clientPortWithConnectOnCreate; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); - }); - sut.portUser.releaseRequest(nullptr); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_EQ(detectedError.value(), iox::PoshError::POPO__CLIENT_PORT_INVALID_REQUEST_TO_FREE_FROM_USER); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CLIENT_PORT_INVALID_REQUEST_TO_FREE_FROM_USER); } TEST_F(ClientPort_test, ReleaseRequestWithValidRequestWorksAndReleasesTheChunkToTheMempool) @@ -293,19 +289,11 @@ TEST_F(ClientPort_test, SendRequestWithNullptrOnConnectedClientPortCallsErrorHan ::testing::Test::RecordProperty("TEST_ID", "e50da541-7621-46e8-accb-46a6b5d7e69b"); auto& sut = clientPortWithConnectOnCreate; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); - }); - sut.portUser.sendRequest(nullptr) .and_then([&]() { GTEST_FAIL() << "Expected request not successfully sent"; }) .or_else([&](auto error) { EXPECT_THAT(error, Eq(ClientSendError::INVALID_REQUEST)); }); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_EQ(detectedError.value(), iox::PoshError::POPO__CLIENT_PORT_INVALID_REQUEST_TO_SEND_FROM_USER); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CLIENT_PORT_INVALID_REQUEST_TO_SEND_FROM_USER); } TEST_F(ClientPort_test, SendRequestOnConnectedClientPortEnqueuesRequestToServerQueue) @@ -412,22 +400,14 @@ TEST_F(ClientPort_test, GetResponseOnConnectedClientPortWithNonEmptyResponseQueu }); } -TEST_F(ClientPort_test, ReleaseResponseWithNullptrIsTerminating) +TEST_F(ClientPort_test, ReleaseResponseWithNullptrCallsErrorHandler) { ::testing::Test::RecordProperty("TEST_ID", "b6ad4c2a-7c52-45ee-afd3-29c286489311"); auto& sut = clientPortWithConnectOnCreate; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); - }); - sut.portUser.releaseResponse(nullptr); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_EQ(detectedError.value(), iox::PoshError::POPO__CLIENT_PORT_INVALID_RESPONSE_TO_RELEASE_FROM_USER); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CLIENT_PORT_INVALID_RESPONSE_TO_RELEASE_FROM_USER); } TEST_F(ClientPort_test, ReleaseResponseWithValidResponseReleasesChunkToTheMempool) @@ -979,18 +959,13 @@ TEST_F(ClientPort_test, InvalidStateTransitionsCallErrorHandler) tryAdvanceToState(sut, targetState); } - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); - }); - - auto caproMessage = CaproMessage{caproMessageType, sut.portData.m_serviceDescription}; - auto responseCaproMessage = sut.portRouDi.dispatchCaProMessageAndGetPossibleResponse(caproMessage); - ASSERT_FALSE(responseCaproMessage.has_value()); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_EQ(detectedError.value(), iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR); + IOX_EXPECT_FATAL_FAILURE( + [&] { + auto caproMessage = CaproMessage{caproMessageType, sut.portData.m_serviceDescription}; + auto responseCaproMessage = sut.portRouDi.dispatchCaProMessageAndGetPossibleResponse(caproMessage); + ASSERT_FALSE(responseCaproMessage.has_value()); + }, + iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR); } } } diff --git a/iceoryx_posh/test/moduletests/test_popo_notification_info.cpp b/iceoryx_posh/test/moduletests/test_popo_notification_info.cpp index dea968b75d..71e411befd 100644 --- a/iceoryx_posh/test/moduletests/test_popo_notification_info.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_notification_info.cpp @@ -15,9 +15,12 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/notification_info.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" + #include namespace @@ -92,35 +95,19 @@ TEST_F(NotificationInfo_test, constGetOriginReturnsCorrectOriginWhenHavingCorrec TEST_F(NotificationInfo_test, getOriginReturnsNullptrWithWrongType) { ::testing::Test::RecordProperty("TEST_ID", "badb467b-bf64-4e43-af30-77c163e90c99"); - auto errorHandlerCalled{false}; - iox::PoshError error{PoshError::NO_ERROR}; - auto errorHandlerGuard = - iox::ErrorHandlerMock::setTemporaryErrorHandler([&](const auto e, const iox::ErrorLevel) { - error = e; - errorHandlerCalled = true; - }); - - m_sut.getOrigin(); - - ASSERT_TRUE(errorHandlerCalled); - EXPECT_EQ(error, iox::PoshError::POPO__NOTIFICATION_INFO_TYPE_INCONSISTENCY_IN_GET_ORIGIN); + + EXPECT_THAT(m_sut.getOrigin(), Eq(nullptr)); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__NOTIFICATION_INFO_TYPE_INCONSISTENCY_IN_GET_ORIGIN); } TEST_F(NotificationInfo_test, constGetOriginReturnsNullptrWithWrongType) { ::testing::Test::RecordProperty("TEST_ID", "4fdb2bed-9928-4181-b195-e411d1b16572"); - auto errorHandlerCalled{false}; - iox::PoshError error{PoshError::NO_ERROR}; - auto errorHandlerGuard = - iox::ErrorHandlerMock::setTemporaryErrorHandler([&](const auto e, const iox::ErrorLevel) { - error = e; - errorHandlerCalled = true; - }); - - const_cast(m_sut).getOrigin(); - - ASSERT_TRUE(errorHandlerCalled); - EXPECT_EQ(error, iox::PoshError::POPO__NOTIFICATION_INFO_TYPE_INCONSISTENCY_IN_GET_ORIGIN); + + EXPECT_THAT(const_cast(m_sut).getOrigin(), Eq(nullptr)); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__NOTIFICATION_INFO_TYPE_INCONSISTENCY_IN_GET_ORIGIN); } TEST_F(NotificationInfo_test, triggerCallbackReturnsTrueAndCallsCallbackWithSettedCallback) diff --git a/iceoryx_posh/test/moduletests/test_popo_request.cpp b/iceoryx_posh/test/moduletests/test_popo_request.cpp index fdc247f2e6..2185b34504 100644 --- a/iceoryx_posh/test/moduletests/test_popo_request.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_request.cpp @@ -14,9 +14,11 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" #include "iox/unique_ptr.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" #include "test_popo_smart_chunk_common.hpp" @@ -76,20 +78,12 @@ TEST_F(Request_test, SendingAlreadySentRequestCallsErrorHandler) EXPECT_FALSE(sutProducer.send().has_error()); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const auto errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - }); - auto sendResult = sutProducer.send(); ASSERT_TRUE(sendResult.has_error()); EXPECT_THAT(sendResult.error(), Eq(CLIENT_SEND_ERROR)); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__SENDING_EMPTY_REQUEST)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__SENDING_EMPTY_REQUEST); } TEST_F(Request_test, SendingMovedRequestCallsErrorHandler) @@ -97,21 +91,13 @@ TEST_F(Request_test, SendingMovedRequestCallsErrorHandler) ::testing::Test::RecordProperty("TEST_ID", "c49cf937-c831-45e6-8d1b-bba37e786979"); constexpr ClientSendError CLIENT_SEND_ERROR{ClientSendError::INVALID_REQUEST}; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const auto errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - }); - auto movedSut = std::move(sutProducer); auto sendResult = sutProducer.send(); ASSERT_TRUE(sendResult.has_error()); EXPECT_THAT(sendResult.error(), Eq(CLIENT_SEND_ERROR)); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__SENDING_EMPTY_REQUEST)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__SENDING_EMPTY_REQUEST); } TEST_F(Request_test, GetRequestHeaderWorks) diff --git a/iceoryx_posh/test/moduletests/test_popo_response.cpp b/iceoryx_posh/test/moduletests/test_popo_response.cpp index 00535d1d05..5d8458d22d 100644 --- a/iceoryx_posh/test/moduletests/test_popo_response.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_response.cpp @@ -14,9 +14,11 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" #include "iox/unique_ptr.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" #include "test_popo_smart_chunk_common.hpp" @@ -76,20 +78,12 @@ TEST_F(Response_test, SendingAlreadySentResponseCallsErrorHandler) EXPECT_FALSE(sutProducer.send().has_error()); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const auto errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - }); - auto sendResult = sutProducer.send(); ASSERT_TRUE(sendResult.has_error()); EXPECT_THAT(sendResult.error(), Eq(SERVER_SEND_ERROR)); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__SENDING_EMPTY_RESPONSE)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__SENDING_EMPTY_RESPONSE); } TEST_F(Response_test, SendingMovedResponseCallsErrorHandler) @@ -97,21 +91,13 @@ TEST_F(Response_test, SendingMovedResponseCallsErrorHandler) ::testing::Test::RecordProperty("TEST_ID", "4e8d7aa2-58d6-421f-9df8-f0fff3f1b9ee"); constexpr ServerSendError SERVER_SEND_ERROR{ServerSendError::INVALID_RESPONSE}; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const auto errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - }); - auto movedSut = std::move(sutProducer); auto sendResult = sutProducer.send(); ASSERT_TRUE(sendResult.has_error()); EXPECT_THAT(sendResult.error(), Eq(SERVER_SEND_ERROR)); - ASSERT_TRUE(detectedError.has_value()); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__SENDING_EMPTY_RESPONSE)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__SENDING_EMPTY_RESPONSE); } TEST_F(Response_test, GetResponseHeaderWorks) diff --git a/iceoryx_posh/test/moduletests/test_popo_sample.cpp b/iceoryx_posh/test/moduletests/test_popo_sample.cpp index 1a011ba1ff..9f82950cc2 100644 --- a/iceoryx_posh/test/moduletests/test_popo_sample.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_sample.cpp @@ -14,9 +14,11 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" #include "iox/unique_ptr.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" #include "test_popo_smart_chunk_common.hpp" @@ -59,35 +61,24 @@ TEST_F(Sample_test, PublishingAlreadyPublishedSampleCallsErrorHandler) sutProducer.publish(); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - }); + IOX_TESTING_EXPECT_OK(); sutProducer.publish(); - ASSERT_TRUE(detectedError.has_value()); - ASSERT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__PUBLISHING_EMPTY_SAMPLE)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__PUBLISHING_EMPTY_SAMPLE); } TEST_F(Sample_test, PublishingMovedSampleCallsErrorHandler) { ::testing::Test::RecordProperty("TEST_ID", "4c3a9a19-0581-4e47-aed7-f55892bef7fa"); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const auto errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - }); - auto movedSut = std::move(sutProducer); + + IOX_TESTING_EXPECT_OK(); + sutProducer.publish(); - ASSERT_TRUE(detectedError.has_value()); - ASSERT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__PUBLISHING_EMPTY_SAMPLE)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__PUBLISHING_EMPTY_SAMPLE); } } // namespace diff --git a/iceoryx_posh/test/moduletests/test_popo_server_port_roudi.cpp b/iceoryx_posh/test/moduletests/test_popo_server_port_roudi.cpp index d1863b030e..daa29bb689 100644 --- a/iceoryx_posh/test/moduletests/test_popo_server_port_roudi.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_server_port_roudi.cpp @@ -14,10 +14,16 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "test_popo_server_port_common.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" + namespace iox_test_popo_server_port { +using namespace iox::testing; + constexpr iox::units::Duration ServerPort_test::DEADLOCK_TIMEOUT; TEST_F(ServerPort_test, GetRequestQueueFullPolicyReturnsCorrectValues) @@ -198,14 +204,6 @@ TEST_F(ServerPort_test, StateOfferedWithCaProMessageTypeConnectAndNoResponseQueu auto caproMessage = CaproMessage{CaproMessageType::CONNECT, sut.portData.m_serviceDescription}; caproMessage.m_chunkQueueData = nullptr; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POPO__SERVER_PORT_NO_CLIENT_RESPONSE_QUEUE_TO_CONNECT)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - detectedError.emplace(error); - }); - sut.portRouDi.dispatchCaProMessageAndGetPossibleResponse(caproMessage) .and_then([&](const auto& responseCaproMessage) { EXPECT_THAT(responseCaproMessage.m_serviceDescription, Eq(sut.portData.m_serviceDescription)); @@ -213,7 +211,7 @@ TEST_F(ServerPort_test, StateOfferedWithCaProMessageTypeConnectAndNoResponseQueu }) .or_else([&]() { GTEST_FAIL() << "Expected CaPro message but got none"; }); - EXPECT_TRUE(detectedError.has_value()); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__SERVER_PORT_NO_CLIENT_RESPONSE_QUEUE_TO_CONNECT); } TEST_F(ServerPort_test, StateOfferedWithCaProMessageTypeDisconnectReactsWithNackWhenResponseQueueNotPresent) @@ -260,19 +258,14 @@ TEST_F(ServerPort_test, StateNotOfferedWithInvalidCaProMessageTypeCallsErrorHand auto caproMessage = CaproMessage{CaproMessageType::PUB, sut.portData.m_serviceDescription}; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - detectedError.emplace(error); - }); - - sut.portRouDi.dispatchCaProMessageAndGetPossibleResponse(caproMessage) - .and_then([&](const auto& responseCaproMessage) { - GTEST_FAIL() << "Expected no CaPro message but got: " << responseCaproMessage.m_type; - }) - .or_else([&]() { GTEST_SUCCEED(); }); + IOX_EXPECT_FATAL_FAILURE( + [&] { + sut.portRouDi.dispatchCaProMessageAndGetPossibleResponse(caproMessage) + .and_then([&](const auto& responseCaproMessage) { + GTEST_FAIL() << "Expected no CaPro message but got: " << responseCaproMessage.m_type; + }); + }, + iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR); } TEST_F(ServerPort_test, StateOfferedWithInvalidCaProMessageTypeCallsErrorHandler) @@ -282,19 +275,14 @@ TEST_F(ServerPort_test, StateOfferedWithInvalidCaProMessageTypeCallsErrorHandler auto caproMessage = CaproMessage{CaproMessageType::SUB, sut.portData.m_serviceDescription}; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - detectedError.emplace(error); - }); - - sut.portRouDi.dispatchCaProMessageAndGetPossibleResponse(caproMessage) - .and_then([&](const auto& responseCaproMessage) { - GTEST_FAIL() << "Expected no CaPro message but got: " << responseCaproMessage.m_type; - }) - .or_else([&]() { GTEST_SUCCEED(); }); + IOX_EXPECT_FATAL_FAILURE( + [&] { + sut.portRouDi.dispatchCaProMessageAndGetPossibleResponse(caproMessage) + .and_then([&](const auto& responseCaproMessage) { + GTEST_FAIL() << "Expected no CaPro message but got: " << responseCaproMessage.m_type; + }); + }, + iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR); } // END test CaPro transitions 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 b9489260c1..28df6e2ab4 100644 --- a/iceoryx_posh/test/moduletests/test_popo_server_port_user.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_server_port_user.cpp @@ -15,8 +15,11 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "test_popo_server_port_common.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" + namespace iox_test_popo_server_port { // NOTE tests related to QueueFullPolicy are done in test_client_server.cpp integration test @@ -402,17 +405,9 @@ TEST_F(ServerPort_test, ReleaseRequestWithInvalidChunkCallsTheErrorHandler) auto sharedChunk = getChunkWithInitializedRequestHeaderAndData(); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POPO__CHUNK_RECEIVER_INVALID_CHUNK_TO_RELEASE_FROM_USER)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - detectedError.emplace(error); - }); - sut.portUser.releaseRequest(static_cast(sharedChunk.getChunkHeader()->userHeader())); - EXPECT_TRUE(detectedError.has_value()); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CHUNK_RECEIVER_INVALID_CHUNK_TO_RELEASE_FROM_USER); } TEST_F(ServerPort_test, ReleaseRequestWithNullptrRequestHeaderCallsTheErrorHandler) @@ -420,17 +415,9 @@ TEST_F(ServerPort_test, ReleaseRequestWithNullptrRequestHeaderCallsTheErrorHandl ::testing::Test::RecordProperty("TEST_ID", "b505019f-ba47-4df4-ba5e-d2d16e5c44cd"); auto& sut = serverPortWithOfferOnCreate; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POPO__SERVER_PORT_INVALID_REQUEST_TO_RELEASE_FROM_USER)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - detectedError.emplace(error); - }); - sut.portUser.releaseRequest(nullptr); - EXPECT_TRUE(detectedError.has_value()); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__SERVER_PORT_INVALID_REQUEST_TO_RELEASE_FROM_USER); } // END releaseRequest tests @@ -634,14 +621,6 @@ TEST_F(ServerPort_test, ReleaseResponseWithInvalidChunkCallsTheErrorHandler) ::testing::Test::RecordProperty("TEST_ID", "fb09c788-0e1b-41c6-877a-1b13a37829d4"); auto& sut = serverPortWithOfferOnCreate; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_FREE_FROM_USER)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - detectedError.emplace(error); - }); - allocateResponseWithRequestHeaderAndThen(sut, [&](const auto, auto res) { sut.portUser.releaseResponse(res); // since the response is already freed, it should not be in the UsedChunkList anymore and the error handler @@ -649,7 +628,7 @@ TEST_F(ServerPort_test, ReleaseResponseWithInvalidChunkCallsTheErrorHandler) sut.portUser.releaseResponse(res); }); - EXPECT_TRUE(detectedError.has_value()); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__CHUNK_SENDER_INVALID_CHUNK_TO_FREE_FROM_USER); } TEST_F(ServerPort_test, ReleaseResponseWithWithNullptrResponseHeaderCallsTheErrorHandler) @@ -657,17 +636,9 @@ TEST_F(ServerPort_test, ReleaseResponseWithWithNullptrResponseHeaderCallsTheErro ::testing::Test::RecordProperty("TEST_ID", "ecb40c4d-7b95-4780-9b51-ac1708830453"); auto& sut = serverPortWithOfferOnCreate; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POPO__SERVER_PORT_INVALID_RESPONSE_TO_FREE_FROM_USER)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - detectedError.emplace(error); - }); - sut.portUser.releaseResponse(nullptr); - EXPECT_TRUE(detectedError.has_value()); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__SERVER_PORT_INVALID_RESPONSE_TO_FREE_FROM_USER); } // END releaseResponse tests @@ -679,19 +650,11 @@ TEST_F(ServerPort_test, SendResponseWithWithNullptrResponseHeaderCallsTheErrorHa ::testing::Test::RecordProperty("TEST_ID", "8d0b0a7f-d1ab-4249-b885-cbc6429eab83"); auto& sut = serverPortWithOfferOnCreate; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POPO__SERVER_PORT_INVALID_RESPONSE_TO_SEND_FROM_USER)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - detectedError.emplace(error); - }); - sut.portUser.sendResponse(nullptr) .and_then([&]() { GTEST_FAIL() << "Expected response not successfully sent"; }) .or_else([&](auto error) { EXPECT_THAT(error, Eq(ServerSendError::INVALID_RESPONSE)); }); - EXPECT_TRUE(detectedError.has_value()); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POPO__SERVER_PORT_INVALID_RESPONSE_TO_SEND_FROM_USER); } TEST_F(ServerPort_test, SendResponseWithoutOfferReleasesTheChunkToTheMempool) diff --git a/iceoryx_posh/test/moduletests/test_popo_subscriber_port.cpp b/iceoryx_posh/test/moduletests/test_popo_subscriber_port.cpp index d5fa419be2..a3e5017c58 100644 --- a/iceoryx_posh/test/moduletests/test_popo_subscriber_port.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_subscriber_port.cpp @@ -23,10 +23,12 @@ #include "iceoryx_posh/internal/popo/ports/subscriber_port_multi_producer.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_single_producer.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" +#include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/popo/subscriber_options.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" -#include "iceoryx_posh/mepoo/mepoo_config.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" #include @@ -34,6 +36,7 @@ namespace { using namespace ::testing; +using namespace iox::testing; class SubscriberPortSingleProducer_test : public Test { @@ -313,51 +316,47 @@ TEST_F(SubscriberPortSingleProducer_test, NackInUnsubscribeRequestedResultsInNot TEST_F(SubscriberPortSingleProducer_test, InvalidMessageResultsInError) { ::testing::Test::RecordProperty("TEST_ID", "23aaa4fd-5567-4831-b539-802c5de238ab"); - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); + iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::SUB, SubscriberPortSingleProducer_test::TEST_SERVICE_DESCRIPTION); - auto maybeCaproMessage = m_sutRouDiSideSingleProducer.dispatchCaProMessageAndGetPossibleResponse(caproMessage); - - EXPECT_FALSE(maybeCaproMessage.has_value()); - EXPECT_TRUE(errorHandlerCalled); + IOX_EXPECT_FATAL_FAILURE( + [&] { + m_sutRouDiSideSingleProducer.dispatchCaProMessageAndGetPossibleResponse(caproMessage) + .and_then([&](const auto& responseCaproMessage) { + GTEST_FAIL() << "Expected no CaPro message but got: " << responseCaproMessage.m_type; + }); + }, + iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR); } TEST_F(SubscriberPortSingleProducer_test, AckWhenNotWaitingForResultsInError) { ::testing::Test::RecordProperty("TEST_ID", "541719e5-fdfa-4ef8-86f6-a9baf4919fe8"); - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); + iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::ACK, SubscriberPortSingleProducer_test::TEST_SERVICE_DESCRIPTION); - auto maybeCaproMessage = m_sutRouDiSideSingleProducer.dispatchCaProMessageAndGetPossibleResponse(caproMessage); - - EXPECT_FALSE(maybeCaproMessage.has_value()); - EXPECT_TRUE(errorHandlerCalled); + IOX_EXPECT_FATAL_FAILURE( + [&] { + m_sutRouDiSideSingleProducer.dispatchCaProMessageAndGetPossibleResponse(caproMessage) + .and_then([&](const auto& responseCaproMessage) { + GTEST_FAIL() << "Expected no CaPro message but got: " << responseCaproMessage.m_type; + }); + }, + iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR); } TEST_F(SubscriberPortSingleProducer_test, NackWhenNotWaitingForResultsInError) { ::testing::Test::RecordProperty("TEST_ID", "063e3a61-209b-4755-abfa-69aed6258ab3"); - auto errorHandlerCalled{false}; - iox::PoshError receivedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled, &receivedError](const iox::PoshError error, const iox::ErrorLevel) { - errorHandlerCalled = true; - receivedError = error; - }); + iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::NACK, SubscriberPortSingleProducer_test::TEST_SERVICE_DESCRIPTION); - auto maybeCaproMessage = m_sutRouDiSideSingleProducer.dispatchCaProMessageAndGetPossibleResponse(caproMessage); - - EXPECT_FALSE(maybeCaproMessage.has_value()); - EXPECT_TRUE(errorHandlerCalled); - ASSERT_THAT(receivedError, Eq(iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR)); + IOX_EXPECT_FATAL_FAILURE( + [&] { m_sutRouDiSideSingleProducer.dispatchCaProMessageAndGetPossibleResponse(caproMessage); }, + iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR); } class SubscriberPortMultiProducer_test : public Test @@ -526,21 +525,13 @@ TEST_F(SubscriberPortMultiProducer_test, UnsubscribeInSubscribedTriggersUnsubMes TEST_F(SubscriberPortMultiProducer_test, InvalidMessageResultsInError) { ::testing::Test::RecordProperty("TEST_ID", "419aa91f-991b-4814-b1ee-11637ee14d30"); - auto errorHandlerCalled{false}; - iox::PoshError receivedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled, &receivedError](const iox::PoshError error, const iox::ErrorLevel) { - errorHandlerCalled = true; - receivedError = error; - }); + iox::capro::CaproMessage caproMessage(iox::capro::CaproMessageType::UNSUB, SubscriberPortSingleProducer_test::TEST_SERVICE_DESCRIPTION); - auto maybeCaproMessage = m_sutRouDiSideMultiProducer.dispatchCaProMessageAndGetPossibleResponse(caproMessage); - - EXPECT_FALSE(maybeCaproMessage.has_value()); - EXPECT_TRUE(errorHandlerCalled); - ASSERT_THAT(receivedError, Eq(iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR)); + IOX_EXPECT_FATAL_FAILURE( + [&] { m_sutRouDiSideMultiProducer.dispatchCaProMessageAndGetPossibleResponse(caproMessage); }, + iox::PoshError::POPO__CAPRO_PROTOCOL_ERROR); } } // namespace diff --git a/iceoryx_posh/test/moduletests/test_popo_trigger.cpp b/iceoryx_posh/test/moduletests/test_popo_trigger.cpp index 7ecc3e350e..e6209da3a1 100644 --- a/iceoryx_posh/test/moduletests/test_popo_trigger.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_trigger.cpp @@ -15,9 +15,12 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/trigger.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" + #include namespace @@ -233,9 +236,6 @@ TEST_F(Trigger_test, TriggerWithEmptyResetInvalidatesTriggerWhenBeingResetted) constexpr uint64_t type = 0U; constexpr uint64_t typeHash = 0U; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError, const iox::ErrorLevel) {}); - Trigger sut( StateBasedTrigger, &m_triggerClass, @@ -251,6 +251,8 @@ TEST_F(Trigger_test, TriggerWithEmptyResetInvalidatesTriggerWhenBeingResetted) EXPECT_FALSE(sut.isValid()); EXPECT_FALSE(static_cast(sut)); + + IOX_TESTING_EXPECT_OK(); } TEST_F(Trigger_test, TriggerCallsHasTriggeredCallback) diff --git a/iceoryx_posh/test/moduletests/test_popo_unique_port_id.cpp b/iceoryx_posh/test/moduletests/test_popo_unique_port_id.cpp index ec2a13acc0..9439eeb79e 100644 --- a/iceoryx_posh/test/moduletests/test_popo_unique_port_id.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_unique_port_id.cpp @@ -17,6 +17,7 @@ #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/attributes.hpp" #include "iox/optional.hpp" #include "iox/scope_guard.hpp" @@ -31,47 +32,26 @@ using namespace iox; TEST(UniquePortId_test, SettingTheRouDiIdWorks) { ::testing::Test::RecordProperty("TEST_ID", "473467bf-1a6f-4cd2-acd8-447a623a5301"); - uint16_t someId = 1243U; - // we cannot ensure that setUniqueRouDiId wasn't called before, therefore we ignore the error - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler([](auto, auto) {}); - auto uniqueRouDiIdResetScopeGuard = - ScopeGuard{[] {}, [] { iox::popo::UniquePortId::setUniqueRouDiId(iox::roudi::DEFAULT_UNIQUE_ROUDI_ID); }}; - iox::popo::UniquePortId::setUniqueRouDiId(someId); - EXPECT_EQ(iox::popo::UniquePortId::getUniqueRouDiId(), someId); + + GTEST_SKIP() << "This test is already performed in " + "IceoryxRoudiApp_test::ConstructorCalledWithArgUniqueIdTwoTimesReturnError"; } TEST(UniquePortId_test, SettingTheRouDiIdTwiceFails) { ::testing::Test::RecordProperty("TEST_ID", "fe468314-cd38-4363-bbf9-f106bf9ec1f4"); - uint16_t someId = 1243U; - optional detectedError; - optional detectedErrorLevel; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - detectedErrorLevel.emplace(errorLevel); - }); - auto uniqueRouDiIdResetScopeGuard = - ScopeGuard{[] {}, [] { iox::popo::UniquePortId::setUniqueRouDiId(iox::roudi::DEFAULT_UNIQUE_ROUDI_ID); }}; - - iox::popo::UniquePortId::setUniqueRouDiId(someId); - // we don't know if setUniqueRouDiId was called before, therefore ignore any error - detectedError.reset(); - detectedErrorLevel.reset(); - - iox::popo::UniquePortId::setUniqueRouDiId(someId); - // now we know that setUniqueRouDiId was called and therefore the error handler must also be called - ASSERT_TRUE(detectedError.has_value()); - ASSERT_TRUE(detectedErrorLevel.has_value()); - EXPECT_THAT(detectedError.value(), - Eq(iox::PoshError::POPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_CUSTOM_UNIQUE_ID)); - EXPECT_THAT(detectedErrorLevel.value(), Eq(iox::ErrorLevel::SEVERE)); + + GTEST_SKIP() << "This test is already performed in " + "IceoryxRoudiApp_test::ConstructorCalledWithArgUniqueIdTwoTimesReturnError"; } TEST(UniquePortId_test, GettingTheRouDiIdWithoutSettingReturnsDefaultId) { ::testing::Test::RecordProperty("TEST_ID", "68de213f-7009-4573-8791-9f09f8ba413c"); + GTEST_SKIP() << "The static variable containing the unique RouDi ID will be set in other tests and therefore this " + "test does not have a meaningful result."; + EXPECT_THAT(iox::popo::UniquePortId::getUniqueRouDiId(), Eq(iox::roudi::DEFAULT_UNIQUE_ROUDI_ID)); } diff --git a/iceoryx_posh/test/moduletests/test_posh_runtime.cpp b/iceoryx_posh/test/moduletests/test_posh_runtime.cpp index 41cc83afd4..6ca838a509 100644 --- a/iceoryx_posh/test/moduletests/test_posh_runtime.cpp +++ b/iceoryx_posh/test/moduletests/test_posh_runtime.cpp @@ -19,6 +19,7 @@ #include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/popo/publisher.hpp" #include "iceoryx_posh/popo/subscriber.hpp" #include "iceoryx_posh/popo/untyped_client.hpp" @@ -29,6 +30,9 @@ #include "iceoryx_posh/testing/mocks/posh_runtime_mock.hpp" #include "iox/detail/convert.hpp" #include "iox/std_string_support.hpp" + +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" #include @@ -39,6 +43,7 @@ using namespace ::testing; using namespace iox::runtime; using namespace iox::capro; using namespace iox; +using namespace iox::testing; using namespace iox::popo; using namespace iox::roudi_env; @@ -117,7 +122,7 @@ TEST_F(PoshRuntime_test, ValidAppName) ::testing::Test::RecordProperty("TEST_ID", "2f4f5dc1-dde0-4520-a341-79a5edd19900"); iox::RuntimeName_t appName("valid_name"); - EXPECT_NO_FATAL_FAILURE({ PoshRuntime::initRuntime(appName); }); + IOX_EXPECT_NO_FATAL_FAILURE([&] { PoshRuntime::initRuntime(appName); }); } TEST_F(PoshRuntime_test, MaxAppNameLength) @@ -187,17 +192,10 @@ TEST_F(PoshRuntime_test, GetInstanceNameIsSuccessful) TEST_F(PoshRuntime_test, GetMiddlewareInterfaceWithInvalidNodeNameIsNotSuccessful) { ::testing::Test::RecordProperty("TEST_ID", "d207e121-d7c2-4a23-a202-1af311f6982b"); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - }); m_runtime->getMiddlewareInterface(iox::capro::Interfaces::INTERNAL, m_invalidNodeName); - ASSERT_THAT(detectedError.has_value(), Eq(true)); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__RUNTIME_ROUDI_GET_MW_INTERFACE_INVALID_RESPONSE)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__RUNTIME_ROUDI_GET_MW_INTERFACE_INVALID_RESPONSE); } TEST_F(PoshRuntime_test, GetMiddlewareInterfaceIsSuccessful) @@ -213,12 +211,6 @@ TEST_F(PoshRuntime_test, GetMiddlewareInterfaceIsSuccessful) TEST_F(PoshRuntime_test, GetMiddlewareInterfaceInterfacelistOverflow) { ::testing::Test::RecordProperty("TEST_ID", "0e164d07-dede-46c3-b2a3-ad78a11c0691"); - auto interfacelistOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&interfacelistOverflowDetected](const iox::PoshError error, const iox::ErrorLevel) { - interfacelistOverflowDetected = true; - EXPECT_THAT(error, Eq(iox::PoshError::PORT_POOL__INTERFACELIST_OVERFLOW)); - }); for (auto i = 0U; i < iox::MAX_INTERFACE_NUMBER; ++i) { @@ -226,12 +218,13 @@ TEST_F(PoshRuntime_test, GetMiddlewareInterfaceInterfacelistOverflow) ASSERT_NE(nullptr, interfacePort); } - EXPECT_FALSE(interfacelistOverflowDetected); + IOX_TESTING_EXPECT_OK(); auto interfacePort = m_runtime->getMiddlewareInterface(iox::capro::Interfaces::INTERNAL); EXPECT_EQ(nullptr, interfacePort); - EXPECT_TRUE(interfacelistOverflowDetected); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__INTERFACELIST_OVERFLOW); } @@ -301,15 +294,6 @@ TEST_F(PoshRuntime_test, getMiddlewarePublisherDefaultArgs) TEST_F(PoshRuntime_test, getMiddlewarePublisherPublisherlistOverflow) { ::testing::Test::RecordProperty("TEST_ID", "f1f1a662-9580-40a1-a116-6ea1cb791516"); - auto publisherlistOverflowDetected{false}; - - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&publisherlistOverflowDetected](const iox::PoshError error, const iox::ErrorLevel) { - if (error == iox::PoshError::PORT_POOL__PUBLISHERLIST_OVERFLOW) - { - publisherlistOverflowDetected = true; - } - }); uint32_t i{0U}; for (; i < (iox::MAX_PUBLISHERS - iox::NUMBER_OF_INTERNAL_PUBLISHERS); ++i) @@ -320,27 +304,20 @@ TEST_F(PoshRuntime_test, getMiddlewarePublisherPublisherlistOverflow) into>(convert::toString(i + 2U)))); ASSERT_NE(nullptr, publisherPort); } - EXPECT_FALSE(publisherlistOverflowDetected); + IOX_TESTING_EXPECT_OK(); auto publisherPort = m_runtime->getMiddlewarePublisher( iox::capro::ServiceDescription(into>(convert::toString(i)), into>(convert::toString(i + 1U)), into>(convert::toString(i + 2U)))); EXPECT_EQ(nullptr, publisherPort); - EXPECT_TRUE(publisherlistOverflowDetected); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__PUBLISHERLIST_OVERFLOW); } TEST_F(PoshRuntime_test, GetMiddlewarePublisherWithSameServiceDescriptionsAndOneToManyPolicyFails) { ::testing::Test::RecordProperty("TEST_ID", "77fb6dfd-a00d-459e-9dd3-90010d7b8af7"); - auto publisherDuplicateDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&publisherDuplicateDetected](const iox::PoshError error, const iox::ErrorLevel) { - if (error == iox::PoshError::POSH__RUNTIME_PUBLISHER_PORT_NOT_UNIQUE) - { - publisherDuplicateDetected = true; - } - }); auto sameServiceDescription = iox::capro::ServiceDescription("99", "1", "20"); @@ -355,7 +332,7 @@ TEST_F(PoshRuntime_test, GetMiddlewarePublisherWithSameServiceDescriptionsAndOne if (std::is_same::value) { ASSERT_EQ(nullptr, publisherPort2); - EXPECT_TRUE(publisherDuplicateDetected); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__RUNTIME_PUBLISHER_PORT_NOT_UNIQUE); } else if (std::is_same::value) { @@ -366,14 +343,6 @@ TEST_F(PoshRuntime_test, GetMiddlewarePublisherWithSameServiceDescriptionsAndOne TEST_F(PoshRuntime_test, GetMiddlewarePublisherWithForbiddenServiceDescriptionsFails) { ::testing::Test::RecordProperty("TEST_ID", "130541c9-94de-4bc4-9471-0a65de310232"); - uint16_t forbiddenServiceDescriptionDetected{0U}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&forbiddenServiceDescriptionDetected](const iox::PoshError error, const iox::ErrorLevel) { - if (error == iox::PoshError::POSH__RUNTIME_SERVICE_DESCRIPTION_FORBIDDEN) - { - forbiddenServiceDescriptionDetected++; - } - }); iox::vector internalServices; const iox::capro::ServiceDescription serviceRegistry{ @@ -391,11 +360,12 @@ TEST_F(PoshRuntime_test, GetMiddlewarePublisherWithForbiddenServiceDescriptionsF for (auto& service : internalServices) { + iox::testing::ErrorHandler::instance().reset(); const auto publisherPort = m_runtime->getMiddlewarePublisher( service, iox::popo::PublisherOptions(), iox::runtime::PortConfigInfo(23U, 23U, 16U)); ASSERT_EQ(nullptr, publisherPort); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__RUNTIME_SERVICE_DESCRIPTION_FORBIDDEN); } - EXPECT_THAT(forbiddenServiceDescriptionDetected, Eq(iox::NUMBER_OF_INTERNAL_PUBLISHERS)); } TEST_F(PoshRuntime_test, GetMiddlewarePublisherWithoutOfferOnCreateLeadsToNotOfferedPublisherBeingCreated) @@ -552,14 +522,6 @@ TEST_F(PoshRuntime_test, GetMiddlewareSubscriberDefaultArgs) TEST_F(PoshRuntime_test, GetMiddlewareSubscriberSubscriberlistOverflow) { ::testing::Test::RecordProperty("TEST_ID", "d1281cbd-6520-424e-aace-fbd3aa5d73e9"); - auto subscriberlistOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&subscriberlistOverflowDetected](const iox::PoshError error, const iox::ErrorLevel) { - if (error == iox::PoshError::PORT_POOL__SUBSCRIBERLIST_OVERFLOW) - { - subscriberlistOverflowDetected = true; - } - }); uint32_t i{0U}; for (; i < iox::MAX_SUBSCRIBERS; ++i) @@ -570,7 +532,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareSubscriberSubscriberlistOverflow) into>(convert::toString(i + 2U)))); ASSERT_NE(nullptr, subscriberPort); } - EXPECT_FALSE(subscriberlistOverflowDetected); + IOX_TESTING_EXPECT_OK(); auto subscriberPort = m_runtime->getMiddlewareSubscriber( iox::capro::ServiceDescription(into>(convert::toString(i)), @@ -578,7 +540,8 @@ TEST_F(PoshRuntime_test, GetMiddlewareSubscriberSubscriberlistOverflow) into>(convert::toString(i + 2U)))); EXPECT_EQ(nullptr, subscriberPort); - EXPECT_TRUE(subscriberlistOverflowDetected); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__SUBSCRIBERLIST_OVERFLOW); } TEST_F(PoshRuntime_test, GetMiddlewareSubscriberWithoutSubscribeOnCreateLeadsToSubscriberThatDoesNotWantToBeSubscribed) @@ -715,14 +678,6 @@ TEST_F(PoshRuntime_test, GetMiddlewareClientWithQueueCapacityZeroClampsQueueCapa TEST_F(PoshRuntime_test, GetMiddlewareClientWhenMaxClientsAreUsedResultsInClientlistOverflow) { ::testing::Test::RecordProperty("TEST_ID", "6f2de2bf-5e7e-47b1-be42-92cf3fa71ba6"); - auto clientOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel) { - if (error == iox::PoshError::PORT_POOL__CLIENTLIST_OVERFLOW) - { - clientOverflowDetected = true; - } - }); uint32_t i{0U}; for (; i < iox::MAX_CLIENTS; ++i) @@ -733,14 +688,15 @@ TEST_F(PoshRuntime_test, GetMiddlewareClientWhenMaxClientsAreUsedResultsInClient into>(convert::toString(i + 2U)))); ASSERT_THAT(clientPort, Ne(nullptr)); } - EXPECT_FALSE(clientOverflowDetected); + IOX_TESTING_EXPECT_OK(); auto clientPort = m_runtime->getMiddlewareClient( iox::capro::ServiceDescription(into>(convert::toString(i)), into>(convert::toString(i + 1U)), into>(convert::toString(i + 2U)))); EXPECT_THAT(clientPort, Eq(nullptr)); - EXPECT_TRUE(clientOverflowDetected); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__CLIENTLIST_OVERFLOW); } TEST_F(PoshRuntime_test, GetMiddlewareClientWithInvalidNodeNameLeadsToErrorHandlerCall) @@ -750,17 +706,9 @@ TEST_F(PoshRuntime_test, GetMiddlewareClientWithInvalidNodeNameLeadsToErrorHandl iox::popo::ClientOptions clientOptions; clientOptions.nodeName = m_invalidNodeName; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - }); - m_runtime->getMiddlewareClient(sd, clientOptions); - ASSERT_THAT(detectedError.has_value(), Eq(true)); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__RUNTIME_ROUDI_REQUEST_CLIENT_INVALID_RESPONSE)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__RUNTIME_ROUDI_REQUEST_CLIENT_INVALID_RESPONSE); } TEST_F(PoshRuntime_test, GetMiddlewareServerWithDefaultArgsIsSuccessful) @@ -826,14 +774,6 @@ TEST_F(PoshRuntime_test, GetMiddlewareServerWithQueueCapacityZeroClampsQueueCapa TEST_F(PoshRuntime_test, GetMiddlewareServerWhenMaxServerAreUsedResultsInServerlistOverflow) { ::testing::Test::RecordProperty("TEST_ID", "8f679838-3332-440c-aa95-d5c82d53a7cd"); - auto serverOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel) { - if (error == iox::PoshError::PORT_POOL__SERVERLIST_OVERFLOW) - { - serverOverflowDetected = true; - } - }); uint32_t i{0U}; for (; i < iox::MAX_SERVERS; ++i) @@ -844,14 +784,15 @@ TEST_F(PoshRuntime_test, GetMiddlewareServerWhenMaxServerAreUsedResultsInServerl into>(convert::toString(i + 2U)))); ASSERT_THAT(serverPort, Ne(nullptr)); } - EXPECT_FALSE(serverOverflowDetected); + IOX_TESTING_EXPECT_OK(); auto serverPort = m_runtime->getMiddlewareServer( iox::capro::ServiceDescription(into>(convert::toString(i)), into>(convert::toString(i + 1U)), into>(convert::toString(i + 2U)))); EXPECT_THAT(serverPort, Eq(nullptr)); - EXPECT_TRUE(serverOverflowDetected); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__SERVERLIST_OVERFLOW); } TEST_F(PoshRuntime_test, GetMiddlewareServerWithInvalidNodeNameLeadsToErrorHandlerCall) @@ -861,17 +802,9 @@ TEST_F(PoshRuntime_test, GetMiddlewareServerWithInvalidNodeNameLeadsToErrorHandl iox::popo::ServerOptions serverOptions; serverOptions.nodeName = m_invalidNodeName; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - }); - m_runtime->getMiddlewareServer(sd, serverOptions); - ASSERT_THAT(detectedError.has_value(), Eq(true)); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__RUNTIME_ROUDI_REQUEST_SERVER_INVALID_RESPONSE)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__RUNTIME_ROUDI_REQUEST_SERVER_INVALID_RESPONSE); } TEST_F(PoshRuntime_test, GetMiddlewareConditionVariableIsSuccessful) @@ -885,25 +818,18 @@ TEST_F(PoshRuntime_test, GetMiddlewareConditionVariableIsSuccessful) TEST_F(PoshRuntime_test, GetMiddlewareConditionVariableListOverflow) { ::testing::Test::RecordProperty("TEST_ID", "6776a648-03c7-4bd0-ab24-72ed7e118e4f"); - auto conditionVariableListOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&conditionVariableListOverflowDetected](const iox::PoshError error, const iox::ErrorLevel) { - if (error == iox::PoshError::PORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW) - { - conditionVariableListOverflowDetected = true; - } - }); for (uint32_t i = 0U; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) { auto conditionVariable = m_runtime->getMiddlewareConditionVariable(); ASSERT_NE(nullptr, conditionVariable); } - EXPECT_FALSE(conditionVariableListOverflowDetected); + IOX_TESTING_EXPECT_OK(); auto conditionVariable = m_runtime->getMiddlewareConditionVariable(); EXPECT_EQ(nullptr, conditionVariable); - EXPECT_TRUE(conditionVariableListOverflowDetected); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW); } TEST_F(PoshRuntime_test, CreateNodeReturnValue) @@ -927,17 +853,9 @@ TEST_F(PoshRuntime_test, CreatingNodeWithInvalidNodeNameLeadsToErrorHandlerCall) const uint32_t nodeDeviceIdentifier = 1U; iox::runtime::NodeProperty nodeProperty(m_invalidNodeName, nodeDeviceIdentifier); - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); - }); - m_runtime->createNode(nodeProperty); - ASSERT_THAT(detectedError.has_value(), Eq(true)); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__RUNTIME_ROUDI_CREATE_NODE_INVALID_RESPONSE)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__RUNTIME_ROUDI_CREATE_NODE_INVALID_RESPONSE); } TEST_F(PoshRuntime_test, ShutdownUnblocksBlockingPublisher) diff --git a/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp b/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp index c3727919a6..d4777fabcd 100644 --- a/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp +++ b/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp @@ -15,15 +15,18 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iceoryx_posh/roudi_env/roudi_env.hpp" #include "iceoryx_posh/runtime/posh_runtime_single_process.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" namespace { using namespace ::testing; +using namespace iox::testing; using namespace iox::runtime; using namespace iox::roudi; using namespace iox::roudi_env; @@ -59,8 +62,8 @@ TEST_F(PoshRuntimeSingleProcess_test, ConstructorPoshRuntimeSingleProcessIsSucce const RuntimeName_t runtimeName{"App"}; - EXPECT_NO_FATAL_FAILURE( - { std::unique_ptr sut{new PoshRuntimeSingleProcess(runtimeName)}; }); + IOX_EXPECT_NO_FATAL_FAILURE( + [&] { std::unique_ptr sut{new PoshRuntimeSingleProcess(runtimeName)}; }); } TEST_F(PoshRuntimeSingleProcess_test, ConstructorPoshRuntimeSingleProcessMultipleProcessIsFound) @@ -70,17 +73,9 @@ TEST_F(PoshRuntimeSingleProcess_test, ConstructorPoshRuntimeSingleProcessMultipl const RuntimeName_t runtimeName{"App"}; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&detectedError](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::FATAL)); - }); - - std::unique_ptr sut{new PoshRuntimeSingleProcess(runtimeName)}; - - ASSERT_THAT(detectedError.has_value(), Eq(true)); - EXPECT_THAT(detectedError.value(), Eq(iox::PoshError::POSH__RUNTIME_IS_CREATED_MULTIPLE_TIMES)); + IOX_EXPECT_FATAL_FAILURE( + [&] { std::unique_ptr sut{new PoshRuntimeSingleProcess(runtimeName)}; }, + iox::PoshError::POSH__RUNTIME_IS_CREATED_MULTIPLE_TIMES); } } // namespace diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index ee0ad415ab..7c45a094d1 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -18,11 +18,16 @@ #include "iceoryx_hoofs/testing/testing_logger.hpp" #include "iceoryx_platform/getopt.hpp" #include "iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/roudi/iceoryx_roudi_app.hpp" #include "iceoryx_posh/roudi/roudi_cmd_line_parser_config_file_option.hpp" #include "iceoryx_posh/roudi/roudi_config_toml_file_provider.hpp" +#include "iox/detail/convert.hpp" #include "iox/logging.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" +#include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" +#include "iceoryx_posh/roudi_env/roudi_env.hpp" #include "test.hpp" #include @@ -32,6 +37,7 @@ namespace using namespace ::testing; using iox::roudi::IceOryxRouDiApp; +using namespace iox::testing; using namespace iox::config; using namespace iox; @@ -146,43 +152,36 @@ TEST_F(IceoryxRoudiApp_test, VerifyRunMethodWithFalseConditionReturnExitSuccess) TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdTwoTimesReturnError) { ::testing::Test::RecordProperty("TEST_ID", "72ec1d9e-7e29-4a9b-a8dd-cb4de82683cb"); + constexpr uint16_t UNIQUE_ROUDI_ID{4242}; constexpr uint8_t NUMBER_OF_ARGS{3U}; char* args[NUMBER_OF_ARGS]; char appName[] = "./foo"; char option[] = "--unique-roudi-id"; - char value[] = "4242"; + auto value = iox::convert::toString(UNIQUE_ROUDI_ID); args[0] = &appName[0]; args[1] = &option[0]; - args[2] = &value[0]; + args[2] = value.data(); auto cmdLineArgs = cmdLineParser.parse(NUMBER_OF_ARGS, args); ASSERT_FALSE(cmdLineArgs.has_error()); - iox::optional detectedError; - iox::optional detectedErrorLevel; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - detectedError.emplace(error); - detectedErrorLevel.emplace(errorLevel); - }); + { + // use the RouDiEnv to reset the UniquePortId finalization from previous tests + roudi_env::RouDiEnv(roudi_env::MinimalRouDiConfigBuilder().create()); + } - IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); - // we don't know if setUniqueRouDiId was called before, therefore ignore any error - detectedError.reset(); - detectedErrorLevel.reset(); + EXPECT_THAT(iox::popo::UniquePortId::getUniqueRouDiId(), Eq(iox::roudi::DEFAULT_UNIQUE_ROUDI_ID)); - IceoryxRoudiApp_Child roudiTest(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); + IOX_EXPECT_NO_FATAL_FAILURE( + [&] { IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); }); + EXPECT_THAT(iox::popo::UniquePortId::getUniqueRouDiId(), Eq(UNIQUE_ROUDI_ID)); - // now we know that setUniqueRouDiId was called and therefore the error handler must also be called - ASSERT_TRUE(detectedError.has_value()); - ASSERT_TRUE(detectedErrorLevel.has_value()); - EXPECT_THAT(detectedError.value(), - Eq(iox::PoshError::POPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_CUSTOM_UNIQUE_ID)); - EXPECT_THAT(detectedErrorLevel.value(), Eq(iox::ErrorLevel::SEVERE)); + EXPECT_THAT(iox::popo::UniquePortId::getUniqueRouDiId(), Eq(UNIQUE_ROUDI_ID)); - // reset unique RouDi ID - iox::popo::UniquePortId::setUniqueRouDiId(iox::roudi::DEFAULT_UNIQUE_ROUDI_ID); + IOX_EXPECT_FATAL_FAILURE( + [&] { IceoryxRoudiApp_Child roudi(cmdLineArgs.value(), iox::RouDiConfig_t().setDefaults()); }, + iox::PoshError::POPO__TYPED_UNIQUE_ID_ROUDI_HAS_ALREADY_DEFINED_CUSTOM_UNIQUE_ID); } TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgVersionSetRunVariableToFalse) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 18b83db0a3..b44f5a6d06 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -16,9 +16,12 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/barrier.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/std_string_support.hpp" #include "test_roudi_portmanager_fixture.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" + namespace iox_test_roudi_portmanager { using iox::into; @@ -247,14 +250,11 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) } { // test if overflow errors get hit - - bool errorHandlerCalled = false; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); + IOX_TESTING_EXPECT_OK(); auto publisherPortDataResult = m_portManager->acquirePublisherPortData( getUniqueSD(), publisherOptions, runtimeName, m_payloadDataSegmentMemoryManager, PortConfigInfo()); - EXPECT_TRUE(errorHandlerCalled); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__PUBLISHERLIST_OVERFLOW); ASSERT_TRUE(publisherPortDataResult.has_error()); EXPECT_THAT(publisherPortDataResult.error(), Eq(PortPoolError::PUBLISHER_PORT_LIST_FULL)); } @@ -306,14 +306,6 @@ TEST_F(PortManager_test, AcquirePublisherPortDataWithSameServiceDescriptionTwice GTEST_FAIL() << "Expected ClientPortData but got PortPoolError: " << static_cast(error); }); - iox::optional detectedError; - auto errorHandlerGuard = - iox::ErrorHandlerMock::setTemporaryErrorHandler([&](const auto error, const auto errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POSH__PORT_MANAGER_PUBLISHERPORT_NOT_UNIQUE)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - detectedError.emplace(error); - }); - // second call auto acquirePublisherPortResult = m_portManager->acquirePublisherPortData( sd, publisherOptions, runtimeName, m_payloadDataSegmentMemoryManager, {}); @@ -322,11 +314,11 @@ TEST_F(PortManager_test, AcquirePublisherPortDataWithSameServiceDescriptionTwice { ASSERT_TRUE(acquirePublisherPortResult.has_error()); EXPECT_THAT(acquirePublisherPortResult.error(), Eq(PortPoolError::UNIQUE_PUBLISHER_PORT_ALREADY_EXISTS)); - EXPECT_TRUE(detectedError.has_value()); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__PORT_MANAGER_PUBLISHERPORT_NOT_UNIQUE); } else { - EXPECT_FALSE(detectedError.has_value()); + IOX_TESTING_EXPECT_OK(); } } @@ -346,20 +338,13 @@ TEST_F(PortManager_test, publisherPortDataResult.value()->m_toBeDestroyed = true; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto error, const auto) { detectedError.emplace(error); }); - // second call must now also succeed m_portManager->acquirePublisherPortData(sd, publisherOptions, runtimeName, m_payloadDataSegmentMemoryManager, {}) .or_else([&](const auto& error) { GTEST_FAIL() << "Expected ClientPortData but got PortPoolError: " << static_cast(error); }); - detectedError.and_then([&](const auto& error) { - GTEST_FAIL() << "Expected error handler to not be called but got: " - << static_cast::type>(error); - }); + IOX_TESTING_EXPECT_OK(); } TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) @@ -376,14 +361,14 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) } { // test if overflow errors get hit + IOX_TESTING_EXPECT_OK(); - bool errorHandlerCalled = false; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); auto subscriberPortDataResult = m_portManager->acquireSubscriberPortData(getUniqueSD(), subscriberOptions, runtimeName1, PortConfigInfo()); - EXPECT_TRUE(errorHandlerCalled); + ASSERT_TRUE(subscriberPortDataResult.has_error()); EXPECT_THAT(subscriberPortDataResult.error(), Eq(PortPoolError::SUBSCRIBER_PORT_LIST_FULL)); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__SUBSCRIBERLIST_OVERFLOW); } } @@ -397,13 +382,12 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails) // test if overflow errors get hit { - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); + IOX_TESTING_EXPECT_OK(); auto interfacePort = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, "itfPenguin"); EXPECT_EQ(interfacePort, nullptr); - EXPECT_TRUE(errorHandlerCalled); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__INTERFACELIST_OVERFLOW); } } @@ -634,14 +618,13 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFa // test if overflow errors get hit { - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); + IOX_TESTING_EXPECT_OK(); auto conditionVariableResult = m_portManager->acquireConditionVariableData("AnotherToad"); - EXPECT_TRUE(conditionVariableResult.has_error()); - EXPECT_TRUE(errorHandlerCalled); + ASSERT_TRUE(conditionVariableResult.has_error()); EXPECT_THAT(conditionVariableResult.error(), Eq(PortPoolError::CONDITION_VARIABLE_LIST_FULL)); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW); } } @@ -707,15 +690,13 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) // first acquire all possible NodeData acquireMaxNumberOfNodes(nodeName, runtimeName); - // test if overflow errors get hit - auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&errorHandlerCalled](const iox::PoshError, const iox::ErrorLevel) { errorHandlerCalled = true; }); + IOX_TESTING_EXPECT_OK(); auto nodeResult = m_portManager->acquireNodeData("AnotherProcess", "AnotherNode"); - EXPECT_THAT(nodeResult.has_error(), Eq(true)); - EXPECT_THAT(errorHandlerCalled, Eq(true)); + ASSERT_THAT(nodeResult.has_error(), Eq(true)); EXPECT_THAT(nodeResult.error(), Eq(PortPoolError::NODE_DATA_LIST_FULL)); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__NODELIST_OVERFLOW); } TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager_client_server.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager_client_server.cpp index 162166305b..739ac38a1b 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager_client_server.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager_client_server.cpp @@ -14,8 +14,11 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "test_roudi_portmanager_fixture.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" + namespace iox_test_roudi_portmanager { using namespace iox::popo; @@ -107,14 +110,6 @@ TEST_F(PortManager_test, AcquireServerPortDataWithSameServiceDescriptionTwiceCal GTEST_FAIL() << "Expected ClientPortData but got PortPoolError: " << static_cast(error); }); - iox::optional detectedError; - auto errorHandlerGuard = - iox::ErrorHandlerMock::setTemporaryErrorHandler([&](const auto error, const auto errorLevel) { - EXPECT_THAT(error, Eq(iox::PoshError::POSH__PORT_MANAGER_SERVERPORT_NOT_UNIQUE)); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - detectedError.emplace(error); - }); - // second call must fail m_portManager->acquireServerPortData(sd, serverOptions, runtimeName, m_payloadDataSegmentMemoryManager, {}) .and_then([&](const auto&) { @@ -122,7 +117,7 @@ TEST_F(PortManager_test, AcquireServerPortDataWithSameServiceDescriptionTwiceCal }) .or_else([&](const auto& error) { EXPECT_THAT(error, Eq(PortPoolError::UNIQUE_SERVER_PORT_ALREADY_EXISTS)); }); - EXPECT_TRUE(detectedError.has_value()); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__PORT_MANAGER_SERVERPORT_NOT_UNIQUE); } TEST_F(PortManager_test, AcquireServerPortDataWithSameServiceDescriptionTwiceAndFirstPortMarkedToBeDestroyedReturnsPort) @@ -140,20 +135,13 @@ TEST_F(PortManager_test, AcquireServerPortDataWithSameServiceDescriptionTwiceAnd serverPortDataResult.value()->m_toBeDestroyed = true; - iox::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto error, const auto) { detectedError.emplace(error); }); - // second call must now also succeed m_portManager->acquireServerPortData(sd, serverOptions, runtimeName, m_payloadDataSegmentMemoryManager, {}) .or_else([&](const auto& error) { GTEST_FAIL() << "Expected ClientPortData but got PortPoolError: " << static_cast(error); }); - detectedError.and_then([&](const auto& error) { - GTEST_FAIL() << "Expected error handler to not be called but got: " - << static_cast::type>(error); - }); + IOX_TESTING_EXPECT_OK(); } // END aquireServerPortData tests diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 5c6bb83018..1336bce470 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -15,6 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/internal/roudi/port_pool_data.hpp" #include "iceoryx_posh/internal/runtime/node_data.hpp" #include "iceoryx_posh/popo/client_options.hpp" @@ -23,6 +24,7 @@ #include "iox/detail/convert.hpp" #include "iox/std_string_support.hpp" +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" namespace @@ -136,18 +138,11 @@ TEST_F(PortPool_test, AddNodeDataWhenNodeListIsFullReturnsError) ASSERT_FALSE(sut.addNodeData(m_runtimeName, m_nodeName, i).has_error()); } - auto errorHandlerCalled{false}; - PoshError error{PoshError::NO_ERROR}; - auto errorHandlerGuard = - ErrorHandlerMock::setTemporaryErrorHandler([&](const auto e, const ErrorLevel) { - error = e; - errorHandlerCalled = true; - }); + IOX_TESTING_EXPECT_OK(); ASSERT_TRUE(sut.addNodeData(m_runtimeName, m_nodeName, MAX_NODE_NUMBER).has_error()); - ASSERT_TRUE(errorHandlerCalled); - EXPECT_EQ(error, PoshError::PORT_POOL__NODELIST_OVERFLOW); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__NODELIST_OVERFLOW); } TEST_F(PortPool_test, GetNodeDataListIsSuccessful) @@ -254,18 +249,11 @@ TEST_F(PortPool_test, AddPublisherPortWhenPublisherListOverflowsReturnsError) EXPECT_FALSE(addPublisherPort(i)); } - auto errorHandlerCalled{false}; - PoshError error{PoshError::NO_ERROR}; - auto errorHandlerGuard = - ErrorHandlerMock::setTemporaryErrorHandler([&](const auto e, const ErrorLevel) { - error = e; - errorHandlerCalled = true; - }); + IOX_TESTING_EXPECT_OK(); EXPECT_TRUE(addPublisherPort(MAX_PUBLISHERS)); - ASSERT_TRUE(errorHandlerCalled); - EXPECT_EQ(error, PoshError::PORT_POOL__PUBLISHERLIST_OVERFLOW); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__PUBLISHERLIST_OVERFLOW); } TEST_F(PortPool_test, GetPublisherPortDataListIsSuccessful) @@ -380,17 +368,11 @@ TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReturnsError) EXPECT_FALSE(addSubscriberPort(i)); } - auto errorHandlerCalled{false}; - PoshError error{PoshError::NO_ERROR}; - auto errorHandlerGuard = - ErrorHandlerMock::setTemporaryErrorHandler([&](const auto e, const ErrorLevel) { - error = e; - errorHandlerCalled = true; - }); + IOX_TESTING_EXPECT_OK(); + EXPECT_TRUE(addSubscriberPort(MAX_SUBSCRIBERS)); - ASSERT_TRUE(errorHandlerCalled); - EXPECT_EQ(error, PoshError::PORT_POOL__SUBSCRIBERLIST_OVERFLOW); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__SUBSCRIBERLIST_OVERFLOW); } TEST_F(PortPool_test, GetSubscriberPortDataListIsSuccessful) @@ -484,20 +466,14 @@ TEST_F(PortPool_test, AddClientPortWhenClientListOverflowsReturnsError) auto addSuccessful = addClientPorts(NUMBER_OF_CLIENTS_TO_ADD, [&](const auto&, const auto&, const auto&) {}); EXPECT_TRUE(addSuccessful); - - auto errorHandlerCalled{false}; - auto errorHandlerGuard = - ErrorHandlerMock::setTemporaryErrorHandler([&](const auto error, const ErrorLevel level) { - errorHandlerCalled = true; - EXPECT_THAT(error, Eq(PoshError::PORT_POOL__CLIENTLIST_OVERFLOW)); - EXPECT_THAT(level, Eq(ErrorLevel::MODERATE)); - }); + IOX_TESTING_EXPECT_OK(); constexpr uint32_t ONE_MORE_CLIENT{1U}; auto additionalAddSuccessful = addClientPorts(ONE_MORE_CLIENT, [&](const auto&, const auto&, const auto&) {}); EXPECT_FALSE(additionalAddSuccessful); - EXPECT_TRUE(errorHandlerCalled); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__CLIENTLIST_OVERFLOW); } TEST_F(PortPool_test, GetClientPortDataListIsSuccessful) @@ -586,19 +562,12 @@ TEST_F(PortPool_test, AddServerPortWhenServerListOverflowsReturnsError) EXPECT_TRUE(addSuccessful); - auto errorHandlerCalled{false}; - auto errorHandlerGuard = - ErrorHandlerMock::setTemporaryErrorHandler([&](const auto error, const ErrorLevel level) { - errorHandlerCalled = true; - EXPECT_THAT(error, Eq(PoshError::PORT_POOL__SERVERLIST_OVERFLOW)); - EXPECT_THAT(level, Eq(ErrorLevel::MODERATE)); - }); - constexpr uint32_t ONE_MORE_SERVER{1U}; auto additionalAddSuccessful = addServerPorts(ONE_MORE_SERVER, [&](const auto&, const auto&, const auto&) {}); EXPECT_FALSE(additionalAddSuccessful); - EXPECT_TRUE(errorHandlerCalled); + + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__SERVERLIST_OVERFLOW); } TEST_F(PortPool_test, GetServerPortDataListIsSuccessful) @@ -674,17 +643,9 @@ TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError) EXPECT_FALSE(sut.addInterfacePort(m_applicationName, Interfaces::INTERFACE_END).has_error()); } - auto errorHandlerCalled{false}; - PoshError error{PoshError::NO_ERROR}; - auto errorHandlerGuard = - ErrorHandlerMock::setTemporaryErrorHandler([&](const auto e, const ErrorLevel) { - error = e; - errorHandlerCalled = true; - }); EXPECT_TRUE(sut.addInterfacePort(m_applicationName, Interfaces::INTERFACE_END).has_error()); - ASSERT_TRUE(errorHandlerCalled); - EXPECT_EQ(error, PoshError::PORT_POOL__INTERFACELIST_OVERFLOW); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__INTERFACELIST_OVERFLOW); } TEST_F(PortPool_test, GetInterfacePortDataListIsSuccessful) @@ -758,17 +719,9 @@ TEST_F(PortPool_test, AddConditionVariableDataWhenContainerIsFullReturnsError) EXPECT_FALSE(sut.addConditionVariableData(m_applicationName).has_error()); } - auto errorHandlerCalled{false}; - PoshError error{PoshError::NO_ERROR}; - auto errorHandlerGuard = - ErrorHandlerMock::setTemporaryErrorHandler([&](const auto e, const ErrorLevel) { - error = e; - errorHandlerCalled = true; - }); EXPECT_TRUE(sut.addConditionVariableData(m_applicationName).has_error()); - ASSERT_TRUE(errorHandlerCalled); - EXPECT_EQ(error, PoshError::PORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::PORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW); } TEST_F(PortPool_test, GetConditionVariableDataListIsSuccessful) diff --git a/iceoryx_posh/test/moduletests/test_roudi_process.cpp b/iceoryx_posh/test/moduletests/test_roudi_process.cpp index 23014ff61f..ca25651dba 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_process.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_process.cpp @@ -17,11 +17,14 @@ #include "iceoryx_platform/types.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/internal/roudi/process.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/roudi/memory/roudi_memory_interface.hpp" #include "iceoryx_posh/version/compatibility_check_level.hpp" #include "iox/string.hpp" + +#include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" namespace @@ -96,20 +99,11 @@ TEST_F(Process_test, sendViaIpcChannelFail) { ::testing::Test::RecordProperty("TEST_ID", "c4d5c133-bf93-45a4-aa4f-9c3c2a50f91a"); iox::runtime::IpcMessage data{""}; - iox::optional sendViaIpcChannelStatusFail; - - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&sendViaIpcChannelStatusFail](const iox::PoshError error, const iox::ErrorLevel errorLevel) { - sendViaIpcChannelStatusFail.emplace(error); - EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); - }); Process roudiproc(processname, pid, user, heartbeatPoolIndex, sessionId); roudiproc.sendViaIpcChannel(data); - ASSERT_THAT(sendViaIpcChannelStatusFail.has_value(), Eq(true)); - EXPECT_THAT(sendViaIpcChannelStatusFail.value(), - Eq(iox::PoshError::POSH__ROUDI_PROCESS_SEND_VIA_IPC_CHANNEL_FAILED)); + IOX_TESTING_EXPECT_ERROR(iox::PoshError::POSH__ROUDI_PROCESS_SEND_VIA_IPC_CHANNEL_FAILED); } TEST_F(Process_test, Heartbeat) diff --git a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface_creator.cpp b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface_creator.cpp index b1d6ef06a7..6697ead567 100644 --- a/iceoryx_posh/test/moduletests/test_runtime_ipc_interface_creator.cpp +++ b/iceoryx_posh/test/moduletests/test_runtime_ipc_interface_creator.cpp @@ -15,10 +15,10 @@ // SPDX-License-Identifier: Apache-2.0 #if !defined(_WIN32) -#include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/internal/runtime/ipc_interface_creator.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" #include @@ -70,8 +70,8 @@ TEST_F(IpcInterfaceCreator_test, CreateWithSameNameLeadsToError) ::testing::Test::RecordProperty("TEST_ID", "2e8c15c8-1b7b-465b-aae5-6db24fc3c34a"); IpcInterfaceCreator m_sut{goodName}; - IOX_EXPECT_FATAL_FAILURE([&] { IpcInterfaceCreator m_sut2{goodName}; }, - iox::PoshError::IPC_INTERFACE__APP_WITH_SAME_NAME_STILL_RUNNING); + IOX_EXPECT_FATAL_FAILURE([&] { IpcInterfaceCreator m_sut2{goodName}; }, + iox::PoshError::IPC_INTERFACE__APP_WITH_SAME_NAME_STILL_RUNNING); } } // namespace From 37769577562abf2d5fda3b01412abc0b9ee2f769 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 29 Jan 2024 06:46:46 +0100 Subject: [PATCH 11/21] iox-#1032 Port 'hoofs' to the new error reporting --- .../test/moduletests/test_chunk.cpp | 2 +- .../test/moduletests/test_client.cpp | 2 +- .../test/moduletests/test_listener.cpp | 2 +- .../test/moduletests/test_node.cpp | 2 +- .../moduletests/test_notification_info.cpp | 2 +- .../test/moduletests/test_publisher.cpp | 2 +- .../test/moduletests/test_request_header.cpp | 2 +- .../test/moduletests/test_response_header.cpp | 2 +- .../test/moduletests/test_runtime.cpp | 2 +- .../test/moduletests/test_server.cpp | 2 +- .../moduletests/test_service_discovery.cpp | 2 +- .../test/moduletests/test_subscriber.cpp | 2 +- .../test/moduletests/test_user_trigger.cpp | 2 +- .../test/moduletests/test_wait_set.cpp | 2 +- iceoryx_hoofs/CMakeLists.txt | 2 +- .../cli/source/command_line_parser.cpp | 2 +- .../error_handling/error_handling.hpp | 44 -------- .../iox/detail/hoofs_error_reporting.hpp | 106 ++++++++++++++++++ .../iox/iceoryx_hoofs_error_reporting.hpp | 31 ----- .../include/iox/iceoryx_hoofs_errors.hpp | 94 ---------------- .../source/hoofs_error_reporting.cpp} | 15 ++- iceoryx_hoofs/test/.clang-tidy | 9 +- .../test/mocktests/test_fatal_failure.cpp | 2 +- .../moduletests/test_cli_cli_definition.cpp | 2 +- .../test_cli_command_line_parser.cpp | 2 +- .../test_cli_option_definition.cpp | 2 +- .../test_concurrent_mpmc_loffli.cpp | 2 +- ...est_container_fixed_position_container.cpp | 2 +- .../test_container_forward_list.cpp | 2 +- .../test/moduletests/test_container_list.cpp | 2 +- .../moduletests/test_container_vector.cpp | 2 +- ...est_design_functional_interface_expect.cpp | 2 +- .../test_filesystem_file_reader.cpp | 2 +- .../test_functional_function_ref.cpp | 2 +- .../moduletests/test_vocabulary_expected.cpp | 2 +- .../test_vocabulary_semantic_string.cpp | 2 +- .../moduletests/test_vocabulary_string.cpp | 2 +- .../iceoryx_hoofs/testing/fatal_failure.inl | 16 +-- .../test/moduletests/test_capro_service.cpp | 2 +- .../moduletests/test_mepoo_chunk_header.cpp | 2 +- .../moduletests/test_mepoo_memory_manager.cpp | 2 +- .../test/moduletests/test_mepoo_mempool.cpp | 2 +- .../test_popo_chunk_distributor.cpp | 2 +- 43 files changed, 166 insertions(+), 221 deletions(-) delete mode 100644 iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp create mode 100644 iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp delete mode 100644 iceoryx_hoofs/reporting/include/iox/iceoryx_hoofs_error_reporting.hpp delete mode 100644 iceoryx_hoofs/reporting/include/iox/iceoryx_hoofs_errors.hpp rename iceoryx_hoofs/{source/error_handling/error_handling.cpp => reporting/source/hoofs_error_reporting.cpp} (53%) diff --git a/iceoryx_binding_c/test/moduletests/test_chunk.cpp b/iceoryx_binding_c/test/moduletests/test_chunk.cpp index 79ff5d7778..3cc5543ebe 100644 --- a/iceoryx_binding_c/test/moduletests/test_chunk.cpp +++ b/iceoryx_binding_c/test/moduletests/test_chunk.cpp @@ -20,7 +20,7 @@ extern "C" { #include "iceoryx_binding_c/runtime.h" } -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_client.cpp b/iceoryx_binding_c/test/moduletests/test_client.cpp index ac5a9c7bf7..3b14290260 100644 --- a/iceoryx_binding_c/test/moduletests/test_client.cpp +++ b/iceoryx_binding_c/test/moduletests/test_client.cpp @@ -15,7 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/capro/service_description.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_listener.cpp b/iceoryx_binding_c/test/moduletests/test_listener.cpp index efe1086937..d69407f8fa 100644 --- a/iceoryx_binding_c/test/moduletests/test_listener.cpp +++ b/iceoryx_binding_c/test/moduletests/test_listener.cpp @@ -17,7 +17,7 @@ #include "iceoryx_binding_c/enums.h" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_node.cpp b/iceoryx_binding_c/test/moduletests/test_node.cpp index d1f57f287c..7b0cebc6e1 100644 --- a/iceoryx_binding_c/test/moduletests/test_node.cpp +++ b/iceoryx_binding_c/test/moduletests/test_node.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_notification_info.cpp b/iceoryx_binding_c/test/moduletests/test_notification_info.cpp index 414ff7b450..79784e1036 100644 --- a/iceoryx_binding_c/test/moduletests/test_notification_info.cpp +++ b/iceoryx_binding_c/test/moduletests/test_notification_info.cpp @@ -16,7 +16,7 @@ #include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp" #include "iceoryx_binding_c/types.h" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_publisher.cpp b/iceoryx_binding_c/test/moduletests/test_publisher.cpp index 15442cc4ff..f016055b0a 100644 --- a/iceoryx_binding_c/test/moduletests/test_publisher.cpp +++ b/iceoryx_binding_c/test/moduletests/test_publisher.cpp @@ -18,7 +18,7 @@ #include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_publisher.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp" #include "iceoryx_posh/internal/popo/ports/publisher_port_roudi.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_request_header.cpp b/iceoryx_binding_c/test/moduletests/test_request_header.cpp index 48c793a8a2..54f9882726 100644 --- a/iceoryx_binding_c/test/moduletests/test_request_header.cpp +++ b/iceoryx_binding_c/test/moduletests/test_request_header.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/popo/rpc_header.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_response_header.cpp b/iceoryx_binding_c/test/moduletests/test_response_header.cpp index fb89e9b280..6de0e3e773 100644 --- a/iceoryx_binding_c/test/moduletests/test_response_header.cpp +++ b/iceoryx_binding_c/test/moduletests/test_response_header.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/popo/rpc_header.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_runtime.cpp b/iceoryx_binding_c/test/moduletests/test_runtime.cpp index fe54a12bb8..7040791423 100644 --- a/iceoryx_binding_c/test/moduletests/test_runtime.cpp +++ b/iceoryx_binding_c/test/moduletests/test_runtime.cpp @@ -18,7 +18,7 @@ extern "C" { #include "iceoryx_binding_c/runtime.h" } -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_server.cpp b/iceoryx_binding_c/test/moduletests/test_server.cpp index 15bf295579..2acdf34a4e 100644 --- a/iceoryx_binding_c/test/moduletests/test_server.cpp +++ b/iceoryx_binding_c/test/moduletests/test_server.cpp @@ -15,7 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/capro/service_description.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp b/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp index 2df97f6922..11439d392f 100644 --- a/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp +++ b/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iceoryx_posh/runtime/service_discovery.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp index ae7bfbc9a6..dcd712f6e9 100644 --- a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp +++ b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp @@ -18,7 +18,7 @@ #include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp b/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp index ee0e1e4664..8e41eb3439 100644 --- a/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp +++ b/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/popo/user_trigger.hpp" #include "mocks/wait_set_mock.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_wait_set.cpp b/iceoryx_binding_c/test/moduletests/test_wait_set.cpp index 157d7deba4..d6217409bd 100644 --- a/iceoryx_binding_c/test/moduletests/test_wait_set.cpp +++ b/iceoryx_binding_c/test/moduletests/test_wait_set.cpp @@ -18,7 +18,7 @@ #include "iceoryx_binding_c/enums.h" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" diff --git a/iceoryx_hoofs/CMakeLists.txt b/iceoryx_hoofs/CMakeLists.txt index 1d9f4a046a..7d20bc45a2 100644 --- a/iceoryx_hoofs/CMakeLists.txt +++ b/iceoryx_hoofs/CMakeLists.txt @@ -117,10 +117,10 @@ iox_add_library( memory/source/relative_pointer_data.cpp primitives/source/type_traits.cpp reporting/source/default_error_handler.cpp + reporting/source/hoofs_error_reporting.cpp reporting/source/console_logger.cpp reporting/source/logger.cpp source/error_handling/error_handler.cpp - source/error_handling/error_handling.cpp time/source/duration.cpp utility/source/unique_id.cpp diff --git a/iceoryx_hoofs/cli/source/command_line_parser.cpp b/iceoryx_hoofs/cli/source/command_line_parser.cpp index 5bdeba88db..5f08d9d43c 100644 --- a/iceoryx_hoofs/cli/source/command_line_parser.cpp +++ b/iceoryx_hoofs/cli/source/command_line_parser.cpp @@ -15,7 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/cli/command_line_parser.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/algorithm.hpp" #include "iox/std_string_support.hpp" diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp deleted file mode 100644 index 231a0da351..0000000000 --- a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. -// Copyright (c) 2020 - 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_ERROR_HANDLING_ERROR_HANDLING_HPP -#define IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLING_HPP - -#include "iceoryx_hoofs/error_handling/error_handler.hpp" - -namespace iox -{ -// clang-format off -#define HOOFS_ERRORS(error) \ - error(EXPECTS_ENSURES_FAILED) - - // EXPECTS_ENSURES_FAILED is used as a temporary solution to make IOX_EXPECTS/IOX_ENSURES testable - -// clang-format on - -// DO NOT TOUCH THE ENUM, you can doodle around with the lines above!!! - -enum class HoofsError : uint32_t -{ - NO_ERROR = HOOFS_MODULE_IDENTIFIER << ERROR_ENUM_OFFSET_IN_BITS, - HOOFS_ERRORS(CREATE_ICEORYX_ERROR_ENUM) -}; - -const char* asStringLiteral(const HoofsError error) noexcept; - -} // namespace iox - -#endif // IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLING_HPP diff --git a/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp b/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp new file mode 100644 index 0000000000..9c5c6386ea --- /dev/null +++ b/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp @@ -0,0 +1,106 @@ +// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 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_ERROR_HANDLING_ERROR_HANDLING_HPP +#define IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLING_HPP + +// Each module (= some unit with its own errors) must provide the following. + +// 1. Define the errors of the module -> see below + +// 2. Include the custom reporting implementation +#include "iox/error_reporting/custom/error_reporting.hpp" + +// 3. Include the error reporting macro API +#include "iox/error_reporting/macros.hpp" + +// additional includes +#include "iox/error_reporting/types.hpp" + +/// @todo iox-#1032 Remove once HOOFS_MODULE_IDENTIFIER is moved to 'ModuleId' in 'error_reporting/types.hpp' +#include "iceoryx_hoofs/error_handling/error_handler.hpp" + +namespace iox +{ +// clang-format off +#define HOOFS_ERRORS(error) \ + error(EXPECTS_ENSURES_FAILED) \ + error(DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER) // keep this always at the end of the error list + + // EXPECTS_ENSURES_FAILED is used as a temporary solution to make IOX_EXPECTS/IOX_ENSURES testable + +// clang-format on + +// DO NOT TOUCH THE ENUM, you can doodle around with the lines above!!! + +enum class HoofsError : iox::er::ErrorCode::type +{ + HOOFS_ERRORS(CREATE_ICEORYX_ERROR_ENUM) +}; + +const char* asStringLiteral(const HoofsError error) noexcept; + +class HoofsErrorType +{ + public: + explicit HoofsErrorType(HoofsError code) + : m_code(static_cast(code)) + { + } + + static constexpr iox::er::ModuleId module() + { + return MODULE_ID; + } + + iox::er::ErrorCode code() const + { + return m_code; + } + + const char* name() const + { + return asStringLiteral(static_cast(m_code.value)); + } + + const char* moduleName() const { + return "iceoryx_hoofs"; + } + + static constexpr iox::er::ModuleId MODULE_ID{POSH_MODULE_IDENTIFIER}; + + protected: + iox::er::ErrorCode m_code; +}; + +namespace er +{ + +inline HoofsErrorType toError(HoofsError code) +{ + return HoofsErrorType(code); +} + +inline ModuleId toModule(HoofsError) +{ + return HoofsErrorType::MODULE_ID; +} + +} // namespace er + +} // namespace iox + +#endif // IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLING_HPP diff --git a/iceoryx_hoofs/reporting/include/iox/iceoryx_hoofs_error_reporting.hpp b/iceoryx_hoofs/reporting/include/iox/iceoryx_hoofs_error_reporting.hpp deleted file mode 100644 index b3747e2517..0000000000 --- a/iceoryx_hoofs/reporting/include/iox/iceoryx_hoofs_error_reporting.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2023 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_REPORTING_ICEORYX_HOOFS_ERROR_REPORTING_HPP -#define IOX_HOOFS_REPORTING_ICEORYX_HOOFS_ERROR_REPORTING_HPP - -// Each module (= some unit with its own errors) must provide the following. - -// 1. Define the errors of the module -#include "iox/iceoryx_hoofs_errors.hpp" - -// 2. Include the custom reporting implementation -#include "iox/error_reporting/custom/error_reporting.hpp" - -// 3. Include the error reporting macro API -#include "iox/error_reporting/macros.hpp" - -#endif // IOX_HOOFS_REPORTING_ICEORYX_HOOFS_ERROR_REPORTING_HPP diff --git a/iceoryx_hoofs/reporting/include/iox/iceoryx_hoofs_errors.hpp b/iceoryx_hoofs/reporting/include/iox/iceoryx_hoofs_errors.hpp deleted file mode 100644 index a541533d2e..0000000000 --- a/iceoryx_hoofs/reporting/include/iox/iceoryx_hoofs_errors.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2023 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_REPORTING_ICEORYX_HOOFS_ERRORS_HPP -#define IOX_HOOFS_REPORTING_ICEORYX_HOOFS_ERRORS_HPP - -#include "iox/error_reporting/types.hpp" -#include "iox/error_reporting/violation.hpp" - -/// @todo iox-#1032 Incomplete and not used yet, will be used in integration or error reporting into -/// iceoryx_hoofs. This is just a sketch/proof of concept. - -namespace iox -{ -namespace hoofs_errors -{ - -using ModuleId = iox::er::ModuleId; - -enum class Code : iox::er::ErrorCode::type -{ - Unknown = 0 -}; - -class Error -{ - public: - explicit Error(Code code = Code::Unknown) - : m_code(static_cast(code)) - { - } - - static constexpr ModuleId module() - { - return MODULE_ID; - } - - iox::er::ErrorCode code() const - { - return m_code; - } - - const char* name() const - { - /// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) temporary mechanism - return errorNames[m_code.value]; - } - - static constexpr ModuleId MODULE_ID{1}; - - protected: - iox::er::ErrorCode m_code; - - /// @todo iox-#1032 Incomplete and not used yet, use a robust compile time mechanism to define names - /// in integration follow up - /// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) temporary mechanism - static constexpr const char* errorNames[] = {"Unknown"}; -}; - -} // namespace hoofs_errors -} // namespace iox - -namespace iox -{ -namespace er -{ - -inline hoofs_errors::Error toError(hoofs_errors::Code code) -{ - return hoofs_errors::Error(code); -} - -inline ModuleId toModule(hoofs_errors::Code) -{ - return hoofs_errors::Error::MODULE_ID; -} - -} // namespace er -} // namespace iox - -#endif // IOX_HOOFS_REPORTING_ICEORYX_HOOFS_ERRORS_HPP diff --git a/iceoryx_hoofs/source/error_handling/error_handling.cpp b/iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp similarity index 53% rename from iceoryx_hoofs/source/error_handling/error_handling.cpp rename to iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp index aba5bbdf68..f11d9225a9 100644 --- a/iceoryx_hoofs/source/error_handling/error_handling.cpp +++ b/iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp @@ -16,14 +16,23 @@ // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" namespace iox { -const char* HOOFS_ERROR_NAMES[] = {HOOFS_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; +// NOLINTJUSTIFICATION Use to map enum tag names to strings +// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays) +const char* const HOOFS_ERROR_NAMES[] = {HOOFS_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; const char* asStringLiteral(const HoofsError error) noexcept { - return HOOFS_ERROR_NAMES[errorToStringIndex(error)]; + auto end = static_cast::type>(HoofsError::DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER); + auto index = static_cast::type>(error); + if(index >= end) { + return "Unknown Error Code!"; + } + // NOLINTJUSTIFICATION Bounds are checked and access is safe + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) + return HOOFS_ERROR_NAMES[index]; } } // namespace iox diff --git a/iceoryx_hoofs/test/.clang-tidy b/iceoryx_hoofs/test/.clang-tidy index eca891619c..9217770085 100644 --- a/iceoryx_hoofs/test/.clang-tidy +++ b/iceoryx_hoofs/test/.clang-tidy @@ -5,6 +5,8 @@ InheritParentConfig: true Checks: ' -cert-err58-cpp, +-cppcoreguidelines-avoid-const-or-ref-data-members +-cppcoreguidelines-avoid-do-while -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-owning-memory, @@ -13,9 +15,14 @@ Checks: ' -readability-identifier-naming, -readability-magic-numbers, ' - ## Justifications for rule deactivation ## # +# * rule: cppcoreguidelines-avoid-const-or-ref-data-members +# justification: this is non-production code and it improves the readability of tests +# +# * rule: cppcoreguidelines-avoid-do-while +# justification: this is non-production code and there is nothing inherently wrong with do-while loops +# # * rule: cert-err58-cpp # justification: caused by TEST_F in gtest with internal macro generated construct: test_info_ # diff --git a/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp index 086da6081a..d68652eed0 100644 --- a/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp +++ b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp @@ -15,7 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/cxx/requires.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_cli_cli_definition.cpp b/iceoryx_hoofs/test/moduletests/test_cli_cli_definition.cpp index 41e325af0d..598873ab78 100644 --- a/iceoryx_hoofs/test/moduletests/test_cli_cli_definition.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cli_cli_definition.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/cli_definition.hpp" #include "iox/optional.hpp" #include "test.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp b/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp index 75bf6e272a..4b22760079 100644 --- a/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" #include "iox/cli/command_line_parser.hpp" #include "iox/function.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_cli_option_definition.cpp b/iceoryx_hoofs/test/moduletests/test_cli_option_definition.cpp index 7298880e34..23fcb0781c 100644 --- a/iceoryx_hoofs/test/moduletests/test_cli_option_definition.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cli_option_definition.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" #include "iox/cli/option_definition.hpp" #include "iox/function.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_concurrent_mpmc_loffli.cpp b/iceoryx_hoofs/test/moduletests/test_concurrent_mpmc_loffli.cpp index 2127801b0d..277f1d0921 100644 --- a/iceoryx_hoofs/test/moduletests/test_concurrent_mpmc_loffli.cpp +++ b/iceoryx_hoofs/test/moduletests/test_concurrent_mpmc_loffli.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iox/detail/mpmc_loffli.hpp" #include "test.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp index 171ae5b402..fff965c87c 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp @@ -17,7 +17,7 @@ #include "iox/fixed_position_container.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/lifetime_and_assignment_tracker.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_container_forward_list.cpp b/iceoryx_hoofs/test/moduletests/test_container_forward_list.cpp index 68a65c807c..48b16a7671 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_forward_list.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_forward_list.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/lifetime_and_assignment_tracker.hpp" #include "iox/attributes.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_container_list.cpp b/iceoryx_hoofs/test/moduletests/test_container_list.cpp index b81becd0a2..0a6389fddd 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_list.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_list.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/lifetime_and_assignment_tracker.hpp" #include "iox/attributes.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_container_vector.cpp b/iceoryx_hoofs/test/moduletests/test_container_vector.cpp index 21db232f58..f41b7b01c0 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_vector.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_vector.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/lifetime_and_assignment_tracker.hpp" #include "iox/vector.hpp" 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 5da1bfad0f..d687635cd6 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test_design_functional_interface_types.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_filesystem_file_reader.cpp b/iceoryx_hoofs/test/moduletests/test_filesystem_file_reader.cpp index 75c6221d10..0368070593 100644 --- a/iceoryx_hoofs/test/moduletests/test_filesystem_file_reader.cpp +++ b/iceoryx_hoofs/test/moduletests/test_filesystem_file_reader.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/testing_logger.hpp" #include "iox/file_reader.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp b/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp index b9249d4883..b24552f10b 100644 --- a/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp +++ b/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "iox/attributes.hpp" #include "iox/function_ref.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp index c8dfc1b14a..76ff67dff5 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iox/expected.hpp" #include "iox/string.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp index 2279ae9166..9a4bb37799 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp @@ -14,7 +14,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_platform/platform_settings.hpp" #include "iox/file_name.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp index d724a02b45..e9a0d8c8bb 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iox/string.hpp" diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl index 9910110c1d..fbb25ad341 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl @@ -32,18 +32,10 @@ inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref testFunction, runInTestThread([&] { testFunction(); }); IOX_TESTING_EXPECT_PANIC(); - if constexpr (std::is_same::value) - { - /// @todo iox-#1032 'hasViolation' should not be necessary - auto hasExpectedError = iox::testing::hasError(expectedError) || iox::testing::hasViolation(); - EXPECT_TRUE(hasExpectedError); - return hasExpectedError; - } - else - { - /// @todo iox-#1032 remove this branch once everything is ported to the new error reporting - return iox::testing::hasPanicked(); - } + /// @todo iox-#1032 'hasViolation' should not be necessary + auto hasExpectedError = iox::testing::hasError(expectedError) || iox::testing::hasViolation(); + EXPECT_TRUE(hasExpectedError); + return hasExpectedError; } inline bool IOX_EXPECT_NO_FATAL_FAILURE(const function_ref testFunction) diff --git a/iceoryx_posh/test/moduletests/test_capro_service.cpp b/iceoryx_posh/test/moduletests/test_capro_service.cpp index 87810063fc..e22f58aa11 100644 --- a/iceoryx_posh/test/moduletests/test_capro_service.cpp +++ b/iceoryx_posh/test/moduletests/test_capro_service.cpp @@ -17,7 +17,7 @@ #include "test.hpp" -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" #include "iceoryx_posh/capro/service_description.hpp" diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 73210d476a..2cba235d2c 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 4f2f2223ba..8f70be7b14 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" diff --git a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp index 4b6d0d7091..96eda40b68 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp @@ -16,7 +16,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/bump_allocator.hpp" diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index 7328280065..1e7a8f2db5 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -15,7 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/barrier.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/internal/mepoo/shared_chunk.hpp" From bd0c8df0b9f58e92fb073194543fb29a7fc9cbdf Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 29 Jan 2024 07:19:55 +0100 Subject: [PATCH 12/21] iox-#1032 Remove old error handling code --- .clang-tidy | 4 + .clang-tidy-diff-scans.txt | 2 - .../internal/binding_c_error_reporting.hpp | 9 +- .../source/binding_c_error_reporting.cpp | 4 +- iceoryx_binding_c/source/c_client.cpp | 2 +- iceoryx_binding_c/source/c_runtime.cpp | 2 +- iceoryx_binding_c/source/c_server.cpp | 2 +- .../source/c_service_discovery.cpp | 2 +- iceoryx_binding_c/test/test.hpp | 2 - iceoryx_examples/iceperf/uds.cpp | 2 +- iceoryx_hoofs/BUILD.bazel | 1 - iceoryx_hoofs/CMakeLists.txt | 1 - .../concurrent/buffer/source/mpmc_loffli.cpp | 2 +- .../include/iox/fixed_position_container.hpp | 2 +- .../container/include/iox/forward_list.hpp | 2 +- iceoryx_hoofs/container/include/iox/list.hpp | 2 +- .../container/include/iox/vector.hpp | 2 +- .../filesystem/source/file_reader.cpp | 2 +- .../include/iox/detail/storable_function.inl | 2 +- .../functional/include/iox/function_ref.hpp | 2 +- .../include/iceoryx_hoofs/cxx/.clang-tidy | 22 --- .../include/iceoryx_hoofs/cxx/requires.hpp | 61 -------- .../error_handling/error_handler.hpp | 144 ------------------ .../iceoryx_hoofs/internal/cxx/.clang-tidy | 1 - .../internal/error_handling/error_handler.inl | 39 ----- .../include/iceoryx_hoofs/cxx/requires.hpp | 48 ++++++ .../memory/include/iox/unique_ptr.hpp | 2 +- .../posix/utility/source/posix_scheduler.cpp | 2 +- .../primitives/include/iox/algorithm.hpp | 2 +- .../reporting/include/iox/assertions.hpp | 29 ++++ .../iox/detail/hoofs_error_reporting.hpp | 15 +- .../include/iox/error_reporting/types.hpp | 9 ++ .../source/hoofs_error_reporting.cpp | 8 +- .../source/error_handling/error_handler.cpp | 53 ------- iceoryx_hoofs/test/.clang-tidy | 1 - .../mocktests/test_error_handler_mock.cpp | 120 --------------- .../test/mocktests/test_fatal_failure.cpp | 4 +- .../test_cli_command_line_parser.cpp | 6 +- .../test_cli_option_definition.cpp | 6 +- iceoryx_hoofs/testing/CMakeLists.txt | 1 - .../iceoryx_hoofs/testing/fatal_failure.hpp | 2 +- .../testing/mocks/error_handler_mock.hpp | 96 ------------ .../testing/mocks/error_handler_mock.cpp | 22 --- .../include/iox/detail/variant_internal.hpp | 2 +- .../vocabulary/include/iox/not_null.hpp | 2 +- .../vocabulary/include/iox/optional.hpp | 2 +- iceoryx_hoofs/vocabulary/include/iox/span.hpp | 2 +- .../internal/posh_error_reporting.hpp | 9 +- iceoryx_posh/source/posh_error_reporting.cpp | 2 +- iceoryx_posh/test/test.hpp | 2 - 50 files changed, 141 insertions(+), 622 deletions(-) delete mode 100644 iceoryx_hoofs/include/iceoryx_hoofs/cxx/.clang-tidy delete mode 100644 iceoryx_hoofs/include/iceoryx_hoofs/cxx/requires.hpp delete mode 100644 iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handler.hpp delete mode 120000 iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/.clang-tidy delete mode 100644 iceoryx_hoofs/include/iceoryx_hoofs/internal/error_handling/error_handler.inl create mode 100644 iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/requires.hpp delete mode 100644 iceoryx_hoofs/source/error_handling/error_handler.cpp delete mode 100644 iceoryx_hoofs/test/mocktests/test_error_handler_mock.cpp delete mode 100644 iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/error_handler_mock.hpp delete mode 100644 iceoryx_hoofs/testing/mocks/error_handler_mock.cpp diff --git a/.clang-tidy b/.clang-tidy index 9a65c1ad1b..201bfa7d35 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -21,6 +21,7 @@ concurrency-*, performance-*, hicpp-*, +-cppcoreguidelines-avoid-do-while -cppcoreguidelines-non-private-member-variables-in-classes, -hicpp-named-parameter, @@ -41,6 +42,9 @@ hicpp-*, ### Temporarily disabled because massive API changes: # * rule: readability-identifier-naming +# * rule: cppcoreguidelines-avoid-do-while -> the new error handling uses 'do{} while(false)' loops +# for the macros to enforce a semicolon at the end; +# can be activated again if we find a better solution ### Justifications for deactivated rules # * rule: readability-avoid-const-params-in-decls diff --git a/.clang-tidy-diff-scans.txt b/.clang-tidy-diff-scans.txt index 507bcafb8b..2bd6660c7e 100644 --- a/.clang-tidy-diff-scans.txt +++ b/.clang-tidy-diff-scans.txt @@ -1,5 +1,3 @@ -./iceoryx_hoofs/include/iceoryx_hoofs/cxx/* - ./iceoryx_hoofs/legacy/**/* ./iceoryx_hoofs/cli/**/* diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp b/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp index 86a0f300f0..7f18c2e699 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp +++ b/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp @@ -31,14 +31,11 @@ // additional includes #include "iox/error_reporting/types.hpp" -/// @todo iox-#1032 Remove once C_BINDING_MODULE_IDENTIFIER is moved to 'ModuleId' in 'error_reporting/types.hpp' -#include "iceoryx_hoofs/error_handling/error_handler.hpp" - namespace iox { // clang-format off -#define C_BINDING_ERRORS(error) \ +#define IOX_BINDING_C_ERRORS(error) \ error(BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY) \ error(BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY) \ error(BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED) \ @@ -59,7 +56,7 @@ namespace iox enum class CBindingError : iox::er::ErrorCode::type { - C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_ENUM) + IOX_BINDING_C_ERRORS(IOX_CREATE_ERROR_ENUM) }; const char* asStringLiteral(const CBindingError error) noexcept; @@ -92,7 +89,7 @@ class CBindingErrorType return "iceoryx_binding_c"; } - static constexpr iox::er::ModuleId MODULE_ID{C_BINDING_MODULE_IDENTIFIER}; + static constexpr iox::er::ModuleId MODULE_ID{iox::er::ModuleId::BINDING_C}; protected: iox::er::ErrorCode m_code; diff --git a/iceoryx_binding_c/source/binding_c_error_reporting.cpp b/iceoryx_binding_c/source/binding_c_error_reporting.cpp index 7a888c7900..2d219692cf 100644 --- a/iceoryx_binding_c/source/binding_c_error_reporting.cpp +++ b/iceoryx_binding_c/source/binding_c_error_reporting.cpp @@ -18,7 +18,7 @@ namespace iox { -const char* C_BINDING_ERROR_NAMES[] = {C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; +const char* BINDING_C_ERROR_NAMES[] = {IOX_BINDING_C_ERRORS(IOX_CREATE_ERROR_STRING)}; const char* asStringLiteral(const CBindingError error) noexcept { @@ -31,6 +31,6 @@ const char* asStringLiteral(const CBindingError error) noexcept } // NOLINTJUSTIFICATION Bounds are checked and access is safe // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) - return C_BINDING_ERROR_NAMES[index]; + return BINDING_C_ERROR_NAMES[index]; } } // namespace iox diff --git a/iceoryx_binding_c/source/c_client.cpp b/iceoryx_binding_c/source/c_client.cpp index 88f8da9e70..385b27aa5f 100644 --- a/iceoryx_binding_c/source/c_client.cpp +++ b/iceoryx_binding_c/source/c_client.cpp @@ -17,8 +17,8 @@ #include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_service_description_translation.hpp" -#include "iceoryx_hoofs/cxx/requires.hpp" #include "iceoryx_posh/popo/untyped_client.hpp" +#include "iox/assertions.hpp" using namespace iox; using namespace iox::popo; diff --git a/iceoryx_binding_c/source/c_runtime.cpp b/iceoryx_binding_c/source/c_runtime.cpp index 99a2a1ab47..441153fb96 100644 --- a/iceoryx_binding_c/source/c_runtime.cpp +++ b/iceoryx_binding_c/source/c_runtime.cpp @@ -15,8 +15,8 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/requires.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/assertions.hpp" using namespace iox; using namespace iox::runtime; diff --git a/iceoryx_binding_c/source/c_server.cpp b/iceoryx_binding_c/source/c_server.cpp index 4857ae7b6e..6e6d50e6de 100644 --- a/iceoryx_binding_c/source/c_server.cpp +++ b/iceoryx_binding_c/source/c_server.cpp @@ -17,8 +17,8 @@ #include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_service_description_translation.hpp" -#include "iceoryx_hoofs/cxx/requires.hpp" #include "iceoryx_posh/popo/untyped_server.hpp" +#include "iox/assertions.hpp" using namespace iox; using namespace iox::popo; diff --git a/iceoryx_binding_c/source/c_service_discovery.cpp b/iceoryx_binding_c/source/c_service_discovery.cpp index 5631a13a26..4e6e233968 100644 --- a/iceoryx_binding_c/source/c_service_discovery.cpp +++ b/iceoryx_binding_c/source/c_service_discovery.cpp @@ -16,8 +16,8 @@ #include "iceoryx_binding_c/internal/c2cpp_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_service_description_translation.hpp" -#include "iceoryx_hoofs/cxx/requires.hpp" #include "iceoryx_posh/runtime/service_discovery.hpp" +#include "iox/assertions.hpp" #include "iox/optional.hpp" using namespace iox; diff --git a/iceoryx_binding_c/test/test.hpp b/iceoryx_binding_c/test/test.hpp index ea1d294820..b98162dc00 100644 --- a/iceoryx_binding_c/test/test.hpp +++ b/iceoryx_binding_c/test/test.hpp @@ -17,8 +17,6 @@ #ifndef IOX_BINDING_C_TEST_HPP #define IOX_BINDING_C_TEST_HPP -#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" - #include #include diff --git a/iceoryx_examples/iceperf/uds.cpp b/iceoryx_examples/iceperf/uds.cpp index cba1683189..c761848c0f 100644 --- a/iceoryx_examples/iceperf/uds.cpp +++ b/iceoryx_examples/iceperf/uds.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "uds.hpp" -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/posix_call.hpp" #include "iox/size.hpp" #include "iox/std_string_support.hpp" diff --git a/iceoryx_hoofs/BUILD.bazel b/iceoryx_hoofs/BUILD.bazel index 1a8a98fe47..1bd006ad85 100644 --- a/iceoryx_hoofs/BUILD.bazel +++ b/iceoryx_hoofs/BUILD.bazel @@ -55,7 +55,6 @@ cc_library( "posix/vocabulary/source/*.cpp", "primitives/source/*.cpp", "reporting/source/*.cpp", - "source/**/*.cpp", "time/source/*.cpp", "utility/source/*.cpp", "vocabulary/source/**/*.cpp", diff --git a/iceoryx_hoofs/CMakeLists.txt b/iceoryx_hoofs/CMakeLists.txt index 7d20bc45a2..e9c0c2270d 100644 --- a/iceoryx_hoofs/CMakeLists.txt +++ b/iceoryx_hoofs/CMakeLists.txt @@ -120,7 +120,6 @@ iox_add_library( reporting/source/hoofs_error_reporting.cpp reporting/source/console_logger.cpp reporting/source/logger.cpp - source/error_handling/error_handler.cpp time/source/duration.cpp utility/source/unique_id.cpp diff --git a/iceoryx_hoofs/concurrent/buffer/source/mpmc_loffli.cpp b/iceoryx_hoofs/concurrent/buffer/source/mpmc_loffli.cpp index e14b803bad..345f41f718 100644 --- a/iceoryx_hoofs/concurrent/buffer/source/mpmc_loffli.cpp +++ b/iceoryx_hoofs/concurrent/buffer/source/mpmc_loffli.cpp @@ -16,8 +16,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/detail/mpmc_loffli.hpp" -#include "iceoryx_hoofs/cxx/requires.hpp" #include "iceoryx_platform/platform_correction.hpp" +#include "iox/assertions.hpp" namespace iox { diff --git a/iceoryx_hoofs/container/include/iox/fixed_position_container.hpp b/iceoryx_hoofs/container/include/iox/fixed_position_container.hpp index c87426aa92..8d8102fe5d 100644 --- a/iceoryx_hoofs/container/include/iox/fixed_position_container.hpp +++ b/iceoryx_hoofs/container/include/iox/fixed_position_container.hpp @@ -17,8 +17,8 @@ #ifndef IOX_HOOFS_CONTAINER_FIXED_POSITION_CONTAINER_HPP #define IOX_HOOFS_CONTAINER_FIXED_POSITION_CONTAINER_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" #include "iox/algorithm.hpp" +#include "iox/assertions.hpp" #include "iox/move_and_copy_helper.hpp" #include "iox/uninitialized_array.hpp" diff --git a/iceoryx_hoofs/container/include/iox/forward_list.hpp b/iceoryx_hoofs/container/include/iox/forward_list.hpp index a16e42baaf..9492d32430 100644 --- a/iceoryx_hoofs/container/include/iox/forward_list.hpp +++ b/iceoryx_hoofs/container/include/iox/forward_list.hpp @@ -18,7 +18,7 @@ #ifndef IOX_HOOFS_CONTAINER_FORWARD_LIST_HPP #define IOX_HOOFS_CONTAINER_FORWARD_LIST_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/uninitialized_array.hpp" #include diff --git a/iceoryx_hoofs/container/include/iox/list.hpp b/iceoryx_hoofs/container/include/iox/list.hpp index f7abf17070..0742458725 100644 --- a/iceoryx_hoofs/container/include/iox/list.hpp +++ b/iceoryx_hoofs/container/include/iox/list.hpp @@ -18,7 +18,7 @@ #ifndef IOX_HOOFS_CONTAINER_LIST_HPP #define IOX_HOOFS_CONTAINER_LIST_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/uninitialized_array.hpp" #include diff --git a/iceoryx_hoofs/container/include/iox/vector.hpp b/iceoryx_hoofs/container/include/iox/vector.hpp index 961af97ade..30fd55192d 100644 --- a/iceoryx_hoofs/container/include/iox/vector.hpp +++ b/iceoryx_hoofs/container/include/iox/vector.hpp @@ -17,8 +17,8 @@ #ifndef IOX_HOOFS_CONTAINER_VECTOR_HPP #define IOX_HOOFS_CONTAINER_VECTOR_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" #include "iox/algorithm.hpp" +#include "iox/assertions.hpp" #include "iox/attributes.hpp" #include "iox/logging.hpp" #include "iox/uninitialized_array.hpp" diff --git a/iceoryx_hoofs/filesystem/source/file_reader.cpp b/iceoryx_hoofs/filesystem/source/file_reader.cpp index 2019f25f70..957a43dea5 100644 --- a/iceoryx_hoofs/filesystem/source/file_reader.cpp +++ b/iceoryx_hoofs/filesystem/source/file_reader.cpp @@ -16,7 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/file_reader.hpp" -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/logging.hpp" #include "iceoryx_platform/platform_correction.hpp" diff --git a/iceoryx_hoofs/functional/include/iox/detail/storable_function.inl b/iceoryx_hoofs/functional/include/iox/detail/storable_function.inl index be6320eff2..bb3ae00081 100644 --- a/iceoryx_hoofs/functional/include/iox/detail/storable_function.inl +++ b/iceoryx_hoofs/functional/include/iox/detail/storable_function.inl @@ -17,7 +17,7 @@ #ifndef IOX_HOOFS_FUNCTIONAL_STORABLE_FUNCTION_INL #define IOX_HOOFS_FUNCTIONAL_STORABLE_FUNCTION_INL -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/detail/storable_function.hpp" #include "iox/memory.hpp" diff --git a/iceoryx_hoofs/functional/include/iox/function_ref.hpp b/iceoryx_hoofs/functional/include/iox/function_ref.hpp index 7f6584199f..6d012096b3 100644 --- a/iceoryx_hoofs/functional/include/iox/function_ref.hpp +++ b/iceoryx_hoofs/functional/include/iox/function_ref.hpp @@ -21,7 +21,7 @@ #define IOX_HOOFS_FUNCTIONAL_FUNCTION_REF_HPP // AXIVION Next Line AutosarC++19_03-A16.2.2 : Needed for IOX_EXPECTS and IOX_ENSURES macros -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/type_traits.hpp" #include diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/.clang-tidy b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/.clang-tidy deleted file mode 100644 index 73e5767e53..0000000000 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/.clang-tidy +++ /dev/null @@ -1,22 +0,0 @@ -# Symlinked to: -# iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/.clang-tidy -# iceoryx_hoofs/source/cxx/.clang-tidy -# iceoryx_platform/.clang-tidy - -InheritParentConfig: true - -CheckOptions: - # - { key: readability-identifier-naming.ClassCase, value: lower_case } - # - { key: readability-identifier-naming.EnumCase, value: lower_case } - # - { key: readability-identifier-naming.StructCase, value: lower_case } - # - { key: readability-identifier-naming.UnionCase, value: lower_case } - # - { key: readability-identifier-naming.MethodCase, value: lower_case } - # - { key: readability-identifier-naming.FunctionCase, value: lower_case } - # - { key: readability-identifier-naming.NamespaceCase, value: lower_case } - - { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ } - - { key: readability-identifier-naming.ProtectedMemberPrefix, value: m_ } - - { key: readability-identifier-naming.MemberCase, value: camelBack } - - { key: readability-identifier-naming.ConstexprVariableCase, value: UPPER_CASE } - - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE } - - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } - - { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase } diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/requires.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/requires.hpp deleted file mode 100644 index f92c9cc5cc..0000000000 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/requires.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. -// Copyright (c) 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_CXX_REQUIRES_HPP -#define IOX_HOOFS_CXX_REQUIRES_HPP - -#include "iceoryx_platform/platform_correction.hpp" -#include "iox/assertions.hpp" - -// implementing C++ Core Guideline, I.6. Prefer Expects -// see: -// https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-expects -/// @NOLINTJUSTIFICATION macro required to capture file, line, function origin of call implicitly -/// @NOLINTBEGIN(cppcoreguidelines-macro-usage) -/// @NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro -/// @NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -#define IOX_EXPECTS(condition) IOX_ENFORCE(condition, "") -/// @NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -/// @NOLINTEND(cppcoreguidelines-macro-usage) - -/// @NOLINTJUSTIFICATION macro required to capture file, line, function origin of call implicitly -/// @NOLINTBEGIN(cppcoreguidelines-macro-usage) -/// @NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro -/// @NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -#define IOX_EXPECTS_WITH_MSG(condition, msg) IOX_ENFORCE(condition, msg) -/// @NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -/// @NOLINTEND(cppcoreguidelines-macro-usage) - -// implementing C++ Core Guideline, I.8. Prefer Ensures -// see: -// https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-ensures -/// @NOLINTJUSTIFICATION macro required to capture file, line, function origin of call implicitly -/// @NOLINTBEGIN(cppcoreguidelines-macro-usage) -/// @NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro -/// @NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -#define IOX_ENSURES(condition) IOX_ENFORCE(condition, "") -/// @NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -/// @NOLINTEND(cppcoreguidelines-macro-usage) - -/// @NOLINTJUSTIFICATION macro required to capture file, line, function origin of call implicitly -/// @NOLINTBEGIN(cppcoreguidelines-macro-usage) -/// @NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro -/// @NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -#define IOX_ENSURES_WITH_MSG(condition, msg) IOX_ENFORCE(condition, msg) -/// @NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) -/// @NOLINTEND(cppcoreguidelines-macro-usage) - -#endif diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handler.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handler.hpp deleted file mode 100644 index c07e4b0ef9..0000000000 --- a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handler.hpp +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. -// Copyright (c) 2020 - 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_ERROR_HANDLING_ERROR_HANDLER_HPP -#define IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLER_HPP - -#include "iox/function.hpp" -#include "iox/log/logger.hpp" -#include "iox/logging.hpp" -#include "iox/scope_guard.hpp" - -#include - -namespace iox -{ -constexpr uint16_t HOOFS_MODULE_IDENTIFIER{1}; -constexpr uint16_t POSH_MODULE_IDENTIFIER{2}; -constexpr uint16_t C_BINDING_MODULE_IDENTIFIER{3}; -// Every identifier larger than USER_DEFINED_MODULE_IDENTIFIER can be used externally -constexpr uint16_t USER_DEFINED_MODULE_IDENTIFIER{256}; - -constexpr uint8_t ERROR_ENUM_OFFSET_IN_BITS{16}; - -#define CREATE_ICEORYX_ERROR_ENUM(name) name, -#define CREATE_ICEORYX_ERROR_STRING(name) #name, - -/// @brief the available error levels -/// FATAL -/// - Log message with FATAL -/// - Application cannot recover from that error and is terminated -/// - Assert (in DEBUG) and terminate -/// - Reporting code must handle this and continue or go to a save state. Error handler could return (e.g. in test) -/// SEVERE -/// - Log message with ERROR -/// - Application can still run. Error is reported -/// - Assert in DEBUG, in RELEASE continue to run -/// - Reporting code must handle this and continue -/// MODERATE -/// - Log message with ERROR -/// - Application can still run. Error is reported -/// - NO assert -/// - Reporting code must handle this and continue -enum class ErrorLevel : uint32_t -{ - /// Log error entry + Assert + terminate - FATAL, - /// warning log entry + Assert - SEVERE, - /// warning log entry - MODERATE -}; - -/// @brief Howto use the error handler correctly -/// 1.) Use the macro ICEORYX_ERRORS(error) to create the enum for your component and -/// add new errors like: -/// error(MODULE_NAME__MY_FUNKY_ERROR) -/// Attention: Create an error after the following convention: -/// MODULE_NAME__A_CLEAR_BUT_SHORT_ERROR_DESCRIPTION -/// And a long name is alright! -/// -/// 2.) Add a new FOO_MODULE_IDENTIFIER at the top of this file or use -/// USER_DEFINED_MODULE_IDENTIFIER as the first entry in the enum: -/// - NO_ERROR = FOO_MODULE_IDENTIFIER << ERROR_ENUM_OFFSET_IN_BITS -/// - NO_ERROR = USER_DEFINED_MODULE_IDENTIFIER << ERROR_ENUM_OFFSET_IN_BITS -/// -/// 3.) Specialize the following methods for your NewEnumErrorType: -/// - const char* asStringLiteral(const NewEnumErrorType error) -/// -/// 4.) Call errorHandler(Error::MODULE_NAME__MY_FUNKY_ERROR); -/// The defaults for ErrorLevel can also be overwritten: -/// errorHandler( -/// Error::MODULE_NAME__MY_FUNKY_ERROR, -/// ErrorLevel::MODERATE -/// ); -/// -/// @code -/// // definition of error_handling.hpp for module 'foo' -/// #define FOO_ERRORS(error) '\' -/// error(PRETTY_CLASS__DIVISION_BY_ZERO) -/// -/// enum class FooError : uint32_t -/// { -/// NO_ERROR = FOO_MODULE_IDENTIFIER << ERROR_ENUM_OFFSET_IN_BITS, -/// FOO_ERRORS(CREATE_ICEORYX_ERROR_ENUM) -/// }; -/// -/// const char* asStringLiteral(const FooError error) noexcept; -/// -/// // usage of the module -/// #include "module_foo/error_handling.hpp" -/// -/// class PrettyClass { -/// float division(float a, float b) { -/// if ( b == 0.0f ) { -/// errorHandler(FooError::PRETTY_CLASS__DIVISION_BY_ZERO); -/// } -/// } -/// }; -/// @endcode -/// -/// @tparam[in] Error type which is used to report the error (typically an enum) -template -void errorHandler(const Error error, const ErrorLevel level = ErrorLevel::FATAL) noexcept; - -using HandlerFunction = function; - -/// @brief Converts an error into its index assuming the enum starts with 'NO_ERROR' -/// @tparam[in] Error type which is used to report the error (typically an enum) -/// @return Use the underlying enum type as return value -template -auto errorToStringIndex(Error error) noexcept; - -class ErrorHandler -{ - template - friend void errorHandler(const Error error, const ErrorLevel level) noexcept; - - protected: - static void reactOnErrorLevel(const ErrorLevel level, const char* errorText) noexcept; - - static void - defaultHandler(const uint32_t error, const char* errorName, const ErrorLevel level = ErrorLevel::FATAL) noexcept; - - static iox::HandlerFunction handler; -}; - -} // namespace iox - -#include "iceoryx_hoofs/internal/error_handling/error_handler.inl" - -#endif // IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLER_HPP diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/.clang-tidy b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/.clang-tidy deleted file mode 120000 index 2fe55de1ca..0000000000 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/.clang-tidy +++ /dev/null @@ -1 +0,0 @@ -../../cxx/.clang-tidy \ No newline at end of file diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/error_handling/error_handler.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/error_handling/error_handler.inl deleted file mode 100644 index dc22d161e3..0000000000 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/error_handling/error_handler.inl +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 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_ERROR_HANDLING_ERROR_HANDLER_INL -#define IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLER_INL - -#include "iceoryx_hoofs/error_handling/error_handler.hpp" - -namespace iox -{ -template -inline void errorHandler(const Error error, const ErrorLevel level) noexcept -{ - ErrorHandler::handler( - static_cast::type>(error), asStringLiteral(error), level); -} - -template -auto errorToStringIndex(Error error) noexcept -{ - return static_cast::type>(error) - - static_cast::type>(Error::NO_ERROR) - 1; -} - -} // namespace iox - -#endif // IOX_HOOFS_ERROR_HANDLING_ERROR_HANDLER_INL diff --git a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/requires.hpp b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/requires.hpp new file mode 100644 index 0000000000..eac66a97c4 --- /dev/null +++ b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/requires.hpp @@ -0,0 +1,48 @@ +// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 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_CXX_REQUIRES_HPP +#define IOX_HOOFS_CXX_REQUIRES_HPP + +#include "iceoryx_platform/platform_correction.hpp" +#include "iox/assertions.hpp" +#include "iox/detail/deprecation_marker.hpp" + +IOX_DEPRECATED_HEADER_SINCE(3, "Please include 'iox/assertions.hpp' and 'IOX_ENFORCE' instead of 'Expects'/'Ensures'.") + +namespace iox +{ +/// @todo iox-#1593 Deprecate namespace with +/// namespace IOX_DEPRECATED_SINCE(3, "Please use the 'iox' namespace directly and the corresponding header.") +namespace cxx +{ + +// NOLINTBEGIN(cppcoreguidelines-macro-usage) deprecated; used for legacy code +// implementing C++ Core Guideline, I.6. Prefer Expects +// see: +// https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-expects +#define Expects(condition) IOX_ENFORCE(condition, "") + +// implementing C++ Core Guideline, I.8. Prefer Ensures +// see: +// https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-ensures +#define Ensures(condition) IOX_ENFORCE(condition, "") +// NOLINTEND(cppcoreguidelines-macro-usage) + +} // namespace cxx +} // namespace iox + +#endif diff --git a/iceoryx_hoofs/memory/include/iox/unique_ptr.hpp b/iceoryx_hoofs/memory/include/iox/unique_ptr.hpp index 7249bf9532..d96a8054fd 100644 --- a/iceoryx_hoofs/memory/include/iox/unique_ptr.hpp +++ b/iceoryx_hoofs/memory/include/iox/unique_ptr.hpp @@ -18,7 +18,7 @@ #ifndef IOX_HOOFS_MEMORY_UNIQUE_PTR_HPP #define IOX_HOOFS_MEMORY_UNIQUE_PTR_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/function.hpp" #include diff --git a/iceoryx_hoofs/posix/utility/source/posix_scheduler.cpp b/iceoryx_hoofs/posix/utility/source/posix_scheduler.cpp index 1ff1d5becf..b6fe00331b 100644 --- a/iceoryx_hoofs/posix/utility/source/posix_scheduler.cpp +++ b/iceoryx_hoofs/posix/utility/source/posix_scheduler.cpp @@ -15,7 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/detail/posix_scheduler.hpp" -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/logging.hpp" #include "iox/posix_call.hpp" diff --git a/iceoryx_hoofs/primitives/include/iox/algorithm.hpp b/iceoryx_hoofs/primitives/include/iox/algorithm.hpp index b599bc93ef..6f61eab3f2 100644 --- a/iceoryx_hoofs/primitives/include/iox/algorithm.hpp +++ b/iceoryx_hoofs/primitives/include/iox/algorithm.hpp @@ -17,7 +17,7 @@ #ifndef IOX_HOOFS_PRIMITIVES_ALGORITHM_HPP #define IOX_HOOFS_PRIMITIVES_ALGORITHM_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/attributes.hpp" #include "iox/type_traits.hpp" diff --git a/iceoryx_hoofs/reporting/include/iox/assertions.hpp b/iceoryx_hoofs/reporting/include/iox/assertions.hpp index 34fd8fcf76..2aef7bda51 100644 --- a/iceoryx_hoofs/reporting/include/iox/assertions.hpp +++ b/iceoryx_hoofs/reporting/include/iox/assertions.hpp @@ -90,6 +90,35 @@ iox::er::forwardPanic(IOX_CURRENT_SOURCE_LOCATION, "Reached code that was supposed to be unreachable."); \ } while (false) + +/// @todo iox-#1032 replace IOX_EXPECTS and IOX_ENSURES with IOX_ENFORCE +// implementing C++ Core Guideline, I.6. Prefer Expects +// see: +// https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-expects +// NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro +// NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) +#define IOX_EXPECTS(condition) IOX_ENFORCE(condition, "") +// NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) + +// NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro +// NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) +#define IOX_EXPECTS_WITH_MSG(condition, msg) IOX_ENFORCE(condition, msg) +// NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) + +// implementing C++ Core Guideline, I.8. Prefer Ensures +// see: +// https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-ensures +// NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro +// NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) +#define IOX_ENSURES(condition) IOX_ENFORCE(condition, "") +// NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) + +// NOLINTJUSTIFICATION array decay: needed for source code location, safely wrapped in macro +// NOLINTBEGIN(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) +#define IOX_ENSURES_WITH_MSG(condition, msg) IOX_ENFORCE(condition, msg) +// NOLINTEND(hicpp-no-array-decay, cppcoreguidelines-pro-bounds-array-to-pointer-decay) + + // NOLINTEND(cppcoreguidelines-macro-usage) #endif // IOX_HOOFS_REPORTING_ASSERTIONS_HPP diff --git a/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp b/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp index 9c5c6386ea..1fb4c50394 100644 --- a/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp +++ b/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp @@ -30,13 +30,13 @@ // additional includes #include "iox/error_reporting/types.hpp" -/// @todo iox-#1032 Remove once HOOFS_MODULE_IDENTIFIER is moved to 'ModuleId' in 'error_reporting/types.hpp' -#include "iceoryx_hoofs/error_handling/error_handler.hpp" - namespace iox { // clang-format off -#define HOOFS_ERRORS(error) \ + +// NOLINTJUSTIFICATION This macro is usee to define an enum and an array with corresponding enum tag names +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define IOX_HOOFS_ERRORS(error) \ error(EXPECTS_ENSURES_FAILED) \ error(DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER) // keep this always at the end of the error list @@ -48,7 +48,7 @@ namespace iox enum class HoofsError : iox::er::ErrorCode::type { - HOOFS_ERRORS(CREATE_ICEORYX_ERROR_ENUM) + IOX_HOOFS_ERRORS(IOX_CREATE_ERROR_ENUM) }; const char* asStringLiteral(const HoofsError error) noexcept; @@ -76,11 +76,12 @@ class HoofsErrorType return asStringLiteral(static_cast(m_code.value)); } - const char* moduleName() const { + static const char* moduleName() + { return "iceoryx_hoofs"; } - static constexpr iox::er::ModuleId MODULE_ID{POSH_MODULE_IDENTIFIER}; + static constexpr iox::er::ModuleId MODULE_ID{iox::er::ModuleId::HOOFS}; protected: iox::er::ErrorCode m_code; diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/types.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/types.hpp index 529025374a..84fb6e1195 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/types.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/types.hpp @@ -60,6 +60,9 @@ struct ModuleId type value; static constexpr type ANY{0}; + static constexpr type HOOFS{1}; + static constexpr type POSH{2}; + static constexpr type BINDING_C{3}; // User module ids should be larger or equal than this to avoid conflicts // with internal modules. @@ -123,4 +126,10 @@ inline const char* toErrorName(const Error& error) } // namespace er } // namespace iox +// NOLINTJUSTIFICATION These macros are used to create enums and corresponding string arrays with the names of the enum tags +// NOLINTBEGIN(cppcoreguidelines-macro-usage) +#define IOX_CREATE_ERROR_ENUM(name) name, +#define IOX_CREATE_ERROR_STRING(name) #name, +// NOLINTEND(cppcoreguidelines-macro-usage) + #endif // IOX_HOOFS_REPORTING_ERROR_REPORTING_TYPES_HPP diff --git a/iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp b/iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp index f11d9225a9..537d1910b2 100644 --- a/iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp +++ b/iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp @@ -22,13 +22,15 @@ namespace iox { // NOLINTJUSTIFICATION Use to map enum tag names to strings // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays) -const char* const HOOFS_ERROR_NAMES[] = {HOOFS_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; +const char* const HOOFS_ERROR_NAMES[] = {IOX_HOOFS_ERRORS(IOX_CREATE_ERROR_STRING)}; const char* asStringLiteral(const HoofsError error) noexcept { - auto end = static_cast::type>(HoofsError::DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER); + auto end = + static_cast::type>(HoofsError::DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER); auto index = static_cast::type>(error); - if(index >= end) { + if (index >= end) + { return "Unknown Error Code!"; } // NOLINTJUSTIFICATION Bounds are checked and access is safe diff --git a/iceoryx_hoofs/source/error_handling/error_handler.cpp b/iceoryx_hoofs/source/error_handling/error_handler.cpp deleted file mode 100644 index 4e1e694afe..0000000000 --- a/iceoryx_hoofs/source/error_handling/error_handler.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. -// 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 - -#include "iceoryx_hoofs/error_handling/error_handler.hpp" -#include "iox/assertions.hpp" - -#include - -namespace iox -{ -// NOLINTNEXTLINE(cert-err58-cpp) ErrorHander only used in tests -iox::HandlerFunction ErrorHandler::handler = {ErrorHandler::defaultHandler}; - -void ErrorHandler::defaultHandler(const uint32_t, const char* errorName, const ErrorLevel level) noexcept -{ - reactOnErrorLevel(level, errorName); -} - -void ErrorHandler::reactOnErrorLevel(const ErrorLevel level, const char* errorName) noexcept -{ - constexpr const char ERROR_TEXT[] = "ICEORYX error! "; - - switch (level) - { - case ErrorLevel::FATAL: - IOX_LOG(ERROR, ERROR_TEXT << errorName); - IOX_PANIC("Fatal error detected!"); - break; - case ErrorLevel::SEVERE: - IOX_LOG(WARN, ERROR_TEXT << errorName); - assert(false); - break; - case ErrorLevel::MODERATE: - IOX_LOG(WARN, ERROR_TEXT << errorName); - break; - } -} - -} // namespace iox diff --git a/iceoryx_hoofs/test/.clang-tidy b/iceoryx_hoofs/test/.clang-tidy index 9217770085..3da91a32e3 100644 --- a/iceoryx_hoofs/test/.clang-tidy +++ b/iceoryx_hoofs/test/.clang-tidy @@ -6,7 +6,6 @@ InheritParentConfig: true Checks: ' -cert-err58-cpp, -cppcoreguidelines-avoid-const-or-ref-data-members --cppcoreguidelines-avoid-do-while -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-owning-memory, diff --git a/iceoryx_hoofs/test/mocktests/test_error_handler_mock.cpp b/iceoryx_hoofs/test/mocktests/test_error_handler_mock.cpp deleted file mode 100644 index 373d137644..0000000000 --- a/iceoryx_hoofs/test/mocktests/test_error_handler_mock.cpp +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) 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 - -#include "iceoryx_hoofs/error_handling/error_handler.hpp" -#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" - -#include "test.hpp" -#include - -namespace -{ -using namespace ::testing; - -constexpr uint16_t MODULE_IDENTIFIER_OFFSET{42}; - -// clang-format off -#define TEST_ERRORS(error) \ - error(TEST__FOOBAR) \ - error(TEST__BARFOO) -// clang-format on - -const char* TEST_ERROR_NAMES[] = {TEST_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; - -enum class KnownError : uint32_t -{ - NO_ERROR = iox::USER_DEFINED_MODULE_IDENTIFIER << iox::ERROR_ENUM_OFFSET_IN_BITS, - TEST_ERRORS(CREATE_ICEORYX_ERROR_ENUM) -}; - -enum class UnknownError : uint32_t -{ - NO_ERROR = (iox::USER_DEFINED_MODULE_IDENTIFIER + MODULE_IDENTIFIER_OFFSET) << iox::ERROR_ENUM_OFFSET_IN_BITS, - TEST_ERRORS(CREATE_ICEORYX_ERROR_ENUM) -}; - -const char* asStringLiteral(const KnownError error) noexcept -{ - return TEST_ERROR_NAMES[iox::errorToStringIndex(error)]; -} - -const char* asStringLiteral(const UnknownError error) noexcept -{ - return TEST_ERROR_NAMES[iox::errorToStringIndex(error)]; -} - -TEST(ErrorHandlerMock_test, UnsettingTemporaryErrorHandlerWithKnownModuleWorks) -{ - ::testing::Test::RecordProperty("TEST_ID", "5b8e3974-42d3-45d9-88bd-07b5213c5b57"); - { - auto errorHandlerGuard = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](const auto, const iox::ErrorLevel) { GTEST_FAIL() << "Temporary ErrorHandler shall not be called"; }); - } - iox::errorHandler(KnownError::TEST__FOOBAR, iox::ErrorLevel::MODERATE); -} - -TEST(ErrorHandlerMock_test, CallingErrorHandlerWithErrorOfKnownModuleAndDefaultLevelIsCaught) -{ - ::testing::Test::RecordProperty("TEST_ID", "988401f2-9eb0-4246-868c-3057dd6c2560"); - iox::optional detectedError; - iox::optional detectedLevel; - auto errorHandlerGuard = - iox::ErrorHandlerMock::setTemporaryErrorHandler([&](const auto error, const iox::ErrorLevel level) { - detectedError.emplace(error); - detectedLevel.emplace(level); - }); - - iox::errorHandler(KnownError::TEST__FOOBAR); - - ASSERT_TRUE(detectedError.has_value()); - EXPECT_THAT(detectedError.value(), Eq(KnownError::TEST__FOOBAR)); - ASSERT_TRUE(detectedLevel.has_value()); - EXPECT_THAT(detectedLevel.value(), Eq(iox::ErrorLevel::FATAL)); -} - -TEST(ErrorHandlerMock_test, CallingErrorHandlerWithErrorOfKnownModuleAndNonDefaultLevelIsCaught) -{ - ::testing::Test::RecordProperty("TEST_ID", "df123c54-a089-4515-87ff-cc16206d45af"); - iox::optional detectedError; - iox::optional detectedLevel; - auto errorHandlerGuard = - iox::ErrorHandlerMock::setTemporaryErrorHandler([&](const auto error, const iox::ErrorLevel level) { - detectedError.emplace(error); - detectedLevel.emplace(level); - }); - - iox::errorHandler(KnownError::TEST__FOOBAR, iox::ErrorLevel::MODERATE); - - ASSERT_TRUE(detectedError.has_value()); - EXPECT_THAT(detectedError.value(), Eq(KnownError::TEST__FOOBAR)); - ASSERT_TRUE(detectedLevel.has_value()); - EXPECT_THAT(detectedLevel.value(), Eq(iox::ErrorLevel::MODERATE)); -} - -TEST(ErrorHandlerMock_test, CallingErrorHandlerWithErrorOfUnknownModuleCallsGTestFail) -{ - ::testing::Test::RecordProperty("TEST_ID", "10a50c0c-e21b-4c4f-ab0e-5ed2a4a14b3f"); - auto errorHandlerGuard = - iox::ErrorHandlerMock::setTemporaryErrorHandler([&](const auto error, const iox::ErrorLevel level) { - EXPECT_THAT(error, Eq(KnownError::TEST__FOOBAR)); - EXPECT_THAT(level, Eq(iox::ErrorLevel::FATAL)); - }); - EXPECT_FATAL_FAILURE({ iox::errorHandler(UnknownError::TEST__FOOBAR); }, - "errorName: TEST__FOOBAR, expected error enum type: " - + std::to_string(iox::USER_DEFINED_MODULE_IDENTIFIER) + ", actual error enum type: " - + std::to_string(iox::USER_DEFINED_MODULE_IDENTIFIER + MODULE_IDENTIFIER_OFFSET)); -} -} // namespace diff --git a/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp index d68652eed0..630198099a 100644 --- a/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp +++ b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp @@ -14,9 +14,9 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/requires.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" +#include "iox/assertions.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "test.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp b/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp index 4b22760079..ecda9eba31 100644 --- a/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cli_command_line_parser.cpp @@ -14,15 +14,15 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" #include "iox/cli/command_line_parser.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/function.hpp" #include "iox/optional.hpp" #include "iox/std_string_support.hpp" -#include "test.hpp" #include "test_cli_command_line_common.hpp" + #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "test.hpp" #include #include diff --git a/iceoryx_hoofs/test/moduletests/test_cli_option_definition.cpp b/iceoryx_hoofs/test/moduletests/test_cli_option_definition.cpp index 23fcb0781c..250ed691c9 100644 --- a/iceoryx_hoofs/test/moduletests/test_cli_option_definition.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cli_option_definition.cpp @@ -14,14 +14,14 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" #include "iox/cli/option_definition.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/function.hpp" #include "iox/optional.hpp" -#include "test.hpp" #include "test_cli_command_line_common.hpp" +#include "test.hpp" + #include #include #include diff --git a/iceoryx_hoofs/testing/CMakeLists.txt b/iceoryx_hoofs/testing/CMakeLists.txt index 33fd5d6c5f..4e9f3cabc5 100644 --- a/iceoryx_hoofs/testing/CMakeLists.txt +++ b/iceoryx_hoofs/testing/CMakeLists.txt @@ -33,7 +33,6 @@ iox_add_library( FILES compile_test.cpp mocks/time_mock.cpp - mocks/error_handler_mock.cpp testing_logger.cpp timing_test.cpp error_reporting/testing_error_handler.cpp diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp index 435c036d64..401ca36b8f 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp @@ -17,9 +17,9 @@ #ifndef IOX_HOOFS_TESTING_FATAL_FAILURE_HPP #define IOX_HOOFS_TESTING_FATAL_FAILURE_HPP -#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" #include "iox/function_ref.hpp" #include "iox/optional.hpp" + #include "test.hpp" #include diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/error_handler_mock.hpp b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/error_handler_mock.hpp deleted file mode 100644 index f79df7f465..0000000000 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/error_handler_mock.hpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) 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_TESTUTILS_ERROR_HANDLER_MOCK_HPP -#define IOX_HOOFS_TESTUTILS_ERROR_HANDLER_MOCK_HPP - -#include "iceoryx_hoofs/error_handling/error_handler.hpp" -#include "iox/function.hpp" -#include "iox/scope_guard.hpp" -#include - -#include "iceoryx_hoofs/testing/test.hpp" - -namespace iox -{ -template -using TypedHandlerFunction = function; - -/// @brief This mock is needed for unit testing, special debugging cases and -/// other corner cases where we'd like to explicitly suppress the -/// error handling. -/// -/// @code -/// bool called = false; -/// auto temporaryErrorHandler = ErrorHandlerMock::setTemporaryErrorHandler( -/// [&](const Error, const ErrorLevel) { -/// called = true; -/// }); -/// -/// errorHandler(Error::TEST__ASSERT_CALLED); -/// ASSERT_TRUE(called); -/// @endcode -class ErrorHandlerMock : protected ErrorHandler -{ - public: - template - static ScopeGuard setTemporaryErrorHandler(const TypedHandlerFunction& newHandler) noexcept; - - protected: - static std::mutex m_handlerMutex; -}; - -template -optional> typedHandler; - -template -inline void errorHandlerForTest(const uint32_t error, const char* errorName, const ErrorLevel level) noexcept -{ - uint32_t errorModuleIdentifier = error >> ERROR_ENUM_OFFSET_IN_BITS; - uint32_t expectedErrorModuleIdentifier = - static_cast::type>(ErrorEnumType::NO_ERROR) - >> ERROR_ENUM_OFFSET_IN_BITS; - - if (errorModuleIdentifier == expectedErrorModuleIdentifier) - { - // We undo the type erasure - auto typedError = static_cast(error); - typedHandler.and_then( - [&](TypedHandlerFunction storedHandler) { storedHandler(typedError, level); }); - } - else - { - GTEST_FAIL() << "errorName: " << errorName << ", expected error enum type: " << expectedErrorModuleIdentifier - << ", actual error enum type: " << errorModuleIdentifier; - } -} - -template -inline ScopeGuard ErrorHandlerMock::setTemporaryErrorHandler(const TypedHandlerFunction& newHandler) noexcept -{ - return ScopeGuard( - [&newHandler] { - std::lock_guard lock(m_handlerMutex); - typedHandler.emplace(newHandler); - handler = errorHandlerForTest; - }, - [] { - std::lock_guard lock(m_handlerMutex); - typedHandler.reset(); - handler = defaultHandler; - }); -} -} // namespace iox -#endif // IOX_HOOFS_TESTUTILS_ERROR_HANDLER_MOCK_HPP diff --git a/iceoryx_hoofs/testing/mocks/error_handler_mock.cpp b/iceoryx_hoofs/testing/mocks/error_handler_mock.cpp deleted file mode 100644 index 744c479b22..0000000000 --- a/iceoryx_hoofs/testing/mocks/error_handler_mock.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 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 - -#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" - -namespace iox -{ -std::mutex ErrorHandlerMock::m_handlerMutex; -} // namespace iox diff --git a/iceoryx_hoofs/vocabulary/include/iox/detail/variant_internal.hpp b/iceoryx_hoofs/vocabulary/include/iox/detail/variant_internal.hpp index a348373340..040826e3fd 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/detail/variant_internal.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/detail/variant_internal.hpp @@ -17,7 +17,7 @@ #ifndef IOX_HOOFS_VOCABULARY_VARIANT_INTERNAL_HPP #define IOX_HOOFS_VOCABULARY_VARIANT_INTERNAL_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include #include diff --git a/iceoryx_hoofs/vocabulary/include/iox/not_null.hpp b/iceoryx_hoofs/vocabulary/include/iox/not_null.hpp index 720162ad4c..e54a10bb0b 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/not_null.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/not_null.hpp @@ -17,7 +17,7 @@ #ifndef IOX_HOOFS_VOCABULARY_NOT_NULL_HPP #define IOX_HOOFS_VOCABULARY_NOT_NULL_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/type_traits.hpp" namespace iox diff --git a/iceoryx_hoofs/vocabulary/include/iox/optional.hpp b/iceoryx_hoofs/vocabulary/include/iox/optional.hpp index 7fdba52317..f5136e97b4 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/optional.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/optional.hpp @@ -17,7 +17,7 @@ #ifndef IOX_HOOFS_VOCABULARY_OPTIONAL_HPP #define IOX_HOOFS_VOCABULARY_OPTIONAL_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/functional_interface.hpp" #include "iox/iceoryx_hoofs_types.hpp" diff --git a/iceoryx_hoofs/vocabulary/include/iox/span.hpp b/iceoryx_hoofs/vocabulary/include/iox/span.hpp index 69dc0c5e85..a1f86afd46 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/span.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/span.hpp @@ -17,7 +17,7 @@ #ifndef IOX_HOOFS_VOCABULARY_SPAN_HPP #define IOX_HOOFS_VOCABULARY_SPAN_HPP -#include "iceoryx_hoofs/cxx/requires.hpp" +#include "iox/assertions.hpp" #include "iox/detail/span_iterator.hpp" #include "iox/detail/uninitialized_array_type_traits.hpp" #include "iox/size.hpp" diff --git a/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp b/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp index ca5e337f46..ab4e70bc88 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp @@ -31,13 +31,10 @@ // additional includes #include "iox/error_reporting/types.hpp" -/// @todo iox-#1032 Remove once C_BINDING_MODULE_IDENTIFIER is moved to 'ModuleId' in 'error_reporting/types.hpp' -#include "iceoryx_hoofs/error_handling/error_handler.hpp" - namespace iox { // clang-format off -#define POSH_ERRORS(error) \ +#define IOX_POSH_ERRORS(error) \ error(POSH__ROUDI_PROCESS_SHUTDOWN_FAILED) \ error(POSH__ROUDI_PROCESS_SEND_VIA_IPC_CHANNEL_FAILED)\ error(POSH__RUNTIME_FACTORY_IS_NOT_SET) \ @@ -179,7 +176,7 @@ namespace iox enum class PoshError : iox::er::ErrorCode::type { - POSH_ERRORS(CREATE_ICEORYX_ERROR_ENUM) + IOX_POSH_ERRORS(IOX_CREATE_ERROR_ENUM) }; const char* asStringLiteral(const PoshError error) noexcept; @@ -212,7 +209,7 @@ class PoshErrorType return "iceoryx_posh"; } - static constexpr iox::er::ModuleId MODULE_ID{POSH_MODULE_IDENTIFIER}; + static constexpr iox::er::ModuleId MODULE_ID{iox::er::ModuleId::POSH}; protected: iox::er::ErrorCode m_code; diff --git a/iceoryx_posh/source/posh_error_reporting.cpp b/iceoryx_posh/source/posh_error_reporting.cpp index a7e3855085..8a5dad9926 100644 --- a/iceoryx_posh/source/posh_error_reporting.cpp +++ b/iceoryx_posh/source/posh_error_reporting.cpp @@ -18,7 +18,7 @@ namespace iox { -const char* POSH_ERROR_NAMES[] = {POSH_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; +const char* POSH_ERROR_NAMES[] = {IOX_POSH_ERRORS(IOX_CREATE_ERROR_STRING)}; const char* asStringLiteral(const PoshError error) noexcept { diff --git a/iceoryx_posh/test/test.hpp b/iceoryx_posh/test/test.hpp index 20cd1d6c01..d499ead99a 100644 --- a/iceoryx_posh/test/test.hpp +++ b/iceoryx_posh/test/test.hpp @@ -17,8 +17,6 @@ #ifndef IOX_POSH_TEST_TEST_HPP #define IOX_POSH_TEST_TEST_HPP -#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" - #include #include #include From 6ab901dee26f7540869d320424c929733c789e16 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 29 Jan 2024 08:23:03 +0100 Subject: [PATCH 13/21] iox-#1032 Move 'iceoryx_version.h/hpp' to the platform layer --- iceoryx_hoofs/BUILD.bazel | 12 +------ iceoryx_hoofs/CMakeLists.txt | 16 ++++------ iceoryx_platform/BUILD.bazel | 32 +++++++++++++++++-- iceoryx_platform/CMakeLists.txt | 9 ++++-- .../cmake/IceoryxVersion.cmake | 0 .../cmake/iceoryx_versions.h.in | 0 .../cmake/iceoryxversions.cmake | 4 +-- .../generic}/include/iceoryx_versions.hpp | 0 8 files changed, 46 insertions(+), 27 deletions(-) rename {iceoryx_hoofs => iceoryx_platform}/cmake/IceoryxVersion.cmake (100%) rename {iceoryx_hoofs => iceoryx_platform}/cmake/iceoryx_versions.h.in (100%) rename {iceoryx_hoofs => iceoryx_platform}/cmake/iceoryxversions.cmake (87%) rename {iceoryx_hoofs => iceoryx_platform/generic}/include/iceoryx_versions.hpp (100%) diff --git a/iceoryx_hoofs/BUILD.bazel b/iceoryx_hoofs/BUILD.bazel index 1bd006ad85..aaa397e4ff 100644 --- a/iceoryx_hoofs/BUILD.bazel +++ b/iceoryx_hoofs/BUILD.bazel @@ -16,7 +16,6 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load("//bazel:configure_file.bzl", "configure_file") -load("//bazel:configure_version.bzl", "configure_version") configure_file( name = "iceoryx_hoofs_deployment_hpp", @@ -30,13 +29,6 @@ configure_file( }, ) -configure_version( - name = "iceoryx_versions_h", - src = "cmake/iceoryx_versions.h.in", - out = "generated/include/iceoryx_versions.h", - version_from = "//:VERSION", -) - cc_library( name = "iceoryx_hoofs", srcs = glob([ @@ -59,9 +51,8 @@ cc_library( "utility/source/*.cpp", "vocabulary/source/**/*.cpp", ]), - hdrs = glob(["buffer/**"]) + glob(["cli/**"]) + glob(["concurrent/**"]) + glob(["container/**"]) + glob(["design/**"]) + glob(["filesystem/**"]) + glob(["functional/**"]) + glob(["include/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["posix/**"]) + glob(["primitives/**"]) + glob(["reporting/**"]) + glob(["time/**"]) + glob(["utility/**"]) + glob(["vocabulary/**"]) + [ + hdrs = glob(["buffer/**"]) + glob(["cli/**"]) + glob(["concurrent/**"]) + glob(["container/**"]) + glob(["design/**"]) + glob(["filesystem/**"]) + glob(["functional/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["posix/**"]) + glob(["primitives/**"]) + glob(["reporting/**"]) + glob(["time/**"]) + glob(["utility/**"]) + glob(["vocabulary/**"]) + [ ":iceoryx_hoofs_deployment_hpp", - ":iceoryx_versions_h", ], includes = [ "buffer/include/", @@ -73,7 +64,6 @@ cc_library( "filesystem/include", "functional/include", "generated/include", - "include/", "legacy/include/", "memory/include/", "posix/auth/include/", diff --git a/iceoryx_hoofs/CMakeLists.txt b/iceoryx_hoofs/CMakeLists.txt index e9c0c2270d..16a9eeb16d 100644 --- a/iceoryx_hoofs/CMakeLists.txt +++ b/iceoryx_hoofs/CMakeLists.txt @@ -35,7 +35,6 @@ if(CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin) endif() set(PREFIX iceoryx/v${CMAKE_PROJECT_VERSION}) -include(cmake/iceoryxversions.cmake) # ########## build iceoryx hoofs lib ########## @@ -47,10 +46,7 @@ iox_add_library( PUBLIC_LIBS iceoryx_platform::iceoryx_platform PRIVATE_LIBS ${ICEORYX_SANITIZER_FLAGS} PRIVATE_LIBS_LINUX acl atomic ${CODE_COVERAGE_LIBS} - BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/include - ${PROJECT_SOURCE_DIR}/legacy/include - - ${PROJECT_SOURCE_DIR}/buffer/include + BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/buffer/include ${PROJECT_SOURCE_DIR}/cli/include ${PROJECT_SOURCE_DIR}/concurrent/buffer/include ${PROJECT_SOURCE_DIR}/concurrent/sync/include @@ -75,11 +71,10 @@ iox_add_library( ${PROJECT_SOURCE_DIR}/posix/vocabulary/include ${CMAKE_BINARY_DIR}/generated/iceoryx_hoofs/include - INSTALL_INTERFACE include/${PREFIX} - EXPORT_INCLUDE_DIRS include/ - legacy/include/ - buffer/include/ + ${PROJECT_SOURCE_DIR}/legacy/include + INSTALL_INTERFACE include/${PREFIX} + EXPORT_INCLUDE_DIRS buffer/include/ cli/include/ concurrent/buffer/include/ concurrent/sync/include/ @@ -102,6 +97,8 @@ iox_add_library( posix/time/include/ posix/utility/include/ posix/vocabulary/include/ + + legacy/include/ FILES cli/source/arguments.cpp cli/source/command_line_parser.cpp @@ -183,6 +180,5 @@ endif() install( FILES cmake/IceoryxPlatform.cmake - cmake/IceoryxVersion.cmake DESTINATION ${DESTINATION_CONFIGDIR} ) diff --git a/iceoryx_platform/BUILD.bazel b/iceoryx_platform/BUILD.bazel index d771e6eee1..b1e06cfdea 100644 --- a/iceoryx_platform/BUILD.bazel +++ b/iceoryx_platform/BUILD.bazel @@ -1,4 +1,21 @@ +# Copyright (c) 2022 - 2023 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 + load("@rules_cc//cc:defs.bzl", "cc_library") +load("//bazel:configure_version.bzl", "configure_version") # # Config & Platform support @@ -40,6 +57,13 @@ config_setting( flag_values = {"@bazel_tools//tools/cpp:compiler": "gcc"}, ) +configure_version( + name = "iceoryx_versions_h", + src = "cmake/iceoryx_versions.h.in", + out = "generated/include/iceoryx_versions.h", + version_from = "//:VERSION", +) + # # Library: iceoryx_platform # @@ -60,7 +84,9 @@ cc_library( ":unix": glob(["unix/include/**"]), ":win": glob(["win/include/**"]), "//conditions:default": glob(["linux/include/**"]), - }), + }) + glob(["generic/**"]) + [ + ":iceoryx_versions_h", + ], includes = select({ ":linux": ["linux/include"], ":mac": ["mac/include/**"], @@ -68,7 +94,9 @@ cc_library( ":unix": ["unix/include/**"], ":win": ["win/include/**"], "//conditions:default": ["linux/include/**"], - }), + }) + [ + generic/include + ], linkopts = select({ ":linux": [ "-lpthread", diff --git a/iceoryx_platform/CMakeLists.txt b/iceoryx_platform/CMakeLists.txt index d79f4d6596..7cea02e2ed 100644 --- a/iceoryx_platform/CMakeLists.txt +++ b/iceoryx_platform/CMakeLists.txt @@ -52,6 +52,7 @@ else() endif() set(PREFIX iceoryx/v${CMAKE_PROJECT_VERSION}) +include(cmake/iceoryxversions.cmake) include("${CMAKE_CURRENT_LIST_DIR}/cmake/IceoryxPackageHelper.cmake") include("${ICEORYX_PLATFORM}/IceoryxPlatformSettings.cmake") @@ -67,12 +68,15 @@ iox_add_library( TARGET iceoryx_platform NAMESPACE iceoryx_platform PROJECT_PREFIX ${PREFIX} - EXPORT_INCLUDE_DIRS ${ICEORYX_PLATFORM}/include/ + EXPORT_INCLUDE_DIRS generic/include/ + ${ICEORYX_PLATFORM}/include/ PUBLIC_LIBS_LINUX rt pthread PUBLIC_LIBS_UNIX rt pthread PRIVATE_LIBS_QNX socket PUBLIC_LIBS_FREERTOS freertos_sdk::FreeRTOS_POSIX - BUILD_INTERFACE ${ICEORYX_PLATFORM}/include/ + BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/generic/include/ + ${ICEORYX_PLATFORM}/include/ + ${CMAKE_BINARY_DIR}/generated/iceoryx_platform/include INSTALL_INTERFACE include/${PREFIX} FILES ${ICEORYX_PLATFORM_FILES} ) @@ -80,6 +84,7 @@ iox_add_library( install( FILES cmake/IceoryxPackageHelper.cmake + cmake/IceoryxVersion.cmake ${ICEORYX_PLATFORM}/IceoryxPlatformSettings.cmake DESTINATION ${DESTINATION_CONFIGDIR} COMPONENT dev diff --git a/iceoryx_hoofs/cmake/IceoryxVersion.cmake b/iceoryx_platform/cmake/IceoryxVersion.cmake similarity index 100% rename from iceoryx_hoofs/cmake/IceoryxVersion.cmake rename to iceoryx_platform/cmake/IceoryxVersion.cmake diff --git a/iceoryx_hoofs/cmake/iceoryx_versions.h.in b/iceoryx_platform/cmake/iceoryx_versions.h.in similarity index 100% rename from iceoryx_hoofs/cmake/iceoryx_versions.h.in rename to iceoryx_platform/cmake/iceoryx_versions.h.in diff --git a/iceoryx_hoofs/cmake/iceoryxversions.cmake b/iceoryx_platform/cmake/iceoryxversions.cmake similarity index 87% rename from iceoryx_hoofs/cmake/iceoryxversions.cmake rename to iceoryx_platform/cmake/iceoryxversions.cmake index fb01cf298c..1c81dd5f4e 100644 --- a/iceoryx_hoofs/cmake/iceoryxversions.cmake +++ b/iceoryx_platform/cmake/iceoryxversions.cmake @@ -31,7 +31,7 @@ if(DEFINED ${PROJECT_VERSION_TWEAK}) endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/iceoryx_versions.h.in" - "${CMAKE_BINARY_DIR}/generated/iceoryx_hoofs/include/iceoryx_versions.h" @ONLY) -install(FILES ${CMAKE_BINARY_DIR}/generated/iceoryx_hoofs/include/iceoryx_versions.h + "${CMAKE_BINARY_DIR}/generated/iceoryx_platform/include/iceoryx_versions.h" @ONLY) +install(FILES ${CMAKE_BINARY_DIR}/generated/iceoryx_platform/include/iceoryx_versions.h DESTINATION include/${PREFIX} COMPONENT dev) diff --git a/iceoryx_hoofs/include/iceoryx_versions.hpp b/iceoryx_platform/generic/include/iceoryx_versions.hpp similarity index 100% rename from iceoryx_hoofs/include/iceoryx_versions.hpp rename to iceoryx_platform/generic/include/iceoryx_versions.hpp From 09f9a38d6c74b3937000bac06e74da14a789ccf4 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 29 Jan 2024 08:56:34 +0100 Subject: [PATCH 14/21] iox-#1032 Run clang-format --- .../test/moduletests/test_c2cpp_enum_translation.cpp | 4 ++-- iceoryx_binding_c/test/moduletests/test_chunk.cpp | 3 ++- iceoryx_binding_c/test/moduletests/test_client.cpp | 7 ++++--- iceoryx_binding_c/test/moduletests/test_listener.cpp | 7 ++++--- iceoryx_binding_c/test/moduletests/test_node.cpp | 5 +++-- .../test/moduletests/test_notification_info.cpp | 5 +++-- iceoryx_binding_c/test/moduletests/test_publisher.cpp | 5 +++-- iceoryx_binding_c/test/moduletests/test_request_header.cpp | 3 ++- .../test/moduletests/test_response_header.cpp | 3 ++- iceoryx_binding_c/test/moduletests/test_runtime.cpp | 3 ++- iceoryx_binding_c/test/moduletests/test_server.cpp | 6 ++++-- .../test/moduletests/test_service_discovery.cpp | 3 ++- iceoryx_binding_c/test/moduletests/test_subscriber.cpp | 5 +++-- iceoryx_binding_c/test/moduletests/test_user_trigger.cpp | 3 ++- iceoryx_binding_c/test/moduletests/test_wait_set.cpp | 7 ++++--- iceoryx_hoofs/cli/source/command_line_parser.cpp | 2 +- iceoryx_hoofs/test/moduletests/test_cli_cli_definition.cpp | 2 +- .../test/moduletests/test_concurrent_mpmc_loffli.cpp | 3 ++- .../test_container_fixed_position_container.cpp | 3 +-- .../test/moduletests/test_container_forward_list.cpp | 5 +++-- iceoryx_hoofs/test/moduletests/test_container_list.cpp | 5 +++-- iceoryx_hoofs/test/moduletests/test_container_vector.cpp | 5 +++-- .../test_design_functional_interface_expect.cpp | 3 ++- .../test/moduletests/test_filesystem_file_reader.cpp | 3 ++- .../test/moduletests/test_functional_function_ref.cpp | 2 +- .../test/moduletests/test_vocabulary_expected.cpp | 3 ++- .../test/moduletests/test_vocabulary_semantic_string.cpp | 2 +- iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp | 4 +++- iceoryx_posh/test/moduletests/test_capro_service.cpp | 7 ++++--- iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp | 4 ++-- .../test/moduletests/test_mepoo_memory_manager.cpp | 2 +- iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp | 2 +- .../test/moduletests/test_popo_chunk_distributor.cpp | 2 +- 33 files changed, 76 insertions(+), 52 deletions(-) diff --git a/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp b/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp index c33aa83e4d..455755eb79 100644 --- a/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp +++ b/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp @@ -124,9 +124,9 @@ TEST(c2cpp_enum_translation_test, ConsumerTooSlowPolicy) #if !defined(__clang__) EXPECT_EQ(c2cpp::consumerTooSlowPolicy(iox_test_binding_c::maxUnderlyingCEnumValue()), iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA); -#endif IOX_TESTING_EXPECT_ERROR(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY); +#endif } TEST(c2cpp_enum_translation_test, QueueFullPolicy) @@ -159,9 +159,9 @@ TEST(c2cpp_enum_translation_test, QueueFullPolicy) #if !defined(__clang__) EXPECT_EQ(c2cpp::queueFullPolicy(iox_test_binding_c::maxUnderlyingCEnumValue()), iox::popo::QueueFullPolicy::DISCARD_OLDEST_DATA); -#endif IOX_TESTING_EXPECT_ERROR(iox::CBindingError::BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY); +#endif } TEST(c2cpp_enum_translation_test, ClientState) diff --git a/iceoryx_binding_c/test/moduletests/test_chunk.cpp b/iceoryx_binding_c/test/moduletests/test_chunk.cpp index 3cc5543ebe..46c7bf55ba 100644 --- a/iceoryx_binding_c/test/moduletests/test_chunk.cpp +++ b/iceoryx_binding_c/test/moduletests/test_chunk.cpp @@ -20,9 +20,10 @@ extern "C" { #include "iceoryx_binding_c/runtime.h" } +#include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iox/detail/hoofs_error_reporting.hpp" + #include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" namespace diff --git a/iceoryx_binding_c/test/moduletests/test_client.cpp b/iceoryx_binding_c/test/moduletests/test_client.cpp index 3b14290260..1ec34def51 100644 --- a/iceoryx_binding_c/test/moduletests/test_client.cpp +++ b/iceoryx_binding_c/test/moduletests/test_client.cpp @@ -15,14 +15,15 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/capro/service_description.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/popo/ports/client_port_roudi.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/popo/untyped_client.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" +#include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/testing/mocks/posh_runtime_mock.hpp" using namespace iox::popo; diff --git a/iceoryx_binding_c/test/moduletests/test_listener.cpp b/iceoryx_binding_c/test/moduletests/test_listener.cpp index d69407f8fa..133e887572 100644 --- a/iceoryx_binding_c/test/moduletests/test_listener.cpp +++ b/iceoryx_binding_c/test/moduletests/test_listener.cpp @@ -17,9 +17,6 @@ #include "iceoryx_binding_c/enums.h" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/popo/ports/client_server_port_types.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_single_producer.hpp" @@ -28,6 +25,10 @@ #include "iceoryx_posh/popo/untyped_client.hpp" #include "iceoryx_posh/popo/untyped_server.hpp" #include "iceoryx_posh/popo/user_trigger.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" +#include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_posh/testing/mocks/posh_runtime_mock.hpp" using namespace iox; diff --git a/iceoryx_binding_c/test/moduletests/test_node.cpp b/iceoryx_binding_c/test/moduletests/test_node.cpp index 7b0cebc6e1..78190ad88f 100644 --- a/iceoryx_binding_c/test/moduletests/test_node.cpp +++ b/iceoryx_binding_c/test/moduletests/test_node.cpp @@ -15,10 +15,11 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" #include diff --git a/iceoryx_binding_c/test/moduletests/test_notification_info.cpp b/iceoryx_binding_c/test/moduletests/test_notification_info.cpp index 79784e1036..5c5e249da6 100644 --- a/iceoryx_binding_c/test/moduletests/test_notification_info.cpp +++ b/iceoryx_binding_c/test/moduletests/test_notification_info.cpp @@ -16,8 +16,6 @@ #include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp" #include "iceoryx_binding_c/types.h" -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp" @@ -27,6 +25,9 @@ #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/popo/notification_info.hpp" #include "iceoryx_posh/popo/user_trigger.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" #include "mocks/wait_set_mock.hpp" #include diff --git a/iceoryx_binding_c/test/moduletests/test_publisher.cpp b/iceoryx_binding_c/test/moduletests/test_publisher.cpp index f016055b0a..8f44f8a311 100644 --- a/iceoryx_binding_c/test/moduletests/test_publisher.cpp +++ b/iceoryx_binding_c/test/moduletests/test_publisher.cpp @@ -18,12 +18,13 @@ #include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_publisher.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp" #include "iceoryx_posh/internal/popo/ports/publisher_port_roudi.hpp" #include "iceoryx_posh/internal/popo/ports/publisher_port_user.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iceoryx_posh/roudi_env/roudi_env.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_request_header.cpp b/iceoryx_binding_c/test/moduletests/test_request_header.cpp index 54f9882726..3129282694 100644 --- a/iceoryx_binding_c/test/moduletests/test_request_header.cpp +++ b/iceoryx_binding_c/test/moduletests/test_request_header.cpp @@ -14,9 +14,10 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/popo/rpc_header.hpp" #include "iox/detail/hoofs_error_reporting.hpp" + #include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_posh/popo/rpc_header.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" using namespace iox::popo; diff --git a/iceoryx_binding_c/test/moduletests/test_response_header.cpp b/iceoryx_binding_c/test/moduletests/test_response_header.cpp index 6de0e3e773..973a51206a 100644 --- a/iceoryx_binding_c/test/moduletests/test_response_header.cpp +++ b/iceoryx_binding_c/test/moduletests/test_response_header.cpp @@ -14,9 +14,10 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/popo/rpc_header.hpp" #include "iox/detail/hoofs_error_reporting.hpp" + #include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_posh/popo/rpc_header.hpp" #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" using namespace iox::popo; diff --git a/iceoryx_binding_c/test/moduletests/test_runtime.cpp b/iceoryx_binding_c/test/moduletests/test_runtime.cpp index 7040791423..42d3fba9f5 100644 --- a/iceoryx_binding_c/test/moduletests/test_runtime.cpp +++ b/iceoryx_binding_c/test/moduletests/test_runtime.cpp @@ -18,9 +18,10 @@ extern "C" { #include "iceoryx_binding_c/runtime.h" } +#include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iox/detail/hoofs_error_reporting.hpp" + #include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_server.cpp b/iceoryx_binding_c/test/moduletests/test_server.cpp index 2acdf34a4e..1e8890c69f 100644 --- a/iceoryx_binding_c/test/moduletests/test_server.cpp +++ b/iceoryx_binding_c/test/moduletests/test_server.cpp @@ -15,14 +15,16 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/capro/service_description.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/popo/ports/client_port_roudi.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iceoryx_posh/popo/untyped_server.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/testing/mocks/posh_runtime_mock.hpp" + #include using namespace iox::popo; diff --git a/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp b/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp index 11439d392f..037aeb1d32 100644 --- a/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp +++ b/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp @@ -14,10 +14,11 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/runtime/service_discovery.hpp" #include "iox/detail/hoofs_error_reporting.hpp" + #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" -#include "iceoryx_posh/runtime/service_discovery.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" using namespace iox; diff --git a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp index dcd712f6e9..3f8a5dad1f 100644 --- a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp +++ b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp @@ -18,14 +18,15 @@ #include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp" #include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_pusher.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_single_producer.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/roudi_env/minimal_roudi_config.hpp" #include "iceoryx_posh/roudi_env/roudi_env.hpp" #include "mocks/wait_set_mock.hpp" diff --git a/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp b/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp index 8e41eb3439..a9e510adfa 100644 --- a/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp +++ b/iceoryx_binding_c/test/moduletests/test_user_trigger.cpp @@ -15,9 +15,10 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_posh/popo/user_trigger.hpp" #include "iox/detail/hoofs_error_reporting.hpp" + #include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_posh/popo/user_trigger.hpp" #include "mocks/wait_set_mock.hpp" using namespace iox; diff --git a/iceoryx_binding_c/test/moduletests/test_wait_set.cpp b/iceoryx_binding_c/test/moduletests/test_wait_set.cpp index d6217409bd..d9a9b12b1f 100644 --- a/iceoryx_binding_c/test/moduletests/test_wait_set.cpp +++ b/iceoryx_binding_c/test/moduletests/test_wait_set.cpp @@ -18,15 +18,16 @@ #include "iceoryx_binding_c/enums.h" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp" #include "iceoryx_posh/popo/untyped_client.hpp" #include "iceoryx_posh/popo/untyped_server.hpp" #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/runtime/service_discovery.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" +#include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_posh/testing/mocks/posh_runtime_mock.hpp" #include "mocks/wait_set_mock.hpp" diff --git a/iceoryx_hoofs/cli/source/command_line_parser.cpp b/iceoryx_hoofs/cli/source/command_line_parser.cpp index 5f08d9d43c..5d2b83beb9 100644 --- a/iceoryx_hoofs/cli/source/command_line_parser.cpp +++ b/iceoryx_hoofs/cli/source/command_line_parser.cpp @@ -15,8 +15,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/cli/command_line_parser.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/algorithm.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/std_string_support.hpp" #include diff --git a/iceoryx_hoofs/test/moduletests/test_cli_cli_definition.cpp b/iceoryx_hoofs/test/moduletests/test_cli_cli_definition.cpp index 598873ab78..f09f88cf11 100644 --- a/iceoryx_hoofs/test/moduletests/test_cli_cli_definition.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cli_cli_definition.cpp @@ -14,8 +14,8 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/cli_definition.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/optional.hpp" #include "test.hpp" #include "test_cli_command_line_common.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_concurrent_mpmc_loffli.cpp b/iceoryx_hoofs/test/moduletests/test_concurrent_mpmc_loffli.cpp index 277f1d0921..b79e06f4df 100644 --- a/iceoryx_hoofs/test/moduletests/test_concurrent_mpmc_loffli.cpp +++ b/iceoryx_hoofs/test/moduletests/test_concurrent_mpmc_loffli.cpp @@ -16,8 +16,9 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iox/detail/mpmc_loffli.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" #include diff --git a/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp index fff965c87c..b65ccc1283 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp @@ -15,12 +15,11 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/fixed_position_container.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/lifetime_and_assignment_tracker.hpp" - #include "test.hpp" namespace diff --git a/iceoryx_hoofs/test/moduletests/test_container_forward_list.cpp b/iceoryx_hoofs/test/moduletests/test_container_forward_list.cpp index 48b16a7671..e9d957b0cb 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_forward_list.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_forward_list.cpp @@ -14,11 +14,12 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iox/attributes.hpp" #include "iox/detail/hoofs_error_reporting.hpp" +#include "iox/forward_list.hpp" + #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/lifetime_and_assignment_tracker.hpp" -#include "iox/attributes.hpp" -#include "iox/forward_list.hpp" #include "test.hpp" namespace diff --git a/iceoryx_hoofs/test/moduletests/test_container_list.cpp b/iceoryx_hoofs/test/moduletests/test_container_list.cpp index 0a6389fddd..c19c7bcf9c 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_list.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_list.cpp @@ -15,12 +15,13 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/lifetime_and_assignment_tracker.hpp" #include "iox/attributes.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/list.hpp" #include "iox/logging.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_container_vector.cpp b/iceoryx_hoofs/test/moduletests/test_container_vector.cpp index f41b7b01c0..96c0d45f66 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_vector.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_vector.cpp @@ -15,10 +15,11 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/lifetime_and_assignment_tracker.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/vector.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" #include 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 d687635cd6..93cab61aba 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp @@ -15,9 +15,10 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test_design_functional_interface_types.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" + namespace { using namespace test_design_functional_interface; diff --git a/iceoryx_hoofs/test/moduletests/test_filesystem_file_reader.cpp b/iceoryx_hoofs/test/moduletests/test_filesystem_file_reader.cpp index 0368070593..d98ac743e9 100644 --- a/iceoryx_hoofs/test/moduletests/test_filesystem_file_reader.cpp +++ b/iceoryx_hoofs/test/moduletests/test_filesystem_file_reader.cpp @@ -16,9 +16,10 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/detail/hoofs_error_reporting.hpp" +#include "iox/file_reader.hpp" + #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_hoofs/testing/testing_logger.hpp" -#include "iox/file_reader.hpp" #include "test.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp b/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp index b24552f10b..67092f6f8b 100644 --- a/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp +++ b/iceoryx_hoofs/test/moduletests/test_functional_function_ref.cpp @@ -15,9 +15,9 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "iox/attributes.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/function_ref.hpp" #include "test.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp index 76ff67dff5..5165b1ae92 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp @@ -16,9 +16,10 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iox/expected.hpp" #include "iox/string.hpp" + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" using namespace ::testing; diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp index 9a4bb37799..4309422fed 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp @@ -14,9 +14,9 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_platform/platform_settings.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/file_name.hpp" #include "iox/file_path.hpp" #include "iox/group_name.hpp" diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp index e9a0d8c8bb..190d5f8b0d 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp @@ -16,10 +16,12 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/detail/hoofs_error_reporting.hpp" +#include "iox/string.hpp" + #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iox/string.hpp" #include "test.hpp" + #include namespace diff --git a/iceoryx_posh/test/moduletests/test_capro_service.cpp b/iceoryx_posh/test/moduletests/test_capro_service.cpp index e22f58aa11..389574d595 100644 --- a/iceoryx_posh/test/moduletests/test_capro_service.cpp +++ b/iceoryx_posh/test/moduletests/test_capro_service.cpp @@ -17,16 +17,17 @@ #include "test.hpp" -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" -#include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" #include "iceoryx_posh/capro/service_description.hpp" #include "iox/detail/convert.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/detail/serialization.hpp" #include "iox/string.hpp" /// @todo iox-#415 replace the service registry include with the new discovery API header #include "iceoryx_posh/internal/roudi/service_registry.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" +#include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" + #include namespace diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 2cba235d2c..5c454972a6 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -15,15 +15,15 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" -#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iox/detail/convert.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iox/type_traits.hpp" #include "iox/unique_ptr.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" #include diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index 8f70be7b14..99595466eb 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -15,12 +15,12 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iox/bump_allocator.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" diff --git a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp index 96eda40b68..bbc1f59588 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp @@ -16,10 +16,10 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_posh/internal/mepoo/mem_pool.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/bump_allocator.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index 1e7a8f2db5..eab1609e2a 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -15,7 +15,6 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/barrier.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/internal/mepoo/shared_chunk.hpp" @@ -28,6 +27,7 @@ #include "iceoryx_posh/internal/popo/building_blocks/variant_queue.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" +#include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" From 55f3527fe6f4465a48cec8a8ae78ff8763c2f450 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 29 Jan 2024 08:57:24 +0100 Subject: [PATCH 15/21] iox-#1032 Fix aarch64 build --- iceoryx_hoofs/CMakeLists.txt | 1 - .../iox/detail/functional_interface.inl | 6 ++-- .../include/iox/functional_interface.hpp | 7 +--- .../design/source/functional_interface.cpp | 32 ------------------- ...est_design_functional_interface_expect.cpp | 2 +- .../iceoryx_hoofs/testing/fatal_failure.inl | 3 +- 6 files changed, 6 insertions(+), 45 deletions(-) delete mode 100644 iceoryx_hoofs/design/source/functional_interface.cpp diff --git a/iceoryx_hoofs/CMakeLists.txt b/iceoryx_hoofs/CMakeLists.txt index 16a9eeb16d..e82490133e 100644 --- a/iceoryx_hoofs/CMakeLists.txt +++ b/iceoryx_hoofs/CMakeLists.txt @@ -106,7 +106,6 @@ iox_add_library( cli/source/option_definition.cpp cli/source/option_manager.cpp concurrent/buffer/source/mpmc_loffli.cpp - design/source/functional_interface.cpp filesystem/source/file_reader.cpp filesystem/source/filesystem.cpp memory/source/bump_allocator.cpp diff --git a/iceoryx_hoofs/design/include/iox/detail/functional_interface.inl b/iceoryx_hoofs/design/include/iox/detail/functional_interface.inl index 34e3907195..c42b5e79c1 100644 --- a/iceoryx_hoofs/design/include/iox/detail/functional_interface.inl +++ b/iceoryx_hoofs/design/include/iox/detail/functional_interface.inl @@ -38,8 +38,7 @@ inline void Expect::expect(const StringType& msg) const noexcept if (!derivedThis) { - print_expect_message(&msg[0]); - IOX_ENSURES(false); + IOX_PANIC(&msg[0]); } } @@ -54,8 +53,7 @@ inline ValueType& ExpectWithValue::expect(const StringType& if (!derivedThis) { - print_expect_message(&msg[0]); - IOX_ENSURES(false); + IOX_PANIC(&msg[0]); } return derivedThis.value(); diff --git a/iceoryx_hoofs/design/include/iox/functional_interface.hpp b/iceoryx_hoofs/design/include/iox/functional_interface.hpp index 7c1df775d8..ad1f897568 100644 --- a/iceoryx_hoofs/design/include/iox/functional_interface.hpp +++ b/iceoryx_hoofs/design/include/iox/functional_interface.hpp @@ -17,6 +17,7 @@ #define IOX_HOOFS_DESIGN_FUNCTIONAL_INTERFACE_HPP #include "iceoryx_platform/unistd.hpp" +#include "iox/assertions.hpp" #include "iox/function_ref.hpp" #include "iox/type_traits.hpp" @@ -46,12 +47,6 @@ struct HasGetErrorMethod().error( { }; -// @todo iox-#1723 use string_view as argument -// AXIVION Next Construct AutosarC++19_03-A3.9.1 : Requires char base type to print strings originating -// from string literals, iox::string::c_str(), std::string::c_str() or other sources. Only with char we -// can achieve the task. -void print_expect_message(const char* message) noexcept; - template // AXIVION Next Construct AutosarC++19_03-A12.0.1 : not required since a default'ed destructor does not define // a destructor, hence the move operations are not deleted. diff --git a/iceoryx_hoofs/design/source/functional_interface.cpp b/iceoryx_hoofs/design/source/functional_interface.cpp deleted file mode 100644 index bdaf5ced58..0000000000 --- a/iceoryx_hoofs/design/source/functional_interface.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 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 - -#include "iox/functional_interface.hpp" -#include "iox/logging.hpp" - -namespace iox -{ -namespace internal -{ -// AXIVION Next Construct AutosarC++19_03-A3.9.1 : See rational in header -void print_expect_message(const char* message) noexcept -{ - // print_expect_message is only called from expect. expect allows only - // string or char arrays which are both correctly null terminated - IOX_LOG(FATAL, message); -} -} // namespace internal -} // namespace iox 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 93cab61aba..525ebb5b6c 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp @@ -79,7 +79,7 @@ void ExpectDoesCallTerminateWhenObjectIsInvalid(const ExpectCall& callExpect) { SutType sut = FactoryType::createInvalidObject(); - IOX_EXPECT_FATAL_FAILURE([&] { callExpect(sut); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); + IOX_EXPECT_FATAL_FAILURE([&] { callExpect(sut); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(FunctionalInterface_test, ExpectDoesCallTerminateWhenObjectIsInvalid_LValueCase) diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl index fbb25ad341..ec9fd39a15 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl @@ -33,7 +33,8 @@ inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref testFunction, IOX_TESTING_EXPECT_PANIC(); /// @todo iox-#1032 'hasViolation' should not be necessary - auto hasExpectedError = iox::testing::hasError(expectedError) || iox::testing::hasViolation(); + auto hasExpectedError = + iox::testing::hasError(expectedError) || iox::testing::hasViolation() || iox::testing::hasPanicked(); EXPECT_TRUE(hasExpectedError); return hasExpectedError; } From 259b690b51dc12b2ebc146f42a72d55be27579fd Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 29 Jan 2024 09:37:12 +0100 Subject: [PATCH 16/21] iox-#1032 Fix CI build --- doc/aspice_swe3_4/CMakeLists.txt | 24 +++++++++++++++++- .../CMakeLists.txt | 2 +- iceoryx_platform/BUILD.bazel | 5 ++-- iceoryx_posh/BUILD.bazel | 25 ++++++++++--------- .../internal/popo/publisher_impl.inl | 2 +- .../source/popo/publisher_options.cpp | 2 +- .../test_mepoo_segment_management.cpp | 5 ++-- .../moduletests/test_posh_runtime_node.cpp | 4 +-- tools/ci/build-test-windows.ps1 | 4 ++- 9 files changed, 50 insertions(+), 23 deletions(-) diff --git a/doc/aspice_swe3_4/CMakeLists.txt b/doc/aspice_swe3_4/CMakeLists.txt index 648e290b20..7ce672a19b 100644 --- a/doc/aspice_swe3_4/CMakeLists.txt +++ b/doc/aspice_swe3_4/CMakeLists.txt @@ -56,7 +56,29 @@ generatedcode="@par Generated by:"]]) set(COMPONENTS iceoryx_hoofs iceoryx_posh iceoryx_binding_c iceoryx_introspection iceoryx_component) set(COMPONENT_DIRS - ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/buffer + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/cli + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/concurrent/buffer + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/concurrent/sync + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/container + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/design + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/filesystem + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/functional + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/legacy/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/memory + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/auth + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/desig + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/filesystem + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/ipc + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/sync + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/time + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/utility + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/posix/vocabulary + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/primitives + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/reporting + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/time + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/utility + ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_hoofs/vocabulary ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_posh ${CMAKE_CURRENT_SOURCE_DIR}/../../iceoryx_binding_c ${CMAKE_CURRENT_SOURCE_DIR}/../../tools/introspection diff --git a/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/CMakeLists.txt b/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/CMakeLists.txt index e2e6cd8f00..489c216f56 100644 --- a/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/CMakeLists.txt +++ b/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/CMakeLists.txt @@ -30,5 +30,5 @@ include(IceoryxPlatformSettings) iox_add_executable( TARGET iox-bm-optional-and-expected FILES ./benchmark_optional_and_expected.cpp - LIBS iceoryx_hoofs::iceoryx_hoofs Threads::Threads + LIBS iceoryx_hoofs::iceoryx_hoofs iceoryx_platform::iceoryx_platform Threads::Threads ) diff --git a/iceoryx_platform/BUILD.bazel b/iceoryx_platform/BUILD.bazel index b1e06cfdea..e36cc6706e 100644 --- a/iceoryx_platform/BUILD.bazel +++ b/iceoryx_platform/BUILD.bazel @@ -84,7 +84,7 @@ cc_library( ":unix": glob(["unix/include/**"]), ":win": glob(["win/include/**"]), "//conditions:default": glob(["linux/include/**"]), - }) + glob(["generic/**"]) + [ + }) + glob(["generic/include/**"]) + [ ":iceoryx_versions_h", ], includes = select({ @@ -95,7 +95,8 @@ cc_library( ":win": ["win/include/**"], "//conditions:default": ["linux/include/**"], }) + [ - generic/include + "generated/include", + "generic/include", ], linkopts = select({ ":linux": [ diff --git a/iceoryx_posh/BUILD.bazel b/iceoryx_posh/BUILD.bazel index 2adf2ceb41..a5d170cce0 100644 --- a/iceoryx_posh/BUILD.bazel +++ b/iceoryx_posh/BUILD.bazel @@ -102,18 +102,19 @@ iox_roudi_executable_files = [ cc_library( name = "iceoryx_posh", srcs = glob( - [ - "source/log/**", - "source/capro/**", - "source/error_handling/**", - "source/mepoo/**", - "source/popo/**", - "source/version/**", - "source/runtime/**", - ], - exclude = iceory_posh_config_files, - ) + - iceory_posh_extra_roudi_files, + [ + "source/log/**", + "source/capro/**", + "source/error_handling/**", + "source/mepoo/**", + "source/popo/**", + "source/version/**", + "source/runtime/**", + ], + exclude = iceory_posh_config_files, + ) + [ + "source/posh_error_reporting.cpp", + ] + iceory_posh_extra_roudi_files, hdrs = glob(["include/**"]) + [ ":iceoryx_posh_deployment_hpp", ], diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/publisher_impl.inl b/iceoryx_posh/include/iceoryx_posh/internal/popo/publisher_impl.inl index f3d264e175..4220c0a972 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/publisher_impl.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/publisher_impl.inl @@ -38,7 +38,7 @@ template template inline expected, AllocationError> PublisherImpl::loan(Args&&... args) noexcept { - return std::move(loanSample().and_then([&](auto& sample) { new (sample.get()) T(std::forward(args)...); })); + return loanSample().and_then([&](auto& sample) { new (sample.get()) T(std::forward(args)...); }); } template diff --git a/iceoryx_posh/source/popo/publisher_options.cpp b/iceoryx_posh/source/popo/publisher_options.cpp index bf2feb007f..bb3645912d 100644 --- a/iceoryx_posh/source/popo/publisher_options.cpp +++ b/iceoryx_posh/source/popo/publisher_options.cpp @@ -34,7 +34,7 @@ expected PublisherOptions::deserialize(c using ConsumerTooSlowPolicyUT = std::underlying_type_t; PublisherOptions publisherOptions; - ConsumerTooSlowPolicyUT subscriberTooSlowPolicy; + ConsumerTooSlowPolicyUT subscriberTooSlowPolicy{}; auto deserializationSuccessful = serialized.extract(publisherOptions.historyCapacity, publisherOptions.nodeName, diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp index 3ff994f239..d3ecab78ff 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp @@ -27,6 +27,7 @@ #include "iox/posix_user.hpp" #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" namespace @@ -191,9 +192,9 @@ TEST_F(SegmentManager_test, addingMoreThanOneWriterGroupFails) SegmentConfig segmentConfig = getInvalidSegmentConfig(); SUT sut{segmentConfig, &allocator}; - sut.getSegmentMappings(PosixUser("iox_roudi_test1")); - IOX_TESTING_EXPECT_ERROR(iox::PoshError::MEPOO__USER_WITH_MORE_THAN_ONE_WRITE_SEGMENT); + IOX_EXPECT_FATAL_FAILURE([&] { sut.getSegmentMappings(PosixUser("iox_roudi_test1")); }, + iox::PoshError::MEPOO__USER_WITH_MORE_THAN_ONE_WRITE_SEGMENT); } TEST_F(SegmentManager_test, addingMaximumNumberOfSegmentsWorks) diff --git a/iceoryx_posh/test/moduletests/test_posh_runtime_node.cpp b/iceoryx_posh/test/moduletests/test_posh_runtime_node.cpp index 11eb3c888b..9b0f4a0da3 100644 --- a/iceoryx_posh/test/moduletests/test_posh_runtime_node.cpp +++ b/iceoryx_posh/test/moduletests/test_posh_runtime_node.cpp @@ -57,7 +57,7 @@ TEST_F(PoshRuntimeNode_test, ConstructorNodeIsSuccess) ::testing::Test::RecordProperty("TEST_ID", "3bba69cc-43ea-47d3-9207-08afdd7eed9b"); const NodeName_t nodeName{"Node"}; - Node node("Node"); + Node node(nodeName); EXPECT_THAT(node.getNodeName(), Eq(nodeName)); } @@ -78,7 +78,7 @@ TEST_F(PoshRuntimeNode_test, ConstructorNodeWithMaximalSizeNodeNameIsSuccess) const NodeName_t nodeName{ "aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaaabbbbbcccccddddd"}; - Node node("aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaaabbbbbcccccddddd"); + Node node(nodeName); EXPECT_THAT(node.getNodeName(), Eq(nodeName)); } diff --git a/tools/ci/build-test-windows.ps1 b/tools/ci/build-test-windows.ps1 index 73095fdd17..8722b9274c 100755 --- a/tools/ci/build-test-windows.ps1 +++ b/tools/ci/build-test-windows.ps1 @@ -63,7 +63,9 @@ if ($?) { Write-Host "## Running tests (excluding timing_tests)" } if ($?) { build\hoofs\test\hoofs_mocktests.exe } if ($?) { build\hoofs\test\hoofs_moduletests.exe --gtest_filter="-*TimingTest*:AdaptiveWait*" } if ($?) { build\hoofs\test\hoofs_integrationtests.exe } -if ($?) { build\posh\test\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\posh_moduletests.exe --gtest_filter="-ChunkHeader_test.ChunkHeaderBinaryCompatibilityCheck:TomlGatewayConfigParser*:IceoryxRoudiApp_test.ConstructorCalledWithArgUniqueIdTwoTimesReturnError:IceoryxRoudiApp_test.ConstructorCalledWithArgVersionSetRunVariableToFalse:ValidTest*:ParseAllMalformedInput*:*TimingTest*:MePooSegment_test.SharedMemoryFileHandleRightsAfterConstructor:PoshRuntimeSingleProcess_test*" } +# The PoshRuntimeSingleProcess_test brings the system into a state from which it will not recover until the process is terminated +if ($?) { build\posh\test\posh_moduletests.exe --gtest_filter="PoshRuntimeSingleProcess_test*" } if ($?) { build\posh\test\posh_integrationtests.exe --gtest_filter="-ChunkBuildingBlocks_IntegrationTest.TwoHopsThreeThreadsNoSoFi:*TimingTest*" } if ($?) { build\binding_c\test\binding_c_moduletests.exe --gtest_filter="-BindingC_Runtime_test.RuntimeNameLengthIsOutOfLimit:BindingC_Runtime_test.RuntimeNameIsNullptr:*TimingTest*" } From fcc360bbe2ff4a39e8e97a432685e8733497ab0e Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 1 Feb 2024 15:20:22 +0100 Subject: [PATCH 17/21] iox-#1032 Fix build for GCC 11 and 12 --- .../include/iox/detail/storable_function.inl | 15 +++++++++++---- .../memory/include/iox/detail/unique_ptr.inl | 12 ++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/iceoryx_hoofs/functional/include/iox/detail/storable_function.inl b/iceoryx_hoofs/functional/include/iox/detail/storable_function.inl index bb3ae00081..23c4961282 100644 --- a/iceoryx_hoofs/functional/include/iox/detail/storable_function.inl +++ b/iceoryx_hoofs/functional/include/iox/detail/storable_function.inl @@ -47,7 +47,7 @@ inline storable_function>::storable_fun m_callable(reinterpret_cast(function)) , m_invoker(&invokeFreeFunction) { - IOX_EXPECTS(function); + IOX_ENFORCE(function != nullptr, "parameter must not be a 'nullptr'"); m_operations.copyFunction = ©FreeFunction; m_operations.moveFunction = &moveFreeFunction; @@ -158,10 +158,17 @@ inline storable_function>::~storable_fu template inline ReturnType storable_function>::operator()(Args... args) const noexcept { - IOX_EXPECTS(m_callable != nullptr); // should not happen unless incorrectly used after move +#if (defined(__GNUC__) && __GNUC__ >= 11 && __GNUC__ <= 12 && !defined(__clang__)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + IOX_ENFORCE(m_callable != nullptr, "should not happen unless incorrectly used after move"); // AXIVION Next Construct AutosarC++19_03-M0.3.1, FaultDetection-NullPointerDereference: m_invoker is initialized in ctor or assignment, // can only be nullptr if this was moved from (calling operator() is illegal in this case) return m_invoker(m_callable, std::forward(args)...); +#if (defined(__GNUC__) && __GNUC__ >= 11 && __GNUC__ <= 12 && !defined(__clang__)) +#pragma GCC diagnostic pop +#endif } template @@ -222,7 +229,7 @@ inline void storable_function>::copy(co // AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type const auto obj = static_cast(src.m_callable); - IOX_EXPECTS(obj != nullptr); // should not happen unless src is incorrectly used after move + IOX_ENFORCE(obj != nullptr, "should not happen unless src is incorrectly used after move"); // AXIVION Next Construct AutosarC++19_03-A18.5.10: False positive! 'safeAlign' takes care of proper alignment and size // NOLINTNEXTLINE(clang-analyzer-core.NonNullParamChecker) checked two lines above @@ -241,7 +248,7 @@ inline void storable_function>::move(st // AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type const auto obj = static_cast(src.m_callable); - IOX_EXPECTS(obj != nullptr); // should not happen unless src is incorrectly used after move + IOX_ENFORCE(obj != nullptr, "should not happen unless src is incorrectly used after move"); // AXIVION Next Construct AutosarC++19_03-A18.5.10: False positive! 'safeAlign' takes care of proper alignment and size // NOLINTNEXTLINE(clang-analyzer-core.NonNullParamChecker) checked two lines above diff --git a/iceoryx_hoofs/memory/include/iox/detail/unique_ptr.inl b/iceoryx_hoofs/memory/include/iox/detail/unique_ptr.inl index bec991a34a..8264c7058b 100644 --- a/iceoryx_hoofs/memory/include/iox/detail/unique_ptr.inl +++ b/iceoryx_hoofs/memory/include/iox/detail/unique_ptr.inl @@ -28,7 +28,7 @@ inline unique_ptr::unique_ptr(T* const object, const function& d : m_ptr(object) , m_deleter(deleter) { - IOX_ENSURES(object != nullptr); + IOX_ENFORCE(object != nullptr, "parameter must not be a 'nullptr'"); } template @@ -61,7 +61,7 @@ inline unique_ptr::~unique_ptr() noexcept template inline T* unique_ptr::operator->() noexcept { - IOX_EXPECTS(m_ptr != nullptr); + IOX_ENFORCE(m_ptr != nullptr, "should not happen unless src is incorrectly used after move"); return get(); } @@ -98,10 +98,18 @@ inline T* unique_ptr::release(unique_ptr&& ptrToBeReleased) noexcept template inline void unique_ptr::destroy() noexcept { +#if (defined(__GNUC__) && __GNUC__ >= 11 && __GNUC__ <= 12 && !defined(__clang__)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif if (m_ptr != nullptr) { m_deleter(m_ptr); } +#if (defined(__GNUC__) && __GNUC__ >= 11 && __GNUC__ <= 12 && !defined(__clang__)) +#pragma GCC diagnostic pop +#endif + m_ptr = nullptr; } From a6e4e8baec4e42c35a580604a6e08ea727429180 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 1 Feb 2024 15:20:52 +0100 Subject: [PATCH 18/21] iox-#1032 Remove do-while loops from macros --- .clang-tidy | 4 -- .../reporting/include/iox/assertions.hpp | 43 +++++++------------ .../include/iox/error_reporting/macros.hpp | 36 ++++++---------- iceoryx_hoofs/test/.clang-tidy | 3 -- .../test_error_reporting_macros.cpp | 3 -- 5 files changed, 29 insertions(+), 60 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 201bfa7d35..9a65c1ad1b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -21,7 +21,6 @@ concurrency-*, performance-*, hicpp-*, --cppcoreguidelines-avoid-do-while -cppcoreguidelines-non-private-member-variables-in-classes, -hicpp-named-parameter, @@ -42,9 +41,6 @@ hicpp-*, ### Temporarily disabled because massive API changes: # * rule: readability-identifier-naming -# * rule: cppcoreguidelines-avoid-do-while -> the new error handling uses 'do{} while(false)' loops -# for the macros to enforce a semicolon at the end; -# can be activated again if we find a better solution ### Justifications for deactivated rules # * rule: readability-avoid-const-params-in-decls diff --git a/iceoryx_hoofs/reporting/include/iox/assertions.hpp b/iceoryx_hoofs/reporting/include/iox/assertions.hpp index 2aef7bda51..13d06d488a 100644 --- a/iceoryx_hoofs/reporting/include/iox/assertions.hpp +++ b/iceoryx_hoofs/reporting/include/iox/assertions.hpp @@ -38,11 +38,7 @@ /// @brief calls panic handler and does not return /// @param message message to be forwarded /// @note could actually throw if desired without breaking control flow asssumptions -#define IOX_PANIC(message) \ - do \ - { \ - iox::er::forwardPanic(IOX_CURRENT_SOURCE_LOCATION, message); \ - } while (false) +#define IOX_PANIC(message) iox::er::forwardPanic(IOX_CURRENT_SOURCE_LOCATION, message) //************************************************************************************************ //* For documentation of intent, defensive programming and debugging @@ -56,39 +52,32 @@ /// @param expr boolean expression that must hold /// @param message message to be forwarded in case of violation #define IOX_ASSERT(expr, message) \ - do \ + if (iox::er::Configuration::CHECK_ASSERT && !(expr)) \ { \ - if (iox::er::Configuration::CHECK_ASSERT && !(expr)) \ - { \ - iox::er::forwardFatalError(iox::er::Violation::createAssertViolation(), \ - iox::er::ASSERT_VIOLATION, \ - IOX_CURRENT_SOURCE_LOCATION, \ - message); \ - } \ - } while (false) + iox::er::forwardFatalError(iox::er::Violation::createAssertViolation(), \ + iox::er::ASSERT_VIOLATION, \ + IOX_CURRENT_SOURCE_LOCATION, \ + message); \ + } \ + [] {}() // the empty lambda forces a semicolon on the caller side /// @brief report fatal enforce violation if expr evaluates to false /// @note for conditions that may actually happen during correct use /// @param expr boolean expression that must hold /// @param message message to be forwarded in case of violation #define IOX_ENFORCE(expr, message) \ - do \ + if (!(expr)) \ { \ - if (!(expr)) \ - { \ - iox::er::forwardFatalError(iox::er::Violation::createEnforceViolation(), \ - iox::er::ENFORCE_VIOLATION, \ - IOX_CURRENT_SOURCE_LOCATION, \ - message); /* @todo iox-#1032 add strigified 'expr' as '#expr' */ \ - } \ - } while (false) + iox::er::forwardFatalError(iox::er::Violation::createEnforceViolation(), \ + iox::er::ENFORCE_VIOLATION, \ + IOX_CURRENT_SOURCE_LOCATION, \ + message); /* @todo iox-#1032 add strigified 'expr' as '#expr' */ \ + } \ + [] {}() // the empty lambda forces a semicolon on the caller side /// @brief panic if control flow reaches this code at runtime #define IOX_UNREACHABLE() \ - do \ - { \ - iox::er::forwardPanic(IOX_CURRENT_SOURCE_LOCATION, "Reached code that was supposed to be unreachable."); \ - } while (false) + iox::er::forwardPanic(IOX_CURRENT_SOURCE_LOCATION, "Reached code that was supposed to be unreachable.") /// @todo iox-#1032 replace IOX_EXPECTS and IOX_ENSURES with IOX_ENFORCE diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp index 4a54cbb6e4..04ccaa0019 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp @@ -40,46 +40,36 @@ /// @param error error object (or code) /// @param kind kind of error, must be non-fatal #define IOX_REPORT(error, kind) \ - do \ - { \ - iox::er::forwardNonFatalError(iox::er::toError(error), kind, IOX_CURRENT_SOURCE_LOCATION); \ - } while (false) + iox::er::forwardNonFatalError(iox::er::toError(error), kind, IOX_CURRENT_SOURCE_LOCATION) /// @brief report fatal error /// @param error error object (or code) #define IOX_REPORT_FATAL(error) \ - do \ - { \ - iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, IOX_CURRENT_SOURCE_LOCATION); \ - } while (false) + iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, IOX_CURRENT_SOURCE_LOCATION) /// @brief report error of some non-fatal kind if expr evaluates to true /// @param expr boolean expression /// @param error error object (or code) /// @param kind kind of error, must be non-fatal #define IOX_REPORT_IF(expr, error, kind) \ - do \ + if (expr) \ { \ - if (expr) \ - { \ - iox::er::forwardNonFatalError( \ - iox::er::toError(error), \ - kind, \ - IOX_CURRENT_SOURCE_LOCATION); /* @todo iox-#1032 add strigified 'expr' as '#expr' */ \ - } \ - } while (false) + iox::er::forwardNonFatalError( \ + iox::er::toError(error), \ + kind, \ + IOX_CURRENT_SOURCE_LOCATION); /* @todo iox-#1032 add strigified 'expr' as '#expr' */ \ + } \ + [] {}() // the empty lambda forces a semicolon on the caller side /// @brief report fatal error if expr evaluates to true /// @param expr boolean expression /// @param error error object (or code) #define IOX_REPORT_FATAL_IF(expr, error) \ - do \ + if (expr) \ { \ - if (expr) \ - { \ - iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, IOX_CURRENT_SOURCE_LOCATION); \ - } \ - } while (false) + iox::er::forwardFatalError(iox::er::toError(error), iox::er::FATAL, IOX_CURRENT_SOURCE_LOCATION); \ + } \ + [] {}() // the empty lambda forces a semicolon on the caller side // NOLINTEND(cppcoreguidelines-macro-usage) diff --git a/iceoryx_hoofs/test/.clang-tidy b/iceoryx_hoofs/test/.clang-tidy index 3da91a32e3..c70ea86e49 100644 --- a/iceoryx_hoofs/test/.clang-tidy +++ b/iceoryx_hoofs/test/.clang-tidy @@ -19,9 +19,6 @@ Checks: ' # * rule: cppcoreguidelines-avoid-const-or-ref-data-members # justification: this is non-production code and it improves the readability of tests # -# * rule: cppcoreguidelines-avoid-do-while -# justification: this is non-production code and there is nothing inherently wrong with do-while loops -# # * rule: cert-err58-cpp # justification: caused by TEST_F in gtest with internal macro generated construct: test_info_ # diff --git a/iceoryx_hoofs/test/moduletests/error_reporting/test_error_reporting_macros.cpp b/iceoryx_hoofs/test/moduletests/error_reporting/test_error_reporting_macros.cpp index 3b66f56265..26a37ddc8b 100644 --- a/iceoryx_hoofs/test/moduletests/error_reporting/test_error_reporting_macros.cpp +++ b/iceoryx_hoofs/test/moduletests/error_reporting/test_error_reporting_macros.cpp @@ -29,8 +29,6 @@ namespace { - -// NOLINTBEGIN(cppcoreguidelines-avoid-do-while) bad rule, disable globally using namespace ::testing; using namespace iox::er; using namespace iox::testing; @@ -247,6 +245,5 @@ TEST_F(ErrorReportingMacroApi_test, panicAtUnreachableCode) IOX_TESTING_EXPECT_PANIC(); } -// NOLINTEND(cppcoreguidelines-avoid-do-while) } // namespace From 7e03a896a61887d7049e837f12e460bf0b08759f Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 2 Feb 2024 02:02:32 +0100 Subject: [PATCH 19/21] iox-#1032 Update copyright --- .../iceoryx_binding_c/internal/binding_c_error_reporting.hpp | 1 + iceoryx_binding_c/source/binding_c_error_reporting.cpp | 1 + iceoryx_hoofs/reporting/include/iox/assertions.hpp | 1 + .../reporting/include/iox/detail/hoofs_error_reporting.hpp | 1 + iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp | 1 + .../reporting/include/iox/error_reporting/violation.hpp | 1 + iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp | 1 + .../testing/include/iceoryx_hoofs/testing/fatal_failure.inl | 1 + iceoryx_hoofs/testing/testing_logger.cpp | 1 + .../include/iceoryx_posh/internal/posh_error_reporting.hpp | 1 + iceoryx_posh/source/posh_error_reporting.cpp | 1 + 11 files changed, 11 insertions(+) diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp b/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp index 7f18c2e699..d2691f7f86 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp +++ b/iceoryx_binding_c/include/iceoryx_binding_c/internal/binding_c_error_reporting.hpp @@ -1,5 +1,6 @@ // Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by 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. diff --git a/iceoryx_binding_c/source/binding_c_error_reporting.cpp b/iceoryx_binding_c/source/binding_c_error_reporting.cpp index 2d219692cf..8457c28724 100644 --- a/iceoryx_binding_c/source/binding_c_error_reporting.cpp +++ b/iceoryx_binding_c/source/binding_c_error_reporting.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 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. diff --git a/iceoryx_hoofs/reporting/include/iox/assertions.hpp b/iceoryx_hoofs/reporting/include/iox/assertions.hpp index 13d06d488a..98df007500 100644 --- a/iceoryx_hoofs/reporting/include/iox/assertions.hpp +++ b/iceoryx_hoofs/reporting/include/iox/assertions.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2023 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 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. diff --git a/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp b/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp index 1fb4c50394..823a59651c 100644 --- a/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp +++ b/iceoryx_hoofs/reporting/include/iox/detail/hoofs_error_reporting.hpp @@ -1,5 +1,6 @@ // Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by 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. diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp index 04ccaa0019..947c3baf2c 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/macros.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2023 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 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. diff --git a/iceoryx_hoofs/reporting/include/iox/error_reporting/violation.hpp b/iceoryx_hoofs/reporting/include/iox/error_reporting/violation.hpp index 5838e2d56c..309f9f2152 100644 --- a/iceoryx_hoofs/reporting/include/iox/error_reporting/violation.hpp +++ b/iceoryx_hoofs/reporting/include/iox/error_reporting/violation.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2023 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 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. diff --git a/iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp b/iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp index 537d1910b2..13e4d5e9be 100644 --- a/iceoryx_hoofs/reporting/source/hoofs_error_reporting.cpp +++ b/iceoryx_hoofs/reporting/source/hoofs_error_reporting.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) 2024 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. diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl index ec9fd39a15..cf38aec8bd 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl @@ -1,4 +1,5 @@ // Copyright (c) 2023 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 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. diff --git a/iceoryx_hoofs/testing/testing_logger.cpp b/iceoryx_hoofs/testing/testing_logger.cpp index 2952136240..5600957499 100644 --- a/iceoryx_hoofs/testing/testing_logger.cpp +++ b/iceoryx_hoofs/testing/testing_logger.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 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. diff --git a/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp b/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp index ab4e70bc88..4caaa5d236 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/posh_error_reporting.hpp @@ -1,5 +1,6 @@ // Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by 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. diff --git a/iceoryx_posh/source/posh_error_reporting.cpp b/iceoryx_posh/source/posh_error_reporting.cpp index 8a5dad9926..a753609218 100644 --- a/iceoryx_posh/source/posh_error_reporting.cpp +++ b/iceoryx_posh/source/posh_error_reporting.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 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. From 6f627feb26059a53e9064cff41ff59513905d1e2 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Fri, 2 Feb 2024 02:38:30 +0100 Subject: [PATCH 20/21] iox-#1032 Make test more robust towards timing issues --- .../test/moduletests/test_popo_trigger_handle.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp b/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp index 1f06533b7f..6bed50ad1e 100644 --- a/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp @@ -121,20 +121,22 @@ TEST_F(TriggerHandle_test, getUniqueIdReturnsCorrectId) TEST_F(TriggerHandle_test, triggerNotifiesConditionVariable) { ::testing::Test::RecordProperty("TEST_ID", "11e752c8-d473-4bfd-b973-869c3b2d9fbc"); - std::atomic_int stage{0}; - iox::deadline_timer timeout{100_ms}; + std::atomic_int stage{0}; std::thread t([&] { stage.store(1); ConditionListener(m_condVar).wait(); + stage.store(2); }); - while (!timeout.hasExpired() && stage.load() < 1) + // the watchdog prevents an infinite loop in case 'stage' is never set to '1' + while (stage.load() < 1) { std::this_thread::yield(); } - ASSERT_FALSE(timeout.hasExpired()); + + iox::deadline_timer timeout{100_ms}; EXPECT_THAT(stage.load(), Eq(1)); std::this_thread::sleep_for(std::chrono::milliseconds(10)); EXPECT_THAT(stage.load(), Eq(1)); From 6e88fa5c669e0b1251ec9691464a25c6ed3c548c Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Sat, 3 Feb 2024 14:26:17 +0100 Subject: [PATCH 21/21] iox-#1032 Fix clang-tidy warnings --- .clang-tidy | 4 ++++ iceoryx_hoofs/concurrent/sync/include/iox/smart_lock.hpp | 7 +++++-- .../include/iox/detail/fixed_position_container.inl | 1 + iceoryx_hoofs/posix/auth/source/posix_user.cpp | 2 +- iceoryx_hoofs/posix/design/include/iox/posix_call.hpp | 4 ++++ iceoryx_hoofs/posix/filesystem/source/posix_acl.cpp | 4 ++-- iceoryx_hoofs/reporting/include/iox/log/logstream.hpp | 4 ++++ .../vocabulary/include/iox/detail/span_iterator.hpp | 5 +++-- 8 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 9a65c1ad1b..4f164dfbc7 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -21,6 +21,7 @@ concurrency-*, performance-*, hicpp-*, +-cppcoreguidelines-avoid-do-while -cppcoreguidelines-non-private-member-variables-in-classes, -hicpp-named-parameter, @@ -100,6 +101,9 @@ hicpp-*, # * rule: readability-use-anyofallof # justification: requires C++20 and std::ranges but we only use C++17 # +# * rule: cppcoreguidelines-avoid-do-while +# justification: there is nothing inherently wrong with do-while loops and there are valid use cases for them +# # * rule: cppcoreguidelines-non-private-member-variables-in-classes # justification: Sometimes it makes sense to have protected members to extend the base class. # Even public members are useful in lightweight classes (effectively structs). diff --git a/iceoryx_hoofs/concurrent/sync/include/iox/smart_lock.hpp b/iceoryx_hoofs/concurrent/sync/include/iox/smart_lock.hpp index 5f8b7295ee..687ba2c49b 100644 --- a/iceoryx_hoofs/concurrent/sync/include/iox/smart_lock.hpp +++ b/iceoryx_hoofs/concurrent/sync/include/iox/smart_lock.hpp @@ -67,8 +67,8 @@ class smart_lock Proxy(const Proxy&) noexcept = default; Proxy(Proxy&&) noexcept = default; - Proxy& operator=(const Proxy&) noexcept = default; - Proxy& operator=(Proxy&&) noexcept = default; + Proxy& operator=(const Proxy&) noexcept = delete; + Proxy& operator=(Proxy&&) noexcept = delete; T* operator->() noexcept; const T* operator->() const noexcept; @@ -77,8 +77,11 @@ class smart_lock const T& operator*() const noexcept; private: + // NOLINTJUSTIFICATION refences are intentionally used since the proxy object does not need to be assignable + // NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members) T& base; MutexType& lock; + // NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members) }; public: diff --git a/iceoryx_hoofs/container/include/iox/detail/fixed_position_container.inl b/iceoryx_hoofs/container/include/iox/detail/fixed_position_container.inl index ab96c99d7d..d5da965597 100644 --- a/iceoryx_hoofs/container/include/iox/detail/fixed_position_container.inl +++ b/iceoryx_hoofs/container/include/iox/detail/fixed_position_container.inl @@ -304,6 +304,7 @@ FixedPositionContainer::emplace(Targs&&... args) noexcept template inline typename FixedPositionContainer::Iterator +// NOLINTNEXTLINE(readability-function-size) The branch-threshold is only violated due to hidden branches in the error handler macros which do not decrease readability FixedPositionContainer::erase(const IndexType index) noexcept { IOX_EXPECTS_WITH_MSG(index <= Index::LAST, "Index out of range"); diff --git a/iceoryx_hoofs/posix/auth/source/posix_user.cpp b/iceoryx_hoofs/posix/auth/source/posix_user.cpp index 6d92ee7201..2f7b3dcfe3 100644 --- a/iceoryx_hoofs/posix/auth/source/posix_user.cpp +++ b/iceoryx_hoofs/posix/auth/source/posix_user.cpp @@ -90,7 +90,7 @@ PosixUser::groupVector_t PosixUser::getGroups() const noexcept groupVector_t vec; for (int32_t i = 0; i < numGroups; ++i) { - vec.emplace_back(PosixGroup(groups[static_cast(i)])); + vec.emplace_back(groups[static_cast(i)]); } return vec; diff --git a/iceoryx_hoofs/posix/design/include/iox/posix_call.hpp b/iceoryx_hoofs/posix/design/include/iox/posix_call.hpp index 4a950d47cb..5e4c9d03c6 100644 --- a/iceoryx_hoofs/posix/design/include/iox/posix_call.hpp +++ b/iceoryx_hoofs/posix/design/include/iox/posix_call.hpp @@ -108,6 +108,8 @@ class [[nodiscard]] PosixCallEvaluator explicit PosixCallEvaluator(detail::PosixCallDetails& details) noexcept; private: + // NOLINTJUSTIFICATION refences are intentionally used since the class does not need to be assignable + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) detail::PosixCallDetails& m_details; }; @@ -139,6 +141,8 @@ class [[nodiscard]] PosixCallVerificator explicit PosixCallVerificator(detail::PosixCallDetails& details) noexcept; private: + // NOLINTJUSTIFICATION refences are intentionally used since the class does not need to be assignable + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) detail::PosixCallDetails& m_details; }; diff --git a/iceoryx_hoofs/posix/filesystem/source/posix_acl.cpp b/iceoryx_hoofs/posix/filesystem/source/posix_acl.cpp index fffd499142..9b1f88432e 100644 --- a/iceoryx_hoofs/posix/filesystem/source/posix_acl.cpp +++ b/iceoryx_hoofs/posix/filesystem/source/posix_acl.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iox/detail/posix_acl.hpp" +#include "iox/assertions.hpp" #include "iox/function.hpp" #include "iox/logging.hpp" #include "iox/posix_call.hpp" @@ -81,7 +82,6 @@ bool PosixAcl::writePermissionsToFile(const int32_t fileDescriptor) const noexce return true; } -// NOLINTEND(readability-function-size,readability-function-cognitive-complexity) expected PosixAcl::createACL(const int32_t numEntries) noexcept { @@ -99,7 +99,7 @@ expected PosixAcl::createACL(const // We ensure here instead of returning as this lambda will be called by unique_ptr /// NOLINTJUSTIFICATION @todo iox-#1032 will be replaced with refactored error handling /// NOLINTNEXTLINE(hicpp-no-array-decay,cppcoreguidelines-pro-bounds-array-to-pointer-decay) - IOX_ENSURES(!aclFreeCall.has_error() && "Could not free ACL memory"); + IOX_ENFORCE(!aclFreeCall.has_error(), "Could not free ACL memory"); }; return ok(aclInitCall->value, freeACL); diff --git a/iceoryx_hoofs/reporting/include/iox/log/logstream.hpp b/iceoryx_hoofs/reporting/include/iox/log/logstream.hpp index ae552878d0..bdca6f65b1 100644 --- a/iceoryx_hoofs/reporting/include/iox/log/logstream.hpp +++ b/iceoryx_hoofs/reporting/include/iox/log/logstream.hpp @@ -53,6 +53,8 @@ class LogHex LogHex(LogHex&&) noexcept = default; + // NOLINTJUSTIFICATION intentionally used since the class does not need to be assignable and the data is not supposed to be changed + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) T m_value; }; @@ -159,6 +161,8 @@ class LogRaw LogRaw(LogRaw&&) noexcept = default; + // NOLINTJUSTIFICATION intentionally used since the class does not need to be assignable and the data is not supposed to be changed + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) const void* const m_data; uint64_t m_size; }; diff --git a/iceoryx_hoofs/vocabulary/include/iox/detail/span_iterator.hpp b/iceoryx_hoofs/vocabulary/include/iox/detail/span_iterator.hpp index 870d502395..2cd87fb2e1 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/detail/span_iterator.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/detail/span_iterator.hpp @@ -32,6 +32,7 @@ class span_iterator final using value_type = std::remove_cv_t; using difference_type = std::ptrdiff_t; using pointer = T*; + using const_pointer = const T*; using reference = T&; constexpr span_iterator(const span_iterator& other) = default; @@ -215,8 +216,8 @@ class span_iterator final return !(*this < rhs); } - const pointer m_begin{nullptr}; - const pointer m_end{nullptr}; + const_pointer m_begin{nullptr}; + const_pointer m_end{nullptr}; pointer m_current{nullptr}; }; } // namespace iox