diff --git a/.clang-tidy-diff-scans.txt b/.clang-tidy-diff-scans.txt index d60ccc64a5b..bda03fc1628 100644 --- a/.clang-tidy-diff-scans.txt +++ b/.clang-tidy-diff-scans.txt @@ -3,10 +3,6 @@ ./iceoryx_hoofs/test/moduletests/test_cxx* ./iceoryx_hoofs/source/cxx/* -./iceoryx_hoofs/include/iceoryx_hoofs/internal/units/* -./iceoryx_hoofs/test/moduletests/test_unit* -./iceoryx_hoofs/source/units/* - ./iceoryx_hoofs/include/iceoryx_hoofs/internal/memory/* ./iceoryx_hoofs/include/iceoryx_hoofs/memory/* ./iceoryx_hoofs/test/moduletests/test_relative_pointer* @@ -28,14 +24,14 @@ ./iceoryx_hoofs/test/moduletests/test_log* ./iceoryx_hoofs/test/moduletests/test_console_logger* ./iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/logger_mock.hpp +./iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure* ./iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/testing_logger.hpp -./iceoryx_hoofs/testing/logger.cpp +./iceoryx_hoofs/testing/testing_logger.cpp ./iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/* ./iceoryx_hoofs/source/posix_wrapper/* ./iceoryx_hoofs/source/posix_wrapper/shared_memory_object/* ./iceoryx_hoofs/test/moduletests/test_posix* -./iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/builder.hpp ./iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/polymorphic_handler.hpp ./iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/static_lifetime_guard.hpp @@ -67,6 +63,9 @@ ./iceoryx_hoofs/buffer/**/* ./iceoryx_hoofs/test/moduletests/test_buffer_* +./iceoryx_hoofs/filesystem/**/* +./iceoryx_hoofs/test/moduletests/test_filesystem_* + # IMPORTANT: # after the first # everything is considered a comment, add new files and # directories only at the top of this file diff --git a/README.md b/README.md index 5b344e74339..57d76c7f206 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Build & Test](https://github.com/eclipse-iceoryx/iceoryx/workflows/Build%20&%20Test/badge.svg?branch=master)](https://github.com/eclipse-iceoryx/iceoryx/actions) [![Integrationtests](https://github.com/eclipse-iceoryx/iceoryx/workflows/Iceoryx%20Integrationtests/badge.svg?branch=master)](https://github.com/eclipse-iceoryx/iceoryx/actions) [![Gitter](https://badges.gitter.im/eclipse-iceoryx/iceoryx.svg)](https://gitter.im/eclipse/iceoryx) -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![Codecov](https://codecov.io/gh/eclipse-iceoryx/iceoryx/branch/master/graph/badge.svg?branch=master)](https://codecov.io/gh/eclipse-iceoryx/iceoryx?branch=master) [![Sanitize](https://github.com/eclipse/iceoryx/workflows/Sanitize/badge.svg?branch=master)](https://github.com/eclipse/iceoryx/actions?query=workflow%3ASanitize) diff --git a/doc/design/error-handling.md b/doc/design/error-handling.md index f63513405ae..c600d03985b 100644 --- a/doc/design/error-handling.md +++ b/doc/design/error-handling.md @@ -264,6 +264,23 @@ auto errorFunc = [](Error& error) { func(arg).and_then(successFunc).or_else(errorFunc); ``` +### Testing fatal error + +For fatal errors the error handler will terminate the execution of the binary. In order to test these paths the +`iox::testing::IOX_EXPECT_FATAL_FAILURE` function should be used instead of the `EXPECT_DEATH` gTest macro. +The `EXPECT_DEATH` gTest macro forks the process which slows down the test execution (especially with the ThreadSanitizer enabled) +and causes issues with running thread. The `IOX_EXPECT_FATAL_FAILURE` registers a temporary error handler and runs the provided +function in a separate thread. When the error handler is called `longjmp` is used to prevent the termination and instead ensures +to gracefully shutdown the thread. + +```cpp +#include "iceoryx_hoofs/testing/fatal_failure.hpp" +TEST(MyTest, valueOnNulloptIsFatal) { + iox::optional sut; + IOX_EXPECT_FATAL_FAILURE([&] { sut.value(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); +} +``` + ## Open points ### Centralized error handling diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 6d68165e8c8..c6800239810 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -116,6 +116,7 @@ - Move `cxx::static_storage` from `iceoryx_hoofs` to `iceoryx_dust` [\#1732](https://github.com/eclipse-iceoryx/iceoryx/issues/1732) - Remove `algorithm::uniqueMergeSortedContainers` from `algorithm.hpp` - Move `std::string` conversion function to `iceoryx_dust` [\#1612](https://github.com/eclipse-iceoryx/iceoryx/issues/1612) +- The posix call `unlink` is directly used in `UnixDomainSocket` [\#1622](https://github.com/eclipse-iceoryx/iceoryx/issues/1622) **Workflow:** @@ -143,7 +144,7 @@ .memorySizeInBytes(16) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); ``` @@ -192,7 +193,7 @@ auto result = iox::posix::NamedSemaphoreBuilder() .name("mySemaphoreName") .openMode(iox::posix::OpenMode::OPEN_OR_CREATE) - .permissions(iox::cxx::perms::owner_all) + .permissions(iox::perms::owner_all) .initialValue(0U) .create(semaphore); ``` @@ -268,7 +269,7 @@ // after auto fileLock = iox::posix::FileLockBuilder().name("lockFileName") .path("/Now/I/Can/Add/A/Path") - .permission(iox::cxx::perms::owner_all) + .permission(iox::perms::owner_all) .create() .expect("Oh no I couldn't create the lock file"); ``` @@ -372,14 +373,14 @@ iox::cxx::isValidPathToFile(..); iox::cxx::isValidPathToDirectory(..); iox::cxx::doesEndWithPathSeparator(..); - + // after - #include "iceoryx_hoofs/cxx/filesystem.hpp" - iox::cxx::isValidPathEntry(..); - iox::cxx::isValidFileName(..); - iox::cxx::isValidPathToFile(..); - iox::cxx::isValidPathToDirectory(..); - iox::cxx::doesEndWithPathSeparator(..); + #include "iox/filesystem.hpp" + iox::isValidPathEntry(..); + iox::isValidFileName(..); + iox::isValidPathToFile(..); + iox::isValidPathToDirectory(..); + iox::doesEndWithPathSeparator(..); ``` ```cpp @@ -994,7 +995,7 @@ std::string myStdString("foo"); // std::string to iox::string - iox::string<3> myIoxString = iox::into>(myStdString); + iox::string<3> myIoxString = iox::into>>(myStdString); // iox::string to std::string std::string myConvertedIoxString = iox::into(myIoxString); ``` diff --git a/iceoryx_binding_c/source/c_runtime.cpp b/iceoryx_binding_c/source/c_runtime.cpp index 4dd491b0494..15f9b1551c7 100644 --- a/iceoryx_binding_c/source/c_runtime.cpp +++ b/iceoryx_binding_c/source/c_runtime.cpp @@ -15,6 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_hoofs/cxx/requires.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" using namespace iox; @@ -26,16 +27,9 @@ extern "C" { void iox_runtime_init(const char* const name) { - if (name == nullptr) - { - LogError() << "Runtime name is a nullptr!"; - std::terminate(); - } - else if (strnlen(name, iox::MAX_RUNTIME_NAME_LENGTH + 1) > MAX_RUNTIME_NAME_LENGTH) - { - LogError() << "Runtime name has more than 100 characters!"; - std::terminate(); - } + iox::cxx::Expects(name != nullptr && "Runtime name is a nullptr!"); + iox::cxx::Expects(strnlen(name, iox::MAX_RUNTIME_NAME_LENGTH + 1) <= MAX_RUNTIME_NAME_LENGTH + && "Runtime name has more than 100 characters!"); PoshRuntime::initRuntime(RuntimeName_t(iox::TruncateToCapacity, name)); } diff --git a/iceoryx_binding_c/test/moduletests/test_publisher.cpp b/iceoryx_binding_c/test/moduletests/test_publisher.cpp index 7e95439526f..bd8c67d79ee 100644 --- a/iceoryx_binding_c/test/moduletests/test_publisher.cpp +++ b/iceoryx_binding_c/test/moduletests/test_publisher.cpp @@ -15,8 +15,10 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_binding_c/error_handling/error_handling.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_publisher.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" @@ -37,6 +39,7 @@ extern "C" { namespace { using namespace ::testing; +using namespace iox::testing; using namespace iox::capro; using namespace iox::cxx; using namespace iox::mepoo; @@ -137,7 +140,8 @@ TEST(iox_pub_test_DeathTest, initPublisherWithNotInitializedPublisherOptionsTerm iox_pub_options_t options; iox_pub_storage_t storage; - EXPECT_DEATH({ iox_pub_init(&storage, "a", "b", "c", &options); }, ".*"); + IOX_EXPECT_FATAL_FAILURE([&] { iox_pub_init(&storage, "a", "b", "c", &options); }, + iox::CBindingError::BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED); } TEST_F(iox_pub_test, initPublisherWithDefaultOptionsWorks) diff --git a/iceoryx_binding_c/test/moduletests/test_runtime.cpp b/iceoryx_binding_c/test/moduletests/test_runtime.cpp index 28e184a0847..75ddc4b64da 100644 --- a/iceoryx_binding_c/test/moduletests/test_runtime.cpp +++ b/iceoryx_binding_c/test/moduletests/test_runtime.cpp @@ -18,6 +18,8 @@ extern "C" { #include "iceoryx_binding_c/runtime.h" } +#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" @@ -25,6 +27,7 @@ namespace { using namespace iox; using namespace iox::runtime; +using namespace iox::testing; class BindingC_Runtime_test : public RouDi_GTest { @@ -69,13 +72,19 @@ TEST_F(BindingC_Runtime_test, RuntimeNameLengthIsOutOfLimit) ::testing::Test::RecordProperty("TEST_ID", "8fd6735d-f331-4c9c-9a91-3f06d3856d15"); std::string tooLongName(iox::MAX_RUNTIME_NAME_LENGTH + 1, 's'); - EXPECT_DEATH({ iox_runtime_init(tooLongName.c_str()); }, ".*"); + IOX_EXPECT_FATAL_FAILURE( + [&] { + iox_runtime_init(tooLongName.c_str()); + ; + }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(BindingC_Runtime_test, RuntimeNameIsNullptr) { ::testing::Test::RecordProperty("TEST_ID", "eb1b76c9-5420-42a9-88b3-db2e36e332de"); - EXPECT_DEATH({ iox_runtime_init(nullptr); }, ".*"); + IOX_EXPECT_FATAL_FAILURE([&] { iox_runtime_init(nullptr); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(BindingC_Runtime_test, GetInstanceNameIsNullptr) diff --git a/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp b/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp index de505975ee8..eb5f0228502 100644 --- a/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp +++ b/iceoryx_binding_c/test/moduletests/test_service_discovery.cpp @@ -14,11 +14,14 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/runtime/service_discovery.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" using namespace iox; using namespace iox::runtime; +using namespace iox::testing; extern "C" { #include "iceoryx_binding_c/publisher.h" @@ -63,7 +66,8 @@ description_vector iox_service_discovery_test::searchResult; TEST(iox_service_discovery_DeathTest, InitServiceDiscoveryWithNullptrForStorageTerminates) { ::testing::Test::RecordProperty("TEST_ID", "be551a9e-7dcf-406a-a74c-7dcb1ee16c30"); - EXPECT_DEATH({ iox_service_discovery_init(nullptr); }, ".*"); + IOX_EXPECT_FATAL_FAILURE([&] { iox_service_discovery_init(nullptr); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } /// @note We test only if the arguments of iox_service_discovery_find_service are correctly passed to diff --git a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp index e3b95c3fe63..55fc6abe9ea 100644 --- a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp +++ b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp @@ -15,8 +15,10 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_binding_c/error_handling/error_handling.hpp" #include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp" #include "iceoryx_binding_c/internal/cpp2c_subscriber.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" @@ -28,6 +30,7 @@ using namespace iox; using namespace iox::popo; +using namespace iox::testing; extern "C" { #include "iceoryx_binding_c/chunk.h" @@ -130,14 +133,14 @@ TEST_F(iox_sub_test, initSubscriberWithNullptrForStorageReturnsNullptr) EXPECT_EQ(iox_sub_init(nullptr, "all", "glory", "hypnotoad", &options), nullptr); } -// this crashes if the fixture is used, therefore a test without a fixture -TEST(iox_sub_test_DeathTest, initSubscriberWithNotInitializedPublisherOptionsTerminates) +TEST_F(iox_sub_test, initSubscriberWithNotInitializedSubscriberOptionsTerminates) { ::testing::Test::RecordProperty("TEST_ID", "6a33309e-fe21-45f6-815a-eebe0136c572"); iox_sub_options_t options; iox_sub_storage_t storage; - EXPECT_DEATH({ iox_sub_init(&storage, "a", "b", "c", &options); }, ".*"); + IOX_EXPECT_FATAL_FAILURE([&] { iox_sub_init(&storage, "a", "b", "c", &options); }, + iox::CBindingError::BINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED); } TEST_F(iox_sub_test, initSubscriberWithDefaultOptionsWorks) diff --git a/iceoryx_dust/include/iceoryx_dust/cxx/std_string_support.hpp b/iceoryx_dust/include/iceoryx_dust/cxx/std_string_support.hpp index ebfa65721e1..8689aee82ff 100644 --- a/iceoryx_dust/include/iceoryx_dust/cxx/std_string_support.hpp +++ b/iceoryx_dust/include/iceoryx_dust/cxx/std_string_support.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// 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. @@ -34,6 +34,12 @@ struct FromImpl> { static string fromImpl(const std::string& value) noexcept; }; + +template +struct FromImpl>> +{ + static string fromImpl(const std::string& value) noexcept; +}; } // namespace iox #include "iceoryx_dust/internal/cxx/std_string_support.inl" diff --git a/iceoryx_dust/include/iceoryx_dust/internal/cli/option_manager.inl b/iceoryx_dust/include/iceoryx_dust/internal/cli/option_manager.inl index 7306cefec0a..61cc16495b3 100644 --- a/iceoryx_dust/include/iceoryx_dust/internal/cli/option_manager.inl +++ b/iceoryx_dust/include/iceoryx_dust/internal/cli/option_manager.inl @@ -62,7 +62,7 @@ inline T OptionManager::defineOption(T& referenceToMember, { constexpr bool IS_NO_SWITCH = false; m_optionSet.addOption(OptionWithDetails{ - {shortName, IS_NO_SWITCH, name, into(cxx::convert::toString(defaultArgumentValue))}, + {shortName, IS_NO_SWITCH, name, into>(cxx::convert::toString(defaultArgumentValue))}, description, optionType, {cxx::TypeInfo::NAME}}); diff --git a/iceoryx_dust/include/iceoryx_dust/internal/cxx/std_string_support.inl b/iceoryx_dust/include/iceoryx_dust/internal/cxx/std_string_support.inl index 44c9ead389b..7ebc22e9c19 100644 --- a/iceoryx_dust/include/iceoryx_dust/internal/cxx/std_string_support.inl +++ b/iceoryx_dust/include/iceoryx_dust/internal/cxx/std_string_support.inl @@ -1,4 +1,4 @@ -// Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// 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. @@ -27,7 +27,17 @@ inline std::string FromImpl, std::string>::fromImpl(const string& v } template -inline string FromImpl>::fromImpl(const std::string& value) noexcept +inline string FromImpl>::fromImpl(const std::string&) noexcept +{ + static_assert(cxx::always_false_v && cxx::always_false_v>, "\n \ + The conversion from 'std::string' to 'iox::sring' is potentially lossy!\n \ + This happens when the size of source string exceeds the capacity of the destination string!\n \ + Please use 'iox::into>>' which returns a 'iox::string' and truncates the\n \ + source string if its size exceeds the capacity of the destination string"); +} + +template +inline string FromImpl>>::fromImpl(const std::string& value) noexcept { return string(TruncateToCapacity, value.c_str(), value.size()); } diff --git a/iceoryx_dust/source/posix_wrapper/named_pipe.cpp b/iceoryx_dust/source/posix_wrapper/named_pipe.cpp index eed84a78a4f..30f84d5bfd3 100644 --- a/iceoryx_dust/source/posix_wrapper/named_pipe.cpp +++ b/iceoryx_dust/source/posix_wrapper/named_pipe.cpp @@ -17,6 +17,7 @@ #include "iceoryx_dust/posix_wrapper/named_pipe.hpp" #include "iceoryx_dust/cxx/std_string_support.hpp" #include "iox/deadline_timer.hpp" +#include "iox/filesystem.hpp" #include "iox/into.hpp" #include @@ -60,10 +61,10 @@ NamedPipe::NamedPipe(const IpcChannelName_t& name, } // leading slash is allowed even though it is not a valid file name - bool isValidPipeName = cxx::isValidFileName(name) + bool isValidPipeName = isValidFileName(name) // name is checked for emptiness, so it's ok to get a first member // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - || (!name.empty() && name.c_str()[0] == '/' && cxx::isValidFileName(*name.substr(1))); + || (!name.empty() && name.c_str()[0] == '/' && isValidFileName(*name.substr(1))); if (!isValidPipeName) { std::cerr << "The named pipe name: \"" << name << "\" is not a valid file path name." << std::endl; @@ -96,7 +97,7 @@ NamedPipe::NamedPipe(const IpcChannelName_t& name, .memorySizeInBytes(sizeof(NamedPipeData) + alignof(NamedPipeData)) .accessMode(AccessMode::READ_WRITE) .openMode((channelSide == IpcChannelSide::SERVER) ? OpenMode::OPEN_OR_CREATE : OpenMode::OPEN_EXISTING) - .permissions(cxx::perms::owner_all | cxx::perms::group_all) + .permissions(perms::owner_all | perms::group_all) .create() .and_then([this](auto& value) { m_sharedMemory.emplace(std::move(value)); })) { @@ -221,7 +222,7 @@ expected NamedPipe::trySend(const std::string& message) const n if (*result) { - IOX_DISCARD_RESULT(m_data->messages.push(into(message))); + IOX_DISCARD_RESULT(m_data->messages.push(into>(message))); cxx::Expects(!m_data->receiveSemaphore().post().has_error()); return success<>(); } @@ -241,7 +242,7 @@ expected NamedPipe::send(const std::string& message) const noex } cxx::Expects(!m_data->sendSemaphore().wait().has_error()); - IOX_DISCARD_RESULT(m_data->messages.push(into(message))); + IOX_DISCARD_RESULT(m_data->messages.push(into>(message))); cxx::Expects(!m_data->receiveSemaphore().post().has_error()); return success<>(); @@ -265,7 +266,7 @@ expected NamedPipe::timedSend(const std::string& message, if (*result == SemaphoreWaitState::NO_TIMEOUT) { - IOX_DISCARD_RESULT(m_data->messages.push(into(message))); + IOX_DISCARD_RESULT(m_data->messages.push(into>(message))); cxx::Expects(!m_data->receiveSemaphore().post().has_error()); return success<>(); } diff --git a/iceoryx_dust/test/moduletests/test_cli_command_line_parser.cpp b/iceoryx_dust/test/moduletests/test_cli_command_line_parser.cpp index 744cc6389ce..d3ef678160e 100644 --- a/iceoryx_dust/test/moduletests/test_cli_command_line_parser.cpp +++ b/iceoryx_dust/test/moduletests/test_cli_command_line_parser.cpp @@ -91,15 +91,15 @@ void FailureTest(const std::vector& options, OptionDefinition optionSet("", [&] { wasErrorHandlerCalled = true; }); for (const auto& o : optionsToRegister) { - optionSet.addOptional(o[0], iox::into(o), "", "int", "0"); + optionSet.addOptional(o[0], iox::into>(o), "", "int", "0"); } for (const auto& s : switchesToRegister) { - optionSet.addSwitch(s[0], iox::into(s), ""); + optionSet.addSwitch(s[0], iox::into>(s), ""); } for (const auto& r : requiredValuesToRegister) { - optionSet.addRequired(r[0], iox::into(r), "", "int"); + optionSet.addRequired(r[0], iox::into>(r), "", "int"); } IOX_DISCARD_RESULT(parseCommandLineArguments(optionSet, args.argc, args.argv, 1U)); @@ -893,15 +893,16 @@ Arguments SuccessTest(const std::vector& options, OptionDefinition optionSet(""); for (const auto& o : optionsToRegister) { - optionSet.addOptional(o[0], iox::into(o), "", "int", CommandLineParser_test::defaultValue); + optionSet.addOptional( + o[0], iox::into>(o), "", "int", CommandLineParser_test::defaultValue); } for (const auto& s : switchesToRegister) { - optionSet.addSwitch(s[0], iox::into(s), ""); + optionSet.addSwitch(s[0], iox::into>(s), ""); } for (const auto& r : requiredValuesToRegister) { - optionSet.addRequired(r[0], iox::into(r), "", "int"); + optionSet.addRequired(r[0], iox::into>(r), "", "int"); } { diff --git a/iceoryx_dust/test/moduletests/test_cxx_forward_list.cpp b/iceoryx_dust/test/moduletests/test_cxx_forward_list.cpp index 9292112930f..596346fbfd5 100644 --- a/iceoryx_dust/test/moduletests/test_cxx_forward_list.cpp +++ b/iceoryx_dust/test/moduletests/test_cxx_forward_list.cpp @@ -16,12 +16,15 @@ #include "iceoryx_dust/cxx/forward_list.hpp" #include "iceoryx_hoofs/cxx/attributes.hpp" +#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" namespace { using namespace ::testing; using namespace iox::cxx; +using namespace iox::testing; constexpr uint64_t TESTLISTCAPACITY{10U}; constexpr int64_t TEST_LIST_ELEMENT_DEFAULT_VALUE{-99L}; @@ -142,15 +145,6 @@ int64_t iteratorTraitReturnDoubleValue(IterType iter) IterValueType m_value = *iter; return (2 * m_value); // will only work for integer-convertible m_value types } - -// in context of EXPECT_DEATH tests, dummyFunc() shall help suppressing following warning : -// -Wunused-comparison -// reason: the warning is already addressed with the internal handling, which shall be tested here -bool dummyFunc(bool whatever) -{ - std::cerr << "Never get here - ever " << whatever << std::endl; - return whatever; -} } // namespace @@ -292,9 +286,7 @@ TEST_F(forward_list_test, FullWhenFilledWithMoreThanCapacityElements) } EXPECT_THAT(sut.full(), Eq(true)); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(sut.emplace_front(), ""); + IOX_EXPECT_FATAL_FAILURE([&] { sut.emplace_front(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(forward_list_test, NotFullWhenFilledWithCapacityAndEraseOneElements) { @@ -666,9 +658,8 @@ TEST_F(forward_list_test, EmplaceAfterWithWrongListIterator) ++cnt; } - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(sut11.emplace_after(iterOfSut12, cnt), ""); + IOX_EXPECT_FATAL_FAILURE([&] { sut11.emplace_after(iterOfSut12, cnt); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(forward_list_test, PushFrontConstCustomSuccessfullWhenSpaceAvailableLValue) @@ -1166,39 +1157,39 @@ TEST_F(forward_list_test, IteratorComparisonOfDifferentLists) auto iterSut1 = sut11.begin(); auto iterSut2 = sut12.begin(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 == iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 == iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.before_begin(); iterSut2 = sut12.before_begin(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 == iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 == iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.end(); iterSut2 = sut12.end(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 == iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 == iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.begin(); iterSut2 = sut12.begin(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 != iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 != iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.before_begin(); iterSut2 = sut12.before_begin(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 != iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 != iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.end(); iterSut2 = sut12.end(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 != iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 != iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } @@ -1988,9 +1979,7 @@ TEST_F(forward_list_test, invalidIteratorErase) auto iter = sut.begin(); sut.pop_front(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(sut.erase_after(iter), ""); + IOX_EXPECT_FATAL_FAILURE([&] { sut.erase_after(iter); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(forward_list_test, invalidIteratorIncrement) @@ -2005,9 +1994,7 @@ TEST_F(forward_list_test, invalidIteratorIncrement) auto iter = sut.cbegin(); sut.pop_front(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(++iter, ""); + IOX_EXPECT_FATAL_FAILURE([&] { ++iter; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(forward_list_test, invalidIteratorComparison) @@ -2022,9 +2009,8 @@ TEST_F(forward_list_test, invalidIteratorComparison) auto iter = sut.cbegin(); sut.pop_front(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(sut.cbegin() == iter), ""); + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(sut.cbegin() == iter); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(forward_list_test, invalidIteratorComparisonUnequal) @@ -2039,9 +2025,8 @@ TEST_F(forward_list_test, invalidIteratorComparisonUnequal) sut.pop_front(); auto iter2 = sut.cbegin(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iter2 != iter), ""); + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iter2 != iter); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(forward_list_test, invalidIteratorDereferencing) @@ -2056,9 +2041,7 @@ TEST_F(forward_list_test, invalidIteratorDereferencing) auto iter = sut.cbegin(); sut.pop_front(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(sut.remove(*iter), ""); + IOX_EXPECT_FATAL_FAILURE([&] { sut.remove(*iter); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(forward_list_test, invalidIteratorAddressOfOperator) @@ -2073,9 +2056,8 @@ TEST_F(forward_list_test, invalidIteratorAddressOfOperator) auto iter = sut.cbegin(); sut.pop_front(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iter->m_value == 12U), ""); + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iter->m_value == 12U); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(forward_list_test, ListIsCopyableViaMemcpy) diff --git a/iceoryx_dust/test/moduletests/test_cxx_string_conversion.cpp b/iceoryx_dust/test/moduletests/test_cxx_string_conversion.cpp index 0fc1f65131b..5cc98960cc5 100644 --- a/iceoryx_dust/test/moduletests/test_cxx_string_conversion.cpp +++ b/iceoryx_dust/test/moduletests/test_cxx_string_conversion.cpp @@ -43,7 +43,7 @@ TYPED_TEST(StdString_test, STDStringToStringConvConstrWithSize0ResultsInSize0) using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString::capacity(); std::string testString; - string fuu = into(testString); + string fuu = into>(testString); EXPECT_THAT(fuu.capacity(), Eq(STRINGCAP)); EXPECT_THAT(fuu.size(), Eq(0U)); EXPECT_THAT(fuu.c_str(), StrEq("")); @@ -55,7 +55,7 @@ TYPED_TEST(StdString_test, STDStringToStringConvConstrWithSizeSmallerCapaResults using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString::capacity(); std::string testString(STRINGCAP - 1U, 'M'); - string fuu = into(testString); + string fuu = into>(testString); EXPECT_THAT(fuu.capacity(), Eq(STRINGCAP)); EXPECT_THAT(fuu.size(), Eq(STRINGCAP - 1U)); EXPECT_THAT(fuu.c_str(), Eq(testString)); @@ -67,7 +67,7 @@ TYPED_TEST(StdString_test, STDStringToStringConvConstrWithSizeCapaResultsInSizeC using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString::capacity(); std::string testString(STRINGCAP, 'M'); - string fuu = into(testString); + string fuu = into>(testString); EXPECT_THAT(fuu.capacity(), Eq(STRINGCAP)); EXPECT_THAT(fuu.size(), Eq(STRINGCAP)); EXPECT_THAT(fuu.c_str(), Eq(testString)); @@ -79,7 +79,7 @@ TYPED_TEST(StdString_test, STDStringToStringConvConstrWithSizeGreaterCapaResults using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString::capacity(); std::string testString(STRINGCAP + 1U, 'M'); - string fuu = into(testString); + string fuu = into>(testString); EXPECT_THAT(fuu.capacity(), Eq(STRINGCAP)); EXPECT_THAT(fuu.size(), Eq(STRINGCAP)); EXPECT_THAT(fuu.c_str(), Eq(testString.substr(0U, STRINGCAP))); diff --git a/iceoryx_dust/test/moduletests/test_file_reader.cpp b/iceoryx_dust/test/moduletests/test_file_reader.cpp index 58e095d1953..c0303aed42b 100644 --- a/iceoryx_dust/test/moduletests/test_file_reader.cpp +++ b/iceoryx_dust/test/moduletests/test_file_reader.cpp @@ -160,6 +160,7 @@ TEST_F(FileReader_test, errorTerminateMode) std::set_terminate([]() { std::cout << "", std::abort(); }); // @todo iox-#1613 remove EXPECT_DEATH + // using IOX_EXPECT_FATAL_FAILURE currently causes issues with the leak sanitizer with this test // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) EXPECT_DEATH( { diff --git a/iceoryx_hoofs/BUILD.bazel b/iceoryx_hoofs/BUILD.bazel index 9d36401f578..e31df5a69f0 100644 --- a/iceoryx_hoofs/BUILD.bazel +++ b/iceoryx_hoofs/BUILD.bazel @@ -1,4 +1,4 @@ -# Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +# 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. @@ -30,20 +30,22 @@ configure_file( cc_library( name = "iceoryx_hoofs", srcs = glob([ - "source/**/*.cpp", - "vocabulary/source/**/*.cpp", - "source/**/*.hpp", - "memory/source/*.cpp", "design/source/*.cpp", + "filesystem/source/*.cpp", + "memory/source/*.cpp", "posix/time/source/*.cpp", + "source/**/*.cpp", + "time/source/*.cpp", + "vocabulary/source/**/*.cpp", ]), - hdrs = glob(["include/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["container/**"]) + glob(["vocabulary/**"]) + glob(["time/**"]) + glob(["utility/**"]) + glob(["primitives/**"]) + glob(["posix/**"]) + glob(["design/**"]) + glob(["buffer/**"]) + [ + hdrs = glob(["include/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["container/**"]) + glob(["vocabulary/**"]) + glob(["time/**"]) + glob(["utility/**"]) + glob(["primitives/**"]) + glob(["posix/**"]) + glob(["design/**"]) + glob(["buffer/**"]) + glob(["filesystem/**"]) + [ ":iceoryx_hoofs_deployment_hpp", ], includes = [ "buffer/include/", "container/include/", "design/include", + "filesystem/include", "include/", "legacy/include/", "memory/include/", diff --git a/iceoryx_hoofs/CMakeLists.txt b/iceoryx_hoofs/CMakeLists.txt index 0dd446b1ac1..43a0043a277 100644 --- a/iceoryx_hoofs/CMakeLists.txt +++ b/iceoryx_hoofs/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (c) 2019 - 2021 by Robert Bosch GmbH. All rights reserved. -# Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +# Copyright (c) 2020 - 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. @@ -57,6 +57,7 @@ iox_add_library( ${PROJECT_SOURCE_DIR}/time/include ${PROJECT_SOURCE_DIR}/posix/time/include ${PROJECT_SOURCE_DIR}/buffer/include + ${PROJECT_SOURCE_DIR}/filesystem/include ${CMAKE_BINARY_DIR}/generated/iceoryx_hoofs/include INSTALL_INTERFACE include/${PREFIX} EXPORT_INCLUDE_DIRS include/ @@ -70,11 +71,15 @@ iox_add_library( time/include/ posix/time/include/ buffer/include/ + filesystem/include/ FILES - source/concurrent/loffli.cpp + design/source/functional_interface.cpp + filesystem/source/filesystem.cpp + memory/source/bump_allocator.cpp + memory/source/memory.cpp posix/time/source/adaptive_wait.cpp posix/time/source/deadline_timer.cpp - source/cxx/filesystem.cpp + source/concurrent/loffli.cpp source/cxx/requires.cpp source/cxx/type_traits.cpp source/cxx/unique_id.cpp @@ -99,10 +104,7 @@ iox_add_library( source/posix_wrapper/unnamed_semaphore.cpp source/posix_wrapper/unix_domain_socket.cpp source/memory/relative_pointer_data.cpp - source/units/duration.cpp - memory/source/bump_allocator.cpp - memory/source/memory.cpp - design/source/functional_interface.cpp + time/source/duration.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/iceoryx_hoofs_deployment.hpp.in" diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/filesystem.inl b/iceoryx_hoofs/filesystem/include/iox/detail/filesystem.inl similarity index 98% rename from iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/filesystem.inl rename to iceoryx_hoofs/filesystem/include/iox/detail/filesystem.inl index 46d2bc24c1a..2cc8647a278 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/filesystem.inl +++ b/iceoryx_hoofs/filesystem/include/iox/detail/filesystem.inl @@ -13,15 +13,13 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#ifndef IOX_HOOFS_CXX_FILESYSTEM_INL -#define IOX_HOOFS_CXX_FILESYSTEM_INL +#ifndef IOX_HOOFS_FILESYSTEM_FILESYSTEM_INL +#define IOX_HOOFS_FILESYSTEM_FILESYSTEM_INL -#include "iceoryx_hoofs/cxx/filesystem.hpp" +#include "iox/filesystem.hpp" namespace iox { -namespace cxx -{ template inline bool isValidPathEntry(const iox::string& name, const RelativePathComponents relativePathComponents) noexcept @@ -220,7 +218,6 @@ constexpr perms operator^=(const perms lhs, const perms rhs) noexcept { return operator^(lhs, rhs); } -} // namespace cxx } // namespace iox #endif diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/filesystem.hpp b/iceoryx_hoofs/filesystem/include/iox/filesystem.hpp similarity index 97% rename from iceoryx_hoofs/include/iceoryx_hoofs/cxx/filesystem.hpp rename to iceoryx_hoofs/filesystem/include/iox/filesystem.hpp index 1b31e53f6fd..68b9197b7ba 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/filesystem.hpp +++ b/iceoryx_hoofs/filesystem/include/iox/filesystem.hpp @@ -13,8 +13,8 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#ifndef IOX_HOOFS_CXX_FILESYSTEM_HPP -#define IOX_HOOFS_CXX_FILESYSTEM_HPP +#ifndef IOX_HOOFS_FILESYSTEM_FILESYSTEM_HPP +#define IOX_HOOFS_FILESYSTEM_FILESYSTEM_HPP #include "iox/string.hpp" @@ -23,8 +23,6 @@ namespace iox { -namespace cxx -{ namespace internal { // AXIVION DISABLE STYLE AutosarC++19_03-A3.9.1: Not used as an integer but as actual character. @@ -197,9 +195,8 @@ constexpr perms operator^=(const perms lhs, const perms rhs) noexcept; /// @return the reference to the stream template StreamType& operator<<(StreamType& stream, const perms value) noexcept; -} // namespace cxx } // namespace iox -#include "iceoryx_hoofs/internal/cxx/filesystem.inl" +#include "iox/detail/filesystem.inl" #endif diff --git a/iceoryx_hoofs/source/cxx/filesystem.cpp b/iceoryx_hoofs/filesystem/source/filesystem.cpp similarity index 98% rename from iceoryx_hoofs/source/cxx/filesystem.cpp rename to iceoryx_hoofs/filesystem/source/filesystem.cpp index e5e824d6d2b..982b48461e6 100644 --- a/iceoryx_hoofs/source/cxx/filesystem.cpp +++ b/iceoryx_hoofs/filesystem/source/filesystem.cpp @@ -14,14 +14,12 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/filesystem.hpp" +#include "iox/filesystem.hpp" #include "iceoryx_hoofs/log/logstream.hpp" #include namespace iox { -namespace cxx -{ template static void outputToStream(StreamType& stream, const char* text, bool& hasPrecedingEntry) { @@ -167,5 +165,4 @@ StreamType& operator<<(StreamType& stream, const perms value) noexcept template std::ostream& operator<<(std::ostream&, const perms) noexcept; template log::LogStream& operator<<(log::LogStream&, const perms) noexcept; -} // namespace cxx } // namespace iox diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp index 2f72a0ad19d..49d7918b204 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp @@ -17,12 +17,12 @@ #ifndef IOX_HOOFS_POSIX_WRAPPER_SHARED_MEMORY_OBJECT_HPP #define IOX_HOOFS_POSIX_WRAPPER_SHARED_MEMORY_OBJECT_HPP -#include "iceoryx_hoofs/cxx/filesystem.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/memory_map.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp" #include "iceoryx_platform/stat.hpp" #include "iox/builder.hpp" #include "iox/bump_allocator.hpp" +#include "iox/filesystem.hpp" #include "iox/optional.hpp" #include @@ -138,7 +138,7 @@ class SharedMemoryObjectBuilder IOX_BUILDER_PARAMETER(optional, baseAddressHint, nullopt) /// @brief Defines the access permissions of the shared memory - IOX_BUILDER_PARAMETER(cxx::perms, permissions, cxx::perms::none) + IOX_BUILDER_PARAMETER(perms, permissions, perms::none) public: expected create() noexcept; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp index 22b0706b41a..d4b1797ebce 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp @@ -17,10 +17,10 @@ #ifndef IOX_HOOFS_POSIX_WRAPPER_SHARED_MEMORY_OBJECT_SHARED_MEMORY_HPP #define IOX_HOOFS_POSIX_WRAPPER_SHARED_MEMORY_OBJECT_SHARED_MEMORY_HPP -#include "iceoryx_hoofs/cxx/filesystem.hpp" #include "iceoryx_hoofs/posix_wrapper/types.hpp" #include "iox/builder.hpp" #include "iox/expected.hpp" +#include "iox/filesystem.hpp" #include "iox/optional.hpp" #include "iox/string.hpp" @@ -116,7 +116,7 @@ class SharedMemoryBuilder IOX_BUILDER_PARAMETER(OpenMode, openMode, OpenMode::OPEN_EXISTING) /// @brief Defines the access permissions of the shared memory - IOX_BUILDER_PARAMETER(cxx::perms, filePermissions, cxx::perms::none) + IOX_BUILDER_PARAMETER(perms, filePermissions, perms::none) /// @brief Defines the size of the shared memory IOX_BUILDER_PARAMETER(uint64_t, size, 0U) diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/file_lock.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/file_lock.hpp index b4dba1848bc..8a4ed25ddfa 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/file_lock.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/file_lock.hpp @@ -16,10 +16,10 @@ #ifndef IOX_HOOFS_POSIX_WRAPPER_FILE_LOCK_HPP #define IOX_HOOFS_POSIX_WRAPPER_FILE_LOCK_HPP -#include "iceoryx_hoofs/cxx/filesystem.hpp" #include "iceoryx_platform/file.hpp" #include "iox/builder.hpp" #include "iox/expected.hpp" +#include "iox/filesystem.hpp" #include "iox/string.hpp" namespace iox @@ -121,7 +121,7 @@ class FileLockBuilder /// @brief Defines the access permissions of the file lock. If they are not /// explicitly set they will be none - IOX_BUILDER_PARAMETER(cxx::perms, permission, cxx::perms::none) + IOX_BUILDER_PARAMETER(perms, permission, perms::none) public: /// @brief Creates a file lock diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/named_semaphore.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/named_semaphore.hpp index e39d4e00d8f..afd3deb9db6 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/named_semaphore.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/named_semaphore.hpp @@ -16,12 +16,12 @@ #ifndef IOX_HOOFS_POSIX_WRAPPER_NAMED_SEMAPHORE_HPP #define IOX_HOOFS_POSIX_WRAPPER_NAMED_SEMAPHORE_HPP -#include "iceoryx_hoofs/cxx/filesystem.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/semaphore_interface.hpp" #include "iceoryx_hoofs/posix_wrapper/types.hpp" #include "iceoryx_platform/platform_settings.hpp" #include "iox/builder.hpp" #include "iox/expected.hpp" +#include "iox/filesystem.hpp" #include "iox/optional.hpp" #include "iox/string.hpp" @@ -64,7 +64,7 @@ class NamedSemaphoreBuilder IOX_BUILDER_PARAMETER(OpenMode, openMode, OpenMode::OPEN_EXISTING) /// @brief Defines the access permissions of the semaphore - IOX_BUILDER_PARAMETER(cxx::perms, permissions, cxx::perms::owner_all) + IOX_BUILDER_PARAMETER(perms, permissions, perms::owner_all) /// @brief Set the initial value of the unnamed posix semaphore. This value is only used when a new semaphore is /// created. diff --git a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/filesystem.hpp b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/filesystem.hpp new file mode 100644 index 00000000000..83497adc1a9 --- /dev/null +++ b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/filesystem.hpp @@ -0,0 +1,32 @@ +// 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_CXX_FILESYSTEM_HPP +#define IOX_HOOFS_CXX_FILESYSTEM_HPP + +#include "iox/filesystem.hpp" + +namespace iox +{ +/// @todo iox-#1593 Deprecate include +/// [[deprecated("Deprecated in 3.0, removed in 4.0, please include 'iox/filesystem.hpp' instead")]] +namespace cxx +{ +/// @deprecated use `iox::perms` instead of `iox::cxx::perms` +using iox::perms; +} // namespace cxx +} // namespace iox + +#endif diff --git a/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp b/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp index 5b666723300..bf3b4d63eb5 100644 --- a/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp @@ -35,13 +35,13 @@ constexpr const char FileLock::LOCK_FILE_SUFFIX[]; expected FileLockBuilder::create() noexcept { - if (!cxx::isValidFileName(m_name)) + if (!isValidFileName(m_name)) { IOX_LOG(ERROR) << "Unable to create FileLock since the name \"" << m_name << "\" is not a valid file name."; return error(FileLockError::INVALID_FILE_NAME); } - if (!cxx::isValidPathToDirectory(m_path)) + if (!isValidPathToDirectory(m_path)) { IOX_LOG(ERROR) << "Unable to create FileLock since the path \"" << m_path << "\" is not a valid path."; return error(FileLockError::INVALID_PATH); @@ -49,7 +49,7 @@ expected FileLockBuilder::create() noexcept FileLock::FilePath_t fileLockPath = m_path; - if (!cxx::doesEndWithPathSeparator(fileLockPath)) + if (!doesEndWithPathSeparator(fileLockPath)) { fileLockPath.unsafe_append(iox::platform::IOX_PATH_SEPARATORS[0]); } diff --git a/iceoryx_hoofs/source/posix_wrapper/named_semaphore.cpp b/iceoryx_hoofs/source/posix_wrapper/named_semaphore.cpp index 4b1e505915f..e1c0273e4c8 100644 --- a/iceoryx_hoofs/source/posix_wrapper/named_semaphore.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/named_semaphore.cpp @@ -104,7 +104,7 @@ tryOpenExistingSemaphore(optional& uninitializedSemaphore, const static expected createSemaphore(optional& uninitializedSemaphore, const NamedSemaphore::Name_t& name, const OpenMode openMode, - const cxx::perms permissions, + const perms permissions, const uint32_t initialValue) noexcept { auto result = posixCall(iox_sem_open_ext)(createNameWithSlash(name).c_str(), @@ -157,7 +157,7 @@ expected // NOLINTNEXTLINE(readability-function-size,readability-function-cognitive-complexity) NamedSemaphoreBuilder::create(optional& uninitializedSemaphore) const noexcept { - if (!cxx::isValidFileName(m_name)) + if (!isValidFileName(m_name)) { IOX_LOG(ERROR) << "The name \"" << m_name << "\" is not a valid semaphore name."; return error(SemaphoreError::INVALID_NAME); diff --git a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp index 8a1182eea0d..298ebe4b385 100644 --- a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp @@ -58,7 +58,7 @@ expected SharedMemoryBuilder::create() noexcept return error(SharedMemoryError::EMPTY_NAME); } - if (!cxx::isValidFileName(m_name)) + if (!isValidFileName(m_name)) { IOX_LOG(ERROR) << "Shared memory requires a valid file name (not path) as name and \"" << m_name << "\" is not a valid file name"; diff --git a/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp b/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp index 2bd1ed41c5e..cdf81ed8fab 100644 --- a/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. -// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2021 - 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. @@ -51,7 +51,7 @@ UnixDomainSocket::UnixDomainSocket(const IpcChannelName_t& name, [&]() -> UdsName_t { /// invalid names will be forwarded and handled by the other constructor /// separately - if (!cxx::isValidPathToFile(name)) + if (!isValidPathToFile(name)) { return name; } @@ -75,7 +75,7 @@ UnixDomainSocket::UnixDomainSocket(const NoPathPrefix_t, : m_name(name) , m_channelSide(channelSide) { - if (!cxx::isValidPathToFile(name)) + if (!isValidPathToFile(name)) { this->m_isInitialized = false; this->m_errorValue = IpcChannelError::INVALID_CHANNEL_NAME; @@ -137,7 +137,7 @@ bool UnixDomainSocket::isInitialized() const noexcept expected UnixDomainSocket::unlinkIfExists(const UdsName_t& name) noexcept { - if (!cxx::isValidPathToFile(name)) + if (!isValidPathToFile(name)) { return error(IpcChannelError::INVALID_CHANNEL_NAME); } @@ -153,7 +153,7 @@ expected UnixDomainSocket::unlinkIfExists(const UdsName_t expected UnixDomainSocket::unlinkIfExists(const NoPathPrefix_t, const UdsName_t& name) noexcept { - if (!cxx::isValidPathToFile(name)) + if (!isValidPathToFile(name)) { return error(IpcChannelError::INVALID_CHANNEL_NAME); } @@ -178,7 +178,14 @@ expected UnixDomainSocket::closeFileDescriptor() noexcept { if (IpcChannelSide::SERVER == m_channelSide) { - unlink(&(m_sockAddr.sun_path[0])); + auto unlinkCall = posixCall(unlink)(&(m_sockAddr.sun_path[0])) + .failureReturnValue(ERROR_CODE) + .ignoreErrnos(ENOENT) + .evaluate(); + if (unlinkCall.has_error()) + { + return error(IpcChannelError::INTERNAL_LOGIC_ERROR); + } } m_sockfd = INVALID_FD; diff --git a/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp new file mode 100644 index 00000000000..1d7487e623f --- /dev/null +++ b/iceoryx_hoofs/test/mocktests/test_fatal_failure.cpp @@ -0,0 +1,73 @@ +// 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 "iceoryx_hoofs/testing/fatal_failure.hpp" + +#include "test.hpp" + +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::cxx::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::cxx::Expects(false); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); + + EXPECT_TRUE(hasFatalFailure); +} + +TEST(FatalFailure, UsingExpectNoFatalFailureWorks) +{ + ::testing::Test::RecordProperty("TEST_ID", "80bf8050-bfaa-4482-b69c-d0c80699bd4b"); + + auto hasNoFatalFailure = IOX_EXPECT_NO_FATAL_FAILURE([&] {}); + + EXPECT_TRUE(hasNoFatalFailure); +} +} // namespace diff --git a/iceoryx_hoofs/test/mocktests/test_hoofs_mock.cpp b/iceoryx_hoofs/test/mocktests/test_hoofs_mock.cpp index 4335565a1f9..2ec14def322 100644 --- a/iceoryx_hoofs/test/mocktests/test_hoofs_mock.cpp +++ b/iceoryx_hoofs/test/mocktests/test_hoofs_mock.cpp @@ -15,6 +15,8 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_hoofs/testing/testing_logger.hpp" + #include "test.hpp" using ::testing::_; @@ -22,5 +24,8 @@ using ::testing::_; int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); + + iox::testing::TestingLogger::init(); + return RUN_ALL_TESTS(); } diff --git a/iceoryx_hoofs/test/moduletests/test_concurrent_loffli.cpp b/iceoryx_hoofs/test/moduletests/test_concurrent_loffli.cpp index 867b7f0903c..2bce21af8c3 100644 --- a/iceoryx_hoofs/test/moduletests/test_concurrent_loffli.cpp +++ b/iceoryx_hoofs/test/moduletests/test_concurrent_loffli.cpp @@ -15,7 +15,9 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_hoofs/error_handling/error_handling.hpp" #include "iceoryx_hoofs/internal/concurrent/loffli.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" #include @@ -25,6 +27,7 @@ namespace { using namespace ::testing; +using namespace iox::testing; constexpr uint32_t Size{4}; using LoFFLiTestSubjects = Types; @@ -53,32 +56,37 @@ class LoFFLi_test : public Test TYPED_TEST(LoFFLi_test, Misuse_NullptrMemory) { ::testing::Test::RecordProperty("TEST_ID", "ab877f29-cab0-48ae-a2c0-054633b6415a"); + decltype(this->m_loffli) loFFLi; - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(loFFLi.init(nullptr, 1), ".*"); + + IOX_EXPECT_FATAL_FAILURE([&] { loFFLi.init(nullptr, 1); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(LoFFLi_test, Misuse_ZeroSize) { ::testing::Test::RecordProperty("TEST_ID", "fb9c797b-22b4-4572-a7a2-eaf13574dbac"); - // NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) needed to test LoFFLi::init + + // NOLINTBEGIN(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) needed to test LoFFLi::init uint32_t memoryLoFFLi[4]; decltype(this->m_loffli) loFFLi; - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(loFFLi.init(&memoryLoFFLi[0], 0), ".*"); + + IOX_EXPECT_FATAL_FAILURE([&] { loFFLi.init(&memoryLoFFLi[0], 0); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); + // NOLINTEND(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) } TYPED_TEST(LoFFLi_test, Misuse_SizeToLarge) { ::testing::Test::RecordProperty("TEST_ID", "14b4b82c-ae2b-4bd2-97cf-93fcea87f050"); - // NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) needed to test LoFFLi::init + + // NOLINTBEGIN(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) needed to test LoFFLi::init uint32_t memoryLoFFLi[4]; decltype(this->m_loffli) loFFLi; - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(loFFLi.init(&memoryLoFFLi[0], UINT32_MAX - 1), ".*"); + + IOX_EXPECT_FATAL_FAILURE([&] { loFFLi.init(&memoryLoFFLi[0], UINT32_MAX - 1); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); + // NOLINTEND(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) } diff --git a/iceoryx_hoofs/test/moduletests/test_cxx_function_ref.cpp b/iceoryx_hoofs/test/moduletests/test_cxx_function_ref.cpp index 8557e219b1e..7bd2fcd8956 100644 --- a/iceoryx_hoofs/test/moduletests/test_cxx_function_ref.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cxx_function_ref.cpp @@ -17,13 +17,15 @@ #include "iceoryx_hoofs/cxx/attributes.hpp" #include "iceoryx_hoofs/cxx/function_ref.hpp" +#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" - namespace { using namespace ::testing; using namespace iox::cxx; +using namespace iox::testing; constexpr int FREE_FUNC_TEST_VALUE = 42 + 42; constexpr int FUNCTOR_TEST_VALUE = 11; @@ -162,15 +164,15 @@ TEST_F(function_refTest, CreateValidByMoveAssignResultEqual) TEST_F(function_refDeathTest, CallMovedFromLeadsToTermination) { ::testing::Test::RecordProperty("TEST_ID", "3402f27e-ced5-483f-ab39-0069cfd172ac"); + auto lambda = []() -> int { return 7654; }; function_ref sut1{lambda}; function_ref sut2{std::move(sut1)}; + // NOLINTJUSTIFICATION Use after move is tested here - // NOLINTBEGIN(bugprone-use-after-move, hicpp-invalid-access-moved, cppcoreguidelines-pro-type-vararg, - // cppcoreguidelines-avoid-goto) - EXPECT_DEATH(sut1(), ""); // ERROR: Empty function_ref invoked - // NOLINTEND(bugprone-use-after-move, hicpp-invalid-access-moved, cppcoreguidelines-pro-type-vararg, - // cppcoreguidelines-avoid-goto) + // NOLINTBEGIN(bugprone-use-after-move, hicpp-invalid-access-moved) + IOX_EXPECT_FATAL_FAILURE([&] { sut1(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); + // NOLINTEND(bugprone-use-after-move, hicpp-invalid-access-moved) } TEST_F(function_refTest, CreateValidAndSwapResultEqual) diff --git a/iceoryx_hoofs/test/moduletests/test_cxx_list.cpp b/iceoryx_hoofs/test/moduletests/test_cxx_list.cpp index ab0e4038ea2..7564c2edf3d 100644 --- a/iceoryx_hoofs/test/moduletests/test_cxx_list.cpp +++ b/iceoryx_hoofs/test/moduletests/test_cxx_list.cpp @@ -17,7 +17,9 @@ #include "iceoryx_hoofs/cxx/attributes.hpp" #include "iceoryx_hoofs/cxx/list.hpp" +#include "iceoryx_hoofs/error_handling/error_handling.hpp" #include "iceoryx_hoofs/log/logging.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" @@ -25,6 +27,7 @@ namespace { using namespace ::testing; using namespace iox::cxx; +using namespace iox::testing; constexpr uint64_t TESTLISTCAPACITY{10U}; constexpr int64_t TEST_LIST_ELEMENT_DEFAULT_VALUE{-99L}; @@ -149,15 +152,6 @@ int64_t iteratorTraitReturnDoubleValue(IterType iter) IterValueType m_value = *iter; return (2 * m_value); // will only work for integer-convertible m_value types } - -// in context of EXPECT_DEATH tests, dummyFunc() shall help suppressing following warning : -// -Wunused-comparison -// reason: the warning is already addressed with the internal handling, which shall be tested here -bool dummyFunc(bool whatever) -{ - IOX_LOG(ERROR) << "Never get here - ever " << whatever; - return whatever; -} } // namespace @@ -272,15 +266,18 @@ TEST_F(list_test, FullWhenFilledWithCapacityElements) TEST_F(list_test, FullWhenFilledWithMoreThanCapacityElements) { ::testing::Test::RecordProperty("TEST_ID", "585bb3d9-112c-4db8-af5e-e4c646723515"); - for (uint64_t i = 0U; i < sut.capacity(); ++i) - { - sut.emplace_front(); - } - EXPECT_THAT(sut.full(), Eq(true)); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(sut.emplace_front(), ""); + IOX_EXPECT_FATAL_FAILURE( + [&] { + for (uint64_t i = 0U; i < sut.capacity(); ++i) + { + sut.emplace_front(); + } + + EXPECT_THAT(sut.full(), Eq(true)); + sut.emplace_front(); + }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(list_test, NotFullWhenFilledWithCapacityAndEraseOneElements) { @@ -727,9 +724,8 @@ TEST_F(list_test, EmplaceBackWithMoreThanCapacityElements) } else { - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(sut1.emplace_back(cnt), ""); + IOX_EXPECT_FATAL_FAILURE([&] { sut1.emplace_back(cnt); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } ++cnt; } @@ -763,9 +759,8 @@ TEST_F(list_test, EmplaceWithWrongListIterator) ++cnt; } - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(sut11.emplace(iterOfSut2, cnt), ""); + IOX_EXPECT_FATAL_FAILURE([&] { sut11.emplace(iterOfSut2, cnt); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(list_test, PushFrontConstCustomSuccessfullWhenSpaceAvailableLValue) @@ -1499,39 +1494,39 @@ TEST_F(list_test, IteratorComparisonOfDifferentLists) auto iterSut1 = sut11.begin(); auto iterSut2 = sut12.begin(); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 == iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 == iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.begin(); iterSut2 = sut12.begin(); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 == iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 == iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.end(); iterSut2 = sut12.end(); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 == iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 == iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.begin(); iterSut2 = sut12.begin(); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 != iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 != iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.begin(); iterSut2 = sut12.begin(); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 != iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 != iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); iterSut1 = sut11.end(); iterSut2 = sut12.end(); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iterSut1 != iterSut2), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iterSut1 != iterSut2); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } @@ -2313,9 +2308,8 @@ TEST_F(list_test, invalidIteratorErase) ++iter; sut.erase(iter); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(sut.erase(iter), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { sut.erase(iter); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(list_test, invalidIteratorIncrement) @@ -2331,9 +2325,7 @@ TEST_F(list_test, invalidIteratorIncrement) ++iter; sut.erase(iter); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(++iter, ""); + IOX_EXPECT_FATAL_FAILURE([&] { ++iter; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(list_test, invalidIteratorDecrement) @@ -2349,9 +2341,7 @@ TEST_F(list_test, invalidIteratorDecrement) ++iter; sut.erase(iter); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(--iter, ""); + IOX_EXPECT_FATAL_FAILURE([&] { --iter; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(list_test, invalidIteratorComparison) @@ -2367,9 +2357,9 @@ TEST_F(list_test, invalidIteratorComparison) ++iter; auto iter2 IOX_MAYBE_UNUSED = sut.erase(iter); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(sut.cbegin() == iter), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(sut.cbegin() == iter); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(list_test, invalidIteratorComparisonUnequal) @@ -2385,9 +2375,9 @@ TEST_F(list_test, invalidIteratorComparisonUnequal) ++iter; auto iter2 = sut.erase(iter); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iter2 != iter), ""); + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iter2 != iter); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(list_test, invalidIteratorDereferencing) @@ -2403,9 +2393,8 @@ TEST_F(list_test, invalidIteratorDereferencing) ++iter; auto iter2 IOX_MAYBE_UNUSED = sut.erase(iter); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc((*iter).m_value), ""); + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT((*iter).m_value); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(list_test, invalidIteratorAddressOfOperator) @@ -2421,9 +2410,8 @@ TEST_F(list_test, invalidIteratorAddressOfOperator) ++iter; auto iter2 IOX_MAYBE_UNUSED = sut.erase(iter); - /// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH - /// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(dummyFunc(iter->m_value == 12U), ""); + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(iter->m_value == 12U); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(list_test, ListIsCopyableViaMemcpy) diff --git a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_and_then.cpp b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_and_then.cpp index 4040c446716..a955fb7f5db 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_and_then.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_and_then.cpp @@ -13,7 +13,7 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/testing/expect_no_death.hpp" + #include "test_design_functional_interface_types.hpp" namespace 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 ae5403acc13..4a36c01752a 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp @@ -13,15 +13,16 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -// + #include "iceoryx_hoofs/error_handling/error_handling.hpp" -#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test_design_functional_interface_types.hpp" namespace { using namespace test_design_functional_interface; using namespace ::testing; +using namespace iox::testing; // the macro is used as code generator to make the tests more readable. because of the // template nature of those tests this cannot be implemented in the same readable fashion @@ -38,15 +39,9 @@ using namespace ::testing; template void ExpectDoesNotCallTerminateWhenObjectIsValid(const ExpectCall& callExpect) { - bool wasErrorHandlerCalled = false; SutType sut = FactoryType::createValidObject(); - { - auto handle = iox::ErrorHandlerMock::setTemporaryErrorHandler( - [&](auto, auto) { wasErrorHandlerCalled = true; }); - callExpect(sut); - } - EXPECT_FALSE(wasErrorHandlerCalled); + IOX_EXPECT_NO_FATAL_FAILURE([&] { callExpect(sut); }); } TYPED_TEST(FunctionalInterface_test, ExpectDoesNotCallTerminateWhenObjectIsValid_LValueCase) @@ -82,13 +77,8 @@ template void ExpectDoesCallTerminateWhenObjectIsInvalid(const ExpectCall& callExpect) { SutType sut = FactoryType::createInvalidObject(); - { - auto handle = - iox::ErrorHandlerMock::setTemporaryErrorHandler([&](auto, auto) { std::terminate(); }); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH(callExpect(sut), ".*"); - } + + IOX_EXPECT_FATAL_FAILURE([&] { callExpect(sut); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(FunctionalInterface_test, ExpectDoesCallTerminateWhenObjectIsInvalid_LValueCase) diff --git a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_or_else.cpp b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_or_else.cpp index 9cc9e82c311..2ac934b394b 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_functional_interface_or_else.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_functional_interface_or_else.cpp @@ -13,7 +13,7 @@ // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/testing/expect_no_death.hpp" + #include "test_design_functional_interface_types.hpp" namespace diff --git a/iceoryx_hoofs/test/moduletests/test_cxx_filesystem.cpp b/iceoryx_hoofs/test/moduletests/test_filesystem_filesystem.cpp similarity index 90% rename from iceoryx_hoofs/test/moduletests/test_cxx_filesystem.cpp rename to iceoryx_hoofs/test/moduletests/test_filesystem_filesystem.cpp index 551fe75461a..20e9daa5f45 100644 --- a/iceoryx_hoofs/test/moduletests/test_cxx_filesystem.cpp +++ b/iceoryx_hoofs/test/moduletests/test_filesystem_filesystem.cpp @@ -15,8 +15,8 @@ // // SPDX-License-Identifier: Apache-2.0 -#include "iceoryx_hoofs/cxx/filesystem.hpp" #include "iceoryx_hoofs/testing/mocks/logger_mock.hpp" +#include "iox/filesystem.hpp" #include "test.hpp" #include @@ -24,8 +24,8 @@ namespace { using namespace ::testing; -using namespace iox::cxx; -using namespace iox::cxx::internal; +using namespace iox; +using namespace iox::internal; using iox::testing::Logger_Mock; @@ -318,13 +318,13 @@ TEST(filesystem_test_isValidPathToFile_isValidPathToDirectory_isValidPathEntry, EXPECT_FALSE(isValidPathToDirectory(invalidCharacterMiddleTest)); EXPECT_FALSE(isValidPathToDirectory(invalidCharacterEndTest)); - EXPECT_FALSE(isValidPathEntry(invalidCharacterFrontTest, iox::cxx::RelativePathComponents::ACCEPT)); - EXPECT_FALSE(isValidPathEntry(invalidCharacterMiddleTest, iox::cxx::RelativePathComponents::ACCEPT)); - EXPECT_FALSE(isValidPathEntry(invalidCharacterEndTest, iox::cxx::RelativePathComponents::ACCEPT)); + EXPECT_FALSE(isValidPathEntry(invalidCharacterFrontTest, iox::RelativePathComponents::ACCEPT)); + EXPECT_FALSE(isValidPathEntry(invalidCharacterMiddleTest, iox::RelativePathComponents::ACCEPT)); + EXPECT_FALSE(isValidPathEntry(invalidCharacterEndTest, iox::RelativePathComponents::ACCEPT)); - EXPECT_FALSE(isValidPathEntry(invalidCharacterFrontTest, iox::cxx::RelativePathComponents::REJECT)); - EXPECT_FALSE(isValidPathEntry(invalidCharacterMiddleTest, iox::cxx::RelativePathComponents::REJECT)); - EXPECT_FALSE(isValidPathEntry(invalidCharacterEndTest, iox::cxx::RelativePathComponents::REJECT)); + EXPECT_FALSE(isValidPathEntry(invalidCharacterFrontTest, iox::RelativePathComponents::REJECT)); + EXPECT_FALSE(isValidPathEntry(invalidCharacterMiddleTest, iox::RelativePathComponents::REJECT)); + EXPECT_FALSE(isValidPathEntry(invalidCharacterEndTest, iox::RelativePathComponents::REJECT)); } } @@ -490,53 +490,53 @@ TEST(filesystem_test_isValidPathEntry, EmptyPathEntryIsValid) { ::testing::Test::RecordProperty("TEST_ID", "1280b360-f26c-4ddf-8305-e01a99d58178"); EXPECT_TRUE( - isValidPathEntry(string(""), iox::cxx::RelativePathComponents::ACCEPT)); + isValidPathEntry(string(""), iox::RelativePathComponents::ACCEPT)); } TEST(filesystem_test_isValidPathEntry, PathEntryWithOnlyValidCharactersIsValid) { ::testing::Test::RecordProperty("TEST_ID", "166fb334-05c6-4b8c-a117-223d6cadb29b"); - EXPECT_TRUE(isValidPathEntry(string("a"), - iox::cxx::RelativePathComponents::ACCEPT)); - EXPECT_TRUE(isValidPathEntry(string("agc"), - iox::cxx::RelativePathComponents::ACCEPT)); + EXPECT_TRUE( + isValidPathEntry(string("a"), iox::RelativePathComponents::ACCEPT)); + EXPECT_TRUE( + isValidPathEntry(string("agc"), iox::RelativePathComponents::ACCEPT)); EXPECT_TRUE(isValidPathEntry(string("a.213jkgc"), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); } TEST(filesystem_test_isValidPathEntry, RelativePathEntriesAreValid) { ::testing::Test::RecordProperty("TEST_ID", "d3432692-7cee-416a-a3f3-c246a02ad1a2"); - EXPECT_TRUE(isValidPathEntry(string("."), - iox::cxx::RelativePathComponents::ACCEPT)); - EXPECT_TRUE(isValidPathEntry(string(".."), - iox::cxx::RelativePathComponents::ACCEPT)); + EXPECT_TRUE( + isValidPathEntry(string("."), iox::RelativePathComponents::ACCEPT)); + EXPECT_TRUE( + isValidPathEntry(string(".."), iox::RelativePathComponents::ACCEPT)); } TEST(filesystem_test_isValidPathEntry, EntriesWithEndingDotAreInvalid) { ::testing::Test::RecordProperty("TEST_ID", "f937de46-19fc-48da-bce6-51292cd9d75e"); - EXPECT_FALSE(isValidPathEntry(string("abc."), - iox::cxx::RelativePathComponents::ACCEPT)); + EXPECT_FALSE( + isValidPathEntry(string("abc."), iox::RelativePathComponents::ACCEPT)); EXPECT_FALSE(isValidPathEntry(string("19283912asdb.."), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); EXPECT_FALSE(isValidPathEntry(string("..19283912asdb.."), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); EXPECT_FALSE(isValidPathEntry(string("..192839.12a.sdb.."), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); } TEST(filesystem_test_isValidPathEntry, EntriesWithDotsNotAtTheEndAreValid) { ::testing::Test::RecordProperty("TEST_ID", "569aa328-2c47-418d-96e2-ddf73925e52f"); - EXPECT_TRUE(isValidPathEntry(string(".abc"), - iox::cxx::RelativePathComponents::ACCEPT)); + EXPECT_TRUE( + isValidPathEntry(string(".abc"), iox::RelativePathComponents::ACCEPT)); EXPECT_TRUE(isValidPathEntry(string(".19283912asdb"), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); EXPECT_TRUE(isValidPathEntry(string("..19283912asdb"), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); EXPECT_TRUE(isValidPathEntry(string("..192839.12a.sdb"), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); } TEST(filesystem_test_isValidPathEntry, StringContainingAllValidCharactersIsValid) @@ -544,53 +544,53 @@ TEST(filesystem_test_isValidPathEntry, StringContainingAllValidCharactersIsValid ::testing::Test::RecordProperty("TEST_ID", "b2c19516-e8fb-4fb8-a366-2b7b5fd9a84b"); EXPECT_TRUE(isValidPathEntry(string( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.:_"), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); } TEST(filesystem_test_isValidPathEntry, StringWithSlashIsInvalid) { ::testing::Test::RecordProperty("TEST_ID", "b1119db1-f897-48a5-af92-9a92eb3f9832"); EXPECT_FALSE(isValidPathEntry(string("/fuuuu/"), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); EXPECT_FALSE(isValidPathEntry(string("fuu/uu"), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); EXPECT_FALSE(isValidPathEntry(string("/fuuuu"), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); EXPECT_FALSE(isValidPathEntry(string("uuuubbuu/"), - iox::cxx::RelativePathComponents::ACCEPT)); + iox::RelativePathComponents::ACCEPT)); } TEST(filesystem_test_isValidPathEntry, StringWithRelativeComponentsIsInvalidWhenItContainsRelativeComponents) { ::testing::Test::RecordProperty("TEST_ID", "6c73e08e-3b42-446e-b8d4-a4ed7685f28e"); EXPECT_FALSE(isValidPathEntry(string("../to/be"), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("../../or/not"), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("to/../be"), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("that/../../is/the/question"), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("whether/tis/nobler/.."), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("in/the/mind/to/suffer//../.."), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("../the/slings/and/arrows/../.."), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("../of/../outrageous/fortune/../.."), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("./or/to/take/../arms/../.."), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("./agains/a/see/./of/troubles/../.."), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("./and/by/../opposing/./."), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("./end/them"), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("to/./die"), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); EXPECT_FALSE(isValidPathEntry(string("to/./sleep/."), - iox::cxx::RelativePathComponents::REJECT)); + iox::RelativePathComponents::REJECT)); } constexpr base_t toBase(const perms permission) noexcept diff --git a/iceoryx_hoofs/test/moduletests/test_posix_file_lock.cpp b/iceoryx_hoofs/test/moduletests/test_posix_file_lock.cpp index 2cef25afebb..8ba8b968553 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_file_lock.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_file_lock.cpp @@ -43,8 +43,7 @@ class FileLock_test : public Test public: void SetUp() override { - auto maybeFileLock = - iox::posix::FileLockBuilder().name(TEST_NAME).permission(iox::cxx::perms::owner_all).create(); + auto maybeFileLock = iox::posix::FileLockBuilder().name(TEST_NAME).permission(iox::perms::owner_all).create(); ASSERT_FALSE(maybeFileLock.has_error()); m_sut.emplace(std::move(maybeFileLock.value())); ASSERT_TRUE(m_sut.has_value()); @@ -134,7 +133,7 @@ TEST_F(FileLock_test, MoveAssignTransfersLock) { ::testing::Test::RecordProperty("TEST_ID", "cd9ee3d0-4f57-44e1-b01c-f892610e805a"); auto movedSut = std::move(m_sut.value()); - auto anotherLock = iox::posix::FileLockBuilder().name(TEST_NAME).permission(iox::cxx::perms::owner_all).create(); + auto anotherLock = iox::posix::FileLockBuilder().name(TEST_NAME).permission(iox::perms::owner_all).create(); ASSERT_TRUE(anotherLock.has_error()); EXPECT_THAT(anotherLock.get_error(), Eq(FileLockError::LOCKED_BY_OTHER_PROCESS)); } diff --git a/iceoryx_hoofs/test/moduletests/test_posix_named_semaphore.cpp b/iceoryx_hoofs/test/moduletests/test_posix_named_semaphore.cpp index 91200ec2fa9..d092b825797 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_named_semaphore.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_named_semaphore.cpp @@ -38,7 +38,7 @@ class NamedSemaphoreTest : public Test optional sut; NamedSemaphore::Name_t sutName{TruncateToCapacity, "dr.peacock_rocks"}; - const iox::cxx::perms sutPermission = iox::cxx::perms::owner_all; + const iox::perms sutPermission = iox::perms::owner_all; }; TEST_F(NamedSemaphoreTest, DefaultInitialValueIsZero) diff --git a/iceoryx_hoofs/test/moduletests/test_posix_semaphore_interface.cpp b/iceoryx_hoofs/test/moduletests/test_posix_semaphore_interface.cpp index 2488daecbee..1b4959c214a 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_semaphore_interface.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_semaphore_interface.cpp @@ -94,7 +94,7 @@ struct NamedSemaphoreTest .initialValue(initialValue) .name("TestSemaphore") .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(iox::cxx::perms::owner_all) + .permissions(iox::perms::owner_all) .create(sut); } }; diff --git a/iceoryx_hoofs/test/moduletests/test_posix_shared_memory.cpp b/iceoryx_hoofs/test/moduletests/test_posix_shared_memory.cpp index 8ee085558f4..39837466119 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_shared_memory.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_shared_memory.cpp @@ -54,7 +54,7 @@ class SharedMemory_Test : public Test .name(name) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(openMode) - .filePermissions(cxx::perms::owner_all) + .filePermissions(perms::owner_all) .size(128) .create(); } diff --git a/iceoryx_hoofs/test/moduletests/test_posix_shared_memory_object.cpp b/iceoryx_hoofs/test/moduletests/test_posix_shared_memory_object.cpp index edaa31e2d41..1c9ef3788a7 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_shared_memory_object.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_shared_memory_object.cpp @@ -72,7 +72,7 @@ TEST_F(SharedMemoryObject_Test, AllocateMemoryInSharedMemoryAndReadIt) .memorySizeInBytes(16) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); ASSERT_THAT(sut.has_error(), Eq(false)); @@ -92,7 +92,7 @@ TEST_F(SharedMemoryObject_Test, AllocateWholeSharedMemoryWithOneChunk) .memorySizeInBytes(8) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); ASSERT_THAT(sut.has_error(), Eq(false)); @@ -109,7 +109,7 @@ TEST_F(SharedMemoryObject_Test, AllocateWholeSharedMemoryWithMultipleChunks) .memorySizeInBytes(8) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); ASSERT_THAT(sut.has_error(), Eq(false)); @@ -132,7 +132,7 @@ TEST_F(SharedMemoryObject_Test, AllocateTooMuchMemoryInSharedMemoryWithOneChunk) .memorySizeInBytes(memorySize) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); ASSERT_THAT(sut.has_error(), Eq(false)); @@ -151,7 +151,7 @@ TEST_F(SharedMemoryObject_Test, AllocateTooMuchSharedMemoryWithMultipleChunks) .memorySizeInBytes(memorySize) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); ASSERT_THAT(sut.has_error(), Eq(false)); @@ -176,7 +176,7 @@ TEST_F(SharedMemoryObject_Test, AllocateAfterFinalizeAllocation) .memorySizeInBytes(8) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); ASSERT_THAT(sut.has_error(), Eq(false)); @@ -196,7 +196,7 @@ TEST_F(SharedMemoryObject_Test, AllocateFailsWithZeroSize) .memorySizeInBytes(8) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); ASSERT_THAT(sut.has_error(), Eq(false)); @@ -216,7 +216,7 @@ TEST_F(SharedMemoryObject_Test, OpeningSharedMemoryAndReadMultipleContents) .memorySizeInBytes(memorySize) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); ASSERT_THAT(shmMemory.has_error(), Eq(false)); @@ -237,7 +237,7 @@ TEST_F(SharedMemoryObject_Test, OpeningSharedMemoryAndReadMultipleContents) .memorySizeInBytes(memorySize) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::OPEN_EXISTING) - .permissions(cxx::perms::owner_all) + .permissions(perms::owner_all) .create(); result = sut->allocate(sizeof(int), 1); diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp index 4e86f29551e..51e68d24c51 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_expected.cpp @@ -15,6 +15,8 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iox/expected.hpp" #include "iox/string.hpp" #include "test.hpp" @@ -22,6 +24,7 @@ using namespace ::testing; using namespace ::iox::cxx; using namespace ::iox; +using namespace ::iox::testing; namespace { @@ -583,121 +586,125 @@ TEST_F(expected_test, MoveAssignmentIsNotEnforcedInMoveConstructor) TEST_F(expected_test, AccessingErrorOfLValueErrorOnlyExpectedWhichContainsValueLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "da162edf-06b5-47d2-b35f-361d6004a6c4"); + auto sut = expected::create_value(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ sut.get_error(); }, ""); // ERROR: Trying to access an error but a value is stored + + IOX_EXPECT_FATAL_FAILURE([&] { sut.get_error(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingErrorOfConstLValueErrorOnlyExpectedWhichContainsValueLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "324cab7d-ba04-4ff0-870f-79af993c272f"); + const auto sut = expected::create_value(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ sut.get_error(); }, ""); // ERROR: Trying to access an error but a value is stored + + IOX_EXPECT_FATAL_FAILURE([&] { sut.get_error(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingErrorOfRValueErrorOnlyExpectedWhichContainsValueLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "0a4309e8-d9f3-41a9-9c4b-bdcfda917277"); + auto sut = expected::create_value(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ std::move(sut).get_error(); }, ""); // ERROR: Trying to access an error but a value is stored + + IOX_EXPECT_FATAL_FAILURE([&] { std::move(sut).get_error(); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingValueOfLValueExpectedWhichContainsErrorWithArrowOpLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "1a821c6f-83db-4fe1-8adf-873afa1251a1"); + auto sut = expected::create_error(TestError::ERROR1); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ IOX_DISCARD_RESULT(sut->m_a); }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(sut->m_a); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingValueOfConstLValueExpectedWhichContainsErrorWithArrowOpLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "c4f04d7c-9fa3-48f6-a6fd-b8e4e47b7632"); + const auto sut = expected::create_error(TestError::ERROR1); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ IOX_DISCARD_RESULT(sut->m_a); }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(sut->m_a); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingValueOfLValueExpectedWhichContainsErrorWithDerefOpLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "08ce6a3f-3813-46de-8e1e-3ffe8087521e"); + auto sut = expected::create_error(TestError::ERROR1); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ *sut; }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { *sut; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingValueOfConstLValueExpectedWhichContainsErrorWithDerefOpLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "838dd364-f91f-40a7-9720-2b662a045b1e"); + const auto sut = expected::create_error(TestError::ERROR1); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ *sut; }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { *sut; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingValueOfLValueExpectedWhichContainsErrorLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "92139583-b8d6-4d83-ae7e-f4109b98d214"); + auto sut = expected::create_error(TestError::ERROR1); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ sut.value(); }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { sut.value(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingValueOfConstLValueExpectedWhichContainsErrorLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "1bcbb835-8b4c-4430-a534-a26573c2380d"); + const auto sut = expected::create_error(TestError::ERROR1); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ sut.value(); }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { sut.value(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingValueOfRValueExpectedWhichContainsErrorLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "32d59b52-81f5-417a-8670-dfb2c54fedfb"); + auto sut = expected::create_error(TestError::ERROR1); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ std::move(sut).value(); }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { std::move(sut).value(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingErrorOfLValueExpectedWhichContainsValueLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "aee85ead-e066-49fd-99fe-6f1a6045756d"); + constexpr int VALID_VALUE{42}; auto sut = expected::create_value(VALID_VALUE, VALID_VALUE); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ sut.get_error(); }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { sut.get_error(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingErrorOfConstLValueExpectedWhichContainsValueLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "a49cf02e-b165-4fd6-9c24-65cedc6cddb9"); + constexpr int VALID_VALUE{42}; const auto sut = expected::create_value(VALID_VALUE, VALID_VALUE); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ sut.get_error(); }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { sut.get_error(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, AccessingErrorOfRValueExpectedWhichContainsValueLeadsToErrorHandlerCall) { ::testing::Test::RecordProperty("TEST_ID", "0ea90b5d-1af6-494a-b35c-da103bed2331"); + constexpr int VALID_VALUE{42}; auto sut = expected::create_value(VALID_VALUE, VALID_VALUE); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-goto, hicpp-avoid-goto, hicpp-vararg) - EXPECT_DEATH({ std::move(sut).get_error(); }, ""); // ERROR: Trying to access a value but an error is stored + + IOX_EXPECT_FATAL_FAILURE([&] { std::move(sut).get_error(); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TEST_F(expected_test, TwoErrorOnlyExpectedWithEqualErrorAreEqual) diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp index 59ab4502971..2f45c756c0b 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string.cpp @@ -15,6 +15,8 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_hoofs/error_handling/error_handling.hpp" +#include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iox/string.hpp" #include "test.hpp" @@ -22,6 +24,7 @@ namespace { using namespace ::testing; using namespace iox; +using namespace iox::testing; template class stringTyped_test : public Test @@ -3140,19 +3143,20 @@ TEST(String100, FindLastOfForNotIncludedSTDStringFails) TYPED_TEST(stringTyped_test, AccessPositionOfEmptyStringViaAtFails) { ::testing::Test::RecordProperty("TEST_ID", "89817818-f05a-4ceb-8663-9727d227048c"); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH({ this->testSubject.at(0U); }, ""); // ERROR: Out of bounds access ! + + IOX_EXPECT_FATAL_FAILURE([&] { this->testSubject.at(0U); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(stringTyped_test, AccessPositionOutOfBoundsViaAtFails) { ::testing::Test::RecordProperty("TEST_ID", "68035709-5f8d-4bcb-80ce-ad5619aba84a"); + using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString().capacity(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH({ this->testSubject.at(STRINGCAP); }, ""); // ERROR: Out of bounds access ! + + IOX_EXPECT_FATAL_FAILURE([&] { this->testSubject.at(STRINGCAP); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(stringTyped_test, AccessFirstPositionOfNonEmptyStringViaAtReturnsCorrectCharacter) @@ -3182,23 +3186,23 @@ TYPED_TEST(stringTyped_test, AccessAndAssignToMaxPositionOfNotEmptyStringViaAtSu TYPED_TEST(stringTyped_test, AccessPositionOfEmptyStringViaConstAtFails) { ::testing::Test::RecordProperty("TEST_ID", "5cf6d322-6ee9-41ce-bbf6-4e0d193fa938"); + using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString().capacity(); const string sut; - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH({ sut.at(0U); }, ""); // ERROR: Out of bounds access ! + + IOX_EXPECT_FATAL_FAILURE([&] { sut.at(0U); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(stringTyped_test, AccessPositionOutOfBoundsViaConstAtFails) { ::testing::Test::RecordProperty("TEST_ID", "90a986f4-b29b-4ce7-ad55-79cc4b7b2b29"); + using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString().capacity(); const string sut; - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH({ sut.at(STRINGCAP); }, ""); // ERROR: Out of bounds access ! + + IOX_EXPECT_FATAL_FAILURE([&] { sut.at(STRINGCAP); }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(stringTyped_test, AccessFirstPositionOfNotEmptyStringViaConstAtReturnsCorrectCharacter) @@ -3226,19 +3230,19 @@ TYPED_TEST(stringTyped_test, AccessMaxPositionOfNotEmptyStringViaConstAtSucceeds TYPED_TEST(stringTyped_test, AccessPositionOfEmptyStringViaSubscriptOperatorFails) { ::testing::Test::RecordProperty("TEST_ID", "95ced457-1aec-47e9-a496-0197ea3f4600"); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH({ this->testSubject[0U]; }, ""); // ERROR: Out of bounds access ! + + IOX_EXPECT_FATAL_FAILURE([&] { this->testSubject[0U]; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(stringTyped_test, AccessPositionOutOfBoundsViaSubscriptOperatorFails) { ::testing::Test::RecordProperty("TEST_ID", "ab52924e-1d6a-41e1-a8a9-8cfd9ab2120d"); + using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString().capacity(); - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH({ this->testSubject[STRINGCAP]; }, ""); // ERROR: Out of bounds access ! + + IOX_EXPECT_FATAL_FAILURE([&] { this->testSubject[STRINGCAP]; }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(stringTyped_test, AccessFirstPositionOfNotEmptyStringViaSubscriptOperatorReturnsCorrectCharacter) @@ -3268,23 +3272,23 @@ TYPED_TEST(stringTyped_test, AccessAndAssignToMaxPositionOfNotEmptyStringViaSubs TYPED_TEST(stringTyped_test, AccessPositionOfEmptyStringViaConstSubscriptOperatorFails) { ::testing::Test::RecordProperty("TEST_ID", "7ca75e53-8e26-4451-8712-a86bfe5bd32c"); + using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString().capacity(); const string sut; - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH({ sut[0U]; }, ""); // ERROR: Out of bounds access ! + + IOX_EXPECT_FATAL_FAILURE([&] { sut[0U]; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(stringTyped_test, AccessPositionOutOfBoundsViaConstSubscriptOperatorFails) { ::testing::Test::RecordProperty("TEST_ID", "5498e314-d321-464a-a667-400ee0c4d81f"); + using MyString = typename TestFixture::stringType; constexpr auto STRINGCAP = MyString().capacity(); const string sut; - // @todo iox-#1613 remove EXPECT_DEATH - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c) - EXPECT_DEATH({ sut[STRINGCAP]; }, ""); // ERROR: Out of bounds access ! + + IOX_EXPECT_FATAL_FAILURE([&] { sut[STRINGCAP]; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } TYPED_TEST(stringTyped_test, AccessFirstPositionOfNotEmptyStringViaConstSubscriptOperatorReturnsCorrectCharacter) diff --git a/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/README.md b/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/README.md index 924845c2419..6696bf8014c 100644 --- a/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/README.md +++ b/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/README.md @@ -2,16 +2,16 @@ ### Howto Perform a Benchmark In bash you could execute this one liner directly in the root directory of iceoryx. -```sh +```sh cd iceoryx -for i in $(seq 0 3); do +for i in $(seq 0 3); do echo Optimization level $i - g++ iceoryx_examples/benchmark_optional_and_expected/benchmark_optional_and_expected.cpp iceoryx_hoofs/source/units/duration.cpp -Iiceoryx_hoofs/include -Iiceoryx_platform/linux/include -pthread -O$i + g++ iceoryx_examples/benchmark_optional_and_expected/benchmark_optional_and_expected.cpp iceoryx_hoofs/time/source/duration.cpp -Iiceoryx_hoofs/include -Iiceoryx_platform/linux/include -pthread -O$i ./a.out done ``` -If you compile it with our default cmake settings you would only compile it in +If you compile it with our default cmake settings you would only compile it in release mode which is naturally faster than debug mode since it does not inject debug symbols and uses optimization level `-O2`. This shell command on the other hand does compile the benchmark for all 4 optimization diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/expect_no_death.hpp b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/expect_no_death.hpp deleted file mode 100644 index a4171be4f41..00000000000 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/expect_no_death.hpp +++ /dev/null @@ -1,52 +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_EXPECT_NO_DEATH_HPP -#define IOX_HOOFS_TESTUTILS_EXPECT_NO_DEATH_HPP - -/// @brief gtest offers EXPECT_DEATH as test but no alternative to test the opposite, that -/// the program does not terminate. -/// EXPECT_NO_DEATH offers to verify that something does not terminate. -/// @param[in] callable The callable which should not lead to termination -#define EXPECT_NO_DEATH(callable) \ - EXPECT_EXIT( \ - { \ - callable(); \ - /* Use fprintf here instead of std::cerr. cerr can be rerouted to another stream which can lead to failing \ - * tests in combination with internal::CaptureStderr() for instance. */ \ - fprintf(stderr, "callable did not terminate"); \ - exit(0); \ - }, \ - ::testing::ExitedWithCode(0), \ - "callable did not terminate"); - -/// @brief gtest offers ASSERT_DEATH as test but no alternative to test the opposite, that -/// the program does not terminate. -/// ASSERT_NO_DEATH offers to verify that something does not terminate. -/// @param[in] callable The callable which should not lead to termination -#define ASSERT_NO_DEATH(callable) \ - ASSERT_EXIT( \ - { \ - callable(); \ - /* Use fprintf here instead of std::cerr. cerr can be rerouted to another stream which can lead to failing \ - * tests in combination with internal::CaptureStderr() for instance. */ \ - fprintf(stderr, "callable did not terminate"); \ - exit(0); \ - }, \ - ::testing::ExitedWithCode(0), \ - "callable did not terminate"); - -#endif diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp new file mode 100644 index 00000000000..1fa423d0714 --- /dev/null +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp @@ -0,0 +1,86 @@ +// 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_TESTING_FATAL_FAILURE_HPP +#define IOX_HOOFS_TESTING_FATAL_FAILURE_HPP + +#include "iceoryx_hoofs/cxx/function_ref.hpp" +#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp" +#include "iox/optional.hpp" +#include "test.hpp" + +#include +#include + +// NOLINTNEXTLINE(hicpp-deprecated-headers) required to work on some platforms +#include + +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 cxx::function_ref testFunction, + const cxx::function_ref onFatalFailurePath, + const cxx::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)); +/// } +/// @endcode +/// @tparam[in] ErrorType The error type which is expected, e.g. 'iox::HoofsError' +/// @param[in] testFunction This function will be executed as SUT and is expected to call the error handler +/// @param[in] expectedError The error value which triggered the fatal failure +/// @return true if a fatal failure occurs, false otherwise +template +bool IOX_EXPECT_FATAL_FAILURE(const cxx::function_ref testFunction, const ErrorType expectedError); + +/// @brief This function is used in cases no fatal failure is expected but could potentially occur. The function only +/// works in combination with the iceoryx error handler. +/// @code +/// TEST(MyTest, valueIsNotFatal) { +/// iox::optional sut{false}; +/// 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 cxx::function_ref testFunction); + +} // namespace testing +} // namespace iox + + +#include "iceoryx_hoofs/testing/fatal_failure.inl" + +#endif // IOX_HOOFS_TESTING_FATAL_FAILURE_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 new file mode 100644 index 00000000000..120ef461eb9 --- /dev/null +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.inl @@ -0,0 +1,100 @@ +// 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_TESTING_FATAL_FAILURE_INL +#define IOX_HOOFS_TESTING_FATAL_FAILURE_INL + +#include "iceoryx_hoofs/testing/fatal_failure.hpp" + +namespace iox +{ +namespace testing +{ +namespace detail +{ +template +inline bool +IOX_FATAL_FAILURE_TEST(const cxx::function_ref testFunction, + const cxx::function_ref onFatalFailurePath, + const cxx::function_ref onNonFatalFailurePath) +{ + 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(); + }); + + th.join(); + + return hasFatalFailure.load(std::memory_order_relaxed); +} +} // namespace detail + +template +inline bool IOX_EXPECT_FATAL_FAILURE(const cxx::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!"; }); +} + +template +inline bool IOX_EXPECT_NO_FATAL_FAILURE(const cxx::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; +} + +} // namespace testing +} // namespace iox + +#endif // IOX_HOOFS_TESTING_FATAL_FAILURE_INL 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 index 39fa207c9b3..bc1890a274c 100644 --- 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 @@ -16,6 +16,7 @@ #ifndef IOX_HOOFS_TESTUTILS_ERROR_HANDLER_MOCK_HPP #define IOX_HOOFS_TESTUTILS_ERROR_HANDLER_MOCK_HPP +#include "iceoryx_hoofs/cxx/function.hpp" #include "iceoryx_hoofs/error_handling/error_handler.hpp" #include @@ -24,7 +25,7 @@ namespace iox { template -using TypedHandlerFunction = std::function; +using TypedHandlerFunction = cxx::function; /// @brief This mock is needed for unit testing, special debugging cases and /// other corner cases where we'd like to explicitly suppress the diff --git a/iceoryx_hoofs/source/units/duration.cpp b/iceoryx_hoofs/time/source/duration.cpp similarity index 100% rename from iceoryx_hoofs/source/units/duration.cpp rename to iceoryx_hoofs/time/source/duration.cpp diff --git a/iceoryx_hoofs/utility/include/iox/detail/into.inl b/iceoryx_hoofs/utility/include/iox/detail/into.inl index f507ed8faaa..7387abf10b2 100644 --- a/iceoryx_hoofs/utility/include/iox/detail/into.inl +++ b/iceoryx_hoofs/utility/include/iox/detail/into.inl @@ -1,4 +1,4 @@ -// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2021 - 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. @@ -23,22 +23,25 @@ namespace iox { template -inline constexpr DestinationType from(const SourceType value) +inline constexpr typename detail::extract_into_type::type_t from(const SourceType value) { return FromImpl::fromImpl(value); } - template -inline DestinationType FromImpl::fromImpl(const SourceType&) +inline auto FromImpl::fromImpl(const SourceType&) { - static_assert(cxx::always_false_v && cxx::always_false_v, - "Conversion for the specified types is not implemented!\ - Please specialize 'template constexpr DestinationType FromImpl::fromImpl(const SourceType&) noexcept'!"); + static_assert(cxx::always_false_v && cxx::always_false_v, "\n \ + Conversion for the specified types is not implemented!\n \ + Please specialize 'FromImpl::fromImpl'!\n \ + -------------------------------------------------------------------------\n \ + template \n \ + constexpr DestinationType FromImpl::fromImpl(const SourceType&) noexcept;\n \ + -------------------------------------------------------------------------"); } template -inline constexpr DestinationType into(const SourceType value) +inline constexpr typename detail::extract_into_type::type_t into(const SourceType value) { return from(value); } diff --git a/iceoryx_hoofs/utility/include/iox/into.hpp b/iceoryx_hoofs/utility/include/iox/into.hpp index a582393a5d0..9b12970aaee 100644 --- a/iceoryx_hoofs/utility/include/iox/into.hpp +++ b/iceoryx_hoofs/utility/include/iox/into.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. -// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2021 - 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. @@ -19,8 +19,42 @@ namespace iox { + +/// @brief Helper struct to indicate a lossy conversion, e.g. from an unbounded type into a bounded type +template +struct lossy +{ +}; + +namespace detail +{ +/// @brief Helper struct to get the actual destination type 'T' for 'into' with an additional indirection like +/// 'into>' +template +struct extract_into_type +{ + using type_t = T; +}; + +/// @brief Helper struct to get the actual destination type 'T' for 'into>' +template +struct extract_into_type> +{ + using type_t = T; +}; +} // namespace detail + /// @brief Converts a value of type SourceType to a corresponding value of type DestinationType. This function needs to -/// be specialized by the user for the types to be converted. +/// be specialized by the user for the types to be converted. If a partial specialization is needed, please have a look +/// at 'FromImpl'. +/// @note If the conversion is potentially lossy 'Destination from(...)' should not be used but +/// instead either one or both of: +/// - 'Destination from>(...)' +/// - 'optional from>(...)' +/// The 'Destination from(...)' implementation should have a 'static_assert' with a hint of the +/// reason, e.g. lossy conversion and a hint to use 'Destination into>(...)' or +/// 'optional into>(...)'. The 'std_string_support.hpp' can be used as a source of +/// inspiration for an implementation and error message. /// @code /// enum class LowLevel /// { @@ -60,18 +94,19 @@ namespace iox /// @param[in] value of type SourceType to convert to DestinationType /// @return converted value of SourceType to corresponding value of DestinationType template -constexpr DestinationType from(const SourceType value); +constexpr typename detail::extract_into_type::type_t from(const SourceType value); + // Using a struct as impl, as free functions do not support partially specialized templates template struct FromImpl { - static DestinationType fromImpl(const SourceType& value); + static auto fromImpl(const SourceType& value); }; /// @brief Converts a value of type SourceType to a corresponding value of type DestinationType. This is a convenience -/// function which is automatically available when `from` is implemented. This function shall therefore not be -/// specialized but always the `from` function. +/// function which is automatically available when 'from' is implemented. This function shall therefore not be +/// specialized but always the 'from' function. /// @code /// Bar b = iox::into(Foo::ENUM_VALUE); /// @endcode @@ -80,7 +115,7 @@ struct FromImpl /// @param[in] value of type SourceType to convert to DestinationType /// @return converted value of SourceType to corresponding value of DestinationType template -constexpr DestinationType into(const SourceType value); +constexpr typename detail::extract_into_type::type_t into(const SourceType value); } // namespace iox diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.hpp index 3d40920de3e..ecc82858070 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.hpp @@ -24,6 +24,7 @@ #include "iceoryx_posh/mepoo/memory_info.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iox/bump_allocator.hpp" +#include "iox/filesystem.hpp" namespace iox { @@ -58,8 +59,8 @@ class MePooSegment uint64_t m_segmentId; iox::mepoo::MemoryInfo m_memoryInfo; - static constexpr cxx::perms SEGMENT_PERMISSIONS = - cxx::perms::owner_read | cxx::perms::owner_write | cxx::perms::group_read | cxx::perms::group_write; + static constexpr perms SEGMENT_PERMISSIONS = + perms::owner_read | perms::owner_write | perms::group_read | perms::group_write; private: void setSegmentId(const uint64_t segmentId) noexcept; 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 c90d23db05a..89c91d5f5f2 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl @@ -29,7 +29,7 @@ namespace iox namespace mepoo { template -constexpr cxx::perms MePooSegment::SEGMENT_PERMISSIONS; +constexpr perms MePooSegment::SEGMENT_PERMISSIONS; template inline MePooSegment::MePooSegment( diff --git a/iceoryx_posh/include/iceoryx_posh/internal/runtime/shared_memory_user.hpp b/iceoryx_posh/include/iceoryx_posh/internal/runtime/shared_memory_user.hpp index e37ff2db80d..5afbd00bf0a 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/runtime/shared_memory_user.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/runtime/shared_memory_user.hpp @@ -20,6 +20,7 @@ #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp" #include "iceoryx_hoofs/memory/relative_pointer.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iox/filesystem.hpp" #include "iox/optional.hpp" #include "iox/vector.hpp" @@ -48,8 +49,8 @@ class SharedMemoryUser private: optional m_shmObject; vector m_dataShmObjects; - static constexpr cxx::perms SHM_SEGMENT_PERMISSIONS = - cxx::perms::owner_read | cxx::perms::owner_write | cxx::perms::group_read | cxx::perms::group_write; + static constexpr perms SHM_SEGMENT_PERMISSIONS = + perms::owner_read | perms::owner_write | perms::group_read | perms::group_write; }; } // namespace runtime 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 18ad4494b18..f3c1d88f792 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 @@ -24,6 +24,7 @@ #include "iceoryx_posh/roudi/memory/default_roudi_memory.hpp" #include "iceoryx_posh/roudi/memory/roudi_memory_manager.hpp" #include "iceoryx_posh/roudi/port_pool.hpp" +#include "iox/filesystem.hpp" namespace iox { @@ -62,7 +63,7 @@ class IceOryxRouDiMemoryManager : public RouDiMemoryInterface posix::FileLock fileLock = std::move( posix::FileLockBuilder() .name(ROUDI_LOCK_NAME) - .permission(iox::cxx::perms::owner_read | iox::cxx::perms::owner_write) + .permission(iox::perms::owner_read | iox::perms::owner_write) .create() .or_else([](auto& error) { if (error == posix::FileLockError::LOCKED_BY_OTHER_PROCESS) diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/memory/posix_shm_memory_provider.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/memory/posix_shm_memory_provider.hpp index 1220cfc4208..43c7eab9591 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/memory/posix_shm_memory_provider.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/memory/posix_shm_memory_provider.hpp @@ -22,6 +22,7 @@ #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iox/expected.hpp" +#include "iox/filesystem.hpp" #include "iox/optional.hpp" #include "iox/string.hpp" @@ -65,8 +66,8 @@ class PosixShmMemoryProvider : public MemoryProvider posix::OpenMode m_openMode{posix::OpenMode::OPEN_EXISTING}; optional m_shmObject; - static constexpr cxx::perms SHM_MEMORY_PERMISSIONS = - cxx::perms::owner_read | cxx::perms::owner_write | cxx::perms::group_read | cxx::perms::group_write; + static constexpr perms SHM_MEMORY_PERMISSIONS = + perms::owner_read | perms::owner_write | perms::group_read | perms::group_write; }; } // namespace roudi diff --git a/iceoryx_posh/source/gateway/toml_gateway_config_parser.cpp b/iceoryx_posh/source/gateway/toml_gateway_config_parser.cpp index a2bd9acf86a..21ffefe5666 100644 --- a/iceoryx_posh/source/gateway/toml_gateway_config_parser.cpp +++ b/iceoryx_posh/source/gateway/toml_gateway_config_parser.cpp @@ -78,9 +78,9 @@ iox::config::TomlGatewayConfigParser::parse(const roudi::ConfigFilePathString_t& auto serviceName = service->get_as(GATEWAY_CONFIG_SERVICE_NAME); auto instance = service->get_as(GATEWAY_CONFIG_SERVICE_INSTANCE_NAME); auto event = service->get_as(GATEWAY_CONFIG_SERVICE_EVENT_NAME); - entry.m_serviceDescription = iox::capro::ServiceDescription(into(*serviceName), - into(*instance), - into(*event)); + entry.m_serviceDescription = iox::capro::ServiceDescription(into>(*serviceName), + into>(*instance), + into>(*event)); config.m_configuredServices.push_back(entry); } diff --git a/iceoryx_posh/source/roudi/memory/posix_shm_memory_provider.cpp b/iceoryx_posh/source/roudi/memory/posix_shm_memory_provider.cpp index e3208747ee2..e77398a6796 100644 --- a/iceoryx_posh/source/roudi/memory/posix_shm_memory_provider.cpp +++ b/iceoryx_posh/source/roudi/memory/posix_shm_memory_provider.cpp @@ -27,7 +27,7 @@ namespace iox { namespace roudi { -constexpr cxx::perms PosixShmMemoryProvider::SHM_MEMORY_PERMISSIONS; +constexpr perms PosixShmMemoryProvider::SHM_MEMORY_PERMISSIONS; PosixShmMemoryProvider::PosixShmMemoryProvider(const ShmName_t& shmName, const posix::AccessMode accessMode, diff --git a/iceoryx_posh/source/roudi/roudi.cpp b/iceoryx_posh/source/roudi/roudi.cpp index 488f76ad131..9e04c6869dd 100644 --- a/iceoryx_posh/source/roudi/roudi.cpp +++ b/iceoryx_posh/source/roudi/roudi.cpp @@ -173,7 +173,7 @@ void RouDi::processRuntimeMessages() noexcept if (roudiIpcInterface.timedReceive(m_runtimeMessagesThreadTimeout, message)) { auto cmd = runtime::stringToIpcMessageType(message.getElementAtIndex(0).c_str()); - RuntimeName_t runtimeName{into(message.getElementAtIndex(1))}; + RuntimeName_t runtimeName{into>(message.getElementAtIndex(1))}; processMessage(message, cmd, runtimeName); } @@ -388,9 +388,11 @@ void RouDi::processMessage(const runtime::IpcMessage& message, } else { - capro::Interfaces interface = StringToCaProInterface(into(message.getElementAtIndex(2))); + capro::Interfaces interface = + StringToCaProInterface(into>(message.getElementAtIndex(2))); - m_prcMgr->addInterfaceForProcess(runtimeName, interface, into(message.getElementAtIndex(3))); + m_prcMgr->addInterfaceForProcess( + runtimeName, interface, into>(message.getElementAtIndex(3))); } break; } diff --git a/iceoryx_posh/source/runtime/ipc_interface_creator.cpp b/iceoryx_posh/source/runtime/ipc_interface_creator.cpp index 6c5b139f49f..25d2235f03f 100644 --- a/iceoryx_posh/source/runtime/ipc_interface_creator.cpp +++ b/iceoryx_posh/source/runtime/ipc_interface_creator.cpp @@ -17,6 +17,7 @@ #include "iceoryx_posh/internal/runtime/ipc_interface_creator.hpp" #include "iceoryx_posh/error_handling/error_handling.hpp" +#include "iox/filesystem.hpp" namespace iox { @@ -29,7 +30,7 @@ IpcInterfaceCreator::IpcInterfaceCreator(const RuntimeName_t& runtimeName, , m_fileLock(std::move( posix::FileLockBuilder() .name(runtimeName) - .permission(iox::cxx::perms::owner_read | iox::cxx::perms::owner_write) + .permission(iox::perms::owner_read | iox::perms::owner_write) .create() .or_else([&runtimeName](auto& error) { if (error == posix::FileLockError::LOCKED_BY_OTHER_PROCESS) diff --git a/iceoryx_posh/source/runtime/posh_runtime.cpp b/iceoryx_posh/source/runtime/posh_runtime.cpp index 1013aeddcdd..7f8928ca53e 100644 --- a/iceoryx_posh/source/runtime/posh_runtime.cpp +++ b/iceoryx_posh/source/runtime/posh_runtime.cpp @@ -19,6 +19,7 @@ #include "iceoryx_hoofs/internal/posix_wrapper/system_configuration.hpp" #include "iceoryx_posh/internal/log/posh_logging.hpp" #include "iceoryx_posh/internal/runtime/posh_runtime_impl.hpp" +#include "iox/filesystem.hpp" #include #include @@ -132,7 +133,7 @@ const RuntimeName_t& PoshRuntime::verifyInstanceName(optional([&] { testHash[4] = 5U; }, iox::HoofsError::EXPECTS_ENSURES_FAILED); } /// END CLASSHASH TESTS diff --git a/iceoryx_posh/test/moduletests/test_gw_gateway_generic.cpp b/iceoryx_posh/test/moduletests/test_gw_gateway_generic.cpp index ed5db5bdad4..c732ec80fdd 100644 --- a/iceoryx_posh/test/moduletests/test_gw_gateway_generic.cpp +++ b/iceoryx_posh/test/moduletests/test_gw_gateway_generic.cpp @@ -34,6 +34,8 @@ using ::testing::_; // ======================================== Helpers ======================================== // +using iox::into; +using iox::lossy; using iox::capro::IdString_t; // We do not need real channel terminals to test the base class. @@ -148,9 +150,9 @@ TEST_F(GatewayGenericTest, HandlesMaxmimumChannelCapacity) for (auto i = 0U; i < iox::MAX_CHANNEL_NUMBER; i++) { auto result = sut->addChannel( - iox::capro::ServiceDescription(iox::into(iox::cxx::convert::toString(i)), - iox::into(iox::cxx::convert::toString(i)), - iox::into(iox::cxx::convert::toString(i))), + iox::capro::ServiceDescription(into>(iox::cxx::convert::toString(i)), + into>(iox::cxx::convert::toString(i)), + into>(iox::cxx::convert::toString(i))), StubbedIceoryxTerminal::Options()); EXPECT_EQ(false, result.has_error()); } @@ -168,9 +170,9 @@ TEST_F(GatewayGenericTest, ThrowsErrorWhenExceedingMaximumChannelCapaicity) for (auto i = 0U; i < iox::MAX_CHANNEL_NUMBER; i++) { auto result = sut->addChannel( - iox::capro::ServiceDescription(iox::into(iox::cxx::convert::toString(i)), - iox::into(iox::cxx::convert::toString(i)), - iox::into(iox::cxx::convert::toString(i))), + iox::capro::ServiceDescription(into>(iox::cxx::convert::toString(i)), + into>(iox::cxx::convert::toString(i)), + into>(iox::cxx::convert::toString(i))), StubbedIceoryxTerminal::Options()); EXPECT_EQ(false, result.has_error()); } diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 8d4eea040cd..171fc71098f 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -17,6 +17,8 @@ #include "iceoryx_dust/cxx/convert.hpp" #include "iceoryx_hoofs/cxx/type_traits.hpp" +#include "iceoryx_hoofs/error_handling/error_handling.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" @@ -30,6 +32,7 @@ namespace { using namespace ::testing; using namespace iox::mepoo; +using namespace iox::testing; using UserPayloadOffset_t = ChunkHeader::UserPayloadOffset_t; @@ -367,7 +370,12 @@ TEST(ChunkHeader_test, ConstructorTerminatesWhenUserPayloadSizeExceedsChunkSize) ASSERT_FALSE(chunkSettingsResult.has_error()); auto& chunkSettings = chunkSettingsResult.value(); - EXPECT_DEATH({ ChunkHeader sut(CHUNK_SIZE, chunkSettings); }, ".*"); + IOX_EXPECT_FATAL_FAILURE( + [&] { + ChunkHeader sut(CHUNK_SIZE, chunkSettings); + ; + }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } // BEGIN PARAMETERIZED TESTS FOR CHUNK HEADER diff --git a/iceoryx_posh/test/moduletests/test_mepoo_config.cpp b/iceoryx_posh/test/moduletests/test_mepoo_config.cpp index 1a0f9fbb1f5..f853a588d70 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_config.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_config.cpp @@ -14,11 +14,14 @@ // // 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/mepoo/mepoo_config.hpp" #include "test.hpp" using namespace ::testing; +using namespace iox::testing; using namespace iox::mepoo; @@ -58,7 +61,11 @@ TEST_F(MePooConfig_Test, AddingMempoolWhenTheMemPoolConfigContainerIsFullReturns { sut.addMemPool({SIZE, CHUNK_COUNT}); } - EXPECT_DEATH({ sut.addMemPool({SIZE, CHUNK_COUNT}); }, ".*"); + IOX_EXPECT_FATAL_FAILURE( + [&] { + sut.addMemPool({SIZE, CHUNK_COUNT}); + }, + iox::PoshError::MEPOO__MAXIMUM_NUMBER_OF_MEMPOOLS_REACHED); } TEST_F(MePooConfig_Test, SetDefaultMethodAddsTheDefaultMemPoolConfigurationToTheMemPoolConfigContainer) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp index f41271e4393..eee4f322f02 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp @@ -49,13 +49,13 @@ class MePooSegment_test : public Test const iox::posix::AccessMode, const iox::posix::OpenMode, const void*, - const iox::cxx::perms)>; + const iox::perms)>; SharedMemoryObject_MOCK(const SharedMemory::Name_t& name, const uint64_t memorySizeInBytes, const AccessMode accessMode, const OpenMode openMode, const void* baseAddressHint, - const iox::cxx::perms permissions) + const iox::perms permissions) : m_memorySizeInBytes(memorySizeInBytes) , m_baseAddressHint(const_cast(baseAddressHint)) { @@ -121,7 +121,7 @@ class MePooSegment_test : public Test IOX_BUILDER_PARAMETER(iox::optional, baseAddressHint, iox::nullopt) - IOX_BUILDER_PARAMETER(iox::cxx::perms, permissions, iox::cxx::perms::none) + IOX_BUILDER_PARAMETER(iox::perms, permissions, iox::perms::none) public: iox::expected create() noexcept @@ -174,7 +174,7 @@ TEST_F(MePooSegment_test, SharedMemoryCreationParameter) const iox::posix::AccessMode f_accessMode, const iox::posix::OpenMode openMode, const void*, - const iox::cxx::perms) { + const iox::perms) { EXPECT_THAT(f_name, Eq(SharedMemory::Name_t("iox_roudi_test2"))); EXPECT_THAT(f_accessMode, Eq(iox::posix::AccessMode::READ_WRITE)); EXPECT_THAT(openMode, Eq(iox::posix::OpenMode::PURGE_AND_CREATE)); @@ -195,7 +195,7 @@ TEST_F(MePooSegment_test, GetSharedMemoryObject) const iox::posix::AccessMode, const iox::posix::OpenMode, const void*, - const iox::cxx::perms) { + const iox::perms) { memorySizeInBytes = f_memorySizeInBytes; }; SUT sut{mepooConfig, m_managementAllocator, PosixGroup{"iox_roudi_test1"}, PosixGroup{"iox_roudi_test2"}}; diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index 8887434a576..f80166eada0 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -16,7 +16,9 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/cxx/variant_queue.hpp" +#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" @@ -33,6 +35,7 @@ namespace { using namespace ::testing; +using namespace iox::testing; using namespace iox::popo; using namespace iox::cxx; using namespace iox::mepoo; @@ -126,17 +129,15 @@ constexpr std::chrono::milliseconds ChunkDistributor_test::BLOCKING_ template constexpr iox::units::Duration ChunkDistributor_test::DEADLOCK_TIMEOUT; -/// @todo iox-#898: this is broken on macOS and triggers the watchdog, even with 5 seconds timeout -#if !defined(__APPLE__) TYPED_TEST(ChunkDistributor_test, AddingNullptrQueueDoesNotWork) { ::testing::Test::RecordProperty("TEST_ID", "aa7eaa9e-c337-45dc-945a-d097b8916eaa"); auto sutData = this->getChunkDistributorData(); typename TestFixture::ChunkDistributor_t sut(sutData.get()); - EXPECT_DEATH(IOX_DISCARD_RESULT(sut.tryAddQueue(nullptr)), ".*"); + IOX_EXPECT_FATAL_FAILURE([&] { IOX_DISCARD_RESULT(sut.tryAddQueue(nullptr)); }, + iox::HoofsError::EXPECTS_ENSURES_FAILED); } -#endif TYPED_TEST(ChunkDistributor_test, NewChunkDistributorHasNoQueues) { diff --git a/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp b/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp index 31a4d948c33..2b6a57e6589 100644 --- a/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp @@ -369,7 +369,7 @@ TEST_F(TomlGatewayConfigParserSuiteTest, ParseValidConfigFileWithMaximumAllowedN for (auto configuredService : config.m_configuredServices) { std::string stringentry = "validservice" + std::to_string(count); - auto convertedStringentry = iox::into(stringentry); + auto convertedStringentry = iox::into>(stringentry); EXPECT_EQ(configuredService.m_serviceDescription.getServiceIDString(), convertedStringentry); EXPECT_EQ(configuredService.m_serviceDescription.getInstanceIDString(), convertedStringentry); EXPECT_EQ(configuredService.m_serviceDescription.getEventIDString(), convertedStringentry); diff --git a/iceoryx_posh/test/moduletests/test_posh_runtime.cpp b/iceoryx_posh/test/moduletests/test_posh_runtime.cpp index 589b9508e6f..c1c83e34588 100644 --- a/iceoryx_posh/test/moduletests/test_posh_runtime.cpp +++ b/iceoryx_posh/test/moduletests/test_posh_runtime.cpp @@ -136,7 +136,7 @@ TEST_F(PoshRuntime_test, MaxAppNameLength) ::testing::Test::RecordProperty("TEST_ID", "dfdf3ce1-c7d4-4c57-94ea-6ed9479371e3"); std::string maxValidName(iox::MAX_RUNTIME_NAME_LENGTH, 's'); - auto& runtime = PoshRuntime::initRuntime(iox::into(maxValidName)); + auto& runtime = PoshRuntime::initRuntime(into>(maxValidName)); EXPECT_THAT(maxValidName, StrEq(runtime.getInstanceName().c_str())); } @@ -322,17 +322,17 @@ TEST_F(PoshRuntime_test, getMiddlewarePublisherPublisherlistOverflow) for (; i < (iox::MAX_PUBLISHERS - iox::NUMBER_OF_INTERNAL_PUBLISHERS); ++i) { auto publisherPort = m_runtime->getMiddlewarePublisher( - iox::capro::ServiceDescription(iox::into(convert::toString(i)), - iox::into(convert::toString(i + 1U)), - iox::into(convert::toString(i + 2U)))); + iox::capro::ServiceDescription(into>(convert::toString(i)), + into>(convert::toString(i + 1U)), + into>(convert::toString(i + 2U)))); ASSERT_NE(nullptr, publisherPort); } EXPECT_FALSE(publisherlistOverflowDetected); auto publisherPort = m_runtime->getMiddlewarePublisher( - iox::capro::ServiceDescription(iox::into(convert::toString(i)), - iox::into(convert::toString(i + 1U)), - iox::into(convert::toString(i + 2U)))); + iox::capro::ServiceDescription(into>(convert::toString(i)), + into>(convert::toString(i + 1U)), + into>(convert::toString(i + 2U)))); EXPECT_EQ(nullptr, publisherPort); EXPECT_TRUE(publisherlistOverflowDetected); } @@ -556,17 +556,17 @@ TEST_F(PoshRuntime_test, GetMiddlewareSubscriberSubscriberlistOverflow) for (; i < iox::MAX_SUBSCRIBERS; ++i) { auto subscriberPort = m_runtime->getMiddlewareSubscriber( - iox::capro::ServiceDescription(iox::into(convert::toString(i)), - iox::into(convert::toString(i + 1U)), - iox::into(convert::toString(i + 2U)))); + iox::capro::ServiceDescription(into>(convert::toString(i)), + into>(convert::toString(i + 1U)), + into>(convert::toString(i + 2U)))); ASSERT_NE(nullptr, subscriberPort); } EXPECT_FALSE(subscriberlistOverflowDetected); auto subscriberPort = m_runtime->getMiddlewareSubscriber( - iox::capro::ServiceDescription(iox::into(convert::toString(i)), - iox::into(convert::toString(i + 1U)), - iox::into(convert::toString(i + 2U)))); + iox::capro::ServiceDescription(into>(convert::toString(i)), + into>(convert::toString(i + 1U)), + into>(convert::toString(i + 2U)))); EXPECT_EQ(nullptr, subscriberPort); EXPECT_TRUE(subscriberlistOverflowDetected); @@ -719,17 +719,17 @@ TEST_F(PoshRuntime_test, GetMiddlewareClientWhenMaxClientsAreUsedResultsInClient for (; i < iox::MAX_CLIENTS; ++i) { auto clientPort = m_runtime->getMiddlewareClient( - iox::capro::ServiceDescription(iox::into(convert::toString(i)), - iox::into(convert::toString(i + 1U)), - iox::into(convert::toString(i + 2U)))); + iox::capro::ServiceDescription(into>(convert::toString(i)), + into>(convert::toString(i + 1U)), + into>(convert::toString(i + 2U)))); ASSERT_THAT(clientPort, Ne(nullptr)); } EXPECT_FALSE(clientOverflowDetected); auto clientPort = m_runtime->getMiddlewareClient( - iox::capro::ServiceDescription(iox::into(convert::toString(i)), - iox::into(convert::toString(i + 1U)), - iox::into(convert::toString(i + 2U)))); + 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); } @@ -830,17 +830,17 @@ TEST_F(PoshRuntime_test, GetMiddlewareServerWhenMaxServerAreUsedResultsInServerl for (; i < iox::MAX_SERVERS; ++i) { auto serverPort = m_runtime->getMiddlewareServer( - iox::capro::ServiceDescription(iox::into(convert::toString(i)), - iox::into(convert::toString(i + 1U)), - iox::into(convert::toString(i + 2U)))); + iox::capro::ServiceDescription(into>(convert::toString(i)), + into>(convert::toString(i + 1U)), + into>(convert::toString(i + 2U)))); ASSERT_THAT(serverPort, Ne(nullptr)); } EXPECT_FALSE(serverOverflowDetected); auto serverPort = m_runtime->getMiddlewareServer( - iox::capro::ServiceDescription(iox::into(convert::toString(i)), - iox::into(convert::toString(i + 1U)), - iox::into(convert::toString(i + 2U)))); + 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); } diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 8248fd8c480..de6496c7af0 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -21,6 +21,9 @@ namespace iox_test_roudi_portmanager { +using iox::into; +using iox::lossy; + PublisherOptions createTestPubOptions() { return PublisherOptions{0U, iox::NodeName_t("node"), true, iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA}; @@ -596,10 +599,10 @@ TEST_F(PortManager_test, DeleteInterfacePortfromMaximumNumberAndAddOneIsSuccessf unsigned int testi = 0; auto newProcessName = runtimeName + iox::cxx::convert::toString(testi); // this is done because there is no removeInterfaceData method in the PortManager class - m_portManager->deletePortsOfProcess(iox::into(newProcessName)); + m_portManager->deletePortsOfProcess(into>(newProcessName)); auto interfacePort = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, - iox::into(newProcessName)); + into>(newProcessName)); EXPECT_NE(interfacePort, nullptr); } } @@ -655,10 +658,10 @@ TEST_F(PortManager_test, DeleteConditionVariablePortfromMaximumNumberAndAddOneIs unsigned int testi = 0; auto newProcessName = runtimeName + iox::cxx::convert::toString(testi); // this is done because there is no removeConditionVariableData method in the PortManager class - m_portManager->deletePortsOfProcess(iox::into(newProcessName)); + m_portManager->deletePortsOfProcess(into>(newProcessName)); auto conditionVariableResult = - m_portManager->acquireConditionVariableData(iox::into(newProcessName)); + m_portManager->acquireConditionVariableData(into>(newProcessName)); EXPECT_FALSE(conditionVariableResult.has_error()); } } @@ -726,8 +729,8 @@ TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful) // delete one and add one NodeData should be possible now unsigned int i = 0U; - iox::RuntimeName_t newProcessName = iox::into(runtimeName + iox::cxx::convert::toString(i)); - iox::NodeName_t newNodeName = iox::into(nodeName + iox::cxx::convert::toString(i)); + iox::RuntimeName_t newProcessName = into>(runtimeName + iox::cxx::convert::toString(i)); + iox::NodeName_t newNodeName = into>(nodeName + iox::cxx::convert::toString(i)); // this is done because there is no removeNodeData method in the PortManager class m_portManager->deletePortsOfProcess(newProcessName); @@ -768,7 +771,7 @@ TEST_F(PortManager_test, UnblockRouDiShutdownMakesAllPublisherStopOffer) for (unsigned int i = 0; i < iox::MAX_PUBLISHERS; i++) { auto servideDescription = getUniqueSD(); - auto publisherRuntimeName = iox::into("pub_" + std::to_string(i)); + auto publisherRuntimeName = into>("pub_" + std::to_string(i)); auto publisherPortDataResult = m_portManager->acquirePublisherPortData(servideDescription, publisherOptions, publisherRuntimeName, diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager_fixture.hpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager_fixture.hpp index d26d0bc0f7e..c0317f12649 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager_fixture.hpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager_fixture.hpp @@ -133,9 +133,9 @@ class PortManager_test : public Test } } } - return {iox::into(convert::toString(m_sIdCounter)), - iox::into(convert::toString(m_eventIdCounter)), - iox::into(convert::toString(m_instIdCounter))}; + return {into>(convert::toString(m_sIdCounter)), + into>(convert::toString(m_eventIdCounter)), + into>(convert::toString(m_instIdCounter))}; } void acquireMaxNumberOfInterfaces( @@ -146,7 +146,7 @@ class PortManager_test : public Test { auto newProcessName = runtimeName + iox::cxx::convert::toString(i); auto interfacePort = m_portManager->acquireInterfacePortData(iox::capro::Interfaces::INTERNAL, - iox::into(newProcessName)); + into>(newProcessName)); ASSERT_NE(interfacePort, nullptr); if (f) { @@ -162,7 +162,7 @@ class PortManager_test : public Test for (unsigned int i = 0; i < iox::MAX_NUMBER_OF_CONDITION_VARIABLES; i++) { auto newProcessName = runtimeName + iox::cxx::convert::toString(i); - auto condVar = m_portManager->acquireConditionVariableData(iox::into(newProcessName)); + auto condVar = m_portManager->acquireConditionVariableData(into>(newProcessName)); ASSERT_FALSE(condVar.has_error()); if (f) { @@ -180,8 +180,8 @@ class PortManager_test : public Test { auto newProcessName = runtimeName + iox::cxx::convert::toString(i); auto newNodeName = nodeName + iox::cxx::convert::toString(i); - auto node = m_portManager->acquireNodeData(iox::into(newProcessName), - iox::into(newNodeName)); + auto node = m_portManager->acquireNodeData(into>(newProcessName), + into>(newNodeName)); ASSERT_FALSE(node.has_error()); if (f) { diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 1561c06bffa..79aa4ef0338 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -45,9 +45,9 @@ class PortPool_test : public Test for (uint32_t i = 0; i < numberOfClientPortsToAdd; ++i) { std::string service = "service" + cxx::convert::toString(i); - auto serviceId = iox::into(service); + auto serviceId = into>(service); ServiceDescription sd{serviceId, "instance", "event"}; - RuntimeName_t runtimeName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t runtimeName = into>("AppName" + cxx::convert::toString(i)); auto clientPortResult = sut.addClientPort(sd, &m_memoryManager, runtimeName, m_clientOptions, m_memoryInfo); if (clientPortResult.has_error()) @@ -68,9 +68,9 @@ class PortPool_test : public Test for (uint32_t i = 0; i < numberOfServerPortsToAdd; ++i) { std::string service = "service" + cxx::convert::toString(i); - auto serviceId = iox::into(service); + auto serviceId = into>(service); ServiceDescription sd{serviceId, "instance", "event"}; - RuntimeName_t runtimeName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t runtimeName = into>("AppName" + cxx::convert::toString(i)); auto serverPortResult = sut.addServerPort(sd, &m_memoryManager, runtimeName, m_serverOptions, m_memoryInfo); if (serverPortResult.has_error()) @@ -221,7 +221,7 @@ TEST_F(PortPool_test, AddPublisherPortWithMaxCapacityIsSuccessful) ::testing::Test::RecordProperty("TEST_ID", "3328692a-77a7-42d4-8ec2-154e1e89f8cd"); for (uint32_t i = 0U; i < MAX_PUBLISHERS; ++i) { - RuntimeName_t applicationName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t applicationName = into>("AppName" + cxx::convert::toString(i)); auto publisherPort = sut.addPublisherPort( m_serviceDescription, &m_memoryManager, applicationName, m_publisherOptions, m_memoryInfo); @@ -242,10 +242,10 @@ TEST_F(PortPool_test, AddPublisherPortWhenPublisherListOverflowsReturnsError) auto addPublisherPort = [&](const uint32_t i) -> bool { std::string service = "service" + cxx::convert::toString(i); std::string instance = "instance" + cxx::convert::toString(i); - RuntimeName_t applicationName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t applicationName = into>("AppName" + cxx::convert::toString(i)); return sut - .addPublisherPort({iox::into(service), iox::into(instance), "foo"}, + .addPublisherPort({into>(service), into>(instance), "foo"}, &m_memoryManager, applicationName, m_publisherOptions) @@ -300,9 +300,9 @@ TEST_F(PortPool_test, GetPublisherPortDataListCompletelyFilledSuccessfully) { std::string service = "service" + cxx::convert::toString(i); std::string instance = "instance" + cxx::convert::toString(i); - RuntimeName_t applicationName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t applicationName = into>("AppName" + cxx::convert::toString(i)); - ASSERT_FALSE(sut.addPublisherPort({iox::into(service), iox::into(instance), "foo"}, + ASSERT_FALSE(sut.addPublisherPort({into>(service), into>(instance), "foo"}, &m_memoryManager, applicationName, m_publisherOptions) @@ -352,7 +352,7 @@ TEST_F(PortPool_test, AddSubscriberPortToMaxCapacityIsSuccessful) { std::string service = "service" + cxx::convert::toString(i); std::string instance = "instance" + cxx::convert::toString(i); - RuntimeName_t applicationName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t applicationName = into>("AppName" + cxx::convert::toString(i)); auto subscriberPort = @@ -374,11 +374,11 @@ TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReturnsError) auto addSubscriberPort = [&](const uint32_t i) -> bool { std::string service = "service" + cxx::convert::toString(i); std::string instance = "instance" + cxx::convert::toString(i); - RuntimeName_t applicationName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t applicationName = into>("AppName" + cxx::convert::toString(i)); auto publisherPort = - sut.addSubscriberPort({iox::into(service), iox::into(instance), "foo"}, + sut.addSubscriberPort({into>(service), into>(instance), "foo"}, applicationName, m_subscriberOptions); return publisherPort.has_error(); @@ -427,10 +427,10 @@ TEST_F(PortPool_test, GetSubscriberPortDataListCompletelyFilledIsSuccessful) { std::string service = "service" + cxx::convert::toString(i); std::string instance = "instance" + cxx::convert::toString(i); - RuntimeName_t applicationName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t applicationName = into>("AppName" + cxx::convert::toString(i)); auto publisherPort = - sut.addSubscriberPort({iox::into(service), iox::into(instance), "foo"}, + sut.addSubscriberPort({into>(service), into>(instance), "foo"}, applicationName, m_subscriberOptions); EXPECT_FALSE(publisherPort.has_error()); @@ -737,7 +737,7 @@ TEST_F(PortPool_test, GetInterfacePortDataListCompletelyFilledIsSuccessful) ::testing::Test::RecordProperty("TEST_ID", "460703f9-72d8-4b72-9c3a-761be22e6c9a"); for (uint32_t i = 0U; i < MAX_INTERFACE_NUMBER; ++i) { - RuntimeName_t applicationName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t applicationName = into>("AppName" + cxx::convert::toString(i)); ASSERT_FALSE(sut.addInterfacePort(applicationName, Interfaces::INTERNAL).has_error()); } auto interfacePortDataList = sut.getInterfacePortDataList(); @@ -824,7 +824,7 @@ TEST_F(PortPool_test, GetConditionVariableDataListCompletelyFilledIsSuccessful) ::testing::Test::RecordProperty("TEST_ID", "42c58990-4dbe-485f-bbf6-7430cc878118"); for (uint32_t i = 0U; i < MAX_NUMBER_OF_CONDITION_VARIABLES; ++i) { - RuntimeName_t applicationName = iox::into("AppName" + cxx::convert::toString(i)); + RuntimeName_t applicationName = into>("AppName" + cxx::convert::toString(i)); ASSERT_FALSE(sut.addConditionVariableData(applicationName).has_error()); } auto condtionalVariableData = sut.getConditionVariableDataList(); diff --git a/iceoryx_posh/test/moduletests/test_roudi_posix_shm_memory_provider.cpp b/iceoryx_posh/test/moduletests/test_roudi_posix_shm_memory_provider.cpp index 469c2e36625..33a9d524a9a 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_posix_shm_memory_provider.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_posix_shm_memory_provider.cpp @@ -52,7 +52,7 @@ class PosixShmMemoryProvider_Test : public Test .memorySizeInBytes(8) .accessMode(iox::posix::AccessMode::READ_ONLY) .openMode(iox::posix::OpenMode::OPEN_EXISTING) - .permissions(iox::cxx::perms::owner_all) + .permissions(iox::perms::owner_all) .create() .has_error(); } diff --git a/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp b/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp index f18615b4e7d..84a766de955 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp @@ -184,7 +184,7 @@ TYPED_TEST(ServiceRegistry_test, AddMaximumNumberOfServiceDescriptionsWorks) for (uint64_t i = 0U; i < CAPACITY; i++) { services.push_back(iox::capro::ServiceDescription( - "Foo", "Bar", iox::into(iox::cxx::convert::toString(i)))); + "Foo", "Bar", iox::into>(iox::cxx::convert::toString(i)))); } for (auto& service : services) @@ -202,7 +202,7 @@ TYPED_TEST(ServiceRegistry_test, AddMoreThanMaximumNumberOfServiceDescriptionsFa for (uint64_t i = 0U; i < CAPACITY; i++) { services.push_back(iox::capro::ServiceDescription( - "Foo", "Bar", iox::into(iox::cxx::convert::toString(i)))); + "Foo", "Bar", iox::into>(iox::cxx::convert::toString(i)))); } for (auto& service : services) @@ -598,7 +598,7 @@ TYPED_TEST(ServiceRegistry_test, SearchInFullRegistryWorks) constexpr auto CAP = string_t::capacity(); - string_t fixedId = iox::into(std::string(CAP, '0')); + string_t fixedId = iox::into>(std::string(CAP, '0')); ServiceDescription lastAdded; do diff --git a/tools/git-hooks/pre-commit b/tools/git-hooks/pre-commit index f5ffde34a98..bd808738b60 100755 --- a/tools/git-hooks/pre-commit +++ b/tools/git-hooks/pre-commit @@ -24,7 +24,7 @@ repo_root_dir=$(git rev-parse --show-toplevel) cd "${repo_root_dir}" || exit -if ! tools/scripts/clang_tidy_check.sh hook; then +if ! tools/scripts/clang_tidy_check.sh hook "$repo_root_dir/.clang-tidy-diff-scans.txt"; then echo "Error while executing clang-tidy" exit 1 fi diff --git a/tools/scripts/check_test_ids.sh b/tools/scripts/check_test_ids.sh index 991c6c5cc92..ec2a20348c2 100755 --- a/tools/scripts/check_test_ids.sh +++ b/tools/scripts/check_test_ids.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +# 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. @@ -24,26 +24,56 @@ set -e ICEORYX_PATH=$(git rev-parse --show-toplevel) cd $ICEORYX_PATH +function numberOfTestCases() { + grep -rn --include="*.cpp" -e "^\(TEST\|TYPED_TEST\|TIMING_TEST\)" $1 | wc -l +} +function numberOfFalsePositives() { + grep -rn --include="*.cpp" TYPED_TEST_SUITE $1 | wc -l +} +function numberOfTestIDs() { + grep -rn --include="*.cpp" "::testing::Test::RecordProperty" $1 | wc -l +} + ## sanity check for number of tests and test IDs -for file in $(find . -iname "*.cpp") -do - echo "Check file: $file" - numberOfTestCases=$(grep -rn --include="*.cpp" -e "^\(TEST\|TYPED_TEST\|TIMING_TEST\)" $file | wc -l) - numberOfFalsePositives=$(grep -rn --include="*.cpp" TYPED_TEST_SUITE $file | wc -l) - set +e - numberOfTestCasesWithoutFalsePositives=$(expr $numberOfTestCases - $numberOfFalsePositives) - set -e - numberOfTestIDs=$(grep -rn --include="*.cpp" "::testing::Test::RecordProperty" $file | wc -l) - if [[ "$numberOfTestCasesWithoutFalsePositives" -gt "$numberOfTestIDs" ]]; then - echo -e "\e[1;31mThe file \"$file\" is missing test IDs for some test cases!\e[m" - exit 1 +## at first a quick check and then a slower check for the respective files +NUMBER_OF_TEST_CASES_TOTAL=$(numberOfTestCases "iceoryx_*") +NUMBER_OF_FALSE_POSITIVES_TOTAL=$(numberOfFalsePositives "iceoryx_*") +NUMBER_OF_TEST_CASES_WITHOUT_FALSE_POSITIVES_TOTAL=$NUMBER_OF_TEST_CASES_TOTAL-$NUMBER_OF_FALSE_POSITIVES_TOTAL +NUMBER_OF_TEST_IDS_TOTAL=$(numberOfTestIDs "iceoryx_*") +if [[ "$NUMBER_OF_TEST_CASES_WITHOUT_FALSE_POSITIVES_TOTAL" -gt "$NUMBER_OF_TEST_IDS_TOTAL" ]]; then + echo -e "\e[1;31mThe number of test IDs do not match the number of test cases!\e[m" + echo "number of test cases: $NUMBER_OF_TEST_CASES_TOTAL" + echo "number of false positives: $NUMBER_OF_FALSE_POSITIVES_TOTAL" + echo "number of test IDs: $NUMBER_OF_TEST_IDS_TOTAL" + echo "" + echo "trying to find files with missing IDs ..." + + # find file with missing IDs + while IFS= read -r -d '' FILE + do + NUMBER_OF_TEST_CASES_IN_FILE=$(numberOfTestCases $FILE) + NUMBER_OF_FALSE_POSITIVES_IN_FILE=$(numberOfFalsePositives $FILE) + NUMBER_OF_TEST_CASES_WITHOUT_FALSE_POSITIVES_IN_FILE=$NUMBER_OF_TEST_CASES_IN_FILE-$NUMBER_OF_FALSE_POSITIVES_IN_FILE + NUMBER_OF_TEST_IDS_IN_FILE=$(numberOfTestIDs $FILE) + if [[ "$NUMBER_OF_TEST_CASES_WITHOUT_FALSE_POSITIVES_IN_FILE" -gt "$NUMBER_OF_TEST_IDS_IN_FILE" ]]; then + echo -e "\e[1;31mThe file \"$FILE\" is missing test IDs for some test cases!\e[m" + FOUND=1 + fi + done < <(find iceoryx_* -iname "*.cpp" -print0) + + if [[ $FOUND ]]; then + echo "... done" + else + echo "... not found" fi -done + exit 1 +fi + ## unique test IDs -notUniqueIds=$(grep -hr "::testing::Test::RecordProperty" | sort | uniq -d) -if [[ -n "$notUniqueIds" ]]; then +NOT_UNIQUE_TEST_IDS=$(grep -hr "::testing::Test::RecordProperty" | sort | uniq -d) +if [[ -n "$NOT_UNIQUE_TEST_IDS" ]]; then echo -e "\e[1;31mThe following test IDs are not unique!\e[m" - echo "$notUniqueIds" + echo "$NOT_UNIQUE_TEST_IDS" exit 1 fi diff --git a/tools/scripts/clang_tidy_check.sh b/tools/scripts/clang_tidy_check.sh index 574c88e6f6f..fe919397613 100755 --- a/tools/scripts/clang_tidy_check.sh +++ b/tools/scripts/clang_tidy_check.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +# 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. @@ -65,23 +65,86 @@ if [[ -n "$noSpaceInSuppressions" ]]; then exit 1 fi +function scanWithFileList() { + FILE_WITH_SCAN_LIST=$1 + FILE_TO_SCAN=$2 + + if ! test -f "$FILE_WITH_SCAN_LIST" + then + echo "Scan list file '${FILE_WITH_SCAN_LIST}' does not exist" + return 1 + fi + + while IFS= read -r LINE + do + # add files until the comment section starts + if [[ "$(echo $LINE | grep "#" | wc -l)" == "1" ]]; then + break + fi + FILE_LIST="${FILE_LIST} $LINE" + done < "$FILE_WITH_SCAN_LIST" + + if [[ -n $FILE_TO_SCAN ]] + then + if ! test -f "$FILE_TO_SCAN" + then + echo "The file which should be scanned '${FILE_TO_SCAN}' does not exist" + return 1 + fi + + if [[ $(find ${FILE_LIST} -type f | grep -E ${FILE_FILTER} | grep ${FILE_TO_SCAN} | wc -l) == "0" ]] + then + echo "Skipping file '${FILE_TO_SCAN}' since it is not part of '${FILE_WITH_SCAN_LIST}'" + return 0 + fi + + echo "Scanning file: ${FILE_TO_SCAN}" + $CLANG_TIDY_CMD --warnings-as-errors=* -p build $FILE_TO_SCAN + else + if [[ -z $FILE_LIST ]] + then + echo "'${FILE_WITH_SCAN_LIST}' is empty skipping folder scan." + return 0 + fi + echo "Performing full scan of all folders in '${FILE_WITH_SCAN_LIST}'" + $CLANG_TIDY_CMD --warnings-as-errors=* -p build "$(find "${FILE_LIST}" -type f | grep -E ${FILE_FILTER})" + fi +} + if [[ "$MODE" == "hook"* ]]; then + if [[ $2 ]]; then + FILE_WITH_SCAN_LIST=$2 + fi + FILES=$(git diff --cached --name-only --diff-filter=CMRT | grep -E "$FILE_FILTER" | cat) # List only added files ADDED_FILES=$(git diff --cached --name-only --diff-filter=A | grep -E "$FILE_FILTER" | cat) echo "Checking files with Clang-Tidy" - echo " " - if [ -z "$FILES" ]; then - echo "No modified files to check, skipping clang-tidy" + echo " Number of modified files: $(echo "${FILES}" | grep -v "^$" | wc -l)" + if [ -z "$FILES" ]; then + echo " -> nothing to do" + else + echo " processing ..." + if [[ $FILE_WITH_SCAN_LIST ]]; then + for FILE_TO_SCAN in $FILES; do + echo " ${FILE_TO_SCAN}" + scanWithFileList $FILE_WITH_SCAN_LIST $FILE_TO_SCAN + done else $CLANG_TIDY_CMD -p build $FILES fi + echo " ... done" + fi - if [ -z "$ADDED_FILES" ]; then - echo "No added files to check, skipping clang-tidy" - else - $CLANG_TIDY_CMD --warnings-as-errors=* -p build $ADDED_FILES - fi + echo " " + echo " Number of added files: $(echo "${ADDED_FILES}" | grep -v "^$" | wc -l)" + if [ -z "$ADDED_FILES" ]; then + echo " -> nothing to do" + else + echo " processing ..." + $CLANG_TIDY_CMD --warnings-as-errors=* -p build $ADDED_FILES + echo " ... done" + fi exit elif [[ "$MODE" == "full"* ]]; then DIRECTORY_TO_SCAN=$2 @@ -109,45 +172,8 @@ elif [[ "$MODE" == "scan_list"* ]]; then FILE_WITH_SCAN_LIST=$2 FILE_TO_SCAN=$3 - if ! test -f "$FILE_WITH_SCAN_LIST" - then - echo "Scan list file '${FILE_WITH_SCAN_LIST}' does not exist" - exit 1 - fi - - for LINE in $(cat $FILE_WITH_SCAN_LIST); do - # add files until the comment section starts - if [[ "$(echo $LINE | grep "#" | wc -l)" == "1" ]]; then - break - fi - FILE_LIST="${FILE_LIST} $LINE" - done - - if [[ -n $FILE_TO_SCAN ]] - then - if ! test -f "$FILE_TO_SCAN" - then - echo "The file which should be scanned '${FILE_TO_SCAN}' does not exist" - exit 1 - fi - - if [[ $(find ${FILE_LIST} -type f | grep -E ${FILE_FILTER} | grep ${FILE_TO_SCAN} | wc -l) == "0" ]] - then - echo "Skipping file '${FILE_TO_SCAN}' since it is not part of '${FILE_WITH_SCAN_LIST}'" - exit 0 - fi + scanWithFileList $FILE_WITH_SCAN_LIST $FILE_TO_SCAN - echo "Scanning file: ${FILE_TO_SCAN}" - $CLANG_TIDY_CMD --warnings-as-errors=* -p build $FILE_TO_SCAN - else - if [[ -z $FILE_LIST ]] - then - echo "'${FILE_WITH_SCAN_LIST}' is empty skipping folder scan." - exit 0 - fi - echo "Performing full scan of all folders in '${FILE_WITH_SCAN_LIST}'" - $CLANG_TIDY_CMD --warnings-as-errors=* -p build $(find ${FILE_LIST} -type f | grep -E ${FILE_FILTER}) - fi exit $? else echo "Invalid mode: ${MODE}"