diff --git a/.clang-tidy b/.clang-tidy index f194f955b2d..89fd2ec1ca0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,38 @@ -Checks: '-*,readability-*,-readability-named-parameter,-readability-avoid-const-params-in-decls,-readability-else-after-return,performance-*,-readability-redundant-access-specifiers,hicpp-*,-hicpp-named-parameter,-hicpp-avoid-c-arrays,cppcoreguidelines-*,-hicpp-no-array-decay,-hicpp-signed-bitwise,-hicpp-vararg,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-vararg,concurrency-*,clang-analyzer-*,cert-*,bugprone-*' +# NOTE: following checks are disabled, because they have duplicates in other group: +# +# - readability-magic-numbers (duplicate of cppcoreguidelines-avoid-magic-numbers) +# - hicpp-no-malloc (duplicate of cppcoreguidelines-no-malloc) +# - hicpp-member-init (duplicate of cppcoreguidelines-pro-type-member-init) +# - performance-move-const-arg (duplicate of hicpp-move-const-arg) +# - bugprone-use-after-move (duplicate of hicpp-move-const-arg) + +Checks: ' +-*, +readability-*, +clang-analyzer-*, +cert-*, +bugprone-*, +-readability-named-parameter, +-readability-avoid-const-params-in-decls, +-readability-else-after-return,performance-*, +-readability-redundant-access-specifiers,hicpp-*, +-readability-magic-numbers, +-hicpp-named-parameter, +-hicpp-avoid-c-arrays,cppcoreguidelines-*, +-hicpp-no-array-decay,-hicpp-signed-bitwise, +-hicpp-vararg, +-hicpp-no-malloc, +-hicpp-member-init, +-performance-move-const-arg, +-cppcoreguidelines-avoid-c-arrays, +-cppcoreguidelines-pro-bounds-constant-array-index, +-cppcoreguidelines-pro-bounds-array-to-pointer-decay, +-cppcoreguidelines-pro-type-vararg,concurrency-*, +-cppcoreguidelines-macro-usage, +-cppcoreguidelines-avoid-non-const-global-variables, +-cppcoreguidelines-pro-type-reinterpret-cast, +-bugprone-use-after-move' + CheckOptions: - { key: readability-identifier-naming.ClassCase, value: CamelCase } - { key: readability-identifier-naming.EnumCase, value: CamelCase } @@ -11,7 +45,7 @@ CheckOptions: - { key: readability-identifier-naming.ProtectedMemberPrefix, value: m_ } - { key: readability-identifier-naming.MemberCase, value: camelBack } - { key: readability-identifier-naming.ConstexprVariableCase, value: UPPER_CASE } - - { key: readability-identifier-naming.EnumCase, value: UPPER_CASE } + - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE } - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } - { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase } - { key: readability-function-size.LineThreshold, value: 200 } diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index cbc1847b0c0..b6f3da8b42b 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -16,6 +16,12 @@ jobs: - uses: actions/checkout@v2 - run: ./tools/check_formatting.sh + run-clang-tidy: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - run: ./tools/ci/run-clang-tidy.sh + build-test-ubuntu: runs-on: ubuntu-18.04 needs: pre-flight-check diff --git a/CHANGELOG.md b/CHANGELOG.md index 69412215b7e..c2ea952e918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ **Refactoring:** +- Add clang-tidy rules for iceoryx_hoofs[\#889](https://github.com/eclipse-iceoryx/iceoryx/issues/889) - Move all tests into an anonymous namespace[\#563](https://github.com/eclipse-iceoryx/iceoryx/issues/563) - Refactor smart_c to use contract by design and expected[\#418](https://github.com/eclipse-iceoryx/iceoryx/issues/418) - PoshRuntime Mock[\#449](https://github.com/eclipse-iceoryx/iceoryx/issues/449) @@ -109,6 +110,21 @@ ServiceDescription("First", "Second", "DontCare") myServiceDescription2; ServiceDescription("Foo", "Bar", "Baz") myServiceDescription3; ``` +`PosixGroup` and `PosixUser` are now accepting consistently const arguments only. +This applies for the group ID and group name. + +```cpp +// before +string_t groupName = "foo"; +auto foo = PosixGroup(groupName); + +// after +const string_t groupName = "foo"; +auto foo = PosixGroup(groupName); + +// Same with PosixUser class +``` + ## [v1.0.1](https://github.com/eclipse-iceoryx/iceoryx/tree/v1.0.0) (2021-06-15) [Full Changelog](https://github.com/eclipse-iceoryx/iceoryx/compare/v1.0.0...v1.0.1) diff --git a/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp b/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp index fd510f325ab..73ed955653b 100644 --- a/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp +++ b/iceoryx_binding_c/test/moduletests/test_c2cpp_enum_translation.cpp @@ -57,7 +57,7 @@ TEST(c2cpp_enum_translation_test, SubscriberState) // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) iox::Error errorValue = iox::Error::kNO_ERROR; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error e, const std::function, const iox::ErrorLevel) { errorValue = e; }); EXPECT_EQ(c2cpp::queueFullPolicy(static_cast(-1)), iox::popo::QueueFullPolicy::DISCARD_OLDEST_DATA); @@ -93,7 +93,7 @@ TEST(c2cpp_enum_translation_test, SubscriberEvent) // the clang sanitizer detects this successfully and this leads to termination, and with this the test fails #if !defined(__clang__) iox::Error errorValue = iox::Error::kNO_ERROR; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error e, const std::function, const iox::ErrorLevel) { errorValue = e; }); EXPECT_EQ(c2cpp::subscriberTooSlowPolicy(static_cast(-1)), iox::popo::SubscriberTooSlowPolicy::DISCARD_OLDEST_DATA); diff --git a/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp b/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp index b5dc0802d69..7c80b9ba5c0 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp +++ b/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp @@ -26,15 +26,23 @@ namespace dds { struct DDSLoggingComponent { + // NOLINTNEXTLINE(readability-identifier-naming) static constexpr char Ctx[] = "DDS"; + // NOLINTNEXTLINE(readability-identifier-naming) static constexpr char Description[] = "Log context of the DDS module."; }; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogFatal = iox::log::ffbb::LogFatal; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogError = iox::log::ffbb::LogError; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogWarn = iox::log::ffbb::LogWarn; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogInfo = iox::log::ffbb::LogInfo; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogDebug = iox::log::ffbb::LogDebug; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogVerbose = iox::log::ffbb::LogVerbose; } // namespace dds diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/attributes.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/attributes.hpp index 2b75ccf329c..7898afa4588 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/attributes.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/attributes.hpp @@ -27,7 +27,8 @@ namespace cxx /// uint32_t foo(); /// IOX_DISCARD_RESULT(foo()); // suppress compiler warning for unused return value /// @endcode -#define IOX_DISCARD_RESULT(expr) static_cast(expr) // NOLINT +// NOLINTNEXTLINE +#define IOX_DISCARD_RESULT(expr) static_cast(expr) /// @brief IOX_NO_DISCARD adds the [[nodiscard]] keyword if it is available for the current compiler. /// If additionally the keyword [[gnu::warn_unused]] is present it will be added as well. @@ -37,14 +38,18 @@ namespace cxx /// activate keywords for gcc>=5 or clang>=4 #if defined(_WIN32) // On WIN32 we are using C++17 which makes the keyword [[nodiscard]] available -#define IOX_NO_DISCARD [[nodiscard]] // NOLINT +// NOLINTNEXTLINE +#define IOX_NO_DISCARD [[nodiscard]] #elif defined(__APPLE__) && defined(__clang__) // On APPLE we are using C++17 which makes the keyword [[nodiscard]] available -#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]] // NOLINT +// NOLINTNEXTLINE +#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]] #elif (defined(__clang__) && __clang_major__ >= 4) -#define IOX_NO_DISCARD [[gnu::warn_unused]] // NOLINT +// NOLINTNEXTLINE +#define IOX_NO_DISCARD [[gnu::warn_unused]] #elif (defined(__GNUC__) && __GNUC__ >= 5) -#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]] // NOLINT +// NOLINTNEXTLINE +#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]] #else // on an unknown platform we use for now nothing since we do not know what is supported there #define IOX_NO_DISCARD @@ -57,13 +62,16 @@ namespace cxx /// activate keywords for gcc>=7 or clang>=4 #if defined(_WIN32) // On WIN32 we are using C++17 which makes the keyword [[fallthrough]] available -#define IOX_FALLTHROUGH [[fallthrough]] // NOLINT +// NOLINTNEXTLINE +#define IOX_FALLTHROUGH [[fallthrough]] #elif defined(__APPLE__) && defined(__clang__) // On APPLE we are using C++17 which makes the keyword [[fallthrough]] available -#define IOX_FALLTHROUGH [[fallthrough]] // NOLINT +// NOLINTNEXTLINE +#define IOX_FALLTHROUGH [[fallthrough]] #elif (defined(__GNUC__) && __GNUC__ >= 7) && !defined(__clang__) // clang prints a warning therefore we exclude it here -#define IOX_FALLTHROUGH [[fallthrough]] // NOLINT +// NOLINTNEXTLINE +#define IOX_FALLTHROUGH [[fallthrough]] #else // on an unknown platform we use for now nothing since we do not know what is supported there #define IOX_FALLTHROUGH @@ -74,10 +82,12 @@ namespace cxx /// @note /// activate attribute for gcc or clang #if defined(__GNUC__) || defined(__clang__) -#define IOX_MAYBE_UNUSED [[gnu::unused]] // NOLINT +// NOLINTNEXTLINE +#define IOX_MAYBE_UNUSED [[gnu::unused]] #elif defined(_WIN32) // On WIN32 we are using C++17 which makes the attribute [[maybe_unused]] available -#define IOX_MAYBE_UNUSED [[maybe_unused]] // NOLINT +// NOLINTNEXTLINE +#define IOX_MAYBE_UNUSED [[maybe_unused]] // on an unknown platform we use for now nothing since we do not know what is supported there #else #define IOX_MAYBE_UNUSED diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/deadline_timer.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/deadline_timer.hpp index cdf4a54e88d..e60966c1138 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/deadline_timer.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/deadline_timer.hpp @@ -45,7 +45,7 @@ class DeadlineTimer public: /// @brief Constructor /// @param[in] timeToWait duration until the timer expires - DeadlineTimer(const iox::units::Duration timeToWait) noexcept; + explicit DeadlineTimer(const iox::units::Duration timeToWait) noexcept; /// @brief Checks if the timer has expired compared to its absolute end time /// @return false if the timer is still active and true if it is expired @@ -63,10 +63,10 @@ class DeadlineTimer /// @brief calculates the remaining time before the timer goes off /// @return the time duration before the timer expires - const iox::units::Duration remainingTime() const noexcept; + iox::units::Duration remainingTime() const noexcept; private: - iox::units::Duration getCurrentMonotonicTime() const noexcept; + static iox::units::Duration getCurrentMonotonicTime() noexcept; iox::units::Duration m_timeToWait; iox::units::Duration m_endTime; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/generic_raii.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/generic_raii.hpp index 3b37ac6d366..feaf085e5b9 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/generic_raii.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/generic_raii.hpp @@ -47,13 +47,13 @@ class GenericRAII public: /// @brief constructor which creates GenericRAII that calls only the cleanupFunction on destruction /// @param[in] cleanupFunction callable which will be called in the destructor - GenericRAII(const std::function cleanupFunction) noexcept; + explicit GenericRAII(const std::function& cleanupFunction) noexcept; /// @brief constructor which calls initFunction and stores the cleanupFunction which will be /// called in the destructor /// @param[in] initFunction callable which will be called in the constructor /// @param[in] cleanupFunction callable which will be called in the destructor - GenericRAII(const function_ref initFunction, const std::function cleanupFunction) noexcept; + GenericRAII(const function_ref& initFunction, const std::function& cleanupFunction) noexcept; /// @brief calls m_cleanupFunction callable if it was set in the constructor ~GenericRAII() noexcept; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/creation.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/creation.hpp index a0001af991b..858fee9dcea 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/creation.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/design_pattern/creation.hpp @@ -21,6 +21,8 @@ #include +#define CREATION_MOVE(rhs) CreationPattern_t::operator=(std::move(*static_cast(&rhs))); + namespace DesignPattern { /// @brief This pattern can be used if you write an abstraction where you have diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp index c705f5369e0..7729e491b9b 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/error_handling/error_handling.hpp @@ -20,7 +20,7 @@ #include "iceoryx_hoofs/cxx/generic_raii.hpp" #include "iceoryx_hoofs/cxx/vector.hpp" -#include +#include #include #include #include @@ -215,22 +215,22 @@ using HandlerFunction = std::function errorCallBack, const ErrorLevel level); + friend void errorHandler(const Error error, const std::function& errorCallBack, const ErrorLevel level); public: - static cxx::GenericRAII SetTemporaryErrorHandler(const HandlerFunction& newHandler); + static cxx::GenericRAII setTemporaryErrorHandler(const HandlerFunction& newHandler); - static const char* ToString(const Error error); + static const char* toString(const Error error); protected: - static void ReactOnErrorLevel(const ErrorLevel level, const char* errorText); + static void reactOnErrorLevel(const ErrorLevel level, const char* errorText); private: - static void DefaultHandler(const Error error, - const std::function errorCallBack, + static void defaultHandler(const Error error, + const std::function& errorCallBack, const ErrorLevel level = ErrorLevel::FATAL); - static const char* errorNames[]; + static const char* ERROR_NAMES[]; static iox::HandlerFunction handler; /// Needed, if you want to exchange the handler. Remember the old one and call it if it is not your error. The error /// mock needs to be the last one exchanging the handler in tests. @@ -266,7 +266,7 @@ class ErrorHandler /// /// @code /// bool called = false; -/// auto temporaryErrorHandler = ErrorHandler::SetTemporaryErrorHandler( +/// auto temporaryErrorHandler = ErrorHandler::setTemporaryErrorHandler( /// [&](const Error e, std::function, const ErrorLevel) { /// called = true; /// }); @@ -275,7 +275,7 @@ class ErrorHandler /// ASSERT_TRUE(called); /// @endcode void errorHandler(const Error error, - const std::function errorCallBack = std::function(), + const std::function& errorCallBack = std::function(), const ErrorLevel level = ErrorLevel::FATAL); } // namespace iox diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/active_object.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/active_object.hpp index 6150fd03f60..78188b45a1d 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/active_object.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/active_object.hpp @@ -32,7 +32,7 @@ class ActiveObject protected: ActiveObject() noexcept; virtual ~ActiveObject() noexcept; - void addTask(const std::function f) noexcept; + void addTask(const std::function& f) noexcept; void mainLoop() noexcept; void stopRunning() noexcept; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/file_reader/file_reader.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/file_reader/file_reader.hpp index c713d503541..fcfc6c5feb0 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/file_reader/file_reader.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/file_reader/file_reader.hpp @@ -31,7 +31,7 @@ namespace cxx /// @code /// cxx::FileReader reader("filename"); /// std::string str; -/// if(reader.IsOpen()) { +/// if(reader.isOpen()) { /// reader.ReadeLine(str); /// } /// @@ -64,9 +64,9 @@ class FileReader ~FileReader() = default; /// Check if the associated file is open. - bool IsOpen() const; + bool isOpen() const; /// Read one line from the file and store the result in f_string. - bool ReadLine(std::string& f_string); + bool readLine(std::string& f_string); private: #ifdef _WIN32 diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/access_control.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/access_control.hpp index 4de9ab83424..ff90e5f8ea8 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/access_control.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/access_control.hpp @@ -113,9 +113,9 @@ class AccessController cxx::vector m_permissions; - cxx::expected createACL(const int32_t f_numEntries) const; - bool createACLEntry(const acl_t f_ACL, const PermissionEntry& f_entry) const; - bool addAclPermission(acl_permset_t f_permset, acl_perm_t f_perm) const; + static cxx::expected createACL(const int32_t f_numEntries); + static bool createACLEntry(const acl_t f_ACL, const PermissionEntry& f_entry); + static bool addAclPermission(acl_permset_t f_permset, acl_perm_t f_perm); bool m_useACLMask{false}; }; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/message_queue.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/message_queue.hpp index c56f1d8a9f4..c5799e86ba0 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/message_queue.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/message_queue.hpp @@ -63,9 +63,9 @@ class MessageQueue : public DesignPattern::Creation open(const IpcChannelName_t& name, const IpcChannelSide channelSide); @@ -111,9 +111,9 @@ class MessageQueue : public DesignPattern::Creation const off_t offset = 0) noexcept; bool isInitialized() const noexcept; bool destroy() noexcept; - MemoryMapError errnoToEnum(const int32_t errnum) const noexcept; + static MemoryMapError errnoToEnum(const int32_t errnum) noexcept; void* m_baseAddress{nullptr}; uint64_t m_length{0U}; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp index adc2a8e41eb..a72363bdc96 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/unix_domain_socket.hpp @@ -140,9 +140,9 @@ class UnixDomainSocket : public DesignPattern::Creation::max(); protected: + // justification: used by a friend class + // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) offset_t m_offset{NULL_POINTER_OFFSET}; offset_t computeOffset(const void* ptr) const noexcept; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp index 4699bf4457d..a6e3e8d4fb4 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/log/logger.hpp @@ -40,44 +40,57 @@ class Logger friend class LogStream; public: - Logger(Logger&& other); - Logger& operator=(Logger&& rhs); + Logger(Logger&& other) noexcept; + Logger& operator=(Logger&& rhs) noexcept; Logger(const Logger& other) = delete; Logger& operator=(const Logger& rhs) = delete; /// @brief Getter method for the current LogLevel /// @return the current LogLevel + // NOLINTNEXTLINE(readability-identifier-naming) LogLevel GetLogLevel() const noexcept; /// @brief Sets the LogLevel for the Logger /// @param[in] logLevel to be set + // NOLINTNEXTLINE(readability-identifier-naming) void SetLogLevel(const LogLevel logLevel) noexcept; /// @brief Sets the LogLevel to the given level for the lifetime of the GenericRAII object and then sets it back to /// the previous one /// @param[in] logLevel to be set temporarily /// @return a scope guard which resets the LogLevel to the value at the time when this method was called + // NOLINTNEXTLINE(readability-identifier-naming) cxx::GenericRAII SetLogLevelForScope(const LogLevel logLevel) noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) void SetLogMode(const LogMode logMode) noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) bool IsEnabled(const LogLevel logLevel) const noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) LogStream LogFatal() noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) LogStream LogError() noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) LogStream LogWarn() noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) LogStream LogInfo() noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) LogStream LogDebug() noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) LogStream LogVerbose() noexcept; protected: - Logger(std::string ctxId, std::string ctxDescription, LogLevel appLogLevel); + Logger(const std::string& ctxId, const std::string& ctxDescription, const LogLevel appLogLevel); // virtual because of Logger_Mock + // NOLINTNEXTLINE(readability-identifier-naming) virtual void Log(const LogEntry& entry) const; private: - void Print(const LogEntry entry) const; + // NOLINTNEXTLINE(readability-identifier-naming) + static void Print(const LogEntry& entry); std::atomic m_logLevel{LogLevel::kVerbose}; std::atomic m_logLevelPredecessor{LogLevel::kVerbose}; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/log/logging.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/log/logging.hpp index cda7a37daa6..0e41eaf5cc6 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/log/logging.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/log/logging.hpp @@ -27,7 +27,9 @@ namespace iox { namespace log { -Logger& CreateLogger(std::string ctxId, std::string ctxDescription, LogLevel appDefLogLevel = LogLevel::kWarn) noexcept; +Logger& createLogger(const std::string& ctxId, + const std::string& ctxDescription, + const LogLevel appDefLogLevel = LogLevel::kWarn) noexcept; inline constexpr LogHex8 HexFormat(uint8_t value) { diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/log/logging_free_function_building_block.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/log/logging_free_function_building_block.hpp index 59c5c5be030..4a2181ec740 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/log/logging_free_function_building_block.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/log/logging_free_function_building_block.hpp @@ -68,7 +68,7 @@ namespace ffbb template static Logger& ComponentLogger() { - static auto& logger = CreateLogger(T::Ctx, T::Description, LogManager::GetLogManager().DefaultLogLevel()); + static auto& logger = createLogger(T::Ctx, T::Description, LogManager::GetLogManager().DefaultLogLevel()); return logger; } diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/log/logmanager.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/log/logmanager.hpp index ecfdff34460..c39260cbb5a 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/log/logmanager.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/log/logmanager.hpp @@ -37,8 +37,13 @@ enum class LogLevelOutput : uint8_t class LogManager { public: + // NOLINTNEXTLINE(readability-identifier-naming) static LogManager& GetLogManager(); - static Logger& CreateLogContext(std::string ctxId, std::string ctxDescription, LogLevel appDefLogLevel) noexcept; + static Logger& + // NOLINTNEXTLINE(readability-identifier-naming) + CreateLogContext(const std::string& ctxId, + const std::string& ctxDescription, + const LogLevel appDefLogLevel) noexcept; ~LogManager() = default; @@ -47,11 +52,15 @@ class LogManager LogManager& operator=(const LogManager&) = delete; LogManager& operator=(LogManager&&) = delete; + // NOLINTNEXTLINE(readability-identifier-naming) LogLevel DefaultLogLevel() const noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) void SetDefaultLogLevel(const LogLevel logLevel, const LogLevelOutput logLevelOutput = LogLevelOutput::kDisplayLogLevel) noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) LogMode DefaultLogMode() const noexcept; + // NOLINTNEXTLINE(readability-identifier-naming) void SetDefaultLogMode(const LogMode logMode) noexcept; protected: diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp index 6a84bae39a7..744ee958055 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp @@ -42,8 +42,8 @@ class PosixGroup { public: using string_t = cxx::string<100>; - PosixGroup(gid_t f_id); - PosixGroup(string_t f_name); + explicit PosixGroup(const gid_t f_id); + explicit PosixGroup(const string_t& f_name); bool operator==(const PosixGroup& other) const; @@ -68,8 +68,8 @@ class PosixUser using groupVector_t = cxx::vector; using string_t = cxx::string<100>; - PosixUser(uid_t f_id); - PosixUser(const string_t& f_name); + explicit PosixUser(const uid_t f_id); + explicit PosixUser(const string_t& f_name); groupVector_t getGroups() const; string_t getName() const; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_call.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_call.hpp index e9374ae6e56..954212d59c3 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_call.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/posix_call.hpp @@ -48,7 +48,7 @@ struct PosixCallResult cxx::string getHumanReadableErrnum() const noexcept; /// @brief the return value of the posix function call - T value; + T value{}; /// @brief the errno value which was set by the posix function call int32_t errnum = POSIX_CALL_INVALID_ERRNO; @@ -188,9 +188,9 @@ class IOX_NO_DISCARD PosixCallBuilder PosixCallVerificator operator()(FunctionArguments... arguments) && noexcept; private: - template - friend PosixCallBuilder - internal::createPosixCallBuilder(ReturnType_ (*posixCall)(FunctionArguments_...), + template + friend PosixCallBuilder + internal::createPosixCallBuilder(ReturnTypeFriend (*posixCall)(FunctionArgumentsFriend...), const char* posixFunctionName, const char* file, const int32_t line, diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/semaphore.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/semaphore.hpp index da526e8aaa8..00099eefb3e 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/semaphore.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/semaphore.hpp @@ -176,7 +176,7 @@ class Semaphore : public DesignPattern::Creation bool m_isNamedSemaphore = true; bool m_isShared = false; - mutable iox_sem_t m_handle; + mutable iox_sem_t m_handle{}; mutable iox_sem_t* m_handlePtr = nullptr; private: @@ -269,7 +269,7 @@ class Semaphore : public DesignPattern::Creation /// undefined behavior. /// /// @return returns false when sem_init fails otherwise true - bool init(iox_sem_t* handle, const int pshared, const unsigned int value) noexcept; + static bool init(iox_sem_t* handle, const int pshared, const unsigned int value) noexcept; /// @brief calls sem_open which initializes and opens a named semaphore /// From the sem_open manpage: sem_open() creates a new POSIX semaphore or @@ -312,7 +312,7 @@ class Semaphore : public DesignPattern::Creation /// open close it. /// /// @return returns false when sem_unlink fails otherwise true - bool unlink(const char* name) noexcept; + static bool unlink(const char* name) noexcept; /// @brief Returns true if the semaphore was created with CreateNamed or /// OpenNamed otherwise it returns false. @@ -320,7 +320,7 @@ class Semaphore : public DesignPattern::Creation void closeHandle() noexcept; - SemaphoreError errnoToEnum(const int errnoValue) const noexcept; + static SemaphoreError errnoToEnum(const int errnoValue) noexcept; }; } // namespace posix } // namespace iox diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/signal_handler.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/signal_handler.hpp index 9bde9df19b1..2d3c978f278 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/signal_handler.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/signal_handler.hpp @@ -69,7 +69,7 @@ class SignalGuard private: Signal m_signal; - struct sigaction m_previousAction; + struct sigaction m_previousAction = {}; bool m_doRestorePreviousAction{false}; }; diff --git a/iceoryx_hoofs/platform/linux/source/file.cpp b/iceoryx_hoofs/platform/linux/source/file.cpp index 4406fc09fe5..2c2315c3951 100644 --- a/iceoryx_hoofs/platform/linux/source/file.cpp +++ b/iceoryx_hoofs/platform/linux/source/file.cpp @@ -16,6 +16,7 @@ #include "iceoryx_hoofs/platform/file.hpp" +// NOLINTNEXTLINE(readability-identifier-naming) int iox_flock(int fd, int op) { return flock(fd, op); diff --git a/iceoryx_hoofs/platform/linux/source/fnctl.cpp b/iceoryx_hoofs/platform/linux/source/fnctl.cpp index 307725cda27..10fd9a18856 100644 --- a/iceoryx_hoofs/platform/linux/source/fnctl.cpp +++ b/iceoryx_hoofs/platform/linux/source/fnctl.cpp @@ -16,6 +16,7 @@ #include "iceoryx_hoofs/platform/fcntl.hpp" +// NOLINTNEXTLINE(readability-identifier-naming) int iox_open(const char* pathname, int flags, mode_t mode) { return open(pathname, flags, mode); diff --git a/iceoryx_hoofs/platform/linux/source/grp.cpp b/iceoryx_hoofs/platform/linux/source/grp.cpp index f4a0180e62d..9f56d2337e1 100644 --- a/iceoryx_hoofs/platform/linux/source/grp.cpp +++ b/iceoryx_hoofs/platform/linux/source/grp.cpp @@ -16,6 +16,7 @@ #include "iceoryx_hoofs/platform/grp.hpp" +// NOLINTNEXTLINE(readability-function-size,readability-identifier-naming) int iox_getgrouplist(const char* user, gid_t group, gid_t* groups, int* ngroups) { return getgrouplist(user, group, groups, ngroups); diff --git a/iceoryx_hoofs/platform/linux/source/mman.cpp b/iceoryx_hoofs/platform/linux/source/mman.cpp index 586af07dd32..509d11dab05 100644 --- a/iceoryx_hoofs/platform/linux/source/mman.cpp +++ b/iceoryx_hoofs/platform/linux/source/mman.cpp @@ -16,11 +16,13 @@ #include "iceoryx_hoofs/platform/mman.hpp" +// NOLINTNEXTLINE(readability-identifier-naming) int iox_shm_open(const char* name, int oflag, mode_t mode) { return shm_open(name, oflag, mode); } +// NOLINTNEXTLINE(readability-identifier-naming) int iox_shm_unlink(const char* name) { return shm_unlink(name); diff --git a/iceoryx_hoofs/platform/linux/source/mqueue.cpp b/iceoryx_hoofs/platform/linux/source/mqueue.cpp index 1d56455a9de..261d313e86a 100644 --- a/iceoryx_hoofs/platform/linux/source/mqueue.cpp +++ b/iceoryx_hoofs/platform/linux/source/mqueue.cpp @@ -16,11 +16,13 @@ #include "iceoryx_hoofs/platform/mqueue.hpp" +// NOLINTNEXTLINE(readability-identifier-naming) mqd_t iox_mq_open2(const char* name, int oflag) { return mq_open(name, oflag); } +// NOLINTNEXTLINE(readability-function-size,readability-identifier-naming) mqd_t iox_mq_open4(const char* name, int oflag, mode_t mode, struct mq_attr* attr) { return mq_open(name, oflag, mode, attr); diff --git a/iceoryx_hoofs/platform/linux/source/socket.cpp b/iceoryx_hoofs/platform/linux/source/socket.cpp index 6750572c86a..232e0c994f7 100644 --- a/iceoryx_hoofs/platform/linux/source/socket.cpp +++ b/iceoryx_hoofs/platform/linux/source/socket.cpp @@ -17,37 +17,44 @@ #include "iceoryx_hoofs/platform/socket.hpp" #include +// NOLINTNEXTLINE(readability-identifier-naming) int iox_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { return bind(sockfd, addr, addrlen); } +// NOLINTNEXTLINE(readability-identifier-naming) int iox_socket(int domain, int type, int protocol) { return socket(domain, type, protocol); } +// NOLINTNEXTLINE(readability-identifier-naming,readability-function-size) int iox_setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t optlen) { return setsockopt(sockfd, level, optname, optval, optlen); } ssize_t +// NOLINTNEXTLINE(readability-identifier-naming,readability-function-size) iox_sendto(int sockfd, const void* buf, size_t len, int flags, const struct sockaddr* dest_addr, socklen_t addrlen) { return sendto(sockfd, buf, len, flags, dest_addr, addrlen); } +// NOLINTNEXTLINE(readability-identifier-naming,readability-function-size) ssize_t iox_recvfrom(int sockfd, void* buf, size_t len, int flags, struct sockaddr* src_addr, socklen_t* addrlen) { return recvfrom(sockfd, buf, len, flags, src_addr, addrlen); } +// NOLINTNEXTLINE(readability-identifier-naming) int iox_connect(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { return connect(sockfd, addr, addrlen); } +// NOLINTNEXTLINE(readability-identifier-naming) int iox_closesocket(int sockfd) { return close(sockfd); diff --git a/iceoryx_hoofs/platform/linux/source/unistd.cpp b/iceoryx_hoofs/platform/linux/source/unistd.cpp index 28b422df06e..ed6616ccca6 100644 --- a/iceoryx_hoofs/platform/linux/source/unistd.cpp +++ b/iceoryx_hoofs/platform/linux/source/unistd.cpp @@ -17,6 +17,7 @@ #include "iceoryx_hoofs/platform/unistd.hpp" +// NOLINTNEXTLINE(readability-identifier-naming) int iox_close(int fd) { return close(fd); diff --git a/iceoryx_hoofs/source/concurrent/active_object.cpp b/iceoryx_hoofs/source/concurrent/active_object.cpp index 4abc1253d1d..b49d578ca9f 100644 --- a/iceoryx_hoofs/source/concurrent/active_object.cpp +++ b/iceoryx_hoofs/source/concurrent/active_object.cpp @@ -31,7 +31,7 @@ ActiveObject::~ActiveObject() noexcept stopRunning(); } -void ActiveObject::addTask(const std::function f) noexcept +void ActiveObject::addTask(const std::function& f) noexcept { m_tasks.push(f); } diff --git a/iceoryx_hoofs/source/concurrent/loffli.cpp b/iceoryx_hoofs/source/concurrent/loffli.cpp index 29a417097b1..6150bbb78ae 100644 --- a/iceoryx_hoofs/source/concurrent/loffli.cpp +++ b/iceoryx_hoofs/source/concurrent/loffli.cpp @@ -40,6 +40,7 @@ void LoFFLi::init(cxx::not_null freeIndicesMemory, const uint32_t capa { for (uint32_t i = 0; i < m_size + 1; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) upper limit of index is set by m_size m_nextFreeIndex[i] = i + 1; } } @@ -58,6 +59,7 @@ bool LoFFLi::pop(Index_t& index) noexcept return false; } + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) upper limit of index set by m_size newHead.indexToNextFreeIndex = m_nextFreeIndex[oldHead.indexToNextFreeIndex]; newHead.abaCounter += 1; } while (!m_head.compare_exchange_weak(oldHead, newHead, std::memory_order_acq_rel, std::memory_order_acquire)); @@ -70,6 +72,7 @@ bool LoFFLi::pop(Index_t& index) noexcept /// either is used by the same thread in push or it is given to another /// thread which performs the cleanup and during this process a synchronization /// is required + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) m_nextFreeIndex[index] = m_invalidIndex; /// we need to synchronize m_nextFreeIndex with push so that we can perform a validation @@ -86,6 +89,7 @@ bool LoFFLi::push(const Index_t index) noexcept /// we want to avoid double free's therefore we check if the index was acquired /// in pop and the push argument "index" is valid + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) index is limited by capacity if (index >= m_size || m_nextFreeIndex[index] != m_invalidIndex) { return false; @@ -96,6 +100,7 @@ bool LoFFLi::push(const Index_t index) noexcept do { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) index is limited by capacity m_nextFreeIndex[index] = oldHead.indexToNextFreeIndex; newHead.indexToNextFreeIndex = index; newHead.abaCounter += 1; diff --git a/iceoryx_hoofs/source/cxx/deadline_timer.cpp b/iceoryx_hoofs/source/cxx/deadline_timer.cpp index d615d8ef640..9317c4c6df6 100644 --- a/iceoryx_hoofs/source/cxx/deadline_timer.cpp +++ b/iceoryx_hoofs/source/cxx/deadline_timer.cpp @@ -43,7 +43,7 @@ void DeadlineTimer::reset(const iox::units::Duration timeToWait) noexcept reset(); } -const iox::units::Duration DeadlineTimer::remainingTime() const noexcept +iox::units::Duration DeadlineTimer::remainingTime() const noexcept { auto currentTime = getCurrentMonotonicTime(); if (m_endTime > currentTime) @@ -53,7 +53,7 @@ const iox::units::Duration DeadlineTimer::remainingTime() const noexcept return iox::units::Duration(std::chrono::milliseconds(0)); } -iox::units::Duration DeadlineTimer::getCurrentMonotonicTime() const noexcept +iox::units::Duration DeadlineTimer::getCurrentMonotonicTime() noexcept { iox::units::Duration currentTime(std::chrono::steady_clock::now().time_since_epoch()); return currentTime; diff --git a/iceoryx_hoofs/source/cxx/generic_raii.cpp b/iceoryx_hoofs/source/cxx/generic_raii.cpp index 22c73840334..256ede1a81e 100644 --- a/iceoryx_hoofs/source/cxx/generic_raii.cpp +++ b/iceoryx_hoofs/source/cxx/generic_raii.cpp @@ -21,12 +21,13 @@ namespace iox { namespace cxx { -GenericRAII::GenericRAII(const std::function cleanupFunction) noexcept +GenericRAII::GenericRAII(const std::function& cleanupFunction) noexcept : GenericRAII(function_ref(), cleanupFunction) { } -GenericRAII::GenericRAII(const function_ref initFunction, const std::function cleanupFunction) noexcept +GenericRAII::GenericRAII(const function_ref& initFunction, + const std::function& cleanupFunction) noexcept : m_cleanupFunction(cleanupFunction) { if (initFunction) diff --git a/iceoryx_hoofs/source/cxx/helplets.cpp b/iceoryx_hoofs/source/cxx/helplets.cpp index d574868f43d..4abf5dfb27f 100644 --- a/iceoryx_hoofs/source/cxx/helplets.cpp +++ b/iceoryx_hoofs/source/cxx/helplets.cpp @@ -25,14 +25,20 @@ void* alignedAlloc(const uint64_t alignment, const uint64_t size) noexcept { // -1 == since the max alignment addition is alignment - 1 otherwise the // memory is already aligned and we have to do nothing + // low-level memory management + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory, cppcoreguidelines-no-malloc, hicpp-use-auto) uint64_t memory = reinterpret_cast(malloc(size + alignment + sizeof(void*) - 1)); if (memory == 0) { return nullptr; } uint64_t alignedMemory = align(memory + sizeof(void*), alignment); + assert(alignedMemory >= memory + 1); + // low-level memory management + // NOLINTNEXTLINE(performance-no-int-to-ptr, cppcoreguidelines-pro-bounds-pointer-arithmetic) reinterpret_cast(alignedMemory)[-1] = reinterpret_cast(memory); + // NOLINTNEXTLINE(performance-no-int-to-ptr) low-level memory management return reinterpret_cast(alignedMemory); } @@ -40,6 +46,9 @@ void alignedFree(void* const memory) { if (memory != nullptr) { + // low-level memory management + // NOLINTNEXTLINE(cppcoreguidelines-owning-memory, cppcoreguidelines-no-malloc, + // cppcoreguidelines-pro-bounds-pointer-arithmetic) free(reinterpret_cast(memory)[-1]); } } diff --git a/iceoryx_hoofs/source/error_handling/error_handling.cpp b/iceoryx_hoofs/source/error_handling/error_handling.cpp index 40cc571a5a3..07e05d5dfb6 100644 --- a/iceoryx_hoofs/source/error_handling/error_handling.cpp +++ b/iceoryx_hoofs/source/error_handling/error_handling.cpp @@ -26,19 +26,20 @@ namespace iox { -const char* ErrorHandler::errorNames[] = {ICEORYX_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; +const char* ErrorHandler::ERROR_NAMES[] = {ICEORYX_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; -HandlerFunction ErrorHandler::handler = {ErrorHandler::DefaultHandler}; +// NOLINTNEXTLINE(cert-err58-cpp) ErrorHander only used in tests +HandlerFunction ErrorHandler::handler = {ErrorHandler::defaultHandler}; std::mutex ErrorHandler::handler_mutex; std::ostream& operator<<(std::ostream& stream, Error value) { - stream << ErrorHandler::ToString(value); + stream << ErrorHandler::toString(value); return stream; } -void ErrorHandler::DefaultHandler(const Error error, const std::function errorCallBack, const ErrorLevel level) +void ErrorHandler::defaultHandler(const Error error, const std::function& errorCallBack, const ErrorLevel level) { if (errorCallBack) { @@ -49,13 +50,13 @@ void ErrorHandler::DefaultHandler(const Error error, const std::function std::stringstream ss; ss << "ICEORYX error! " << error; - ReactOnErrorLevel(level, ss.str().c_str()); + reactOnErrorLevel(level, ss.str().c_str()); } } -void ErrorHandler::ReactOnErrorLevel(const ErrorLevel level, const char* errorText) +void ErrorHandler::reactOnErrorLevel(const ErrorLevel level, const char* errorText) { - static auto& logger = CreateLogger("", "", log::LogManager::GetLogManager().DefaultLogLevel()); + static auto& logger = createLogger("", "", log::LogManager::GetLogManager().DefaultLogLevel()); switch (level) { case ErrorLevel::FATAL: @@ -73,7 +74,7 @@ void ErrorHandler::ReactOnErrorLevel(const ErrorLevel level, const char* errorTe } } -cxx::GenericRAII ErrorHandler::SetTemporaryErrorHandler(const HandlerFunction& newHandler) +cxx::GenericRAII ErrorHandler::setTemporaryErrorHandler(const HandlerFunction& newHandler) { return cxx::GenericRAII( [&newHandler] { @@ -82,17 +83,17 @@ cxx::GenericRAII ErrorHandler::SetTemporaryErrorHandler(const HandlerFunction& n }, [] { std::lock_guard lock(handler_mutex); - handler = DefaultHandler; + handler = defaultHandler; }); } -const char* ErrorHandler::ToString(const Error error) +const char* ErrorHandler::toString(const Error error) { - return ErrorHandler::errorNames[static_cast(error)]; + return ErrorHandler::ERROR_NAMES[static_cast(error)]; } -void errorHandler(const Error error, const std::function errorCallBack, const ErrorLevel level) +void errorHandler(const Error error, const std::function& errorCallBack, const ErrorLevel level) { ErrorHandler::handler(error, errorCallBack, level); } diff --git a/iceoryx_hoofs/source/file_reader/file_reader.cpp b/iceoryx_hoofs/source/file_reader/file_reader.cpp index c81d706c52a..dd13aea950b 100644 --- a/iceoryx_hoofs/source/file_reader/file_reader.cpp +++ b/iceoryx_hoofs/source/file_reader/file_reader.cpp @@ -31,7 +31,7 @@ FileReader::FileReader(const std::string& f_fileName, const std::string& f_fileP m_file = f_filePath.empty() ? f_fileName : f_filePath + PATH_SEPARATOR + f_fileName; m_fileStream.open(m_file, std::fstream::in); - if (!IsOpen()) + if (!isOpen()) { errorHandler(Error::kFILEREADER__FAILED_TO_OPEN_FILE, [=]() { switch (m_errorMode) @@ -61,12 +61,12 @@ FileReader::FileReader(const std::string& f_fileName, const std::string& f_fileP } } -bool FileReader::IsOpen() const +bool FileReader::isOpen() const { return m_fileStream.is_open(); } -bool FileReader::ReadLine(std::string& f_string) +bool FileReader::readLine(std::string& f_string) { return static_cast(std::getline(m_fileStream, f_string)); } diff --git a/iceoryx_hoofs/source/log/logger.cpp b/iceoryx_hoofs/source/log/logger.cpp index 0fb84960ef8..da970d63123 100644 --- a/iceoryx_hoofs/source/log/logger.cpp +++ b/iceoryx_hoofs/source/log/logger.cpp @@ -34,34 +34,39 @@ namespace iox { namespace log { -Logger::Logger(IOX_MAYBE_UNUSED std::string ctxId, IOX_MAYBE_UNUSED std::string ctxDescription, LogLevel appLogLevel) +Logger::Logger(IOX_MAYBE_UNUSED const std::string& ctxId, + IOX_MAYBE_UNUSED const std::string& ctxDescription, + LogLevel appLogLevel) : m_logLevel(appLogLevel) { } -Logger::Logger(Logger&& other) +Logger::Logger(Logger&& other) noexcept { m_logLevel.store(other.m_logLevel.load(std::memory_order_relaxed), std::memory_order_relaxed); m_logMode.store(other.m_logMode.load(std::memory_order_relaxed), std::memory_order_relaxed); } -Logger& Logger::operator=(Logger&& rhs) +Logger& Logger::operator=(Logger&& rhs) noexcept { m_logLevel.store(rhs.m_logLevel.load(std::memory_order_relaxed), std::memory_order_relaxed); m_logMode.store(rhs.m_logMode.load(std::memory_order_relaxed), std::memory_order_relaxed); return *this; } +// NOLINTNEXTLINE(readability-identifier-naming) LogLevel Logger::GetLogLevel() const noexcept { return m_logLevel.load(std::memory_order_relaxed); } +// NOLINTNEXTLINE(readability-identifier-naming) void Logger::SetLogLevel(const LogLevel logLevel) noexcept { m_logLevel.store(logLevel, std::memory_order_relaxed); } +// NOLINTNEXTLINE(readability-identifier-naming) cxx::GenericRAII Logger::SetLogLevelForScope(const LogLevel logLevel) noexcept { m_logLevelPredecessor.store(m_logLevel.load(std::memory_order_relaxed), std::memory_order_relaxed); @@ -69,6 +74,7 @@ cxx::GenericRAII Logger::SetLogLevelForScope(const LogLevel logLevel) noexcept return cxx::GenericRAII([] {}, [&] { this->SetLogLevel(m_logLevelPredecessor.load(std::memory_order_relaxed)); }); } +// NOLINTNEXTLINE(readability-identifier-naming) void Logger::SetLogMode(const LogMode logMode) noexcept { m_logMode.store(logMode, std::memory_order_relaxed); @@ -84,37 +90,44 @@ void Logger::SetLogMode(const LogMode logMode) noexcept } } +// NOLINTNEXTLINE(readability-identifier-naming) LogStream Logger::LogFatal() noexcept { return LogStream(*this, LogLevel::kFatal); } +// NOLINTNEXTLINE(readability-identifier-naming) LogStream Logger::LogError() noexcept { return LogStream(*this, LogLevel::kError); } +// NOLINTNEXTLINE(readability-identifier-naming) LogStream Logger::LogWarn() noexcept { return LogStream(*this, LogLevel::kWarn); } +// NOLINTNEXTLINE(readability-identifier-naming) LogStream Logger::LogInfo() noexcept { return LogStream(*this, LogLevel::kInfo); } +// NOLINTNEXTLINE(readability-identifier-naming) LogStream Logger::LogDebug() noexcept { return LogStream(*this, LogLevel::kDebug); } +// NOLINTNEXTLINE(readability-identifier-naming) LogStream Logger::LogVerbose() noexcept { return LogStream(*this, LogLevel::kVerbose); } -void Logger::Print(const LogEntry entry) const +// NOLINTNEXTLINE(readability-identifier-naming) +void Logger::Print(const LogEntry& entry) { // as long as there is only this synchronous logger, buffer the output before using clog to prevent interleaving // output because of threaded access @@ -123,21 +136,27 @@ void Logger::Print(const LogEntry entry) const auto sec = std::chrono::duration_cast(entry.time); std::time_t time = sec.count(); - auto timeInfo = std::localtime(&time); + // TODO: std::localtime is thread-unsafe, may be remove + // NOLINTNEXTLINE(concurrency-mt-unsafe) + auto* timeInfo = std::localtime(&time); + // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers) + auto milliseconds = entry.time.count() % 1000; buffer << "\033[0;90m" << std::put_time(timeInfo, "%Y-%m-%d %H:%M:%S"); - buffer << "." << std::right << std::setfill('0') << std::setw(3) << entry.time.count() % 1000 << " "; + buffer << "." << std::right << std::setfill('0') << std::setw(3) << milliseconds << " "; buffer << LogLevelColor[cxx::enumTypeAsUnderlyingType(entry.level)] << LogLevelText[cxx::enumTypeAsUnderlyingType(entry.level)]; buffer << "\033[m: " << entry.message << std::endl; std::clog << buffer.str(); } +// NOLINTNEXTLINE(readability-identifier-naming) bool Logger::IsEnabled(const LogLevel logLevel) const noexcept { return (logLevel <= m_logLevel.load(std::memory_order_relaxed)); } +// NOLINTNEXTLINE(readability-identifier-naming) void Logger::Log(const LogEntry& entry) const { /// @todo do we want a ringbuffer where we store the last e.g. 100 logs diff --git a/iceoryx_hoofs/source/log/logging.cpp b/iceoryx_hoofs/source/log/logging.cpp index f37783de6e9..a33981f6051 100644 --- a/iceoryx_hoofs/source/log/logging.cpp +++ b/iceoryx_hoofs/source/log/logging.cpp @@ -15,6 +15,8 @@ // // SPDX-License-Identifier: Apache-2.0 +#include + #include "iceoryx_hoofs/log/logging.hpp" #include "iceoryx_hoofs/log/logger.hpp" @@ -25,7 +27,8 @@ namespace iox { namespace log { -Logger& CreateLogger(std::string ctxId, std::string ctxDescription, LogLevel appDefLogLevel) noexcept +Logger& +createLogger(const std::string& ctxId, const std::string& ctxDescription, const LogLevel appDefLogLevel) noexcept { return LogManager::CreateLogContext(ctxId, ctxDescription, appDefLogLevel); } diff --git a/iceoryx_hoofs/source/log/logging_internal.cpp b/iceoryx_hoofs/source/log/logging_internal.cpp index a851272a25b..1cdc94a6106 100644 --- a/iceoryx_hoofs/source/log/logging_internal.cpp +++ b/iceoryx_hoofs/source/log/logging_internal.cpp @@ -21,7 +21,9 @@ namespace iox { namespace log { +// NOLINTNEXTLINE(readability-identifier-naming) constexpr char LoggingComponent::Ctx[]; +// NOLINTNEXTLINE(readability-identifier-naming) constexpr char LoggingComponent::Description[]; } // namespace log } // namespace iox diff --git a/iceoryx_hoofs/source/log/logging_internal.hpp b/iceoryx_hoofs/source/log/logging_internal.hpp index 7b74cb0a29e..dce5043f469 100644 --- a/iceoryx_hoofs/source/log/logging_internal.hpp +++ b/iceoryx_hoofs/source/log/logging_internal.hpp @@ -24,15 +24,23 @@ namespace log { struct LoggingComponent { + // NOLINTNEXTLINE(readability-identifier-naming) static constexpr char Ctx[] = "IceoryxHoofs"; + // NOLINTNEXTLINE(readability-identifier-naming) static constexpr char Description[] = "Log context of the IceoryxHoofs component!"; }; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogFatal = iox::log::ffbb::LogFatal; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogError = iox::log::ffbb::LogError; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogWarn = iox::log::ffbb::LogWarn; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogInfo = iox::log::ffbb::LogInfo; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogDebug = iox::log::ffbb::LogDebug; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogVerbose = iox::log::ffbb::LogVerbose; } // namespace log diff --git a/iceoryx_hoofs/source/log/logmanager.cpp b/iceoryx_hoofs/source/log/logmanager.cpp index 517f55a1547..7894c4b23c8 100644 --- a/iceoryx_hoofs/source/log/logmanager.cpp +++ b/iceoryx_hoofs/source/log/logmanager.cpp @@ -23,20 +23,23 @@ #include "logging_internal.hpp" #include +#include namespace iox { namespace log { +// NOLINTNEXTLINE(readability-identifier-naming) LogManager& LogManager::GetLogManager() { static LogManager manager; return manager; } -Logger& LogManager::CreateLogContext(IOX_MAYBE_UNUSED std::string ctxId, - IOX_MAYBE_UNUSED std::string ctxDescription, - LogLevel appDefLogLevel) noexcept +// NOLINTNEXTLINE(readability-identifier-naming) +Logger& LogManager::CreateLogContext(IOX_MAYBE_UNUSED const std::string& ctxId, + IOX_MAYBE_UNUSED const std::string& ctxDescription, + const LogLevel appDefLogLevel) noexcept { static std::mutex mtx; std::lock_guard lock(mtx); @@ -54,11 +57,13 @@ Logger& LogManager::CreateLogContext(IOX_MAYBE_UNUSED std::string ctxId, } } +// NOLINTNEXTLINE(readability-identifier-naming) LogLevel LogManager::DefaultLogLevel() const noexcept { return m_defaultLogLevel.load(std::memory_order_relaxed); } +// NOLINTNEXTLINE(readability-identifier-naming) void LogManager::SetDefaultLogLevel(const LogLevel logLevel, const LogLevelOutput logLevelOutput) noexcept { m_defaultLogLevel.store(logLevel, std::memory_order_relaxed); @@ -75,11 +80,13 @@ void LogManager::SetDefaultLogLevel(const LogLevel logLevel, const LogLevelOutpu } } +// NOLINTNEXTLINE(readability-identifier-naming) LogMode LogManager::DefaultLogMode() const noexcept { return m_defaultLogMode.load(std::memory_order_relaxed); } +// NOLINTNEXTLINE(readability-identifier-naming) void LogManager::SetDefaultLogMode(const LogMode logMode) noexcept { m_defaultLogMode.store(logMode, std::memory_order_relaxed); diff --git a/iceoryx_hoofs/source/log/logstream.cpp b/iceoryx_hoofs/source/log/logstream.cpp index bc987141d59..5aae7a35a9b 100644 --- a/iceoryx_hoofs/source/log/logstream.cpp +++ b/iceoryx_hoofs/source/log/logstream.cpp @@ -42,6 +42,7 @@ LogStream::~LogStream() Flush(); } +// NOLINTNEXTLINE(readability-identifier-naming) void LogStream::Flush() { /// @todo do we want to send the log to the logger even if the loglevel is lower than the global log level? @@ -99,7 +100,10 @@ LogStream& LogStream::operator<<(const LogRawBuffer& value) noexcept for (int8_t i = 0; i < value.size; ++i) { // the '+value' is there to not interpret the uint8_t as char and print the character instead of the hex value - ss << (i > 0 ? " " : "") << std::setw(2) << +value.data[i]; + ss << (i > 0 ? " " : "") + << std::setw(2) + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + << +value.data[i]; } ss << "]"; m_logEntry.message.append(ss.str()); diff --git a/iceoryx_hoofs/source/posix_wrapper/access_control.cpp b/iceoryx_hoofs/source/posix_wrapper/access_control.cpp index a0a7f68021f..15e4aa32b6a 100644 --- a/iceoryx_hoofs/source/posix_wrapper/access_control.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/access_control.cpp @@ -34,7 +34,7 @@ bool AccessController::writePermissionsToFile(const int32_t f_fileDescriptor) co return false; } - auto maybeWorkingACL = createACL((m_permissions.size() + m_useACLMask) ? 1 : 0); + auto maybeWorkingACL = createACL(m_permissions.size() + (m_useACLMask ? 1U : 0U)); if (maybeWorkingACL.has_error()) { @@ -56,7 +56,7 @@ bool AccessController::writePermissionsToFile(const int32_t f_fileDescriptor) co // add mask to acl if specific users or groups have been added if (m_useACLMask) { - createACLEntry(workingACL.get(), {ACL_MASK, Permission::READWRITE, -1u}); + createACLEntry(workingACL.get(), {ACL_MASK, Permission::READWRITE, -1U}); } // check if acl is valid @@ -80,7 +80,7 @@ bool AccessController::writePermissionsToFile(const int32_t f_fileDescriptor) co } cxx::expected -AccessController::createACL(const int32_t f_numEntries) const +AccessController::createACL(const int32_t f_numEntries) { // allocate memory for a new ACL auto aclInitCall = posixCall(acl_init)(f_numEntries).failureReturnValue(nullptr).evaluate(); @@ -195,10 +195,10 @@ bool AccessController::addPermissionEntry(const Category f_category, const Permi return true; } -bool AccessController::createACLEntry(const acl_t f_ACL, const PermissionEntry& f_entry) const +bool AccessController::createACLEntry(const acl_t f_ACL, const PermissionEntry& f_entry) { // create new entry in acl - acl_entry_t newEntry; + acl_entry_t newEntry{}; acl_t l_ACL{f_ACL}; auto aclCreateEntryCall = posixCall(acl_create_entry)(&l_ACL, &newEntry).successReturnValue(0).evaluate(); @@ -210,7 +210,7 @@ bool AccessController::createACLEntry(const acl_t f_ACL, const PermissionEntry& } // set tag type for new entry (user, group, ...) - acl_tag_t tagType = static_cast(f_entry.m_category); + auto tagType = static_cast(f_entry.m_category); auto aclSetTagTypeCall = posixCall(acl_set_tag_type)(newEntry, tagType).successReturnValue(0).evaluate(); if (aclSetTagTypeCall.has_error()) @@ -253,7 +253,7 @@ bool AccessController::createACLEntry(const acl_t f_ACL, const PermissionEntry& } // get reference to permission set in new entry - acl_permset_t entryPermissionSet; + acl_permset_t entryPermissionSet{}; auto aclGetPermsetCall = posixCall(acl_get_permset)(newEntry, &entryPermissionSet).successReturnValue(0).evaluate(); @@ -275,7 +275,7 @@ bool AccessController::createACLEntry(const acl_t f_ACL, const PermissionEntry& } case Permission::READWRITE: { - if (addAclPermission(entryPermissionSet, ACL_READ) == false) + if (!addAclPermission(entryPermissionSet, ACL_READ)) { return false; } @@ -292,7 +292,7 @@ bool AccessController::createACLEntry(const acl_t f_ACL, const PermissionEntry& } } -bool AccessController::addAclPermission(acl_permset_t f_permset, acl_perm_t f_perm) const +bool AccessController::addAclPermission(acl_permset_t f_permset, acl_perm_t f_perm) { auto aclAddPermCall = posixCall(acl_add_perm)(f_permset, f_perm).successReturnValue(0).evaluate(); diff --git a/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp b/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp index f72812220ce..77356dec0ac 100644 --- a/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp @@ -45,10 +45,10 @@ cxx::expected FileLock::initializeFileLock() noexcept return cxx::error(FileLockError::INVALID_FILE_NAME); } PathName_t fullPath(platform::IOX_LOCK_FILE_PATH_PREFIX + m_name + ".lock"); - constexpr int createFileForReadWrite = O_CREAT | O_RDWR; + constexpr int CREATE_FILE_FOR_READ_WRITE = O_CREAT | O_RDWR; mode_t userReadWriteAccess = S_IRUSR | S_IWUSR; - auto openCall = posixCall(iox_open)(fullPath.c_str(), createFileForReadWrite, userReadWriteAccess) + auto openCall = posixCall(iox_open)(fullPath.c_str(), CREATE_FILE_FOR_READ_WRITE, userReadWriteAccess) .failureReturnValue(ERROR_CODE) .evaluate() .and_then([this](auto& r) { this->m_fd = r.value; }); @@ -89,11 +89,10 @@ FileLock& FileLock::operator=(FileLock&& rhs) noexcept std::cerr << "Unable to cleanup file lock \"" << m_name << "\" in the move constructor/move assingment operator" << std::endl; } - - CreationPattern_t::operator=(std::move(rhs)); + CREATION_MOVE(rhs); m_name = std::move(rhs.m_name); - m_fd = std::move(rhs.m_fd); + m_fd = rhs.m_fd; rhs.m_name.assign(""); rhs.m_fd = INVALID_FD; diff --git a/iceoryx_hoofs/source/posix_wrapper/message_queue.cpp b/iceoryx_hoofs/source/posix_wrapper/message_queue.cpp index f2e1c7c69d2..08cf925355d 100644 --- a/iceoryx_hoofs/source/posix_wrapper/message_queue.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/message_queue.cpp @@ -35,6 +35,7 @@ MessageQueue::MessageQueue() this->m_errorValue = IpcChannelError::NOT_INITIALIZED; } +// NOLINTNEXTLINE(readability-function-size) todo(iox-#832): make a struct out of arguments MessageQueue::MessageQueue(const IpcChannelName_t& name, const IpcChannelSide channelSide, const size_t maxMsgSize, @@ -93,7 +94,7 @@ MessageQueue::MessageQueue(const IpcChannelName_t& name, } } -MessageQueue::MessageQueue(MessageQueue&& other) +MessageQueue::MessageQueue(MessageQueue&& other) noexcept { *this = std::move(other); } @@ -106,7 +107,7 @@ MessageQueue::~MessageQueue() } } -MessageQueue& MessageQueue::operator=(MessageQueue&& other) +MessageQueue& MessageQueue::operator=(MessageQueue&& other) noexcept { if (this != &other) { @@ -115,12 +116,16 @@ MessageQueue& MessageQueue::operator=(MessageQueue&& other) std::cerr << "unable to cleanup message queue \"" << m_name << "\" during move operation - resource leaks are possible!" << std::endl; } - CreationPattern_t::operator=(std::move(other)); + CREATION_MOVE(other); m_name = std::move(other.m_name); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_attributes = std::move(other.m_attributes); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_mqDescriptor = std::move(other.m_mqDescriptor); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_channelSide = std::move(other.m_channelSide); + other.m_mqDescriptor = INVALID_DESCRIPTOR; } @@ -321,7 +326,7 @@ cxx::expected MessageQueue::timedSend(const std::string& msg, c cxx::expected MessageQueue::isOutdated() { - struct stat sb; + struct stat sb = {}; auto fstatCall = posixCall(fstat)(m_mqDescriptor, &sb).failureReturnValue(-1).evaluate(); if (fstatCall.has_error()) { @@ -376,6 +381,7 @@ cxx::error MessageQueue::createErrorFromErrnum(const IpcChannel } default: { + // NOLINTNEXTLINE(concurrency-mt-unsafe) impossible case std::cerr << "internal logic error in message queue \"" << name << "\" occurred [errno: " << errnum << ": " << strerror(errnum) << "]" << std::endl; return cxx::error(IpcChannelError::INTERNAL_LOGIC_ERROR); @@ -394,6 +400,8 @@ MessageQueue::sanitizeIpcChannelName(const IpcChannelName_t& name) noexcept { return cxx::error(IpcChannelError::INVALID_CHANNEL_NAME); } + // name is checked for emptiness, so it's ok to get a first member + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) else if (name.c_str()[0] != '/') { return cxx::success(IpcChannelName_t("/").append(iox::cxx::TruncateToCapacity, name)); diff --git a/iceoryx_hoofs/source/posix_wrapper/mutex.cpp b/iceoryx_hoofs/source/posix_wrapper/mutex.cpp index 33b1aa562cb..d5e6354f9df 100644 --- a/iceoryx_hoofs/source/posix_wrapper/mutex.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/mutex.cpp @@ -57,6 +57,7 @@ mutex::~mutex() cxx::Ensures(!destroyCall.has_error() && "Could not destroy mutex"); } +// NOLINTNEXTLINE(readability-identifier-naming) C++ STL code guidelines pthread_mutex_t mutex::get_native_handle() const noexcept { return m_handle; @@ -72,6 +73,7 @@ bool mutex::unlock() return !posixCall(pthread_mutex_unlock)(&m_handle).successReturnValue(0).evaluate().has_error(); } +// NOLINTNEXTLINE(readability-identifier-naming) C++ STL code guidelines bool mutex::try_lock() { auto result = posixCall(pthread_mutex_trylock)(&m_handle).returnValueMatchesErrno().ignoreErrnos(EBUSY).evaluate(); diff --git a/iceoryx_hoofs/source/posix_wrapper/named_pipe.cpp b/iceoryx_hoofs/source/posix_wrapper/named_pipe.cpp index 79890e89e6e..ebafb1a0429 100644 --- a/iceoryx_hoofs/source/posix_wrapper/named_pipe.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/named_pipe.cpp @@ -36,6 +36,7 @@ NamedPipe::NamedPipe() noexcept this->m_errorValue = IpcChannelError::NOT_INITIALIZED; } +// NOLINTNEXTLINE(readability-function-size) todo(iox-#832): make a struct out of arguments NamedPipe::NamedPipe(const IpcChannelName_t& name, const IpcChannelSide channelSide, const size_t maxMsgSize, @@ -58,6 +59,8 @@ NamedPipe::NamedPipe(const IpcChannelName_t& name, // leading slash is allowed even though it is not a valid file name bool isValidPipeName = cxx::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))); if (!isValidPipeName) { @@ -117,7 +120,7 @@ NamedPipe::NamedPipe(const IpcChannelName_t& name, else { m_isInitialized = m_data->waitForInitialization(); - if (m_isInitialized == false) + if (!m_isInitialized) { m_errorValue = IpcChannelError::INTERNAL_LOGIC_ERROR; } @@ -134,10 +137,12 @@ NamedPipe& NamedPipe::operator=(NamedPipe&& rhs) noexcept if (this != &rhs) { IOX_DISCARD_RESULT(destroy()); - CreationPattern_t::operator=(std::move(rhs)); + CREATION_MOVE(rhs) m_sharedMemory = std::move(rhs.m_sharedMemory); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_data = std::move(rhs.m_data); + rhs.m_data = nullptr; } @@ -153,6 +158,7 @@ template IpcChannelName_t NamedPipe::convertName(const Prefix& p, const IpcChannelName_t& name) noexcept { return IpcChannelName_t(cxx::TruncateToCapacity, + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) cxx::concatenate(p, (name.c_str()[0] == '/') ? *name.substr(1) : name).c_str()); } @@ -172,6 +178,7 @@ cxx::expected NamedPipe::destroy() noexcept return cxx::success<>(); } +// NOLINTNEXTLINE(readability-convert-member-functions-to-static) API can be misused if IPC channel changes cxx::expected NamedPipe::isOutdated() noexcept { return cxx::success(false); @@ -324,6 +331,7 @@ cxx::expected NamedPipe::timedReceive(const units: return cxx::error(IpcChannelError::TIMEOUT); } +// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) semaphores are initalized via placementCreate call NamedPipe::NamedPipeData::NamedPipeData(bool& isInitialized, IpcChannelError& error, const uint64_t maxMsgNumber) noexcept diff --git a/iceoryx_hoofs/source/posix_wrapper/posix_access_rights.cpp b/iceoryx_hoofs/source/posix_wrapper/posix_access_rights.cpp index 7e8683c3667..2e5f7a2f3ac 100644 --- a/iceoryx_hoofs/source/posix_wrapper/posix_access_rights.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/posix_access_rights.cpp @@ -43,7 +43,7 @@ PosixGroup::PosixGroup(gid_t f_id) { } -PosixGroup::PosixGroup(PosixGroup::string_t f_name) +PosixGroup::PosixGroup(const PosixGroup::string_t& f_name) { auto id = getGroupID(f_name); if (id.has_value()) diff --git a/iceoryx_hoofs/source/posix_wrapper/semaphore.cpp b/iceoryx_hoofs/source/posix_wrapper/semaphore.cpp index ab7fb766629..5df78bd1f68 100644 --- a/iceoryx_hoofs/source/posix_wrapper/semaphore.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/semaphore.cpp @@ -24,9 +24,7 @@ namespace iox { namespace posix { -Semaphore::Semaphore() noexcept -{ -} +Semaphore::Semaphore() noexcept = default; Semaphore::Semaphore(Semaphore&& rhs) noexcept { @@ -39,15 +37,21 @@ Semaphore& Semaphore::operator=(Semaphore&& rhs) noexcept { closeHandle(); - CreationPattern_t::operator=(std::move(rhs)); + CREATION_MOVE(rhs) m_name = std::move(rhs.m_name); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_isCreated = std::move(rhs.m_isCreated); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_isNamedSemaphore = std::move(rhs.m_isNamedSemaphore); + // NOLINTNEXTLINE(hicpp-move-const-arg) because m_handle cannot be copied in macos m_handle = std::move(rhs.m_handle); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_isShared = std::move(rhs.m_isShared); + if (m_isNamedSemaphore || m_isShared) { + // NOLINTNEXTLINE m_handlePtr = std::move(rhs.m_handlePtr); } else @@ -89,7 +93,7 @@ void Semaphore::closeHandle() noexcept cxx::expected Semaphore::getValue() const noexcept { - int value; + int value{0}; auto call = posixCall(iox_sem_getvalue)(getHandle(), &value).failureReturnValue(-1).evaluate(); if (call.has_error()) { @@ -190,7 +194,7 @@ Semaphore::Semaphore(CreateUnnamedSharedMemorySemaphore_t, const unsigned int va Semaphore::Semaphore(OpenNamedSemaphore_t, const char* name, const int oflag) noexcept : m_isCreated(false) { - if (m_name.unsafe_assign(name) == false) + if (!m_name.unsafe_assign(name)) { m_isInitialized = false; m_errorValue = SemaphoreError::NAME_TOO_LONG; @@ -208,10 +212,11 @@ Semaphore::Semaphore(OpenNamedSemaphore_t, const char* name, const int oflag) no } } +// NOLINTNEXTLINE(readability-function-size) todo(iox-#832): make a struct out of arguments Semaphore::Semaphore(CreateNamedSemaphore_t, const char* name, const mode_t mode, const unsigned int value) noexcept : m_isCreated(true) { - if (m_name.unsafe_assign(name) == false) + if (!m_name.unsafe_assign(name)) { m_isInitialized = false; m_errorValue = SemaphoreError::NAME_TOO_LONG; @@ -275,7 +280,7 @@ bool Semaphore::isNamedSemaphore() const noexcept return m_isNamedSemaphore; } -SemaphoreError Semaphore::errnoToEnum(const int errnoValue) const noexcept +SemaphoreError Semaphore::errnoToEnum(const int errnoValue) noexcept { switch (errnoValue) { @@ -290,7 +295,7 @@ SemaphoreError Semaphore::errnoToEnum(const int errnoValue) const noexcept return SemaphoreError::INTERRUPTED_BY_SIGNAL_HANDLER; default: std::cerr << "an unexpected error occurred in semaphore - this should never happen! errno: " - << strerror(errnoValue) << std::endl; + << strerror(errnoValue) << std::endl; // NOLINT(concurrency-mt-unsafe) impossible case return SemaphoreError::UNDEFINED; } } diff --git a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp index 6c3609a819a..4274bfeb776 100644 --- a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp @@ -44,6 +44,8 @@ static void memsetSigbusHandler(int) _exit(EXIT_FAILURE); } +// TODO: reduce number of arguments by moving them to struct +// NOLINTNEXTLINE(readability-function-size) SharedMemoryObject::SharedMemoryObject(const SharedMemory::Name_t& name, const uint64_t memorySizeInBytes, const AccessMode accessMode, @@ -74,7 +76,7 @@ SharedMemoryObject::SharedMemoryObject(const SharedMemory::Name_t& name, }); } - if (m_isInitialized == false) + if (!m_isInitialized) { auto flags = std::cerr.flags(); std::cerr << "Unable to create a shared memory object with the following properties [ name = " << name diff --git a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/allocator.cpp b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/allocator.cpp index 13a459ce659..ed4ad6ff25b 100644 --- a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/allocator.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/allocator.cpp @@ -49,6 +49,7 @@ void* Allocator::allocate(const uint64_t size, const uint64_t alignment) noexcep if (m_length >= alignedPosition + size) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) low-level memory management l_returnValue = m_startAddress + alignedPosition; m_currentPosition = alignedPosition + size; } diff --git a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/memory_map.cpp b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/memory_map.cpp index 23616f2c420..ead31259770 100644 --- a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/memory_map.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/memory_map.cpp @@ -24,6 +24,8 @@ namespace iox { namespace posix { +// TODO: reduce number of arguments by moving them to struct +// NOLINTNEXTLINE(readability-function-size) MemoryMap::MemoryMap(const void* baseAddressHint, const uint64_t length, const int32_t fileDescriptor, @@ -44,7 +46,9 @@ MemoryMap::MemoryMap(const void* baseAddressHint, } // PRQA S 3066 1 # incompatibility with POSIX definition of mmap + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) low-level memory management posixCall(mmap)(const_cast(baseAddressHint), m_length, l_memoryProtection, flags, fileDescriptor, offset) + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr) .failureReturnValue(reinterpret_cast(MAP_FAILED)) .evaluate() .and_then([this](auto& r) { @@ -68,7 +72,7 @@ MemoryMap::MemoryMap(const void* baseAddressHint, }); } -MemoryMapError MemoryMap::errnoToEnum(const int32_t errnum) const noexcept +MemoryMapError MemoryMap::errnoToEnum(const int32_t errnum) noexcept { switch (errnum) { @@ -144,9 +148,11 @@ MemoryMap& MemoryMap::operator=(MemoryMap&& rhs) noexcept std::cerr << "move assignment failed to unmap mapped memory" << std::endl; } - CreationPattern_t::operator=(std::move(rhs)); + CREATION_MOVE(rhs) + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_baseAddress = std::move(rhs.m_baseAddress); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_length = std::move(rhs.m_length); rhs.m_baseAddress = nullptr; 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 dfeae83ad68..b0c8dce3779 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 @@ -25,14 +25,15 @@ #include "iceoryx_hoofs/platform/unistd.hpp" #include "iceoryx_hoofs/posix_wrapper/posix_call.hpp" -#include #include +#include #include namespace iox { namespace posix { +// NOLINTNEXTLINE(readability-function-size) todo(iox-#832): make a struct out of arguments SharedMemory::SharedMemory(const Name_t& name, const AccessMode accessMode, const OpenMode openMode, @@ -47,6 +48,8 @@ SharedMemory::SharedMemory(const Name_t& name, m_isInitialized = false; m_errorValue = SharedMemoryError::EMPTY_NAME; } + // empty case handled above, so it's fine to get first element + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) else if (name.c_str()[0] != '/') { std::cerr << "Shared memory name must start with a leading slash!" << std::endl; @@ -113,11 +116,11 @@ SharedMemory& SharedMemory::operator=(SharedMemory&& rhs) noexcept { destroy(); - CreationPattern_t::operator=(std::move(rhs)); + CREATION_MOVE(rhs); - m_name = rhs.m_name; - m_hasOwnership = std::move(rhs.m_hasOwnership); - m_handle = std::move(rhs.m_handle); + m_name = std::move(rhs.m_name); + m_hasOwnership = rhs.m_hasOwnership; + m_handle = rhs.m_handle; rhs.reset(); } @@ -134,6 +137,7 @@ bool SharedMemory::hasOwnership() const noexcept return m_hasOwnership; } +// NOLINTNEXTLINE(readability-function-size) todo(iox-#832): make a struct out of arguments bool SharedMemory::open(const AccessMode accessMode, const OpenMode openMode, const mode_t permissions, @@ -221,7 +225,7 @@ bool SharedMemory::unlink() noexcept if (m_isInitialized && m_hasOwnership) { auto unlinkResult = unlinkIfExist(m_name); - if (unlinkResult.has_error() || unlinkResult.value() == false) + if (unlinkResult.has_error() || !unlinkResult.value()) { std::cerr << "Unable to unlink SharedMemory (shm_unlink failed)." << std::endl; return false; diff --git a/iceoryx_hoofs/source/posix_wrapper/signal_handler.cpp b/iceoryx_hoofs/source/posix_wrapper/signal_handler.cpp index 8490d105076..42cba14ae34 100644 --- a/iceoryx_hoofs/source/posix_wrapper/signal_handler.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/signal_handler.cpp @@ -30,8 +30,11 @@ SignalGuard::SignalGuard(const Signal signal, const struct sigaction& previousAc SignalGuard::SignalGuard(SignalGuard&& rhs) noexcept { + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_signal = std::move(rhs.m_signal); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_previousAction = std::move(rhs.m_previousAction); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_doRestorePreviousAction = std::move(rhs.m_doRestorePreviousAction); rhs.m_doRestorePreviousAction = false; @@ -57,7 +60,8 @@ void SignalGuard::restorePreviousAction() noexcept SignalGuard registerSignalHandler(const Signal signal, const SignalHandlerCallback_t callback) noexcept { - struct sigaction action; + struct sigaction action = {}; + // sigemptyset fails when a nullptr is provided and this should never happen with this logic if (posixCall(sigemptyset)(&action.sa_mask).successReturnValue(0).evaluate().has_error()) @@ -68,10 +72,13 @@ SignalGuard registerSignalHandler(const Signal signal, const SignalHandlerCallba return SignalGuard(); } + // system struct, no way to avoid union + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) action.sa_handler = callback; action.sa_flags = 0; - struct sigaction previousAction; + + struct sigaction previousAction = {}; // sigaction fails when action is a nullptr (which we ensure that its not) or when the signal SIGSTOP or SIGKILL // should be registered which can also never happen - ensured by the enum class. diff --git a/iceoryx_hoofs/source/posix_wrapper/timer.cpp b/iceoryx_hoofs/source/posix_wrapper/timer.cpp index d123bb19934..548f2162d4d 100644 --- a/iceoryx_hoofs/source/posix_wrapper/timer.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/timer.cpp @@ -31,21 +31,26 @@ Timer::OsTimerCallbackHandle Timer::OsTimer::s_callbackHandlePool[MAX_NUMBER_OF_ sigval Timer::OsTimerCallbackHandle::indexAndDescriptorToSigval(uint8_t index, uint32_t descriptor) noexcept { assert(descriptor < MAX_DESCRIPTOR_VALUE); + // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers) shift 8 bits uint32_t temp = (descriptor << 8) | static_cast(index); - sigval sigvalData; + sigval sigvalData{}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) system struct sigvalData.sival_int = static_cast(temp); return sigvalData; } uint8_t Timer::OsTimerCallbackHandle::sigvalToIndex(sigval intVal) noexcept { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access, cppcoreguidelines-avoid-magic-numbers) system struct return static_cast(0xFF & intVal.sival_int); } uint32_t Timer::OsTimerCallbackHandle::sigvalToDescriptor(sigval intVal) noexcept { - uint32_t temp = static_cast(intVal.sival_int); - return (temp >> 8u) & 0xFFFFFFu; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) system struct + auto temp = static_cast(intVal.sival_int); + // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers) shift 8 bits + return (temp >> 8U) & 0xFFFFFFU; } void Timer::OsTimerCallbackHandle::incrementDescriptor() noexcept @@ -54,7 +59,7 @@ void Timer::OsTimerCallbackHandle::incrementDescriptor() noexcept callbackHandleDescriptor++; if (callbackHandleDescriptor >= Timer::OsTimerCallbackHandle::MAX_DESCRIPTOR_VALUE) { - callbackHandleDescriptor = 0u; + callbackHandleDescriptor = 0U; } m_descriptor.store(callbackHandleDescriptor, std::memory_order_relaxed); @@ -81,7 +86,8 @@ void Timer::OsTimer::callbackHelper(sigval data) // signal that we intend to call the callback (but we may not start it ourself, it may be done // by another invocation of this function) - auto invocationCounter = handle.m_timerInvocationCounter.fetch_add(1u, std::memory_order_relaxed); + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) used in a do-while loop below + auto invocationCounter = handle.m_timerInvocationCounter.fetch_add(1U, std::memory_order_relaxed); // avoid the spurious failures of try_lock with this flag end still reduce contention // if another thread is in this section we return but we already stated our intention to call the callback @@ -128,10 +134,10 @@ void Timer::OsTimer::callbackHelper(sigval data) return; } - invocationCounter = handle.m_timerInvocationCounter.exchange(0u, std::memory_order_acq_rel); + invocationCounter = handle.m_timerInvocationCounter.exchange(0U, std::memory_order_acq_rel); // did someone else execute the callback for us? - if (invocationCounter != 0u) + if (invocationCounter != 0U) { handle.m_timer->executeCallback(); } @@ -156,7 +162,7 @@ void Timer::OsTimer::callbackHelper(sigval data) // and be able to enter the region or the flag to be set again, in which case this thread // will take care of the call - } while (handle.m_catchUpPolicy == CatchUpPolicy::IMMEDIATE && invocationCounter > 0u); + } while (handle.m_catchUpPolicy == CatchUpPolicy::IMMEDIATE && invocationCounter > 0U); } else { @@ -182,7 +188,7 @@ Timer::OsTimer::OsTimer(const units::Duration timeToWait, const std::function Timer::OsTimer::start(const RunMode runMode, const CatchUpPolicy catchUpPolicy) noexcept { // Convert units::Duration to itimerspec - struct itimerspec interval; + struct itimerspec interval = {}; interval.it_value = m_timeToWait.timespec(units::TimeSpecReference::None); if (runMode == RunMode::PERIODIC) @@ -327,7 +336,7 @@ cxx::expected Timer::OsTimer::stop() noexcept return cxx::success(); } - struct itimerspec interval; + struct itimerspec interval = {}; units::Duration zero = 0_s; interval.it_value = zero.timespec(units::TimeSpecReference::None); interval.it_interval.tv_sec = 0; @@ -383,7 +392,7 @@ cxx::expected Timer::OsTimer::restart(const units::Duration timeToWa cxx::expected Timer::OsTimer::timeUntilExpiration() noexcept { - struct itimerspec currentInterval; + struct itimerspec currentInterval = {}; auto result = posixCall(timer_gettime)(m_timerId, ¤tInterval).failureReturnValue(-1).evaluate(); @@ -423,7 +432,7 @@ TimerError Timer::OsTimer::getError() const noexcept cxx::expected Timer::now() noexcept { - struct timespec value; + struct timespec value = {}; auto result = posixCall(clock_gettime)(CLOCK_REALTIME, &value).failureReturnValue(-1).evaluate(); if (result.has_error()) diff --git a/iceoryx_hoofs/source/posix_wrapper/timespec.cpp b/iceoryx_hoofs/source/posix_wrapper/timespec.cpp index 8aa7435396a..42147652a4c 100644 --- a/iceoryx_hoofs/source/posix_wrapper/timespec.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/timespec.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/internal/posix_wrapper/timespec.hpp" +#include namespace iox { @@ -23,8 +24,9 @@ namespace posix { struct timespec addTimeMs(struct timespec time, const uint32_t timeToAdd_ms) { - decltype(time.tv_nsec) sec_ns = time.tv_nsec + ((timeToAdd_ms % 1000) * TS_DIVIDER_msec); - time.tv_sec += (timeToAdd_ms / 1000); + constexpr uint32_t MSEC_IN_SEC{1000}; + decltype(time.tv_nsec) sec_ns = time.tv_nsec + ((timeToAdd_ms % MSEC_IN_SEC) * TS_DIVIDER_msec); + time.tv_sec += (timeToAdd_ms / MSEC_IN_SEC); if (sec_ns < TS_DIVIDER_sec) { time.tv_nsec = sec_ns; @@ -48,7 +50,8 @@ double subtractTimespecMS(const struct timespec minuend, const struct timespec s const TimeType diff_s = static_cast(minuend.tv_sec) - static_cast(subtrahend.tv_sec); const TimeType diff_ns = static_cast(minuend.tv_nsec) - static_cast(subtrahend.tv_nsec); - return (static_cast(diff_s) * 1000.) + constexpr double MSEC_IN_SEC{1000.}; + return (static_cast(diff_s) * MSEC_IN_SEC) + (static_cast(diff_ns) / static_cast(TS_DIVIDER_msec)); } diff --git a/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp b/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp index e276d9eac03..fb00cf1034f 100644 --- a/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp @@ -40,6 +40,7 @@ UnixDomainSocket::UnixDomainSocket() noexcept this->m_errorValue = IpcChannelError::NOT_INITIALIZED; } +// NOLINTNEXTLINE(readability-convert-member-functions-to-static) API can be misused if IPC channel changes cxx::expected UnixDomainSocket::isOutdated() noexcept { // This is for being API compatible with the message queue, but has no equivalent for socket. @@ -54,6 +55,7 @@ UnixDomainSocket::UnixDomainSocket(UnixDomainSocket&& other) noexcept *this = std::move(other); } +// NOLINTNEXTLINE(readability-function-size) todo(iox-#832): make a struct out of arguments UnixDomainSocket::UnixDomainSocket(const IpcChannelName_t& name, const IpcChannelSide channelSide, const size_t maxMsgSize, @@ -75,6 +77,7 @@ UnixDomainSocket::UnixDomainSocket(const IpcChannelName_t& name, { } +// NOLINTNEXTLINE(readability-function-size) todo(iox-#832): make a struct out of arguments UnixDomainSocket::UnixDomainSocket(const NoPathPrefix_t, const UdsName_t& name, const IpcChannelSide channelSide, @@ -123,12 +126,16 @@ UnixDomainSocket& UnixDomainSocket::operator=(UnixDomainSocket&& other) noexcept << "\" in the move constructor/move assingment operator" << std::endl; } - CreationPattern_t::operator=(std::move(other)); + CREATION_MOVE(other) m_name = std::move(other.m_name); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_channelSide = std::move(other.m_channelSide); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_sockfd = std::move(other.m_sockfd); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_sockAddr = std::move(other.m_sockAddr); + // NOLINTNEXTLINE(hicpp-move-const-arg) might break silently if object becomes non-trivial m_maxMessageSize = std::move(other.m_maxMessageSize); other.m_sockfd = INVALID_FD; @@ -262,7 +269,7 @@ cxx::expected UnixDomainSocket::receive() const no { // we also support timedReceive. The setsockopt call sets the timeout for all further recvfrom calls, so we must set // it to 0 to turn the timeout off - struct timeval tv; + struct timeval tv = {}; tv.tv_sec = 0; tv.tv_usec = 0; @@ -413,7 +420,7 @@ IpcChannelError UnixDomainSocket::convertErrnoToIpcChannelError(const int32_t er } case ENOBUFS: { - std::cerr << "out of memory for unix domain socket \"" << m_name << "\"" << std::endl; + std::cerr << "queue is full for unix domain socket \"" << m_name << "\"" << std::endl; return IpcChannelError(IpcChannelError::OUT_OF_MEMORY); } case ENOMEM: @@ -438,7 +445,7 @@ IpcChannelError UnixDomainSocket::convertErrnoToIpcChannelError(const int32_t er } case ENOTSOCK: { - std::cerr << "invalid file descriptor for unix domain socket \"" << m_name << "\"" << std::endl; + std::cerr << "invalid unix domain socket \"" << m_name << "\"" << std::endl; return IpcChannelError(IpcChannelError::INVALID_FILE_DESCRIPTOR); } case EADDRNOTAVAIL: diff --git a/iceoryx_hoofs/source/relocatable_pointer/base_relative_pointer.cpp b/iceoryx_hoofs/source/relocatable_pointer/base_relative_pointer.cpp index abe885c54d4..7651713a664 100644 --- a/iceoryx_hoofs/source/relocatable_pointer/base_relative_pointer.cpp +++ b/iceoryx_hoofs/source/relocatable_pointer/base_relative_pointer.cpp @@ -39,6 +39,7 @@ BaseRelativePointer::BaseRelativePointer(ptr_t ptr) noexcept { } +// NOLINTNEXTLINE(hicpp-use-equals-default) style consistency BaseRelativePointer::BaseRelativePointer(const BaseRelativePointer& other) noexcept : m_id(other.m_id) , m_offset(other.m_offset) @@ -134,7 +135,7 @@ BaseRelativePointer::offset_t BaseRelativePointer::getOffset(const id_t id, cons { return NULL_POINTER_OFFSET; } - auto basePtr = getBasePtr(id); + auto* basePtr = getBasePtr(id); return reinterpret_cast(ptr) - reinterpret_cast(basePtr); } @@ -144,7 +145,8 @@ BaseRelativePointer::ptr_t BaseRelativePointer::getPtr(const id_t id, const offs { return nullptr; } - auto basePtr = getBasePtr(id); + auto* basePtr = getBasePtr(id); + // NOLINTNEXTLINE(performance-no-int-to-ptr) reliance on integers for offset computation by design return reinterpret_cast(offset + reinterpret_cast(basePtr)); } diff --git a/iceoryx_hoofs/source/relocatable_pointer/base_relocatable_pointer.cpp b/iceoryx_hoofs/source/relocatable_pointer/base_relocatable_pointer.cpp index b8a7c9aa0df..1fe943c4380 100644 --- a/iceoryx_hoofs/source/relocatable_pointer/base_relocatable_pointer.cpp +++ b/iceoryx_hoofs/source/relocatable_pointer/base_relocatable_pointer.cpp @@ -21,10 +21,6 @@ namespace iox { namespace rp { -BaseRelocatablePointer::BaseRelocatablePointer() noexcept -{ -} - BaseRelocatablePointer::BaseRelocatablePointer(const void* ptr) noexcept : m_offset(computeOffset(ptr)) { @@ -105,9 +101,12 @@ BaseRelocatablePointer::offset_t BaseRelocatablePointer::computeOffset(const voi void* BaseRelocatablePointer::computeRawPtr() const noexcept { if (m_offset == NULL_POINTER_OFFSET) + { return nullptr; + } /// @todo find most efficient way to do this (see above) + // NOLINTNEXTLINE(performance-no-int-to-ptr) return reinterpret_cast(reinterpret_cast(&m_offset) - m_offset); } } // namespace rp diff --git a/iceoryx_hoofs/source/relocatable_pointer/relative_pointer_data.cpp b/iceoryx_hoofs/source/relocatable_pointer/relative_pointer_data.cpp index 0b4a903dfd2..ec01fa6db0d 100644 --- a/iceoryx_hoofs/source/relocatable_pointer/relative_pointer_data.cpp +++ b/iceoryx_hoofs/source/relocatable_pointer/relative_pointer_data.cpp @@ -15,6 +15,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/internal/relocatable_pointer/relative_pointer_data.hpp" +#include namespace iox { @@ -23,6 +24,7 @@ namespace rp // This is necessary if an supervising application needs to do a cleanup of resources hold by a crashed application. If // the size is larger than 8 bytes on a 64 bit system, torn writes happens and if the application crashes at the wrong // time, the supervisor reads corrupt data. +// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers) static_assert(sizeof(RelativePointerData) <= 8U, "The RelativePointerData size must not exceed 64 bit!"); // This ensures that the address of the RelativePointerData object is appropriately aligned to be accessed within one // CPU cycle, i.e. if the size is 8 and the alignment is 4 it could be placed at an address with modulo 4 which would @@ -49,6 +51,8 @@ RelativePointerData::id_t RelativePointerData::id() const noexcept RelativePointerData::offset_t RelativePointerData::offset() const noexcept { + // extract offset by removing id (first 16 bits) + // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers) return (m_idAndOffset >> 16) & OFFSET_RANGE; } diff --git a/iceoryx_hoofs/source/units/duration.cpp b/iceoryx_hoofs/source/units/duration.cpp index 04424ec618e..3397131cef6 100644 --- a/iceoryx_hoofs/source/units/duration.cpp +++ b/iceoryx_hoofs/source/units/duration.cpp @@ -47,7 +47,7 @@ struct timespec Duration::timespec(const TimeSpecReference& reference) const noe } else { - struct timespec referenceTime; + struct timespec referenceTime = {}; if (posix::posixCall(clock_gettime)((reference == TimeSpecReference::Epoch) ? CLOCK_REALTIME : CLOCK_MONOTONIC, &referenceTime) diff --git a/iceoryx_hoofs/test/moduletests/test_file_reader.cpp b/iceoryx_hoofs/test/moduletests/test_file_reader.cpp index f2b52b8ee17..b203cdfd3f6 100644 --- a/iceoryx_hoofs/test/moduletests/test_file_reader.cpp +++ b/iceoryx_hoofs/test/moduletests/test_file_reader.cpp @@ -79,28 +79,28 @@ class FileReader_test : public Test TEST_F(FileReader_test, openNonExisting) { iox::cxx::FileReader reader("a_file_that_wasn't_there.txt"); - EXPECT_FALSE(reader.IsOpen()); + EXPECT_FALSE(reader.isOpen()); } TEST_F(FileReader_test, openExisting) { iox::cxx::FileReader reader(TestFilePath); - EXPECT_TRUE(reader.IsOpen()); + EXPECT_TRUE(reader.isOpen()); } TEST_F(FileReader_test, openWithPath) { iox::cxx::FileReader reader(TestFile, TempPath); - EXPECT_TRUE(reader.IsOpen()); + EXPECT_TRUE(reader.isOpen()); iox::cxx::FileReader almostTheSameReader(TestFile, TempPath); - EXPECT_TRUE(almostTheSameReader.IsOpen()); + EXPECT_TRUE(almostTheSameReader.isOpen()); } TEST_F(FileReader_test, openWithWrongPath) { iox::cxx::FileReader reader(TestFile, CrapPath); - EXPECT_FALSE(reader.IsOpen()); + EXPECT_FALSE(reader.isOpen()); } TEST_F(FileReader_test, readLines) @@ -108,11 +108,11 @@ TEST_F(FileReader_test, readLines) iox::cxx::FileReader reader(TestFilePath); std::string stringLine; - bool isLineCorrect = reader.ReadLine(stringLine); + bool isLineCorrect = reader.readLine(stringLine); EXPECT_TRUE(isLineCorrect); EXPECT_EQ(stringLine.compare("This is a test file."), 0); - isLineCorrect = reader.ReadLine(stringLine); + isLineCorrect = reader.readLine(stringLine); EXPECT_TRUE(isLineCorrect); EXPECT_EQ(stringLine.compare("It consists of more than one line."), 0); } @@ -122,7 +122,7 @@ TEST_F(FileReader_test, readAllLines) iox::cxx::FileReader reader(TestFilePath); std::string stringLine; int numLines = 0; - while (reader.ReadLine(stringLine)) + while (reader.readLine(stringLine)) { ++numLines; } diff --git a/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp b/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp index 7f5c4ba9703..9140e7cabaf 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp @@ -66,7 +66,7 @@ class SignalHandler_test : public Test void registerSignal(const int signal, void (*const callback)(int)) { - struct sigaction action; + struct sigaction action = {}; sigemptyset(&action.sa_mask); action.sa_handler = callback; action.sa_flags = 0; diff --git a/iceoryx_hoofs/test/moduletests/test_posix_timer.cpp b/iceoryx_hoofs/test/moduletests/test_posix_timer.cpp index 9983f350384..ace9dfc8279 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_timer.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_timer.cpp @@ -372,7 +372,7 @@ TEST_F(Timer_test, GetOverrunsFailsWithNoCallback) TIMING_TEST_F(Timer_test, CatchUpPolicySkipToNextBeatContinuesWhenCallbackIsLongerThenTriggerTime, Repeat(5), [&] { std::atomic_bool hasTerminated{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error, const std::function, const iox::ErrorLevel) { hasTerminated = true; }); Timer sut(TIMEOUT, [] { std::this_thread::sleep_for(std::chrono::milliseconds(TIMEOUT.toMilliseconds() * 10)); }); @@ -385,7 +385,7 @@ TIMING_TEST_F(Timer_test, CatchUpPolicySkipToNextBeatContinuesWhenCallbackIsLong TIMING_TEST_F(Timer_test, CatchUpPolicyImmediateContinuesWhenCallbackIsLongerThenTriggerTime, Repeat(5), [&] { std::atomic_bool hasTerminated{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error, const std::function, const iox::ErrorLevel) { hasTerminated = true; }); Timer sut(TIMEOUT, [] { std::this_thread::sleep_for(std::chrono::milliseconds(TIMEOUT.toMilliseconds() * 10)); }); @@ -398,7 +398,7 @@ TIMING_TEST_F(Timer_test, CatchUpPolicyImmediateContinuesWhenCallbackIsLongerThe TIMING_TEST_F(Timer_test, CatchUpPolicyTerminateTerminatesWhenCallbackIsLongerThenTriggerTime, Repeat(5), [&] { std::atomic_bool hasTerminated{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error, const std::function, const iox::ErrorLevel) { hasTerminated = true; }); Timer sut(TIMEOUT, [] { std::this_thread::sleep_for(std::chrono::milliseconds(TIMEOUT.toMilliseconds() * 10)); }); @@ -411,7 +411,7 @@ TIMING_TEST_F(Timer_test, CatchUpPolicyTerminateTerminatesWhenCallbackIsLongerTh TIMING_TEST_F(Timer_test, CatchUpPolicyChangeToTerminateChangesBehaviorToTerminate, Repeat(5), [&] { std::atomic_bool hasTerminated{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error, const std::function, const iox::ErrorLevel) { hasTerminated = true; }); Timer sut(TIMEOUT, [] { std::this_thread::sleep_for(std::chrono::milliseconds(TIMEOUT.toMilliseconds() * 10)); }); diff --git a/iceoryx_posh/include/iceoryx_posh/internal/log/posh_config_logging.hpp b/iceoryx_posh/include/iceoryx_posh/internal/log/posh_config_logging.hpp index 576985b489b..3330384ba34 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/log/posh_config_logging.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/log/posh_config_logging.hpp @@ -26,15 +26,23 @@ namespace config { struct LoggingComponent { + // NOLINTNEXTLINE(readability-identifier-naming) static constexpr char Ctx[] = "POSH Config"; + // NOLINTNEXTLINE(readability-identifier-naming) static constexpr char Description[] = "Log context for the POSH configuration library."; }; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogFatal = iox::log::ffbb::LogFatal; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogError = iox::log::ffbb::LogError; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogWarn = iox::log::ffbb::LogWarn; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogInfo = iox::log::ffbb::LogInfo; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogDebug = iox::log::ffbb::LogDebug; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogVerbose = iox::log::ffbb::LogVerbose; } // namespace config diff --git a/iceoryx_posh/include/iceoryx_posh/internal/log/posh_logging.hpp b/iceoryx_posh/include/iceoryx_posh/internal/log/posh_logging.hpp index 47554247422..a5270088988 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/log/posh_logging.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/log/posh_logging.hpp @@ -24,17 +24,26 @@ namespace iox { struct LoggingComponentPosh { + // NOLINTNEXTLINE(readability-identifier-naming) static constexpr char Ctx[] = "POSH"; + // NOLINTNEXTLINE(readability-identifier-naming) static constexpr char Description[] = "Log context of the POSH component!"; }; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LoggerPosh = iox::log::ffbb::ComponentLogger; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogFatal = iox::log::ffbb::LogFatal; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogError = iox::log::ffbb::LogError; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogWarn = iox::log::ffbb::LogWarn; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogInfo = iox::log::ffbb::LogInfo; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogDebug = iox::log::ffbb::LogDebug; +// NOLINTNEXTLINE(readability-identifier-naming) static constexpr auto LogVerbose = iox::log::ffbb::LogVerbose; } // namespace iox diff --git a/iceoryx_posh/source/gateway/toml_gateway_config_parser.cpp b/iceoryx_posh/source/gateway/toml_gateway_config_parser.cpp index b42673174ce..506189f4cb1 100644 --- a/iceoryx_posh/source/gateway/toml_gateway_config_parser.cpp +++ b/iceoryx_posh/source/gateway/toml_gateway_config_parser.cpp @@ -41,7 +41,7 @@ iox::config::TomlGatewayConfigParser::parse(const roudi::ConfigFilePathString_t& /// @todo Replace with C++17 std::filesystem::exists() iox::cxx::FileReader configFile(path, "", cxx::FileReader::ErrorMode::Ignore); - if (!configFile.IsOpen()) + if (!configFile.isOpen()) { LogWarn() << "Gateway config file not found at: '" << path << "'. Falling back to built-in config."; return iox::cxx::success(config); diff --git a/iceoryx_posh/source/log/posh_logging.cpp b/iceoryx_posh/source/log/posh_logging.cpp index 28b3e98ea86..6fdf359cbde 100644 --- a/iceoryx_posh/source/log/posh_logging.cpp +++ b/iceoryx_posh/source/log/posh_logging.cpp @@ -1,4 +1,3 @@ - // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/iceoryx_posh/source/roudi/roudi.cpp b/iceoryx_posh/source/roudi/roudi.cpp index 5f36d9f320d..ce074786d4e 100644 --- a/iceoryx_posh/source/roudi/roudi.cpp +++ b/iceoryx_posh/source/roudi/roudi.cpp @@ -18,6 +18,7 @@ #include "iceoryx_posh/internal/roudi/roudi.hpp" #include "iceoryx_hoofs/cxx/convert.hpp" #include "iceoryx_hoofs/cxx/helplets.hpp" +#include "iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp" #include "iceoryx_hoofs/posix_wrapper/thread.hpp" #include "iceoryx_posh/internal/log/posh_logging.hpp" #include "iceoryx_posh/internal/runtime/node_property.hpp" @@ -212,13 +213,17 @@ void RouDi::processMessage(const runtime::IpcMessage& message, } else { - uint32_t pid; - uid_t userId; - int64_t transmissionTimestamp; + uint32_t pid{0U}; + uid_t userId{0}; + int64_t transmissionTimestamp{0}; version::VersionInfo versionInfo = parseRegisterMessage(message, pid, userId, transmissionTimestamp); - registerProcess( - runtimeName, pid, {userId}, transmissionTimestamp, getUniqueSessionIdForProcess(), versionInfo); + registerProcess(runtimeName, + pid, + iox::posix::PosixUser{userId}, + transmissionTimestamp, + getUniqueSessionIdForProcess(), + versionInfo); } break; } diff --git a/iceoryx_posh/source/roudi/roudi_config_toml_file_provider.cpp b/iceoryx_posh/source/roudi/roudi_config_toml_file_provider.cpp index d492487c9aa..5a75584d181 100644 --- a/iceoryx_posh/source/roudi/roudi_config_toml_file_provider.cpp +++ b/iceoryx_posh/source/roudi/roudi_config_toml_file_provider.cpp @@ -40,7 +40,7 @@ TomlRouDiConfigFileProvider::TomlRouDiConfigFileProvider(config::CmdLineArgs_t& /// @todo Replace with C++17 std::filesystem::exists() cxx::FileReader configFile(defaultConfigFilePath, "", cxx::FileReader::ErrorMode::Ignore); - if (configFile.IsOpen()) + if (configFile.isOpen()) { LogInfo() << "No config file provided. Using '" << defaultConfigFilePath << "'"; m_customConfigFilePath = defaultConfigFilePath; diff --git a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp index 962f95eb7fc..fcd34e694f0 100644 --- a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp +++ b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp @@ -405,7 +405,7 @@ TEST_F(Mepoo_IntegrationTest, WrongSampleSize) const int repetition3 = 1; auto errorHandlerCalled{false}; iox::Error receivedError{iox::Error::kNO_ERROR}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled, &receivedError](const iox::Error error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; @@ -427,7 +427,7 @@ TEST_F(Mepoo_IntegrationTest, SampleOverflow) const int repetition1 = 2 * DefaultNumChunks; auto errorHandlerCalled{false}; iox::Error receivedError{iox::Error::kNO_ERROR}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled, &receivedError](const iox::Error error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; diff --git a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp index c01e1e5ddd1..cdc9ad5fdaa 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_memory_manager.cpp @@ -74,7 +74,7 @@ TEST_F(MemoryManager_test, AddingMempoolNotInTheIncreasingOrderReturnsError) mempoolconf.addMemPool({CHUNK_SIZE_256, CHUNK_COUNT}); mempoolconf.addMemPool({CHUNK_SIZE_64, CHUNK_COUNT}); iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::FATAL); @@ -93,7 +93,7 @@ TEST_F(MemoryManager_test, WrongCallOfConfigureMemoryManagerReturnsError) mempoolconf.addMemPool({CHUNK_SIZE_64, CHUNK_COUNT}); sut->configureMemoryManager(mempoolconf, *allocator, *allocator); iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::FATAL); @@ -136,7 +136,7 @@ TEST_F(MemoryManager_test, GetNumberOfMemPoolsMethodReturnsTheNumberOfMemPools) TEST_F(MemoryManager_test, GetChunkMethodWithNoMemPoolInMemConfigReturnsError) { iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); @@ -163,7 +163,7 @@ TEST_F(MemoryManager_test, GetChunkMethodWithChunkSizeGreaterThanAvailableChunkS sut->configureMemoryManager(mempoolconf, *allocator, *allocator); iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); @@ -194,7 +194,7 @@ TEST_F(MemoryManager_test, GetChunkMethodWhenNoFreeChunksInMemPoolConfigReturnsE chunkStore.push_back(sut->getChunk(chunkSettings)); iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::MODERATE); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp index ca10c70c066..4823765816d 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp @@ -70,7 +70,7 @@ TEST_F(MemPool_test, MempoolCtorWhenChunkSizeIsNotAMultipleOfAlignmentReturnErro constexpr uint32_t NOT_ALLIGNED_CHUNKED_SIZE{33U}; iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::FATAL)); @@ -165,7 +165,7 @@ TEST_F(MemPool_test, FreeChunkMethodWhenSameChunkIsTriedToFreeTwiceReturnsError) chunks.push_back(reinterpret_cast(sut.getChunk())); sut.freeChunk(chunks[INDEX]); iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::FATAL)); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp index 91e58afa157..38788d12b6b 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp @@ -21,6 +21,7 @@ #include "iceoryx_hoofs/platform/fcntl.hpp" #include "iceoryx_hoofs/platform/stat.hpp" #include "iceoryx_hoofs/platform/types.hpp" +#include "iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp" #include "iceoryx_hoofs/testing/test_definitions.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/mepoo/mepoo_segment.hpp" @@ -138,7 +139,7 @@ class MePooSegment_test : public Test MePooConfig mepooConfig = setupMepooConfig(); MePooSegment sut{ - mepooConfig, m_managementAllocator, {"iox_roudi_test1"}, {"iox_roudi_test2"}}; + mepooConfig, m_managementAllocator, PosixGroup{"iox_roudi_test1"}, PosixGroup{"iox_roudi_test2"}}; }; MePooSegment_test::SharedMemoryObject_MOCK::createFct MePooSegment_test::SharedMemoryObject_MOCK::createVerificator; @@ -160,7 +161,7 @@ TEST_F(MePooSegment_test, ADD_TEST_WITH_ADDITIONAL_USER(SharedMemoryCreationPara EXPECT_THAT(openMode, Eq(iox::posix::OpenMode::PURGE_AND_CREATE)); }; MePooSegment sut2{ - mepooConfig, m_managementAllocator, {"iox_roudi_test1"}, {"iox_roudi_test2"}}; + mepooConfig, m_managementAllocator, PosixGroup{"iox_roudi_test1"}, PosixGroup{"iox_roudi_test2"}}; MePooSegment_test::SharedMemoryObject_MOCK::createVerificator = MePooSegment_test::SharedMemoryObject_MOCK::createFct(); } @@ -177,7 +178,7 @@ TEST_F(MePooSegment_test, ADD_TEST_WITH_ADDITIONAL_USER(GetSharedMemoryObject)) memorySizeInBytes = f_memorySizeInBytes; }; MePooSegment sut2{ - mepooConfig, m_managementAllocator, {"iox_roudi_test1"}, {"iox_roudi_test2"}}; + mepooConfig, m_managementAllocator, PosixGroup{"iox_roudi_test1"}, PosixGroup{"iox_roudi_test2"}}; MePooSegment_test::SharedMemoryObject_MOCK::createVerificator = MePooSegment_test::SharedMemoryObject_MOCK::createFct(); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp index 20193d02f4e..9e2696a39bf 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment_management.cpp @@ -19,6 +19,7 @@ #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp" #include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/allocator.hpp" #include "iceoryx_hoofs/internal/relocatable_pointer/base_relative_pointer.hpp" +#include "iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp" #include "iceoryx_hoofs/testing/test_definitions.hpp" #include "iceoryx_posh/internal/mepoo/memory_manager.hpp" #include "iceoryx_posh/internal/mepoo/segment_manager.hpp" @@ -128,33 +129,33 @@ class SegmentManager_test : public Test TEST_F(SegmentManager_test, ADD_TEST_WITH_ADDITIONAL_USER(getSegmentMappingsForReadUser)) { - auto mapping = sut.getSegmentMappings({"iox_roudi_test1"}); + auto mapping = sut.getSegmentMappings(PosixUser{"iox_roudi_test1"}); ASSERT_THAT(mapping.size(), Eq(1u)); EXPECT_THAT(mapping[0].m_isWritable, Eq(false)); } TEST_F(SegmentManager_test, ADD_TEST_WITH_ADDITIONAL_USER(getSegmentMappingsForWriteUser)) { - auto mapping = sut.getSegmentMappings({"iox_roudi_test2"}); + auto mapping = sut.getSegmentMappings(PosixUser{"iox_roudi_test2"}); ASSERT_THAT(mapping.size(), Eq(2u)); EXPECT_THAT(mapping[0].m_isWritable == mapping[1].m_isWritable, Eq(false)); } TEST_F(SegmentManager_test, ADD_TEST_WITH_ADDITIONAL_USER(getSegmentMappingsEmptyForNonRegisteredUser)) { - auto mapping = sut.getSegmentMappings({"roudi_test4"}); + auto mapping = sut.getSegmentMappings(PosixUser{"roudi_test4"}); ASSERT_THAT(mapping.size(), Eq(0u)); } TEST_F(SegmentManager_test, ADD_TEST_WITH_ADDITIONAL_USER(getSegmentMappingsEmptyForNonExistingUser)) { - auto mapping = sut.getSegmentMappings({"no_user"}); + auto mapping = sut.getSegmentMappings(PosixUser{"no_user"}); ASSERT_THAT(mapping.size(), Eq(0u)); } TEST_F(SegmentManager_test, ADD_TEST_WITH_ADDITIONAL_USER(getMemoryManagerForUserWithWriteUser)) { - auto memoryManager = sut.getSegmentInformationWithWriteAccessForUser({"iox_roudi_test2"}).m_memoryManager; + auto memoryManager = sut.getSegmentInformationWithWriteAccessForUser(PosixUser{"iox_roudi_test2"}).m_memoryManager; ASSERT_TRUE(memoryManager.has_value()); ASSERT_THAT(memoryManager.value().get().getNumberOfMemPools(), Eq(2u)); @@ -166,19 +167,20 @@ TEST_F(SegmentManager_test, ADD_TEST_WITH_ADDITIONAL_USER(getMemoryManagerForUse TEST_F(SegmentManager_test, ADD_TEST_WITH_ADDITIONAL_USER(getMemoryManagerForUserFailWithReadOnlyUser)) { - EXPECT_FALSE(sut.getSegmentInformationWithWriteAccessForUser({"iox_roudi_test1"}).m_memoryManager.has_value()); + EXPECT_FALSE( + sut.getSegmentInformationWithWriteAccessForUser(PosixUser{"iox_roudi_test1"}).m_memoryManager.has_value()); } TEST_F(SegmentManager_test, ADD_TEST_WITH_ADDITIONAL_USER(getMemoryManagerForUserFailWithNonExistingUser)) { - EXPECT_FALSE(sut.getSegmentInformationWithWriteAccessForUser({"no_user"}).m_memoryManager.has_value()); + EXPECT_FALSE(sut.getSegmentInformationWithWriteAccessForUser(PosixUser{"no_user"}).m_memoryManager.has_value()); } TEST_F(SegmentManager_test, ADD_TEST_WITH_ADDITIONAL_USER(addingMoreThanOneWriterGroupFails)) { auto errorHandlerCalled{false}; iox::Error receivedError{iox::Error::kNO_ERROR}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled, &receivedError](const iox::Error error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index 1b31724350e..b426693c6e2 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -150,7 +150,7 @@ TYPED_TEST(ChunkDistributor_test, QueueOverflow) typename TestFixture::ChunkDistributor_t sut(sutData.get()); auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp index 2ae556bf6b2..46cf32922e2 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_queue.cpp @@ -170,7 +170,7 @@ TYPED_TEST(ChunkQueue_test, PopChunkWithIncompatibleChunkHeaderCallsErrorHandler this->m_pusher.push(chunk); iox::Error receivedError{iox::Error::kNO_ERROR}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { receivedError = error; EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp index d5b864bd5af..4a73c666323 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_receiver.cpp @@ -196,7 +196,7 @@ TEST_F(ChunkReceiver_test, releaseInvalidChunk) } auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp index 020b75e8df4..1b20191a330 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_sender.cpp @@ -233,7 +233,7 @@ TEST_F(ChunkSender_test, freeInvalidChunk) EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -399,7 +399,7 @@ TEST_F(ChunkSender_test, sendTillRunningOutOfChunks) } auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -418,7 +418,7 @@ TEST_F(ChunkSender_test, sendInvalidChunk) EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -452,7 +452,7 @@ TEST_F(ChunkSender_test, pushInvalidChunkToHistory) EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); diff --git a/iceoryx_posh/test/moduletests/test_popo_client_port.cpp b/iceoryx_posh/test/moduletests/test_popo_client_port.cpp index 0ec7fc7bbcf..fb79ffadb20 100644 --- a/iceoryx_posh/test/moduletests/test_popo_client_port.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_client_port.cpp @@ -248,7 +248,7 @@ TEST_F(ClientPort_test, FreeRequestWithNullptrCallsErrorHandler) auto& sut = clientPortWithConnectOnCreate; iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); @@ -280,7 +280,7 @@ TEST_F(ClientPort_test, SendRequestWithNullptrOnConnectedClientPortTerminates) auto& sut = clientPortWithConnectOnCreate; iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); @@ -397,7 +397,7 @@ TEST_F(ClientPort_test, ReleaseResponseWithNullptrIsTerminating) auto& sut = clientPortWithConnectOnCreate; iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); @@ -851,7 +851,7 @@ TEST_F(ClientPort_test, InvalidStateTransitionsCallErrorHandler) } iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::SEVERE); diff --git a/iceoryx_posh/test/moduletests/test_popo_notification_info.cpp b/iceoryx_posh/test/moduletests/test_popo_notification_info.cpp index 9f70c56a1d2..2e538adb384 100644 --- a/iceoryx_posh/test/moduletests/test_popo_notification_info.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_notification_info.cpp @@ -88,7 +88,7 @@ TEST_F(NotificationInfo_test, getOriginReturnsNullptrWithWrongType) { auto errorHandlerCalled{false}; iox::Error errorHandlerType; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; @@ -104,7 +104,7 @@ TEST_F(NotificationInfo_test, constGetOriginReturnsNullptrWithWrongType) { auto errorHandlerCalled{false}; iox::Error errorHandlerType; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; diff --git a/iceoryx_posh/test/moduletests/test_popo_sample.cpp b/iceoryx_posh/test/moduletests/test_popo_sample.cpp index 9df82e5f4b4..22f4d68e1a4 100644 --- a/iceoryx_posh/test/moduletests/test_popo_sample.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_sample.cpp @@ -100,7 +100,7 @@ TEST_F(SampleTest, PublishingEmptySampleCallsErrorHandler) sut.publish(); iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::MODERATE)); diff --git a/iceoryx_posh/test/moduletests/test_popo_subscriber_port.cpp b/iceoryx_posh/test/moduletests/test_popo_subscriber_port.cpp index 6141e6a6a26..52ab4ddeca3 100644 --- a/iceoryx_posh/test/moduletests/test_popo_subscriber_port.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_subscriber_port.cpp @@ -300,7 +300,7 @@ TEST_F(SubscriberPortSingleProducer_test, NackInUnsubscribeRequestedResultsInNot TEST_F(SubscriberPortSingleProducer_test, InvalidMessageResultsInError) { auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -316,7 +316,7 @@ TEST_F(SubscriberPortSingleProducer_test, InvalidMessageResultsInError) TEST_F(SubscriberPortSingleProducer_test, AckWhenNotWaitingForResultsInError) { auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -333,7 +333,7 @@ TEST_F(SubscriberPortSingleProducer_test, NackWhenNotWaitingForResultsInError) { auto errorHandlerCalled{false}; iox::Error receivedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled, &receivedError](const iox::Error error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; @@ -508,7 +508,7 @@ TEST_F(SubscriberPortMultiProducer_test, InvalidMessageResultsInError) { auto errorHandlerCalled{false}; iox::Error receivedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled, &receivedError](const iox::Error error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; diff --git a/iceoryx_posh/test/moduletests/test_popo_trigger.cpp b/iceoryx_posh/test/moduletests/test_popo_trigger.cpp index c8ecb3153fe..67ca809a7d5 100644 --- a/iceoryx_posh/test/moduletests/test_popo_trigger.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_trigger.cpp @@ -195,7 +195,7 @@ TEST_F(Trigger_test, TriggerWithInvalidHasTriggeredCallbackCallsErrorHandlerAndI bool hasTerminated = false; iox::Error errorType = iox::Error::kNO_ERROR; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel) { hasTerminated = true; errorType = error; @@ -226,7 +226,7 @@ TEST_F(Trigger_test, TriggerWithEmptyResetCallCallsErrorHandlerAndIsInvalid) bool hasTerminated = false; iox::Error errorType = iox::Error::kNO_ERROR; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel) { hasTerminated = true; errorType = error; @@ -292,7 +292,7 @@ TEST_F(Trigger_test, TriggerWithEmptyResetInvalidatesTriggerWhenBeingResetted) constexpr uint64_t type = 0U; constexpr uint64_t typeHash = 0U; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error, const std::function, const iox::ErrorLevel) {}); Trigger sut(StateBasedTrigger, @@ -664,7 +664,7 @@ TEST_F(Trigger_test, EventBasedTriggerWithEmptyResetCallInvokesErrorHandlerAndIs bool hasTerminated = false; iox::Error errorType = iox::Error::kNO_ERROR; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&](const iox::Error error, const std::function, const iox::ErrorLevel) { hasTerminated = true; errorType = error; diff --git a/iceoryx_posh/test/moduletests/test_popo_typed_unique_id.cpp b/iceoryx_posh/test/moduletests/test_popo_typed_unique_id.cpp index f87ab698713..1ac4e4ab478 100644 --- a/iceoryx_posh/test/moduletests/test_popo_typed_unique_id.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_typed_unique_id.cpp @@ -38,7 +38,7 @@ TEST(TypedUniqueId_RouDiId, SettingTheRouDiIdTwiceFails) { uint16_t someId = 1243u; bool errorHandlerCalled = false; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error error IOX_MAYBE_UNUSED, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -53,7 +53,7 @@ TEST(TypedUniqueId_RouDiId, SettingTheRouDiIdTwiceFails) TEST(TypedUniqueId_RouDiId, GettingTheRouDiIdWithoutSettingFails) { bool errorHandlerCalled = false; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error error IOX_MAYBE_UNUSED, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); diff --git a/iceoryx_posh/test/moduletests/test_posh_runtime.cpp b/iceoryx_posh/test/moduletests/test_posh_runtime.cpp index 5127d4bc5ea..8564c6cde80 100644 --- a/iceoryx_posh/test/moduletests/test_posh_runtime.cpp +++ b/iceoryx_posh/test/moduletests/test_posh_runtime.cpp @@ -107,7 +107,7 @@ TEST(PoshRuntime, LeadingSlashAppName) auto errorHandlerCalled{false}; iox::Error receivedError{iox::Error::kNO_ERROR}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled, &receivedError](const iox::Error error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; @@ -153,7 +153,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareApplicationIsSuccessful) TEST_F(PoshRuntime_test, GetMiddlewareInterfaceWithInvalidNodeNameIsNotSuccessful) { iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); @@ -169,7 +169,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareInterfaceWithInvalidNodeNameIsNotSuccessfu TEST_F(PoshRuntime_test, GetMiddlewareApplicationApplicationlistOverflow) { auto applicationlistOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&applicationlistOverflowDetected](const iox::Error error, const std::function, const iox::ErrorLevel) { applicationlistOverflowDetected = true; EXPECT_THAT(error, Eq(iox::Error::kPORT_POOL__APPLICATIONLIST_OVERFLOW)); @@ -204,7 +204,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareInterfaceIsSuccessful) TEST_F(PoshRuntime_test, GetMiddlewareInterfaceInterfacelistOverflow) { auto interfacelistOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&interfacelistOverflowDetected](const iox::Error error, const std::function, const iox::ErrorLevel) { interfacelistOverflowDetected = true; EXPECT_THAT(error, Eq(iox::Error::kPORT_POOL__INTERFACELIST_OVERFLOW)); @@ -304,7 +304,7 @@ TEST_F(PoshRuntime_test, getMiddlewarePublisherPublisherlistOverflow) { auto publisherlistOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&publisherlistOverflowDetected](const iox::Error error, const std::function, const iox::ErrorLevel) { if (error == iox::Error::kPORT_POOL__PUBLISHERLIST_OVERFLOW) { @@ -334,7 +334,7 @@ TEST_F(PoshRuntime_test, getMiddlewarePublisherPublisherlistOverflow) TEST_F(PoshRuntime_test, GetMiddlewarePublisherWithSameServiceDescriptionsAndOneToManyPolicyFails) { auto publisherDuplicateDetected{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&publisherDuplicateDetected](const iox::Error error, const std::function, const iox::ErrorLevel) { if (error == iox::Error::kPOSH__RUNTIME_PUBLISHER_PORT_NOT_UNIQUE) { @@ -494,7 +494,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareSubscriberDefaultArgs) TEST_F(PoshRuntime_test, GetMiddlewareSubscriberSubscriberlistOverflow) { auto subscriberlistOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&subscriberlistOverflowDetected](const iox::Error error, const std::function, const iox::ErrorLevel) { if (error == iox::Error::kPORT_POOL__SUBSCRIBERLIST_OVERFLOW) { @@ -596,7 +596,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareConditionVariableIsSuccessful) TEST_F(PoshRuntime_test, GetMiddlewareConditionVariableListOverflow) { auto conditionVariableListOverflowDetected{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&conditionVariableListOverflowDetected]( const iox::Error error, const std::function, const iox::ErrorLevel) { if (error == iox::Error::kPORT_POOL__CONDITION_VARIABLE_LIST_OVERFLOW) @@ -653,7 +653,7 @@ TEST_F(PoshRuntime_test, CreatingNodeWithInvalidNameLeadsToTermination) iox::runtime::NodeProperty nodeProperty(m_invalidNodeName, nodeDeviceIdentifier); iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::SEVERE)); diff --git a/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp b/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp index 2f66fd9afe4..15cf67e0540 100644 --- a/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp +++ b/iceoryx_posh/test/moduletests/test_posh_runtime_single_process.cpp @@ -66,7 +66,7 @@ TEST_F(PoshRuntimeSingleProcess_test, ConstructorPoshRuntimeSingleProcessMultipl const RuntimeName_t m_runtimeName{"App"}; iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::FATAL)); diff --git a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp index a10f104b2ce..58c457006eb 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_iceoryx_roudi_app.cpp @@ -188,7 +188,7 @@ TEST_F(IceoryxRoudiApp_test, ConstructorCalledWithArgUniqueIdTwoTimesReturnError ASSERT_FALSE(cmdLineArgs.has_error()); iox::cxx::optional detectedError; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&detectedError](const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { detectedError.emplace(error); EXPECT_EQ(errorLevel, iox::ErrorLevel::MODERATE); diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 88d32f0034f..359ceb90e91 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -82,7 +82,7 @@ class PortManager_test : public Test EXPECT_FALSE(m_roudiMemoryManager->createAndAnnounceMemory().has_error()); m_portManager = new PortManagerTester(m_roudiMemoryManager); - auto user = iox::posix::PosixUser::getUserOfCurrentProcess().getName(); + auto user = iox::posix::PosixUser::getUserOfCurrentProcess(); auto segmentInfo = m_roudiMemoryManager->segmentManager().value()->getSegmentInformationWithWriteAccessForUser(user); ASSERT_TRUE(segmentInfo.m_memoryManager.has_value()); @@ -445,7 +445,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfPublishersFails) { // test if overflow errors get hit bool errorHandlerCalled = false; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error error IOX_MAYBE_UNUSED, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -473,7 +473,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfSubscribersFails) { // test if overflow errors get hit bool errorHandlerCalled = false; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error error IOX_MAYBE_UNUSED, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -494,7 +494,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails) // test if overflow errors get hit { auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -645,7 +645,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfApplicationsFails) // test if overflow errors get hit { auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -703,7 +703,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFa // test if overflow errors get hit { auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); @@ -773,7 +773,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails) // test if overflow errors get hit auto errorHandlerCalled{false}; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&errorHandlerCalled](const iox::Error, const std::function, const iox::ErrorLevel) { errorHandlerCalled = true; }); diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 8041a897318..f1fdd5fe018 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -81,7 +81,7 @@ TEST_F(PortPool_test, AddNodeDataWhenNodeListIsFullReturnsError) auto errorHandlerCalled{false}; Error errorHandlerType; auto errorHandlerGuard = - ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + ErrorHandler::setTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; }); @@ -192,7 +192,7 @@ TEST_F(PortPool_test, AddPublisherPortWhenPublisherListOverflowsReturnsError) auto errorHandlerCalled{false}; Error errorHandlerType; auto errorHandlerGuard = - ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + ErrorHandler::setTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; }); @@ -315,7 +315,7 @@ TEST_F(PortPool_test, AddSubscriberPortWhenSubscriberListOverflowsReturnsError) auto errorHandlerCalled{false}; Error errorHandlerType; auto errorHandlerGuard = - ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + ErrorHandler::setTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; }); @@ -400,7 +400,7 @@ TEST_F(PortPool_test, AddInterfacePortWhenInterfaceListOverflowsReturnsError) auto errorHandlerCalled{false}; Error errorHandlerType; auto errorHandlerGuard = - ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + ErrorHandler::setTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; }); @@ -477,7 +477,7 @@ TEST_F(PortPool_test, AddApplicationPortWhenApplicationListOverflowsReturnsError auto errorHandlerCalled{false}; Error errorHandlerType; auto errorHandlerGuard = - ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + ErrorHandler::setTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; }); @@ -553,7 +553,7 @@ TEST_F(PortPool_test, AddConditionVariableDataWhenContainerIsFullReturnsError) auto errorHandlerCalled{false}; Error errorHandlerType; auto errorHandlerGuard = - ErrorHandler::SetTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { + ErrorHandler::setTemporaryErrorHandler([&](const Error error, const std::function, const ErrorLevel) { errorHandlerType = error; errorHandlerCalled = true; }); diff --git a/iceoryx_posh/test/moduletests/test_roudi_process.cpp b/iceoryx_posh/test/moduletests/test_roudi_process.cpp index e1d9609dda9..0d3145e4a82 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_process.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_process.cpp @@ -90,7 +90,7 @@ TEST_F(Process_test, sendViaIpcChannelFail) iox::runtime::IpcMessage data{""}; iox::cxx::optional sendViaIpcChannelStatusFail; - auto errorHandlerGuard = iox::ErrorHandler::SetTemporaryErrorHandler( + auto errorHandlerGuard = iox::ErrorHandler::setTemporaryErrorHandler( [&sendViaIpcChannelStatusFail]( const iox::Error error, const std::function, const iox::ErrorLevel errorLevel) { sendViaIpcChannelStatusFail.emplace(error); diff --git a/iceoryx_posh/test/moduletests/test_roudi_process_manager.cpp b/iceoryx_posh/test/moduletests/test_roudi_process_manager.cpp index 0939f4b9976..0ca61906304 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_process_manager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_process_manager.cpp @@ -16,6 +16,7 @@ #include "iceoryx_hoofs/cxx/string.hpp" #include "iceoryx_hoofs/platform/types.hpp" +#include "iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/roudi/process_manager.hpp" @@ -121,7 +122,7 @@ TEST_F(ProcessManager_test, HandleProcessShutdownPreparationRequestWorks) { m_sut->registerProcess(m_processname, m_pid, m_user, m_isMonitored, 1U, 1U, m_versionInfo); - auto user = iox::posix::PosixUser::getUserOfCurrentProcess().getName(); + auto user = iox::posix::PosixUser::getUserOfCurrentProcess(); auto payloadDataSegmentMemoryManager = m_roudiMemoryManager->segmentManager() .value() ->getSegmentInformationWithWriteAccessForUser(user) diff --git a/tools/ci/run-clang-tidy.sh b/tools/ci/run-clang-tidy.sh new file mode 100755 index 00000000000..3a80790b667 --- /dev/null +++ b/tools/ci/run-clang-tidy.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# Copyright (c) 2021 by Apex.AI Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +# This script builds iceoryx_hoofs und iceoryx_posh and executes all tests + +set -e + +msg() { + printf "\033[1;32m%s: %s\033[0m\n" ${FUNCNAME[1]} "$1" +} + +WORKSPACE=$(git rev-parse --show-toplevel) +cd ${WORKSPACE} + +msg "installing build dependencies and clang-tidy-10" +sudo apt-get update && sudo apt-get install -y libacl1-dev libncurses5-dev bison clang-tidy-10 + +msg "compiler versions: +$(clang-10 --version)" + +msg "generating compile_commands.json" +CXX=clang++-10 CC=clang-10 cmake -Bbuild -Hiceoryx_meta + +# NOTE: run only for one package and do not fail. +# In the future, add more packages here and ideally fail, +# when there are violations +msg "running clang-tidy" +run-clang-tidy-10.py -quiet -p build iceoryx_hoofs