From 1e3dbb3cbb7ff933ff9f5bc9eb68e2a8487ce81a Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 1 Sep 2023 07:33:46 +0200 Subject: [PATCH 1/9] Setting infraestructure for naming threads (#3821) * Refs #19375. Added internal header for threading utilities. Signed-off-by: Miguel Company * Refs #19375. Added empty implementation for set_name_to_current_thread. Signed-off-by: Miguel Company * Refs #19375. Added name on Log thread. Signed-off-by: Miguel Company * Refs #19375. Added name on shm watchdog thread. Signed-off-by: Miguel Company * Refs #19375. Added name for filewatch threads. Signed-off-by: Miguel Company * Refs #19375. Added name on ResourceEvent threads. Signed-off-by: Miguel Company * Refs #19375. Added name on udp reception thread. Signed-off-by: Miguel Company * Refs #19375. Added name on shm reception thread. Signed-off-by: Miguel Company * Refs #19375. Added name on data-sharing reception thread. Signed-off-by: Miguel Company * Refs #19375. Added name for TCP threads. Signed-off-by: Miguel Company * Refs #19375. Added name on FlowController thread. Signed-off-by: Miguel Company * Refs #19375. Added name for SHM dump threads. Signed-off-by: Miguel Company * Refs #19375. Added initialization callback to LogTopic. Signed-off-by: Miguel Company * Refs #19375. SecurityManager refactor to receive plugin factory by dependency injection. Signed-off-by: Miguel Company * Refs #19375. Allow easy overload of creation of builtin plugins. Signed-off-by: Miguel Company * Refs #19375. RTPSParticipantImpl configures the logging thread. Signed-off-by: Miguel Company * Refs #19375. Uncrustify. Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company --- .../fastdds/rtps/resources/ResourceEvent.h | 9 ++- src/cpp/fastdds/log/Log.cpp | 3 + .../rtps/DataSharing/DataSharingListener.cpp | 3 + .../discovery/participant/PDPServer.cpp | 8 +- .../flowcontrol/FlowControllerFactory.cpp | 26 ++++--- .../flowcontrol/FlowControllerFactory.hpp | 3 + .../rtps/flowcontrol/FlowControllerImpl.hpp | 30 +++++-- .../rtps/participant/RTPSParticipantImpl.cpp | 22 +++++- .../rtps/participant/RTPSParticipantImpl.h | 6 ++ src/cpp/rtps/resources/ResourceEvent.cpp | 12 ++- .../rtps/security/ISecurityPluginFactory.h | 78 +++++++++++++++++++ src/cpp/rtps/security/SecurityManager.cpp | 18 +---- src/cpp/rtps/security/SecurityManager.h | 42 +++++----- .../rtps/security/SecurityPluginFactory.cpp | 62 ++++++++++----- src/cpp/rtps/security/SecurityPluginFactory.h | 54 +++++++------ .../rtps/transport/TCPTransportInterface.cpp | 7 +- src/cpp/rtps/transport/UDPChannelResource.cpp | 3 + .../shared_mem/SharedMemChannelResource.hpp | 6 +- .../transport/shared_mem/SharedMemLog.hpp | 8 ++ .../shared_mem/SharedMemTransport.cpp | 2 +- src/cpp/security/logging/LogTopic.cpp | 43 ++++++---- src/cpp/security/logging/LogTopic.h | 4 +- src/cpp/utils/SystemInfo.cpp | 4 + .../utils/shared_memory/SharedMemWatchdog.hpp | 4 + src/cpp/utils/threading.hpp | 34 ++++++++ src/cpp/utils/threading/threading_empty.ipp | 35 +++++++++ .../rtps/security/SecurityPluginFactory.h | 60 +++++++------- ...FlowControllerPublishModesOnAsyncTests.cpp | 2 +- ...trollerPublishModesOnLimitedAsyncTests.cpp | 2 +- ...wControllerPublishModesOnPureSyncTests.cpp | 2 +- .../FlowControllerPublishModesOnSyncTests.cpp | 2 +- .../FlowControllerSchedulersTests.cpp | 8 +- test/unittest/rtps/security/SecurityTests.hpp | 3 +- thirdparty/filewatch/FileWatch.hpp | 4 + 34 files changed, 438 insertions(+), 171 deletions(-) create mode 100644 src/cpp/rtps/security/ISecurityPluginFactory.h create mode 100644 src/cpp/utils/threading.hpp create mode 100644 src/cpp/utils/threading/threading_empty.ipp diff --git a/include/fastdds/rtps/resources/ResourceEvent.h b/include/fastdds/rtps/resources/ResourceEvent.h index e39f8b147be..3709f3ff120 100644 --- a/include/fastdds/rtps/resources/ResourceEvent.h +++ b/include/fastdds/rtps/resources/ResourceEvent.h @@ -25,8 +25,9 @@ #include #include -#include #include +#include +#include #include namespace eprosima { @@ -49,8 +50,12 @@ class ResourceEvent /*! * @brief Method to initialize the internal thread. + * + * @param[in] configure_cb Function to be called in the context of the started thread + * before calling the internal service routine. */ - void init_thread(); + void init_thread( + std::function configure_cb = {}); void stop_thread(); diff --git a/src/cpp/fastdds/log/Log.cpp b/src/cpp/fastdds/log/Log.cpp index fa568b4de37..27e37ff53b4 100644 --- a/src/cpp/fastdds/log/Log.cpp +++ b/src/cpp/fastdds/log/Log.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace eprosima { namespace fastdds { @@ -258,6 +259,8 @@ struct LogResources void run() { + set_name_to_current_thread("dds.log"); + std::unique_lock guard(cv_mutex_); while (logging_) diff --git a/src/cpp/rtps/DataSharing/DataSharingListener.cpp b/src/cpp/rtps/DataSharing/DataSharingListener.cpp index 0e4f0dbc955..a358767d317 100644 --- a/src/cpp/rtps/DataSharing/DataSharingListener.cpp +++ b/src/cpp/rtps/DataSharing/DataSharingListener.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -49,6 +50,8 @@ DataSharingListener::~DataSharingListener() void DataSharingListener::run() { + set_name_to_current_thread("dds.dsha.%u", reader_->getGuid().entityId.to_uint32() & 0x0000FFFF); + std::unique_lock lock(notification_->notification_->notification_mutex, std::defer_lock); while (is_running_.load()) { diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp index 1bd25b69c33..6e524dd8e7b 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp @@ -54,6 +54,8 @@ #include +#include + namespace eprosima { namespace fastdds { namespace rtps { @@ -160,7 +162,11 @@ bool PDPServer::init( getRTPSParticipant()->enableReader(edp->publications_reader_.first); // Initialize server dedicated thread. - resource_event_thread_.init_thread(); + uint32_t id_for_thread = static_cast(getRTPSParticipant()->getRTPSParticipantAttributes().participantID); + resource_event_thread_.init_thread([id_for_thread]() + { + set_name_to_current_thread("dds.ds_ev.%u", id_for_thread); + }); /* Given the fact that a participant is either a client or a server the diff --git a/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp b/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp index 31bd130cb2e..e1e3b9f5464 100644 --- a/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp +++ b/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp @@ -25,26 +25,26 @@ void FlowControllerFactory::init( pure_sync_flow_controller_name, std::unique_ptr( new FlowControllerImpl(participant_, nullptr)))); + FlowControllerFifoSchedule>(participant_, nullptr, 0)))); // SyncFlowController -> used by rest of besteffort writers. flow_controllers_.insert(decltype(flow_controllers_)::value_type( sync_flow_controller_name, std::unique_ptr( new FlowControllerImpl(participant_, nullptr)))); + FlowControllerFifoSchedule>(participant_, nullptr, async_controller_index_++)))); // AsyncFlowController flow_controllers_.insert(decltype(flow_controllers_)::value_type( async_flow_controller_name, std::unique_ptr( new FlowControllerImpl(participant_, nullptr)))); + FlowControllerFifoSchedule>(participant_, nullptr, async_controller_index_++)))); #ifdef FASTDDS_STATISTICS flow_controllers_.insert(decltype(flow_controllers_)::value_type( async_statistics_flow_controller_name, std::unique_ptr( new FlowControllerImpl(participant_, nullptr)))); + FlowControllerFifoSchedule>(participant_, nullptr, async_controller_index_++)))); #endif // ifndef FASTDDS_STATISTICS } @@ -67,7 +67,8 @@ void FlowControllerFactory::register_flow_controller ( flow_controller_descr.name, std::unique_ptr( new FlowControllerImpl(participant_, &flow_controller_descr)))); + FlowControllerFifoSchedule>(participant_, + &flow_controller_descr, async_controller_index_++)))); break; case FlowControllerSchedulerPolicy::ROUND_ROBIN: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -75,7 +76,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr)))); + &flow_controller_descr, async_controller_index_++)))); break; case FlowControllerSchedulerPolicy::HIGH_PRIORITY: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -83,7 +84,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr)))); + &flow_controller_descr, async_controller_index_++)))); break; case FlowControllerSchedulerPolicy::PRIORITY_WITH_RESERVATION: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -91,7 +92,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr)))); + &flow_controller_descr, async_controller_index_++)))); break; default: assert(false); @@ -106,7 +107,8 @@ void FlowControllerFactory::register_flow_controller ( flow_controller_descr.name, std::unique_ptr( new FlowControllerImpl(participant_, &flow_controller_descr)))); + FlowControllerFifoSchedule>(participant_, + &flow_controller_descr, async_controller_index_++)))); break; case FlowControllerSchedulerPolicy::ROUND_ROBIN: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -114,7 +116,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr)))); + &flow_controller_descr, async_controller_index_++)))); break; case FlowControllerSchedulerPolicy::HIGH_PRIORITY: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -122,7 +124,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr)))); + &flow_controller_descr, async_controller_index_++)))); break; case FlowControllerSchedulerPolicy::PRIORITY_WITH_RESERVATION: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -130,7 +132,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr)))); + &flow_controller_descr, async_controller_index_++)))); break; default: assert(false); diff --git a/src/cpp/rtps/flowcontrol/FlowControllerFactory.hpp b/src/cpp/rtps/flowcontrol/FlowControllerFactory.hpp index bb9dcd7e633..009ba79cb06 100644 --- a/src/cpp/rtps/flowcontrol/FlowControllerFactory.hpp +++ b/src/cpp/rtps/flowcontrol/FlowControllerFactory.hpp @@ -66,6 +66,9 @@ class FlowControllerFactory //! Stores the created flow controllers. std::map> flow_controllers_; + //! Counter used for thread identification + uint32_t async_controller_index_ = 0; + }; } // namespace rtps diff --git a/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp b/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp index 1060bd941aa..62515ed1ce7 100644 --- a/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp +++ b/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp @@ -1,12 +1,6 @@ #ifndef _RTPS_FLOWCONTROL_FLOWCONTROLLERIMPL_HPP_ #define _RTPS_FLOWCONTROL_FLOWCONTROLLERIMPL_HPP_ -#include "FlowController.hpp" -#include -#include -#include -#include - #include #include #include @@ -14,6 +8,15 @@ #include #include +#include "FlowController.hpp" +#include +#include +#include +#include + +#include +#include + namespace eprosima { namespace fastdds { namespace rtps { @@ -926,11 +929,19 @@ class FlowControllerImpl : public FlowController FlowControllerImpl( fastrtps::rtps::RTPSParticipantImpl* participant, - const FlowControllerDescriptor* descriptor + const FlowControllerDescriptor* descriptor, + uint32_t async_index ) : participant_(participant) , async_mode(participant, descriptor) + , participant_id_(0) + , async_index_(async_index) { + if (nullptr != participant) + { + participant_id_ = static_cast(participant->getRTPSParticipantAttributes().participantID); + } + uint32_t limitation = get_max_payload(); if (std::numeric_limits::max() != limitation) @@ -1328,6 +1339,8 @@ class FlowControllerImpl : public FlowController */ void run() { + set_name_to_current_thread("dds.asyn.%u.%u", participant_id_, async_index_); + while (async_mode.running) { // There are writers interested in removing a sample. @@ -1470,6 +1483,9 @@ class FlowControllerImpl : public FlowController // async_mode must be destroyed before sched. publish_mode async_mode; + + uint32_t participant_id_ = 0; + uint32_t async_index_ = 0; }; } // namespace rtps diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index 4d5ab5d69bc..7be88aad027 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -61,6 +61,11 @@ #include #include #include +#include + +#if HAVE_SECURITY +#include +#endif // HAVE_SECURITY namespace eprosima { namespace fastrtps { @@ -137,7 +142,7 @@ RTPSParticipantImpl::RTPSParticipantImpl( , internal_metatraffic_locators_(false) , internal_default_locators_(false) #if HAVE_SECURITY - , m_security_manager(this) + , m_security_manager(this, *this) #endif // if HAVE_SECURITY , mp_participantListener(plisten) , mp_userParticipant(par) @@ -239,7 +244,11 @@ RTPSParticipantImpl::RTPSParticipantImpl( } mp_userParticipant->mp_impl = this; - mp_event_thr.init_thread(); + uint32_t id_for_thread = static_cast(m_att.participantID); + mp_event_thr.init_thread([id_for_thread]() + { + set_name_to_current_thread("dds.ev.%u", id_for_thread); + }); if (!networkFactoryHasRegisteredTransports()) { @@ -2196,6 +2205,15 @@ bool RTPSParticipantImpl::is_security_enabled_for_reader( return false; } +security::Logging* RTPSParticipantImpl::create_builtin_logging_plugin() +{ + return new security::LogTopic([this]() + { + uint32_t participant_id = static_cast(m_att.participantID); + set_name_to_current_thread("dds.slog.%u", participant_id); + }); +} + #endif // if HAVE_SECURITY PDP* RTPSParticipantImpl::pdp() diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.h b/src/cpp/rtps/participant/RTPSParticipantImpl.h index c4f0bb88610..eff26d891a1 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.h +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.h @@ -59,6 +59,7 @@ #include #include #include +#include #endif // if HAVE_SECURITY namespace eprosima { @@ -106,6 +107,9 @@ class WLP; */ class RTPSParticipantImpl : public fastdds::statistics::StatisticsParticipantImpl +#if HAVE_SECURITY + , private security::SecurityPluginFactory +#endif // if HAVE_SECURITY { /* Receiver Control block is a struct we use to encapsulate the resources that take part in message reception. @@ -398,6 +402,8 @@ class RTPSParticipantImpl bool is_security_enabled_for_reader( const ReaderAttributes& reader_attributes); + security::Logging* create_builtin_logging_plugin() override; + #endif // if HAVE_SECURITY PDPSimple* pdpsimple(); diff --git a/src/cpp/rtps/resources/ResourceEvent.cpp b/src/cpp/rtps/resources/ResourceEvent.cpp index 82acd562dcb..d5f58eb0a81 100644 --- a/src/cpp/rtps/resources/ResourceEvent.cpp +++ b/src/cpp/rtps/resources/ResourceEvent.cpp @@ -303,7 +303,8 @@ void ResourceEvent::do_timer_actions() } } -void ResourceEvent::init_thread() +void ResourceEvent::init_thread( + std::function configure_cb) { std::lock_guard lock(mutex_); @@ -311,7 +312,14 @@ void ResourceEvent::init_thread() stop_.store(false); resize_collections(); - thread_ = std::thread(&ResourceEvent::event_service, this); + thread_ = std::thread([this, configure_cb]() + { + if (configure_cb) + { + configure_cb(); + } + event_service(); + }); } } /* namespace rtps */ diff --git a/src/cpp/rtps/security/ISecurityPluginFactory.h b/src/cpp/rtps/security/ISecurityPluginFactory.h new file mode 100644 index 00000000000..8dd30280616 --- /dev/null +++ b/src/cpp/rtps/security/ISecurityPluginFactory.h @@ -0,0 +1,78 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/*! + * @file ISecurityPluginFactory.h + */ +#ifndef _RTPS_SECURITY_ISECURITYPLUGINFACTORY_H_ +#define _RTPS_SECURITY_ISECURITYPLUGINFACTORY_H_ + +#include +#include +#include +#include +#include + +namespace eprosima { +namespace fastrtps { +namespace rtps { +namespace security { + +class ISecurityPluginFactory +{ +public: + + /*! + * @brief Create an Authentication plugin described in the PropertyPolicy. + * @param property_policy PropertyPolicy containing the definition of the Authentication + * plugin that has to be created. + * @param Pointer to the new Authentication plugin. In case of error nullptr will be returned. + */ + virtual Authentication* create_authentication_plugin( + const PropertyPolicy& property_policy) = 0; + + /*! + * @brief Create an AccessControl plugin described in the PropertyPolicy. + * @param property_policy PropertyPolicy containing the definition of the AccessControl + * plugin that has to be created. + * @param Pointer to the new AccessControl plugin. In case of error nullptr will be returned. + */ + virtual AccessControl* create_access_control_plugin( + const PropertyPolicy& property_policy) = 0; + + /*! + * @brief Create an Cryptographic plugin described in the PropertyPolicy. + * @param property_policy PropertyPolicy containing the definition of the Cryptographic + * plugin that has to be created. + * @param Pointer to the new Cryptographic plugin. In case of error nullptr will be returned. + */ + virtual Cryptography* create_cryptography_plugin( + const PropertyPolicy& property_policy) = 0; + + /** + * @brief Create a Logging plugin described in the PropertyPolicy. + * @param property_policy PropertyPolicy containing the definition of the Logging + * plugin that has to be created. + * @return Pointer to the new Logging plugin. In case of error nullptr will be returned. + */ + virtual Logging* create_logging_plugin( + const PropertyPolicy& property_policy) = 0; +}; + +} //namespace security +} //namespace rtps +} //namespace fastrtps +} //namespace eprosima + +#endif // _RTPS_SECURITY_SECURITYPLUGINFACTORY_H_ diff --git a/src/cpp/rtps/security/SecurityManager.cpp b/src/cpp/rtps/security/SecurityManager.cpp index 604ce8de011..e769af97f8f 100644 --- a/src/cpp/rtps/security/SecurityManager.cpp +++ b/src/cpp/rtps/security/SecurityManager.cpp @@ -74,25 +74,13 @@ inline bool usleep_bool() } SecurityManager::SecurityManager( - RTPSParticipantImpl* participant) + RTPSParticipantImpl* participant, + ISecurityPluginFactory& plugin_factory) : participant_stateless_message_listener_(*this) , participant_volatile_message_secure_listener_(*this) , participant_(participant) - , participant_stateless_message_writer_(nullptr) - , participant_stateless_message_writer_history_(nullptr) - , participant_stateless_message_reader_(nullptr) - , participant_stateless_message_reader_history_(nullptr) - , participant_volatile_message_secure_writer_(nullptr) - , participant_volatile_message_secure_writer_history_(nullptr) - , participant_volatile_message_secure_reader_(nullptr) - , participant_volatile_message_secure_reader_history_(nullptr) - , logging_plugin_(nullptr) - , authentication_plugin_(nullptr) - , access_plugin_(nullptr) - , crypto_plugin_(nullptr) + , factory_(plugin_factory) , domain_id_(0) - , local_identity_handle_(nullptr) - , local_permissions_handle_(nullptr) , auth_last_sequence_number_(1) , crypto_last_sequence_number_(1) , temp_reader_proxies_({ diff --git a/src/cpp/rtps/security/SecurityManager.h b/src/cpp/rtps/security/SecurityManager.h index 26eeb984c98..dbd6410cd7f 100644 --- a/src/cpp/rtps/security/SecurityManager.h +++ b/src/cpp/rtps/security/SecurityManager.h @@ -18,7 +18,7 @@ #ifndef _RTPS_SECURITY_SECURITYMANAGER_H_ #define _RTPS_SECURITY_SECURITYMANAGER_H_ -#include +#include #include #include @@ -75,7 +75,8 @@ class SecurityManager * @param participant RTPSParticipantImpl* references the associated participant */ SecurityManager( - RTPSParticipantImpl* participant); + RTPSParticipantImpl* participant, + ISecurityPluginFactory& plugin_factory); // @brief Destructor ~SecurityManager(); @@ -769,30 +770,27 @@ class SecurityManager const ParticipantProxyData& participant_data, const SecurityException& exception) const; - RTPSParticipantImpl* participant_; - StatelessWriter* participant_stateless_message_writer_; - WriterHistory* participant_stateless_message_writer_history_; - StatelessReader* participant_stateless_message_reader_; - ReaderHistory* participant_stateless_message_reader_history_; - StatefulWriter* participant_volatile_message_secure_writer_; - WriterHistory* participant_volatile_message_secure_writer_history_; - StatefulReader* participant_volatile_message_secure_reader_; - ReaderHistory* participant_volatile_message_secure_reader_history_; - SecurityPluginFactory factory_; + RTPSParticipantImpl* participant_ = nullptr; + StatelessWriter* participant_stateless_message_writer_ = nullptr; + WriterHistory* participant_stateless_message_writer_history_ = nullptr; + StatelessReader* participant_stateless_message_reader_ = nullptr; + ReaderHistory* participant_stateless_message_reader_history_ = nullptr; + StatefulWriter* participant_volatile_message_secure_writer_ = nullptr; + WriterHistory* participant_volatile_message_secure_writer_history_ = nullptr; + StatefulReader* participant_volatile_message_secure_reader_ = nullptr; + ReaderHistory* participant_volatile_message_secure_reader_history_ = nullptr; + ISecurityPluginFactory& factory_; - Logging* logging_plugin_; + Logging* logging_plugin_ = nullptr; + Authentication* authentication_plugin_ = nullptr; + AccessControl* access_plugin_ = nullptr; + Cryptography* crypto_plugin_ = nullptr; - Authentication* authentication_plugin_; + uint32_t domain_id_ = 0; - AccessControl* access_plugin_; + IdentityHandle* local_identity_handle_ = nullptr; - Cryptography* crypto_plugin_; - - uint32_t domain_id_; - - IdentityHandle* local_identity_handle_; - - PermissionsHandle* local_permissions_handle_; + PermissionsHandle* local_permissions_handle_ = nullptr; std::shared_ptr local_participant_crypto_handle_; diff --git a/src/cpp/rtps/security/SecurityPluginFactory.cpp b/src/cpp/rtps/security/SecurityPluginFactory.cpp index 8ac864bd9c4..c5f07d83878 100644 --- a/src/cpp/rtps/security/SecurityPluginFactory.cpp +++ b/src/cpp/rtps/security/SecurityPluginFactory.cpp @@ -25,71 +25,95 @@ using namespace eprosima::fastrtps::rtps; using namespace eprosima::fastrtps::rtps::security; -Authentication* SecurityPluginFactory::create_authentication_plugin(const PropertyPolicy& property_policy) +Authentication* SecurityPluginFactory::create_authentication_plugin( + const PropertyPolicy& property_policy) { Authentication* plugin = nullptr; const std::string* auth_plugin_property = PropertyPolicyHelper::find_property(property_policy, - "dds.sec.auth.plugin"); + "dds.sec.auth.plugin"); - if(auth_plugin_property != nullptr) + if (auth_plugin_property != nullptr) { - if(auth_plugin_property->compare("builtin.PKI-DH") == 0) + if (auth_plugin_property->compare("builtin.PKI-DH") == 0) { - plugin = new PKIDH(); + plugin = create_builtin_authentication_plugin(); } } return plugin; } -AccessControl* SecurityPluginFactory::create_access_control_plugin(const PropertyPolicy& property_policy) +AccessControl* SecurityPluginFactory::create_access_control_plugin( + const PropertyPolicy& property_policy) { AccessControl* plugin = nullptr; const std::string* access_plugin_property = PropertyPolicyHelper::find_property(property_policy, - "dds.sec.access.plugin"); + "dds.sec.access.plugin"); - if(access_plugin_property != nullptr) + if (access_plugin_property != nullptr) { - if(access_plugin_property->compare("builtin.Access-Permissions") == 0) + if (access_plugin_property->compare("builtin.Access-Permissions") == 0) { - plugin = new Permissions(); + plugin = create_builtin_access_control_plugin(); } } return plugin; } -Cryptography* SecurityPluginFactory::create_cryptography_plugin(const PropertyPolicy& property_policy) +Cryptography* SecurityPluginFactory::create_cryptography_plugin( + const PropertyPolicy& property_policy) { Cryptography* plugin = nullptr; const std::string* crypto_plugin_property = PropertyPolicyHelper::find_property(property_policy, - "dds.sec.crypto.plugin"); + "dds.sec.crypto.plugin"); - if(crypto_plugin_property != nullptr) + if (crypto_plugin_property != nullptr) { // Check it is builtin DDS:Auth:PKI-DH. - if(crypto_plugin_property->compare("builtin.AES-GCM-GMAC") == 0) + if (crypto_plugin_property->compare("builtin.AES-GCM-GMAC") == 0) { - plugin = new AESGCMGMAC(); + plugin = create_builtin_cryptography_plugin(); } } return plugin; } -Logging* SecurityPluginFactory::create_logging_plugin(const PropertyPolicy& property_policy) +Logging* SecurityPluginFactory::create_logging_plugin( + const PropertyPolicy& property_policy) { Logging* plugin = nullptr; const std::string* logging_plugin_property = PropertyPolicyHelper::find_property(property_policy, "dds.sec.log.plugin"); - if(logging_plugin_property != nullptr) + if (logging_plugin_property != nullptr) { - if(logging_plugin_property->compare("builtin.DDS_LogTopic") == 0) + if (logging_plugin_property->compare("builtin.DDS_LogTopic") == 0) { - plugin = new LogTopic(); + plugin = create_builtin_logging_plugin(); } } return plugin; } + +Authentication* SecurityPluginFactory::create_builtin_authentication_plugin() +{ + return new PKIDH(); +} + +AccessControl* SecurityPluginFactory::create_builtin_access_control_plugin() +{ + return new Permissions(); +} + +Cryptography* SecurityPluginFactory::create_builtin_cryptography_plugin() +{ + return new AESGCMGMAC(); +} + +Logging* SecurityPluginFactory::create_builtin_logging_plugin() +{ + return new LogTopic(); +} diff --git a/src/cpp/rtps/security/SecurityPluginFactory.h b/src/cpp/rtps/security/SecurityPluginFactory.h index 41cb02f4ec3..772f867c8d4 100644 --- a/src/cpp/rtps/security/SecurityPluginFactory.h +++ b/src/cpp/rtps/security/SecurityPluginFactory.h @@ -24,40 +24,38 @@ #include #include +#include + namespace eprosima { namespace fastrtps { namespace rtps { namespace security { -class SecurityPluginFactory +class SecurityPluginFactory : public ISecurityPluginFactory { - public: - - /*! - * @brief Create an Authentication plugin described in the PropertyPolicy. - * @param property_policy PropertyPolicy containing the definition of the Authentication - * plugin that has to be created. - * @param Pointer to the new Authentication plugin. In case of error nullptr will be returned. - */ - Authentication* create_authentication_plugin(const PropertyPolicy& property_policy); - - AccessControl* create_access_control_plugin(const PropertyPolicy& property_policy); - - /*! - * @brief Create an Cryptographic plugin described in the PropertyPolicy. - * @param property_policy PropertyPolicy containing the definition of the Cryptographic - * plugin that has to be created. - * @param Pointer to the new Cryptographic plugin. In case of error nullptr will be returned. - */ - Cryptography* create_cryptography_plugin(const PropertyPolicy& property_policy); - - /** - * @brief Create a loggin plugin described in the PropertyPolicy. - * @param property_policy PropertyPolicy containing the definition of the Logging - * plugin that has to be created. - * @return Pointer to the new Logging plugin. In case of error nullptr will be returned. - */ - Logging* create_logging_plugin(const PropertyPolicy& property_policy); +public: + + Authentication* create_authentication_plugin( + const PropertyPolicy& property_policy) override; + + AccessControl* create_access_control_plugin( + const PropertyPolicy& property_policy) override; + + Cryptography* create_cryptography_plugin( + const PropertyPolicy& property_policy) override; + + Logging* create_logging_plugin( + const PropertyPolicy& property_policy) override; + +protected: + + virtual Authentication* create_builtin_authentication_plugin(); + + virtual AccessControl* create_builtin_access_control_plugin(); + + virtual Cryptography* create_builtin_cryptography_plugin(); + + virtual Logging* create_builtin_logging_plugin(); }; } //namespace security diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index f375da66701..2df9d257208 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -34,6 +34,7 @@ #endif // if TLS_FOUND #include #include +#include using namespace std; using namespace asio; @@ -418,6 +419,7 @@ bool TCPTransportInterface::init( auto ioServiceFunction = [&]() { + set_name_to_current_thread("dds.tcp_accept"); #if ASIO_VERSION >= 101200 asio::executor_work_guard work(io_service_.get_executor()); #else @@ -431,7 +433,7 @@ bool TCPTransportInterface::init( { io_service_timers_thread_ = std::make_shared([&]() { - + set_name_to_current_thread("dds.tcp_keep"); #if ASIO_VERSION >= 101200 asio::executor_work_guard work(io_service_timers_. get_executor()); @@ -818,6 +820,9 @@ void TCPTransportInterface::perform_listen_operation( if (channel) { + uint32_t port = channel->local_endpoint().port(); + set_name_to_current_thread("dds.tcp.%u", port); + if (channel->tcp_connection_type() == TCPChannelResource::TCPConnectionType::TCP_CONNECT_TYPE) { rtcp_message_manager->sendConnectionRequest(channel); diff --git a/src/cpp/rtps/transport/UDPChannelResource.cpp b/src/cpp/rtps/transport/UDPChannelResource.cpp index b68594909e1..62904444c7c 100644 --- a/src/cpp/rtps/transport/UDPChannelResource.cpp +++ b/src/cpp/rtps/transport/UDPChannelResource.cpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace eprosima { namespace fastdds { @@ -53,6 +54,8 @@ UDPChannelResource::~UDPChannelResource() void UDPChannelResource::perform_listen_operation( Locator input_locator) { + set_name_to_current_thread("dds.udp.%u", input_locator.port); + Locator remote_locator; while (alive()) diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemChannelResource.hpp b/src/cpp/rtps/transport/shared_mem/SharedMemChannelResource.hpp index c4e6c7951e0..da7a95e5122 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemChannelResource.hpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemChannelResource.hpp @@ -22,6 +22,8 @@ #include #include +#include + namespace eprosima { namespace fastdds { namespace rtps { @@ -49,7 +51,7 @@ class SharedMemChannelResource : public ChannelResource auto packets_file_consumer = std::unique_ptr( new SHMPacketFileConsumer(dump_file)); - packet_logger_ = std::make_shared>(); + packet_logger_ = std::make_shared>(locator.port); packet_logger_->RegisterConsumer(std::move(packets_file_consumer)); } @@ -123,6 +125,8 @@ class SharedMemChannelResource : public ChannelResource void perform_listen_operation( Locator input_locator) { + set_name_to_current_thread("dds.shm.%u", input_locator.port); + Locator remote_locator; while (alive()) diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp b/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp index 90a6af29297..893fef62e0e 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp @@ -199,6 +199,12 @@ class PacketsLog { public: + PacketsLog( + uint32_t thread_id) + : thread_id_(thread_id) + { + } + ~PacketsLog() { Flush(); @@ -349,9 +355,11 @@ class PacketsLog }; Resources resources_; + uint32_t thread_id_; void run() { + set_name_to_current_thread("dds.shmd.%u", thread_id_); std::unique_lock guard(resources_.cv_mutex); while (resources_.logging) diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp b/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp index c138b88f88f..00095d1f9a7 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp @@ -290,7 +290,7 @@ bool SharedMemTransport::init( auto packets_file_consumer = std::unique_ptr( new SHMPacketFileConsumer(configuration_.rtps_dump_file())); - packet_logger_ = std::make_shared>(); + packet_logger_ = std::make_shared>(0); packet_logger_->RegisterConsumer(std::move(packets_file_consumer)); } } diff --git a/src/cpp/security/logging/LogTopic.cpp b/src/cpp/security/logging/LogTopic.cpp index 88214bc6a12..b461cc9fc7e 100644 --- a/src/cpp/security/logging/LogTopic.cpp +++ b/src/cpp/security/logging/LogTopic.cpp @@ -3,32 +3,41 @@ #include #include +#include + namespace eprosima { namespace fastrtps { namespace rtps { namespace security { -LogTopic::LogTopic() +LogTopic::LogTopic( + std::function thread_init_cb) : stop_(false) - , thread_([this]() { - for (;;) - { - // Put the thread asleep until there is - // something to process - auto p = queue_.wait_pop(); + , thread_([this, thread_init_cb]() + { + if (thread_init_cb) + { + thread_init_cb(); + } + + while (true) + { + // Put the thread asleep until there is + // something to process + auto p = queue_.wait_pop(); - if (!p) + if (!p) + { + if (stop_) { - if (stop_) - { - return; - } - continue; + return; } - - publish(*p); + continue; } - }) + + publish(*p); + } + }) { // } @@ -68,7 +77,7 @@ bool LogTopic::enable_logging_impl( { file_stream_.open(options.log_file, std::ios::out | std::ios::app); - if ( (file_stream_.rdstate() & std::ofstream::failbit ) != 0 ) + if ((file_stream_.rdstate() & std::ofstream::failbit ) != 0 ) { exception = SecurityException("Error opening file: " + options.log_file); return false; diff --git a/src/cpp/security/logging/LogTopic.h b/src/cpp/security/logging/LogTopic.h index bd75ce735da..47ebcd9be7e 100644 --- a/src/cpp/security/logging/LogTopic.h +++ b/src/cpp/security/logging/LogTopic.h @@ -25,6 +25,7 @@ #include #include +#include #include namespace eprosima { @@ -41,7 +42,8 @@ class LogTopic final : public Logging public: - LogTopic(); + LogTopic( + std::function thread_init_cb = {}); ~LogTopic(); private: diff --git a/src/cpp/utils/SystemInfo.cpp b/src/cpp/utils/SystemInfo.cpp index 63b63a4bbc0..ac231d43743 100644 --- a/src/cpp/utils/SystemInfo.cpp +++ b/src/cpp/utils/SystemInfo.cpp @@ -35,6 +35,7 @@ #include #include +#include namespace eprosima { @@ -275,3 +276,6 @@ std::string SystemInfo::get_timestamp( std::string SystemInfo::environment_file_; } // eprosima + +// threading.hpp implementations +#include "threading/threading_empty.ipp" diff --git a/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp b/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp index 347d0c5dad3..e77c3131fad 100644 --- a/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp +++ b/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp @@ -22,6 +22,8 @@ #include #include +#include + namespace eprosima { namespace fastdds { namespace rtps { @@ -121,6 +123,8 @@ class SharedMemWatchdog void run() { + set_name_to_current_thread("dds.shm.wdog"); + while (!exit_thread_) { { diff --git a/src/cpp/utils/threading.hpp b/src/cpp/utils/threading.hpp new file mode 100644 index 00000000000..974fff639ad --- /dev/null +++ b/src/cpp/utils/threading.hpp @@ -0,0 +1,34 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +#ifndef UTILS__THREADING_HPP_ +#define UTILS__THREADING_HPP_ + +namespace eprosima { + +void set_name_to_current_thread( + const char* name); + +void set_name_to_current_thread( + const char* fmt, + uint32_t arg); + +void set_name_to_current_thread( + const char* fmt, + uint32_t arg1, + uint32_t arg2); + +} // eprosima + +#endif // UTILS__THREADING_HPP_ diff --git a/src/cpp/utils/threading/threading_empty.ipp b/src/cpp/utils/threading/threading_empty.ipp new file mode 100644 index 00000000000..30d97890bca --- /dev/null +++ b/src/cpp/utils/threading/threading_empty.ipp @@ -0,0 +1,35 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +namespace eprosima { + +void set_name_to_current_thread( + const char* /* name */) +{ +} + +void set_name_to_current_thread( + const char* /* fmt */, + uint32_t /* arg */) +{ +} + +void set_name_to_current_thread( + const char* /* fmt */, + uint32_t /* arg1 */, + uint32_t /* arg2 */) +{ +} + +} // namespace eprosima diff --git a/test/mock/rtps/SecurityPluginFactory/rtps/security/SecurityPluginFactory.h b/test/mock/rtps/SecurityPluginFactory/rtps/security/SecurityPluginFactory.h index e175d8d5ccd..74fe9e1b46d 100644 --- a/test/mock/rtps/SecurityPluginFactory/rtps/security/SecurityPluginFactory.h +++ b/test/mock/rtps/SecurityPluginFactory/rtps/security/SecurityPluginFactory.h @@ -24,60 +24,58 @@ #include #include +#include + namespace eprosima { namespace fastrtps { namespace rtps { namespace security { -class SecurityPluginFactory +class SecurityPluginFactory : public ISecurityPluginFactory { - public: +public: - /*! - * @brief Create an Authentication plugin described in the PropertyPolicy. - * @param property_policy PropertyPolicy containing the definition of the Authentication - * plugin that has to be created. - * @param Pointer to the new Authentication plugin. In case of error nullptr will be returned. - */ - Authentication* create_authentication_plugin(const PropertyPolicy& property_policy); + Authentication* create_authentication_plugin( + const PropertyPolicy& property_policy) override; - AccessControl* create_access_control_plugin(const PropertyPolicy& property_policy); + AccessControl* create_access_control_plugin( + const PropertyPolicy& property_policy) override; - /*! - * @brief Create an Cryptography plugin described in the PropertyPolicy. - * @param property_policy PropertyPolicy containing the definition of the Cryptography - * plugin that has to be created. - * @param Pointer to the new Cryptography plugin. In case of error nullptr will be returned. - */ - Cryptography* create_cryptography_plugin(const PropertyPolicy& property_policy); + Cryptography* create_cryptography_plugin( + const PropertyPolicy& property_policy) override; - Logging* create_logging_plugin(const PropertyPolicy& property_policy); + Logging* create_logging_plugin( + const PropertyPolicy& property_policy) override; - static void set_auth_plugin(Authentication* plugin); + static void set_auth_plugin( + Authentication* plugin); - static void release_auth_plugin(); + static void release_auth_plugin(); - static void set_access_control_plugin(AccessControl* plugin); + static void set_access_control_plugin( + AccessControl* plugin); - static void release_access_control_plugin(); + static void release_access_control_plugin(); - static void set_crypto_plugin(Cryptography* plugin); + static void set_crypto_plugin( + Cryptography* plugin); - static void release_crypto_plugin(); + static void release_crypto_plugin(); - static void set_logging_plugin(Logging* plugin); + static void set_logging_plugin( + Logging* plugin); - static void release_logging_plugin(); + static void release_logging_plugin(); - private: +private: - static Authentication* auth_plugin_; + static Authentication* auth_plugin_; - static AccessControl* access_plugin_; + static AccessControl* access_plugin_; - static Cryptography* crypto_plugin_; + static Cryptography* crypto_plugin_; - static Logging* logging_plugin_; + static Logging* logging_plugin_; }; } //namespace security diff --git a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnAsyncTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnAsyncTests.cpp index a29e881cfde..801d753830f 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnAsyncTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnAsyncTests.cpp @@ -7,7 +7,7 @@ TYPED_TEST(FlowControllerPublishModes, async_publish_mode) { FlowControllerDescriptor flow_controller_descr; FlowControllerImpl async(nullptr, - &flow_controller_descr); + &flow_controller_descr, 0); async.init(); // Instantiate writers. diff --git a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnLimitedAsyncTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnLimitedAsyncTests.cpp index 75eb1b9264e..a95e6144ec6 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnLimitedAsyncTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnLimitedAsyncTests.cpp @@ -28,7 +28,7 @@ TYPED_TEST(FlowControllerPublishModes, limited_async_publish_mode) flow_controller_descr.max_bytes_per_period = 10200; flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr); + &flow_controller_descr, 0); async.init(); // Instantiate writers. diff --git a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnPureSyncTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnPureSyncTests.cpp index 73a08987d95..b06ff64d6a1 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnPureSyncTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnPureSyncTests.cpp @@ -7,7 +7,7 @@ TYPED_TEST(FlowControllerPublishModes, pure_sync_publish_mode) { FlowControllerDescriptor flow_controller_descr; FlowControllerImpl pure_sync(nullptr, - &flow_controller_descr); + &flow_controller_descr, 0); pure_sync.init(); // Initialize callback to get info. diff --git a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnSyncTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnSyncTests.cpp index 3a805c0946a..8c64e3940c7 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnSyncTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnSyncTests.cpp @@ -7,7 +7,7 @@ TYPED_TEST(FlowControllerPublishModes, sync_publish_mode) { FlowControllerDescriptor flow_controller_descr; FlowControllerImpl sync(nullptr, - &flow_controller_descr); + &flow_controller_descr, 0); sync.init(); // Instantiate writers. diff --git a/test/unittest/rtps/flowcontrol/FlowControllerSchedulersTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerSchedulersTests.cpp index 7ffe0ba2bab..2b83a4cd886 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerSchedulersTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerSchedulersTests.cpp @@ -90,7 +90,7 @@ TEST_F(FlowControllerSchedulers, Fifo) flow_controller_descr.max_bytes_per_period = 10200; flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr); + &flow_controller_descr, 0); async.init(); // Instantiate writers. @@ -691,7 +691,7 @@ TEST_F(FlowControllerSchedulers, RoundRobin) flow_controller_descr.max_bytes_per_period = 10200; flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr); + &flow_controller_descr, 0); async.init(); // Instantiate writers. @@ -1292,7 +1292,7 @@ TEST_F(FlowControllerSchedulers, HighPriority) flow_controller_descr.max_bytes_per_period = 10200; flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr); + &flow_controller_descr, 0); async.init(); // Instantiate writers. @@ -1916,7 +1916,7 @@ TEST_F(FlowControllerSchedulers, PriorityWithReservation) flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr); + &flow_controller_descr, 0); async.init(); // Instantiate writers. diff --git a/test/unittest/rtps/security/SecurityTests.hpp b/test/unittest/rtps/security/SecurityTests.hpp index 2a9910a2c9c..3ac17a5076a 100644 --- a/test/unittest/rtps/security/SecurityTests.hpp +++ b/test/unittest/rtps/security/SecurityTests.hpp @@ -137,7 +137,7 @@ class SecurityTest : public ::testing::Test , stateless_reader_(nullptr) , volatile_writer_(nullptr) , volatile_reader_(nullptr) - , manager_(&participant_) + , manager_(&participant_, plugin_factory_) , participant_data_(c_default_RTPSParticipantAllocationAttributes) , default_cdr_message(RTPSMESSAGE_DEFAULT_SIZE) { @@ -162,6 +162,7 @@ class SecurityTest : public ::testing::Test ::testing::NiceMock* volatile_writer_; ::testing::NiceMock* volatile_reader_; PDP pdp_; + SecurityPluginFactory plugin_factory_; SecurityManager manager_; // handles diff --git a/thirdparty/filewatch/FileWatch.hpp b/thirdparty/filewatch/FileWatch.hpp index b2909226f0e..a714d284953 100644 --- a/thirdparty/filewatch/FileWatch.hpp +++ b/thirdparty/filewatch/FileWatch.hpp @@ -23,6 +23,8 @@ #ifndef FILEWATCHER_H #define FILEWATCHER_H +#include + #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #define stat _stat @@ -209,6 +211,7 @@ namespace filewatch { #endif // WIN32 _callback_thread = std::move(std::thread([this]() { try { + eprosima::set_name_to_current_thread("dds.fwatch.cb"); callback_thread(); } catch (...) { try { @@ -219,6 +222,7 @@ namespace filewatch { })); _watch_thread = std::move(std::thread([this]() { try { + eprosima::set_name_to_current_thread("dds.fwatch"); monitor_directory(); } catch (...) { try { From 50c07872ff61c19ba8cf19f6fd77bc229bff0c0f Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 4 Sep 2023 07:33:02 +0200 Subject: [PATCH 2/9] Platform implementations for set_name_to_current_thread (#3823) * Refs #17492. Added pthread implementation for set_name_to_current_thread Signed-off-by: Miguel Company * Refs #17492. Added implementation for Windows. Signed-off-by: Miguel Company * Refs #17492. Added implementation for Mac. Signed-off-by: Miguel Company * Refs #17492. Added doxygen to threading.hpp Signed-off-by: Miguel Company * Refs #17492. Using pthread implementation for Android. Signed-off-by: Miguel Company * Refs #17492. Fix build error on snprintf. Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company --- src/cpp/utils/SystemInfo.cpp | 8 +++ src/cpp/utils/threading.hpp | 26 +++++++++ src/cpp/utils/threading/threading_osx.ipp | 51 +++++++++++++++++ src/cpp/utils/threading/threading_pthread.ipp | 52 +++++++++++++++++ src/cpp/utils/threading/threading_win32.ipp | 56 +++++++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 src/cpp/utils/threading/threading_osx.ipp create mode 100644 src/cpp/utils/threading/threading_pthread.ipp create mode 100644 src/cpp/utils/threading/threading_win32.ipp diff --git a/src/cpp/utils/SystemInfo.cpp b/src/cpp/utils/SystemInfo.cpp index ac231d43743..74fd688ba51 100644 --- a/src/cpp/utils/SystemInfo.cpp +++ b/src/cpp/utils/SystemInfo.cpp @@ -278,4 +278,12 @@ std::string SystemInfo::environment_file_; } // eprosima // threading.hpp implementations +#ifdef _WIN32 +#include "threading/threading_win32.ipp" +#elif defined(__APPLE__) +#include "threading/threading_osx.ipp" +#elif defined(_POSIX_SOURCE) || defined(__QNXNTO__) || defined(__ANDROID__) +#include "threading/threading_pthread.ipp" +#else #include "threading/threading_empty.ipp" +#endif // Platform selection diff --git a/src/cpp/utils/threading.hpp b/src/cpp/utils/threading.hpp index 974fff639ad..dc28df06dc7 100644 --- a/src/cpp/utils/threading.hpp +++ b/src/cpp/utils/threading.hpp @@ -17,13 +17,39 @@ namespace eprosima { +/** + * @brief Give a name to the thread calling this function. + * + * @param[in] name A null-terminated string with the name to give to the calling thread. + * The implementation for certain platforms may truncate the final thread + * name if there is a limit on the length of the name of a thread. + */ void set_name_to_current_thread( const char* name); +/** + * @brief Give a name to the thread calling this function. + * + * @param[in] fmt A null-terminated string to be used as the format argument of + * a `snprintf` like function, in order to accomodate the restrictions of + * the OS. Those restrictions may truncate the final thread name if there + * is a limit on the length of the name of a thread. + * @param[in] arg Single variadic argument passed to the formatting function. + */ void set_name_to_current_thread( const char* fmt, uint32_t arg); +/** + * @brief Give a name to the thread calling this function. + * + * @param[in] fmt A null-terminated string to be used as the format argument of + * a `snprintf` like function, in order to accomodate the restrictions of + * the OS. Those restrictions may truncate the final thread name if there + * is a limit on the length of the name of a thread. + * @param[in] arg1 First variadic argument passed to the formatting function. + * @param[in] arg2 Second variadic argument passed to the formatting function. + */ void set_name_to_current_thread( const char* fmt, uint32_t arg1, diff --git a/src/cpp/utils/threading/threading_osx.ipp b/src/cpp/utils/threading/threading_osx.ipp new file mode 100644 index 00000000000..efb215bd99b --- /dev/null +++ b/src/cpp/utils/threading/threading_osx.ipp @@ -0,0 +1,51 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +namespace eprosima { + +template +static void set_name_to_current_thread_impl( + const char* fmt, Args... args) +{ + char thread_name[16]{}; + snprintf(thread_name, 16, fmt, args...); + pthread_setname_np(thread_name); +} + +void set_name_to_current_thread( + const char* name) +{ + set_name_to_current_thread_impl("%s", name); +} + +void set_name_to_current_thread( + const char* fmt, + uint32_t arg) +{ + set_name_to_current_thread_impl(fmt, arg); +} + +void set_name_to_current_thread( + const char* fmt, + uint32_t arg1, + uint32_t arg2) +{ + set_name_to_current_thread_impl(fmt, arg1, arg2); +} + +} // namespace eprosima diff --git a/src/cpp/utils/threading/threading_pthread.ipp b/src/cpp/utils/threading/threading_pthread.ipp new file mode 100644 index 00000000000..1090d9939c0 --- /dev/null +++ b/src/cpp/utils/threading/threading_pthread.ipp @@ -0,0 +1,52 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +namespace eprosima { + +template +static void set_name_to_current_thread_impl( + const char* fmt, Args... args) +{ + char thread_name[16]{}; + snprintf(thread_name, 16, fmt, args...); + auto id = pthread_self(); + pthread_setname_np(id, thread_name); +} + +void set_name_to_current_thread( + const char* name) +{ + set_name_to_current_thread_impl("%s", name); +} + +void set_name_to_current_thread( + const char* fmt, + uint32_t arg) +{ + set_name_to_current_thread_impl(fmt, arg); +} + +void set_name_to_current_thread( + const char* fmt, + uint32_t arg1, + uint32_t arg2) +{ + set_name_to_current_thread_impl(fmt, arg1, arg2); +} + +} // namespace eprosima diff --git a/src/cpp/utils/threading/threading_win32.ipp b/src/cpp/utils/threading/threading_win32.ipp new file mode 100644 index 00000000000..1a9f683bd0f --- /dev/null +++ b/src/cpp/utils/threading/threading_win32.ipp @@ -0,0 +1,56 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +namespace eprosima { + +template +static void set_name_to_current_thread_impl( + const char* fmt, Args... args) +{ + char thread_name[16]{}; + snprintf(thread_name, 16, fmt, args...); + + std::wstringstream stream; + stream << thread_name; + std::wstring w_thread_name = stream.str(); + + SetThreadDescription(GetCurrentThread(), w_thread_name.c_str()); +} + +void set_name_to_current_thread( + const char* name) +{ + set_name_to_current_thread_impl("%s", name); +} + +void set_name_to_current_thread( + const char* fmt, + uint32_t arg) +{ + set_name_to_current_thread_impl(fmt, arg); +} + +void set_name_to_current_thread( + const char* fmt, + uint32_t arg1, + uint32_t arg2) +{ + set_name_to_current_thread_impl(fmt, arg1, arg2); +} + +} // namespace eprosima From 2e317a340e61f4f4553c94fdc00062162763037d Mon Sep 17 00:00:00 2001 From: Eduardo Ponz Segrelles Date: Wed, 27 Sep 2023 07:16:41 +0200 Subject: [PATCH 3/9] Add ThreadSettings to Qos (#3848) * Refs #19377: Add ThreadSettings struct Signed-off-by: Eduardo Ponz * Refs #19377: Add ThreadSetting to Log API Signed-off-by: Eduardo Ponz * Refs #19377: Add ThreadSetting to DomainParticipantFactoryQos Signed-off-by: Eduardo Ponz * Refs #19377: Add ThreadSetting to DomainParticipantQos Signed-off-by: Eduardo Ponz * Refs #19377: Add ThreadSetting to TransportConfigQos Signed-off-by: Eduardo Ponz * Refs #19377: Add ThreadSetting to TransportDescriptorInterface Signed-off-by: Eduardo Ponz * Refs #19377: Add ThreadSetting to SharedMemTransportDescriptor Signed-off-by: Eduardo Ponz * Refs #19377: Add ThreadSetting to FlowControllerDescriptor Signed-off-by: Eduardo Ponz * Refs #19377: Add ThreadSetting to DataReaderQos Signed-off-by: Eduardo Ponz * Refs #19377: Add ThreadSetting to DomainParticipantQos for builtin flow controllers Signed-off-by: Eduardo Ponz * Refs #19377: Address Miguel's comments in DomainParticipant Signed-off-by: EduPonz * Refs #19377: Address Miguel's comments in DataReader Signed-off-by: EduPonz * Refs #19377: Address Miguel's comments in ParticipantTests Signed-off-by: EduPonz * Refs #19377: Address Miguel's comments in QosConverters Signed-off-by: EduPonz * Refs #19377: Address Miguel's comments in Transport descriptors Signed-off-by: EduPonz * Refs #19377: Address Miguel's comments in DataReaderTests Signed-off-by: EduPonz * Refs #19377: Address Miguel's comments in RTPSParticipantAttibutes Signed-off-by: EduPonz * Refs #19377: Address Miguel's comments in PortBasedTransportDescriptor Signed-off-by: EduPonz * Refs #19377: Add builtin_controllers_sender_thread to UpdatableDomainParticipantQos Signed-off-by: EduPonz * Refs #19377: Refactor PortBasedTransportDescriptor accessors Signed-off-by: EduPonz * Refs #19377: Add TCP related thread settings Signed-off-by: EduPonz * Refs #19377: Add data_sharing_listener_thread to ReaderAttributes Signed-off-by: EduPonz * Refs #19377: Fix windows warning Signed-off-by: EduPonz --------- Signed-off-by: Eduardo Ponz Signed-off-by: EduPonz --- .../fastdds/dds/core/policy/QosPolicies.hpp | 11 +- .../qos/DomainParticipantFactoryQos.hpp | 76 ++++- .../dds/domain/qos/DomainParticipantQos.hpp | 150 ++++++++- include/fastdds/dds/log/Log.hpp | 12 +- .../dds/subscriber/qos/DataReaderQos.hpp | 44 ++- .../attributes/RTPSParticipantAttributes.h | 25 +- .../rtps/attributes/ReaderAttributes.h | 9 +- .../rtps/attributes/ThreadSettings.hpp | 107 +++++++ .../flowcontrol/FlowControllerDescriptor.hpp | 6 + .../PortBasedTransportDescriptor.hpp | 113 +++++++ .../transport/SocketTransportDescriptor.h | 22 +- .../rtps/transport/TCPTransportDescriptor.h | 13 +- .../transport/TransportDescriptorInterface.h | 25 +- .../shared_mem/SharedMemTransportDescriptor.h | 24 +- src/cpp/CMakeLists.txt | 22 +- .../fastdds/domain/DomainParticipantImpl.cpp | 26 ++ src/cpp/fastdds/log/Log.cpp | 14 + src/cpp/fastdds/subscriber/DataReaderImpl.cpp | 10 +- src/cpp/fastdds/utils/QosConverters.cpp | 12 + src/cpp/rtps/attributes/ThreadSettings.cpp | 32 ++ .../flowcontrol/FlowControllerFactory.cpp | 33 +- .../rtps/flowcontrol/FlowControllerImpl.hpp | 9 +- .../PortBasedTransportDescriptor.cpp | 84 ++++++ .../rtps/transport/TCPTransportInterface.cpp | 58 +++- .../SharedMemTransportDescriptor.cpp | 11 +- .../shared_mem/SharedMemTransportDescriptor.h | 6 +- test/unittest/CMakeLists.txt | 1 + .../dds/participant/ParticipantTests.cpp | 26 +- test/unittest/dds/publisher/CMakeLists.txt | 38 +-- test/unittest/dds/status/CMakeLists.txt | 20 +- .../dds/subscriber/DataReaderTests.cpp | 102 +++++++ test/unittest/dynamic_types/CMakeLists.txt | 17 +- test/unittest/rtps/attributes/CMakeLists.txt | 47 +++ .../rtps/attributes/ThreadSettingsTests.cpp | 149 +++++++++ .../FlowControllerFactoryTests.cpp | 16 +- ...FlowControllerPublishModesOnAsyncTests.cpp | 18 +- ...trollerPublishModesOnLimitedAsyncTests.cpp | 18 +- ...wControllerPublishModesOnPureSyncTests.cpp | 18 +- .../FlowControllerPublishModesOnSyncTests.cpp | 18 +- .../FlowControllerSchedulersTests.cpp | 28 +- test/unittest/rtps/network/CMakeLists.txt | 40 +-- test/unittest/statistics/dds/CMakeLists.txt | 41 +-- test/unittest/transport/CMakeLists.txt | 163 ++++++---- .../PortBasedTransportDescriptorTests.cpp | 285 ++++++++++++++++++ test/unittest/xmlparser/CMakeLists.txt | 148 ++++----- 45 files changed, 1837 insertions(+), 310 deletions(-) create mode 100644 include/fastdds/rtps/attributes/ThreadSettings.hpp create mode 100644 include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp create mode 100644 src/cpp/rtps/attributes/ThreadSettings.cpp create mode 100644 src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp create mode 100644 test/unittest/rtps/attributes/CMakeLists.txt create mode 100644 test/unittest/rtps/attributes/ThreadSettingsTests.cpp create mode 100644 test/unittest/transport/PortBasedTransportDescriptorTests.cpp diff --git a/include/fastdds/dds/core/policy/QosPolicies.hpp b/include/fastdds/dds/core/policy/QosPolicies.hpp index 3c4341fd5b5..964cfaae070 100644 --- a/include/fastdds/dds/core/policy/QosPolicies.hpp +++ b/include/fastdds/dds/core/policy/QosPolicies.hpp @@ -23,17 +23,16 @@ #include #include - #include #include #include #include +#include #include -#include #include -#include +#include #include - +#include #include #include @@ -2763,6 +2762,7 @@ class TransportConfigQos : public QosPolicy (this->use_builtin_transports == b.use_builtin_transports) && (this->send_socket_buffer_size == b.send_socket_buffer_size) && (this->listen_socket_buffer_size == b.listen_socket_buffer_size) && + (this->builtin_transports_reception_threads_ == b.builtin_transports_reception_threads_) && QosPolicy::operator ==(b); } @@ -2788,6 +2788,9 @@ class TransportConfigQos : public QosPolicy * By default, 0. */ uint32_t listen_socket_buffer_size; + + //! Thread settings for the builtin transports reception threads + rtps::ThreadSettings builtin_transports_reception_threads_; }; //! Qos Policy to configure the endpoint diff --git a/include/fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp b/include/fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp index c5562c1c462..27a49ac6819 100644 --- a/include/fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp +++ b/include/fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp @@ -20,8 +20,9 @@ #ifndef _FASTDDS_PARTICIPANTFACTORYQOS_HPP_ #define _FASTDDS_PARTICIPANTFACTORYQOS_HPP_ -#include #include +#include +#include namespace eprosima { namespace fastdds { @@ -53,7 +54,9 @@ class DomainParticipantFactoryQos bool operator ==( const DomainParticipantFactoryQos& b) const { - return (this->entity_factory_ == b.entity_factory()); + return (this->shm_watchdog_thread_ == b.shm_watchdog_thread()) && + (this->file_watch_threads_ == b.file_watch_threads()) && + (this->entity_factory_ == b.entity_factory()); } /** @@ -84,10 +87,79 @@ class DomainParticipantFactoryQos entity_factory_ = entity_factory; } + /** + * Getter for SHM watchdog ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + rtps::ThreadSettings& shm_watchdog_thread() + { + return shm_watchdog_thread_; + } + + /** + * Getter for SHM watchdog ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + const rtps::ThreadSettings& shm_watchdog_thread() const + { + return shm_watchdog_thread_; + } + + /** + * Setter for the SHM watchdog ThreadSettings + * + * @param value New ThreadSettings to be set + */ + void shm_watchdog_thread( + const rtps::ThreadSettings& value) + { + shm_watchdog_thread_ = value; + } + + /** + * Getter for file watch related ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + rtps::ThreadSettings& file_watch_threads() + { + return file_watch_threads_; + } + + /** + * Getter for file watch related ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + const rtps::ThreadSettings& file_watch_threads() const + { + return file_watch_threads_; + } + + /** + * Setter for the file watch related ThreadSettings + * + * @param value New ThreadSettings to be set + */ + void file_watch_threads( + const rtps::ThreadSettings& value) + { + file_watch_threads_ = value; + } + private: //!EntityFactoryQosPolicy, implemented in the library. EntityFactoryQosPolicy entity_factory_; + + //! Thread settings for the SHM watchdog thread + rtps::ThreadSettings shm_watchdog_thread_; + + //! Thread settings for the file watch related threads + rtps::ThreadSettings file_watch_threads_; + }; } /* namespace dds */ diff --git a/include/fastdds/dds/domain/qos/DomainParticipantQos.hpp b/include/fastdds/dds/domain/qos/DomainParticipantQos.hpp index 0f040b583d7..f2b1b8e1206 100644 --- a/include/fastdds/dds/domain/qos/DomainParticipantQos.hpp +++ b/include/fastdds/dds/domain/qos/DomainParticipantQos.hpp @@ -22,9 +22,10 @@ #include -#include #include +#include #include +#include namespace eprosima { namespace fastdds { @@ -81,6 +82,12 @@ class DomainParticipantQos (this->wire_protocol_ == b.wire_protocol()) && (this->transport_ == b.transport()) && (this->name_ == b.name()) && + (this->builtin_controllers_sender_thread_ == b.builtin_controllers_sender_thread()) && + (this->timed_events_thread_ == b.timed_events_thread()) && + (this->discovery_server_thread_ == b.discovery_server_thread()) && +#if HAVE_SECURITY + (this->security_log_thread_ == b.security_log_thread()) && +#endif // if HAVE_SECURITY (this->flow_controllers_ == b.flow_controllers()); } @@ -321,6 +328,133 @@ class DomainParticipantQos return flow_controllers_; } + /** + * Getter for builtin flow controllers sender threads ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + rtps::ThreadSettings& builtin_controllers_sender_thread() + { + return builtin_controllers_sender_thread_; + } + + /** + * Getter for builtin flow controllers sender threads ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + const rtps::ThreadSettings& builtin_controllers_sender_thread() const + { + return builtin_controllers_sender_thread_; + } + + /** + * Setter for the builtin flow controllers sender threads ThreadSettings + * + * @param value New ThreadSettings to be set + */ + void builtin_controllers_sender_thread( + const rtps::ThreadSettings& value) + { + builtin_controllers_sender_thread_ = value; + } + + /** + * Getter for timed event ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + rtps::ThreadSettings& timed_events_thread() + { + return timed_events_thread_; + } + + /** + * Getter for timed event ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + const rtps::ThreadSettings& timed_events_thread() const + { + return timed_events_thread_; + } + + /** + * Setter for the timed event ThreadSettings + * + * @param value New ThreadSettings to be set + */ + void timed_events_thread( + const rtps::ThreadSettings& value) + { + timed_events_thread_ = value; + } + + /** + * Getter for discovery server ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + rtps::ThreadSettings& discovery_server_thread() + { + return discovery_server_thread_; + } + + /** + * Getter for discovery server ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + const rtps::ThreadSettings& discovery_server_thread() const + { + return discovery_server_thread_; + } + + /** + * Setter for the discovery server ThreadSettings + * + * @param value New ThreadSettings to be set + */ + void discovery_server_thread( + const rtps::ThreadSettings& value) + { + discovery_server_thread_ = value; + } + +#if HAVE_SECURITY + /** + * Getter for security log ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + rtps::ThreadSettings& security_log_thread() + { + return security_log_thread_; + } + + /** + * Getter for security log ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + const rtps::ThreadSettings& security_log_thread() const + { + return security_log_thread_; + } + + /** + * Setter for the security log ThreadSettings + * + * @param value New ThreadSettings to be set + */ + void security_log_thread( + const rtps::ThreadSettings& value) + { + security_log_thread_ = value; + } + +#endif // if HAVE_SECURITY + private: //!UserData Qos, implemented in the library. @@ -350,6 +484,20 @@ class DomainParticipantQos */ FlowControllerDescriptorList flow_controllers_; + //! Thread settings for the builtin flow controllers sender threads + rtps::ThreadSettings builtin_controllers_sender_thread_; + + //! Thread settings for the timed events thread + rtps::ThreadSettings timed_events_thread_; + + //! Thread settings for the discovery server thread + rtps::ThreadSettings discovery_server_thread_; + +#if HAVE_SECURITY + //! Thread settings for the security log thread + rtps::ThreadSettings security_log_thread_; +#endif // if HAVE_SECURITY + }; RTPS_DllAPI extern const DomainParticipantQos PARTICIPANT_QOS_DEFAULT; diff --git a/include/fastdds/dds/log/Log.hpp b/include/fastdds/dds/log/Log.hpp index 1cc524ff9cb..1bbbd3bf4bc 100644 --- a/include/fastdds/dds/log/Log.hpp +++ b/include/fastdds/dds/log/Log.hpp @@ -15,11 +15,13 @@ #ifndef _FASTDDS_DDS_LOG_LOG_HPP_ #define _FASTDDS_DDS_LOG_LOG_HPP_ -#include -#include -#include #include #include +#include +#include + +#include +#include /** * eProsima log layer. Logging categories and verbosity can be specified dynamically at runtime. @@ -131,6 +133,10 @@ class Log RTPS_DllAPI static void SetErrorStringFilter( const std::regex&); + //! Sets thread configuration for the logging thread. + RTPS_DllAPI static void SetThreadConfig( + const rtps::ThreadSettings&); + //! Returns the logging engine to configuration defaults. RTPS_DllAPI static void Reset(); diff --git a/include/fastdds/dds/subscriber/qos/DataReaderQos.hpp b/include/fastdds/dds/subscriber/qos/DataReaderQos.hpp index 87a80a2764f..046babaf8b7 100644 --- a/include/fastdds/dds/subscriber/qos/DataReaderQos.hpp +++ b/include/fastdds/dds/subscriber/qos/DataReaderQos.hpp @@ -21,13 +21,13 @@ #define _FASTDDS_DATAREADERQOS_HPP #include +#include #include #include -#include - #include +#include #include - +#include namespace eprosima { namespace fastdds { @@ -208,7 +208,8 @@ class DataReaderQos (properties_ == b.properties()) && (endpoint_ == b.endpoint()) && (reader_resource_limits_ == b.reader_resource_limits()) && - (data_sharing_ == b.data_sharing()); + (data_sharing_ == b.data_sharing()) && + (data_sharing_listener_thread_ == b.data_sharing_listener_thread()); } RTPS_DllAPI ReaderQos get_readerqos( @@ -855,6 +856,37 @@ class DataReaderQos data_sharing_ = data_sharing; } + /** + * Getter for data sharing listener ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + RTPS_DllAPI rtps::ThreadSettings& data_sharing_listener_thread() + { + return data_sharing_listener_thread_; + } + + /** + * Getter for data sharing listener ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + RTPS_DllAPI const rtps::ThreadSettings& data_sharing_listener_thread() const + { + return data_sharing_listener_thread_; + } + + /** + * Setter for data sharing listener ThreadSettings + * + * @param data_sharing_listener_thread new value for the rtps::ThreadSettings + */ + RTPS_DllAPI void data_sharing_listener_thread( + const rtps::ThreadSettings& data_sharing_listener_thread) + { + data_sharing_listener_thread_ = data_sharing_listener_thread; + } + private: //!Durability Qos, implemented in the library. @@ -893,7 +925,6 @@ class DataReaderQos //!Reader Data Lifecycle Qos, NOT implemented in the library. ReaderDataLifecycleQosPolicy reader_data_lifecycle_; - //!Lifespan Qos (Extension). LifespanQosPolicy lifespan_; @@ -920,6 +951,9 @@ class DataReaderQos //!DataSharing configuration (Extension) DataSharingQosPolicy data_sharing_; + + //! Thread settings for the data-sharing listener thread + rtps::ThreadSettings data_sharing_listener_thread_; }; RTPS_DllAPI extern const DataReaderQos DATAREADER_QOS_DEFAULT; diff --git a/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h b/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h index b6ce937ccdf..ea73277ca7a 100644 --- a/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h +++ b/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h @@ -19,10 +19,14 @@ #ifndef _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ #define _FASTDDS_RTPSPARTICIPANTPARAMETERS_H_ +#include +#include + #include #include #include #include +#include #include #include #include @@ -31,11 +35,9 @@ #include #include #include +#include #include -#include -#include - namespace eprosima { namespace fastdds { @@ -484,7 +486,8 @@ class RTPSParticipantAttributes (this->useBuiltinTransports == b.useBuiltinTransports) && (this->properties == b.properties) && (this->prefix == b.prefix) && - (this->flow_controllers == b.flow_controllers); + (this->flow_controllers == b.flow_controllers) && + (this->builtin_controllers_sender_thread == b.builtin_controllers_sender_thread); } /** @@ -576,6 +579,20 @@ class RTPSParticipantAttributes //! Flow controllers. FlowControllerDescriptorList flow_controllers; + //! Thread settings for the builtin flow controllers sender threads + fastdds::rtps::ThreadSettings builtin_controllers_sender_thread; + + //! Thread settings for the timed events thread + fastdds::rtps::ThreadSettings timed_events_thread; + + //! Thread settings for the discovery server thread + fastdds::rtps::ThreadSettings discovery_server_thread; + +#if HAVE_SECURITY + //! Thread settings for the security log thread + fastdds::rtps::ThreadSettings security_log_thread; +#endif // if HAVE_SECURITY + private: //! Name of the participant. diff --git a/include/fastdds/rtps/attributes/ReaderAttributes.h b/include/fastdds/rtps/attributes/ReaderAttributes.h index d7431f057b5..890623425eb 100644 --- a/include/fastdds/rtps/attributes/ReaderAttributes.h +++ b/include/fastdds/rtps/attributes/ReaderAttributes.h @@ -20,14 +20,12 @@ #ifndef _FASTDDS_RTPS_ATTRIBUTES_READERATTRIBUTES_H_ #define _FASTDDS_RTPS_ATTRIBUTES_READERATTRIBUTES_H_ -#include -#include #include +#include +#include #include #include -#include - namespace eprosima { namespace fastrtps { namespace rtps { @@ -106,6 +104,9 @@ class ReaderAttributes //! Define the allocation behaviour for matched-writer-dependent collections. ResourceLimitedContainerConfig matched_writers_allocation; + + //! Thread settings for the data-sharing listener thread + fastdds::rtps::ThreadSettings data_sharing_listener_thread; }; } /* namespace rtps */ diff --git a/include/fastdds/rtps/attributes/ThreadSettings.hpp b/include/fastdds/rtps/attributes/ThreadSettings.hpp new file mode 100644 index 00000000000..bd6c9ad34ae --- /dev/null +++ b/include/fastdds/rtps/attributes/ThreadSettings.hpp @@ -0,0 +1,107 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/** + * @file ThreadSettings.hpp + */ + +#include + +#include + +#ifndef _FASTDDS_THREADSETTINGS_HPP_ +#define _FASTDDS_THREADSETTINGS_HPP_ + +namespace eprosima { +namespace fastdds { +namespace rtps { + +/** + * Struct ThreadSettings to specify various thread settings. + * This class is used to define attributes across a wide set of Qos and APIs. + * @ingroup RTPS_ATTRIBUTES_MODULE + */ +struct RTPS_DllAPI ThreadSettings +{ + /** + * @brief The scheduling policy used for this thread. + * + * Configures the scheduling policy used for the thread. + * A value of -1 indicates system default. + * + * This value is platform specific and it is used as-is to configure the specific platform thread. + * Setting this value to something other than the default one may require different privileges + * on different platforms. + */ + int32_t scheduling_policy = -1; + + /** + * @brief The thread's priority. + * + * Configures the thread's priority. + * A value of 0 indicates system default. + * + * This value is platform specific and it is used as-is to configure the specific platform thread. + * Setting this value to something other than the default one may require different privileges + * on different platforms. + */ + int32_t priority = 0; + + /** + * @brief The thread's core affinity. + * + * cpu_mask is a bit mask for setting the threads affinity to each core individually. + * A value of 0 indicates no particular affinity. + * + * This value is platform specific and it is used as-is to configure the specific platform thread. + * Setting this value to something other than the default one may require different privileges + * on different platforms. + */ + uint32_t cpu_mask = 0; + + /** + * @brief The thread's stack size in bytes. + * + * Configures the thread's stack size. + * A value of -1 indicates system default. + * + * This value is platform specific and it is used as-is to configure the specific platform thread. + * Setting this value to something other than the default one may require different privileges + * on different platforms. + */ + int32_t stack_size = -1; + + /** + * Compare the left hand side (LHS) ThreadSetting with another one for equality. + * + * @param rhs The ThreadSettings instance to compare with the LHS one. + */ + bool operator ==( + const ThreadSettings& rhs) const; + + /** + * Compare the left hand side (LHS) ThreadSetting with another one for inequality. + * + * @param rhs The ThreadSettings instance to compare with the LHS one. + */ + bool operator !=( + const ThreadSettings& rhs) const; + +}; + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +#endif /* _FASTDDS_THREADSETTINGS_HPP_ */ diff --git a/include/fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp b/include/fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp index 8e5c489eb74..35873f7f994 100644 --- a/include/fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp +++ b/include/fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp @@ -15,6 +15,8 @@ #ifndef FASTDDS_RTPS_FLOWCONTROL_FLOWCONTROLLERDESCRIPTOR_HPP #define FASTDDS_RTPS_FLOWCONTROL_FLOWCONTROLLERDESCRIPTOR_HPP +#include + #include "FlowControllerConsts.hpp" #include "FlowControllerSchedulerPolicy.hpp" @@ -50,6 +52,10 @@ struct FlowControllerDescriptor //! Period of time on which the flow controller is allowed to send max_bytes_per_period. //! Default value: 100ms. uint64_t period_ms = 100; + + //! Thread settings for the sender thread + ThreadSettings sender_thread; + }; } // namespace rtps diff --git a/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp b/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp new file mode 100644 index 00000000000..e34002ac0a5 --- /dev/null +++ b/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp @@ -0,0 +1,113 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +#ifndef _FASTDDS_PORT_BASED_TRANSPORT_DESCRIPTOR_H_ +#define _FASTDDS_PORT_BASED_TRANSPORT_DESCRIPTOR_H_ + +#include +#include + +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + +/** + * Base class for all port based transport descriptors + * + * This class provides a common thread settings configuration for all + * port based transport descriptor implementations + * + * @ingroup TRANSPORT_MODULE + */ +class PortBasedTransportDescriptor : public TransportDescriptorInterface +{ +public: + + using ReceptionThreadsConfigMap = std::map; + + //! Constructor + RTPS_DllAPI PortBasedTransportDescriptor( + uint32_t maximumMessageSize, + uint32_t maximumInitialPeersRange); + + //! Copy constructor + RTPS_DllAPI PortBasedTransportDescriptor( + const PortBasedTransportDescriptor& t) = default; + + //! Copy assignment + RTPS_DllAPI PortBasedTransportDescriptor& operator =( + const PortBasedTransportDescriptor& t) = default; + + //! Destructor + virtual RTPS_DllAPI ~PortBasedTransportDescriptor() = default; + + //! Comparison operator + bool RTPS_DllAPI operator ==( + const PortBasedTransportDescriptor& t) const; + + /** + * @brief Get the ThreadSettings for a specific port + * + * This function first looks for the port-specific ThreadSettings in the user-configured + * reception threads map, i.e. the collection of ThreadSettings returned by @ref reception_threads(). + * If the ThreadSettings are found within said map, then @ref get_thread_config_for_port(uint32_t) returns them; + * else it returns the default reception thread settings, i.e. the ThreadSettings returned by + * @ref default_reception_threads(). + * + * @warning This function will return the default reception thread ThreadSettings when called with a non-default, + * non-user-configured port. + * + * @param port The port to which the returned ThreadSetting apply. + * + * @return The ThreadSettings for the given port. + */ + virtual RTPS_DllAPI const ThreadSettings& get_thread_config_for_port( + uint32_t port); + + virtual RTPS_DllAPI bool set_thread_config_for_port( + const uint32_t& port, + const ThreadSettings& thread_settings); + + //! Returns the ThreadSettings for the default reception threads + RTPS_DllAPI const ThreadSettings& default_reception_threads() const; + + //! Set the ThreadSettings for the default reception threads + virtual RTPS_DllAPI void default_reception_threads( + const ThreadSettings& default_reception_threads); + + //! Returns the ThreadSettings for the user-configured reception threads + RTPS_DllAPI const ReceptionThreadsConfigMap& reception_threads() const; + + //! Set the ThreadSettings for the user-configured reception threads + virtual RTPS_DllAPI bool reception_threads( + const ReceptionThreadsConfigMap& reception_threads); + +protected: + + //! Thread settings for the default reception threads + ThreadSettings default_reception_threads_; + + //! Thread settings for the specific reception threads, indexed by port + ReceptionThreadsConfigMap reception_threads_; +}; + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +#endif // ifndef _FASTDDS_PORT_BASED_TRANSPORT_DESCRIPTOR_H_ diff --git a/include/fastdds/rtps/transport/SocketTransportDescriptor.h b/include/fastdds/rtps/transport/SocketTransportDescriptor.h index 2ca5cb4d62f..0b03eabdb23 100644 --- a/include/fastdds/rtps/transport/SocketTransportDescriptor.h +++ b/include/fastdds/rtps/transport/SocketTransportDescriptor.h @@ -15,12 +15,12 @@ #ifndef _FASTDDS_SOCKET_TRANSPORT_DESCRIPTOR_H_ #define _FASTDDS_SOCKET_TRANSPORT_DESCRIPTOR_H_ -#include - #include #include #include +#include + namespace eprosima { namespace fastdds { namespace rtps { @@ -41,13 +41,13 @@ constexpr uint8_t s_defaultTTL = 1; * * @ingroup RTPS_MODULE * */ -struct SocketTransportDescriptor : public TransportDescriptorInterface +struct SocketTransportDescriptor : public PortBasedTransportDescriptor { //! Constructor - SocketTransportDescriptor( + RTPS_DllAPI SocketTransportDescriptor( uint32_t maximumMessageSize, uint32_t maximumInitialPeersRange) - : TransportDescriptorInterface(maximumMessageSize, maximumInitialPeersRange) + : PortBasedTransportDescriptor(maximumMessageSize, maximumInitialPeersRange) , sendBufferSize(0) , receiveBufferSize(0) , TTL(s_defaultTTL) @@ -55,30 +55,30 @@ struct SocketTransportDescriptor : public TransportDescriptorInterface } //! Copy constructor - SocketTransportDescriptor( + RTPS_DllAPI SocketTransportDescriptor( const SocketTransportDescriptor& t) = default; //! Copy assignment - SocketTransportDescriptor& operator =( + RTPS_DllAPI SocketTransportDescriptor& operator =( const SocketTransportDescriptor& t) = default; //! Destructor - virtual ~SocketTransportDescriptor() = default; + virtual RTPS_DllAPI ~SocketTransportDescriptor() = default; - virtual uint32_t min_send_buffer_size() const override + virtual RTPS_DllAPI uint32_t min_send_buffer_size() const override { return sendBufferSize; } //! Comparison operator - bool operator ==( + bool RTPS_DllAPI operator ==( const SocketTransportDescriptor& t) const { return (this->sendBufferSize == t.min_send_buffer_size() && this->receiveBufferSize == t.receiveBufferSize && this->interfaceWhiteList == t.interfaceWhiteList && this->TTL == t.TTL && - TransportDescriptorInterface::operator ==(t)); + PortBasedTransportDescriptor::operator ==(t)); } //! Length of the send buffer. diff --git a/include/fastdds/rtps/transport/TCPTransportDescriptor.h b/include/fastdds/rtps/transport/TCPTransportDescriptor.h index 43b7737b019..013441ef90a 100644 --- a/include/fastdds/rtps/transport/TCPTransportDescriptor.h +++ b/include/fastdds/rtps/transport/TCPTransportDescriptor.h @@ -15,9 +15,14 @@ #ifndef _FASTDDS_TCP_TRANSPORT_DESCRIPTOR_H_ #define _FASTDDS_TCP_TRANSPORT_DESCRIPTOR_H_ +#include +#include +#include +#include + +#include #include #include -#include namespace eprosima { namespace fastdds { @@ -265,6 +270,12 @@ struct TCPTransportDescriptor : public SocketTransportDescriptor //! Configuration of the TLS (Transport Layer Security) TLSConfig tls_config; + //! Thread settings for keep alive thread + ThreadSettings keep_alive_thread; + + //! Thread settings for the accept connections thread + ThreadSettings accept_thread; + //! Add listener port to the listening_ports list void add_listener_port( uint16_t port) diff --git a/include/fastdds/rtps/transport/TransportDescriptorInterface.h b/include/fastdds/rtps/transport/TransportDescriptorInterface.h index 232f15aa722..47a9fbfd609 100644 --- a/include/fastdds/rtps/transport/TransportDescriptorInterface.h +++ b/include/fastdds/rtps/transport/TransportDescriptorInterface.h @@ -15,12 +15,11 @@ #ifndef _FASTDDS_TRANSPORT_DESCRIPTOR_INTERFACE_H_ #define _FASTDDS_TRANSPORT_DESCRIPTOR_INTERFACE_H_ -#include - #include -#include #include +#include + namespace eprosima { namespace fastdds { namespace rtps { @@ -39,10 +38,10 @@ class TransportInterface; * * @ingroup RTPS_MODULE * */ -struct RTPS_DllAPI TransportDescriptorInterface +struct TransportDescriptorInterface { //! Constructor - TransportDescriptorInterface( + RTPS_DllAPI TransportDescriptorInterface( uint32_t maximumMessageSize, uint32_t maximumInitialPeersRange) : maxMessageSize(maximumMessageSize) @@ -51,28 +50,28 @@ struct RTPS_DllAPI TransportDescriptorInterface } //! Copy constructor - TransportDescriptorInterface( + RTPS_DllAPI TransportDescriptorInterface( const TransportDescriptorInterface& t) = default; //! Copy assignment - TransportDescriptorInterface& operator =( + RTPS_DllAPI TransportDescriptorInterface& operator =( const TransportDescriptorInterface& t) = default; //! Destructor - virtual ~TransportDescriptorInterface() = default; + virtual RTPS_DllAPI ~TransportDescriptorInterface() = default; /** * Factory method pattern. It will create and return a TransportInterface * corresponding to this descriptor. This provides an interface to the NetworkFactory * to create the transports without the need to know about their type */ - virtual TransportInterface* create_transport() const = 0; + virtual RTPS_DllAPI TransportInterface* create_transport() const = 0; //! Returns the minimum size required for a send operation. - virtual uint32_t min_send_buffer_size() const = 0; + virtual RTPS_DllAPI uint32_t min_send_buffer_size() const = 0; //! Returns the maximum size expected for received messages. - virtual uint32_t max_message_size() const + virtual RTPS_DllAPI uint32_t max_message_size() const { return maxMessageSize; } @@ -80,13 +79,13 @@ struct RTPS_DllAPI TransportDescriptorInterface /** Returns the maximum number of opened channels for each initial remote peer * (maximum number of guessed initial peers to try to connect) */ - virtual uint32_t max_initial_peers_range() const + virtual RTPS_DllAPI uint32_t max_initial_peers_range() const { return maxInitialPeersRange; } //! Comparison operator - bool operator ==( + RTPS_DllAPI bool operator ==( const TransportDescriptorInterface& t) const { return (this->maxMessageSize == t.max_message_size() && diff --git a/include/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h b/include/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h index 9152efc0893..db8d1951607 100644 --- a/include/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h +++ b/include/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h @@ -15,7 +15,11 @@ #ifndef _FASTDDS_SHAREDMEM_TRANSPORT_DESCRIPTOR_ #define _FASTDDS_SHAREDMEM_TRANSPORT_DESCRIPTOR_ -#include "fastdds/rtps/transport/TransportDescriptorInterface.h" +#include + +#include +#include +#include namespace eprosima { namespace fastdds { @@ -37,7 +41,7 @@ class TransportInterface; * * @ingroup TRANSPORT_MODULE */ -struct SharedMemTransportDescriptor : public TransportDescriptorInterface +struct SharedMemTransportDescriptor : public PortBasedTransportDescriptor { //! Destructor virtual ~SharedMemTransportDescriptor() = default; @@ -126,6 +130,19 @@ struct SharedMemTransportDescriptor : public TransportDescriptorInterface rtps_dump_file_ = rtps_dump_file; } + //! Return the thread settings for the transport dump thread + RTPS_DllAPI ThreadSettings dump_thread() const + { + return dump_thread_; + } + + //! Set the thread settings for the transport dump thread + RTPS_DllAPI void dump_thread( + const ThreadSettings& dump_thread) + { + dump_thread_ = dump_thread; + } + //! Comparison operator RTPS_DllAPI bool operator ==( const SharedMemTransportDescriptor& t) const; @@ -137,6 +154,9 @@ struct SharedMemTransportDescriptor : public TransportDescriptorInterface uint32_t healthy_check_timeout_ms_; std::string rtps_dump_file_; + //! Thread settings for the transport dump thread + ThreadSettings dump_thread_; + }; } // namespace rtps diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 9a459ac15b7..b3da097019a 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -122,23 +122,24 @@ set(${PROJECT_NAME}_source_files fastdds/builtin/typelookup/TypeLookupManager.cpp fastdds/builtin/typelookup/TypeLookupRequestListener.cpp fastdds/builtin/typelookup/TypeLookupReplyListener.cpp + rtps/transport/ChainingTransport.cpp rtps/transport/ChannelResource.cpp - rtps/transport/UDPChannelResource.cpp - rtps/transport/TCPChannelResource.cpp - rtps/transport/TCPChannelResourceBasic.cpp + rtps/transport/PortBasedTransportDescriptor.cpp + rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp + rtps/transport/tcp/RTCPMessageManager.cpp + rtps/transport/tcp/TCPControlMessage.cpp rtps/transport/TCPAcceptor.cpp rtps/transport/TCPAcceptorBasic.cpp - rtps/transport/UDPv4Transport.cpp + rtps/transport/TCPChannelResource.cpp + rtps/transport/TCPChannelResourceBasic.cpp rtps/transport/TCPTransportInterface.cpp - rtps/transport/UDPTransportInterface.cpp - rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp rtps/transport/TCPv4Transport.cpp - rtps/transport/UDPv6Transport.cpp rtps/transport/TCPv6Transport.cpp rtps/transport/test_UDPv4Transport.cpp - rtps/transport/tcp/TCPControlMessage.cpp - rtps/transport/tcp/RTCPMessageManager.cpp - rtps/transport/ChainingTransport.cpp + rtps/transport/UDPChannelResource.cpp + rtps/transport/UDPTransportInterface.cpp + rtps/transport/UDPv4Transport.cpp + rtps/transport/UDPv6Transport.cpp dynamic-types/AnnotationDescriptor.cpp dynamic-types/AnnotationParameterValue.cpp @@ -198,6 +199,7 @@ set(${PROJECT_NAME}_source_files rtps/flowcontrol/FlowControllerFactory.cpp rtps/exceptions/Exception.cpp rtps/attributes/PropertyPolicy.cpp + rtps/attributes/ThreadSettings.cpp rtps/common/Token.cpp rtps/xmlparser/XMLParserCommon.cpp rtps/xmlparser/XMLElementParser.cpp diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index b703685cda8..56e4023b637 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -2322,6 +2322,32 @@ bool DomainParticipantImpl::can_qos_be_updated( updatable = false; EPROSIMA_LOG_WARNING(RTPS_QOS_CHECK, "Participant name cannot be changed after the participant is enabled"); } + if (!(to.builtin_controllers_sender_thread() == from.builtin_controllers_sender_thread())) + { + updatable = false; + EPROSIMA_LOG_WARNING(RTPS_QOS_CHECK, + "Participant builtin_controllers_sender_thread cannot be changed after the participant is enabled"); + } + if (!(to.timed_events_thread() == from.timed_events_thread())) + { + updatable = false; + EPROSIMA_LOG_WARNING(RTPS_QOS_CHECK, + "Participant timed_events_thread cannot be changed after the participant is enabled"); + } + if (!(to.discovery_server_thread() == from.discovery_server_thread())) + { + updatable = false; + EPROSIMA_LOG_WARNING(RTPS_QOS_CHECK, + "Participant discovery_server_thread cannot be changed after the participant is enabled"); + } +#if HAVE_SECURITY + if (!(to.security_log_thread() == from.security_log_thread())) + { + updatable = false; + EPROSIMA_LOG_WARNING(RTPS_QOS_CHECK, + "Participant security_log_thread cannot be changed after the participant is enabled"); + } +#endif // if HAVE_SECURITY return updatable; } diff --git a/src/cpp/fastdds/log/Log.cpp b/src/cpp/fastdds/log/Log.cpp index 27e37ff53b4..ff33c5f5b96 100644 --- a/src/cpp/fastdds/log/Log.cpp +++ b/src/cpp/fastdds/log/Log.cpp @@ -130,6 +130,14 @@ struct LogResources error_string_filter_.reset(new std::regex(filter)); } + //! Sets thread configuration for the logging thread. + void SetThreadConfig( + const rtps::ThreadSettings& config) + { + static_cast(config); + return; + } + //! Returns the logging_ engine to configuration defaults. void Reset() { @@ -439,6 +447,12 @@ void Log::SetErrorStringFilter( detail::get_log_resources()->SetErrorStringFilter(filter); } +void Log::SetThreadConfig( + const rtps::ThreadSettings& config) +{ + detail::get_log_resources()->SetThreadConfig(config); +} + void LogConsumer::print_timestamp( std::ostream& stream, const Log::Entry& entry, diff --git a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp index 700de22f92b..f21d339f7c2 100644 --- a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp +++ b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp @@ -139,6 +139,7 @@ ReturnCode_t DataReaderImpl::enable() ReaderAttributes att; + // TODO(eduponz): Encapsulate this in QosConverters.cpp att.endpoint.durabilityKind = qos_.durability().durabilityKind(); att.endpoint.endpointKind = READER; att.endpoint.reliabilityKind = qos_.reliability().kind == RELIABLE_RELIABILITY_QOS ? RELIABLE : BEST_EFFORT; @@ -158,7 +159,7 @@ ReturnCode_t DataReaderImpl::enable() att.matched_writers_allocation = qos_.reader_resource_limits().matched_publisher_allocation; att.expectsInlineQos = qos_.expects_inline_qos(); att.disable_positive_acks = qos_.reliable_reader_qos().disable_positive_ACKs.enabled; - + att.data_sharing_listener_thread = qos_.data_sharing_listener_thread(); // TODO(Ricardo) Remove in future // Insert topic_name and partitions @@ -810,6 +811,7 @@ void DataReaderImpl::update_rtps_reader_qos() } ReaderQos rqos = qos_.get_readerqos(get_subscriber()->get_qos()); subscriber_->rtps_participant()->updateReader(reader_, topic_attributes(), rqos, filter_property); + // TODO(eduponz): RTPSReader attributes must be updated here } } @@ -1563,6 +1565,12 @@ bool DataReaderImpl::can_qos_be_updated( EPROSIMA_LOG_WARNING(RTPS_QOS_CHECK, "Positive ACKs QoS cannot be changed after the creation of a DataReader."); } + if (!(to.data_sharing_listener_thread() == from.data_sharing_listener_thread())) + { + updatable = false; + EPROSIMA_LOG_WARNING(RTPS_QOS_CHECK, + "data_sharing_listener_thread cannot be changed after the DataReader is enabled"); + } return updatable; } diff --git a/src/cpp/fastdds/utils/QosConverters.cpp b/src/cpp/fastdds/utils/QosConverters.cpp index dbfcb7453e4..6d8b0e44d5b 100644 --- a/src/cpp/fastdds/utils/QosConverters.cpp +++ b/src/cpp/fastdds/utils/QosConverters.cpp @@ -156,6 +156,12 @@ void set_qos_from_attributes( qos.transport().listen_socket_buffer_size = attr.listenSocketBufferSize; qos.name() = attr.getName(); qos.flow_controllers() = attr.flow_controllers; + qos.builtin_controllers_sender_thread() = attr.builtin_controllers_sender_thread; + qos.timed_events_thread() = attr.timed_events_thread; + qos.discovery_server_thread() = attr.discovery_server_thread; +#if HAVE_SECURITY + qos.security_log_thread() = attr.security_log_thread; +#endif // if HAVE_SECURITY // Merge attributes and qos properties for (auto property : attr.properties.properties()) @@ -196,6 +202,12 @@ void set_attributes_from_qos( attr.listenSocketBufferSize = qos.transport().listen_socket_buffer_size; attr.userData = qos.user_data().data_vec(); attr.flow_controllers = qos.flow_controllers(); + attr.builtin_controllers_sender_thread = qos.builtin_controllers_sender_thread(); + attr.timed_events_thread = qos.timed_events_thread(); + attr.discovery_server_thread = qos.discovery_server_thread(); +#if HAVE_SECURITY + attr.security_log_thread = qos.security_log_thread(); +#endif // if HAVE_SECURITY } void set_qos_from_attributes( diff --git a/src/cpp/rtps/attributes/ThreadSettings.cpp b/src/cpp/rtps/attributes/ThreadSettings.cpp new file mode 100644 index 00000000000..8ee925711d1 --- /dev/null +++ b/src/cpp/rtps/attributes/ThreadSettings.cpp @@ -0,0 +1,32 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +using namespace eprosima::fastdds::rtps; + +bool ThreadSettings::operator ==( + const ThreadSettings& rhs) const +{ + return (scheduling_policy == rhs.scheduling_policy && + priority == rhs.priority && + cpu_mask == rhs.cpu_mask && + stack_size == rhs.stack_size); +} + +bool ThreadSettings::operator !=( + const ThreadSettings& rhs) const +{ + return !(*this == rhs); +} diff --git a/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp b/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp index e1e3b9f5464..aa5860dfd63 100644 --- a/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp +++ b/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp @@ -20,31 +20,38 @@ void FlowControllerFactory::init( participant_ = participant; // Create default flow controllers. + const ThreadSettings& sender_thread_settings = + (nullptr == participant_) ? ThreadSettings{} + : participant_->getAttributes().builtin_controllers_sender_thread; + // PureSyncFlowController -> used by volatile besteffort writers. flow_controllers_.insert(decltype(flow_controllers_)::value_type( pure_sync_flow_controller_name, std::unique_ptr( new FlowControllerImpl(participant_, nullptr, 0)))); + FlowControllerFifoSchedule>(participant_, nullptr, 0, sender_thread_settings)))); // SyncFlowController -> used by rest of besteffort writers. flow_controllers_.insert(decltype(flow_controllers_)::value_type( sync_flow_controller_name, std::unique_ptr( new FlowControllerImpl(participant_, nullptr, async_controller_index_++)))); + FlowControllerFifoSchedule>(participant_, nullptr, async_controller_index_++, + sender_thread_settings)))); // AsyncFlowController flow_controllers_.insert(decltype(flow_controllers_)::value_type( async_flow_controller_name, std::unique_ptr( new FlowControllerImpl(participant_, nullptr, async_controller_index_++)))); + FlowControllerFifoSchedule>(participant_, nullptr, async_controller_index_++, + sender_thread_settings)))); #ifdef FASTDDS_STATISTICS flow_controllers_.insert(decltype(flow_controllers_)::value_type( async_statistics_flow_controller_name, std::unique_ptr( new FlowControllerImpl(participant_, nullptr, async_controller_index_++)))); + FlowControllerFifoSchedule>(participant_, nullptr, async_controller_index_++, + sender_thread_settings)))); #endif // ifndef FASTDDS_STATISTICS } @@ -58,6 +65,8 @@ void FlowControllerFactory::register_flow_controller ( return; } + const ThreadSettings& sender_thread_settings = flow_controller_descr.sender_thread; + if (0 < flow_controller_descr.max_bytes_per_period) { switch (flow_controller_descr.scheduler) @@ -68,7 +77,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr, async_controller_index_++)))); + &flow_controller_descr, async_controller_index_++, sender_thread_settings)))); break; case FlowControllerSchedulerPolicy::ROUND_ROBIN: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -76,7 +85,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr, async_controller_index_++)))); + &flow_controller_descr, async_controller_index_++, sender_thread_settings)))); break; case FlowControllerSchedulerPolicy::HIGH_PRIORITY: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -84,7 +93,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr, async_controller_index_++)))); + &flow_controller_descr, async_controller_index_++, sender_thread_settings)))); break; case FlowControllerSchedulerPolicy::PRIORITY_WITH_RESERVATION: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -92,7 +101,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr, async_controller_index_++)))); + &flow_controller_descr, async_controller_index_++, sender_thread_settings)))); break; default: assert(false); @@ -108,7 +117,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr, async_controller_index_++)))); + &flow_controller_descr, async_controller_index_++, sender_thread_settings)))); break; case FlowControllerSchedulerPolicy::ROUND_ROBIN: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -116,7 +125,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr, async_controller_index_++)))); + &flow_controller_descr, async_controller_index_++, sender_thread_settings)))); break; case FlowControllerSchedulerPolicy::HIGH_PRIORITY: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -124,7 +133,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr, async_controller_index_++)))); + &flow_controller_descr, async_controller_index_++, sender_thread_settings)))); break; case FlowControllerSchedulerPolicy::PRIORITY_WITH_RESERVATION: flow_controllers_.insert(decltype(flow_controllers_)::value_type( @@ -132,7 +141,7 @@ void FlowControllerFactory::register_flow_controller ( std::unique_ptr( new FlowControllerImpl(participant_, - &flow_controller_descr, async_controller_index_++)))); + &flow_controller_descr, async_controller_index_++, sender_thread_settings)))); break; default: assert(false); diff --git a/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp b/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp index 62515ed1ce7..0ae267ff6d3 100644 --- a/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp +++ b/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp @@ -9,6 +9,7 @@ #include #include "FlowController.hpp" +#include #include #include #include @@ -930,12 +931,13 @@ class FlowControllerImpl : public FlowController FlowControllerImpl( fastrtps::rtps::RTPSParticipantImpl* participant, const FlowControllerDescriptor* descriptor, - uint32_t async_index - ) + uint32_t async_index, + ThreadSettings thread_settings) : participant_(participant) , async_mode(participant, descriptor) , participant_id_(0) , async_index_(async_index) + , thread_settings_(thread_settings) { if (nullptr != participant) { @@ -1486,6 +1488,9 @@ class FlowControllerImpl : public FlowController uint32_t participant_id_ = 0; uint32_t async_index_ = 0; + + //! Thread settings for the sender thread + ThreadSettings thread_settings_; }; } // namespace rtps diff --git a/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp b/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp new file mode 100644 index 00000000000..d57ba8d30dd --- /dev/null +++ b/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp @@ -0,0 +1,84 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include + +using namespace eprosima::fastdds::rtps; + +namespace eprosima { +namespace fastdds { +namespace rtps { + +PortBasedTransportDescriptor::PortBasedTransportDescriptor( + uint32_t maximumMessageSize, + uint32_t maximumInitialPeersRange) + : TransportDescriptorInterface(maximumMessageSize, maximumInitialPeersRange) +{ +} + +bool PortBasedTransportDescriptor::operator ==( + const PortBasedTransportDescriptor& t) const +{ + return (TransportDescriptorInterface::operator ==(t) && + this->default_reception_threads_ == t.default_reception_threads() && + this->reception_threads_ == t.reception_threads()); +} + +const ThreadSettings& PortBasedTransportDescriptor::get_thread_config_for_port( + uint32_t port) +{ + auto search = reception_threads_.find(port); + if (search != reception_threads_.end()) + { + return search->second; + } + return default_reception_threads_; +} + +bool PortBasedTransportDescriptor::set_thread_config_for_port( + const uint32_t& port, + const ThreadSettings& thread_settings) +{ + reception_threads_[port] = thread_settings; + return true; +} + +const ThreadSettings& PortBasedTransportDescriptor::default_reception_threads() const +{ + return default_reception_threads_; +} + +void PortBasedTransportDescriptor::default_reception_threads( + const ThreadSettings& default_reception_threads) +{ + default_reception_threads_ = default_reception_threads; +} + +const PortBasedTransportDescriptor::ReceptionThreadsConfigMap& PortBasedTransportDescriptor::reception_threads() const +{ + return reception_threads_; +} + +bool PortBasedTransportDescriptor::reception_threads( + const ReceptionThreadsConfigMap& reception_threads) +{ + reception_threads_ = reception_threads; + return true; +} + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index 2df9d257208..7b4f3ba528f 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -12,30 +12,60 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include "TCPTransportInterface.h" -#include -#include #include +#include #include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include #include +#include +#if TLS_FOUND +#include +#endif // if TLS_FOUND + #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#if TLS_FOUND -#include -#include -#endif // if TLS_FOUND + #include #include #include +#include "tcp/RTCPHeader.h" +#include "tcp/RTCPMessageManager.h" +#include "TCPAcceptorBasic.h" +#include "TCPChannelResourceBasic.h" +#include "TCPSenderResource.hpp" +#if TLS_FOUND +#include "TCPAcceptorSecure.h" +#include "TCPChannelResourceSecure.h" +#endif // if TLS_FOUND + using namespace std; using namespace asio; @@ -92,6 +122,8 @@ TCPTransportDescriptor::TCPTransportDescriptor( , check_crc(t.check_crc) , apply_security(t.apply_security) , tls_config(t.tls_config) + , keep_alive_thread(t.keep_alive_thread) + , accept_thread(t.accept_thread) { } @@ -117,6 +149,8 @@ TCPTransportDescriptor& TCPTransportDescriptor::operator =( check_crc = t.check_crc; apply_security = t.apply_security; tls_config = t.tls_config; + keep_alive_thread = t.keep_alive_thread; + accept_thread = t.accept_thread; return *this; } @@ -136,6 +170,8 @@ bool TCPTransportDescriptor::operator ==( this->check_crc == t.check_crc && this->apply_security == t.apply_security && this->tls_config == t.tls_config && + this->keep_alive_thread == t.keep_alive_thread && + this->accept_thread == t.accept_thread && SocketTransportDescriptor::operator ==(t)); } diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp b/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp index ba51f754711..7b477ff0b06 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp @@ -12,9 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include + #include +#include +#include + using namespace eprosima::fastdds::rtps; namespace eprosima { @@ -33,7 +37,7 @@ static constexpr uint32_t shm_default_healthy_check_timeout_ms = 1000; // SharedMemTransportDescriptor //********************************************************* SharedMemTransportDescriptor::SharedMemTransportDescriptor() - : TransportDescriptorInterface(shm_default_segment_size, s_maximumInitialPeersRange) + : PortBasedTransportDescriptor(shm_default_segment_size, s_maximumInitialPeersRange) , segment_size_(shm_default_segment_size) , port_queue_capacity_(shm_default_port_queue_capacity) , healthy_check_timeout_ms_(shm_default_healthy_check_timeout_ms) @@ -49,7 +53,8 @@ bool SharedMemTransportDescriptor::operator ==( this->port_queue_capacity_ == t.port_queue_capacity() && this->healthy_check_timeout_ms_ == t.healthy_check_timeout_ms() && this->rtps_dump_file_ == t.rtps_dump_file() && - TransportDescriptorInterface::operator ==(t)); + this->dump_thread_ == t.dump_thread() && + PortBasedTransportDescriptor::operator ==(t)); } #ifdef FASTDDS_SHM_TRANSPORT_DISABLED diff --git a/test/mock/rtps/SharedMemTransportDescriptor/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h b/test/mock/rtps/SharedMemTransportDescriptor/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h index e5e2e283648..1f0a7312c9f 100644 --- a/test/mock/rtps/SharedMemTransportDescriptor/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h +++ b/test/mock/rtps/SharedMemTransportDescriptor/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h @@ -15,7 +15,7 @@ #ifndef _FASTDDS_SHAREDMEM_TRANSPORT_DESCRIPTOR_ #define _FASTDDS_SHAREDMEM_TRANSPORT_DESCRIPTOR_ -#include "fastdds/rtps/transport/TransportDescriptorInterface.h" +#include namespace eprosima { namespace fastdds { @@ -28,7 +28,7 @@ class TransportInterface; * * @ingroup TRANSPORT_MODULE */ -typedef struct SharedMemTransportDescriptor : public TransportDescriptorInterface +typedef struct SharedMemTransportDescriptor : public PortBasedTransportDescriptor { virtual ~SharedMemTransportDescriptor() { @@ -36,7 +36,7 @@ typedef struct SharedMemTransportDescriptor : public TransportDescriptorInterfac } RTPS_DllAPI SharedMemTransportDescriptor() - : TransportDescriptorInterface(0, 0) + : PortBasedTransportDescriptor(0, 0) { } diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index d16837b321d..2eca626d922 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -14,6 +14,7 @@ add_compile_definitions(FASTRTPS_NO_LIB) +add_subdirectory(rtps/attributes) add_subdirectory(rtps/common) add_subdirectory(rtps/DataSharing) add_subdirectory(rtps/builtin) diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index a97aa46c298..84af1c34e77 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -2979,12 +2979,11 @@ TEST(ParticipantTests, SetDomainParticipantQos) } /* - * This test checks that the PropertyPolicyQos and TransportConfigQos are immutable policy qos, i.e. these can not be + * This test checks that the inmutable policy qos can not be * changed in an enabled participant */ TEST(ParticipantTests, UpdatableDomainParticipantQos) { - DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant( (uint32_t)GET_PID() % 230, PARTICIPANT_QOS_DEFAULT); @@ -3001,7 +3000,30 @@ TEST(ParticipantTests, UpdatableDomainParticipantQos) pqos.transport().listen_socket_buffer_size = 262144; ASSERT_EQ(participant->set_qos(pqos), ReturnCode_t::RETCODE_IMMUTABLE_POLICY); + // Check that the builtin_controllers_sender_thread can not be changed in an enabled participant + participant->get_qos(pqos); + pqos.builtin_controllers_sender_thread().cpu_mask = 1; + ASSERT_EQ(participant->set_qos(pqos), ReturnCode_t::RETCODE_IMMUTABLE_POLICY); + + // Check that the timed_events_thread can not be changed in an enabled participant + participant->get_qos(pqos); + pqos.timed_events_thread().cpu_mask = 1; + ASSERT_EQ(participant->set_qos(pqos), ReturnCode_t::RETCODE_IMMUTABLE_POLICY); + + // Check that the discovery_server_thread can not be changed in an enabled participant + participant->get_qos(pqos); + pqos.discovery_server_thread().cpu_mask = 1; + ASSERT_EQ(participant->set_qos(pqos), ReturnCode_t::RETCODE_IMMUTABLE_POLICY); + +#if HAVE_SECURITY + // Check that the security_log_thread can not be changed in an enabled participant + participant->get_qos(pqos); + pqos.security_log_thread().cpu_mask = 1; + ASSERT_EQ(participant->set_qos(pqos), ReturnCode_t::RETCODE_IMMUTABLE_POLICY); + ASSERT_EQ(DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK); +#endif // if HAVE_SECURITY + } /* diff --git a/test/unittest/dds/publisher/CMakeLists.txt b/test/unittest/dds/publisher/CMakeLists.txt index 7cceabdc612..a8b9d4152f7 100644 --- a/test/unittest/dds/publisher/CMakeLists.txt +++ b/test/unittest/dds/publisher/CMakeLists.txt @@ -32,7 +32,6 @@ set(sqlite3_source_files set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${DDSSQLFILTER_SOURCES} - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp @@ -55,16 +54,16 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectHashId.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/common/RPCHeadersImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/common/TypeLookupTypes.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/TypeLookupManager.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/TypeLookupReplyListener.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/TypeLookupRequestListener.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/common/TypeLookupTypes.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/Entity.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/Condition.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/ConditionNotifier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/StatusCondition.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/StatusConditionImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/WaitSetImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/Entity.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/QosPolicyUtils.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/DomainParticipant.cpp @@ -85,36 +84,32 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/DataReader.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/DataReaderImpl.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/ReadCondition.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/Subscriber.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/SubscriberImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/history/DataReaderHistory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/DataReaderQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/SubscriberQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/ReadCondition.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/Subscriber.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/SubscriberImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/ContentFilteredTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/Topic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/utils/QosConverters.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastrtps_deprecated/subscriber/SubscriberHistory.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingListener.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingNotification.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/RTPSDomain.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/BuiltinProtocols.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ReaderProxyData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/WriterProxyData.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/backup/SharedBackupFunctions.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/DiscoveryDataBase.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/DiscoveryParticipantInfo.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/DiscoveryParticipantsAckStatus.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/DiscoverySharedInfo.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/backup/SharedBackupFunctions.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/endpoint/EDPClient.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/endpoint/EDPServer.cpp @@ -135,6 +130,9 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/liveliness/WLP.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/liveliness/WLPListener.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingListener.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingNotification.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingPayloadPool.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp @@ -164,7 +162,12 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/ResourceEvent.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEvent.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/RTPSDomain.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/TCPControlMessage.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptorBasic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResource.cpp @@ -176,15 +179,12 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv6Transport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/TCPControlMessage.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/LivelinessManager.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/LocatorSelectorSender.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/PersistentWriter.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/RTPSWriter.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/ReaderLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/ReaderProxy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/RTPSWriter.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/StatefulPersistentWriter.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/StatefulWriter.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/StatelessPersistentWriter.cpp @@ -197,11 +197,11 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLProfileManager.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/StringMatching.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp ) if(SQLITE3_SUPPORT) diff --git a/test/unittest/dds/status/CMakeLists.txt b/test/unittest/dds/status/CMakeLists.txt index 4b03f13a0ef..c41b0095dd2 100644 --- a/test/unittest/dds/status/CMakeLists.txt +++ b/test/unittest/dds/status/CMakeLists.txt @@ -16,7 +16,6 @@ file(GLOB DDSSQLFILTER_SOURCES ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/DDSSQ set(LISTENERTESTS_SOURCE ListenerTests.cpp ${DDSSQLFILTER_SOURCES} - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp @@ -39,12 +38,12 @@ set(LISTENERTESTS_SOURCE ListenerTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectHashId.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/Entity.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/Condition.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/ConditionNotifier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/StatusCondition.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/StatusConditionImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/WaitSetImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/Entity.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/QosPolicyUtils.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/DomainParticipant.cpp @@ -67,28 +66,31 @@ set(LISTENERTESTS_SOURCE ListenerTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/DataReader.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/DataReaderImpl.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/ReadCondition.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/Subscriber.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/SubscriberImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/history/DataReaderHistory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/DataReaderQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/SubscriberQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/ReadCondition.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/Subscriber.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/SubscriberImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/ContentFilteredTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/Topic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/utils/QosConverters.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/utils/QosConverters.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/history/CacheChangePool.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/history/TopicPayloadPool.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/history/TopicPayloadPoolRegistry.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/LocatorSelectorSender.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLElementParser.cpp @@ -99,10 +101,10 @@ set(LISTENERTESTS_SOURCE ListenerTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/statistics/fastdds/publisher/qos/DataWriterQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp ) if (FASTDDS_STATISTICS) diff --git a/test/unittest/dds/subscriber/DataReaderTests.cpp b/test/unittest/dds/subscriber/DataReaderTests.cpp index 4ab05b7c493..0cf8b1a1273 100644 --- a/test/unittest/dds/subscriber/DataReaderTests.cpp +++ b/test/unittest/dds/subscriber/DataReaderTests.cpp @@ -3545,6 +3545,108 @@ TEST_F(DataReaderTests, CustomPoolCreation) DomainParticipantFactory::get_instance()->delete_participant(participant); } +// Check DataReaderQos inmutabilities +TEST_F(DataReaderTests, UpdateInmutableQos) +{ + /* Test setup */ + DomainParticipant* participant = + DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT); + ASSERT_NE(participant, nullptr); + + Subscriber* subscriber = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT); + ASSERT_NE(subscriber, nullptr); + + TypeSupport type(new FooTypeSupport()); + type.register_type(participant); + + Topic* topic = participant->create_topic("footopic", type.get_type_name(), TOPIC_QOS_DEFAULT); + ASSERT_NE(topic, nullptr); + + DataReader* data_reader = subscriber->create_datareader(topic, DATAREADER_QOS_DEFAULT); + ASSERT_NE(data_reader, nullptr); + + /* Test actions */ + // Resource limits + DataReaderQos reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.resource_limits().max_samples = reader_qos.resource_limits().max_samples - 1; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + // History + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.history().kind = KEEP_ALL_HISTORY_QOS; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.history().depth = reader_qos.history().depth + 1; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + // Durability + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.durability().kind = TRANSIENT_LOCAL_DURABILITY_QOS; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + // Liveliness + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.liveliness().kind = MANUAL_BY_TOPIC_LIVELINESS_QOS; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.liveliness().lease_duration = Duration_t{123, 123}; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.liveliness().announcement_period = Duration_t{123, 123}; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + // Relibility + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.reliability().kind = RELIABLE_RELIABILITY_QOS; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + // Ownsership + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.ownership().kind = EXCLUSIVE_OWNERSHIP_QOS; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + // Destination order (currently reports unsupported) + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.destination_order().kind = BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS; + ASSERT_EQ(ReturnCode_t::RETCODE_UNSUPPORTED, data_reader->set_qos(reader_qos)); + + // Reader resource limits + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.reader_resource_limits().matched_publisher_allocation.maximum = + reader_qos.reader_resource_limits().matched_publisher_allocation.maximum - 1; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + // Datasharing + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.data_sharing().off(); + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.data_sharing().automatic("."); + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.data_sharing().add_domain_id(static_cast(12)); + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + // Unique network flows + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.properties().properties().push_back({"fastdds.unique_network_flows", "true"}); + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + // Datasharing listener thread + reader_qos = DATAREADER_QOS_DEFAULT; + reader_qos.data_sharing_listener_thread().priority = reader_qos.data_sharing_listener_thread().priority + 1; + ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); + + /* Cleanup */ + participant->delete_contained_entities(); + DomainParticipantFactory::get_instance()->delete_participant(participant); +} + int main( int argc, char** argv) diff --git a/test/unittest/dynamic_types/CMakeLists.txt b/test/unittest/dynamic_types/CMakeLists.txt index 4bcb40fd526..08e5539a326 100644 --- a/test/unittest/dynamic_types/CMakeLists.txt +++ b/test/unittest/dynamic_types/CMakeLists.txt @@ -77,16 +77,17 @@ set(DYNAMIC_TYPES_TEST_SOURCE idl/BasicPubSubTypes.cxx idl/BasicTypeObject.cxx ${DYNAMIC_TYPES_SOURCE} - - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLProfileManager.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLElementParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParserCommon.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLElementParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParserCommon.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLProfileManager.cpp ) set(DYNAMIC_COMPLEX_TYPES_TEST_SOURCE @@ -118,13 +119,13 @@ target_compile_definitions(DynamicTypesTests PRIVATE ) target_include_directories(DynamicTypesTests PRIVATE ${Asio_INCLUDE_DIR} + ${PROJECT_SOURCE_DIR}/test/mock/rtps/SharedMemTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv6TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv6TransportDescriptor - ${PROJECT_SOURCE_DIR}/test/mock/rtps/SharedMemTransportDescriptor $<$:${TINYXML2_INCLUDE_DIR}> ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/src/cpp diff --git a/test/unittest/rtps/attributes/CMakeLists.txt b/test/unittest/rtps/attributes/CMakeLists.txt new file mode 100644 index 00000000000..e4b28b53c24 --- /dev/null +++ b/test/unittest/rtps/attributes/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# 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. + +set(THREAD_SETTINGS_TESTS_EXEC ThreadSettingsTests) + +set(THREAD_SETTINGS_TESTS_SOURCE + ThreadSettingsTests.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp) + +if(WIN32) + add_definitions(-D_WIN32_WINNT=0x0601) +endif() + +add_executable(${THREAD_SETTINGS_TESTS_EXEC} ${THREAD_SETTINGS_TESTS_SOURCE}) + +target_include_directories( + ${THREAD_SETTINGS_TESTS_EXEC} + PRIVATE + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_BINARY_DIR}/include) + +target_link_libraries( + ${THREAD_SETTINGS_TESTS_EXEC} + GTest::gtest + ${CMAKE_DL_LIBS}) + +add_gtest( + ${THREAD_SETTINGS_TESTS_EXEC} + SOURCES + ${THREAD_SETTINGS_TESTS_SOURCE}) + +if(ANDROID) + set_property( + TARGET ${THREAD_SETTINGS_TESTS_EXEC} + PROPERTY CROSSCOMPILING_EMULATOR "adb;shell;cd;${CMAKE_CURRENT_BINARY_DIR};&&") +endif() diff --git a/test/unittest/rtps/attributes/ThreadSettingsTests.cpp b/test/unittest/rtps/attributes/ThreadSettingsTests.cpp new file mode 100644 index 00000000000..25a540a2b40 --- /dev/null +++ b/test/unittest/rtps/attributes/ThreadSettingsTests.cpp @@ -0,0 +1,149 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include + +TEST(ThreadSettingsTests, EqualOperators) +{ + eprosima::fastdds::rtps::ThreadSettings settings_1; + eprosima::fastdds::rtps::ThreadSettings settings_2; + + ASSERT_TRUE(settings_1 == settings_2); + ASSERT_FALSE(settings_1 != settings_2); + + // Fixed scheduling_policy cases + settings_2.scheduling_policy = settings_1.scheduling_policy; + settings_2.priority = settings_1.priority + 1; + settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.stack_size = settings_1.stack_size; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy; + settings_2.priority = settings_1.priority; + settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.stack_size = settings_1.stack_size; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy; + settings_2.priority = settings_1.priority; + settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.stack_size = settings_1.stack_size + 1; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy; + settings_2.priority = settings_1.priority + 1; + settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.stack_size = settings_1.stack_size; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy; + settings_2.priority = settings_1.priority; + settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.stack_size = settings_1.stack_size + 1; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy; + settings_2.priority = settings_1.priority + 1; + settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.stack_size = settings_1.stack_size + 1; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy; + settings_2.priority = settings_1.priority + 1; + settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.stack_size = settings_1.stack_size + 1; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + // Fixed priority cases (not already covered) + settings_2.scheduling_policy = settings_1.scheduling_policy + 1; + settings_2.priority = settings_1.priority; + settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.stack_size = settings_1.stack_size; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy + 1; + settings_2.priority = settings_1.priority; + settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.stack_size = settings_1.stack_size; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy + 1; + settings_2.priority = settings_1.priority; + settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.stack_size = settings_1.stack_size + 1; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy + 1; + settings_2.priority = settings_1.priority; + settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.stack_size = settings_1.stack_size + 1; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + // Fixed cpu_mask cases (not already covered) + settings_2.scheduling_policy = settings_1.scheduling_policy + 1; + settings_2.priority = settings_1.priority + 1; + settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.stack_size = settings_1.stack_size; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy + 1; + settings_2.priority = settings_1.priority + 1; + settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.stack_size = settings_1.stack_size + 1; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + // Fixed stack_size cases (not already covered) + settings_2.scheduling_policy = settings_1.scheduling_policy + 1; + settings_2.priority = settings_1.priority + 1; + settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.stack_size = settings_1.stack_size; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + settings_2.scheduling_policy = settings_1.scheduling_policy + 1; + settings_2.priority = settings_1.priority + 1; + settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.stack_size = settings_1.stack_size + 1; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); + + // All different + settings_2.scheduling_policy = settings_1.scheduling_policy + 1; + settings_2.priority = settings_1.priority + 1; + settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.stack_size = settings_1.stack_size + 1; + ASSERT_FALSE(settings_1 == settings_2); + ASSERT_TRUE(settings_1 != settings_2); +} + +int main() +{ + testing::InitGoogleTest(); + return RUN_ALL_TESTS(); +} diff --git a/test/unittest/rtps/flowcontrol/FlowControllerFactoryTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerFactoryTests.cpp index d6d142ec157..ba30728fbb0 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerFactoryTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerFactoryTests.cpp @@ -1,5 +1,19 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include -#include +#include #include diff --git a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnAsyncTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnAsyncTests.cpp index 801d753830f..e7ae98b337c 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnAsyncTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnAsyncTests.cpp @@ -1,3 +1,19 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + #include "FlowControllerPublishModesTests.hpp" using namespace eprosima::fastdds::rtps; @@ -7,7 +23,7 @@ TYPED_TEST(FlowControllerPublishModes, async_publish_mode) { FlowControllerDescriptor flow_controller_descr; FlowControllerImpl async(nullptr, - &flow_controller_descr, 0); + &flow_controller_descr, 0, ThreadSettings{}); async.init(); // Instantiate writers. diff --git a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnLimitedAsyncTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnLimitedAsyncTests.cpp index a95e6144ec6..71781c1748c 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnLimitedAsyncTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnLimitedAsyncTests.cpp @@ -1,3 +1,19 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + #include "FlowControllerPublishModesTests.hpp" using namespace eprosima::fastdds::rtps; @@ -28,7 +44,7 @@ TYPED_TEST(FlowControllerPublishModes, limited_async_publish_mode) flow_controller_descr.max_bytes_per_period = 10200; flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr, 0); + &flow_controller_descr, 0, ThreadSettings{}); async.init(); // Instantiate writers. diff --git a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnPureSyncTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnPureSyncTests.cpp index b06ff64d6a1..b31c5baea09 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnPureSyncTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnPureSyncTests.cpp @@ -1,3 +1,19 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + #include "FlowControllerPublishModesTests.hpp" using namespace eprosima::fastdds::rtps; @@ -7,7 +23,7 @@ TYPED_TEST(FlowControllerPublishModes, pure_sync_publish_mode) { FlowControllerDescriptor flow_controller_descr; FlowControllerImpl pure_sync(nullptr, - &flow_controller_descr, 0); + &flow_controller_descr, 0, ThreadSettings{}); pure_sync.init(); // Initialize callback to get info. diff --git a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnSyncTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnSyncTests.cpp index 8c64e3940c7..63ad9fbdd8f 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnSyncTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerPublishModesOnSyncTests.cpp @@ -1,3 +1,19 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + #include "FlowControllerPublishModesTests.hpp" using namespace eprosima::fastdds::rtps; @@ -7,7 +23,7 @@ TYPED_TEST(FlowControllerPublishModes, sync_publish_mode) { FlowControllerDescriptor flow_controller_descr; FlowControllerImpl sync(nullptr, - &flow_controller_descr, 0); + &flow_controller_descr, 0, ThreadSettings{}); sync.init(); // Instantiate writers. diff --git a/test/unittest/rtps/flowcontrol/FlowControllerSchedulersTests.cpp b/test/unittest/rtps/flowcontrol/FlowControllerSchedulersTests.cpp index 2b83a4cd886..f827492eb05 100644 --- a/test/unittest/rtps/flowcontrol/FlowControllerSchedulersTests.cpp +++ b/test/unittest/rtps/flowcontrol/FlowControllerSchedulersTests.cpp @@ -1,8 +1,24 @@ -#include -#include +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include +#include +#include + +#include + namespace eprosima { namespace fastrtps { namespace rtps { @@ -90,7 +106,7 @@ TEST_F(FlowControllerSchedulers, Fifo) flow_controller_descr.max_bytes_per_period = 10200; flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr, 0); + &flow_controller_descr, 0, ThreadSettings{}); async.init(); // Instantiate writers. @@ -691,7 +707,7 @@ TEST_F(FlowControllerSchedulers, RoundRobin) flow_controller_descr.max_bytes_per_period = 10200; flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr, 0); + &flow_controller_descr, 0, ThreadSettings{}); async.init(); // Instantiate writers. @@ -1292,7 +1308,7 @@ TEST_F(FlowControllerSchedulers, HighPriority) flow_controller_descr.max_bytes_per_period = 10200; flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr, 0); + &flow_controller_descr, 0, ThreadSettings{}); async.init(); // Instantiate writers. @@ -1916,7 +1932,7 @@ TEST_F(FlowControllerSchedulers, PriorityWithReservation) flow_controller_descr.period_ms = 10; FlowControllerImpl async(nullptr, - &flow_controller_descr, 0); + &flow_controller_descr, 0, ThreadSettings{}); async.init(); // Instantiate writers. diff --git a/test/unittest/rtps/network/CMakeLists.txt b/test/unittest/rtps/network/CMakeLists.txt index 6ab726d6425..baaac1b52a9 100644 --- a/test/unittest/rtps/network/CMakeLists.txt +++ b/test/unittest/rtps/network/CMakeLists.txt @@ -15,49 +15,41 @@ set(NETWORKFACTORYTESTS_SOURCE NetworkFactoryTests.cpp mock/MockTransport.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageCreator.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/ResourceEvent.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEvent.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv6Transport.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/TCPControlMessage.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResource.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResourceBasic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptorBasic.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResourceBasic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPv4Transport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPv6Transport.cpp - - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageCreator.cpp - - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp - - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/ResourceEvent.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEvent.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp - - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv6Transport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/System.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp ) if(TLS_FOUND) diff --git a/test/unittest/statistics/dds/CMakeLists.txt b/test/unittest/statistics/dds/CMakeLists.txt index cf6cdc34777..b7286598000 100644 --- a/test/unittest/statistics/dds/CMakeLists.txt +++ b/test/unittest/statistics/dds/CMakeLists.txt @@ -122,16 +122,16 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectHashId.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/common/RPCHeadersImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/common/TypeLookupTypes.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/TypeLookupManager.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/TypeLookupReplyListener.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/TypeLookupRequestListener.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/builtin/typelookup/common/TypeLookupTypes.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/Entity.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/Condition.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/ConditionNotifier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/StatusCondition.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/StatusConditionImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/condition/WaitSetImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/Entity.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/QosPolicyUtils.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/QosPolicyUtils.cpp @@ -152,35 +152,32 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/DataReader.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/DataReaderImpl.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/ReadCondition.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/Subscriber.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/SubscriberImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/history/DataReaderHistory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/DataReaderQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/SubscriberQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/ReadCondition.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/Subscriber.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/SubscriberImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/ContentFilteredTopic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/Topic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/utils/QosConverters.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingListener.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingNotification.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingPayloadPool.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/RTPSDomain.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/BuiltinProtocols.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ReaderProxyData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/WriterProxyData.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/backup/SharedBackupFunctions.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/DiscoveryDataBase.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/DiscoveryParticipantInfo.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/DiscoveryParticipantsAckStatus.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/DiscoverySharedInfo.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/database/backup/SharedBackupFunctions.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/endpoint/EDPClient.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/endpoint/EDPServer.cpp @@ -201,6 +198,9 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/liveliness/WLP.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/liveliness/WLPListener.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingListener.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingNotification.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingPayloadPool.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp @@ -221,8 +221,8 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) ${PROJECT_SOURCE_DIR}/src/cpp/rtps/participant/RTPSParticipant.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/participant/RTPSParticipantImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/persistence/PersistenceFactory.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/persistence/SQLite3PersistenceService.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/persistence/sqlite3.c + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/persistence/SQLite3PersistenceService.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/reader/RTPSReader.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/reader/StatefulPersistentReader.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/reader/StatefulReader.cpp @@ -232,7 +232,12 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/ResourceEvent.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEvent.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/RTPSDomain.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/TCPControlMessage.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptorBasic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResource.cpp @@ -244,15 +249,12 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv6Transport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/TCPControlMessage.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/LivelinessManager.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/LocatorSelectorSender.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/PersistentWriter.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/RTPSWriter.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/ReaderLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/ReaderProxy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/RTPSWriter.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/StatefulPersistentWriter.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/StatefulWriter.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/writer/StatelessPersistentWriter.cpp @@ -267,19 +269,19 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) ${PROJECT_SOURCE_DIR}/src/cpp/statistics/fastdds/domain/DomainParticipantImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/statistics/fastdds/domain/DomainParticipantStatisticsListener.cpp ${PROJECT_SOURCE_DIR}/src/cpp/statistics/fastdds/publisher/qos/DataWriterQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/statistics/rtps/StatisticsBase.cpp ${PROJECT_SOURCE_DIR}/src/cpp/statistics/rtps/reader/StatisticsReaderImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/statistics/rtps/StatisticsBase.cpp ${PROJECT_SOURCE_DIR}/src/cpp/statistics/rtps/writer/StatisticsWriterImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/statistics/types/types.cxx ${PROJECT_SOURCE_DIR}/src/cpp/statistics/types/typesv1.cxx ${PROJECT_SOURCE_DIR}/src/cpp/statistics/types/typesPubSubTypes.cxx ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/StringMatching.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp ) # SHM Transport @@ -301,6 +303,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) # Security Support if(SECURITY) list(APPEND STATISTICS_DOMAINPARTICIPANT_MOCK_TESTS_SOURCE + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/exceptions/Exception.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Token.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/security/exceptions/SecurityException.cpp diff --git a/test/unittest/transport/CMakeLists.txt b/test/unittest/transport/CMakeLists.txt index f73dfe82909..0650089a9dc 100644 --- a/test/unittest/transport/CMakeLists.txt +++ b/test/unittest/transport/CMakeLists.txt @@ -49,21 +49,23 @@ endif() set(UDPV4TESTS_SOURCE UDPv4Tests.cpp mock/MockReceiverResource.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ) set(UDPV6TESTS_SOURCE @@ -74,10 +76,12 @@ set(UDPV6TESTS_SOURCE ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp @@ -97,6 +101,7 @@ set(TCPV4TESTS_SOURCE ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageCreator.cpp @@ -105,23 +110,24 @@ set(TCPV4TESTS_SOURCE ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEvent.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/TCPControlMessage.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptorBasic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResource.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResourceBasic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPv4Transport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/TCPControlMessage.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/System.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp ) if(TLS_FOUND) @@ -141,6 +147,7 @@ set(TCPV6TESTS_SOURCE ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageCreator.cpp @@ -149,14 +156,15 @@ set(TCPV6TESTS_SOURCE ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEvent.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/TCPControlMessage.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPAcceptorBasic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResource.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPChannelResourceBasic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/TCPv6Transport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/tcp/TCPControlMessage.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp @@ -164,8 +172,8 @@ set(TCPV6TESTS_SOURCE ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/System.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp ) if(TLS_FOUND) @@ -178,26 +186,28 @@ endif() set(TEST_UDPV4TESTS_SOURCE test_UDPv4Tests.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageCreator.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/messages/RTPSMessageCreator.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/test_UDPv4Transport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ) set(SHAREDMEMTESTS_SOURCE @@ -208,15 +218,17 @@ set(SHAREDMEMTESTS_SOURCE ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/NetworkFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPChannelResource.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPTransportInterface.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/UDPv4Transport.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp @@ -245,6 +257,9 @@ endif() include_directories(mock/) +########################## +# UDPv4 tests +########################## add_executable(UDPv4Tests ${UDPV4TESTS_SOURCE}) target_compile_definitions(UDPv4Tests PRIVATE BOOST_ASIO_STANDALONE @@ -273,9 +288,45 @@ endif() add_gtest(UDPv4Tests SOURCES ${UDPV4TESTS_SOURCE}) set(TRANSPORT_XFAIL_LIST XFAIL_UDP4) +add_executable(test_UDPv4Tests ${TEST_UDPV4TESTS_SOURCE}) +target_compile_definitions(test_UDPv4Tests PRIVATE + BOOST_ASIO_STANDALONE + ASIO_STANDALONE + $<$>,$>:__DEBUG> + $<$:__INTERNALDEBUG> # Internal debug activated. + ) +target_include_directories(test_UDPv4Tests PRIVATE + ${Asio_INCLUDE_DIR} + ${PROJECT_SOURCE_DIR}/test/mock/rtps/ParticipantProxyData + ${PROJECT_SOURCE_DIR}/test/mock/dds/QosPolicies + ${PROJECT_SOURCE_DIR}/test/mock/rtps/MessageReceiver + ${PROJECT_SOURCE_DIR}/test/mock/rtps/ReceiverResource + ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include + ${PROJECT_SOURCE_DIR}/src/cpp + $<$:${ANDROID_IFADDRS_INCLUDE_DIR}> + ) +target_link_libraries(test_UDPv4Tests + fastcdr + GTest::gtest + ${MOCKS}) +if(QNX) + target_link_libraries(test_UDPv4Tests socket) +endif() +if(MSVC OR MSVC_IDE) + target_link_libraries(test_UDPv4Tests ${PRIVACY} iphlpapi Shlwapi) +endif() +add_gtest(test_UDPv4Tests SOURCES ${TEST_UDPV4TESTS_SOURCE}) +set(TRANSPORT_XFAIL_LIST ${TRANSPORT_XFAIL_LIST} XFAIL_TEST_UDP4) + +########################## +# IPv6 tests +########################## option(DISABLE_UDPV6_TESTS "Disable UDPv6 tests because fails in some systems" OFF) if(NOT DISABLE_UDPV6_TESTS) + ########################## + # UDPv6 tests + ########################## add_executable(UDPv6Tests ${UDPV6TESTS_SOURCE}) target_compile_definitions(UDPv6Tests PRIVATE BOOST_ASIO_STANDALONE @@ -303,6 +354,9 @@ if(NOT DISABLE_UDPV6_TESTS) add_gtest(UDPv6Tests SOURCES ${UDPV6TESTS_SOURCE}) set(TRANSPORT_XFAIL_LIST ${TRANSPORT_XFAIL_LIST} XFAIL_UDP6) + ########################## + # TCPv6 tests + ########################## add_executable(TCPv6Tests ${TCPV6TESTS_SOURCE}) target_compile_definitions(TCPv6Tests PRIVATE BOOST_ASIO_STANDALONE @@ -337,38 +391,9 @@ if(NOT DISABLE_UDPV6_TESTS) set(TRANSPORT_XFAIL_LIST ${TRANSPORT_XFAIL_LIST} XFAIL_TCP6) endif() -add_executable(test_UDPv4Tests ${TEST_UDPV4TESTS_SOURCE}) -target_compile_definitions(test_UDPv4Tests PRIVATE - BOOST_ASIO_STANDALONE - ASIO_STANDALONE - $<$>,$>:__DEBUG> - $<$:__INTERNALDEBUG> # Internal debug activated. - ) -target_include_directories(test_UDPv4Tests PRIVATE - ${Asio_INCLUDE_DIR} - ${PROJECT_SOURCE_DIR}/test/mock/rtps/ParticipantProxyData - ${PROJECT_SOURCE_DIR}/test/mock/dds/QosPolicies - ${PROJECT_SOURCE_DIR}/test/mock/rtps/MessageReceiver - ${PROJECT_SOURCE_DIR}/test/mock/rtps/ReceiverResource - ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include - ${PROJECT_SOURCE_DIR}/src/cpp - $<$:${ANDROID_IFADDRS_INCLUDE_DIR}> - ) -target_link_libraries(test_UDPv4Tests - fastcdr - GTest::gtest - ${MOCKS}) -if(QNX) - target_link_libraries(test_UDPv4Tests socket) -endif() -if(MSVC OR MSVC_IDE) - target_link_libraries(test_UDPv4Tests ${PRIVACY} iphlpapi Shlwapi) -else() - target_link_libraries(test_UDPv4Tests ${PRIVACY}) -endif() -add_gtest(test_UDPv4Tests SOURCES ${TEST_UDPV4TESTS_SOURCE}) -set(TRANSPORT_XFAIL_LIST ${TRANSPORT_XFAIL_LIST} XFAIL_TEST_UDP4) - +########################## +# TCPv4 tests +########################## add_executable(TCPv4Tests ${TCPV4TESTS_SOURCE}) target_compile_definitions(TCPv4Tests PRIVATE BOOST_ASIO_STANDALONE @@ -402,6 +427,9 @@ endif() add_gtest(TCPv4Tests SOURCES ${TCPV4TESTS_SOURCE}) set(TRANSPORT_XFAIL_LIST ${TRANSPORT_XFAIL_LIST} XFAIL_TCP4) +########################## +# SHM tests +########################## if(IS_THIRDPARTY_BOOST_OK) add_executable(SharedMemTests ${SHAREDMEMTESTS_SOURCE}) @@ -455,3 +483,34 @@ if(ANDROID) set_property(TARGET SharedMemTests PROPERTY CROSSCOMPILING_EMULATOR "adb;shell;cd;${CMAKE_CURRENT_BINARY_DIR};&&") set_property(TARGET test_UDPv4Tests PROPERTY CROSSCOMPILING_EMULATOR "adb;shell;cd;${CMAKE_CURRENT_BINARY_DIR};&&") endif() + +##################################### +# PortBasedTransportDescriptor tests +##################################### +set(PORTBASED_TRANSPORTDESCRIPTOR_TESTS_SOURCES + PortBasedTransportDescriptorTests.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp) + +set(PORTBASED_TRANSPORTDESCRIPTOR_TESTS_TARGET PortBasedTransportDescriptorTests) + +add_executable(${PORTBASED_TRANSPORTDESCRIPTOR_TESTS_TARGET} + ${PORTBASED_TRANSPORTDESCRIPTOR_TESTS_SOURCES}) + +target_compile_definitions(${PORTBASED_TRANSPORTDESCRIPTOR_TESTS_TARGET} + PRIVATE + $<$>,$>:__DEBUG> + $<$:__INTERNALDEBUG>) + +target_include_directories(${PORTBASED_TRANSPORTDESCRIPTOR_TESTS_TARGET} + PRIVATE + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_BINARY_DIR}/include) + +target_link_libraries(${PORTBASED_TRANSPORTDESCRIPTOR_TESTS_TARGET} + GTest::gtest + ${MOCKS}) + +add_gtest(${PORTBASED_TRANSPORTDESCRIPTOR_TESTS_TARGET} + SOURCES + ${PORTBASED_TRANSPORTDESCRIPTOR_TESTS_SOURCES}) diff --git a/test/unittest/transport/PortBasedTransportDescriptorTests.cpp b/test/unittest/transport/PortBasedTransportDescriptorTests.cpp new file mode 100644 index 00000000000..88c7b5e7021 --- /dev/null +++ b/test/unittest/transport/PortBasedTransportDescriptorTests.cpp @@ -0,0 +1,285 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include +#include +#include + +using namespace eprosima::fastdds::rtps; + +class CustomPortBasedTransportDescriptor : public PortBasedTransportDescriptor +{ +public: + + CustomPortBasedTransportDescriptor() + : PortBasedTransportDescriptor(0, 0) + { + } + + TransportInterface* create_transport() const override + { + return nullptr; + } + + //! Returns the minimum size required for a send operation. + uint32_t min_send_buffer_size() const override + { + return 0; + } + +}; + +class PortBasedTransportDescriptorTests : public CustomPortBasedTransportDescriptor, public testing::Test +{ +public: + + TransportInterface* create_transport() const override + { + return nullptr; + } + + //! Returns the minimum size required for a send operation. + uint32_t min_send_buffer_size() const override + { + return 0; + } + +}; + +TEST_F(PortBasedTransportDescriptorTests, get_thread_config_for_port) +{ + // Add an entry to the user-defined settings map + PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings; + set_settings[1234].scheduling_policy = 33; + set_settings[1234].priority = 33; + set_settings[1234].cpu_mask = 33; + set_settings[1234].stack_size = 33; + + ASSERT_TRUE(reception_threads(set_settings)); + + // Check that the new entry can be retrieved + ASSERT_EQ(set_settings[1234], get_thread_config_for_port(1234)); + + // Check that the new entry is not the same as the default settings + ASSERT_NE(default_reception_threads(), get_thread_config_for_port(1234)); + + // Check that a non-existing entry is returns default settings + ASSERT_EQ(default_reception_threads(), get_thread_config_for_port(4321)); +} + +TEST_F(PortBasedTransportDescriptorTests, set_thread_config_for_port) +{ + // Set some initial config + PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings; + set_settings[1234].scheduling_policy = 33; + set_settings[1234].priority = 33; + set_settings[1234].cpu_mask = 33; + set_settings[1234].stack_size = 33; + ASSERT_TRUE(reception_threads(set_settings)); + + // Check updating a config + ThreadSettings other_settings; + ASSERT_NE(set_settings[1234], other_settings); + ASSERT_TRUE(set_thread_config_for_port(1234, other_settings)); + ASSERT_EQ(other_settings, get_thread_config_for_port(1234)); + + // Setting a new config + other_settings.priority += 1; + ASSERT_NE(set_settings[4321], other_settings); + ASSERT_TRUE(set_thread_config_for_port(4321, other_settings)); + ASSERT_EQ(other_settings, get_thread_config_for_port(4321)); + ASSERT_NE(other_settings, get_thread_config_for_port(1234)); +} + +TEST_F(PortBasedTransportDescriptorTests, get_default_reception_threads) +{ + ASSERT_EQ(default_reception_threads_, default_reception_threads()); +} + +TEST_F(PortBasedTransportDescriptorTests, set_default_reception_threads) +{ + ThreadSettings& initial_settings = default_reception_threads_; + + ThreadSettings set_settings; + set_settings.scheduling_policy = 33; + set_settings.priority = 33; + set_settings.cpu_mask = 33; + set_settings.stack_size = 33; + + ASSERT_NE(initial_settings, set_settings); + + default_reception_threads(set_settings); + ASSERT_EQ(set_settings, default_reception_threads()); +} + +TEST_F(PortBasedTransportDescriptorTests, get_reception_threads) +{ + ASSERT_EQ(reception_threads_, reception_threads()); +} + +TEST_F(PortBasedTransportDescriptorTests, set_reception_threads) +{ + PortBasedTransportDescriptor::ReceptionThreadsConfigMap& initial_settings = reception_threads_; + + PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings; + set_settings[1234].scheduling_policy = 33; + set_settings[1234].priority = 33; + set_settings[1234].cpu_mask = 33; + set_settings[1234].stack_size = 33; + + ASSERT_NE(initial_settings, set_settings); + + ASSERT_TRUE(reception_threads(set_settings)); + ASSERT_EQ(set_settings, reception_threads()); +} + +TEST_F(PortBasedTransportDescriptorTests, equal_operator) +{ + // Two new instances are equal + CustomPortBasedTransportDescriptor other; + auto original_max_message_size = other.maxMessageSize; + auto original_default_reception_thread_settings = other.default_reception_threads(); + auto original_thread_reception_settings = other.reception_threads(); + ASSERT_EQ(*this, other); + + { + // Parent is different + other.maxMessageSize += 1; + ASSERT_FALSE(*this == other); + } + { + // default_reception_threads is different + other.maxMessageSize = original_max_message_size; + other.default_reception_threads(original_default_reception_thread_settings); + ASSERT_TRUE(other.reception_threads(original_thread_reception_settings)); + ASSERT_EQ(*this, other); + + ThreadSettings set_settings; + set_settings.scheduling_policy = 33; + set_settings.priority = 33; + set_settings.cpu_mask = 33; + set_settings.stack_size = 33; + other.default_reception_threads(set_settings); + ASSERT_FALSE(*this == other); + } + { + // reception_threads is different + other.maxMessageSize = original_max_message_size; + other.default_reception_threads(original_default_reception_thread_settings); + ASSERT_TRUE(other.reception_threads(original_thread_reception_settings)); + ASSERT_EQ(*this, other); + + PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings_map; + set_settings_map[1234].scheduling_policy = 33; + set_settings_map[1234].priority = 33; + set_settings_map[1234].cpu_mask = 33; + set_settings_map[1234].stack_size = 33; + ASSERT_TRUE(other.reception_threads(set_settings_map)); + ASSERT_FALSE(*this == other); + } + { + // Parent & default_reception_threads are different + other.maxMessageSize = original_max_message_size; + other.default_reception_threads(original_default_reception_thread_settings); + ASSERT_TRUE(other.reception_threads(original_thread_reception_settings)); + ASSERT_EQ(*this, other); + + other.maxMessageSize += 1; + + ThreadSettings set_settings; + set_settings.scheduling_policy = 33; + set_settings.priority = 33; + set_settings.cpu_mask = 33; + set_settings.stack_size = 33; + other.default_reception_threads(set_settings); + + ASSERT_FALSE(*this == other); + } + { + // Parent & reception_threads are different + other.maxMessageSize = original_max_message_size; + other.default_reception_threads(original_default_reception_thread_settings); + ASSERT_TRUE(other.reception_threads(original_thread_reception_settings)); + ASSERT_EQ(*this, other); + + other.maxMessageSize += 1; + + PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings_map; + set_settings_map[1234].scheduling_policy = 33; + set_settings_map[1234].priority = 33; + set_settings_map[1234].cpu_mask = 33; + set_settings_map[1234].stack_size = 33; + ASSERT_TRUE(other.reception_threads(set_settings_map)); + + ASSERT_FALSE(*this == other); + } + { + // default_reception_threads & reception_threads are different + other.maxMessageSize = original_max_message_size; + other.default_reception_threads(original_default_reception_thread_settings); + ASSERT_TRUE(other.reception_threads(original_thread_reception_settings)); + ASSERT_EQ(*this, other); + + ThreadSettings set_settings; + set_settings.scheduling_policy = 33; + set_settings.priority = 33; + set_settings.cpu_mask = 33; + set_settings.stack_size = 33; + other.default_reception_threads(set_settings); + + PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings_map; + set_settings_map[1234].scheduling_policy = 33; + set_settings_map[1234].priority = 33; + set_settings_map[1234].cpu_mask = 33; + set_settings_map[1234].stack_size = 33; + ASSERT_TRUE(other.reception_threads(set_settings_map)); + + ASSERT_FALSE(*this == other); + } + { + // Parent, default_reception_threads, & reception_threads are different + other.maxMessageSize = original_max_message_size; + other.default_reception_threads(original_default_reception_thread_settings); + ASSERT_TRUE(other.reception_threads(original_thread_reception_settings)); + ASSERT_EQ(*this, other); + + other.maxMessageSize += 1; + + ThreadSettings set_settings; + set_settings.scheduling_policy = 33; + set_settings.priority = 33; + set_settings.cpu_mask = 33; + set_settings.stack_size = 33; + other.default_reception_threads(set_settings); + + PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings_map; + set_settings_map[1234].scheduling_policy = 33; + set_settings_map[1234].priority = 33; + set_settings_map[1234].cpu_mask = 33; + set_settings_map[1234].stack_size = 33; + ASSERT_TRUE(other.reception_threads(set_settings_map)); + + ASSERT_FALSE(*this == other); + } +} + +int main( + int argc, + char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/unittest/xmlparser/CMakeLists.txt b/test/unittest/xmlparser/CMakeLists.txt index 1984ec75669..205c608ac9b 100644 --- a/test/unittest/xmlparser/CMakeLists.txt +++ b/test/unittest/xmlparser/CMakeLists.txt @@ -78,43 +78,45 @@ file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/regressions" DESTINATION "${CMAKE_CURRENT ################################### XMLProfileParserTests #################################################### set(XMLPROFILEPARSER_SOURCE XMLProfileParserTests.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLProfileManager.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLElementParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParserCommon.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataFactory.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataPtr.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilder.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeMember.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/MemberDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifierTypes.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectHashId.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLElementParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParserCommon.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLProfileManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ) # External sources @@ -177,49 +179,50 @@ add_gtest(XMLProfileParserTests SOURCES XMLProfileParserTests.cpp) set(XMLPARSER_SOURCE XMLParserTests.cpp XMLElementParserTests.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLProfileManager.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLElementParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParserCommon.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/FileConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataFactory.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataPtr.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilder.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeMember.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/MemberDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifierTypes.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectHashId.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/FileConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLElementParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParserCommon.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLProfileManager.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ) # External sources @@ -245,13 +248,13 @@ target_compile_definitions(XMLParserTests PRIVATE $<$:__INTERNALDEBUG> # Internal debug activated. ) target_include_directories(XMLParserTests PRIVATE + ${PROJECT_SOURCE_DIR}/test/mock/rtps/SharedMemTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv6TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv6TransportDescriptor - ${PROJECT_SOURCE_DIR}/test/mock/rtps/SharedMemTransportDescriptor ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/src/cpp @@ -307,47 +310,44 @@ add_gtest(XMLTreeTests SOURCES XMLTreeTests.cpp) ################################### XMLENDPOINTPARSERTESTS ################################################### set(XMLENDPOINTPARSERTESTS_SOURCE XMLEndpointParserTests.cpp - - # parser - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLEndpointParser.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParserCommon.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLElementParser.cpp - - # log - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/FileConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataFactory.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataPtr.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilder.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeMember.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/MemberDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifierTypes.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectHashId.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/FileConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLElementParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLEndpointParser.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/xmlparser/XMLParserCommon.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp # locators ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp @@ -384,8 +384,8 @@ target_include_directories(XMLEndpointParserTests PRIVATE ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPTransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv4TransportDescriptor ${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv6TransportDescriptor - ${PROJECT_SOURCE_DIR}/test/mock/rtps/XMLProfileManager ${PROJECT_SOURCE_DIR}/test/mock/rtps/WriterProxyData + ${PROJECT_SOURCE_DIR}/test/mock/rtps/XMLProfileManager ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/src/cpp From 010a9d9793dfcf076f2a8b144e5e29a61f21e104 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 23 Oct 2023 12:19:43 +0200 Subject: [PATCH 4/9] Apply thread settings (#3874) * Refs #19436. Added thread creation wrapper infrastructure. Signed-off-by: Miguel Company * Refs #19436. Added empty implementation for apply_thread_settings_to_current_thread. Signed-off-by: Miguel Company * Refs #19436. Refactor on Log.cpp Signed-off-by: Miguel Company * Refs #19436. Add implementation for setting scheduler and priority. Signed-off-by: Miguel Company * Refs #19436. Add implementation for setting cpu affinity. Signed-off-by: Miguel Company * Refs #19436. Add test setting config for Log thread. Signed-off-by: Miguel Company * Refs #19436. Fix SystemInfoTests link issue. Signed-off-by: Miguel Company * Refs #19436. Changes on ResourceEvent. Signed-off-by: Miguel Company * Refs #19436. Changes on DataSharingListener. Signed-off-by: Miguel Company * Refs #19436. Changes on FlowControllerImpl. Signed-off-by: Miguel Company * Refs #19436. Changes on security LogTopic. Signed-off-by: Miguel Company * Refs #19436. Apply settings on SharedMemWatchdog. Signed-off-by: Miguel Company * Refs #19436. Apply settings on SharedMem reception threads. Signed-off-by: Miguel Company * Refs #19436. Apply settings on SharedMem packet dump threads. Signed-off-by: Miguel Company * Refs #19436. Apply settings on UDP reception threads. Signed-off-by: Miguel Company * Refs #19436. Apply settings on TCP accept and keep_alive threads. Signed-off-by: Miguel Company * Refs #19436. Apply settings on TCP reception threads. Signed-off-by: Miguel Company * Refs #19436. Include what you use. Signed-off-by: Miguel Company * Refs #19436. Add MacOS implementation for setting scheduler and priority. Signed-off-by: Miguel Company * Refs #19436. Add MacOS implementation for setting thread affinity. Signed-off-by: Miguel Company * Refs #19437. Member cpu_mask changed to affinity and made it 64 bits. Signed-off-by: Miguel Company * Refs #19437. Windows implementation for thread affinity. Signed-off-by: Miguel Company * Refs #19437. Windows implementation for thread priority. Signed-off-by: Miguel Company * Refs #19436. Made `get_thread_config_for_port` a const method. Signed-off-by: Miguel Company * Refs #19436. Apply suggestions from code review. Signed-off-by: Miguel Company Co-authored-by: Eduardo Ponz Segrelles * Refs #19435. Some refactors on FileWatch: - Namespace moved to eprosima::filewatch - Constructor receives thread settings - Copy constructors deleted Signed-off-by: Miguel Company * Refs #19435. SystemInfo::watch_file receives thread settings. Signed-off-by: Miguel Company * Refs #19435. Added RTPSDomain::set_filewatch_thread_config Signed-off-by: Miguel Company * Refs #19435. Call RTPSDomain::set_filewatch_thread_config inside DomainParticipantFactory::create_participant Signed-off-by: Miguel Company * Refs #19435. Change priority default value. Signed-off-by: Miguel Company * Refs #19435. Account for default values in threading_pthread Signed-off-by: Miguel Company * Refs #19435. Account for default values in threading_osx Signed-off-by: Miguel Company * Refs #19435. Account for default values in threading_win32 Signed-off-by: Miguel Company * Refs #19435. Linters. Signed-off-by: Miguel Company * Refs #19435. Use C++ headers. Signed-off-by: Miguel Company * Refs #19435. Documentation updates. Signed-off-by: Miguel Company * Refs #19435. Suggestions on Log test. Signed-off-by: Miguel Company * Refs #19435. Removed unused overload of create_thread. Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company Co-authored-by: Eduardo Ponz Segrelles --- include/fastdds/rtps/RTPSDomain.h | 13 ++ .../rtps/attributes/ThreadSettings.hpp | 14 +- .../fastdds/rtps/resources/ResourceEvent.h | 18 ++- .../PortBasedTransportDescriptor.hpp | 2 +- .../domain/DomainParticipantFactory.cpp | 5 + src/cpp/fastdds/log/Log.cpp | 37 +++-- .../rtps/DataSharing/DataSharingListener.cpp | 18 ++- .../rtps/DataSharing/DataSharingListener.hpp | 16 ++- src/cpp/rtps/RTPSDomain.cpp | 21 ++- src/cpp/rtps/RTPSDomainImpl.hpp | 15 ++ src/cpp/rtps/attributes/ThreadSettings.cpp | 2 +- .../discovery/participant/PDPServer.cpp | 9 +- .../rtps/flowcontrol/FlowControllerImpl.hpp | 7 +- .../rtps/participant/RTPSParticipantImpl.cpp | 13 +- src/cpp/rtps/reader/RTPSReader.cpp | 1 + src/cpp/rtps/resources/ResourceEvent.cpp | 19 ++- .../PortBasedTransportDescriptor.cpp | 2 +- .../rtps/transport/TCPTransportInterface.cpp | 57 ++++---- .../rtps/transport/TCPTransportInterface.h | 30 ++-- src/cpp/rtps/transport/UDPChannelResource.cpp | 14 +- src/cpp/rtps/transport/UDPChannelResource.h | 6 +- .../rtps/transport/UDPTransportInterface.cpp | 2 +- .../shared_mem/SharedMemChannelResource.hpp | 20 ++- .../transport/shared_mem/SharedMemLog.hpp | 34 ++--- .../shared_mem/SharedMemTransport.cpp | 7 +- .../test_SharedMemChannelResource.hpp | 7 +- src/cpp/security/logging/LogTopic.cpp | 20 ++- src/cpp/security/logging/LogTopic.h | 4 +- src/cpp/utils/SystemInfo.cpp | 8 +- src/cpp/utils/SystemInfo.hpp | 8 +- .../utils/shared_memory/SharedMemWatchdog.hpp | 22 ++- src/cpp/utils/threading.hpp | 45 ++++++ src/cpp/utils/threading/threading_empty.ipp | 5 + src/cpp/utils/threading/threading_osx.ipp | 86 +++++++++++- src/cpp/utils/threading/threading_pthread.ipp | 129 +++++++++++++++++- src/cpp/utils/threading/threading_win32.ipp | 34 +++++ .../rtps/RTPSDomain/fastdds/rtps/RTPSDomain.h | 7 + .../dds/participant/ParticipantTests.cpp | 8 +- test/unittest/logging/LogTests.cpp | 31 +++++ .../rtps/attributes/ThreadSettingsTests.cpp | 34 ++--- .../PortBasedTransportDescriptorTests.cpp | 24 ++-- test/unittest/utils/CMakeLists.txt | 4 + test/unittest/utils/SystemInfoTests.cpp | 2 +- thirdparty/filewatch/FileWatch.hpp | 60 ++++---- 44 files changed, 685 insertions(+), 235 deletions(-) diff --git a/include/fastdds/rtps/RTPSDomain.h b/include/fastdds/rtps/RTPSDomain.h index 287ad1f792d..401a1d1a6b3 100644 --- a/include/fastdds/rtps/RTPSDomain.h +++ b/include/fastdds/rtps/RTPSDomain.h @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -54,6 +55,18 @@ class RTPSDomain { public: + /** + * Method to set the configuration of the threads created by the file watcher for the environment file. + * In order for these settings to take effect, this method must be called before the first call + * to @ref createParticipant. + * + * @param watch_thread Settings for the thread watching the environment file. + * @param callback_thread Settings for the thread executing the callback when the environment file changed. + */ + RTPS_DllAPI static void set_filewatch_thread_config( + const fastdds::rtps::ThreadSettings& watch_thread, + const fastdds::rtps::ThreadSettings& callback_thread); + /** * Method to shut down all RTPSParticipants, readers, writers, etc. * It must be called at the end of the process to avoid memory leaks. diff --git a/include/fastdds/rtps/attributes/ThreadSettings.hpp b/include/fastdds/rtps/attributes/ThreadSettings.hpp index bd6c9ad34ae..ed2a85f0b9b 100644 --- a/include/fastdds/rtps/attributes/ThreadSettings.hpp +++ b/include/fastdds/rtps/attributes/ThreadSettings.hpp @@ -17,6 +17,7 @@ */ #include +#include #include @@ -41,6 +42,7 @@ struct RTPS_DllAPI ThreadSettings * A value of -1 indicates system default. * * This value is platform specific and it is used as-is to configure the specific platform thread. + * It is ignored on Windows platforms. * Setting this value to something other than the default one may require different privileges * on different platforms. */ @@ -50,25 +52,27 @@ struct RTPS_DllAPI ThreadSettings * @brief The thread's priority. * * Configures the thread's priority. - * A value of 0 indicates system default. + * A value of -2^31 indicates system default. * * This value is platform specific and it is used as-is to configure the specific platform thread. * Setting this value to something other than the default one may require different privileges * on different platforms. */ - int32_t priority = 0; + int32_t priority = std::numeric_limits::min(); /** - * @brief The thread's core affinity. + * @brief The thread's affinity. * - * cpu_mask is a bit mask for setting the threads affinity to each core individually. + * On some systems (Windows, Linux), this is a bit mask for setting the threads affinity to each core individually. + * On MacOS, this sets the affinity tag for the thread, and the OS tries to share the L2 cache between threads + * with the same affinity. * A value of 0 indicates no particular affinity. * * This value is platform specific and it is used as-is to configure the specific platform thread. * Setting this value to something other than the default one may require different privileges * on different platforms. */ - uint32_t cpu_mask = 0; + uint64_t affinity = 0; /** * @brief The thread's stack size in bytes. diff --git a/include/fastdds/rtps/resources/ResourceEvent.h b/include/fastdds/rtps/resources/ResourceEvent.h index 3709f3ff120..5cb68311720 100644 --- a/include/fastdds/rtps/resources/ResourceEvent.h +++ b/include/fastdds/rtps/resources/ResourceEvent.h @@ -22,14 +22,15 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC -#include -#include - #include #include #include #include +#include +#include +#include + namespace eprosima { namespace fastrtps { namespace rtps { @@ -51,11 +52,16 @@ class ResourceEvent /*! * @brief Method to initialize the internal thread. * - * @param[in] configure_cb Function to be called in the context of the started thread - * before calling the internal service routine. + * @param[in] thread_cfg Settings to apply to the created thread. + * @param[in] name_fmt A null-terminated string to be used as the format argument of + * a `snprintf` like function, taking `thread_id` as additional + * argument, and used to give a name to the created thread. + * @param[in] thread_id Single variadic argument passed to the formatting function. */ void init_thread( - std::function configure_cb = {}); + const fastdds::rtps::ThreadSettings& thread_cfg = {}, + const char* name_fmt = "event %u", + uint32_t thread_id = 0); void stop_thread(); diff --git a/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp b/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp index e34002ac0a5..e35ad1dfa33 100644 --- a/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp +++ b/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp @@ -77,7 +77,7 @@ class PortBasedTransportDescriptor : public TransportDescriptorInterface * @return The ThreadSettings for the given port. */ virtual RTPS_DllAPI const ThreadSettings& get_thread_config_for_port( - uint32_t port); + uint32_t port) const; virtual RTPS_DllAPI bool set_thread_config_for_port( const uint32_t& port, diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index 12049b35d0f..ed27c18d7c5 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -35,6 +35,7 @@ #include #include #include +#include using namespace eprosima::fastrtps::xmlparser; @@ -156,6 +157,8 @@ DomainParticipant* DomainParticipantFactory::create_participant( { load_profiles(); + RTPSDomain::set_filewatch_thread_config(factory_qos_.file_watch_threads(), factory_qos_.file_watch_threads()); + const DomainParticipantQos& pqos = (&qos == &PARTICIPANT_QOS_DEFAULT) ? default_participant_qos_ : qos; DomainParticipant* dom_part = new DomainParticipant(mask); @@ -422,6 +425,8 @@ void DomainParticipantFactory::set_qos( (void) first_time; //As all the Qos can always be updated and none of them need to be sent to = from; + + rtps::SharedMemWatchdog::set_thread_settings(to.shm_watchdog_thread()); } ReturnCode_t DomainParticipantFactory::check_qos( diff --git a/src/cpp/fastdds/log/Log.cpp b/src/cpp/fastdds/log/Log.cpp index ff33c5f5b96..0652d1145c0 100644 --- a/src/cpp/fastdds/log/Log.cpp +++ b/src/cpp/fastdds/log/Log.cpp @@ -134,14 +134,17 @@ struct LogResources void SetThreadConfig( const rtps::ThreadSettings& config) { - static_cast(config); - return; + std::lock_guard guard(cv_mutex_); + thread_settings_ = config; } //! Returns the logging_ engine to configuration defaults. void Reset() { - std::unique_lock configGuard(config_mutex_); + rtps::ThreadSettings thr_config{}; + SetThreadConfig(thr_config); + + std::lock_guard configGuard(config_mutex_); category_filter_.reset(); filename_filter_.reset(); error_string_filter_.reset(); @@ -162,7 +165,7 @@ struct LogResources { std::unique_lock guard(cv_mutex_); - if (!logging_ && !logging_thread_) + if (!logging_ && !logging_thread_.joinable()) { // already killed return; @@ -237,19 +240,13 @@ struct LogResources work_ = false; } - if (logging_thread_) + if (logging_thread_.joinable()) { cv_.notify_all(); - // The #ifdef workaround here is due to an unsolved MSVC bug, which Microsoft has announced - // they have no intention of solving: https://connect.microsoft.com/VisualStudio/feedback/details/747145 - // Each VS version deals with post-main deallocation of threads in a very different way. -#if !defined(_WIN32) || defined(FASTRTPS_STATIC_LINK) || _MSC_VER >= 1800 - if (logging_thread_->joinable() && logging_thread_->get_id() != std::this_thread::get_id()) + if (logging_thread_.get_id() != std::this_thread::get_id()) { - logging_thread_->join(); + logging_thread_.join(); } -#endif // if !defined(_WIN32) || defined(FASTRTPS_STATIC_LINK) || _MSC_VER >= 1800 - logging_thread_.reset(); } } @@ -258,17 +255,19 @@ struct LogResources void StartThread() { std::unique_lock guard(cv_mutex_); - if (!logging_ && !logging_thread_) + if (!logging_ && !logging_thread_.joinable()) { logging_ = true; - logging_thread_.reset(new std::thread(&LogResources::run, this)); + auto thread_fn = [this]() + { + run(); + }; + logging_thread_ = eprosima::create_thread(thread_fn, thread_settings_, "dds.log"); } } void run() { - set_name_to_current_thread("dds.log"); - std::unique_lock guard(cv_mutex_); while (logging_) @@ -343,7 +342,7 @@ struct LogResources fastrtps::DBQueue logs_; std::vector> consumers_; - std::unique_ptr logging_thread_; + std::thread logging_thread_; // Condition variable segment. std::condition_variable cv_; @@ -361,7 +360,7 @@ struct LogResources std::unique_ptr error_string_filter_; std::atomic verbosity_; - + rtps::ThreadSettings thread_settings_; }; std::shared_ptr get_log_resources() diff --git a/src/cpp/rtps/DataSharing/DataSharingListener.cpp b/src/cpp/rtps/DataSharing/DataSharingListener.cpp index a358767d317..e4aed898a11 100644 --- a/src/cpp/rtps/DataSharing/DataSharingListener.cpp +++ b/src/cpp/rtps/DataSharing/DataSharingListener.cpp @@ -31,6 +31,7 @@ namespace rtps { DataSharingListener::DataSharingListener( std::shared_ptr notification, const std::string& datasharing_pools_directory, + const fastdds::rtps::ThreadSettings& thr_config, ResourceLimitedContainerConfig limits, RTPSReader* reader) : notification_(notification) @@ -39,6 +40,7 @@ DataSharingListener::DataSharingListener( , writer_pools_(limits) , writer_pools_changed_(false) , datasharing_pools_directory_(datasharing_pools_directory) + , thread_config_(thr_config) { } @@ -50,8 +52,6 @@ DataSharingListener::~DataSharingListener() void DataSharingListener::run() { - set_name_to_current_thread("dds.dsha.%u", reader_->getGuid().entityId.to_uint32() & 0x0000FFFF); - std::unique_lock lock(notification_->notification_->notification_mutex, std::defer_lock); while (is_running_.load()) { @@ -100,13 +100,15 @@ void DataSharingListener::start() } // Initialize the thread - listening_thread_ = new std::thread(&DataSharingListener::run, this); + uint32_t thread_id = reader_->getGuid().entityId.to_uint32() & 0x0000FFFF; + listening_thread_ = create_thread([this]() + { + run(); + }, thread_config_, "dds.dsha.%u", thread_id); } void DataSharingListener::stop() { - std::thread* thr = nullptr; - { std::lock_guard guard(mutex_); @@ -116,15 +118,11 @@ void DataSharingListener::stop() { return; } - - thr = listening_thread_; - listening_thread_ = nullptr; } // Notify the thread and wait for it to finish notification_->notify(); - thr->join(); - delete thr; + listening_thread_.join(); } void DataSharingListener::process_new_data () diff --git a/src/cpp/rtps/DataSharing/DataSharingListener.hpp b/src/cpp/rtps/DataSharing/DataSharingListener.hpp index 41d27b4029c..3afc0bce6f5 100644 --- a/src/cpp/rtps/DataSharing/DataSharingListener.hpp +++ b/src/cpp/rtps/DataSharing/DataSharingListener.hpp @@ -19,15 +19,17 @@ #ifndef RTPS_DATASHARING_DATASHARINGLISTENER_HPP #define RTPS_DATASHARING_DATASHARINGLISTENER_HPP +#include +#include +#include + #include +#include +#include + #include #include #include -#include - -#include -#include -#include namespace eprosima { namespace fastrtps { @@ -46,6 +48,7 @@ class DataSharingListener : public IDataSharingListener DataSharingListener( std::shared_ptr notification, const std::string& datasharing_pools_directory, + const fastdds::rtps::ThreadSettings& thr_config, ResourceLimitedContainerConfig limits, RTPSReader* reader); @@ -111,10 +114,11 @@ class DataSharingListener : public IDataSharingListener std::shared_ptr notification_; std::atomic is_running_; RTPSReader* reader_; - std::thread* listening_thread_; + std::thread listening_thread_; ResourceLimitedVector writer_pools_; std::atomic writer_pools_changed_; std::string datasharing_pools_directory_; + fastdds::rtps::ThreadSettings thread_config_; mutable std::mutex mutex_; }; diff --git a/src/cpp/rtps/RTPSDomain.cpp b/src/cpp/rtps/RTPSDomain.cpp index d89595b498f..0b385ea4359 100644 --- a/src/cpp/rtps/RTPSDomain.cpp +++ b/src/cpp/rtps/RTPSDomain.cpp @@ -66,6 +66,13 @@ std::shared_ptr RTPSDomainImpl::get_instance() return instance; } +void RTPSDomain::set_filewatch_thread_config( + const fastdds::rtps::ThreadSettings& watch_thread, + const fastdds::rtps::ThreadSettings& callback_thread) +{ + RTPSDomainImpl::set_filewatch_thread_config(watch_thread, callback_thread); +} + void RTPSDomain::stopAll() { RTPSDomainImpl::stopAll(); @@ -143,8 +150,10 @@ RTPSParticipant* RTPSDomainImpl::createParticipant( std::string filename = SystemInfo::get_environment_file(); if (!filename.empty() && SystemInfo::file_exists(filename)) { + std::lock_guard guard(instance->m_mutex); // Create filewatch - instance->file_watch_handle_ = SystemInfo::watch_file(filename, RTPSDomainImpl::file_watch_callback); + instance->file_watch_handle_ = SystemInfo::watch_file(filename, RTPSDomainImpl::file_watch_callback, + instance->watch_thread_config_, instance->callback_thread_config_); } else if (!filename.empty()) { @@ -778,6 +787,16 @@ void RTPSDomainImpl::file_watch_callback() } } +void RTPSDomainImpl::set_filewatch_thread_config( + const fastdds::rtps::ThreadSettings& watch_thread, + const fastdds::rtps::ThreadSettings& callback_thread) +{ + auto instance = get_instance(); + std::lock_guard guard(instance->m_mutex); + instance->watch_thread_config_ = watch_thread; + instance->callback_thread_config_ = callback_thread; +} + } // namespace rtps } // namespace fastrtps } // namespace eprosima diff --git a/src/cpp/rtps/RTPSDomainImpl.hpp b/src/cpp/rtps/RTPSDomainImpl.hpp index fefa90b6001..88025e52404 100644 --- a/src/cpp/rtps/RTPSDomainImpl.hpp +++ b/src/cpp/rtps/RTPSDomainImpl.hpp @@ -25,6 +25,7 @@ #include #endif // defined(_WIN32) || defined(__unix__) +#include #include #include #include @@ -203,6 +204,18 @@ class RTPSDomainImpl */ static void file_watch_callback(); + /** + * Method to set the configuration of the threads created by the file watcher for the environment file. + * In order for these settings to take effect, this method must be called before the first call + * to @ref createParticipant. + * + * @param watch_thread Settings for the thread watching the environment file. + * @param callback_thread Settings for the thread executing the callback when the environment file changed. + */ + static void set_filewatch_thread_config( + const fastdds::rtps::ThreadSettings& watch_thread, + const fastdds::rtps::ThreadSettings& callback_thread); + private: /** @@ -252,6 +265,8 @@ class RTPSDomainImpl std::unordered_map m_RTPSParticipantIDs; FileWatchHandle file_watch_handle_; + fastdds::rtps::ThreadSettings watch_thread_config_; + fastdds::rtps::ThreadSettings callback_thread_config_; }; } // namespace rtps diff --git a/src/cpp/rtps/attributes/ThreadSettings.cpp b/src/cpp/rtps/attributes/ThreadSettings.cpp index 8ee925711d1..0c2761539f6 100644 --- a/src/cpp/rtps/attributes/ThreadSettings.cpp +++ b/src/cpp/rtps/attributes/ThreadSettings.cpp @@ -21,7 +21,7 @@ bool ThreadSettings::operator ==( { return (scheduling_policy == rhs.scheduling_policy && priority == rhs.priority && - cpu_mask == rhs.cpu_mask && + affinity == rhs.affinity && stack_size == rhs.stack_size); } diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp index 6e524dd8e7b..cb39e120049 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp @@ -162,11 +162,10 @@ bool PDPServer::init( getRTPSParticipant()->enableReader(edp->publications_reader_.first); // Initialize server dedicated thread. - uint32_t id_for_thread = static_cast(getRTPSParticipant()->getRTPSParticipantAttributes().participantID); - resource_event_thread_.init_thread([id_for_thread]() - { - set_name_to_current_thread("dds.ds_ev.%u", id_for_thread); - }); + const RTPSParticipantAttributes& part_attr = getRTPSParticipant()->getRTPSParticipantAttributes(); + uint32_t id_for_thread = static_cast(part_attr.participantID); + const fastdds::rtps::ThreadSettings& thr_config = part_attr.discovery_server_thread; + resource_event_thread_.init_thread(thr_config, "dds.ds_ev.%u", id_for_thread); /* Given the fact that a participant is either a client or a server the diff --git a/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp b/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp index 0ae267ff6d3..a31a68b8534 100644 --- a/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp +++ b/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp @@ -1062,7 +1062,10 @@ class FlowControllerImpl : public FlowController if (async_mode.running.compare_exchange_strong(expected, true)) { // Code for initializing the asynchronous thread. - async_mode.thread = std::thread(&FlowControllerImpl::run, this); + async_mode.thread = create_thread([this]() + { + run(); + }, thread_settings_, "dds.asyn.%u.%u", participant_id_, async_index_); } } @@ -1341,8 +1344,6 @@ class FlowControllerImpl : public FlowController */ void run() { - set_name_to_current_thread("dds.asyn.%u.%u", participant_id_, async_index_); - while (async_mode.running) { // There are writers interested in removing a sample. diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index 7be88aad027..ed8a32a0ee4 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -245,10 +245,8 @@ RTPSParticipantImpl::RTPSParticipantImpl( mp_userParticipant->mp_impl = this; uint32_t id_for_thread = static_cast(m_att.participantID); - mp_event_thr.init_thread([id_for_thread]() - { - set_name_to_current_thread("dds.ev.%u", id_for_thread); - }); + const fastdds::rtps::ThreadSettings& thr_config = m_att.timed_events_thread; + mp_event_thr.init_thread(thr_config, "dds.ev.%u", id_for_thread); if (!networkFactoryHasRegisteredTransports()) { @@ -2207,11 +2205,8 @@ bool RTPSParticipantImpl::is_security_enabled_for_reader( security::Logging* RTPSParticipantImpl::create_builtin_logging_plugin() { - return new security::LogTopic([this]() - { - uint32_t participant_id = static_cast(m_att.participantID); - set_name_to_current_thread("dds.slog.%u", participant_id); - }); + uint32_t participant_id = static_cast(m_att.participantID); + return new security::LogTopic(participant_id, m_att.security_log_thread); } #endif // if HAVE_SECURITY diff --git a/src/cpp/rtps/reader/RTPSReader.cpp b/src/cpp/rtps/reader/RTPSReader.cpp index d337520d456..297feee6ef9 100644 --- a/src/cpp/rtps/reader/RTPSReader.cpp +++ b/src/cpp/rtps/reader/RTPSReader.cpp @@ -130,6 +130,7 @@ void RTPSReader::init( datasharing_listener_.reset(new DataSharingListener( notification, att.endpoint.data_sharing_configuration().shm_directory(), + att.data_sharing_listener_thread, att.matched_writers_allocation, this)); diff --git a/src/cpp/rtps/resources/ResourceEvent.cpp b/src/cpp/rtps/resources/ResourceEvent.cpp index d5f58eb0a81..66acf31f4c1 100644 --- a/src/cpp/rtps/resources/ResourceEvent.cpp +++ b/src/cpp/rtps/resources/ResourceEvent.cpp @@ -16,13 +16,14 @@ * @file ResourceEvent.cpp */ +#include +#include + #include #include #include "TimedEventImpl.h" - -#include -#include +#include namespace eprosima { namespace fastrtps { @@ -304,7 +305,9 @@ void ResourceEvent::do_timer_actions() } void ResourceEvent::init_thread( - std::function configure_cb) + const fastdds::rtps::ThreadSettings& thread_cfg, + const char* name_fmt, + uint32_t thread_id) { std::lock_guard lock(mutex_); @@ -312,14 +315,10 @@ void ResourceEvent::init_thread( stop_.store(false); resize_collections(); - thread_ = std::thread([this, configure_cb]() + thread_ = eprosima::create_thread([this]() { - if (configure_cb) - { - configure_cb(); - } event_service(); - }); + }, thread_cfg, name_fmt, thread_id); } } /* namespace rtps */ diff --git a/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp b/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp index d57ba8d30dd..91640346586 100644 --- a/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp +++ b/src/cpp/rtps/transport/PortBasedTransportDescriptor.cpp @@ -38,7 +38,7 @@ bool PortBasedTransportDescriptor::operator ==( } const ThreadSettings& PortBasedTransportDescriptor::get_thread_config_for_port( - uint32_t port) + uint32_t port) const { auto search = reception_threads_.find(port); if (search != reception_threads_.end()) diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index 7b4f3ba528f..e4a3c2a111f 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -196,11 +196,10 @@ void TCPTransportInterface::clean() alive_.store(false); keep_alive_event_.cancel(); - if (io_service_timers_thread_) + if (io_service_timers_thread_.joinable()) { io_service_timers_.stop(); - io_service_timers_thread_->join(); - io_service_timers_thread_ = nullptr; + io_service_timers_thread_.join(); } { @@ -242,11 +241,10 @@ void TCPTransportInterface::clean() } } - if (io_service_thread_) + if (io_service_thread_.joinable()) { io_service_.stop(); - io_service_thread_->join(); - io_service_thread_ = nullptr; + io_service_thread_.join(); } } @@ -455,7 +453,6 @@ bool TCPTransportInterface::init( auto ioServiceFunction = [&]() { - set_name_to_current_thread("dds.tcp_accept"); #if ASIO_VERSION >= 101200 asio::executor_work_guard work(io_service_.get_executor()); #else @@ -463,21 +460,22 @@ bool TCPTransportInterface::init( #endif // if ASIO_VERSION >= 101200 io_service_.run(); }; - io_service_thread_ = std::make_shared(ioServiceFunction); + io_service_thread_ = create_thread(ioServiceFunction, configuration()->accept_thread, "dds.tcp_accept"); if (0 < configuration()->keep_alive_frequency_ms) { - io_service_timers_thread_ = std::make_shared([&]() - { - set_name_to_current_thread("dds.tcp_keep"); + auto ioServiceTimersFunction = [&]() + { #if ASIO_VERSION >= 101200 - asio::executor_work_guard work(io_service_timers_. + asio::executor_work_guard work(io_service_timers_. get_executor()); #else - io_service::work work(io_service_timers_); + io_service::work work(io_service_timers_); #endif // if ASIO_VERSION >= 101200 - io_service_timers_.run(); - }); + io_service_timers_.run(); + }; + io_service_timers_thread_ = create_thread(ioServiceTimersFunction, + configuration()->keep_alive_thread, "dds.tcp_keep"); } return true; @@ -839,6 +837,20 @@ void TCPTransportInterface::keep_alive() */ } +void TCPTransportInterface::create_listening_thread( + const std::shared_ptr& channel) +{ + std::weak_ptr channel_weak_ptr = channel; + std::weak_ptr rtcp_manager_weak_ptr = rtcp_message_manager_; + auto fn = [this, channel_weak_ptr, rtcp_manager_weak_ptr]() + { + perform_listen_operation(channel_weak_ptr, rtcp_manager_weak_ptr); + }; + uint32_t port = channel->local_endpoint().port(); + const ThreadSettings& thr_config = configuration()->get_thread_config_for_port(port); + channel->thread(create_thread(fn, thr_config, "dds.tcp.%u", port)); +} + void TCPTransportInterface::perform_listen_operation( std::weak_ptr channel_weak, std::weak_ptr rtcp_manager) @@ -1342,10 +1354,7 @@ void TCPTransportInterface::SocketAccepted( } channel->set_options(configuration()); - std::weak_ptr channel_weak_ptr = channel; - std::weak_ptr rtcp_manager_weak_ptr = rtcp_message_manager_; - channel->thread(std::thread(&TCPTransportInterface::perform_listen_operation, this, - channel_weak_ptr, rtcp_manager_weak_ptr)); + create_listening_thread(channel); EPROSIMA_LOG_INFO(RTCP, "Accepted connection (local: " << IPLocator::to_string(locator) << ", remote: " @@ -1389,10 +1398,7 @@ void TCPTransportInterface::SecureSocketAccepted( } secure_channel->set_options(configuration()); - std::weak_ptr channel_weak_ptr = secure_channel; - std::weak_ptr rtcp_manager_weak_ptr = rtcp_message_manager_; - secure_channel->thread(std::thread(&TCPTransportInterface::perform_listen_operation, this, - channel_weak_ptr, rtcp_manager_weak_ptr)); + create_listening_thread(secure_channel); EPROSIMA_LOG_INFO(RTCP, " Accepted connection (local: " << IPLocator::to_string(locator) << ", remote: " << socket->lowest_layer().remote_endpoint().address() @@ -1434,10 +1440,7 @@ void TCPTransportInterface::SocketConnected( { channel->change_status(TCPChannelResource::eConnectionStatus::eConnected); channel->set_options(configuration()); - - std::weak_ptr rtcp_manager_weak_ptr = rtcp_message_manager_; - channel->thread(std::thread(&TCPTransportInterface::perform_listen_operation, this, - channel_weak_ptr, rtcp_manager_weak_ptr)); + create_listening_thread(channel); } } else diff --git a/src/cpp/rtps/transport/TCPTransportInterface.h b/src/cpp/rtps/transport/TCPTransportInterface.h index f21f61b2e3f..412c905b475 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.h +++ b/src/cpp/rtps/transport/TCPTransportInterface.h @@ -15,12 +15,23 @@ #ifndef _FASTDDS_TCP_TRANSPORT_INTERFACE_H_ #define _FASTDDS_TCP_TRANSPORT_INTERFACE_H_ -#include +#include +#include +#include +#include +#include + +#include +#include + #include +#include #include + #include -#include #include +#include + #if TLS_FOUND #define OPENSSL_API_COMPAT 10101 #include @@ -29,14 +40,6 @@ #include -#include -#include -#include -#include -#include -#include -#include - namespace eprosima { namespace fastdds { namespace rtps { @@ -79,8 +82,8 @@ class TCPTransportInterface : public TransportInterface #if TLS_FOUND asio::ssl::context ssl_context_; #endif // if TLS_FOUND - std::shared_ptr io_service_thread_; - std::shared_ptr io_service_timers_thread_; + std::thread io_service_thread_; + std::thread io_service_timers_thread_; std::shared_ptr rtcp_message_manager_; std::mutex rtcp_message_manager_mutex_; std::condition_variable rtcp_message_manager_cv_; @@ -195,6 +198,9 @@ class TCPTransportInterface : public TransportInterface std::shared_ptr& channel, const Locator& remote_locator); + void create_listening_thread( + const std::shared_ptr& channel); + public: friend class RTCPMessageManager; diff --git a/src/cpp/rtps/transport/UDPChannelResource.cpp b/src/cpp/rtps/transport/UDPChannelResource.cpp index 62904444c7c..03efd8737d1 100644 --- a/src/cpp/rtps/transport/UDPChannelResource.cpp +++ b/src/cpp/rtps/transport/UDPChannelResource.cpp @@ -15,7 +15,10 @@ #include #include + +#include #include + #include #include @@ -32,7 +35,8 @@ UDPChannelResource::UDPChannelResource( uint32_t maxMsgSize, const Locator& locator, const std::string& sInterface, - TransportReceiverInterface* receiver) + TransportReceiverInterface* receiver, + const ThreadSettings& thread_config) : ChannelResource(maxMsgSize) , message_receiver_(receiver) , socket_(moveSocket(socket)) @@ -40,7 +44,11 @@ UDPChannelResource::UDPChannelResource( , interface_(sInterface) , transport_(transport) { - thread(std::thread(&UDPChannelResource::perform_listen_operation, this, locator)); + auto fn = [this, locator]() + { + perform_listen_operation(locator); + }; + thread(create_thread(fn, thread_config, "dds.udp.%u", locator.port)); } UDPChannelResource::~UDPChannelResource() @@ -54,8 +62,6 @@ UDPChannelResource::~UDPChannelResource() void UDPChannelResource::perform_listen_operation( Locator input_locator) { - set_name_to_current_thread("dds.udp.%u", input_locator.port); - Locator remote_locator; while (alive()) diff --git a/src/cpp/rtps/transport/UDPChannelResource.h b/src/cpp/rtps/transport/UDPChannelResource.h index 146b164c3f4..a496a89bf13 100644 --- a/src/cpp/rtps/transport/UDPChannelResource.h +++ b/src/cpp/rtps/transport/UDPChannelResource.h @@ -16,7 +16,10 @@ #define _FASTDDS_UDP_CHANNEL_RESOURCE_INFO_ #include + +#include #include + #include namespace eprosima { @@ -110,7 +113,8 @@ class UDPChannelResource : public ChannelResource uint32_t maxMsgSize, const Locator& locator, const std::string& sInterface, - TransportReceiverInterface* receiver); + TransportReceiverInterface* receiver, + const ThreadSettings& thread_config); virtual ~UDPChannelResource() override; diff --git a/src/cpp/rtps/transport/UDPTransportInterface.cpp b/src/cpp/rtps/transport/UDPTransportInterface.cpp index 19adeb1a91a..820056e26b3 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.cpp +++ b/src/cpp/rtps/transport/UDPTransportInterface.cpp @@ -231,7 +231,7 @@ UDPChannelResource* UDPTransportInterface::CreateInputChannelResource( eProsimaUDPSocket unicastSocket = OpenAndBindInputSocket(sInterface, IPLocator::getPhysicalPort(locator), is_multicast); UDPChannelResource* p_channel_resource = new UDPChannelResource(this, unicastSocket, maxMsgSize, locator, - sInterface, receiver); + sInterface, receiver, configuration()->get_thread_config_for_port(locator.port)); return p_channel_resource; } diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemChannelResource.hpp b/src/cpp/rtps/transport/shared_mem/SharedMemChannelResource.hpp index da7a95e5122..3a110f6bb44 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemChannelResource.hpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemChannelResource.hpp @@ -15,6 +15,7 @@ #ifndef _FASTDDS_SHAREDMEM_CHANNEL_RESOURCE_ #define _FASTDDS_SHAREDMEM_CHANNEL_RESOURCE_ +#include #include #include @@ -39,7 +40,9 @@ class SharedMemChannelResource : public ChannelResource const Locator& locator, TransportReceiverInterface* receiver, const std::string& dump_file, - bool should_init_thread = true) + const ThreadSettings& dump_thr_config, + bool should_init_thread, + const ThreadSettings& thr_config) : ChannelResource() , message_receiver_(receiver) , listener_(listener) @@ -51,13 +54,13 @@ class SharedMemChannelResource : public ChannelResource auto packets_file_consumer = std::unique_ptr( new SHMPacketFileConsumer(dump_file)); - packet_logger_ = std::make_shared>(locator.port); + packet_logger_ = std::make_shared>(locator.port, dump_thr_config); packet_logger_->RegisterConsumer(std::move(packets_file_consumer)); } if (should_init_thread) { - init_thread(locator); + init_thread(locator, thr_config); } } @@ -125,8 +128,6 @@ class SharedMemChannelResource : public ChannelResource void perform_listen_operation( Locator input_locator) { - set_name_to_current_thread("dds.shm.%u", input_locator.port); - Locator remote_locator; while (alive()) @@ -168,9 +169,14 @@ class SharedMemChannelResource : public ChannelResource protected: void init_thread( - const Locator& locator) + const Locator& locator, + const ThreadSettings& thr_config) { - this->thread(std::thread(&SharedMemChannelResource::perform_listen_operation, this, locator)); + auto fn = [this, locator]() + { + perform_listen_operation(locator); + }; + this->thread(create_thread(fn, thr_config, "dds.shm.%u", locator.port)); } /** diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp b/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp index 893fef62e0e..80f3ebf0bea 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp @@ -15,10 +15,13 @@ #ifndef _FASTDDS_SHAREDMEM_LOG_H_ #define _FASTDDS_SHAREDMEM_LOG_H_ +#include #include #include + #include #include +#include namespace eprosima { namespace fastdds { @@ -200,8 +203,10 @@ class PacketsLog public: PacketsLog( - uint32_t thread_id) + uint32_t thread_id, + const ThreadSettings& thread_config) : thread_id_(thread_id) + , thread_config_(thread_config) { } @@ -242,7 +247,7 @@ class PacketsLog { std::unique_lock guard(resources_.cv_mutex); - if (!resources_.logging && !resources_.logging_thread) + if (!resources_.logging && !resources_.logging_thread.joinable()) { // already killed return; @@ -286,31 +291,26 @@ class PacketsLog resources_.work = false; } - if (resources_.logging_thread) + if (resources_.logging_thread.joinable()) { resources_.cv.notify_all(); - // The #ifdef workaround here is due to an unsolved MSVC bug, which Microsoft has announced - // they have no intention of solving: https://connect.microsoft.com/VisualStudio/feedback/details/747145 - // Each VS version deals with post-main deallocation of threads in a very different way. - #if !defined(_WIN32) || defined(FASTRTPS_STATIC_LINK) || _MSC_VER >= 1800 - resources_.logging_thread->join(); - #endif // if !defined(_WIN32) || defined(FASTRTPS_STATIC_LINK) || _MSC_VER >= 1800 - resources_.logging_thread.reset(); + resources_.logging_thread.join(); } } - // Note: In VS2013, if you're linking this class statically, you will have to call KillThread before leaving - // main, due to an unsolved MSVC bug. - void QueueLog( const typename TPacketConsumer::Pkt& packet) { { std::unique_lock guard(resources_.cv_mutex); - if (!resources_.logging && !resources_.logging_thread) + if (!resources_.logging && !resources_.logging_thread.joinable()) { resources_.logging = true; - resources_.logging_thread.reset(new std::thread(&PacketsLog::run, this)); + auto fn = [this]() + { + run(); + }; + resources_.logging_thread = create_thread(fn, thread_config_, "dds.shmd.%u", thread_id_); } } @@ -333,7 +333,7 @@ class PacketsLog { eprosima::fastrtps::DBQueue logs; std::vector> consumers; - std::unique_ptr logging_thread; + std::thread logging_thread; // Condition variable segment. std::condition_variable cv; @@ -356,10 +356,10 @@ class PacketsLog Resources resources_; uint32_t thread_id_; + ThreadSettings thread_config_; void run() { - set_name_to_current_thread("dds.shmd.%u", thread_id_); std::unique_lock guard(resources_.cv_mutex); while (resources_.logging) diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp b/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp index 00095d1f9a7..8c54f702c6d 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp @@ -290,7 +290,7 @@ bool SharedMemTransport::init( auto packets_file_consumer = std::unique_ptr( new SHMPacketFileConsumer(configuration_.rtps_dump_file())); - packet_logger_ = std::make_shared>(0); + packet_logger_ = std::make_shared>(0, configuration_.dump_thread()); packet_logger_->RegisterConsumer(std::move(packets_file_consumer)); } } @@ -341,7 +341,10 @@ SharedMemChannelResource* SharedMemTransport::CreateInputChannelResource( open_mode)->create_listener(), locator, receiver, - configuration_.rtps_dump_file()); + configuration_.rtps_dump_file(), + configuration_.dump_thread(), + true, + configuration_.get_thread_config_for_port(locator.port)); } bool SharedMemTransport::OpenOutputChannel( diff --git a/src/cpp/rtps/transport/shared_mem/test_SharedMemChannelResource.hpp b/src/cpp/rtps/transport/shared_mem/test_SharedMemChannelResource.hpp index a950f74f7ec..641677feec8 100644 --- a/src/cpp/rtps/transport/shared_mem/test_SharedMemChannelResource.hpp +++ b/src/cpp/rtps/transport/shared_mem/test_SharedMemChannelResource.hpp @@ -33,11 +33,14 @@ class test_SharedMemChannelResource : public SharedMemChannelResource TransportReceiverInterface* receiver, uint32_t big_buffer_size, uint32_t* big_buffer_size_count) - : SharedMemChannelResource(listener, locator, receiver, std::string(), false) + : SharedMemChannelResource( + listener, locator, receiver, + std::string(), ThreadSettings{}, + false, ThreadSettings{}) , big_buffer_size_(big_buffer_size) , big_buffer_size_count_(big_buffer_size_count) { - init_thread(locator); + init_thread(locator, ThreadSettings{}); } virtual ~test_SharedMemChannelResource() override diff --git a/src/cpp/security/logging/LogTopic.cpp b/src/cpp/security/logging/LogTopic.cpp index b461cc9fc7e..747710d915c 100644 --- a/src/cpp/security/logging/LogTopic.cpp +++ b/src/cpp/security/logging/LogTopic.cpp @@ -1,25 +1,22 @@ #include -#include -#include - #include +#include + namespace eprosima { namespace fastrtps { namespace rtps { namespace security { LogTopic::LogTopic( - std::function thread_init_cb) + uint32_t thread_id, + const fastdds::rtps::ThreadSettings& thr_config) : stop_(false) - , thread_([this, thread_init_cb]() + , thread_( + create_thread( + [this]() { - if (thread_init_cb) - { - thread_init_cb(); - } - while (true) { // Put the thread asleep until there is @@ -37,7 +34,8 @@ LogTopic::LogTopic( publish(*p); } - }) + }, + thr_config, "dds.slog.%u", thread_id)) { // } diff --git a/src/cpp/security/logging/LogTopic.h b/src/cpp/security/logging/LogTopic.h index 47ebcd9be7e..6c19f958708 100644 --- a/src/cpp/security/logging/LogTopic.h +++ b/src/cpp/security/logging/LogTopic.h @@ -18,6 +18,7 @@ #ifndef _FASTDDS_RTPS_SECURITY_LOGGING_LOGTOPIC_H_ #define _FASTDDS_RTPS_SECURITY_LOGGING_LOGTOPIC_H_ +#include #include #include @@ -43,7 +44,8 @@ class LogTopic final : public Logging public: LogTopic( - std::function thread_init_cb = {}); + uint32_t thread_id = 0, + const fastdds::rtps::ThreadSettings& thr_config = {}); ~LogTopic(); private: diff --git a/src/cpp/utils/SystemInfo.cpp b/src/cpp/utils/SystemInfo.cpp index 74fd688ba51..8c285d39b0e 100644 --- a/src/cpp/utils/SystemInfo.cpp +++ b/src/cpp/utils/SystemInfo.cpp @@ -214,7 +214,9 @@ const std::string& SystemInfo::get_environment_file() FileWatchHandle SystemInfo::watch_file( std::string filename, - std::function callback) + std::function callback, + const fastdds::rtps::ThreadSettings& watch_thread_config, + const fastdds::rtps::ThreadSettings& callback_thread_config) { #if defined(_WIN32) || defined(__unix__) return FileWatchHandle (new filewatch::FileWatch(filename, @@ -229,10 +231,12 @@ FileWatchHandle SystemInfo::watch_file( // No-op break; } - })); + }, watch_thread_config, callback_thread_config)); #else // defined(_WIN32) || defined(__unix__) static_cast(filename); static_cast(callback); + static_cast(watch_thread_config); + static_cast(callback_thread_config); return FileWatchHandle(); #endif // defined(_WIN32) || defined(__unix__) } diff --git a/src/cpp/utils/SystemInfo.hpp b/src/cpp/utils/SystemInfo.hpp index d2b4420c4be..418da3d9963 100644 --- a/src/cpp/utils/SystemInfo.hpp +++ b/src/cpp/utils/SystemInfo.hpp @@ -25,6 +25,8 @@ #include #include +#include + #include #include @@ -193,12 +195,16 @@ class SystemInfo * * @param [in] filename Path/name of the file to watch. * @param [in] callback Callback to execute when the file changes. + * @param [in] watch_thread_config Thread settings for watch thread. + * @param [in] callback_thread_config Thread settings for callback thread. * * @return The handle that represents the watcher object. */ static FileWatchHandle watch_file( std::string filename, - std::function callback); + std::function callback, + const fastdds::rtps::ThreadSettings& watch_thread_config, + const fastdds::rtps::ThreadSettings& callback_thread_config); /** * Stop a file watcher. diff --git a/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp b/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp index e77c3131fad..cf9ac1edd28 100644 --- a/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp +++ b/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp @@ -22,6 +22,8 @@ #include #include +#include + #include namespace eprosima { @@ -77,6 +79,12 @@ class SharedMemWatchdog } } + static void set_thread_settings( + const ThreadSettings& thr_config) + { + thread_settings() = thr_config; + } + static constexpr std::chrono::milliseconds period() { return std::chrono::milliseconds(1000); @@ -101,11 +109,21 @@ class SharedMemWatchdog std::atomic_bool exit_thread_; + static ThreadSettings& thread_settings() + { + static ThreadSettings s_settings(ThreadSettings{}); + return s_settings; + } + SharedMemWatchdog() : wake_run_(false) , exit_thread_(false) { - thread_run_ = std::thread(&SharedMemWatchdog::run, this); + auto fn = [this]() + { + run(); + }; + thread_run_ = create_thread(fn, thread_settings(), "dds.shm.wdog"); } /** @@ -123,8 +141,6 @@ class SharedMemWatchdog void run() { - set_name_to_current_thread("dds.shm.wdog"); - while (!exit_thread_) { { diff --git a/src/cpp/utils/threading.hpp b/src/cpp/utils/threading.hpp index dc28df06dc7..778d8662c35 100644 --- a/src/cpp/utils/threading.hpp +++ b/src/cpp/utils/threading.hpp @@ -15,8 +15,17 @@ #ifndef UTILS__THREADING_HPP_ #define UTILS__THREADING_HPP_ +#include + namespace eprosima { +// Forward declare dependencies +namespace fastdds { +namespace rtps { +struct ThreadSettings; +} // namespace rtps +} // namespace fastdds + /** * @brief Give a name to the thread calling this function. * @@ -55,6 +64,42 @@ void set_name_to_current_thread( uint32_t arg1, uint32_t arg2); + +/** + * @brief Apply thread settings to the thread calling this function. + * + * @param[in] settings Thread settings to apply. + */ +void apply_thread_settings_to_current_thread( + const fastdds::rtps::ThreadSettings& settings); + +/** + * @brief Create and start a thread with custom settings and name. + * + * This wrapper will create a thread on which the incoming functor will be called after + * applying giving it a custom name and applying the thread settings. + * + * @param[in] func Functor with the logic to be run on the created thread. + * @param[in] settings Thread settings to apply to the created thread. + * @param[in] name Name (format) for the created thread. + * @param[in] args Additional arguments to complete the thread name. + * See @ref set_name_to_current_thread for details. + */ +template +std::thread create_thread( + Functor func, + const fastdds::rtps::ThreadSettings& settings, + const char* name, + Args... args) +{ + return std::thread([=]() + { + apply_thread_settings_to_current_thread(settings); + set_name_to_current_thread(name, args ...); + func(); + }); +} + } // eprosima #endif // UTILS__THREADING_HPP_ diff --git a/src/cpp/utils/threading/threading_empty.ipp b/src/cpp/utils/threading/threading_empty.ipp index 30d97890bca..684664fc29a 100644 --- a/src/cpp/utils/threading/threading_empty.ipp +++ b/src/cpp/utils/threading/threading_empty.ipp @@ -32,4 +32,9 @@ void set_name_to_current_thread( { } +void apply_thread_settings_to_current_thread( + const fastdds::rtps::ThreadSettings& /*settings*/) +{ +} + } // namespace eprosima diff --git a/src/cpp/utils/threading/threading_osx.ipp b/src/cpp/utils/threading/threading_osx.ipp index efb215bd99b..3131d3642a7 100644 --- a/src/cpp/utils/threading/threading_osx.ipp +++ b/src/cpp/utils/threading/threading_osx.ipp @@ -12,9 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include +#include + #include -#include -#include + +#include +#include namespace eprosima { @@ -48,4 +53,81 @@ void set_name_to_current_thread( set_name_to_current_thread_impl(fmt, arg1, arg2); } +static void configure_current_thread_scheduler( + int sched_class, + int sched_priority) +{ + pthread_t self_tid = pthread_self(); + sched_param param; + sched_param current_param; + int current_class; + int result = 0; + bool change_priority = (std::numeric_limits::min() != sched_priority); + + // Get current scheduling parameters + memset(¤t_param, 0, sizeof(current_param)); + pthread_getschedparam(self_tid, ¤t_class, ¤t_param); + + memset(¶m, 0, sizeof(param)); + param.sched_priority = 0; + sched_class = (sched_class == -1) ? current_class : sched_class; + + // + // Set Scheduler Class and Priority + // + + if((sched_class == SCHED_OTHER) || + (sched_class == SCHED_BATCH) || + (sched_class == SCHED_IDLE)) + { + // + // BATCH and IDLE do not have explicit priority values. + // - Requires priorty value to be zero (0). + + result = pthread_setschedparam(self_tid, sched_class, ¶m); + + // + // Sched OTHER has a nice value, that we pull from the priority parameter. + // + + if(sched_class == SCHED_OTHER && change_priority) + { + result = setpriority(PRIO_PROCESS, gettid(), sched_priority); + } + } + else if((sched_class == SCHED_FIFO) || + (sched_class == SCHED_RR)) + { + // + // RT Policies use a different priority numberspace. + // + + param.sched_priority = change_priority ? sched_priority : current_param.sched_priority; + result = pthread_setschedparam(self_tid, sched_class, ¶m); + } + + if (0 != result) + { + EPROSIMA_LOG_ERROR(SYSTEM, "Error '" << strerror(result) << "' configuring scheduler for thread " << self_tid); + } +} + +static void configure_current_thread_affinity( + uint64_t affinity) +{ + if (affinity <= static_cast(std::numeric_limits::max())) + { + thread_affinity_policy_data_t policy = { static_cast(affinity) }; + pthread_t self_tid = pthread_self(); + thread_policy_set(pthread_mach_thread_np(self_tid), THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1); + } +} + +void apply_thread_settings_to_current_thread( + const fastdds::rtps::ThreadSettings& settings) +{ + configure_current_thread_scheduler(settings.scheduling_policy, settings.priority); + configure_current_thread_affinity(settings.affinity); +} + } // namespace eprosima diff --git a/src/cpp/utils/threading/threading_pthread.ipp b/src/cpp/utils/threading/threading_pthread.ipp index 1090d9939c0..5803c3464e1 100644 --- a/src/cpp/utils/threading/threading_pthread.ipp +++ b/src/cpp/utils/threading/threading_pthread.ipp @@ -12,9 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include +#include + #include -#include -#include +#include +#include +#include +#include + +#include +#include namespace eprosima { @@ -49,4 +58,120 @@ void set_name_to_current_thread( set_name_to_current_thread_impl(fmt, arg1, arg2); } +static void configure_current_thread_scheduler( + int sched_class, + int sched_priority) +{ + pthread_t self_tid = pthread_self(); + sched_param param; + sched_param current_param; + int current_class; + int result = 0; + bool change_priority = (std::numeric_limits::min() != sched_priority); + + // Get current scheduling parameters + memset(¤t_param, 0, sizeof(current_param)); + pthread_getschedparam(self_tid, ¤t_class, ¤t_param); + + memset(¶m, 0, sizeof(param)); + param.sched_priority = 0; + sched_class = (sched_class == -1) ? current_class : sched_class; + + // + // Set Scheduler Class and Priority + // + + if((sched_class == SCHED_OTHER) || + (sched_class == SCHED_BATCH) || + (sched_class == SCHED_IDLE)) + { + // + // BATCH and IDLE do not have explicit priority values. + // - Requires priorty value to be zero (0). + + result = pthread_setschedparam(self_tid, sched_class, ¶m); + + // + // Sched OTHER has a nice value, that we pull from the priority parameter. + // + + if(sched_class == SCHED_OTHER && change_priority) + { + result = setpriority(PRIO_PROCESS, gettid(), sched_priority); + } + } + else if((sched_class == SCHED_FIFO) || + (sched_class == SCHED_RR)) + { + // + // RT Policies use a different priority numberspace. + // + + param.sched_priority = change_priority ? sched_priority : current_param.sched_priority; + result = pthread_setschedparam(self_tid, sched_class, ¶m); + } + + if (0 != result) + { + EPROSIMA_LOG_ERROR(SYSTEM, "Error '" << strerror(result) << "' configuring scheduler for thread " << self_tid); + } +} + +static void configure_current_thread_affinity( + uint64_t affinity_mask) +{ + int a; + int result; + int cpu_count; + cpu_set_t cpu_set; + pthread_t self_tid = pthread_self(); + + result = 0; + + // + // Rebuilt the cpu set from scratch... + // + + CPU_ZERO(&cpu_set); + + // + // If the bit is set in our mask, set it into the cpu_set + // We only consider up to the total number of CPU's the + // system has. + // + cpu_count = get_nprocs_conf(); + + for(a = 0; a < cpu_count; a++) + { + if(0 != (affinity_mask & 1)) + { + CPU_SET(a, &cpu_set); + result++; + } + affinity_mask >>= 1; + } + + if (affinity_mask > 0) + { + EPROSIMA_LOG_ERROR(SYSTEM, "Affinity mask has more processors than the ones present in the system"); + } + + if(result > 0) + { + result = pthread_setaffinity_np(self_tid, sizeof(cpu_set_t), &cpu_set); + } + + if (0 != result) + { + EPROSIMA_LOG_ERROR(SYSTEM, "Error '" << strerror(result) << "' configuring affinity for thread " << self_tid); + } +} + +void apply_thread_settings_to_current_thread( + const fastdds::rtps::ThreadSettings& settings) +{ + configure_current_thread_scheduler(settings.scheduling_policy, settings.priority); + configure_current_thread_affinity(settings.affinity); +} + } // namespace eprosima diff --git a/src/cpp/utils/threading/threading_win32.ipp b/src/cpp/utils/threading/threading_win32.ipp index 1a9f683bd0f..4c3565663f5 100644 --- a/src/cpp/utils/threading/threading_win32.ipp +++ b/src/cpp/utils/threading/threading_win32.ipp @@ -12,10 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include #include +#include + namespace eprosima { template @@ -53,4 +56,35 @@ void set_name_to_current_thread( set_name_to_current_thread_impl(fmt, arg1, arg2); } +static void configure_current_thread_priority( + int32_t priority) +{ + if (priority != std::numeric_limits::min()) + { + if (0 == SetThreadPriority(GetCurrentThread(), priority)) + { + EPROSIMA_LOG_ERROR(SYSTEM, "Error '" << GetLastError() << "' configuring priority for thread " << GetCurrentThread()); + } + } +} + +static void configure_current_thread_affinity( + uint64_t affinity_mask) +{ + if (affinity_mask != 0) + { + if (0 == SetThreadAffinityMask(GetCurrentThread(), affinity_mask)) + { + EPROSIMA_LOG_ERROR(SYSTEM, "Error '" << GetLastError() << "' configuring affinity for thread " << GetCurrentThread()); + } + } +} + +void apply_thread_settings_to_current_thread( + const fastdds::rtps::ThreadSettings& settings) +{ + configure_current_thread_priority(settings.priority); + configure_current_thread_affinity(settings.affinity); +} + } // namespace eprosima diff --git a/test/mock/rtps/RTPSDomain/fastdds/rtps/RTPSDomain.h b/test/mock/rtps/RTPSDomain/fastdds/rtps/RTPSDomain.h index 7cf26913643..4c16829e480 100644 --- a/test/mock/rtps/RTPSDomain/fastdds/rtps/RTPSDomain.h +++ b/test/mock/rtps/RTPSDomain/fastdds/rtps/RTPSDomain.h @@ -16,6 +16,7 @@ #define _FASTDDS_RTPS_DOMAIN_H_ #include +#include #include #include @@ -44,6 +45,12 @@ class RTPSDomain { public: + static void set_filewatch_thread_config( + const fastdds::rtps::ThreadSettings&, + const fastdds::rtps::ThreadSettings&) + { + } + static void stopAll() { } diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index 84af1c34e77..91f89279ef4 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -3002,23 +3002,23 @@ TEST(ParticipantTests, UpdatableDomainParticipantQos) // Check that the builtin_controllers_sender_thread can not be changed in an enabled participant participant->get_qos(pqos); - pqos.builtin_controllers_sender_thread().cpu_mask = 1; + pqos.builtin_controllers_sender_thread().affinity = 1; ASSERT_EQ(participant->set_qos(pqos), ReturnCode_t::RETCODE_IMMUTABLE_POLICY); // Check that the timed_events_thread can not be changed in an enabled participant participant->get_qos(pqos); - pqos.timed_events_thread().cpu_mask = 1; + pqos.timed_events_thread().affinity = 1; ASSERT_EQ(participant->set_qos(pqos), ReturnCode_t::RETCODE_IMMUTABLE_POLICY); // Check that the discovery_server_thread can not be changed in an enabled participant participant->get_qos(pqos); - pqos.discovery_server_thread().cpu_mask = 1; + pqos.discovery_server_thread().affinity = 1; ASSERT_EQ(participant->set_qos(pqos), ReturnCode_t::RETCODE_IMMUTABLE_POLICY); #if HAVE_SECURITY // Check that the security_log_thread can not be changed in an enabled participant participant->get_qos(pqos); - pqos.security_log_thread().cpu_mask = 1; + pqos.security_log_thread().affinity = 1; ASSERT_EQ(participant->set_qos(pqos), ReturnCode_t::RETCODE_IMMUTABLE_POLICY); ASSERT_EQ(DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK); diff --git a/test/unittest/logging/LogTests.cpp b/test/unittest/logging/LogTests.cpp index aee0743b44f..a6caae4cb87 100644 --- a/test/unittest/logging/LogTests.cpp +++ b/test/unittest/logging/LogTests.cpp @@ -664,6 +664,37 @@ TEST_F(LogTests, flush_n) loggind_thread.join(); } +/** + * The goal of this test is to be able to manually check that the thread settings are applied, using an external + * tool like `htop` in Linux. + * It sets some scheduling configuration for the logging thread, and performs one log every second for 10 seconds, + * giving enough time for the tool to show the scheduling configuration and name of said thread. + */ +TEST_F(LogTests, thread_config) +{ + // Set general verbosity + Log::SetVerbosity(Log::Info); + const unsigned int n_logs = 10; + + // Set thread settings + eprosima::fastdds::rtps::ThreadSettings thr_settings{}; +#if defined(_POSIX_SOURCE) + thr_settings.affinity = 3; + thr_settings.scheduling_policy = SCHED_OTHER; + thr_settings.priority = 1; +#endif // if defined(_POSIX_SOURCE) + Log::SetThreadConfig(thr_settings); + + for (unsigned int i = 0; i < n_logs; i++) + { + EPROSIMA_LOG_INFO(TEST_THREADS, "Info message " << i); + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + auto entries = HELPER_WaitForEntries(n_logs); + EXPECT_EQ(entries.size(), n_logs); +} + int main( int argc, char** argv) diff --git a/test/unittest/rtps/attributes/ThreadSettingsTests.cpp b/test/unittest/rtps/attributes/ThreadSettingsTests.cpp index 25a540a2b40..8abce8ff719 100644 --- a/test/unittest/rtps/attributes/ThreadSettingsTests.cpp +++ b/test/unittest/rtps/attributes/ThreadSettingsTests.cpp @@ -27,49 +27,49 @@ TEST(ThreadSettingsTests, EqualOperators) // Fixed scheduling_policy cases settings_2.scheduling_policy = settings_1.scheduling_policy; settings_2.priority = settings_1.priority + 1; - settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.affinity = settings_1.affinity; settings_2.stack_size = settings_1.stack_size; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy; settings_2.priority = settings_1.priority; - settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.affinity = settings_1.affinity + 1; settings_2.stack_size = settings_1.stack_size; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy; settings_2.priority = settings_1.priority; - settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.affinity = settings_1.affinity; settings_2.stack_size = settings_1.stack_size + 1; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy; settings_2.priority = settings_1.priority + 1; - settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.affinity = settings_1.affinity + 1; settings_2.stack_size = settings_1.stack_size; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy; settings_2.priority = settings_1.priority; - settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.affinity = settings_1.affinity + 1; settings_2.stack_size = settings_1.stack_size + 1; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy; settings_2.priority = settings_1.priority + 1; - settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.affinity = settings_1.affinity; settings_2.stack_size = settings_1.stack_size + 1; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy; settings_2.priority = settings_1.priority + 1; - settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.affinity = settings_1.affinity + 1; settings_2.stack_size = settings_1.stack_size + 1; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); @@ -77,43 +77,43 @@ TEST(ThreadSettingsTests, EqualOperators) // Fixed priority cases (not already covered) settings_2.scheduling_policy = settings_1.scheduling_policy + 1; settings_2.priority = settings_1.priority; - settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.affinity = settings_1.affinity; settings_2.stack_size = settings_1.stack_size; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy + 1; settings_2.priority = settings_1.priority; - settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.affinity = settings_1.affinity + 1; settings_2.stack_size = settings_1.stack_size; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy + 1; settings_2.priority = settings_1.priority; - settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.affinity = settings_1.affinity; settings_2.stack_size = settings_1.stack_size + 1; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy + 1; settings_2.priority = settings_1.priority; - settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.affinity = settings_1.affinity + 1; settings_2.stack_size = settings_1.stack_size + 1; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); - // Fixed cpu_mask cases (not already covered) + // Fixed affinity cases (not already covered) settings_2.scheduling_policy = settings_1.scheduling_policy + 1; settings_2.priority = settings_1.priority + 1; - settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.affinity = settings_1.affinity; settings_2.stack_size = settings_1.stack_size; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy + 1; settings_2.priority = settings_1.priority + 1; - settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.affinity = settings_1.affinity; settings_2.stack_size = settings_1.stack_size + 1; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); @@ -121,14 +121,14 @@ TEST(ThreadSettingsTests, EqualOperators) // Fixed stack_size cases (not already covered) settings_2.scheduling_policy = settings_1.scheduling_policy + 1; settings_2.priority = settings_1.priority + 1; - settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.affinity = settings_1.affinity + 1; settings_2.stack_size = settings_1.stack_size; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); settings_2.scheduling_policy = settings_1.scheduling_policy + 1; settings_2.priority = settings_1.priority + 1; - settings_2.cpu_mask = settings_1.cpu_mask; + settings_2.affinity = settings_1.affinity; settings_2.stack_size = settings_1.stack_size + 1; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); @@ -136,7 +136,7 @@ TEST(ThreadSettingsTests, EqualOperators) // All different settings_2.scheduling_policy = settings_1.scheduling_policy + 1; settings_2.priority = settings_1.priority + 1; - settings_2.cpu_mask = settings_1.cpu_mask + 1; + settings_2.affinity = settings_1.affinity + 1; settings_2.stack_size = settings_1.stack_size + 1; ASSERT_FALSE(settings_1 == settings_2); ASSERT_TRUE(settings_1 != settings_2); diff --git a/test/unittest/transport/PortBasedTransportDescriptorTests.cpp b/test/unittest/transport/PortBasedTransportDescriptorTests.cpp index 88c7b5e7021..28bca4a8bab 100644 --- a/test/unittest/transport/PortBasedTransportDescriptorTests.cpp +++ b/test/unittest/transport/PortBasedTransportDescriptorTests.cpp @@ -65,7 +65,7 @@ TEST_F(PortBasedTransportDescriptorTests, get_thread_config_for_port) PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings; set_settings[1234].scheduling_policy = 33; set_settings[1234].priority = 33; - set_settings[1234].cpu_mask = 33; + set_settings[1234].affinity = 33; set_settings[1234].stack_size = 33; ASSERT_TRUE(reception_threads(set_settings)); @@ -86,7 +86,7 @@ TEST_F(PortBasedTransportDescriptorTests, set_thread_config_for_port) PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings; set_settings[1234].scheduling_policy = 33; set_settings[1234].priority = 33; - set_settings[1234].cpu_mask = 33; + set_settings[1234].affinity = 33; set_settings[1234].stack_size = 33; ASSERT_TRUE(reception_threads(set_settings)); @@ -116,7 +116,7 @@ TEST_F(PortBasedTransportDescriptorTests, set_default_reception_threads) ThreadSettings set_settings; set_settings.scheduling_policy = 33; set_settings.priority = 33; - set_settings.cpu_mask = 33; + set_settings.affinity = 33; set_settings.stack_size = 33; ASSERT_NE(initial_settings, set_settings); @@ -137,7 +137,7 @@ TEST_F(PortBasedTransportDescriptorTests, set_reception_threads) PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings; set_settings[1234].scheduling_policy = 33; set_settings[1234].priority = 33; - set_settings[1234].cpu_mask = 33; + set_settings[1234].affinity = 33; set_settings[1234].stack_size = 33; ASSERT_NE(initial_settings, set_settings); @@ -170,7 +170,7 @@ TEST_F(PortBasedTransportDescriptorTests, equal_operator) ThreadSettings set_settings; set_settings.scheduling_policy = 33; set_settings.priority = 33; - set_settings.cpu_mask = 33; + set_settings.affinity = 33; set_settings.stack_size = 33; other.default_reception_threads(set_settings); ASSERT_FALSE(*this == other); @@ -185,7 +185,7 @@ TEST_F(PortBasedTransportDescriptorTests, equal_operator) PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings_map; set_settings_map[1234].scheduling_policy = 33; set_settings_map[1234].priority = 33; - set_settings_map[1234].cpu_mask = 33; + set_settings_map[1234].affinity = 33; set_settings_map[1234].stack_size = 33; ASSERT_TRUE(other.reception_threads(set_settings_map)); ASSERT_FALSE(*this == other); @@ -202,7 +202,7 @@ TEST_F(PortBasedTransportDescriptorTests, equal_operator) ThreadSettings set_settings; set_settings.scheduling_policy = 33; set_settings.priority = 33; - set_settings.cpu_mask = 33; + set_settings.affinity = 33; set_settings.stack_size = 33; other.default_reception_threads(set_settings); @@ -220,7 +220,7 @@ TEST_F(PortBasedTransportDescriptorTests, equal_operator) PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings_map; set_settings_map[1234].scheduling_policy = 33; set_settings_map[1234].priority = 33; - set_settings_map[1234].cpu_mask = 33; + set_settings_map[1234].affinity = 33; set_settings_map[1234].stack_size = 33; ASSERT_TRUE(other.reception_threads(set_settings_map)); @@ -236,14 +236,14 @@ TEST_F(PortBasedTransportDescriptorTests, equal_operator) ThreadSettings set_settings; set_settings.scheduling_policy = 33; set_settings.priority = 33; - set_settings.cpu_mask = 33; + set_settings.affinity = 33; set_settings.stack_size = 33; other.default_reception_threads(set_settings); PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings_map; set_settings_map[1234].scheduling_policy = 33; set_settings_map[1234].priority = 33; - set_settings_map[1234].cpu_mask = 33; + set_settings_map[1234].affinity = 33; set_settings_map[1234].stack_size = 33; ASSERT_TRUE(other.reception_threads(set_settings_map)); @@ -261,14 +261,14 @@ TEST_F(PortBasedTransportDescriptorTests, equal_operator) ThreadSettings set_settings; set_settings.scheduling_policy = 33; set_settings.priority = 33; - set_settings.cpu_mask = 33; + set_settings.affinity = 33; set_settings.stack_size = 33; other.default_reception_threads(set_settings); PortBasedTransportDescriptor::ReceptionThreadsConfigMap set_settings_map; set_settings_map[1234].scheduling_policy = 33; set_settings_map[1234].priority = 33; - set_settings_map[1234].cpu_mask = 33; + set_settings_map[1234].affinity = 33; set_settings_map[1234].stack_size = 33; ASSERT_TRUE(other.reception_threads(set_settings_map)); diff --git a/test/unittest/utils/CMakeLists.txt b/test/unittest/utils/CMakeLists.txt index 893eaeb519c..97cdb5ff8bc 100644 --- a/test/unittest/utils/CMakeLists.txt +++ b/test/unittest/utils/CMakeLists.txt @@ -48,6 +48,10 @@ set(FIXEDSIZEQUEUETESTS_SOURCE set(SYSTEMINFOTESTS_SOURCE SystemInfoTests.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp) include_directories(mock/) diff --git a/test/unittest/utils/SystemInfoTests.cpp b/test/unittest/utils/SystemInfoTests.cpp index 3b8238268c0..d94a6e4bb34 100644 --- a/test/unittest/utils/SystemInfoTests.cpp +++ b/test/unittest/utils/SystemInfoTests.cpp @@ -238,7 +238,7 @@ TEST_F(SystemInfoTests, FileWatchTest) eprosima::SystemInfo::wait_for_file_closure(filename, _1s); ++times_called_; cv_.notify_all(); - }); + }, {}, {}); std::this_thread::sleep_for(_1s); diff --git a/thirdparty/filewatch/FileWatch.hpp b/thirdparty/filewatch/FileWatch.hpp index a714d284953..37c462762d9 100644 --- a/thirdparty/filewatch/FileWatch.hpp +++ b/thirdparty/filewatch/FileWatch.hpp @@ -23,6 +23,8 @@ #ifndef FILEWATCHER_H #define FILEWATCHER_H +#include + #include #ifdef _WIN32 @@ -67,6 +69,7 @@ #include #include +namespace eprosima { namespace filewatch { enum class Event { added, @@ -93,35 +96,33 @@ namespace filewatch { public: - FileWatch(T path, UnderpinningRegex pattern, std::function callback) : - _path(path), - _pattern(pattern), - _callback(callback), - _directory(get_directory(path)) + FileWatch( + T path, + UnderpinningRegex pattern, + std::function callback, + const fastdds::rtps::ThreadSettings& watch_thread_config, + const fastdds::rtps::ThreadSettings& callback_thread_config) + : _path(path) + , _pattern(pattern) + , _callback(callback) + , _directory(get_directory(path)) { - init(); + init(watch_thread_config, callback_thread_config); } - FileWatch(T path, std::function callback) : - FileWatch(path, UnderpinningRegex(_regex_all), callback) {} + FileWatch( + T path, + std::function callback, + const fastdds::rtps::ThreadSettings& watch_thread_config, + const fastdds::rtps::ThreadSettings& callback_thread_config) + : FileWatch(path, UnderpinningRegex(_regex_all), callback, watch_thread_config, callback_thread_config) {} ~FileWatch() { destroy(); } - FileWatch(const FileWatch& other) : FileWatch(other._path, other._callback) {} - - FileWatch& operator=(const FileWatch& other) - { - if (this == &other) { return *this; } - - destroy(); - _path = other._path; - _callback = other._callback; - _directory = get_directory(other._path); - init(); - return *this; - } + FileWatch(const FileWatch& other) = delete; + FileWatch& operator=(const FileWatch& other) = delete; // Const memeber varibles don't let me implent moves nicely, if moves are really wanted std::unique_ptr should be used and move that. FileWatch(FileWatch&&) = delete; @@ -201,7 +202,9 @@ namespace filewatch { const static std::size_t event_size = (sizeof(struct inotify_event)); #endif // __unix__ - void init() + void init( + const fastdds::rtps::ThreadSettings& watch_thread_config = {}, + const fastdds::rtps::ThreadSettings& callback_thread_config = {}) { #ifdef _WIN32 _close_event = CreateEvent(NULL, TRUE, FALSE, NULL); @@ -209,9 +212,8 @@ namespace filewatch { throw std::system_error(GetLastError(), std::system_category()); } #endif // WIN32 - _callback_thread = std::move(std::thread([this]() { + _callback_thread = create_thread([this]() { try { - eprosima::set_name_to_current_thread("dds.fwatch.cb"); callback_thread(); } catch (...) { try { @@ -219,10 +221,9 @@ namespace filewatch { } catch (...) {} // set_exception() may throw too } - })); - _watch_thread = std::move(std::thread([this]() { + }, callback_thread_config, "dds.fwatch.cb"); + _watch_thread = create_thread([this]() { try { - eprosima::set_name_to_current_thread("dds.fwatch"); monitor_directory(); } catch (...) { try { @@ -230,7 +231,7 @@ namespace filewatch { } catch (...) {} // set_exception() may throw too } - })); + }, watch_thread_config, "dds.fwatch"); std::future future = _running.get_future(); future.get(); //block until the monitor_directory is up and running @@ -624,5 +625,6 @@ namespace filewatch { template constexpr typename FileWatch::C FileWatch::_regex_all[]; template constexpr typename FileWatch::C FileWatch::_this_directory[]; -} +} // namespace filewatch +} // namespace eprosima #endif From d37d11e08722cb4c801d52bc5bda4e5ae4793343 Mon Sep 17 00:00:00 2001 From: Eduardo Ponz Segrelles Date: Thu, 26 Oct 2023 10:00:28 +0200 Subject: [PATCH 5/9] Add XML support for ThreadSettings (#3922) * Refs #19378: Add threadSettingsTypes to XSD schema Signed-off-by: EduPonz * Refs #19378: Add unit test for parsing thread_settings XML elements Signed-off-by: EduPonz * Refs #19378: Add getXMLThreadSettings to XMLElementParser Signed-off-by: EduPonz * Refs #19378: Add Log test cases to XMLProfileParserBasicTests.thread_settings_qos test Signed-off-by: EduPonz * Refs #19378: Add XML ThreadSettings config to Log Signed-off-by: EduPonz * Refs #19378: Add domainparticipant_factory XML tag tests Signed-off-by: EduPonz * Refs #19378: Add domainparticipant_factory XSD Signed-off-by: EduPonz * Refs #19378: Add XML ThreadSettings config to DomainParticipantFactory Signed-off-by: EduPonz * Refs #19378: Add getXMLEntityFactoryQos unit test Signed-off-by: EduPonz * Refs #19378: Add domainparticipant XML thread settings tests Signed-off-by: EduPonz * Refs #19378: Add XML ThreadSettings config to DomainParticipant Signed-off-by: EduPonz * Refs #19378: Uncrustify Signed-off-by: EduPonz * Refs #19378: Add parseXMLReceptionThreads API & unit test Signed-off-by: EduPonz * Refs #19378: Add transport descriptor XML thread settings tests Signed-off-by: EduPonz * Refs #19378: Add parseXMLReceptionThreads implementation Signed-off-by: EduPonz * Refs #19378: Add transport descriptor XML thread settings config Signed-off-by: EduPonz * Refs #19378: Add datareader XML thread settings tests Signed-off-by: EduPonz * Refs #19378: Add datareader XML thread settings Signed-off-by: EduPonz * Refs #19378: Add builtin_transports_reception_threads to domainparticipant XML test Signed-off-by: EduPonz * Refs #19378: Add builtin_transports_reception_threads to domainparticipant XML Signed-off-by: EduPonz * Refs #19378: Fix Windows warning regarding sscanf Signed-off-by: EduPonz * Refs #19378: Fix flow controllers unittests build when using Fast CDR as thirdparty Signed-off-by: EduPonz * Refs #19378: Apply Miguel's suggestions Signed-off-by: EduPonz * Refs #19378: Apply some other suggestions Signed-off-by: EduPonz * Refs #19378. OSx has neither `SCHED_BATCH` nor `SCHED_IDLE` Signed-off-by: Miguel Company * Refs #19378. Check result on pthread_setschedparam Signed-off-by: Miguel Company * Refs #19378. Add include on `threading_osx.ipp` Signed-off-by: Miguel Company * Refs #19378. Avoid using gettid on `threading_osx.ipp` Signed-off-by: Miguel Company * Refs #19378: Fix mac warning Signed-off-by: EduPonz --------- Signed-off-by: EduPonz Signed-off-by: Miguel Company Co-authored-by: Miguel Company --- .../fastdds/dds/core/policy/QosPolicies.hpp | 36 + .../dds/subscriber/qos/DataReaderQos.hpp | 38 +- .../attributes/RTPSParticipantAttributes.h | 12 +- include/fastrtps/xmlparser/XMLParser.h | 79 +- include/fastrtps/xmlparser/XMLParserCommon.h | 22 + .../fastrtps/xmlparser/XMLProfileManager.h | 45 +- include/fastrtps/xmlparser/XMLTree.h | 3 +- resources/xsd/fastRTPS_profiles.xsd | 217 +++-- src/cpp/fastdds/subscriber/DataReaderImpl.cpp | 4 +- .../rtps/participant/RTPSParticipantImpl.cpp | 2 + src/cpp/rtps/xmlparser/XMLElementParser.cpp | 334 ++++++- src/cpp/rtps/xmlparser/XMLParser.cpp | 465 +++++++-- src/cpp/rtps/xmlparser/XMLParserCommon.cpp | 22 + src/cpp/rtps/xmlparser/XMLProfileManager.cpp | 82 +- src/cpp/utils/threading/threading_osx.ipp | 21 +- src/cpp/utils/threading/threading_pthread.ipp | 2 +- test/mock/rtps/Log/fastdds/dds/log/Log.hpp | 12 + .../shared_mem/SharedMemTransportDescriptor.h | 18 + .../XMLTesterExample_profile.xml | 7 + .../tools/xmlvalidation/all_profile.xml | 7 + .../profiles/test_xml_for_string_profile.xml | 60 ++ .../dds/profiles/test_xml_profile.xml | 60 ++ .../dds/subscriber/DataReaderTests.cpp | 8 +- test/unittest/rtps/builtin/CMakeLists.txt | 54 +- test/unittest/rtps/discovery/CMakeLists.txt | 41 +- test/unittest/rtps/network/CMakeLists.txt | 36 +- ...M_transport_descriptors_config_profile.xml | 26 + ...P_transport_descriptors_config_profile.xml | 54 +- .../xmlparser/XMLElementParserTests.cpp | 215 ++++ test/unittest/xmlparser/XMLParserTests.cpp | 279 +++++- .../xmlparser/XMLProfileParserTests.cpp | 917 +++++++++++++++++- .../xmlparser/log_def_file_profile.xml | 6 + .../xmlparser/test_xml_deprecated.xml | 30 + test/unittest/xmlparser/test_xml_profile.xml | 49 + .../xmlparser/test_xml_profile_env_var.xml | 49 + .../xmlparser/test_xml_rooted_deprecated.xml | 30 + .../xmlparser/test_xml_rooted_profile.xml | 49 + .../xmlparser/wrapper/XMLParserTest.hpp | 40 + 38 files changed, 3076 insertions(+), 355 deletions(-) diff --git a/include/fastdds/dds/core/policy/QosPolicies.hpp b/include/fastdds/dds/core/policy/QosPolicies.hpp index 964cfaae070..fcdb9d5a4bf 100644 --- a/include/fastdds/dds/core/policy/QosPolicies.hpp +++ b/include/fastdds/dds/core/policy/QosPolicies.hpp @@ -2951,6 +2951,7 @@ class DataSharingQosPolicy : public Parameter_t, public QosPolicy max_domains_ : b.domain_ids().size()); domain_ids_ = b.domain_ids(); + data_sharing_listener_thread_ = b.data_sharing_listener_thread(); return *this; } @@ -2961,6 +2962,7 @@ class DataSharingQosPolicy : public Parameter_t, public QosPolicy return kind_ == b.kind_ && shm_directory_ == b.shm_directory_ && domain_ids_ == b.domain_ids_ && + data_sharing_listener_thread_ == b.data_sharing_listener_thread_ && Parameter_t::operator ==(b) && QosPolicy::operator ==(b); } @@ -3137,6 +3139,37 @@ class DataSharingQosPolicy : public Parameter_t, public QosPolicy } } + /** + * Getter for DataSharing listener thread ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + rtps::ThreadSettings& data_sharing_listener_thread() + { + return data_sharing_listener_thread_; + } + + /** + * Getter for DataSharing listener thread ThreadSettings + * + * @return rtps::ThreadSettings reference + */ + const rtps::ThreadSettings& data_sharing_listener_thread() const + { + return data_sharing_listener_thread_; + } + + /** + * Setter for the DataSharing listener thread ThreadSettings + * + * @param value New ThreadSettings to be set + */ + void data_sharing_listener_thread( + const rtps::ThreadSettings& value) + { + data_sharing_listener_thread_ = value; + } + private: void setup( @@ -3165,6 +3198,9 @@ class DataSharingQosPolicy : public Parameter_t, public QosPolicy //! Only endpoints with matching domain IDs are DataSharing compatible std::vector domain_ids_; + + //! Thread settings for the DataSharing listener thread + rtps::ThreadSettings data_sharing_listener_thread_; }; diff --git a/include/fastdds/dds/subscriber/qos/DataReaderQos.hpp b/include/fastdds/dds/subscriber/qos/DataReaderQos.hpp index 046babaf8b7..6dc01c45f34 100644 --- a/include/fastdds/dds/subscriber/qos/DataReaderQos.hpp +++ b/include/fastdds/dds/subscriber/qos/DataReaderQos.hpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -208,8 +207,7 @@ class DataReaderQos (properties_ == b.properties()) && (endpoint_ == b.endpoint()) && (reader_resource_limits_ == b.reader_resource_limits()) && - (data_sharing_ == b.data_sharing()) && - (data_sharing_listener_thread_ == b.data_sharing_listener_thread()); + (data_sharing_ == b.data_sharing()); } RTPS_DllAPI ReaderQos get_readerqos( @@ -856,37 +854,6 @@ class DataReaderQos data_sharing_ = data_sharing; } - /** - * Getter for data sharing listener ThreadSettings - * - * @return rtps::ThreadSettings reference - */ - RTPS_DllAPI rtps::ThreadSettings& data_sharing_listener_thread() - { - return data_sharing_listener_thread_; - } - - /** - * Getter for data sharing listener ThreadSettings - * - * @return rtps::ThreadSettings reference - */ - RTPS_DllAPI const rtps::ThreadSettings& data_sharing_listener_thread() const - { - return data_sharing_listener_thread_; - } - - /** - * Setter for data sharing listener ThreadSettings - * - * @param data_sharing_listener_thread new value for the rtps::ThreadSettings - */ - RTPS_DllAPI void data_sharing_listener_thread( - const rtps::ThreadSettings& data_sharing_listener_thread) - { - data_sharing_listener_thread_ = data_sharing_listener_thread; - } - private: //!Durability Qos, implemented in the library. @@ -951,9 +918,6 @@ class DataReaderQos //!DataSharing configuration (Extension) DataSharingQosPolicy data_sharing_; - - //! Thread settings for the data-sharing listener thread - rtps::ThreadSettings data_sharing_listener_thread_; }; RTPS_DllAPI extern const DataReaderQos DATAREADER_QOS_DEFAULT; diff --git a/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h b/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h index ea73277ca7a..78d74be6690 100644 --- a/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h +++ b/include/fastdds/rtps/attributes/RTPSParticipantAttributes.h @@ -487,7 +487,14 @@ class RTPSParticipantAttributes (this->properties == b.properties) && (this->prefix == b.prefix) && (this->flow_controllers == b.flow_controllers) && - (this->builtin_controllers_sender_thread == b.builtin_controllers_sender_thread); + (this->builtin_controllers_sender_thread == b.builtin_controllers_sender_thread) && + (this->timed_events_thread == b.timed_events_thread) && +#if HAVE_SECURITY + (this->security_log_thread == b.security_log_thread) && +#endif // if HAVE_SECURITY + (this->discovery_server_thread == b.discovery_server_thread) && + (this->builtin_transports_reception_threads == b.builtin_transports_reception_threads); + } /** @@ -588,6 +595,9 @@ class RTPSParticipantAttributes //! Thread settings for the discovery server thread fastdds::rtps::ThreadSettings discovery_server_thread; + //! Thread settings for the builtin transports reception threads + fastdds::rtps::ThreadSettings builtin_transports_reception_threads; + #if HAVE_SECURITY //! Thread settings for the security log thread fastdds::rtps::ThreadSettings security_log_thread; diff --git a/include/fastrtps/xmlparser/XMLParser.h b/include/fastrtps/xmlparser/XMLParser.h index 980d24a7641..9799280d5a0 100644 --- a/include/fastrtps/xmlparser/XMLParser.h +++ b/include/fastrtps/xmlparser/XMLParser.h @@ -15,19 +15,26 @@ #ifndef XML_PARSER_H_ #define XML_PARSER_H_ -#include -#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include +#include +#include +#include #include -#include - -#include -#include +#include namespace tinyxml2 { class XMLElement; @@ -52,6 +59,11 @@ typedef std::map sp_transport_map_t; typedef types::DynamicTypeBuilder* p_dynamictypebuilder_t; typedef std::map p_dynamictype_map_t; +typedef std::unique_ptr up_participantfactory_t; +typedef DataNode node_participantfactory_t; +typedef node_participantfactory_t* p_node_participantfactory_t; +typedef std::unique_ptr up_node_participantfactory_t; + typedef std::unique_ptr up_participant_t; typedef DataNode node_participant_t; typedef node_participant_t* p_node_participant_t; @@ -177,6 +189,10 @@ class XMLParser RTPS_DllAPI static XMLP_ret parseXMLTransportsProf( tinyxml2::XMLElement* p_root); + RTPS_DllAPI static XMLP_ret parseXMLDomainParticipantFactoryProf( + tinyxml2::XMLElement* p_root, + BaseNode& rootNode); + RTPS_DllAPI static XMLP_ret parseXMLParticipantProf( tinyxml2::XMLElement* p_root, BaseNode& rootNode); @@ -204,10 +220,21 @@ class XMLParser RTPS_DllAPI static XMLP_ret parseXMLTransportData( tinyxml2::XMLElement* p_root); + RTPS_DllAPI static XMLP_ret validateXMLTransportElements( + tinyxml2::XMLElement& p_root); + RTPS_DllAPI static XMLP_ret parseXMLCommonTransportData( tinyxml2::XMLElement* p_root, sp_transport_t p_transport); + RTPS_DllAPI static XMLP_ret parseXMLPortBasedTransportData( + tinyxml2::XMLElement* p_root, + std::shared_ptr p_transport); + + RTPS_DllAPI static XMLP_ret parseXMLSocketTransportData( + tinyxml2::XMLElement* p_root, + std::shared_ptr p_transport); + RTPS_DllAPI static XMLP_ret parseXMLCommonTCPTransportData( tinyxml2::XMLElement* p_root, sp_transport_t p_transport); @@ -220,6 +247,10 @@ class XMLParser tinyxml2::XMLElement* p_root, sp_transport_t tcp_transport); + RTPS_DllAPI static XMLP_ret parseXMLReceptionThreads( + tinyxml2::XMLElement& p_root, + fastdds::rtps::PortBasedTransportDescriptor::ReceptionThreadsConfigMap& reception_threads); + /** * Load a XML consumer node and parses it. Adds the parsed consumer to Log directly. * @param consumer Node to be loaded. @@ -280,6 +311,10 @@ class XMLParser types::MemberId mId, const std::string& values); + RTPS_DllAPI static XMLP_ret fillDataNode( + tinyxml2::XMLElement* p_profile, + DataNode& factory_node); + RTPS_DllAPI static XMLP_ret fillDataNode( tinyxml2::XMLElement* p_profile, DataNode& participant_node); @@ -549,6 +584,11 @@ class XMLParser uint16_t* ui16, uint8_t ident); + RTPS_DllAPI static XMLP_ret getXMLUint( + tinyxml2::XMLElement* elem, + uint64_t* ui64, + uint8_t ident); + RTPS_DllAPI static XMLP_ret getXMLBool( tinyxml2::XMLElement* elem, bool* b, @@ -599,6 +639,10 @@ class XMLParser rtps::GuidPrefix_t& prefix, uint8_t ident); + RTPS_DllAPI static XMLP_ret getXMLDomainParticipantFactoryQos( + tinyxml2::XMLElement& elem, + fastdds::dds::DomainParticipantFactoryQos& qos); + RTPS_DllAPI static XMLP_ret getXMLPublisherAttributes( tinyxml2::XMLElement* elem, PublisherAttributes& publisher, @@ -608,6 +652,23 @@ class XMLParser tinyxml2::XMLElement* elem, SubscriberAttributes& subscriber, uint8_t ident); + + RTPS_DllAPI static XMLP_ret getXMLThreadSettings( + tinyxml2::XMLElement& elem, + fastdds::rtps::ThreadSettings& thread_setting); + + /* + Return XMLP_ret::XML_OK when OK, XMLP_ret::XML_NOK when port attribute is not present, and + XMLP_ret::XML_ERROR if error + */ + RTPS_DllAPI static XMLP_ret getXMLThreadSettingsWithPort( + tinyxml2::XMLElement& elem, + fastdds::rtps::ThreadSettings& thread_setting, + uint32_t& port); + + RTPS_DllAPI static XMLP_ret getXMLEntityFactoryQos( + tinyxml2::XMLElement& elem, + fastdds::dds::EntityFactoryQosPolicy& entity_factory); }; } // namespace xmlparser diff --git a/include/fastrtps/xmlparser/XMLParserCommon.h b/include/fastrtps/xmlparser/XMLParserCommon.h index 227f58cde6e..ac16431ec0d 100644 --- a/include/fastrtps/xmlparser/XMLParserCommon.h +++ b/include/fastrtps/xmlparser/XMLParserCommon.h @@ -42,6 +42,7 @@ extern const char* LIBRARY_SETTINGS; extern const char* TRANSPORT_DESCRIPTORS; extern const char* PROFILE_NAME; extern const char* DEFAULT_PROF; +extern const char* DOMAINPARTICIPANT_FACTORY; extern const char* PARTICIPANT; extern const char* PUBLISHER; extern const char* SUBSCRIBER; @@ -80,8 +81,17 @@ extern const char* HEALTHY_CHECK_TIMEOUT_MS; extern const char* DISCARD; extern const char* FAIL; extern const char* RTPS_DUMP_FILE; +extern const char* DEFAULT_RECEPTION_THREADS; +extern const char* RECEPTION_THREADS; +extern const char* RECEPTION_THREAD; +extern const char* DUMP_THREAD; extern const char* ON; extern const char* AUTO; +extern const char* THREAD_SETTINGS; +extern const char* SCHEDULING_POLICY; +extern const char* PRIORITY; +extern const char* AFFINITY; +extern const char* STACK_SIZE; // IntraprocessDeliveryType extern const char* OFF; @@ -98,6 +108,12 @@ extern const char* DATA_READER; /// LibrarySettings attributes extern const char* INTRAPROCESS_DELIVERY; +/// DomainParticipantFactory Qos +extern const char* ENTITY_FACTORY; +extern const char* AUTOENABLE_CREATED_ENTITIES; +extern const char* SHM_WATCHDOG_THREAD; +extern const char* FILE_WATCH_THREADS; + /// RTPS Participant attributes extern const char* ALLOCATION; extern const char* PREFIX; @@ -132,6 +148,11 @@ extern const char* DYNAMIC_LC; extern const char* MAX_PROPERTIES; extern const char* MAX_USER_DATA; extern const char* MAX_PARTITIONS; +extern const char* TIMED_EVENTS_THREAD; +extern const char* DISCOVERY_SERVER_THREAD; +extern const char* SECURITY_LOG_THREAD; +extern const char* BUILTIN_TRANSPORTS_RECEPTION_THREADS; +extern const char* BUILTIN_CONTROLLERS_SENDER_THREAD; /// Publisher-subscriber attributes extern const char* TOPIC; @@ -149,6 +170,7 @@ extern const char* USER_DEF_ID; extern const char* ENTITY_ID; extern const char* MATCHED_SUBSCRIBERS_ALLOCATION; extern const char* MATCHED_PUBLISHERS_ALLOCATION; +extern const char* DATA_SHARING_LISTENER_THREAD; /// extern const char* IGN_NON_MATCHING_LOCS; diff --git a/include/fastrtps/xmlparser/XMLProfileManager.h b/include/fastrtps/xmlparser/XMLProfileManager.h index bb934e3b978..d94996a7451 100644 --- a/include/fastrtps/xmlparser/XMLProfileManager.h +++ b/include/fastrtps/xmlparser/XMLProfileManager.h @@ -15,23 +15,26 @@ #ifndef XML_PROFILE_MANAGER_H_ #define XML_PROFILE_MANAGER_H_ +#include +#include +#include + +#include #include #include #include -#include -#include -#include -#include #include - -#include -#include -#include +#include +#include +#include +#include namespace eprosima { namespace fastrtps { namespace xmlparser { +using participant_factory_map_t = std::map; +using part_factory_map_iterator_t = participant_factory_map_t::iterator; using participant_map_t = std::map; using part_map_iterator_t = participant_map_t::iterator; using publisher_map_t = std::map; @@ -135,6 +138,25 @@ class XMLProfileManager RTPS_DllAPI static void getDefaultParticipantAttributes( ParticipantAttributes& participant_attributes); + /** + * Search for the profile specified and fill the structure. + * @param profile_name Name for the profile to be used to fill the structure. + * @param qos Structure to be filled. + * @param log_error Flag to log an error if the profile_name is not found. Defaults true. + * @return XMLP_ret::XML_OK on success, XMLP_ret::XML_ERROR in other case. + */ + RTPS_DllAPI static XMLP_ret fillDomainParticipantFactoryQos( + const std::string& profile_name, + fastdds::dds::DomainParticipantFactoryQos& qos, + bool log_error = true); + + /** + * Fills input domain participant factory qos with the default values. + * @param qos Structure to be filled. + */ + RTPS_DllAPI static void getDefaultDomainParticipantFactoryQos( + fastdds::dds::DomainParticipantFactoryQos& qos); + /** * Search for the profile specified and fill the structure. * @param profile_name Name for the profile to be used to fill the structure. @@ -227,6 +249,7 @@ class XMLProfileManager */ RTPS_DllAPI static void DeleteInstance() { + participant_factory_profiles_.clear(); participant_profiles_.clear(); publisher_profiles_.clear(); subscriber_profiles_.clear(); @@ -268,6 +291,10 @@ class XMLProfileManager up_base_node_t properties, const std::string& filename); + RTPS_DllAPI static XMLP_ret extractDomainParticipantFactoryProfile( + up_base_node_t& profile, + const std::string& filename); + RTPS_DllAPI static XMLP_ret extractParticipantProfile( up_base_node_t& profile, const std::string& filename); @@ -296,6 +323,8 @@ class XMLProfileManager static LibrarySettingsAttributes library_settings_; + static participant_factory_map_t participant_factory_profiles_; + static participant_map_t participant_profiles_; static publisher_map_t publisher_profiles_; diff --git a/include/fastrtps/xmlparser/XMLTree.h b/include/fastrtps/xmlparser/XMLTree.h index 8ef44c8867e..2c69442f739 100644 --- a/include/fastrtps/xmlparser/XMLTree.h +++ b/include/fastrtps/xmlparser/XMLTree.h @@ -28,7 +28,8 @@ enum class NodeType LOG, REQUESTER, REPLIER, - LIBRARY_SETTINGS + LIBRARY_SETTINGS, + DOMAINPARTICIPANT_FACTORY }; class BaseNode diff --git a/resources/xsd/fastRTPS_profiles.xsd b/resources/xsd/fastRTPS_profiles.xsd index e03a2237b77..1a7c1310596 100644 --- a/resources/xsd/fastRTPS_profiles.xsd +++ b/resources/xsd/fastRTPS_profiles.xsd @@ -35,14 +35,16 @@ + ├ domainparticipant_factory [0~*], + ├ participant [0~*], + ├ data_writer [0~*], + ├ data_reader [0~*], + ├ transport_descriptors [0~1], + â”” topic [0~*] --> + @@ -61,13 +63,15 @@ + ├ use_default [bool], + ├ consumer [1~*], + â”” thread_settings [threadSettingsType],--> + @@ -93,29 +97,47 @@ + + + + + + + + + + ├ name [string], + ├ defaultUnicastLocatorList [0~1], + ├ defaultMulticastLocatorList [0~1], + ├ default_external_unicast_locators [0~1], + ├ ignore_non_matching_locators [bool], + ├ sendSocketBufferSize [uint32], + ├ listenSocketBufferSize [uint32], + ├ builtin [0~1], + ├ port [0~1], + ├ participantID [int32], + ├ userTransports [0~1], + | â”” transport_id [1~*] [string], + ├ useBuiltinTransports [bool], + ├ propertiesPolicy [0~1], + ├ allocation [0~1], + ├ userData [0~1], + ├ prefix [0~1], + ├ builtin_controllers_sender_thread [threadSettingsType], + ├ timed_events_thread [threadSettingsType], + ├ discovery_server_thread [threadSettingsType], + ├ builtin_transports_reception_threads [threadSettingsType], + â”” security_log_thread [threadSettingsType]--> @@ -145,6 +167,11 @@ + + + + + @@ -805,33 +832,36 @@ + ├ transport_id [string], + ├ type [string] ("UDPv4", "UDPv6", "TCPv4", "TCPv6", "SHM"), + ├ sendBufferSize [uint32], + ├ receiveBufferSize [uint32], + ├ maxMessageSize [uint32], + ├ maxInitialPeersRange [uint32], + ├ interfaceWhiteList [0~*], (NOT available for SHM type) + | â”” address [ipv4Address|ipv6Address] + ├ TTL [uint8], (ONLY available for UDP type) + ├ non_blocking_send [boolean], (ONLY available for UDP type) + ├ output_port [uint16], (ONLY available for UDP type) + ├ wan_addr [ipv4AddressFormat], (ONLY available for TCPv4 type) + ├ keep_alive_frequency_ms [uint32], (ONLY available for TCP type) + ├ keep_alive_timeout_ms [uint32], (ONLY available for TCP type) + ├ max_logical_port [uint16], (ONLY available for TCP type) + ├ logical_port_range [uint16], (ONLY available for TCP type) + ├ logical_port_increment [uint16], (ONLY available for TCP type) + ├ listening_ports [0~*], (ONLY available for TCP type) + | â”” port [uint16] (ONLY available for TCP type) + ├ tls [0~1], (ONLY available for TCP type) + ├ calculate_crc [bool], (ONLY available for TCP type) + ├ check_crc [bool], (ONLY available for TCP type) + ├ enable_tcp_nodelay [bool], (ONLY available for TCP type) + ├ segment_size [uint32], (ONLY available for SHM type) + ├ port_queue_capacity [uint32], (ONLY available for SHM type) + ├ healthy_check_timeout_ms [uint32], (ONLY available for SHM type) + ├ rtps_dump_file [string] (ONLY available for SHM type) + ├ default_reception_threads [threadSettingsType] + ├ reception_threads [receptionThreadsListType] (ONLY available for SHM type) + â”” dump_thread [threadSettingsType] (ONLY available for SHM type) --> @@ -886,6 +916,9 @@ + + + @@ -1078,6 +1111,18 @@ + + + + + + + + + @@ -1153,7 +1197,6 @@ - @@ -1331,11 +1374,12 @@ + ├ kind [string] ("AUTOMATIC", "ON", "OFF"), + ├ shared_dir [string], + ├ domain_ids [0~*], + | â”” domainID [uint32] + ├ max_domains [uint32] + â”” data_sharing_listener_thread [0~1]--> @@ -1351,11 +1395,12 @@ - + + @@ -1429,13 +1474,11 @@ - + + + + + + + + + + + + + + + + + + + + + + + + @@ -1818,6 +1899,16 @@ + + + + + + + + + + diff --git a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp index f21d339f7c2..377e40012d1 100644 --- a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp +++ b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp @@ -159,7 +159,7 @@ ReturnCode_t DataReaderImpl::enable() att.matched_writers_allocation = qos_.reader_resource_limits().matched_publisher_allocation; att.expectsInlineQos = qos_.expects_inline_qos(); att.disable_positive_acks = qos_.reliable_reader_qos().disable_positive_ACKs.enabled; - att.data_sharing_listener_thread = qos_.data_sharing_listener_thread(); + att.data_sharing_listener_thread = qos_.data_sharing().data_sharing_listener_thread(); // TODO(Ricardo) Remove in future // Insert topic_name and partitions @@ -1565,7 +1565,7 @@ bool DataReaderImpl::can_qos_be_updated( EPROSIMA_LOG_WARNING(RTPS_QOS_CHECK, "Positive ACKs QoS cannot be changed after the creation of a DataReader."); } - if (!(to.data_sharing_listener_thread() == from.data_sharing_listener_thread())) + if (!(to.data_sharing().data_sharing_listener_thread() == from.data_sharing().data_sharing_listener_thread())) { updatable = false; EPROSIMA_LOG_WARNING(RTPS_QOS_CHECK, diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index ed8a32a0ee4..e0d469d6251 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -161,6 +161,7 @@ RTPSParticipantImpl::RTPSParticipantImpl( UDPv4TransportDescriptor descriptor; descriptor.sendBufferSize = m_att.sendSocketBufferSize; descriptor.receiveBufferSize = m_att.listenSocketBufferSize; + descriptor.default_reception_threads(m_att.builtin_transports_reception_threads); if (is_intraprocess_only()) { // Avoid multicast leaving the host for intraprocess-only participants @@ -179,6 +180,7 @@ RTPSParticipantImpl::RTPSParticipantImpl( shm_transport.segment_size(segment_size_udp_equivalent); // Use same default max_message_size on both UDP and SHM shm_transport.max_message_size(descriptor.max_message_size()); + shm_transport.default_reception_threads(m_att.builtin_transports_reception_threads); has_shm_transport_ |= m_network_Factory.RegisterTransport(&shm_transport); } #endif // ifdef SHM_TRANSPORT_BUILTIN diff --git a/src/cpp/rtps/xmlparser/XMLElementParser.cpp b/src/cpp/rtps/xmlparser/XMLElementParser.cpp index b8743d08487..405cdb36162 100644 --- a/src/cpp/rtps/xmlparser/XMLElementParser.cpp +++ b/src/cpp/rtps/xmlparser/XMLElementParser.cpp @@ -14,8 +14,11 @@ // #include +#include +#include #include #include +#include #include #include @@ -2109,10 +2112,25 @@ XMLP_ret XMLParser::getXMLDataSharingQos( /* - - - - + + + + + + + + + + + + + + + + + + + */ @@ -2216,6 +2234,14 @@ XMLP_ret XMLParser::getXMLDataSharingQos( return XMLP_ret::XML_ERROR; } } + else if (strcmp(name, DATA_SHARING_LISTENER_THREAD) == 0) + { + // data_sharing_listener_thread + if (XMLP_ret::XML_OK != getXMLThreadSettings(*p_aux0, data_sharing.data_sharing_listener_thread())) + { + return XMLP_ret::XML_ERROR; + } + } else { EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found in 'data_sharing'. Name: " << name); @@ -3718,6 +3744,56 @@ XMLP_ret XMLParser::getXMLUint( return XMLP_ret::XML_OK; } +XMLP_ret XMLParser::getXMLUint( + tinyxml2::XMLElement* elem, + uint64_t* ui64, + uint8_t /*ident*/) +{ + unsigned long int ui = 0u; + if (nullptr == elem || nullptr == ui64) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "nullptr when getXMLUint XML_ERROR!"); + return XMLP_ret::XML_ERROR; + } + + auto to_uint64 = [](const char* str, unsigned long int* value) -> bool + { + // Look for a '-' sign + bool ret = false; + const char minus = '-'; + const char* minus_result = str; + if (nullptr == std::strchr(minus_result, minus)) + { + // Minus not found + ret = true; + } + + if (ret) + { + ret = false; +#ifdef _WIN32 + if (sscanf_s(str, "%lu", value) == 1) +#else + if (sscanf(str, "%lu", value) == 1) +#endif // ifdef _WIN32 + { + // Number found + ret = true; + } + } + return ret; + }; + + std::string text = get_element_text(elem); + if (text.empty() || !to_uint64(text.c_str(), &ui)) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "<" << elem->Value() << "> getXMLUint XML_ERROR!"); + return XMLP_ret::XML_ERROR; + } + *ui64 = static_cast(ui); + return XMLP_ret::XML_OK; +} + XMLP_ret XMLParser::getXMLBool( tinyxml2::XMLElement* elem, bool* b, @@ -4033,6 +4109,65 @@ XMLP_ret XMLParser::getXMLguidPrefix( } +XMLP_ret XMLParser::getXMLDomainParticipantFactoryQos( + tinyxml2::XMLElement& elem, + fastdds::dds::DomainParticipantFactoryQos& qos) +{ + /* + + + + + + + + */ + + std::set tags_present; + + for (tinyxml2::XMLElement* element = elem.FirstChildElement(); element != nullptr; + element = element->NextSiblingElement()) + { + const char* name = element->Name(); + if (tags_present.count(name) != 0) + { + EPROSIMA_LOG_ERROR(XMLPARSER, + "Duplicated element found in 'domainParticipantFactoryQosPoliciesType'. Name: " << name); + return XMLP_ret::XML_ERROR; + } + tags_present.emplace(name); + + if (strcmp(name, ENTITY_FACTORY) == 0) + { + if (XMLP_ret::XML_OK != getXMLEntityFactoryQos(*element, qos.entity_factory())) + { + return XMLP_ret::XML_ERROR; + } + } + else if (strcmp(name, SHM_WATCHDOG_THREAD) == 0) + { + if (XMLP_ret::XML_OK != getXMLThreadSettings(*element, qos.shm_watchdog_thread())) + { + return XMLP_ret::XML_ERROR; + } + } + else if (strcmp(name, FILE_WATCH_THREADS) == 0) + { + if (XMLP_ret::XML_OK != getXMLThreadSettings(*element, qos.file_watch_threads())) + { + return XMLP_ret::XML_ERROR; + } + } + else + { + EPROSIMA_LOG_ERROR(XMLPARSER, + "Invalid element found into 'domainParticipantFactoryQosPoliciesType'. Name: " << name); + return XMLP_ret::XML_ERROR; + } + } + return XMLP_ret::XML_OK; +} + XMLP_ret XMLParser::getXMLPublisherAttributes( tinyxml2::XMLElement* elem, PublisherAttributes& publisher, @@ -4372,6 +4507,197 @@ XMLP_ret XMLParser::getXMLSubscriberAttributes( return XMLP_ret::XML_OK; } +XMLP_ret XMLParser::getXMLThreadSettings( + tinyxml2::XMLElement& elem, + fastdds::rtps::ThreadSettings& thread_setting) +{ + /* + + + + + + + + + */ + uint32_t port = 0; + return getXMLThreadSettingsWithPort(elem, thread_setting, + port) != XMLP_ret::XML_ERROR ? XMLP_ret::XML_OK : XMLP_ret::XML_ERROR; +} + +XMLP_ret XMLParser::getXMLThreadSettingsWithPort( + tinyxml2::XMLElement& elem, + fastdds::rtps::ThreadSettings& thread_setting, + uint32_t& port) +{ + /* + + + + + + + + */ + + /* + * The are 4 allowed elements, all their min occurrences are 0, and their max are 1. + * In case port is not present, return NOK instead of ERROR + */ + XMLP_ret ret = XMLP_ret::XML_OK; + bool port_found = false; + for (const tinyxml2::XMLAttribute* attrib = elem.FirstAttribute(); attrib != nullptr; attrib = attrib->Next()) + { + if (strcmp(attrib->Name(), PORT) == 0) + { + try + { + std::string temp = attrib->Value(); + temp.erase(std::remove_if(temp.begin(), temp.end(), [](unsigned char c) + { + return std::isspace(c); + }), temp.end()); + if (attrib->Value()[0] == '-') + { + throw std::invalid_argument("Negative value detected"); + } + port = static_cast(std::stoul(attrib->Value())); + port_found = true; + } + catch (std::invalid_argument& except) + { + EPROSIMA_LOG_ERROR(XMLPARSER, + "Found wrong value " << attrib->Value() << " for port attribute. " << + except.what()); + ret = XMLP_ret::XML_ERROR; + break; + } + } + else + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Found wrong attribute " << attrib->Name() << " in 'thread_settings"); + ret = XMLP_ret::XML_ERROR; + break; + } + } + + // Set ret to NOK is port attribute was not present + if (ret == XMLP_ret::XML_OK && !port_found) + { + ret = XMLP_ret::XML_NOK; + } + + const uint8_t ident = 1; + std::set tags_present; + + for (tinyxml2::XMLElement* current_elem = elem.FirstChildElement(); + current_elem != nullptr && ret != XMLP_ret::XML_ERROR; + current_elem = current_elem->NextSiblingElement()) + { + const char* name = current_elem->Name(); + if (tags_present.count(name) != 0) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Duplicated element found in 'thread_settings'. Tag: " << name); + ret = XMLP_ret::XML_ERROR; + break; + } + tags_present.emplace(name); + + if (strcmp(current_elem->Name(), SCHEDULING_POLICY) == 0) + { + // scheduling_policy - int32Type + if (XMLP_ret::XML_OK != getXMLInt(current_elem, &thread_setting.scheduling_policy, ident) || + thread_setting.scheduling_policy < -1) + { + ret = XMLP_ret::XML_ERROR; + break; + } + } + else if (strcmp(current_elem->Name(), PRIORITY) == 0) + { + // priority - int32Type + if (XMLP_ret::XML_OK != getXMLInt(current_elem, &thread_setting.priority, ident)) + { + ret = XMLP_ret::XML_ERROR; + break; + } + } + else if (strcmp(current_elem->Name(), AFFINITY) == 0) + { + // affinity - uint64Type + if (XMLP_ret::XML_OK != getXMLUint(current_elem, &thread_setting.affinity, ident)) + { + ret = XMLP_ret::XML_ERROR; + break; + } + } + else if (strcmp(current_elem->Name(), STACK_SIZE) == 0) + { + // stack_size - int32Type + if (XMLP_ret::XML_OK != getXMLInt(current_elem, &thread_setting.stack_size, ident) || + thread_setting.stack_size < -1) + { + ret = XMLP_ret::XML_ERROR; + break; + } + } + else + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Found incorrect tag '" << current_elem->Name() << "'"); + ret = XMLP_ret::XML_ERROR; + break; + } + } + return ret; +} + +XMLP_ret XMLParser::getXMLEntityFactoryQos( + tinyxml2::XMLElement& elem, + fastdds::dds::EntityFactoryQosPolicy& entity_factory) +{ + /* + + + + + + */ + + /* + * The only allowed element is autoenable_created_entities, its min occurrences is 0, and its max is 1. + */ + const uint8_t ident = 1; + std::set tags_present; + + for (tinyxml2::XMLElement* current_elem = elem.FirstChildElement(); current_elem != nullptr; + current_elem = current_elem->NextSiblingElement()) + { + const char* name = current_elem->Name(); + if (tags_present.count(name) != 0) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Duplicated element found in 'entityFactoryQosPolicyType'. Tag: " << name); + return XMLP_ret::XML_ERROR; + } + tags_present.emplace(name); + + if (strcmp(current_elem->Name(), AUTOENABLE_CREATED_ENTITIES) == 0) + { + // autoenable_created_entities - boolean + if (XMLP_ret::XML_OK != getXMLBool(current_elem, &entity_factory.autoenable_created_entities, ident)) + { + return XMLP_ret::XML_ERROR; + } + } + else + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Found incorrect tag '" << current_elem->Name() << "'"); + return XMLP_ret::XML_ERROR; + } + } + return XMLP_ret::XML_OK; +} + } // namespace xmlparser } // namespace fastrtps } // namespace eprosima diff --git a/src/cpp/rtps/xmlparser/XMLParser.cpp b/src/cpp/rtps/xmlparser/XMLParser.cpp index 6dd3d7af836..1cab55ce91b 100644 --- a/src/cpp/rtps/xmlparser/XMLParser.cpp +++ b/src/cpp/rtps/xmlparser/XMLParser.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -122,6 +123,10 @@ XMLP_ret XMLParser::parseXML( root->addChild(std::move(library_node)); } } + else if (strcmp(tag, DOMAINPARTICIPANT_FACTORY) == 0) + { + ret = parseXMLDomainParticipantFactoryProf(node, *root); + } else if (strcmp(tag, PARTICIPANT) == 0) { ret = parseXMLParticipantProf(node, *root); @@ -249,6 +254,11 @@ XMLP_ret XMLParser::parseXMLTransportData( */ + if (XMLP_ret::XML_OK != validateXMLTransportElements(*p_root)) + { + return XMLP_ret::XML_ERROR; + } + tinyxml2::XMLElement* p_aux0 = nullptr; p_aux0 = p_root->FirstChildElement(TRANSPORT_ID); if (nullptr == p_aux0) @@ -361,9 +371,25 @@ XMLP_ret XMLParser::parseXMLTransportData( return XMLP_ret::XML_ERROR; } + ret = parseXMLCommonTransportData(p_root, pDescriptor); + if (ret != XMLP_ret::XML_OK) + { + return ret; + } + + std::shared_ptr temp_1 = + std::dynamic_pointer_cast(pDescriptor); + ret = parseXMLPortBasedTransportData(p_root, temp_1); + if (ret != XMLP_ret::XML_OK) + { + return ret; + } + if (sType != SHM) { - ret = parseXMLCommonTransportData(p_root, pDescriptor); + std::shared_ptr temp_2 = + std::dynamic_pointer_cast(pDescriptor); + ret = parseXMLSocketTransportData(p_root, temp_2); if (ret != XMLP_ret::XML_OK) { return ret; @@ -374,6 +400,53 @@ XMLP_ret XMLParser::parseXMLTransportData( return ret; } +XMLP_ret XMLParser::validateXMLTransportElements( + tinyxml2::XMLElement& p_root) +{ + XMLP_ret ret = XMLP_ret::XML_OK; + for (tinyxml2::XMLElement* p_aux0 = p_root.FirstChildElement(); p_aux0 != nullptr; + p_aux0 = p_aux0->NextSiblingElement()) + { + const char* name = p_aux0->Name(); + if (!(strcmp(name, TRANSPORT_ID) == 0 || + strcmp(name, TYPE) == 0 || + strcmp(name, SEND_BUFFER_SIZE) == 0 || + strcmp(name, RECEIVE_BUFFER_SIZE) == 0 || + strcmp(name, MAX_MESSAGE_SIZE) == 0 || + strcmp(name, MAX_INITIAL_PEERS_RANGE) == 0 || + strcmp(name, WHITE_LIST) == 0 || + strcmp(name, TTL) == 0 || + strcmp(name, NON_BLOCKING_SEND) == 0 || + strcmp(name, UDP_OUTPUT_PORT) == 0 || + strcmp(name, TCP_WAN_ADDR) == 0 || + strcmp(name, KEEP_ALIVE_FREQUENCY) == 0 || + strcmp(name, KEEP_ALIVE_TIMEOUT) == 0 || + strcmp(name, MAX_LOGICAL_PORT) == 0 || + strcmp(name, LOGICAL_PORT_RANGE) == 0 || + strcmp(name, LOGICAL_PORT_INCREMENT) == 0 || + strcmp(name, LISTENING_PORTS) == 0 || + strcmp(name, CALCULATE_CRC) == 0 || + strcmp(name, CHECK_CRC) == 0 || + strcmp(name, ENABLE_TCP_NODELAY) == 0 || + strcmp(name, TLS) == 0 || + strcmp(name, SEGMENT_SIZE) == 0 || + strcmp(name, PORT_QUEUE_CAPACITY) == 0 || + strcmp(name, HEALTHY_CHECK_TIMEOUT_MS) == 0 || + strcmp(name, RTPS_DUMP_FILE) == 0 || + strcmp(name, DEFAULT_RECEPTION_THREADS) == 0 || + strcmp(name, RECEPTION_THREADS) == 0 || + strcmp(name, DUMP_THREAD) == 0 || + strcmp(name, PORT_OVERFLOW_POLICY) == 0 || + strcmp(name, SEGMENT_OVERFLOW_POLICY) == 0)) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found into 'transportDescriptorType'. Name: " << name); + ret = XMLP_ret::XML_ERROR; + } + } + + return ret; +} + XMLP_ret XMLParser::parseXMLCommonTransportData( tinyxml2::XMLElement* p_root, sp_transport_t p_transport) @@ -383,28 +456,101 @@ XMLP_ret XMLParser::parseXMLCommonTransportData( - - - - - - - - - - - - - */ + tinyxml2::XMLElement* p_aux0 = nullptr; + const char* name = nullptr; + for (p_aux0 = p_root->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement()) + { + name = p_aux0->Name(); + if (strcmp(name, MAX_MESSAGE_SIZE) == 0) + { + // maxMessageSize - uint32Type + uint32_t uSize = 0; + if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &uSize, 0)) + { + return XMLP_ret::XML_ERROR; + } + p_transport->maxMessageSize = uSize; + } + else if (strcmp(name, MAX_INITIAL_PEERS_RANGE) == 0) + { + // maxInitialPeersRange - uint32Type + uint32_t uRange = 0; + if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &uRange, 0)) + { + return XMLP_ret::XML_ERROR; + } + p_transport->maxInitialPeersRange = uRange; + } + } + return XMLP_ret::XML_OK; +} - std::shared_ptr pDesc = - std::dynamic_pointer_cast(p_transport); +XMLP_ret XMLParser::parseXMLPortBasedTransportData( + tinyxml2::XMLElement* p_root, + std::shared_ptr p_transport) +{ + /* + + + + + + + */ + tinyxml2::XMLElement* p_aux0 = nullptr; + const char* name = nullptr; + for (p_aux0 = p_root->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement()) + { + name = p_aux0->Name(); + if (strcmp(name, DEFAULT_RECEPTION_THREADS) == 0) + { + fastdds::rtps::ThreadSettings thread_settings; + if (getXMLThreadSettings(*p_aux0, thread_settings) == XMLP_ret::XML_OK) + { + p_transport->default_reception_threads(thread_settings); + } + else + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Incorrect thread settings"); + return XMLP_ret::XML_ERROR; + } + } + else if (strcmp(name, RECEPTION_THREADS) == 0) + { + fastdds::rtps::PortBasedTransportDescriptor::ReceptionThreadsConfigMap reception_threads; + if (parseXMLReceptionThreads(*p_aux0, reception_threads) == XMLP_ret::XML_OK) + { + p_transport->reception_threads(reception_threads); + } + else + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Incorrect thread settings"); + return XMLP_ret::XML_ERROR; + } + } + } + return XMLP_ret::XML_OK; +} +XMLP_ret XMLParser::parseXMLSocketTransportData( + tinyxml2::XMLElement* p_root, + std::shared_ptr p_transport) +{ + /* + + + + + + + + + */ tinyxml2::XMLElement* p_aux0 = nullptr; const char* name = nullptr; for (p_aux0 = p_root->FirstChildElement(); p_aux0 != nullptr; p_aux0 = p_aux0->NextSiblingElement()) @@ -418,7 +564,7 @@ XMLP_ret XMLParser::parseXMLCommonTransportData( { return XMLP_ret::XML_ERROR; } - pDesc->sendBufferSize = iSize; + p_transport->sendBufferSize = iSize; } else if (strcmp(name, RECEIVE_BUFFER_SIZE) == 0) { @@ -428,7 +574,7 @@ XMLP_ret XMLParser::parseXMLCommonTransportData( { return XMLP_ret::XML_ERROR; } - pDesc->receiveBufferSize = iSize; + p_transport->receiveBufferSize = iSize; } else if (strcmp(name, TTL) == 0) { @@ -438,27 +584,7 @@ XMLP_ret XMLParser::parseXMLCommonTransportData( { return XMLP_ret::XML_ERROR; } - pDesc->TTL = static_cast(iTTL); - } - else if (strcmp(name, MAX_MESSAGE_SIZE) == 0) - { - // maxMessageSize - uint32Type - uint32_t uSize = 0; - if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &uSize, 0)) - { - return XMLP_ret::XML_ERROR; - } - std::dynamic_pointer_cast(p_transport)->maxMessageSize = uSize; - } - else if (strcmp(name, MAX_INITIAL_PEERS_RANGE) == 0) - { - // maxInitialPeersRange - uint32Type - uint32_t uRange = 0; - if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &uRange, 0)) - { - return XMLP_ret::XML_ERROR; - } - pDesc->maxInitialPeersRange = uRange; + p_transport->TTL = static_cast(iTTL); } else if (strcmp(name, WHITE_LIST) == 0) { @@ -473,7 +599,7 @@ XMLP_ret XMLParser::parseXMLCommonTransportData( std::string text = get_element_text(p_aux1); if (!text.empty()) { - pDesc->interfaceWhiteList.emplace_back(text); + p_transport->interfaceWhiteList.emplace_back(text); } } else @@ -483,26 +609,6 @@ XMLP_ret XMLParser::parseXMLCommonTransportData( } } } - else if (strcmp(name, TCP_WAN_ADDR) == 0 || strcmp(name, UDP_OUTPUT_PORT) == 0 || - strcmp(name, TRANSPORT_ID) == 0 || strcmp(name, TYPE) == 0 || - strcmp(name, KEEP_ALIVE_FREQUENCY) == 0 || strcmp(name, KEEP_ALIVE_TIMEOUT) == 0 || - strcmp(name, MAX_LOGICAL_PORT) == 0 || strcmp(name, LOGICAL_PORT_RANGE) == 0 || - strcmp(name, LOGICAL_PORT_INCREMENT) == 0 || strcmp(name, LISTENING_PORTS) == 0 || - strcmp(name, CALCULATE_CRC) == 0 || strcmp(name, CHECK_CRC) == 0 || - strcmp(name, ENABLE_TCP_NODELAY) == 0 || strcmp(name, TLS) == 0 || - strcmp(name, NON_BLOCKING_SEND) == 0 || - strcmp(name, SEGMENT_SIZE) == 0 || strcmp(name, PORT_QUEUE_CAPACITY) == 0 || - strcmp(name, PORT_OVERFLOW_POLICY) == 0 || strcmp(name, SEGMENT_OVERFLOW_POLICY) == 0 || - strcmp(name, HEALTHY_CHECK_TIMEOUT_MS) == 0 || strcmp(name, HEALTHY_CHECK_TIMEOUT_MS) == 0 || - strcmp(name, RTPS_DUMP_FILE) == 0) - { - // Parsed outside of this method - } - else - { - EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found into 'rtpsTransportDescriptorType'. Name: " << name); - return XMLP_ret::XML_ERROR; - } } return XMLP_ret::XML_OK; } @@ -637,20 +743,6 @@ XMLP_ret XMLParser::parseXMLCommonTCPTransportData( return XMLP_ret::XML_ERROR; } } - else if (strcmp(name, TCP_WAN_ADDR) == 0 || strcmp(name, TRANSPORT_ID) == 0 || - strcmp(name, TYPE) == 0 || strcmp(name, SEND_BUFFER_SIZE) == 0 || - strcmp(name, RECEIVE_BUFFER_SIZE) == 0 || strcmp(name, TTL) == 0 || - strcmp(name, MAX_MESSAGE_SIZE) == 0 || strcmp(name, MAX_INITIAL_PEERS_RANGE) == 0 || - strcmp(name, WHITE_LIST) == 0) - { - // Parsed Outside of this method - } - else - { - EPROSIMA_LOG_ERROR(XMLPARSER, - "Invalid element found into 'rtpsTransportDescriptorType'. Name: " << name); - return XMLP_ret::XML_ERROR; - } } } else @@ -675,7 +767,8 @@ XMLP_ret XMLParser::parseXMLCommonSharedMemTransportData( - + + */ @@ -723,36 +816,17 @@ XMLP_ret XMLParser::parseXMLCommonSharedMemTransportData( } transport_descriptor->rtps_dump_file(str); } - else if (strcmp(name, MAX_MESSAGE_SIZE) == 0) + else if (strcmp(name, DUMP_THREAD) == 0) { - // maxMessageSize - uint32Type - uint32_t uSize = 0; - if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &uSize, 0)) + fastdds::rtps::ThreadSettings thread_settings; + if (getXMLThreadSettings(*p_aux0, thread_settings) != XMLP_ret::XML_OK) { + EPROSIMA_LOG_ERROR(XMLPARSER, "Incorrect thread settings"); return XMLP_ret::XML_ERROR; } - transport_descriptor->max_message_size(uSize); - } - else if (strcmp(name, MAX_INITIAL_PEERS_RANGE) == 0) - { - // maxInitialPeersRange - uint32Type - uint32_t uRange = 0; - if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &uRange, 0)) - { - return XMLP_ret::XML_ERROR; - } - transport_descriptor->maxInitialPeersRange = uRange; - } - else if (strcmp(name, TRANSPORT_ID) == 0 || strcmp(name, TYPE) == 0) - { - // Parsed Outside of this method - } - else - { - EPROSIMA_LOG_ERROR(XMLPARSER, - "Invalid element found into 'rtpsTransportDescriptorType'. Name: " << name); - return XMLP_ret::XML_ERROR; + transport_descriptor->dump_thread(thread_settings); } + // Do not parse nor fail on unkown tags; these may be parsed elsewhere } } else @@ -1130,6 +1204,48 @@ XMLP_ret XMLParser::parse_tls_config( return ret; } +XMLP_ret XMLParser::parseXMLReceptionThreads( + tinyxml2::XMLElement& p_root, + fastdds::rtps::PortBasedTransportDescriptor::ReceptionThreadsConfigMap& reception_threads) +{ + /* + + + + + + */ + + /* + * The only allowed element is + */ + XMLP_ret ret = XMLP_ret::XML_OK; + for (tinyxml2::XMLElement* p_element = p_root.FirstChildElement(); p_element != nullptr; + p_element = p_element->NextSiblingElement()) + { + if (strcmp(p_element->Name(), RECEPTION_THREAD) == 0) + { + uint32_t port = 0; + fastdds::rtps::ThreadSettings thread_settings; + ret = getXMLThreadSettingsWithPort(*p_element, thread_settings, port); + if (XMLP_ret::XML_OK != ret || reception_threads.count(port) != 0) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Error parsing reception_threads thread settings. Port: " << port); + ret = XMLP_ret::XML_ERROR; + break; + } + reception_threads[port] = thread_settings; + } + else + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Error parsing reception_threads. Wrong tag: " << p_element->Name()); + ret = XMLP_ret::XML_ERROR; + break; + } + } + return ret; +} + XMLP_ret XMLParser::parseXMLLibrarySettings( tinyxml2::XMLElement* p_root) { @@ -1166,6 +1282,27 @@ XMLP_ret XMLParser::parseXMLLibrarySettings( return ret; } +XMLP_ret XMLParser::parseXMLDomainParticipantFactoryProf( + tinyxml2::XMLElement* p_root, + BaseNode& rootNode) +{ + XMLP_ret ret = XMLP_ret::XML_OK; + up_participantfactory_t factory_qos{new fastdds::dds::DomainParticipantFactoryQos}; + up_node_participantfactory_t factory_node{new node_participantfactory_t{NodeType::DOMAINPARTICIPANT_FACTORY, + std::move(factory_qos)}}; + if (XMLP_ret::XML_OK == fillDataNode(p_root, *factory_node)) + { + rootNode.addChild(std::move(factory_node)); + } + else + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Error parsing participant profile"); + ret = XMLP_ret::XML_ERROR; + } + + return ret; +} + XMLP_ret XMLParser::parseXMLParticipantProf( tinyxml2::XMLElement* p_root, BaseNode& rootNode) @@ -1317,6 +1454,10 @@ XMLP_ret XMLParser::parseProfiles( { parseOk &= parseXMLLibrarySettings(p_profile) == XMLP_ret::XML_OK; } + else if (strcmp(tag, DOMAINPARTICIPANT_FACTORY) == 0) + { + parseOk &= parseXMLDomainParticipantFactoryProf(p_profile, profilesNode) == XMLP_ret::XML_OK; + } else if (strcmp(tag, PARTICIPANT) == 0) { parseOk &= parseXMLParticipantProf(p_profile, profilesNode) == XMLP_ret::XML_OK; @@ -1384,6 +1525,7 @@ XMLP_ret XMLParser::parseLogConfig( + @@ -1406,11 +1548,24 @@ XMLP_ret XMLParser::parseLogConfig( p_aux0 = p_root; } + std::set tags_present; tinyxml2::XMLElement* p_element = p_aux0->FirstChildElement(); + fastdds::rtps::ThreadSettings thread_settings; + bool set_thread_settings = false; while (ret == XMLP_ret::XML_OK && nullptr != p_element) { + const char* name = p_element->Name(); const char* tag = p_element->Value(); + + // Fail on duplicated not allowed elements + if (strcmp(tag, CONSUMER) != 0 && tags_present.count(name) != 0) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Duplicated element found in 'log'. Tag: " << name); + return XMLP_ret::XML_ERROR; + } + tags_present.emplace(name); + if (nullptr != tag) { if (strcmp(tag, USE_DEFAULT) == 0) @@ -1439,6 +1594,18 @@ XMLP_ret XMLParser::parseLogConfig( { ret = parseXMLConsumer(*p_element); } + else if (strcmp(tag, THREAD_SETTINGS) == 0) + { + ret = getXMLThreadSettings(*p_element, thread_settings); + if (ret == XMLP_ret::XML_OK) + { + set_thread_settings = true; + } + else + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Incorrect thread settings"); + } + } else { EPROSIMA_LOG_ERROR(XMLPARSER, "Not expected tag: '" << tag << "'"); @@ -1448,10 +1615,15 @@ XMLP_ret XMLParser::parseLogConfig( if (ret == XMLP_ret::XML_OK) { - p_element = p_element->NextSiblingElement(CONSUMER); + p_element = p_element->NextSiblingElement(); } } + if (ret == XMLP_ret::XML_OK && set_thread_settings) + { + fastdds::dds::Log::SetThreadConfig(thread_settings); + } + return ret; } @@ -1717,6 +1889,54 @@ XMLP_ret XMLParser::fillDataNode( return XMLP_ret::XML_OK; } +XMLP_ret XMLParser::fillDataNode( + tinyxml2::XMLElement* p_profile, + DataNode& factory_node) +{ + /* + + + + + + + + */ + + if (nullptr == p_profile) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Bad parameters!"); + return XMLP_ret::XML_ERROR; + } + + addAllAttributes(p_profile, factory_node); + + /* + * The only allowed element , and its max is 1; look for it. + */ + std::set tags_present; + for (tinyxml2::XMLElement* p_element = p_profile->FirstChildElement(); p_element != nullptr; + p_element = p_element->NextSiblingElement()) + { + const char* name = p_element->Name(); + if (tags_present.count(name) != 0) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Duplicated element found in 'participant'. Tag: " << name); + return XMLP_ret::XML_ERROR; + } + tags_present.emplace(name); + + if (strcmp(p_element->Name(), QOS) == 0) + { + if (XMLP_ret::XML_OK != getXMLDomainParticipantFactoryQos(*p_element, *factory_node.get())) + { + return XMLP_ret::XML_ERROR; + } + } + } + return XMLP_ret::XML_OK; +} + XMLP_ret XMLParser::fillDataNode( tinyxml2::XMLElement* p_profile, DataNode& participant_node) @@ -1961,6 +2181,49 @@ XMLP_ret XMLParser::fillDataNode( } participant_node.get()->rtps.setName(s.c_str()); } + else if (strcmp(name, BUILTIN_CONTROLLERS_SENDER_THREAD) == 0) + { + if (XMLP_ret::XML_OK != + getXMLThreadSettings(*p_aux0, + participant_node.get()->rtps.builtin_controllers_sender_thread)) + { + return XMLP_ret::XML_ERROR; + } + } + else if (strcmp(name, TIMED_EVENTS_THREAD) == 0) + { + if (XMLP_ret::XML_OK != getXMLThreadSettings(*p_aux0, participant_node.get()->rtps.timed_events_thread)) + { + return XMLP_ret::XML_ERROR; + } + } + else if (strcmp(name, DISCOVERY_SERVER_THREAD) == 0) + { + if (XMLP_ret::XML_OK != getXMLThreadSettings(*p_aux0, participant_node.get()->rtps.discovery_server_thread)) + { + return XMLP_ret::XML_ERROR; + } + } + else if (strcmp(name, BUILTIN_TRANSPORTS_RECEPTION_THREADS) == 0) + { + if (XMLP_ret::XML_OK != + getXMLThreadSettings(*p_aux0, + participant_node.get()->rtps.builtin_transports_reception_threads)) + { + return XMLP_ret::XML_ERROR; + } + } + else if (strcmp(name, SECURITY_LOG_THREAD) == 0) + { +#if HAVE_SECURITY + if (XMLP_ret::XML_OK != getXMLThreadSettings(*p_aux0, participant_node.get()->rtps.security_log_thread)) + { + return XMLP_ret::XML_ERROR; + } +#else + EPROSIMA_LOG_WARNING(XMLPARSER, "Ignoring '" << SECURITY_LOG_THREAD << "' since security is disabled"); +#endif // if HAVE_SECURITY + } else { EPROSIMA_LOG_ERROR(XMLPARSER, "Invalid element found into 'rtpsParticipantAttributesType'. Name: " << name); diff --git a/src/cpp/rtps/xmlparser/XMLParserCommon.cpp b/src/cpp/rtps/xmlparser/XMLParserCommon.cpp index 0c4e39bad0a..6baf830e963 100644 --- a/src/cpp/rtps/xmlparser/XMLParserCommon.cpp +++ b/src/cpp/rtps/xmlparser/XMLParserCommon.cpp @@ -29,6 +29,7 @@ const char* LIBRARY_SETTINGS = "library_settings"; const char* TRANSPORT_DESCRIPTORS = "transport_descriptors"; const char* PROFILE_NAME = "profile_name"; const char* DEFAULT_PROF = "is_default_profile"; +const char* DOMAINPARTICIPANT_FACTORY = "domainparticipant_factory"; const char* PARTICIPANT = "participant"; const char* PUBLISHER = "publisher"; const char* SUBSCRIBER = "subscriber"; @@ -67,8 +68,17 @@ const char* HEALTHY_CHECK_TIMEOUT_MS = "healthy_check_timeout_ms"; const char* DISCARD = "DISCARD"; const char* FAIL = "FAIL"; const char* RTPS_DUMP_FILE = "rtps_dump_file"; +const char* DEFAULT_RECEPTION_THREADS = "default_reception_threads"; +const char* RECEPTION_THREADS = "reception_threads"; +const char* RECEPTION_THREAD = "reception_thread"; +const char* DUMP_THREAD = "dump_thread"; const char* ON = "ON"; const char* AUTO = "AUTO"; +const char* THREAD_SETTINGS = "thread_settings"; +const char* SCHEDULING_POLICY = "scheduling_policy"; +const char* PRIORITY = "priority"; +const char* AFFINITY = "affinity"; +const char* STACK_SIZE = "stack_size"; const char* OFF = "OFF"; const char* USER_DATA_ONLY = "USER_DATA_ONLY"; @@ -81,6 +91,12 @@ const char* TYPE = "type"; const char* DATA_WRITER = "data_writer"; const char* DATA_READER = "data_reader"; +/// DomainParticipantFactory Qos +const char* ENTITY_FACTORY = "entity_factory"; +const char* AUTOENABLE_CREATED_ENTITIES = "autoenable_created_entities"; +const char* SHM_WATCHDOG_THREAD = "shm_watchdog_thread"; +const char* FILE_WATCH_THREADS = "file_watch_threads"; + /// RTPS Domain attributes const char* INTRAPROCESS_DELIVERY = "intraprocess_delivery"; @@ -116,6 +132,11 @@ const char* DYNAMIC_LC = "dynamic"; const char* MAX_PROPERTIES = "max_properties"; const char* MAX_USER_DATA = "max_user_data"; const char* MAX_PARTITIONS = "max_partitions"; +const char* TIMED_EVENTS_THREAD = "timed_events_thread"; +const char* DISCOVERY_SERVER_THREAD = "discovery_server_thread"; +const char* SECURITY_LOG_THREAD = "security_log_thread"; +const char* BUILTIN_TRANSPORTS_RECEPTION_THREADS = "builtin_transports_reception_threads"; +const char* BUILTIN_CONTROLLERS_SENDER_THREAD = "builtin_controllers_sender_thread"; /// Publisher-subscriber attributes const char* TOPIC = "topic"; @@ -133,6 +154,7 @@ const char* USER_DEF_ID = "userDefinedID"; const char* ENTITY_ID = "entityID"; const char* MATCHED_SUBSCRIBERS_ALLOCATION = "matchedSubscribersAllocation"; const char* MATCHED_PUBLISHERS_ALLOCATION = "matchedPublishersAllocation"; +const char* DATA_SHARING_LISTENER_THREAD = "data_sharing_listener_thread"; /// const char* IGN_NON_MATCHING_LOCS = "ignore_non_matching_locators"; diff --git a/src/cpp/rtps/xmlparser/XMLProfileManager.cpp b/src/cpp/rtps/xmlparser/XMLProfileManager.cpp index 63b82d858d6..f14c23b0cdf 100644 --- a/src/cpp/rtps/xmlparser/XMLProfileManager.cpp +++ b/src/cpp/rtps/xmlparser/XMLProfileManager.cpp @@ -12,20 +12,26 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include #include -#include -#include #include #ifdef _WIN32 #include #endif // ifdef _WIN32 +#include + +#include +#include +#include + using namespace eprosima::fastrtps; +using namespace eprosima::fastdds; using namespace ::xmlparser; LibrarySettingsAttributes XMLProfileManager::library_settings_; +std::map XMLProfileManager::participant_factory_profiles_; +dds::DomainParticipantFactoryQos default_participant_factory_qos; std::map XMLProfileManager::participant_profiles_; ParticipantAttributes default_participant_attributes; std::map XMLProfileManager::publisher_profiles_; @@ -149,6 +155,30 @@ void XMLProfileManager::getDefaultPublisherAttributes( publisher_attributes = default_publisher_attributes; } +XMLP_ret XMLProfileManager::fillDomainParticipantFactoryQos( + const std::string& profile_name, + dds::DomainParticipantFactoryQos& qos, + bool log_error) +{ + part_factory_map_iterator_t it = participant_factory_profiles_.find(profile_name); + if (it == participant_factory_profiles_.end()) + { + if (log_error) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Profile '" << profile_name << "' not found"); + } + return XMLP_ret::XML_ERROR; + } + qos = *(it->second); + return XMLP_ret::XML_OK; +} + +void XMLProfileManager::getDefaultDomainParticipantFactoryQos( + dds::DomainParticipantFactoryQos& qos) +{ + qos = default_participant_factory_qos; +} + void XMLProfileManager::getDefaultSubscriberAttributes( SubscriberAttributes& subscriber_attributes) { @@ -368,7 +398,18 @@ XMLP_ret XMLProfileManager::extractProfiles( XMLP_ret ret = XMLP_ret::XML_OK; for (auto&& profile: profiles->getChildren()) { - if (NodeType::PARTICIPANT == profile->getType()) + if (NodeType::DOMAINPARTICIPANT_FACTORY == profile->getType()) + { + if (XMLP_ret::XML_OK == extractDomainParticipantFactoryProfile(profile, filename)) + { + ++profile_count; + } + else + { + ret = XMLP_ret::XML_NOK; + } + } + else if (NodeType::PARTICIPANT == profile->getType()) { if (XMLP_ret::XML_OK == extractParticipantProfile(profile, filename)) { @@ -449,6 +490,39 @@ XMLP_ret XMLProfileManager::extractProfiles( return ret; } +XMLP_ret XMLProfileManager::extractDomainParticipantFactoryProfile( + up_base_node_t& profile, + const std::string& filename) +{ + static_cast(filename); + std::string profile_name = ""; + + p_node_participantfactory_t node_factory = dynamic_cast(profile.get()); + node_att_map_cit_t it = node_factory->getAttributes().find(PROFILE_NAME); + if (it == node_factory->getAttributes().end() || it->second.empty()) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Error adding profile from file '" << filename << "': no name found"); + return XMLP_ret::XML_ERROR; + } + + profile_name = it->second; + + std::pair emplace = participant_factory_profiles_.emplace(profile_name, + node_factory->getData()); + if (false == emplace.second) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Error adding profile '" << profile_name << "' from file '" << filename << "'"); + return XMLP_ret::XML_ERROR; + } + + it = node_factory->getAttributes().find(DEFAULT_PROF); + if (it != node_factory->getAttributes().end() && it->second == "true") // Set as default profile + { + default_participant_factory_qos = *(emplace.first->second.get()); + } + return XMLP_ret::XML_OK; +} + XMLP_ret XMLProfileManager::extractParticipantProfile( up_base_node_t& profile, const std::string& filename) diff --git a/src/cpp/utils/threading/threading_osx.ipp b/src/cpp/utils/threading/threading_osx.ipp index 3131d3642a7..70c7cf817f2 100644 --- a/src/cpp/utils/threading/threading_osx.ipp +++ b/src/cpp/utils/threading/threading_osx.ipp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -76,23 +77,19 @@ static void configure_current_thread_scheduler( // Set Scheduler Class and Priority // - if((sched_class == SCHED_OTHER) || - (sched_class == SCHED_BATCH) || - (sched_class == SCHED_IDLE)) + if(sched_class == SCHED_OTHER) { - // - // BATCH and IDLE do not have explicit priority values. - // - Requires priorty value to be zero (0). - result = pthread_setschedparam(self_tid, sched_class, ¶m); - // // Sched OTHER has a nice value, that we pull from the priority parameter. + // - Requires priorty value to be zero (0). // - - if(sched_class == SCHED_OTHER && change_priority) - { - result = setpriority(PRIO_PROCESS, gettid(), sched_priority); + result = pthread_setschedparam(self_tid, sched_class, ¶m); + if(0 == result && change_priority) + { + uint64_t tid; + pthread_threadid_np(NULL, &tid); + result = setpriority(PRIO_PROCESS, tid, sched_priority); } } else if((sched_class == SCHED_FIFO) || diff --git a/src/cpp/utils/threading/threading_pthread.ipp b/src/cpp/utils/threading/threading_pthread.ipp index 5803c3464e1..e9f1e96b852 100644 --- a/src/cpp/utils/threading/threading_pthread.ipp +++ b/src/cpp/utils/threading/threading_pthread.ipp @@ -95,7 +95,7 @@ static void configure_current_thread_scheduler( // Sched OTHER has a nice value, that we pull from the priority parameter. // - if(sched_class == SCHED_OTHER && change_priority) + if(0 == result && sched_class == SCHED_OTHER && change_priority) { result = setpriority(PRIO_PROCESS, gettid(), sched_priority); } diff --git a/test/mock/rtps/Log/fastdds/dds/log/Log.hpp b/test/mock/rtps/Log/fastdds/dds/log/Log.hpp index 2f9c7dac846..5f84e08fa69 100644 --- a/test/mock/rtps/Log/fastdds/dds/log/Log.hpp +++ b/test/mock/rtps/Log/fastdds/dds/log/Log.hpp @@ -18,8 +18,11 @@ #include #include + #include +#include + /** * eProsima log mock. */ @@ -82,6 +85,13 @@ class Log ClearConsumersFunc(); } + static std::function SetThreadConfigFunc; + static void SetThreadConfig( + rtps::ThreadSettings&) + { + SetThreadConfigFunc(); + } + }; using ::testing::_; @@ -100,6 +110,8 @@ class LogMock MOCK_METHOD1(RegisterConsumer, void(std::unique_ptr&)); MOCK_METHOD0(ClearConsumers, void()); + + MOCK_METHOD(void, SetThreadConfig, ()); }; } // namespace dds diff --git a/test/mock/rtps/SharedMemTransportDescriptor/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h b/test/mock/rtps/SharedMemTransportDescriptor/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h index 1f0a7312c9f..21795787fff 100644 --- a/test/mock/rtps/SharedMemTransportDescriptor/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h +++ b/test/mock/rtps/SharedMemTransportDescriptor/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h @@ -15,6 +15,10 @@ #ifndef _FASTDDS_SHAREDMEM_TRANSPORT_DESCRIPTOR_ #define _FASTDDS_SHAREDMEM_TRANSPORT_DESCRIPTOR_ +#include +#include + +#include #include namespace eprosima { @@ -106,12 +110,26 @@ typedef struct SharedMemTransportDescriptor : public PortBasedTransportDescripto rtps_dump_file_ = rtps_dump_file; } + //! Return the thread settings for the transport dump thread + RTPS_DllAPI ThreadSettings dump_thread() const + { + return dump_thread_; + } + + //! Set the thread settings for the transport dump thread + RTPS_DllAPI void dump_thread( + const ThreadSettings& dump_thread) + { + dump_thread_ = dump_thread; + } + private: uint32_t segment_size_; uint32_t port_queue_capacity_; uint32_t healthy_check_timeout_ms_; std::string rtps_dump_file_; + ThreadSettings dump_thread_; }SharedMemTransportDescriptor; diff --git a/test/system/tools/xmlvalidation/XMLTesterExample_profile.xml b/test/system/tools/xmlvalidation/XMLTesterExample_profile.xml index c559ea5af1c..9fcda9e5a55 100644 --- a/test/system/tools/xmlvalidation/XMLTesterExample_profile.xml +++ b/test/system/tools/xmlvalidation/XMLTesterExample_profile.xml @@ -749,6 +749,13 @@ TRUE + + + 12 + 12 + 12 + 12 + diff --git a/test/system/tools/xmlvalidation/all_profile.xml b/test/system/tools/xmlvalidation/all_profile.xml index 69fd2a97892..f90f3907d81 100644 --- a/test/system/tools/xmlvalidation/all_profile.xml +++ b/test/system/tools/xmlvalidation/all_profile.xml @@ -1008,6 +1008,13 @@ true + + + -1 + 0 + 0 + -1 + diff --git a/test/unittest/dds/profiles/test_xml_for_string_profile.xml b/test/unittest/dds/profiles/test_xml_for_string_profile.xml index 29d35118097..b5b33707d20 100644 --- a/test/unittest/dds/profiles/test_xml_for_string_profile.xml +++ b/test/unittest/dds/profiles/test_xml_for_string_profile.xml @@ -126,6 +126,36 @@ 66 true test_name + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + @@ -251,6 +281,36 @@ 99 true default_name + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + diff --git a/test/unittest/dds/profiles/test_xml_profile.xml b/test/unittest/dds/profiles/test_xml_profile.xml index 02b00ad4426..a0c59ac24d7 100644 --- a/test/unittest/dds/profiles/test_xml_profile.xml +++ b/test/unittest/dds/profiles/test_xml_profile.xml @@ -123,6 +123,36 @@ 66 true test_name + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + @@ -248,6 +278,36 @@ 99 true default_name + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + diff --git a/test/unittest/dds/subscriber/DataReaderTests.cpp b/test/unittest/dds/subscriber/DataReaderTests.cpp index 0cf8b1a1273..ea56aa958a3 100644 --- a/test/unittest/dds/subscriber/DataReaderTests.cpp +++ b/test/unittest/dds/subscriber/DataReaderTests.cpp @@ -3632,14 +3632,14 @@ TEST_F(DataReaderTests, UpdateInmutableQos) reader_qos.data_sharing().add_domain_id(static_cast(12)); ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); - // Unique network flows reader_qos = DATAREADER_QOS_DEFAULT; - reader_qos.properties().properties().push_back({"fastdds.unique_network_flows", "true"}); + reader_qos.data_sharing().data_sharing_listener_thread().priority = + reader_qos.data_sharing().data_sharing_listener_thread().priority + 1; ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); - // Datasharing listener thread + // Unique network flows reader_qos = DATAREADER_QOS_DEFAULT; - reader_qos.data_sharing_listener_thread().priority = reader_qos.data_sharing_listener_thread().priority + 1; + reader_qos.properties().properties().push_back({"fastdds.unique_network_flows", "true"}); ASSERT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader->set_qos(reader_qos)); /* Cleanup */ diff --git a/test/unittest/rtps/builtin/CMakeLists.txt b/test/unittest/rtps/builtin/CMakeLists.txt index abaef6fe2af..3876d83c195 100644 --- a/test/unittest/rtps/builtin/CMakeLists.txt +++ b/test/unittest/rtps/builtin/CMakeLists.txt @@ -13,53 +13,51 @@ # limitations under the License. set(BUILTIN_DATA_SERIALIZATION_TESTS_SOURCE BuiltinDataSerializationTests.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp - - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ReaderProxyData.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/WriterProxyData.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/ResourceEvent.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEvent.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp - - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataFactory.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataPtr.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilder.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeMember.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/MemberDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifierTypes.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectHashId.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/ReaderProxyData.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/data/WriterProxyData.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/ResourceEvent.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEvent.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/resources/TimedEventImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPFinder.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/TimedConditionVariable.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp) + ) if(WIN32) add_definitions(-D_WIN32_WINNT=0x0601) diff --git a/test/unittest/rtps/discovery/CMakeLists.txt b/test/unittest/rtps/discovery/CMakeLists.txt index 240e9f0223d..08f9df15cbb 100644 --- a/test/unittest/rtps/discovery/CMakeLists.txt +++ b/test/unittest/rtps/discovery/CMakeLists.txt @@ -13,42 +13,43 @@ # limitations under the License. set(EDPTESTS_SOURCE EdpTests.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/StringMatching.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataFactory.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataPtr.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilder.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeMember.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/MemberDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifierTypes.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectHashId.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutErrConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/StringMatching.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp ) diff --git a/test/unittest/rtps/network/CMakeLists.txt b/test/unittest/rtps/network/CMakeLists.txt index baaac1b52a9..8dcbf6f8688 100644 --- a/test/unittest/rtps/network/CMakeLists.txt +++ b/test/unittest/rtps/network/CMakeLists.txt @@ -97,46 +97,42 @@ if(QNX) endif() add_executable(ExternalLocatorsProcessorTests ExternalLocatorsProcessorTests.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ExternalLocatorsProcessor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicData.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataFactory.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicDataPtr.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicPubSubType.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicType.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilder.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeBuilderPtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypeMember.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/DynamicTypePtr.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/MemberDescriptor.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/AnnotationParameterValue.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeIdentifierTypes.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeObjectHashId.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypeNamesGenerator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/TypesBase.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/dynamic-types/BuiltinAnnotationsTypeObject.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/ThreadSettings.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp - + ${PROJECT_SOURCE_DIR}/src/cpp/rtps/network/ExternalLocatorsProcessor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/IPLocator.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/md5.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/utils/StringMatching.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/string_convert.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/utils/StringMatching.cpp ${PROJECT_SOURCE_DIR}/src/cpp/utils/SystemInfo.cpp - - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/publisher/qos/WriterQos.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/subscriber/qos/ReaderQos.cpp - - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/OStreamConsumer.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp ) target_compile_definitions(ExternalLocatorsProcessorTests PRIVATE BOOST_ASIO_STANDALONE diff --git a/test/unittest/xmlparser/SHM_transport_descriptors_config_profile.xml b/test/unittest/xmlparser/SHM_transport_descriptors_config_profile.xml index c73fda0779d..a079f97229b 100644 --- a/test/unittest/xmlparser/SHM_transport_descriptors_config_profile.xml +++ b/test/unittest/xmlparser/SHM_transport_descriptors_config_profile.xml @@ -10,6 +10,32 @@ 4294967295 test_file.dump 128000 + + -1 + 0 + 0 + -1 + + + + -1 + 0 + 0 + -1 + + + -1 + 0 + 0 + -1 + + + + -1 + 0 + 0 + -1 + diff --git a/test/unittest/xmlparser/UDP_transport_descriptors_config_profile.xml b/test/unittest/xmlparser/UDP_transport_descriptors_config_profile.xml index 0b58e2a1a0f..e76c68ca781 100644 --- a/test/unittest/xmlparser/UDP_transport_descriptors_config_profile.xml +++ b/test/unittest/xmlparser/UDP_transport_descriptors_config_profile.xml @@ -1,22 +1,42 @@ - - - Test - UDPv4 - 8192 - 8192 - 250 - true - 16384 - 100 - -
192.168.1.41
-
127.0.0.1
-
- 5101 -
-
+ + + Test + UDPv4 + 8192 + 8192 + 250 + true + 16384 + 100 + +
192.168.1.41
+
127.0.0.1
+
+ 5101 + + -1 + 0 + 0 + -1 + + + + -1 + 0 + 0 + -1 + + + -1 + 0 + 0 + -1 + + +
+
diff --git a/test/unittest/xmlparser/XMLElementParserTests.cpp b/test/unittest/xmlparser/XMLElementParserTests.cpp index 693f52a6c9b..f28768dfdf6 100644 --- a/test/unittest/xmlparser/XMLElementParserTests.cpp +++ b/test/unittest/xmlparser/XMLElementParserTests.cpp @@ -16,11 +16,16 @@ #include #include #include +#include +#include #include +#include +#include #include #include +#include #include #include #include @@ -1279,6 +1284,7 @@ TEST_F(XMLParserTests, getXMLUint_NegativeClauses) uint8_t ident = 1; unsigned int ui; uint16_t ui16; + uint64_t ui64; tinyxml2::XMLDocument xml_doc; tinyxml2::XMLElement* titleElement; @@ -1293,6 +1299,12 @@ TEST_F(XMLParserTests, getXMLUint_NegativeClauses) ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse("not_an_uint")); titleElement = xml_doc.RootElement(); EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParserTest::getXMLUint_wrapper(titleElement, &ui16, ident)); + + EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParserTest::getXMLUint_wrapper(nullptr, &ui64, ident)); + + ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse("not_an_uint")); + titleElement = xml_doc.RootElement(); + EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParserTest::getXMLUint_wrapper(titleElement, &ui64, ident)); } /* @@ -4112,3 +4124,206 @@ TEST_F(XMLParserTests, env_var_substitution) clear_environment_variable(env_var_1); clear_environment_variable(env_var_2); } + +/* + * This test checks parsing of thread_settings elements. + */ +TEST_F(XMLParserTests, getXMLThreadSettings) +{ + /* Define the test cases */ + std::vector, XMLP_ret>> test_cases = + { + {{"12", "12", "12", "12", ""}, XMLP_ret::XML_OK}, + {{"-1", "12", "12", "12", ""}, XMLP_ret::XML_OK}, + {{"12", "-1", "12", "12", ""}, XMLP_ret::XML_OK}, + {{"12", "12", "12", "-1", ""}, XMLP_ret::XML_OK}, + {{"-2", "12", "12", "12", ""}, XMLP_ret::XML_ERROR}, + {{"12", "12", "-2", "12", ""}, XMLP_ret::XML_ERROR}, + {{"12", "12", "12", "-2", ""}, XMLP_ret::XML_ERROR}, + {{"a", "12", "12", "12", ""}, XMLP_ret::XML_ERROR}, + {{"12", "a", "12", "12", ""}, XMLP_ret::XML_ERROR}, + {{"12", "12", "a", "12", ""}, XMLP_ret::XML_ERROR}, + {{"12", "12", "12", "a", ""}, XMLP_ret::XML_ERROR}, + {{"12", "12", "12", "12", "12"}, XMLP_ret::XML_ERROR}, + {{"12", "12", "12", "12", "12"}, XMLP_ret::XML_ERROR}, + {{"12", "12", "12", "12", "12"}, XMLP_ret::XML_ERROR}, + {{"12", "12", "12", "12", "12"}, XMLP_ret::XML_ERROR}, + {{"12", "12", "12", "12", "12"}, XMLP_ret::XML_ERROR}, + }; + + /* Run the tests */ + for (auto test_case : test_cases) + { + std::vector& params = test_case.first; + XMLP_ret& expectation = test_case.second; + + using namespace eprosima::fastdds::rtps; + ThreadSettings thread_settings; + tinyxml2::XMLDocument xml_doc; + tinyxml2::XMLElement* titleElement; + + // Create XML snippet + std::string xml = + "" + " " + params[0] + "" + " " + params[1] + "" + " " + params[2] + "" + " " + params[3] + "" + + params[4] + + ""; + + // Parse the XML snippet + ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse(xml.c_str())) << xml; + + // Extract ThreadSetting + titleElement = xml_doc.RootElement(); + ASSERT_EQ(expectation, XMLParserTest::getXMLThreadSettings_wrapper(titleElement, thread_settings)); + + // Validate in the OK cases + if (expectation == XMLP_ret::XML_OK) + { + ASSERT_EQ(thread_settings.scheduling_policy, static_cast(std::stoi(params[0]))); + ASSERT_EQ(thread_settings.priority, static_cast(std::stoi(params[1]))); + ASSERT_EQ(thread_settings.affinity, static_cast(std::stoi(params[2]))); + ASSERT_EQ(thread_settings.stack_size, static_cast(std::stoi(params[3]))); + } + } +} + +/* + * This test checks parsing of thread_settings with port elements. + */ +TEST_F(XMLParserTests, getXMLThreadSettingsWithPort) +{ + /* Define the test cases */ + std::vector, XMLP_ret>> test_cases = + { + {{"12345", "", "12", "12", "12", "12", ""}, XMLP_ret::XML_OK}, + {{"12345", "", "-1", "12", "12", "12", ""}, XMLP_ret::XML_OK}, + {{"12345", "", "12", "-1", "12", "12", ""}, XMLP_ret::XML_OK}, + {{"12345", "", "12", "12", "12", "-1", ""}, XMLP_ret::XML_OK}, + {{"12345", "", "-2", "12", "12", "12", ""}, XMLP_ret::XML_ERROR}, + {{"-1", "", "12", "12", "12", "12", ""}, XMLP_ret::XML_ERROR}, + {{"a", "", "12", "12", "12", "12", ""}, XMLP_ret::XML_ERROR}, + {{"a", "wrong_attr=\"12\"", "12", "12", "12", "12", ""}, XMLP_ret::XML_ERROR}, + {{"12345", "", "12", "12", "12", "-2", ""}, XMLP_ret::XML_ERROR}, + {{"12345", "", "a", "12", "12", "12", ""}, XMLP_ret::XML_ERROR}, + {{"12345", "", "12", "a", "12", "12", ""}, XMLP_ret::XML_ERROR}, + {{"12345", "", "12", "12", "a", "12", ""}, XMLP_ret::XML_ERROR}, + {{"12345", "", "12", "12", "12", "a", ""}, XMLP_ret::XML_ERROR}, + {{"12345", "", "12", "12", "12", "12", "12"}, XMLP_ret::XML_ERROR}, + {{"12345", "", "12", "12", "12", "12", "12"}, XMLP_ret::XML_ERROR}, + }; + + /* Run the tests */ + for (auto test_case : test_cases) + { + std::vector& params = test_case.first; + XMLP_ret& expectation = test_case.second; + + using namespace eprosima::fastdds::rtps; + ThreadSettings thread_settings; + tinyxml2::XMLDocument xml_doc; + tinyxml2::XMLElement* titleElement; + + // Create XML snippet + std::string xml = + "" + " " + params[2] + "" + " " + params[3] + "" + " " + params[4] + "" + " " + params[5] + "" + + params[6] + + ""; + + // Parse the XML snippet + ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse(xml.c_str())) << xml; + + // Extract ThreadSetting + titleElement = xml_doc.RootElement(); + uint32_t port; + ASSERT_EQ(expectation, + XMLParserTest::getXMLThreadSettingsWithPort_wrapper(titleElement, thread_settings, port)); + + // Validate in the OK cases + if (expectation == XMLP_ret::XML_OK) + { + ASSERT_EQ(port, static_cast(std::stoi(params[0]))); + ASSERT_EQ(thread_settings.scheduling_policy, static_cast(std::stoi(params[2]))); + ASSERT_EQ(thread_settings.priority, static_cast(std::stoi(params[3]))); + ASSERT_EQ(thread_settings.affinity, static_cast(std::stoi(params[4]))); + ASSERT_EQ(thread_settings.stack_size, static_cast(std::stoi(params[5]))); + } + } +} + +/* + * This test checks parsing of entity factory qos elements. + */ +TEST_F(XMLParserTests, getXMLEntityFactoryQos) +{ + /* Define the test cases */ + std::vector, XMLP_ret>> test_cases = + { + {{"true", ""}, XMLP_ret::XML_OK}, + {{"false", ""}, XMLP_ret::XML_OK}, + {{"0", ""}, XMLP_ret::XML_OK}, + {{"1", ""}, XMLP_ret::XML_OK}, + {{"20", ""}, XMLP_ret::XML_OK}, + {{"wrong_value", ""}, XMLP_ret::XML_ERROR} + }; + + /* Run the tests */ + for (auto test_case : test_cases) + { + std::vector& params = test_case.first; + XMLP_ret& expectation = test_case.second; + + using namespace eprosima::fastdds::dds; + EntityFactoryQosPolicy entity_factory_qos; + tinyxml2::XMLDocument xml_doc; + tinyxml2::XMLElement* titleElement; + + // Create XML snippet + std::string xml = + "" + " " + params[0] + "" + + params[1] + + ""; + + std::cout << xml << std::endl; + + // Parse the XML snippet + ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, xml_doc.Parse(xml.c_str())); + + // Extract ThreadSetting + titleElement = xml_doc.RootElement(); + ASSERT_EQ(expectation, XMLParserTest::getXMLEntityFactoryQos_wrapper(titleElement, entity_factory_qos)); + + // Validate in the OK cases + if (expectation == XMLP_ret::XML_OK) + { + bool expected_value; + if (params[0] == "true") + { + expected_value = true; + } + else if (params[0] == "false") + { + expected_value = false; + } + else + { + try + { + expected_value = static_cast(std::stoi(params[0])); + } + catch (std::invalid_argument&) + { + expected_value = false; + } + } + ASSERT_EQ(entity_factory_qos.autoenable_created_entities, expected_value); + } + } +} diff --git a/test/unittest/xmlparser/XMLParserTests.cpp b/test/unittest/xmlparser/XMLParserTests.cpp index 5629106e161..bc68f792246 100644 --- a/test/unittest/xmlparser/XMLParserTests.cpp +++ b/test/unittest/xmlparser/XMLParserTests.cpp @@ -12,30 +12,34 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "XMLParserTests.hpp" + +#include +#include + +#include #include #include -#include #include #include -#include "../logging/mock/MockConsumer.h" -#include "XMLParserTests.hpp" -#include "wrapper/XMLParserTest.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include + #include -#include -#include +#include "../logging/mock/MockConsumer.h" +#include "wrapper/XMLParserTest.hpp" using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; @@ -861,6 +865,12 @@ TEST_F(XMLParserTests, loadXMLProfiles) */ TEST_F(XMLParserTests, parseXMLTransportData) { + eprosima::fastdds::rtps::ThreadSettings modified_thread_settings; + modified_thread_settings.scheduling_policy = 12; + modified_thread_settings.priority = 12; + modified_thread_settings.affinity = 12; + modified_thread_settings.stack_size = 12; + // Test UDPv4 and UDPv6 { tinyxml2::XMLDocument xml_doc; @@ -900,9 +910,29 @@ TEST_F(XMLParserTests, parseXMLTransportData) 512\ 1000\ rtsp_messages.log\ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ \ "; - constexpr size_t xml_len {2000}; + constexpr size_t xml_len {3000}; char xml[xml_len]; // UDPv4 @@ -922,6 +952,9 @@ TEST_F(XMLParserTests, parseXMLTransportData) EXPECT_EQ(pUDPv4Desc->interfaceWhiteList[0], "192.168.1.41"); EXPECT_EQ(pUDPv4Desc->interfaceWhiteList[1], "127.0.0.1"); EXPECT_EQ(pUDPv4Desc->m_output_udp_socket, 5101u); + EXPECT_EQ(pUDPv4Desc->default_reception_threads(), modified_thread_settings); + EXPECT_EQ(pUDPv4Desc->get_thread_config_for_port(12345), modified_thread_settings); + EXPECT_EQ(pUDPv4Desc->get_thread_config_for_port(12346), modified_thread_settings); xmlparser::XMLProfileManager::DeleteInstance(); @@ -942,6 +975,9 @@ TEST_F(XMLParserTests, parseXMLTransportData) EXPECT_EQ(pUDPv6Desc->interfaceWhiteList[0], "192.168.1.41"); EXPECT_EQ(pUDPv6Desc->interfaceWhiteList[1], "127.0.0.1"); EXPECT_EQ(pUDPv6Desc->m_output_udp_socket, 5101u); + EXPECT_EQ(pUDPv6Desc->default_reception_threads(), modified_thread_settings); + EXPECT_EQ(pUDPv6Desc->get_thread_config_for_port(12345), modified_thread_settings); + EXPECT_EQ(pUDPv6Desc->get_thread_config_for_port(12346), modified_thread_settings); xmlparser::XMLProfileManager::DeleteInstance(); } @@ -978,9 +1014,29 @@ TEST_F(XMLParserTests, parseXMLTransportData) false\ false\ \ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ \ "; - constexpr size_t xml_len {2000}; + constexpr size_t xml_len {3000}; char xml[xml_len]; // TCPv4 @@ -1010,6 +1066,9 @@ TEST_F(XMLParserTests, parseXMLTransportData) EXPECT_EQ(pTCPv4Desc->logical_port_increment, 2u); EXPECT_EQ(pTCPv4Desc->listening_ports[0], 5100u); EXPECT_EQ(pTCPv4Desc->listening_ports[1], 5200u); + EXPECT_EQ(pTCPv4Desc->default_reception_threads(), modified_thread_settings); + EXPECT_EQ(pTCPv4Desc->get_thread_config_for_port(12345), modified_thread_settings); + EXPECT_EQ(pTCPv4Desc->get_thread_config_for_port(12346), modified_thread_settings); xmlparser::XMLProfileManager::DeleteInstance(); // TCPv6 @@ -1035,6 +1094,9 @@ TEST_F(XMLParserTests, parseXMLTransportData) EXPECT_EQ(pTCPv6Desc->logical_port_increment, 2u); EXPECT_EQ(pTCPv6Desc->listening_ports[0], 5100u); EXPECT_EQ(pTCPv6Desc->listening_ports[1], 5200u); + EXPECT_EQ(pTCPv6Desc->default_reception_threads(), modified_thread_settings); + EXPECT_EQ(pTCPv6Desc->get_thread_config_for_port(12345), modified_thread_settings); + EXPECT_EQ(pTCPv6Desc->get_thread_config_for_port(12346), modified_thread_settings); xmlparser::XMLProfileManager::DeleteInstance(); } @@ -1054,6 +1116,32 @@ TEST_F(XMLParserTests, parseXMLTransportData) rtsp_messages.log\ 16384\ 100\ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ + \ + 12\ + 12\ + 12\ + 12\ + \ \ "; @@ -1069,6 +1157,10 @@ TEST_F(XMLParserTests, parseXMLTransportData) EXPECT_EQ(pSHMDesc->rtps_dump_file(), "rtsp_messages.log"); EXPECT_EQ(pSHMDesc->max_message_size(), 16384u); EXPECT_EQ(pSHMDesc->max_initial_peers_range(), 100u); + EXPECT_EQ(pSHMDesc->default_reception_threads(), modified_thread_settings); + EXPECT_EQ(pSHMDesc->get_thread_config_for_port(12345), modified_thread_settings); + EXPECT_EQ(pSHMDesc->get_thread_config_for_port(12346), modified_thread_settings); + EXPECT_EQ(pSHMDesc->dump_thread(), modified_thread_settings); xmlparser::XMLProfileManager::DeleteInstance(); } @@ -1099,6 +1191,8 @@ TEST_F(XMLParserTests, parseXMLTransportData_NegativeClauses) "non_blocking_send", "interfaceWhiteList", "output_port", + "default_reception_threads", + "reception_threads", "bad_element" }; @@ -1109,9 +1203,7 @@ TEST_F(XMLParserTests, parseXMLTransportData_NegativeClauses) "sendBufferSize", "receiveBufferSize", "TTL", - "non_blocking_send", "interfaceWhiteList", - "output_port", "keep_alive_frequency_ms", "keep_alive_timeout_ms", "max_logical_port", @@ -1121,6 +1213,8 @@ TEST_F(XMLParserTests, parseXMLTransportData_NegativeClauses) "check_crc", "enable_tcp_nodelay", "tls", + "default_reception_threads", + "reception_threads", "bad_element" }; @@ -1132,6 +1226,9 @@ TEST_F(XMLParserTests, parseXMLTransportData_NegativeClauses) "port_queue_capacity", "healthy_check_timeout_ms", "rtps_dump_file", + "default_reception_threads", + "reception_threads", + "dump_thread", "bad_element" }; @@ -1559,7 +1656,7 @@ TEST_F(XMLParserTests, parseXMLConsumerNegativeClauses) /* * This test checks the return of the parseLogConfig method. - * 1. Check a consummer with a wrong class + * 1. Check a consumer with a wrong class * 2. Check the use_default tag without TRUE and TRUE * 3. Check a wrong tag */ @@ -2879,6 +2976,146 @@ TEST_F(XMLParserTests, parseXMLTopicDataNegativeClauses) EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParserTest::parseXMLTopicData_wrapper(nullptr, *topic_node)); } +/* + * This test checks the behaviour of the parseXMLReceptionThreads function. + */ +TEST_F(XMLParserTests, parseXMLReceptionThreads) +{ + using namespace eprosima::fastdds::rtps; + + struct TestCase + { + std::string title; + std::string xml; + xmlparser::XMLP_ret result; + PortBasedTransportDescriptor::ReceptionThreadsConfigMap threads_config; + }; + + ThreadSettings modified_thread_settings; + modified_thread_settings.scheduling_policy = 12; + modified_thread_settings.priority = 12; + modified_thread_settings.affinity = 12; + modified_thread_settings.stack_size = 12; + + + std::vector test_cases = + { + { + "reception_threads_empty", + "", + xmlparser::XMLP_ret::XML_OK, + {} + }, + { + "reception_threads_ok", + R"( + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + )", + xmlparser::XMLP_ret::XML_OK, + { + {12345, {modified_thread_settings}}, + {12346, {modified_thread_settings}} + } + }, + { + "reception_threads_duplicated", + R"( + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + )", + xmlparser::XMLP_ret::XML_ERROR, + {} + }, + { + "reception_threads_wrong_tags", + R"( + + + 12 + 12 + 12 + 12 + + )", + xmlparser::XMLP_ret::XML_ERROR, + {} + }, + { + "reception_threads_wrong_attribute", + R"( + + + 12 + 12 + 12 + 12 + + )", + xmlparser::XMLP_ret::XML_ERROR, + {} + }, + { + "reception_threads_no_attribute", + R"( + + + 12 + 12 + 12 + 12 + + )", + xmlparser::XMLP_ret::XML_ERROR, + {} + }, + }; + + for (auto test_case : test_cases) + { + tinyxml2::XMLDocument xml_doc; + std::unique_ptr root; + tinyxml2::XMLElement* titleElement; + PortBasedTransportDescriptor::ReceptionThreadsConfigMap reception_threads; + + ASSERT_EQ(tinyxml2::XMLError::XML_SUCCESS, + xml_doc.Parse(test_case.xml.c_str())) << "test_case = [" << test_case.title << "]"; + + titleElement = xml_doc.RootElement(); + EXPECT_EQ(test_case.result, XMLParserTest::parseXMLReceptionThreads_wrapper(*titleElement, reception_threads)); + + if (test_case.result == xmlparser::XMLP_ret::XML_OK) + { + for (auto entry : test_case.threads_config) + { + EXPECT_EQ(entry.second, reception_threads[entry.first]); + } + } + } +} + int main( int argc, char** argv) diff --git a/test/unittest/xmlparser/XMLProfileParserTests.cpp b/test/unittest/xmlparser/XMLProfileParserTests.cpp index 39e617a6fa0..5947a466e5f 100644 --- a/test/unittest/xmlparser/XMLProfileParserTests.cpp +++ b/test/unittest/xmlparser/XMLProfileParserTests.cpp @@ -22,6 +22,8 @@ #include #include +#include +#include #include #include #include @@ -57,8 +59,14 @@ void TestClearConsumersFunc() log_mock->ClearConsumers(); } +void TestSetThreadConfigFunc() +{ + log_mock->SetThreadConfig(); +} + std::function&&)> Log::RegisterConsumerFunc = TestRegisterConsumerFunc; std::function Log::ClearConsumersFunc = TestClearConsumersFunc; +std::function Log::SetThreadConfigFunc = TestSetThreadConfigFunc; class XMLProfileParserBasicTests : public ::testing::Test { @@ -122,7 +130,7 @@ class XMLProfileParserTests : public XMLProfileParserBasicTests, public testing: std::string xml_filename_ = "test_xml_profile.xml"; - const std::pair c_environment_values_[156] + const std::pair c_environment_values_[161] { {"XML_PROFILES_ENV_VAR_1", "123"}, {"XML_PROFILES_ENV_VAR_2", "4"}, @@ -279,7 +287,12 @@ class XMLProfileParserTests : public XMLProfileParserBasicTests, public testing: {"XML_PROFILES_ENV_VAR_153", "0"}, {"XML_PROFILES_ENV_VAR_154", "KEEP_ALL"}, {"XML_PROFILES_ENV_VAR_155", "1001"}, - {"XML_PROFILES_ENV_VAR_156", "FULL"} + {"XML_PROFILES_ENV_VAR_156", "FULL"}, + {"XML_PROFILES_ENV_VAR_157", "true"}, + {"XML_PROFILES_ENV_VAR_158", "-1"}, + {"XML_PROFILES_ENV_VAR_159", "0"}, + {"XML_PROFILES_ENV_VAR_160", "0"}, + {"XML_PROFILES_ENV_VAR_161", "-1"} }; }; @@ -1638,6 +1651,7 @@ TEST_F(XMLProfileParserBasicTests, file_and_default) using namespace eprosima::fastdds::dds; EXPECT_CALL(*log_mock, RegisterConsumer(IsFileConsumer())).Times(1); + EXPECT_CALL(*log_mock, SetThreadConfig()).Times(1); xmlparser::XMLProfileManager::loadXMLFile("log_def_file_profile.xml"); } @@ -3188,6 +3202,905 @@ TEST_F(XMLProfileParserBasicTests, external_locators_feature) } } +/** + * This test checks positive and negative cases for parsing of ThreadSettings in Log + */ +TEST_F(XMLProfileParserBasicTests, log_thread_settings_qos) +{ + struct TestCase + { + std::string title; + std::string xml; + xmlparser::XMLP_ret result; + }; + + std::vector test_cases = + { + /* Log test cases */ + { + "log_thread_settings_ok", + R"( + + + + + -1 + 0 + 0 + -1 + + + )", + xmlparser::XMLP_ret::XML_OK + }, + { + "log_thread_settings_duplicate", + R"( + + + + + -1 + 0 + 0 + -1 + + + -1 + 0 + 0 + -1 + + + )", + xmlparser::XMLP_ret::XML_ERROR + }, + { + "log_thread_settings_wrong", + R"( + + + + + -1 + 0 + 0 + -1 + 0 + + + )", + xmlparser::XMLP_ret::XML_ERROR + }, + }; + + EXPECT_CALL(*log_mock, SetThreadConfig()).Times(1); + for (const TestCase& test : test_cases) + { + EXPECT_EQ(test.result, xmlparser::XMLProfileManager::loadXMLString(test.xml.c_str(), test.xml.length())) << + " test_case = [" << test.title << "]"; + xmlparser::XMLProfileManager::DeleteInstance(); + } +} + +/** + * This test checks positive and negative cases for parsing of DomainParticipantFactory Qos + */ +TEST_F(XMLProfileParserBasicTests, domainparticipantfactory) +{ + using namespace eprosima::fastdds::dds; + using namespace eprosima::fastdds::rtps; + struct TestCase + { + std::string title; + std::string xml; + xmlparser::XMLP_ret result; + EntityFactoryQosPolicy entity_factory; + ThreadSettings shm_watchdog_thread; + ThreadSettings file_watch_threads; + }; + + ThreadSettings default_thread_settings; + ThreadSettings modified_thread_settings; + modified_thread_settings.scheduling_policy = 12; + modified_thread_settings.priority = 12; + modified_thread_settings.affinity = 12; + modified_thread_settings.stack_size = 12; + + std::vector test_cases = + { + /* DomainParticipantFactory cases */ + { + "entity_factory_ok", + R"( + + + + + + + false + + + + + )", + xmlparser::XMLP_ret::XML_OK, + EntityFactoryQosPolicy(false), + default_thread_settings, + default_thread_settings + }, + { + "shm_watchdog_thread_ok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_OK, + EntityFactoryQosPolicy(true), + modified_thread_settings, + default_thread_settings + }, + { + "file_watch_threads_ok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_OK, + EntityFactoryQosPolicy(true), + default_thread_settings, + modified_thread_settings + }, + { + "all_present_ok", + R"( + + + + + + + false + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_OK, + EntityFactoryQosPolicy(false), + modified_thread_settings, + modified_thread_settings + }, + { + "qos_duplicated", + R"( + + + + + + + false + + + + + false + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + EntityFactoryQosPolicy(true), + default_thread_settings, + default_thread_settings + }, + { + "entity_factory_wrong_tag", + R"( + + + + + + + false + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + EntityFactoryQosPolicy(true), + default_thread_settings, + default_thread_settings + }, + { + "entity_factory_duplicated_autoenable_created_entities_tag", + R"( + + + + + + + false + false + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + EntityFactoryQosPolicy(true), + default_thread_settings, + default_thread_settings + }, + { + "entity_factory_duplicated_autoenable_created_entities_and_wrong_tag", + R"( + + + + + + + false + false + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + EntityFactoryQosPolicy(true), + default_thread_settings, + default_thread_settings + }, + { + "entity_factory_duplicated", + R"( + + + + + + + false + + + false + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + EntityFactoryQosPolicy(true), + modified_thread_settings, + modified_thread_settings + }, + { + "shm_watchdog_thread_duplicated", + R"( + + + + + + + false + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + EntityFactoryQosPolicy(true), + modified_thread_settings, + modified_thread_settings + }, + { + "file_watch_threads_duplicated", + R"( + + + + + + + false + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + EntityFactoryQosPolicy(true), + modified_thread_settings, + modified_thread_settings + } + }; + + for (const TestCase& test : test_cases) + { + EXPECT_EQ(test.result, xmlparser::XMLProfileManager::loadXMLString(test.xml.c_str(), test.xml.length())) << + " test_case = [" << test.title << "]"; + if (test.result == xmlparser::XMLP_ret::XML_OK) + { + using namespace eprosima::fastdds::dds; + + DomainParticipantFactoryQos profile_qos; + ASSERT_EQ(xmlparser::XMLP_ret::XML_OK, + xmlparser::XMLProfileManager::fillDomainParticipantFactoryQos("factory", profile_qos)); + + DomainParticipantFactoryQos default_qos; + xmlparser::XMLProfileManager::getDefaultDomainParticipantFactoryQos(default_qos); + + ASSERT_EQ(profile_qos, default_qos); + ASSERT_EQ(profile_qos.entity_factory(), test.entity_factory); + ASSERT_EQ(profile_qos.shm_watchdog_thread(), test.shm_watchdog_thread); + ASSERT_EQ(profile_qos.file_watch_threads(), test.file_watch_threads); + } + xmlparser::XMLProfileManager::DeleteInstance(); + } +} + +/** + * This test checks positive and negative cases for parsing of DomainParticipant ThreadSettings + */ +TEST_F(XMLProfileParserBasicTests, participant_thread_settings) +{ + using namespace eprosima::fastdds::dds; + using namespace eprosima::fastdds::rtps; + struct TestCase + { + std::string title; + std::string xml; + xmlparser::XMLP_ret result; + ThreadSettings builtin_controllers_sender_thread; + ThreadSettings timed_events_thread; + ThreadSettings discovery_server_thread; + ThreadSettings builtin_transports_reception_threads; +#if HAVE_SECURITY + ThreadSettings security_log_thread; +#endif // if HAVE_SECURITY + }; + + ThreadSettings default_thread_settings; + ThreadSettings modified_thread_settings; + modified_thread_settings.scheduling_policy = 12; + modified_thread_settings.priority = 12; + modified_thread_settings.affinity = 12; + modified_thread_settings.stack_size = 12; + + std::vector test_cases = + { + { + "builtin_controllers_sender_thread_ok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_OK, + modified_thread_settings, + default_thread_settings, + default_thread_settings, + default_thread_settings, + default_thread_settings + }, + { + "builtin_controllers_sender_thread_nok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + modified_thread_settings, + default_thread_settings, + default_thread_settings, + default_thread_settings, + default_thread_settings + }, + { + "timed_events_thread_ok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_OK, + default_thread_settings, + modified_thread_settings, + default_thread_settings, + default_thread_settings, + default_thread_settings + }, + { + "timed_events_thread_nok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + default_thread_settings, + modified_thread_settings, + default_thread_settings, + default_thread_settings, + default_thread_settings + }, + { + "discovery_server_thread_ok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_OK, + default_thread_settings, + default_thread_settings, + modified_thread_settings, + default_thread_settings, + default_thread_settings + }, + { + "discovery_server_thread_nok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + default_thread_settings, + default_thread_settings, + modified_thread_settings, + default_thread_settings, + default_thread_settings + }, + { + "builtin_transports_reception_threads_ok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_OK, + default_thread_settings, + default_thread_settings, + default_thread_settings, + modified_thread_settings, + default_thread_settings + }, + { + "builtin_transports_reception_threads_nok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + default_thread_settings, + default_thread_settings, + default_thread_settings, + modified_thread_settings, + default_thread_settings + }, +#if HAVE_SECURITY + { + "security_log_thread_ok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_OK, + default_thread_settings, + default_thread_settings, + default_thread_settings, + default_thread_settings, + modified_thread_settings + }, + { + "security_log_thread_nok", + R"( + + + + + + + 12 + 12 + 12 + 12 + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + default_thread_settings, + default_thread_settings, + default_thread_settings, + default_thread_settings, + modified_thread_settings + }, +#endif // if HAVE_SECURITY + }; + + for (const TestCase& test : test_cases) + { + EXPECT_EQ(test.result, xmlparser::XMLProfileManager::loadXMLString(test.xml.c_str(), test.xml.length())) << + " test_case = [" << test.title << "]"; + if (test.result == xmlparser::XMLP_ret::XML_OK) + { + using namespace eprosima::fastdds::dds; + + ParticipantAttributes profile_attr; + ASSERT_EQ(xmlparser::XMLP_ret::XML_OK, + xmlparser::XMLProfileManager::fillParticipantAttributes("participant", profile_attr)); + + ParticipantAttributes default_attr; + xmlparser::XMLProfileManager::getDefaultParticipantAttributes(default_attr); + + ASSERT_EQ(profile_attr, default_attr); + ASSERT_EQ(profile_attr.rtps.builtin_controllers_sender_thread, test.builtin_controllers_sender_thread); + ASSERT_EQ(profile_attr.rtps.timed_events_thread, test.timed_events_thread); + ASSERT_EQ(profile_attr.rtps.discovery_server_thread, test.discovery_server_thread); + ASSERT_EQ(profile_attr.rtps.builtin_transports_reception_threads, + test.builtin_transports_reception_threads); +#if HAVE_SECURITY + ASSERT_EQ(profile_attr.rtps.security_log_thread, test.security_log_thread); +#endif // if HAVE_SECURITY + } + xmlparser::XMLProfileManager::DeleteInstance(); + } +} + +/** + * This test checks positive and negative cases for parsing of DataReader ThreadSettings + */ +TEST_F(XMLProfileParserBasicTests, datareader_thread_settings) +{ + using namespace eprosima::fastdds::dds; + using namespace eprosima::fastdds::rtps; + struct TestCase + { + std::string title; + std::string xml; + xmlparser::XMLP_ret result; + ThreadSettings data_sharing_listener_thread; + }; + + ThreadSettings default_thread_settings; + ThreadSettings modified_thread_settings; + modified_thread_settings.scheduling_policy = 12; + modified_thread_settings.priority = 12; + modified_thread_settings.affinity = 12; + modified_thread_settings.stack_size = 12; + + std::vector test_cases = + { + { + "data_sharing_listener_thread_ok", + R"( + + + + + + + AUTOMATIC + + 12 + 12 + 12 + 12 + + + + + + )", + xmlparser::XMLP_ret::XML_OK, + modified_thread_settings + }, + { + "data_sharing_listener_thread_empty", + R"( + + + + + + + AUTOMATIC + + + + + + + )", + xmlparser::XMLP_ret::XML_OK, + default_thread_settings, + }, + { + "no_data_sharing_listener_thread", + R"( + + + + + + + AUTOMATIC + + + + + )", + xmlparser::XMLP_ret::XML_OK, + default_thread_settings, + }, + { + "data_sharing_listener_thread_wrong_value", + R"( + + + + + + + AUTOMATIC + + aa + 0 + 0 + 0 + + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + default_thread_settings, + }, + { + "data_sharing_listener_thread_wrong_tag", + R"( + + + + + + + AUTOMATIC + + -1 + 0 + 0 + 0 + + + + + + )", + xmlparser::XMLP_ret::XML_ERROR, + default_thread_settings, + }, + }; + + for (const TestCase& test : test_cases) + { + EXPECT_EQ(test.result, xmlparser::XMLProfileManager::loadXMLString(test.xml.c_str(), test.xml.length())) << + " test_case = [" << test.title << "]"; + if (test.result == xmlparser::XMLP_ret::XML_OK) + { + SubscriberAttributes profile_attr; + ASSERT_EQ(xmlparser::XMLP_ret::XML_OK, + xmlparser::XMLProfileManager::fillSubscriberAttributes("datareader", profile_attr)); + + SubscriberAttributes default_attr; + xmlparser::XMLProfileManager::getDefaultSubscriberAttributes(default_attr); + + ASSERT_EQ(profile_attr, default_attr); + ASSERT_EQ(profile_attr.qos.data_sharing.data_sharing_listener_thread(), test.data_sharing_listener_thread); + } + xmlparser::XMLProfileManager::DeleteInstance(); + } +} + INSTANTIATE_TEST_SUITE_P(XMLProfileParserTests, XMLProfileParserTests, testing::Values(false)); INSTANTIATE_TEST_SUITE_P(XMLProfileParserEnvVarTests, XMLProfileParserTests, testing::Values(true)); diff --git a/test/unittest/xmlparser/log_def_file_profile.xml b/test/unittest/xmlparser/log_def_file_profile.xml index fc803ed3fe6..38b052a081c 100644 --- a/test/unittest/xmlparser/log_def_file_profile.xml +++ b/test/unittest/xmlparser/log_def_file_profile.xml @@ -5,5 +5,11 @@ FileConsumer + + -1 + 0 + 0 + -1 + diff --git a/test/unittest/xmlparser/test_xml_deprecated.xml b/test/unittest/xmlparser/test_xml_deprecated.xml index 2d38fdb4fdc..99ead8f8282 100644 --- a/test/unittest/xmlparser/test_xml_deprecated.xml +++ b/test/unittest/xmlparser/test_xml_deprecated.xml @@ -151,6 +151,36 @@ 56.30.0.CE + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 +
diff --git a/test/unittest/xmlparser/test_xml_profile.xml b/test/unittest/xmlparser/test_xml_profile.xml index 39f8b8e284c..f97ae1328ce 100644 --- a/test/unittest/xmlparser/test_xml_profile.xml +++ b/test/unittest/xmlparser/test_xml_profile.xml @@ -1,6 +1,25 @@ + + + + true + + + -1 + 0 + 0 + -1 + + + -1 + 0 + 0 + -1 + + + 123 @@ -147,6 +166,36 @@ 56.30.0.ce + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + diff --git a/test/unittest/xmlparser/test_xml_profile_env_var.xml b/test/unittest/xmlparser/test_xml_profile_env_var.xml index a5abd2143f0..91b238eb638 100644 --- a/test/unittest/xmlparser/test_xml_profile_env_var.xml +++ b/test/unittest/xmlparser/test_xml_profile_env_var.xml @@ -147,6 +147,36 @@ ${XML_PROFILES_ENV_VAR_66} + + ${XML_PROFILES_ENV_VAR_158} + ${XML_PROFILES_ENV_VAR_159} + ${XML_PROFILES_ENV_VAR_160} + ${XML_PROFILES_ENV_VAR_161} + + + ${XML_PROFILES_ENV_VAR_158} + ${XML_PROFILES_ENV_VAR_159} + ${XML_PROFILES_ENV_VAR_160} + ${XML_PROFILES_ENV_VAR_161} + + + ${XML_PROFILES_ENV_VAR_158} + ${XML_PROFILES_ENV_VAR_159} + ${XML_PROFILES_ENV_VAR_160} + ${XML_PROFILES_ENV_VAR_161} + + + ${XML_PROFILES_ENV_VAR_158} + ${XML_PROFILES_ENV_VAR_159} + ${XML_PROFILES_ENV_VAR_160} + ${XML_PROFILES_ENV_VAR_161} + + + ${XML_PROFILES_ENV_VAR_158} + ${XML_PROFILES_ENV_VAR_159} + ${XML_PROFILES_ENV_VAR_160} + ${XML_PROFILES_ENV_VAR_161} +
@@ -388,4 +418,23 @@ ${XML_PROFILES_ENV_VAR_156} + + + + ${XML_PROFILES_ENV_VAR_157} + + + ${XML_PROFILES_ENV_VAR_158} + ${XML_PROFILES_ENV_VAR_159} + ${XML_PROFILES_ENV_VAR_160} + ${XML_PROFILES_ENV_VAR_161} + + + ${XML_PROFILES_ENV_VAR_158} + ${XML_PROFILES_ENV_VAR_159} + ${XML_PROFILES_ENV_VAR_160} + ${XML_PROFILES_ENV_VAR_161} + + + diff --git a/test/unittest/xmlparser/test_xml_rooted_deprecated.xml b/test/unittest/xmlparser/test_xml_rooted_deprecated.xml index 2225fe2c134..79d773dfba8 100644 --- a/test/unittest/xmlparser/test_xml_rooted_deprecated.xml +++ b/test/unittest/xmlparser/test_xml_rooted_deprecated.xml @@ -126,6 +126,36 @@ true test_name + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 +
diff --git a/test/unittest/xmlparser/test_xml_rooted_profile.xml b/test/unittest/xmlparser/test_xml_rooted_profile.xml index 9a28be1f38b..b6e95e1751e 100644 --- a/test/unittest/xmlparser/test_xml_rooted_profile.xml +++ b/test/unittest/xmlparser/test_xml_rooted_profile.xml @@ -1,6 +1,25 @@ + + + + true + + + -1 + 0 + 0 + -1 + + + -1 + 0 + 0 + -1 + + + 123 @@ -122,6 +141,36 @@ 9898 true test_name + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 + + + 12 + 12 + 12 + 12 +
diff --git a/test/unittest/xmlparser/wrapper/XMLParserTest.hpp b/test/unittest/xmlparser/wrapper/XMLParserTest.hpp index 9c4fe763afd..c78524bb6bf 100644 --- a/test/unittest/xmlparser/wrapper/XMLParserTest.hpp +++ b/test/unittest/xmlparser/wrapper/XMLParserTest.hpp @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include +#include #include using namespace eprosima::fastrtps; @@ -214,6 +217,14 @@ class XMLParserTest : public XMLParser return getXMLUint(elem, ui16, ident); } + static XMLP_ret getXMLUint_wrapper( + tinyxml2::XMLElement* elem, + uint64_t* ui64, + uint8_t ident) + { + return getXMLUint(elem, ui64, ident); + } + static XMLP_ret getXMLBuiltinAttributes_wrapper( tinyxml2::XMLElement* elem, BuiltinAttributes& builtin, @@ -494,6 +505,13 @@ class XMLParserTest : public XMLParser return parse_tls_config(p_root, tcp_transport); } + static XMLP_ret parseXMLReceptionThreads_wrapper( + tinyxml2::XMLElement& p_root, + eprosima::fastdds::rtps::PortBasedTransportDescriptor::ReceptionThreadsConfigMap& reception_threads) + { + return parseXMLReceptionThreads(p_root, reception_threads); + } + static XMLP_ret parseXMLLibrarySettings_wrapper( tinyxml2::XMLElement* p_root) { @@ -577,4 +595,26 @@ class XMLParserTest : public XMLParser return parseXMLTopicData(p_root, rootNode); } + static XMLP_ret getXMLThreadSettings_wrapper( + tinyxml2::XMLElement* p_root, + eprosima::fastdds::rtps::ThreadSettings& thread_settings) + { + return getXMLThreadSettings(*p_root, thread_settings); + } + + static XMLP_ret getXMLThreadSettingsWithPort_wrapper( + tinyxml2::XMLElement* p_root, + eprosima::fastdds::rtps::ThreadSettings& thread_settings, + uint32_t& port) + { + return getXMLThreadSettingsWithPort(*p_root, thread_settings, port); + } + + static XMLP_ret getXMLEntityFactoryQos_wrapper( + tinyxml2::XMLElement* p_root, + eprosima::fastdds::dds::EntityFactoryQosPolicy& entity_factory) + { + return getXMLEntityFactoryQos(*p_root, entity_factory); + } + }; From 22ba2297dbe160be058723a4e4f2b4b54d911b6a Mon Sep 17 00:00:00 2001 From: Eduardo Ponz Segrelles Date: Thu, 2 Nov 2023 09:56:27 +0100 Subject: [PATCH 6/9] Fix doxygen (#3987) Signed-off-by: EduPonz --- include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp b/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp index e35ad1dfa33..44f96e589f6 100644 --- a/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp +++ b/include/fastdds/rtps/transport/PortBasedTransportDescriptor.hpp @@ -65,7 +65,7 @@ class PortBasedTransportDescriptor : public TransportDescriptorInterface * * This function first looks for the port-specific ThreadSettings in the user-configured * reception threads map, i.e. the collection of ThreadSettings returned by @ref reception_threads(). - * If the ThreadSettings are found within said map, then @ref get_thread_config_for_port(uint32_t) returns them; + * If the ThreadSettings are found within said map, then @ref get_thread_config_for_port() returns them; * else it returns the default reception thread settings, i.e. the ThreadSettings returned by * @ref default_reception_threads(). * From 12f3727be016f02a00af243e9e4c18d5663d5a3f Mon Sep 17 00:00:00 2001 From: Eduardo Ponz Segrelles Date: Fri, 10 Nov 2023 07:25:46 +0100 Subject: [PATCH 7/9] Parse missing TCPTransportDescriptor XML elements (#4001) * Refs #19378: Set DomainParticipantFactoryQos when loading profiles Signed-off-by: EduPonz * Refs #19378: Parse missing TCPTransportDescriptor XML elements Signed-off-by: EduPonz --------- Signed-off-by: EduPonz --- .../qos/DomainParticipantFactoryQos.hpp | 2 ++ include/fastrtps/xmlparser/XMLParserCommon.h | 2 ++ resources/xsd/fastRTPS_profiles.xsd | 4 ++++ .../domain/DomainParticipantFactory.cpp | 23 ++++++++++++------- .../qos/DomainParticipantFactoryQos.cpp | 13 ++++++++++- src/cpp/rtps/xmlparser/XMLParser.cpp | 20 ++++++++++++++++ src/cpp/rtps/xmlparser/XMLParserCommon.cpp | 2 ++ .../transport/TCPTransportDescriptor.h | 3 +++ .../fastrtps/xmlparser/XMLEndpointParser.h | 4 +--- test/unittest/dds/publisher/CMakeLists.txt | 1 + test/unittest/statistics/dds/CMakeLists.txt | 1 + test/unittest/xmlparser/XMLParserTests.cpp | 20 +++++++++++++++- 12 files changed, 82 insertions(+), 13 deletions(-) diff --git a/include/fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp b/include/fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp index 27a49ac6819..12e46cc1535 100644 --- a/include/fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp +++ b/include/fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp @@ -162,6 +162,8 @@ class DomainParticipantFactoryQos }; +RTPS_DllAPI extern const DomainParticipantFactoryQos PARTICIPANT_FACTORY_QOS_DEFAULT; + } /* namespace dds */ } /* namespace fastdds */ } /* namespace eprosima */ diff --git a/include/fastrtps/xmlparser/XMLParserCommon.h b/include/fastrtps/xmlparser/XMLParserCommon.h index ac16431ec0d..8aa85c99711 100644 --- a/include/fastrtps/xmlparser/XMLParserCommon.h +++ b/include/fastrtps/xmlparser/XMLParserCommon.h @@ -73,6 +73,8 @@ extern const char* METADATA_LOGICAL_PORT; extern const char* LISTENING_PORTS; extern const char* CALCULATE_CRC; extern const char* CHECK_CRC; +extern const char* KEEP_ALIVE_THREAD; +extern const char* ACCEPT_THREAD; extern const char* SEGMENT_SIZE; extern const char* PORT_QUEUE_CAPACITY; extern const char* PORT_OVERFLOW_POLICY; diff --git a/resources/xsd/fastRTPS_profiles.xsd b/resources/xsd/fastRTPS_profiles.xsd index 1a7c1310596..4ceefe0e91b 100644 --- a/resources/xsd/fastRTPS_profiles.xsd +++ b/resources/xsd/fastRTPS_profiles.xsd @@ -855,6 +855,8 @@ ├ calculate_crc [bool], (ONLY available for TCP type) ├ check_crc [bool], (ONLY available for TCP type) ├ enable_tcp_nodelay [bool], (ONLY available for TCP type) + ├ keep_alive_thread [threadSettingsType], (ONLY available for TCP type) + ├ accept_thread [threadSettingsType], (ONLY available for TCP type) ├ segment_size [uint32], (ONLY available for SHM type) ├ port_queue_capacity [uint32], (ONLY available for SHM type) ├ healthy_check_timeout_ms [uint32], (ONLY available for SHM type) @@ -912,6 +914,8 @@ + + diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index ed27c18d7c5..c14387e810b 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -19,23 +19,24 @@ #include #include +#include #include +#include +#include #include #include +#include #include #include #include -#include #include +#include -#include -#include -#include -#include #include +#include #include -#include #include +#include using namespace eprosima::fastrtps::xmlparser; @@ -157,8 +158,6 @@ DomainParticipant* DomainParticipantFactory::create_participant( { load_profiles(); - RTPSDomain::set_filewatch_thread_config(factory_qos_.file_watch_threads(), factory_qos_.file_watch_threads()); - const DomainParticipantQos& pqos = (&qos == &PARTICIPANT_QOS_DEFAULT) ? default_participant_qos_ : qos; DomainParticipant* dom_part = new DomainParticipant(mask); @@ -337,11 +336,19 @@ ReturnCode_t DomainParticipantFactory::load_profiles() // Change as already loaded default_xml_profiles_loaded = true; + // Only change factory qos when not explicitly set by the user + if (factory_qos_ == PARTICIPANT_FACTORY_QOS_DEFAULT) + { + XMLProfileManager::getDefaultDomainParticipantFactoryQos(factory_qos_); + } + // Only change default participant qos when not explicitly set by the user if (default_participant_qos_ == PARTICIPANT_QOS_DEFAULT) { reset_default_participant_qos(); } + + RTPSDomain::set_filewatch_thread_config(factory_qos_.file_watch_threads(), factory_qos_.file_watch_threads()); } return ReturnCode_t::RETCODE_OK; diff --git a/src/cpp/fastdds/domain/qos/DomainParticipantFactoryQos.cpp b/src/cpp/fastdds/domain/qos/DomainParticipantFactoryQos.cpp index 07b859fbd88..307b6c7dec0 100644 --- a/src/cpp/fastdds/domain/qos/DomainParticipantFactoryQos.cpp +++ b/src/cpp/fastdds/domain/qos/DomainParticipantFactoryQos.cpp @@ -13,8 +13,19 @@ // limitations under the License. /** - * @file DomainParticipantQos.cpp + * @file DomainParticipantFactoryQos.cpp * */ #include + + +namespace eprosima { +namespace fastdds { +namespace dds { + +const DomainParticipantFactoryQos PARTICIPANT_FACTORY_QOS_DEFAULT; + +} /* namespace dds */ +} /* namespace fastdds */ +} /* namespace eprosima */ diff --git a/src/cpp/rtps/xmlparser/XMLParser.cpp b/src/cpp/rtps/xmlparser/XMLParser.cpp index 1cab55ce91b..1f025faa755 100644 --- a/src/cpp/rtps/xmlparser/XMLParser.cpp +++ b/src/cpp/rtps/xmlparser/XMLParser.cpp @@ -427,6 +427,8 @@ XMLP_ret XMLParser::validateXMLTransportElements( strcmp(name, LISTENING_PORTS) == 0 || strcmp(name, CALCULATE_CRC) == 0 || strcmp(name, CHECK_CRC) == 0 || + strcmp(name, KEEP_ALIVE_THREAD) == 0 || + strcmp(name, ACCEPT_THREAD) == 0 || strcmp(name, ENABLE_TCP_NODELAY) == 0 || strcmp(name, TLS) == 0 || strcmp(name, SEGMENT_SIZE) == 0 || @@ -634,6 +636,8 @@ XMLP_ret XMLParser::parseXMLCommonTCPTransportData( + + */ @@ -743,6 +747,22 @@ XMLP_ret XMLParser::parseXMLCommonTCPTransportData( return XMLP_ret::XML_ERROR; } } + else if (strcmp(name, KEEP_ALIVE_THREAD) == 0) + { + if (getXMLThreadSettings(*p_aux0, pTCPDesc->keep_alive_thread) != XMLP_ret::XML_OK) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Incorrect thread settings"); + return XMLP_ret::XML_ERROR; + } + } + else if (strcmp(name, ACCEPT_THREAD) == 0) + { + if (getXMLThreadSettings(*p_aux0, pTCPDesc->accept_thread) != XMLP_ret::XML_OK) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Incorrect thread settings"); + return XMLP_ret::XML_ERROR; + } + } } } else diff --git a/src/cpp/rtps/xmlparser/XMLParserCommon.cpp b/src/cpp/rtps/xmlparser/XMLParserCommon.cpp index 6baf830e963..b1cdb43d984 100644 --- a/src/cpp/rtps/xmlparser/XMLParserCommon.cpp +++ b/src/cpp/rtps/xmlparser/XMLParserCommon.cpp @@ -60,6 +60,8 @@ const char* METADATA_LOGICAL_PORT = "metadata_logical_port"; const char* LISTENING_PORTS = "listening_ports"; const char* CALCULATE_CRC = "calculate_crc"; const char* CHECK_CRC = "check_crc"; +const char* KEEP_ALIVE_THREAD = "keep_alive_thread"; +const char* ACCEPT_THREAD = "accept_thread"; const char* SEGMENT_SIZE = "segment_size"; const char* PORT_QUEUE_CAPACITY = "port_queue_capacity"; const char* PORT_OVERFLOW_POLICY = "port_overflow_policy"; diff --git a/test/mock/rtps/TCPTransportDescriptor/fastrtps/transport/TCPTransportDescriptor.h b/test/mock/rtps/TCPTransportDescriptor/fastrtps/transport/TCPTransportDescriptor.h index ef1d97811c1..404c85b727b 100644 --- a/test/mock/rtps/TCPTransportDescriptor/fastrtps/transport/TCPTransportDescriptor.h +++ b/test/mock/rtps/TCPTransportDescriptor/fastrtps/transport/TCPTransportDescriptor.h @@ -175,6 +175,9 @@ typedef struct TCPTransportDescriptor : public SocketTransportDescriptor TLSConfig tls_config; + fastdds::rtps::ThreadSettings keep_alive_thread; + fastdds::rtps::ThreadSettings accept_thread; + void add_listener_port( uint16_t port) { diff --git a/test/mock/rtps/XMLEndPointParser/fastrtps/xmlparser/XMLEndpointParser.h b/test/mock/rtps/XMLEndPointParser/fastrtps/xmlparser/XMLEndpointParser.h index ecdc6030295..b2167de2ef0 100644 --- a/test/mock/rtps/XMLEndPointParser/fastrtps/xmlparser/XMLEndpointParser.h +++ b/test/mock/rtps/XMLEndPointParser/fastrtps/xmlparser/XMLEndpointParser.h @@ -21,14 +21,12 @@ #define XMLENDPOINTPARSER_H_ #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - +#include namespace eprosima { namespace fastrtps { namespace xmlparser { - - /** * Class XMLEndpointParser used to parse the XML file that contains information about remote endpoints. * @ingroup DISCVOERYMODULE diff --git a/test/unittest/dds/publisher/CMakeLists.txt b/test/unittest/dds/publisher/CMakeLists.txt index a8b9d4152f7..e8c189fd80c 100644 --- a/test/unittest/dds/publisher/CMakeLists.txt +++ b/test/unittest/dds/publisher/CMakeLists.txt @@ -69,6 +69,7 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/DomainParticipant.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/DomainParticipantFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/DomainParticipantImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/qos/DomainParticipantFactoryQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/qos/DomainParticipantQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/FileConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp diff --git a/test/unittest/statistics/dds/CMakeLists.txt b/test/unittest/statistics/dds/CMakeLists.txt index b7286598000..c52fe0681db 100644 --- a/test/unittest/statistics/dds/CMakeLists.txt +++ b/test/unittest/statistics/dds/CMakeLists.txt @@ -137,6 +137,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS AND NOT QNX) ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/QosPolicyUtils.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/DomainParticipant.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/DomainParticipantFactory.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/qos/DomainParticipantFactoryQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/domain/qos/DomainParticipantQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/FileConsumer.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp diff --git a/test/unittest/xmlparser/XMLParserTests.cpp b/test/unittest/xmlparser/XMLParserTests.cpp index bc68f792246..d1b9a333a1c 100644 --- a/test/unittest/xmlparser/XMLParserTests.cpp +++ b/test/unittest/xmlparser/XMLParserTests.cpp @@ -1014,6 +1014,18 @@ TEST_F(XMLParserTests, parseXMLTransportData) false\ false\ \ + \ + 12\ + 12\ + 12\ + 12\ + \ + \ + 12\ + 12\ + 12\ + 12\ + \ \ 12\ 12\ @@ -1036,7 +1048,7 @@ TEST_F(XMLParserTests, parseXMLTransportData) \ \ "; - constexpr size_t xml_len {3000}; + constexpr size_t xml_len {3500}; char xml[xml_len]; // TCPv4 @@ -1066,6 +1078,8 @@ TEST_F(XMLParserTests, parseXMLTransportData) EXPECT_EQ(pTCPv4Desc->logical_port_increment, 2u); EXPECT_EQ(pTCPv4Desc->listening_ports[0], 5100u); EXPECT_EQ(pTCPv4Desc->listening_ports[1], 5200u); + EXPECT_EQ(pTCPv4Desc->keep_alive_thread, modified_thread_settings); + EXPECT_EQ(pTCPv4Desc->accept_thread, modified_thread_settings); EXPECT_EQ(pTCPv4Desc->default_reception_threads(), modified_thread_settings); EXPECT_EQ(pTCPv4Desc->get_thread_config_for_port(12345), modified_thread_settings); EXPECT_EQ(pTCPv4Desc->get_thread_config_for_port(12346), modified_thread_settings); @@ -1094,6 +1108,8 @@ TEST_F(XMLParserTests, parseXMLTransportData) EXPECT_EQ(pTCPv6Desc->logical_port_increment, 2u); EXPECT_EQ(pTCPv6Desc->listening_ports[0], 5100u); EXPECT_EQ(pTCPv6Desc->listening_ports[1], 5200u); + EXPECT_EQ(pTCPv4Desc->keep_alive_thread, modified_thread_settings); + EXPECT_EQ(pTCPv4Desc->accept_thread, modified_thread_settings); EXPECT_EQ(pTCPv6Desc->default_reception_threads(), modified_thread_settings); EXPECT_EQ(pTCPv6Desc->get_thread_config_for_port(12345), modified_thread_settings); EXPECT_EQ(pTCPv6Desc->get_thread_config_for_port(12346), modified_thread_settings); @@ -1213,6 +1229,8 @@ TEST_F(XMLParserTests, parseXMLTransportData_NegativeClauses) "check_crc", "enable_tcp_nodelay", "tls", + "keep_alive_thread", + "accept_thread", "default_reception_threads", "reception_threads", "bad_element" From db25515451db24a4b845359b76e3c700ed0c113b Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 13 Nov 2023 15:12:34 +0100 Subject: [PATCH 8/9] Custom eprosima::thread class that allows setting the stack size (#4000) * Refs #19797. Initial refactor. eprosima::thread inherits from std::thread. Signed-off-by: Miguel Company * Refs #19797. Update code in ResourceEvent. Signed-off-by: Miguel Company * Refs #19797. Using eprosima::thread instead of std::thread. Signed-off-by: Miguel Company * Refs #19797. Include `` where `std::this_thread` is used. Signed-off-by: Miguel Company * Refs #19797. Copy basic eprosima::thread implementation into ipp files. Signed-off-by: Miguel Company * Refs #19797. Select ipp file depending on platform. Signed-off-by: Miguel Company * Refs #19797. Copy windows implementation on `thread_impl_win32.ipp` Signed-off-by: Miguel Company * Refs #19797. Added `is_calling_thread method`. Signed-off-by: Miguel Company * Refs #19797. Using `is_calling_thread` instead of comparing ids. Signed-off-by: Miguel Company * Refs #19797. Using stack size argument. Signed-off-by: Miguel Company * Refs #19797. Update test. Signed-off-by: Miguel Company * Refs #19797. Implementation for pthread based platforms. Signed-off-by: Miguel Company * Refs #19797. Use pthread based implementation on Mac. Signed-off-by: Miguel Company * Refs #19797. Change windows implementation approach. Signed-off-by: Miguel Company * Refs #19797. Factor out common code. Signed-off-by: Miguel Company * Refs #19797. Linter Signed-off-by: Miguel Company * Refs #19797. Use local `swap` method. Signed-off-by: Miguel Company * Refs #19797. Pass 0 value to `pthread_attr_setstacksize`. Signed-off-by: Miguel Company * Refs #19797. Linter Signed-off-by: Miguel Company * Refs #19797. Improve include what you use. Signed-off-by: Miguel Company * Refs #19797. Add missing includes Signed-off-by: EduPonz * Refs #19797. Fix thread settings on dds unit test xml profiles. Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company Signed-off-by: EduPonz Co-authored-by: EduPonz --- .../deadlinepayloadPublisher.cxx | 3 + .../DisablePositiveACKsSubscriber.cpp | 4 + .../DiscoveryServerServer.cpp | 1 + .../HelloWorldSubscriber.cpp | 17 +- .../Filtering/FilteringExamplePublisher.cxx | 7 +- .../FlowControlExamplePublisher.cxx | 6 +- .../HelloWorldSubscriber.cpp | 4 + .../HelloWorldSubscriber.cpp | 12 +- .../HelloWorldSubscriber.cpp | 4 + .../HelloWorld_main.cpp | 2 + .../HelloWorldSubscriber.cpp | 4 + examples/cpp/dds/HistoryKind/pastsamples.cpp | 8 +- examples/cpp/dds/Keys/keys.cpp | 14 +- examples/cpp/dds/LateJoiners/latejoiners.cpp | 12 +- .../LifespanQoSExample/LifespanSubscriber.cpp | 5 +- .../LivelinessQoS/LivelinessSubscriber.cpp | 5 +- .../OwnershipStrengthPublisher.cxx | 6 +- .../sampleconfig_safest.cpp | 9 +- .../sampleconfig_triggers.cpp | 8 +- .../sampleconfig_fastest.cpp | 8 +- .../HelloWorldSubscriber.cpp | 4 + .../HelloWorldPublisher.cpp | 6 +- .../HelloWorldSubscriber.cpp | 5 +- .../TypeLookupSubscriber.cpp | 15 +- .../rtps/Persistent/TestWriterPersistent.cpp | 16 +- .../rtps/Registered/TestWriterRegistered.cpp | 16 +- include/fastdds/dds/log/Log.hpp | 2 - .../messages/RTPSMessageSenderInterface.hpp | 7 +- .../fastdds/rtps/resources/ResourceEvent.h | 9 +- include/fastdds/rtps/resources/TimedEvent.h | 8 +- .../domain/DomainParticipantFactory.cpp | 2 + src/cpp/fastdds/log/Log.cpp | 5 +- .../rtps/DataSharing/DataSharingListener.cpp | 1 + .../rtps/DataSharing/DataSharingListener.hpp | 3 +- src/cpp/rtps/RTPSDomainImpl.hpp | 1 - .../discovery/participant/PDPServer.cpp | 2 - .../rtps/flowcontrol/FlowControllerImpl.hpp | 4 +- src/cpp/rtps/messages/MessageReceiver.cpp | 7 +- src/cpp/rtps/network/ReceiverResource.cpp | 1 + .../rtps/participant/RTPSParticipantImpl.cpp | 1 - src/cpp/rtps/reader/StatefulReader.cpp | 9 +- src/cpp/rtps/reader/StatelessReader.cpp | 9 +- src/cpp/rtps/resources/ResourceEvent.cpp | 15 +- src/cpp/rtps/security/SecurityManager.cpp | 2 +- src/cpp/rtps/security/SecurityManager.h | 13 +- src/cpp/rtps/transport/ChannelResource.cpp | 4 +- src/cpp/rtps/transport/ChannelResource.h | 10 +- .../transport/TCPChannelResourceSecure.cpp | 3 +- .../rtps/transport/TCPTransportInterface.cpp | 1 + .../rtps/transport/TCPTransportInterface.h | 6 +- src/cpp/rtps/transport/TCPv4Transport.h | 1 - src/cpp/rtps/transport/TCPv6Transport.h | 4 +- .../rtps/transport/UDPTransportInterface.h | 11 +- .../transport/shared_mem/SharedMemGlobal.hpp | 1 + .../transport/shared_mem/SharedMemLog.hpp | 5 +- .../transport/shared_mem/SharedMemManager.hpp | 1 + .../shared_mem/SharedMemTransport.cpp | 1 + .../rtps/transport/tcp/RTCPMessageManager.cpp | 6 +- src/cpp/security/logging/LogTopic.cpp | 1 + src/cpp/security/logging/LogTopic.h | 12 +- src/cpp/utils/SystemInfo.cpp | 3 + src/cpp/utils/shared_memory/SharedMemUUID.hpp | 9 +- .../utils/shared_memory/SharedMemWatchdog.hpp | 4 +- src/cpp/utils/thread.hpp | 25 +++ .../utils/thread_impl/thread_impl_basic.hpp | 48 ++++ .../utils/thread_impl/thread_impl_custom.hpp | 205 ++++++++++++++++++ .../utils/thread_impl/thread_impl_pthread.ipp | 103 +++++++++ .../utils/thread_impl/thread_impl_win32.ipp | 79 +++++++ src/cpp/utils/threading.hpp | 8 +- .../common/BlackboxTestsTransportTCP.cpp | 8 +- .../common/RTPSBlackboxTestsPositiveAck.cpp | 5 +- .../common/RTPSBlackboxTestsVolatile.cpp | 8 +- test/communication/Publisher.cpp | 16 +- test/communication/Subscriber.cpp | 15 +- test/dds/communication/PublisherDynamic.cpp | 21 +- test/dds/communication/PublisherModule.cpp | 17 +- test/dds/communication/SubscriberModule.cpp | 16 +- .../latency/LatencyTestPublisher.cpp | 10 +- .../latency/LatencyTestSubscriber.cpp | 6 +- .../throughput/ThroughputPublisher.cpp | 9 +- .../throughput/ThroughputSubscriber.cpp | 6 +- .../profiles/test_xml_for_string_profile.xml | 60 ++--- .../dds/profiles/test_xml_profile.xml | 60 ++--- test/unittest/logging/LogTests.cpp | 3 +- test/xtypes/TestPublisher.cpp | 26 ++- thirdparty/filewatch/FileWatch.hpp | 5 +- 86 files changed, 848 insertions(+), 296 deletions(-) create mode 100644 src/cpp/utils/thread.hpp create mode 100644 src/cpp/utils/thread_impl/thread_impl_basic.hpp create mode 100644 src/cpp/utils/thread_impl/thread_impl_custom.hpp create mode 100644 src/cpp/utils/thread_impl/thread_impl_pthread.ipp create mode 100644 src/cpp/utils/thread_impl/thread_impl_win32.ipp diff --git a/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPublisher.cxx b/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPublisher.cxx index c80c08b9c79..71594c56df2 100644 --- a/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPublisher.cxx +++ b/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPublisher.cxx @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include + #include #include "deadlinepayloadPublisher.h" diff --git a/examples/cpp/dds/DisablePositiveACKs/DisablePositiveACKsSubscriber.cpp b/examples/cpp/dds/DisablePositiveACKs/DisablePositiveACKsSubscriber.cpp index a12671467b2..72186e17663 100644 --- a/examples/cpp/dds/DisablePositiveACKs/DisablePositiveACKsSubscriber.cpp +++ b/examples/cpp/dds/DisablePositiveACKs/DisablePositiveACKsSubscriber.cpp @@ -18,6 +18,10 @@ */ #include "DisablePositiveACKsSubscriber.h" + +#include +#include + #include #include #include diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.cpp b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.cpp index 8f9ee30c845..ece39ca7f57 100644 --- a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.cpp +++ b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldSubscriber.cpp b/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldSubscriber.cpp index d474a95e76c..753a1590e0d 100644 --- a/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/DynamicHelloWorldExample/HelloWorldSubscriber.cpp @@ -18,16 +18,19 @@ */ #include "HelloWorldSubscriber.h" + +#include +#include +#include + +#include +#include +#include +#include #include #include -#include -#include -#include -#include - -#include #include -#include +#include using namespace eprosima::fastdds::dds; using eprosima::fastrtps::types::ReturnCode_t; diff --git a/examples/cpp/dds/Filtering/FilteringExamplePublisher.cxx b/examples/cpp/dds/Filtering/FilteringExamplePublisher.cxx index bf6f1709954..36cbdd32767 100644 --- a/examples/cpp/dds/Filtering/FilteringExamplePublisher.cxx +++ b/examples/cpp/dds/Filtering/FilteringExamplePublisher.cxx @@ -12,10 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include "FilteringExamplePublisher.h" +#include +#include + +#include + using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/examples/cpp/dds/FlowControlExample/FlowControlExamplePublisher.cxx b/examples/cpp/dds/FlowControlExample/FlowControlExamplePublisher.cxx index db448ad3153..3506549fceb 100644 --- a/examples/cpp/dds/FlowControlExample/FlowControlExamplePublisher.cxx +++ b/examples/cpp/dds/FlowControlExample/FlowControlExamplePublisher.cxx @@ -19,10 +19,12 @@ * This file was generated by the tool fastcdrgen. */ +#include "FlowControlExamplePublisher.h" -#include +#include +#include -#include "FlowControlExamplePublisher.h" +#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp b/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp index 74977ccf078..6823a32f4e6 100644 --- a/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/HelloWorldExample/HelloWorldSubscriber.cpp @@ -18,6 +18,10 @@ */ #include "HelloWorldSubscriber.h" + +#include +#include + #include #include #include diff --git a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.cpp b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.cpp index 7a75a0abc71..4e0e1fa9c58 100644 --- a/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/HelloWorldExampleDataSharing/HelloWorldSubscriber.cpp @@ -18,13 +18,17 @@ */ #include "HelloWorldSubscriber.h" -#include -#include + +#include +#include + #include -#include #include -#include #include +#include +#include +#include +#include using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.cpp b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.cpp index a22d83624ab..9afd1360353 100644 --- a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorldSubscriber.cpp @@ -18,6 +18,10 @@ */ #include "HelloWorldSubscriber.h" + +#include +#include + #include #include #include diff --git a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorld_main.cpp b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorld_main.cpp index ebc31b75ffb..04339bba607 100644 --- a/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorld_main.cpp +++ b/examples/cpp/dds/HelloWorldExampleSharedMem/HelloWorld_main.cpp @@ -20,6 +20,8 @@ #include "HelloWorldPublisher.h" #include "HelloWorldSubscriber.h" +#include + #include #include diff --git a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.cpp b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.cpp index 9c96b51344c..4e63d3587da 100644 --- a/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/HelloWorldExampleTCP/HelloWorldSubscriber.cpp @@ -18,6 +18,10 @@ */ #include "HelloWorldSubscriber.h" + +#include +#include + #include #include #include diff --git a/examples/cpp/dds/HistoryKind/pastsamples.cpp b/examples/cpp/dds/HistoryKind/pastsamples.cpp index 9327b6fc381..6561d835ede 100644 --- a/examples/cpp/dds/HistoryKind/pastsamples.cpp +++ b/examples/cpp/dds/HistoryKind/pastsamples.cpp @@ -1,16 +1,18 @@ +#include #include #include +#include #include #include -#include #include #include -#include +#include #include #include -#include #include +#include +#include #include #include "samplePubSubTypes.h" diff --git a/examples/cpp/dds/Keys/keys.cpp b/examples/cpp/dds/Keys/keys.cpp index 9f77177f75a..d32c03e1513 100644 --- a/examples/cpp/dds/Keys/keys.cpp +++ b/examples/cpp/dds/Keys/keys.cpp @@ -1,17 +1,19 @@ +#include +#include #include #include -#include +#include #include #include -#include +#include +#include +#include #include #include -#include #include -#include -#include -#include +#include +#include #include #include "samplePubSubTypes.h" diff --git a/examples/cpp/dds/LateJoiners/latejoiners.cpp b/examples/cpp/dds/LateJoiners/latejoiners.cpp index 54277d1d1ab..4566c146b45 100644 --- a/examples/cpp/dds/LateJoiners/latejoiners.cpp +++ b/examples/cpp/dds/LateJoiners/latejoiners.cpp @@ -1,16 +1,18 @@ #include #include +#include +#include #include #include -#include +#include +#include +#include #include #include -#include #include -#include -#include -#include +#include +#include #include #include "samplePubSubTypes.h" diff --git a/examples/cpp/dds/LifespanQoSExample/LifespanSubscriber.cpp b/examples/cpp/dds/LifespanQoSExample/LifespanSubscriber.cpp index 66f3c329a0b..737f92b99f2 100644 --- a/examples/cpp/dds/LifespanQoSExample/LifespanSubscriber.cpp +++ b/examples/cpp/dds/LifespanQoSExample/LifespanSubscriber.cpp @@ -19,9 +19,12 @@ #include "LifespanSubscriber.h" +#include +#include + #include -#include #include +#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/examples/cpp/dds/LivelinessQoS/LivelinessSubscriber.cpp b/examples/cpp/dds/LivelinessQoS/LivelinessSubscriber.cpp index 661ff03fcc6..6e94d9570e6 100644 --- a/examples/cpp/dds/LivelinessQoS/LivelinessSubscriber.cpp +++ b/examples/cpp/dds/LivelinessQoS/LivelinessSubscriber.cpp @@ -19,9 +19,12 @@ #include "LivelinessSubscriber.h" +#include +#include + #include -#include #include +#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPublisher.cxx b/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPublisher.cxx index 2b4b7a612d7..50eb0fed5b1 100644 --- a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPublisher.cxx +++ b/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPublisher.cxx @@ -21,9 +21,11 @@ #include "OwnershipStrengthPublisher.h" -#include - +#include #include +#include + +#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/examples/cpp/dds/SampleConfig_Controller/sampleconfig_safest.cpp b/examples/cpp/dds/SampleConfig_Controller/sampleconfig_safest.cpp index 3ed2f8ae36f..9d3580e9a88 100644 --- a/examples/cpp/dds/SampleConfig_Controller/sampleconfig_safest.cpp +++ b/examples/cpp/dds/SampleConfig_Controller/sampleconfig_safest.cpp @@ -1,19 +1,20 @@ #include #include +#include +#include #include #include -#include #include #include -#include -#include +#include #include #include #include +#include +#include #include - #include "samplePubSubTypes.h" using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/dds/SampleConfig_Events/sampleconfig_triggers.cpp b/examples/cpp/dds/SampleConfig_Events/sampleconfig_triggers.cpp index 8058cab044c..97641f71866 100644 --- a/examples/cpp/dds/SampleConfig_Events/sampleconfig_triggers.cpp +++ b/examples/cpp/dds/SampleConfig_Events/sampleconfig_triggers.cpp @@ -1,16 +1,18 @@ +#include #include #include +#include #include #include -#include #include #include -#include -#include +#include #include #include #include +#include +#include #include #include "samplePubSubTypes.h" diff --git a/examples/cpp/dds/SampleConfig_Multimedia/sampleconfig_fastest.cpp b/examples/cpp/dds/SampleConfig_Multimedia/sampleconfig_fastest.cpp index 753b52ae8a5..65e979b8bb7 100644 --- a/examples/cpp/dds/SampleConfig_Multimedia/sampleconfig_fastest.cpp +++ b/examples/cpp/dds/SampleConfig_Multimedia/sampleconfig_fastest.cpp @@ -1,16 +1,18 @@ #include #include +#include +#include #include #include -#include #include #include -#include -#include +#include #include #include #include +#include +#include #include #include "samplePubSubTypes.h" diff --git a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.cpp b/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.cpp index 4672baf09ed..175eb640873 100644 --- a/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/SecureHelloWorldExample/HelloWorldSubscriber.cpp @@ -18,6 +18,10 @@ */ #include "HelloWorldSubscriber.h" + +#include +#include + #include #include diff --git a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.cpp b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.cpp index 4f2245f1068..dd47e64be7c 100644 --- a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.cpp +++ b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldPublisher.cpp @@ -18,8 +18,12 @@ */ #include "HelloWorldPublisher.h" -#include + +#include +#include + #include +#include #include using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.cpp b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.cpp index 09ca9953251..278d65536c4 100644 --- a/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.cpp +++ b/examples/cpp/dds/StaticHelloWorldExample/HelloWorldSubscriber.cpp @@ -18,11 +18,14 @@ */ #include "HelloWorldSubscriber.h" + +#include +#include + #include #include #include - using namespace eprosima::fastdds::dds; HelloWorldSubscriber::HelloWorldSubscriber() diff --git a/examples/cpp/dds/TypeLookupService/TypeLookupSubscriber.cpp b/examples/cpp/dds/TypeLookupService/TypeLookupSubscriber.cpp index dbec799c74e..108822411d0 100644 --- a/examples/cpp/dds/TypeLookupService/TypeLookupSubscriber.cpp +++ b/examples/cpp/dds/TypeLookupService/TypeLookupSubscriber.cpp @@ -18,15 +18,18 @@ */ #include "TypeLookupSubscriber.h" + +#include +#include + +#include +#include +#include +#include #include #include -#include -#include -#include -#include - -#include #include +#include #include using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/rtps/Persistent/TestWriterPersistent.cpp b/examples/cpp/rtps/Persistent/TestWriterPersistent.cpp index 031dbe1efcb..02be80fb581 100644 --- a/examples/cpp/rtps/Persistent/TestWriterPersistent.cpp +++ b/examples/cpp/rtps/Persistent/TestWriterPersistent.cpp @@ -19,18 +19,18 @@ #include "TestWriterPersistent.h" -#include -#include -#include +#include +#include +#include +#include +#include #include #include -#include - #include - -#include -#include +#include +#include +#include using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; diff --git a/examples/cpp/rtps/Registered/TestWriterRegistered.cpp b/examples/cpp/rtps/Registered/TestWriterRegistered.cpp index cba73befb7f..04155160eb0 100644 --- a/examples/cpp/rtps/Registered/TestWriterRegistered.cpp +++ b/examples/cpp/rtps/Registered/TestWriterRegistered.cpp @@ -19,18 +19,18 @@ #include "TestWriterRegistered.h" -#include "fastrtps/rtps/writer/RTPSWriter.h" -#include "fastrtps/rtps/participant/RTPSParticipant.h" -#include "fastrtps/rtps/RTPSDomain.h" +#include +#include +#include "fastrtps/attributes/TopicAttributes.h" +#include "fastrtps/qos/WriterQos.h" +#include "fastrtps/rtps/attributes/HistoryAttributes.h" #include "fastrtps/rtps/attributes/RTPSParticipantAttributes.h" #include "fastrtps/rtps/attributes/WriterAttributes.h" -#include "fastrtps/rtps/attributes/HistoryAttributes.h" - #include "fastrtps/rtps/history/WriterHistory.h" - -#include "fastrtps/attributes/TopicAttributes.h" -#include "fastrtps/qos/WriterQos.h" +#include "fastrtps/rtps/participant/RTPSParticipant.h" +#include "fastrtps/rtps/RTPSDomain.h" +#include "fastrtps/rtps/writer/RTPSWriter.h" using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; diff --git a/include/fastdds/dds/log/Log.hpp b/include/fastdds/dds/log/Log.hpp index 1bbbd3bf4bc..72c864a30d8 100644 --- a/include/fastdds/dds/log/Log.hpp +++ b/include/fastdds/dds/log/Log.hpp @@ -15,10 +15,8 @@ #ifndef _FASTDDS_DDS_LOG_LOG_HPP_ #define _FASTDDS_DDS_LOG_LOG_HPP_ -#include #include #include -#include #include #include diff --git a/include/fastdds/rtps/messages/RTPSMessageSenderInterface.hpp b/include/fastdds/rtps/messages/RTPSMessageSenderInterface.hpp index 219594bd037..6ef5c16e5b8 100644 --- a/include/fastdds/rtps/messages/RTPSMessageSenderInterface.hpp +++ b/include/fastdds/rtps/messages/RTPSMessageSenderInterface.hpp @@ -22,11 +22,12 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC -#include -#include - +#include #include +#include +#include + namespace eprosima { namespace fastrtps { namespace rtps { diff --git a/include/fastdds/rtps/resources/ResourceEvent.h b/include/fastdds/rtps/resources/ResourceEvent.h index 5cb68311720..33be690b67d 100644 --- a/include/fastdds/rtps/resources/ResourceEvent.h +++ b/include/fastdds/rtps/resources/ResourceEvent.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -32,6 +32,9 @@ #include namespace eprosima { + +class thread; + namespace fastrtps { namespace rtps { @@ -45,7 +48,7 @@ class ResourceEvent { public: - ResourceEvent() = default; + ResourceEvent(); ~ResourceEvent(); @@ -140,7 +143,7 @@ class ResourceEvent std::chrono::steady_clock::time_point current_time_; //! Execution thread. - std::thread thread_; + std::unique_ptr thread_; /*! * @brief Registers a new TimedEventImpl object in the internal queue to be processed. diff --git a/include/fastdds/rtps/resources/TimedEvent.h b/include/fastdds/rtps/resources/TimedEvent.h index 6ded2159411..686a5f5d297 100644 --- a/include/fastdds/rtps/resources/TimedEvent.h +++ b/include/fastdds/rtps/resources/TimedEvent.h @@ -22,11 +22,11 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC -#include - -#include -#include +#include #include +#include + +#include namespace eprosima { namespace fastrtps { diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index c14387e810b..bb9457b8bd4 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -17,6 +17,8 @@ * */ +#include + #include #include #include diff --git a/src/cpp/fastdds/log/Log.cpp b/src/cpp/fastdds/log/Log.cpp index 0652d1145c0..893d2b73510 100644 --- a/src/cpp/fastdds/log/Log.cpp +++ b/src/cpp/fastdds/log/Log.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace eprosima { @@ -243,7 +244,7 @@ struct LogResources if (logging_thread_.joinable()) { cv_.notify_all(); - if (logging_thread_.get_id() != std::this_thread::get_id()) + if (!logging_thread_.is_calling_thread()) { logging_thread_.join(); } @@ -342,7 +343,7 @@ struct LogResources fastrtps::DBQueue logs_; std::vector> consumers_; - std::thread logging_thread_; + eprosima::thread logging_thread_; // Condition variable segment. std::condition_variable cv_; diff --git a/src/cpp/rtps/DataSharing/DataSharingListener.cpp b/src/cpp/rtps/DataSharing/DataSharingListener.cpp index e4aed898a11..49a05c53d66 100644 --- a/src/cpp/rtps/DataSharing/DataSharingListener.cpp +++ b/src/cpp/rtps/DataSharing/DataSharingListener.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include diff --git a/src/cpp/rtps/DataSharing/DataSharingListener.hpp b/src/cpp/rtps/DataSharing/DataSharingListener.hpp index 3afc0bce6f5..392764b3a48 100644 --- a/src/cpp/rtps/DataSharing/DataSharingListener.hpp +++ b/src/cpp/rtps/DataSharing/DataSharingListener.hpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace eprosima { namespace fastrtps { @@ -114,7 +115,7 @@ class DataSharingListener : public IDataSharingListener std::shared_ptr notification_; std::atomic is_running_; RTPSReader* reader_; - std::thread listening_thread_; + eprosima::thread listening_thread_; ResourceLimitedVector writer_pools_; std::atomic writer_pools_changed_; std::string datasharing_pools_directory_; diff --git a/src/cpp/rtps/RTPSDomainImpl.hpp b/src/cpp/rtps/RTPSDomainImpl.hpp index 88025e52404..1f736cd66f2 100644 --- a/src/cpp/rtps/RTPSDomainImpl.hpp +++ b/src/cpp/rtps/RTPSDomainImpl.hpp @@ -18,7 +18,6 @@ #include #include -#include #include #if defined(_WIN32) || defined(__unix__) diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp index cb39e120049..6f04b540b44 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp @@ -54,8 +54,6 @@ #include -#include - namespace eprosima { namespace fastdds { namespace rtps { diff --git a/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp b/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp index a31a68b8534..6e9fc92b828 100644 --- a/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp +++ b/src/cpp/rtps/flowcontrol/FlowControllerImpl.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include "FlowController.hpp" @@ -16,6 +15,7 @@ #include #include +#include #include namespace eprosima { @@ -242,7 +242,7 @@ struct FlowControllerAsyncPublishMode { } - std::thread thread; + eprosima::thread thread; std::atomic_bool running {false}; diff --git a/src/cpp/rtps/messages/MessageReceiver.cpp b/src/cpp/rtps/messages/MessageReceiver.cpp index edecbbef5e0..8df4d532a11 100644 --- a/src/cpp/rtps/messages/MessageReceiver.cpp +++ b/src/cpp/rtps/messages/MessageReceiver.cpp @@ -17,13 +17,14 @@ * */ +#include +#include +#include + #include #include #include -#include -#include - #include #include #include diff --git a/src/cpp/rtps/network/ReceiverResource.cpp b/src/cpp/rtps/network/ReceiverResource.cpp index 82d0450aa1e..f2b1a37a195 100644 --- a/src/cpp/rtps/network/ReceiverResource.cpp +++ b/src/cpp/rtps/network/ReceiverResource.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index e0d469d6251..f55f8c099e4 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -61,7 +61,6 @@ #include #include #include -#include #if HAVE_SECURITY #include diff --git a/src/cpp/rtps/reader/StatefulReader.cpp b/src/cpp/rtps/reader/StatefulReader.cpp index 6a4e4b72378..c1bacf8f6fd 100644 --- a/src/cpp/rtps/reader/StatefulReader.cpp +++ b/src/cpp/rtps/reader/StatefulReader.cpp @@ -17,6 +17,10 @@ * */ +#include +#include +#include + #include #include #include @@ -34,11 +38,6 @@ #include "rtps/RTPSDomainImpl.hpp" -#include -#include - -#include - #define IDSTRING "(ID:" << std::this_thread::get_id() << ") " << using namespace eprosima::fastrtps::rtps; diff --git a/src/cpp/rtps/reader/StatelessReader.cpp b/src/cpp/rtps/reader/StatelessReader.cpp index df08b8e14d9..1fda4c3789c 100644 --- a/src/cpp/rtps/reader/StatelessReader.cpp +++ b/src/cpp/rtps/reader/StatelessReader.cpp @@ -17,6 +17,10 @@ * */ +#include +#include +#include + #include #include #include @@ -31,11 +35,6 @@ #include "rtps/RTPSDomainImpl.hpp" -#include -#include - -#include - #define IDSTRING "(ID:" << std::this_thread::get_id() << ") " << using namespace eprosima::fastrtps::rtps; diff --git a/src/cpp/rtps/resources/ResourceEvent.cpp b/src/cpp/rtps/resources/ResourceEvent.cpp index 66acf31f4c1..6957c2c1239 100644 --- a/src/cpp/rtps/resources/ResourceEvent.cpp +++ b/src/cpp/rtps/resources/ResourceEvent.cpp @@ -17,12 +17,12 @@ */ #include -#include #include #include #include "TimedEventImpl.h" +#include #include namespace eprosima { @@ -36,6 +36,11 @@ static bool event_compare( return lhs->next_trigger_time() < rhs->next_trigger_time(); } +ResourceEvent::ResourceEvent() + : thread_(new eprosima::thread()) +{ +} + ResourceEvent::~ResourceEvent() { // All timer should be unregistered before destroying this object. @@ -48,14 +53,14 @@ ResourceEvent::~ResourceEvent() void ResourceEvent::stop_thread() { EPROSIMA_LOG_INFO(RTPS_PARTICIPANT, "Removing event thread"); - if (thread_.joinable()) + if (thread_->joinable()) { { std::lock_guard guard(mutex_); stop_.store(true); cv_.notify_one(); } - thread_.join(); + thread_->join(); } } @@ -76,7 +81,7 @@ void ResourceEvent::unregister_timer( { std::unique_lock lock(mutex_); - bool is_service_thread = std::this_thread::get_id() == thread_.get_id(); + bool is_service_thread = thread_->is_calling_thread(); //! Let the service thread to manipulate resources if (!is_service_thread) @@ -315,7 +320,7 @@ void ResourceEvent::init_thread( stop_.store(false); resize_collections(); - thread_ = eprosima::create_thread([this]() + *thread_ = eprosima::create_thread([this]() { event_service(); }, thread_cfg, name_fmt, thread_id); diff --git a/src/cpp/rtps/security/SecurityManager.cpp b/src/cpp/rtps/security/SecurityManager.cpp index e769af97f8f..61dae9fbb47 100644 --- a/src/cpp/rtps/security/SecurityManager.cpp +++ b/src/cpp/rtps/security/SecurityManager.cpp @@ -20,8 +20,8 @@ #include #include -#include #include +#include #include #include diff --git a/src/cpp/rtps/security/SecurityManager.h b/src/cpp/rtps/security/SecurityManager.h index dbd6410cd7f..6f237a61684 100644 --- a/src/cpp/rtps/security/SecurityManager.h +++ b/src/cpp/rtps/security/SecurityManager.h @@ -18,6 +18,13 @@ #ifndef _RTPS_SECURITY_SECURITYMANAGER_H_ #define _RTPS_SECURITY_SECURITYMANAGER_H_ +#include +#include +#include +#include +#include +#include + #include #include @@ -33,12 +40,6 @@ #include #include -#include -#include -#include -#include -#include - namespace eprosima { namespace fastrtps { namespace rtps { diff --git a/src/cpp/rtps/transport/ChannelResource.cpp b/src/cpp/rtps/transport/ChannelResource.cpp index 1ccea4fe5e2..83a2806db88 100644 --- a/src/cpp/rtps/transport/ChannelResource.cpp +++ b/src/cpp/rtps/transport/ChannelResource.cpp @@ -14,7 +14,7 @@ #include -#include +#include namespace eprosima { namespace fastdds { @@ -59,7 +59,7 @@ void ChannelResource::clear() alive_.store(false); if (thread_.joinable()) { - if (thread_.get_id() != std::this_thread::get_id()) + if (!thread_.is_calling_thread()) { // wait for it to finish thread_.join(); diff --git a/src/cpp/rtps/transport/ChannelResource.h b/src/cpp/rtps/transport/ChannelResource.h index 1e9dd81102d..58a25b2b764 100644 --- a/src/cpp/rtps/transport/ChannelResource.h +++ b/src/cpp/rtps/transport/ChannelResource.h @@ -15,11 +15,13 @@ #ifndef _FASTDDS_CHANNEL_RESOURCE_INFO_ #define _FASTDDS_CHANNEL_RESOURCE_INFO_ -#include -#include +#include + #include #include +#include + namespace eprosima { namespace fastdds { namespace rtps { @@ -38,7 +40,7 @@ class ChannelResource virtual void clear(); inline void thread( - std::thread&& pThread) + eprosima::thread&& pThread) { if (thread_.joinable()) { @@ -69,7 +71,7 @@ class ChannelResource fastrtps::rtps::CDRMessage_t message_buffer_; std::atomic alive_; - std::thread thread_; + eprosima::thread thread_; }; } // namespace rtps diff --git a/src/cpp/rtps/transport/TCPChannelResourceSecure.cpp b/src/cpp/rtps/transport/TCPChannelResourceSecure.cpp index 92497e7e662..c19aff1eca4 100644 --- a/src/cpp/rtps/transport/TCPChannelResourceSecure.cpp +++ b/src/cpp/rtps/transport/TCPChannelResourceSecure.cpp @@ -14,8 +14,9 @@ #include -#include #include +#include +#include #include #include diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index e4a3c2a111f..34a87ea5fd8 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -54,6 +54,7 @@ #include #include +#include #include #include "tcp/RTCPHeader.h" diff --git a/src/cpp/rtps/transport/TCPTransportInterface.h b/src/cpp/rtps/transport/TCPTransportInterface.h index 412c905b475..5e16a7dfd42 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.h +++ b/src/cpp/rtps/transport/TCPTransportInterface.h @@ -15,7 +15,6 @@ #ifndef _FASTDDS_TCP_TRANSPORT_INTERFACE_H_ #define _FASTDDS_TCP_TRANSPORT_INTERFACE_H_ -#include #include #include #include @@ -39,6 +38,7 @@ #endif // if TLS_FOUND #include +#include namespace eprosima { namespace fastdds { @@ -82,8 +82,8 @@ class TCPTransportInterface : public TransportInterface #if TLS_FOUND asio::ssl::context ssl_context_; #endif // if TLS_FOUND - std::thread io_service_thread_; - std::thread io_service_timers_thread_; + eprosima::thread io_service_thread_; + eprosima::thread io_service_timers_thread_; std::shared_ptr rtcp_message_manager_; std::mutex rtcp_message_manager_mutex_; std::condition_variable rtcp_message_manager_cv_; diff --git a/src/cpp/rtps/transport/TCPv4Transport.h b/src/cpp/rtps/transport/TCPv4Transport.h index d094168b9d1..a305ab8b722 100644 --- a/src/cpp/rtps/transport/TCPv4Transport.h +++ b/src/cpp/rtps/transport/TCPv4Transport.h @@ -15,7 +15,6 @@ #ifndef _FASTDDS_TCPV4_TRANSPORT_H_ #define _FASTDDS_TCPV4_TRANSPORT_H_ -#include #include #include #include diff --git a/src/cpp/rtps/transport/TCPv6Transport.h b/src/cpp/rtps/transport/TCPv6Transport.h index fa68307e0a0..e7e1b2e7820 100644 --- a/src/cpp/rtps/transport/TCPv6Transport.h +++ b/src/cpp/rtps/transport/TCPv6Transport.h @@ -15,12 +15,12 @@ #ifndef _FASTDDS_TCPV6_TRANSPORT_H_ #define _FASTDDS_TCPV6_TRANSPORT_H_ -#include -#include #include #include +#include #include + #include #include #include diff --git a/src/cpp/rtps/transport/UDPTransportInterface.h b/src/cpp/rtps/transport/UDPTransportInterface.h index d6f0645d11e..287aa5b32b8 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.h +++ b/src/cpp/rtps/transport/UDPTransportInterface.h @@ -15,8 +15,12 @@ #ifndef _FASTDDS_UDP_TRANSPORT_INTERFACE_H_ #define _FASTDDS_UDP_TRANSPORT_INTERFACE_H_ +#include +#include +#include +#include + #include -#include #include #include @@ -25,11 +29,6 @@ #include #include -#include -#include -#include -#include - namespace eprosima { namespace fastdds { namespace rtps { diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemGlobal.hpp b/src/cpp/rtps/transport/shared_mem/SharedMemGlobal.hpp index 4f5cf24363f..c3e3a9a35a4 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemGlobal.hpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemGlobal.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp b/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp index 80f3ebf0bea..22754952850 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemLog.hpp @@ -15,12 +15,15 @@ #ifndef _FASTDDS_SHAREDMEM_LOG_H_ #define _FASTDDS_SHAREDMEM_LOG_H_ +#include + #include #include #include #include #include +#include #include namespace eprosima { @@ -333,7 +336,7 @@ class PacketsLog { eprosima::fastrtps::DBQueue logs; std::vector> consumers; - std::thread logging_thread; + eprosima::thread logging_thread; // Condition variable segment. std::condition_variable cv; diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemManager.hpp b/src/cpp/rtps/transport/shared_mem/SharedMemManager.hpp index 3f5fd7c9ebd..dc5a331f2a7 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemManager.hpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemManager.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp b/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp index 8c54f702c6d..ef5469e9526 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp +++ b/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #ifdef ANDROID diff --git a/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp b/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp index f5b0364d4a1..43a646bc57e 100644 --- a/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp +++ b/src/cpp/rtps/transport/tcp/RTCPMessageManager.cpp @@ -16,13 +16,17 @@ * @file RTCPMessageManager.cpp * */ + +#include + +#include + #include #include #include #include #include #include -#include #include #include diff --git a/src/cpp/security/logging/LogTopic.cpp b/src/cpp/security/logging/LogTopic.cpp index 747710d915c..a7be352c349 100644 --- a/src/cpp/security/logging/LogTopic.cpp +++ b/src/cpp/security/logging/LogTopic.cpp @@ -2,6 +2,7 @@ #include +#include #include namespace eprosima { diff --git a/src/cpp/security/logging/LogTopic.h b/src/cpp/security/logging/LogTopic.h index 6c19f958708..5fbc2b0a41d 100644 --- a/src/cpp/security/logging/LogTopic.h +++ b/src/cpp/security/logging/LogTopic.h @@ -18,16 +18,16 @@ #ifndef _FASTDDS_RTPS_SECURITY_LOGGING_LOGTOPIC_H_ #define _FASTDDS_RTPS_SECURITY_LOGGING_LOGTOPIC_H_ +#include +#include +#include + #include #include #include #include - -#include -#include -#include -#include +#include namespace eprosima { namespace fastrtps { @@ -77,7 +77,7 @@ class LogTopic final : public Logging std::atomic_bool stop_; - std::thread thread_; + eprosima::thread thread_; }; } //namespace security diff --git a/src/cpp/utils/SystemInfo.cpp b/src/cpp/utils/SystemInfo.cpp index 8c285d39b0e..14a2e190b7d 100644 --- a/src/cpp/utils/SystemInfo.cpp +++ b/src/cpp/utils/SystemInfo.cpp @@ -284,10 +284,13 @@ std::string SystemInfo::environment_file_; // threading.hpp implementations #ifdef _WIN32 #include "threading/threading_win32.ipp" +#include "thread_impl/thread_impl_win32.ipp" #elif defined(__APPLE__) #include "threading/threading_osx.ipp" +#include "thread_impl/thread_impl_pthread.ipp" #elif defined(_POSIX_SOURCE) || defined(__QNXNTO__) || defined(__ANDROID__) #include "threading/threading_pthread.ipp" +#include "thread_impl/thread_impl_pthread.ipp" #else #include "threading/threading_empty.ipp" #endif // Platform selection diff --git a/src/cpp/utils/shared_memory/SharedMemUUID.hpp b/src/cpp/utils/shared_memory/SharedMemUUID.hpp index a697bd3ba95..f713202e890 100644 --- a/src/cpp/utils/shared_memory/SharedMemUUID.hpp +++ b/src/cpp/utils/shared_memory/SharedMemUUID.hpp @@ -20,12 +20,13 @@ #include #endif // ifdef _MSC_VER -#include -#include +#include +#include #include -#include #include -#include +#include +#include +#include namespace eprosima { namespace fastdds { diff --git a/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp b/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp index cf9ac1edd28..a0445413206 100644 --- a/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp +++ b/src/cpp/utils/shared_memory/SharedMemWatchdog.hpp @@ -19,11 +19,11 @@ #include #include #include -#include #include #include +#include #include namespace eprosima { @@ -100,7 +100,7 @@ class SharedMemWatchdog private: std::unordered_set tasks_; - std::thread thread_run_; + eprosima::thread thread_run_; std::mutex running_tasks_mutex_; std::condition_variable wake_run_cv_; diff --git a/src/cpp/utils/thread.hpp b/src/cpp/utils/thread.hpp new file mode 100644 index 00000000000..8c079333506 --- /dev/null +++ b/src/cpp/utils/thread.hpp @@ -0,0 +1,25 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +#ifndef UTILS__THREAD_HPP_ +#define UTILS__THREAD_HPP_ + +// thread.hpp declarations +#if defined(_WIN32) || defined(__APPLE__) || defined(_POSIX_SOURCE) || defined(__QNXNTO__) || defined(__ANDROID__) +#include "thread_impl/thread_impl_custom.hpp" +#else +#include "thread_impl/thread_impl_basic.hpp" +#endif // Platform selection + +#endif // UTILS__THREAD_HPP_ diff --git a/src/cpp/utils/thread_impl/thread_impl_basic.hpp b/src/cpp/utils/thread_impl/thread_impl_basic.hpp new file mode 100644 index 00000000000..6ca1a3f5072 --- /dev/null +++ b/src/cpp/utils/thread_impl/thread_impl_basic.hpp @@ -0,0 +1,48 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +namespace eprosima { + +class thread : public std::thread +{ +public: + + thread() = default; + + template + thread( + int32_t /*stack_size*/, + _Fn&& _Fx) + : std::thread(std::forward<_Fn>(_Fx)) + { + } + + // *INDENT-OFF* + thread(thread&& _Other) noexcept = default; + thread& operator =(thread&& _Other) noexcept = default; + + thread(const thread&) = delete; + thread& operator =(const thread&) = delete; + // *INDENT-ON* + + inline bool is_calling_thread() const noexcept + { + return get_id() == std::this_thread::get_id(); + } + +}; + +} // eprosima diff --git a/src/cpp/utils/thread_impl/thread_impl_custom.hpp b/src/cpp/utils/thread_impl/thread_impl_custom.hpp new file mode 100644 index 00000000000..8c2659642f7 --- /dev/null +++ b/src/cpp/utils/thread_impl/thread_impl_custom.hpp @@ -0,0 +1,205 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(_WIN32) +#include +#endif // !defined(_WIN32) + +namespace eprosima { + +class thread +{ + +#ifdef _WIN32 + // This method is a generic proxy that serves as the starting address of the thread + template + static unsigned __stdcall ThreadProxy( + void* Ptr) + { + // Take ownership of the trampoline + std::unique_ptr Callee(static_cast(Ptr)); + // Call the trampoline + (*Callee)(); + // Finish thread + return 0; + } + +#else + // This method is a generic proxy that serves as the starting address of the thread + template + static void* ThreadProxy( + void* Ptr) + { + // Take ownership of the trampoline + std::unique_ptr Callee(static_cast(Ptr)); + // Call the trampoline + (*Callee)(); + // Finish thread + return nullptr; + } + +#endif // _WIN32 + +public: + +#ifdef _WIN32 + typedef void* native_handle_type; + typedef unsigned long id; +#else + using native_handle_type = pthread_t; + using id = pthread_t; +#endif // _WIN32 + + thread() + : thread_hnd_(native_handle_type()) + { + } + + template + thread( + int32_t stack_size, + _Fn&& f) + { + // Prepare trampoline to pass to ThreadProxy + using CalleeType = typename std::decay<_Fn>::type; + std::unique_ptr callee(new CalleeType(std::forward<_Fn>(f))); + + // Start thread + thread_hnd_ = start_thread_impl(stack_size, ThreadProxy, callee.get()); + if (thread_hnd_ != native_handle_type()) + { + // Thread has been correctly created. Since the ThreadProxy will + // take ownership of the trampoline, we need to release ownership here + callee.release(); + } + } + + ~thread() + { + if (joinable()) + { + std::terminate(); + } + } + + // *INDENT-OFF* + thread(const thread&) = delete; + thread& operator =(const thread&) = delete; + // *INDENT-ON* + + thread( + thread&& other) noexcept + : thread_hnd_(native_handle_type()) + { + swap(other); + } + + thread& operator =( + thread&& other) noexcept + { + if (joinable()) + { + std::terminate(); + } + thread_hnd_ = native_handle_type(); + swap(other); + return *this; + } + + void swap( + thread& other) noexcept + { + std::swap(thread_hnd_, other.thread_hnd_); + } + + inline bool joinable() const noexcept + { + return thread_hnd_ != native_handle_type(); + } + + inline id get_id() const noexcept + { + return get_thread_id_impl(thread_hnd_); + } + + inline native_handle_type native_handle() const noexcept + { + return thread_hnd_; + } + + static unsigned hardware_concurrency() + { + return std::thread::hardware_concurrency(); + } + + inline void join() + { + if (!joinable()) + { + throw std::system_error(std::make_error_code(std::errc::invalid_argument)); + } + + if (is_calling_thread()) + { + throw std::system_error(std::make_error_code(std::errc::resource_deadlock_would_occur)); + } + + join_thread_impl(thread_hnd_); + thread_hnd_ = native_handle_type(); + } + + inline void detach() + { + detach_thread_impl(thread_hnd_); + thread_hnd_ = native_handle_type(); + } + + inline bool is_calling_thread() const noexcept + { + return get_id() == get_current_thread_id_impl(); + } + +private: + + native_handle_type thread_hnd_; + +#ifdef _WIN32 + using start_routine_type = unsigned(__stdcall*)(void*); +#else + using start_routine_type = void* (*)(void*); +#endif // ifdef _WIN32 + + static native_handle_type start_thread_impl( + int32_t stack_size, + start_routine_type start, + void* arg); + static id get_thread_id_impl( + native_handle_type hnd); + static void join_thread_impl( + native_handle_type hnd); + static void detach_thread_impl( + native_handle_type hnd); + static id get_current_thread_id_impl(); +}; + +} // eprosima diff --git a/src/cpp/utils/thread_impl/thread_impl_pthread.ipp b/src/cpp/utils/thread_impl/thread_impl_pthread.ipp new file mode 100644 index 00000000000..0c9149bb036 --- /dev/null +++ b/src/cpp/utils/thread_impl/thread_impl_pthread.ipp @@ -0,0 +1,103 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "utils/thread.hpp" + +#include + +namespace eprosima { + +thread::native_handle_type thread::start_thread_impl( + int32_t stack_size, + thread::start_routine_type start, + void* arg) +{ + int errnum; + + // Construct the attributes object. + pthread_attr_t attr; + if ((errnum = ::pthread_attr_init(&attr)) != 0) + { + throw std::system_error(errnum, std::system_category(), "pthread_attr_init failed"); + } + + // Ensure the attributes object is destroyed + auto attr_deleter = [](pthread_attr_t* a) + { + int err; + if ((err = ::pthread_attr_destroy(a)) != 0) + { + throw std::system_error(err, std::system_category(), "pthread_attr_destroy failed"); + } + }; + std::unique_ptr attr_scope_destroy(&attr, attr_deleter); + + // Set the requested stack size, if given. + if (stack_size >= 0) + { + if (sizeof(unsigned) <= sizeof(int32_t) && + stack_size > static_cast(std::numeric_limits::max() / 2)) + { + throw std::invalid_argument("Cannot cast stack_size into unsigned"); + } + + if ((errnum = ::pthread_attr_setstacksize(&attr, stack_size)) != 0) + { + throw std::system_error(errnum, std::system_category(), "pthread_attr_setstacksize failed"); + } + } + + // Construct and execute the thread. + pthread_t hnd; + if ((errnum = ::pthread_create(&hnd, &attr, start, arg)) != 0) + { + throw std::system_error(errnum, std::system_category(), "pthread_create failed"); + } + + return hnd; +} + +thread::id thread::get_thread_id_impl( + thread::native_handle_type hnd) +{ + return hnd; +} + +void thread::join_thread_impl( + thread::native_handle_type hnd) +{ + int errnum; + if ((errnum = ::pthread_join(hnd, nullptr)) != 0) + { + throw std::system_error(std::make_error_code(std::errc::no_such_process), "pthread_join failed"); + } +} + +void thread::detach_thread_impl( + thread::native_handle_type hnd) +{ + int errnum; + + if ((errnum = ::pthread_detach(hnd)) != 0) + { + throw std::system_error(errnum, std::system_category(), "pthread_detach failed"); + } +} + +thread::id thread::get_current_thread_id_impl() +{ + return ::pthread_self(); +} + +} // eprosima diff --git a/src/cpp/utils/thread_impl/thread_impl_win32.ipp b/src/cpp/utils/thread_impl/thread_impl_win32.ipp new file mode 100644 index 00000000000..746d80bd1cb --- /dev/null +++ b/src/cpp/utils/thread_impl/thread_impl_win32.ipp @@ -0,0 +1,79 @@ +// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "utils/thread.hpp" + +#include +#include + +namespace eprosima { + +thread::native_handle_type thread::start_thread_impl( + int32_t stack_size, + thread::start_routine_type start, + void* arg) +{ + // Set the requested stack size, if given. + unsigned stack_attr = 0; + if (stack_size > 0) + { + if (sizeof(unsigned) <= sizeof(int32_t) && + stack_size > static_cast(std::numeric_limits::max() / 2)) + { + throw std::invalid_argument("Cannot cast stack_size into unsigned"); + } + + stack_attr = static_cast(stack_size); + } + + // Construct and execute the thread. + HANDLE hnd = (HANDLE) ::_beginthreadex(NULL, stack_attr, start, arg, 0, NULL); + if(!hnd) + { + throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)); + } + + return hnd; + } + +thread::id thread::get_thread_id_impl( + thread::native_handle_type hnd) +{ + return ::GetThreadId(hnd); +} + +void thread::join_thread_impl( + thread::native_handle_type hnd) +{ + if (::WaitForSingleObject(hnd, INFINITE) == WAIT_FAILED) + { + throw std::system_error(std::make_error_code(std::errc::no_such_process)); + } +} + +void thread::detach_thread_impl( + thread::native_handle_type hnd) +{ + if (::CloseHandle(hnd) == FALSE) + { + throw std::system_error(std::make_error_code(std::errc::no_such_process)); + } +} + +thread::id thread::get_current_thread_id_impl() +{ + return ::GetCurrentThreadId(); +} + +} // eprosima diff --git a/src/cpp/utils/threading.hpp b/src/cpp/utils/threading.hpp index 778d8662c35..db489490c41 100644 --- a/src/cpp/utils/threading.hpp +++ b/src/cpp/utils/threading.hpp @@ -15,7 +15,7 @@ #ifndef UTILS__THREADING_HPP_ #define UTILS__THREADING_HPP_ -#include +#include "./thread.hpp" namespace eprosima { @@ -77,7 +77,7 @@ void apply_thread_settings_to_current_thread( * @brief Create and start a thread with custom settings and name. * * This wrapper will create a thread on which the incoming functor will be called after - * applying giving it a custom name and applying the thread settings. + * giving it a custom name and applying the thread settings. * * @param[in] func Functor with the logic to be run on the created thread. * @param[in] settings Thread settings to apply to the created thread. @@ -86,13 +86,13 @@ void apply_thread_settings_to_current_thread( * See @ref set_name_to_current_thread for details. */ template -std::thread create_thread( +eprosima::thread create_thread( Functor func, const fastdds::rtps::ThreadSettings& settings, const char* name, Args... args) { - return std::thread([=]() + return eprosima::thread(settings.stack_size, [=]() { apply_thread_settings_to_current_thread(settings); set_name_to_current_thread(name, args ...); diff --git a/test/blackbox/common/BlackboxTestsTransportTCP.cpp b/test/blackbox/common/BlackboxTestsTransportTCP.cpp index a7254f60d8d..765003b5159 100644 --- a/test/blackbox/common/BlackboxTestsTransportTCP.cpp +++ b/test/blackbox/common/BlackboxTestsTransportTCP.cpp @@ -13,14 +13,18 @@ // limitations under the License. #include "BlackboxTests.hpp" -#include "TCPReqRepHelloWorldRequester.hpp" -#include "TCPReqRepHelloWorldReplier.hpp" + +#include +#include #include #include #include +#include "TCPReqRepHelloWorldRequester.hpp" +#include "TCPReqRepHelloWorldReplier.hpp" + using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; diff --git a/test/blackbox/common/RTPSBlackboxTestsPositiveAck.cpp b/test/blackbox/common/RTPSBlackboxTestsPositiveAck.cpp index 8d2ab09bd60..53b457b2c65 100644 --- a/test/blackbox/common/RTPSBlackboxTestsPositiveAck.cpp +++ b/test/blackbox/common/RTPSBlackboxTestsPositiveAck.cpp @@ -14,10 +14,13 @@ #include "BlackboxTests.hpp" +#include +#include + #include -#include "RTPSAsSocketWriter.hpp" #include "RTPSAsSocketReader.hpp" +#include "RTPSAsSocketWriter.hpp" #include "RTPSWithRegistrationReader.hpp" #include "RTPSWithRegistrationWriter.hpp" diff --git a/test/blackbox/common/RTPSBlackboxTestsVolatile.cpp b/test/blackbox/common/RTPSBlackboxTestsVolatile.cpp index 7cab100bfa3..d3981ab4575 100644 --- a/test/blackbox/common/RTPSBlackboxTestsVolatile.cpp +++ b/test/blackbox/common/RTPSBlackboxTestsVolatile.cpp @@ -14,12 +14,16 @@ #include "BlackboxTests.hpp" -#include "RTPSAsSocketReader.hpp" -#include "RTPSAsSocketWriter.hpp" +#include +#include #include + #include +#include "RTPSAsSocketReader.hpp" +#include "RTPSAsSocketWriter.hpp" + using namespace eprosima::fastrtps; enum communication_type diff --git a/test/communication/Publisher.cpp b/test/communication/Publisher.cpp index a21f596c185..6fbfe49faff 100644 --- a/test/communication/Publisher.cpp +++ b/test/communication/Publisher.cpp @@ -15,19 +15,23 @@ /** * @file Publisher.cpp */ -#include #include "Publisher.hpp" -#include + +#include +#include +#include +#include + +#include + #include #include -#include #include +#include +#include #include -#include -#include - Publisher::~Publisher() { if (participant_) diff --git a/test/communication/Subscriber.cpp b/test/communication/Subscriber.cpp index 3045dc587df..fcc7d918155 100644 --- a/test/communication/Subscriber.cpp +++ b/test/communication/Subscriber.cpp @@ -17,20 +17,23 @@ * */ +#include "Subscriber.hpp" + +#include +#include +#include +#include + #include -#include "Subscriber.hpp" -#include #include #include -#include #include +#include #include +#include #include -#include -#include - Subscriber::~Subscriber() { if (participant_) diff --git a/test/dds/communication/PublisherDynamic.cpp b/test/dds/communication/PublisherDynamic.cpp index b58edf411ec..47659e778b4 100644 --- a/test/dds/communication/PublisherDynamic.cpp +++ b/test/dds/communication/PublisherDynamic.cpp @@ -16,27 +16,28 @@ * @file Publisher.cpp */ +#include +#include +#include +#include +#include +#include + #include -#include #include +#include #include +#include #include #include -#include -#include #include - -#include +#include #include #include +#include #include -#include -#include -#include -#include - using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; diff --git a/test/dds/communication/PublisherModule.cpp b/test/dds/communication/PublisherModule.cpp index 547b442b9ef..99d1bb437b1 100644 --- a/test/dds/communication/PublisherModule.cpp +++ b/test/dds/communication/PublisherModule.cpp @@ -15,18 +15,21 @@ /** * @file PublisherModule.cpp */ -#include #include "PublisherModule.hpp" -#include -#include -#include -#include -#include - +#include #include #include +#include + +#include + +#include +#include +#include +#include +#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/test/dds/communication/SubscriberModule.cpp b/test/dds/communication/SubscriberModule.cpp index 9f2c5aece87..e08b024c6d4 100644 --- a/test/dds/communication/SubscriberModule.cpp +++ b/test/dds/communication/SubscriberModule.cpp @@ -17,18 +17,20 @@ * */ -#include - #include "SubscriberModule.hpp" +#include +#include +#include +#include + +#include + #include -#include +#include #include +#include #include -#include - -#include -#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/test/performance/latency/LatencyTestPublisher.cpp b/test/performance/latency/LatencyTestPublisher.cpp index 60081566de7..45cac09b1eb 100644 --- a/test/performance/latency/LatencyTestPublisher.cpp +++ b/test/performance/latency/LatencyTestPublisher.cpp @@ -21,20 +21,22 @@ #include -#include +#include #include #include +#include +#include #include #include -#include #include +#include #include #include #include -#include -#include #include +#include +#include #define TIME_LIMIT_US 10000 diff --git a/test/performance/latency/LatencyTestSubscriber.cpp b/test/performance/latency/LatencyTestSubscriber.cpp index 862e741e5aa..f6e34bca42a 100644 --- a/test/performance/latency/LatencyTestSubscriber.cpp +++ b/test/performance/latency/LatencyTestSubscriber.cpp @@ -19,6 +19,8 @@ #include "LatencyTestSubscriber.hpp" #include +#include +#include #include #include @@ -26,10 +28,10 @@ #include #include #include -#include #include -#include #include +#include +#include using namespace eprosima::fastrtps::rtps; using namespace eprosima::fastrtps::types; diff --git a/test/performance/throughput/ThroughputPublisher.cpp b/test/performance/throughput/ThroughputPublisher.cpp index d30b64f5f3e..ba56678fde8 100644 --- a/test/performance/throughput/ThroughputPublisher.cpp +++ b/test/performance/throughput/ThroughputPublisher.cpp @@ -19,9 +19,10 @@ #include "ThroughputPublisher.hpp" -#include -#include #include +#include +#include +#include #include #include @@ -31,10 +32,10 @@ #include #include #include +#include +#include #include #include -#include -#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/test/performance/throughput/ThroughputSubscriber.cpp b/test/performance/throughput/ThroughputSubscriber.cpp index 2a790d68aaa..70f326bc5c5 100644 --- a/test/performance/throughput/ThroughputSubscriber.cpp +++ b/test/performance/throughput/ThroughputSubscriber.cpp @@ -19,6 +19,8 @@ #include "ThroughputSubscriber.hpp" +#include +#include #include #include @@ -28,10 +30,10 @@ #include #include #include +#include +#include #include #include -#include -#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/test/unittest/dds/profiles/test_xml_for_string_profile.xml b/test/unittest/dds/profiles/test_xml_for_string_profile.xml index b5b33707d20..0f25801a726 100644 --- a/test/unittest/dds/profiles/test_xml_for_string_profile.xml +++ b/test/unittest/dds/profiles/test_xml_for_string_profile.xml @@ -127,34 +127,24 @@ true test_name - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 @@ -282,34 +272,24 @@ true default_name - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 diff --git a/test/unittest/dds/profiles/test_xml_profile.xml b/test/unittest/dds/profiles/test_xml_profile.xml index a0c59ac24d7..acb0bef30e7 100644 --- a/test/unittest/dds/profiles/test_xml_profile.xml +++ b/test/unittest/dds/profiles/test_xml_profile.xml @@ -124,34 +124,24 @@ true test_name - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 @@ -279,34 +269,24 @@ true default_name - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 - 12 - 12 - 12 - 12 + 15 + 1048576 diff --git a/test/unittest/logging/LogTests.cpp b/test/unittest/logging/LogTests.cpp index a6caae4cb87..fe8b4192603 100644 --- a/test/unittest/logging/LogTests.cpp +++ b/test/unittest/logging/LogTests.cpp @@ -678,8 +678,9 @@ TEST_F(LogTests, thread_config) // Set thread settings eprosima::fastdds::rtps::ThreadSettings thr_settings{}; -#if defined(_POSIX_SOURCE) + thr_settings.stack_size = 1024 * 1024 * 4; thr_settings.affinity = 3; +#if defined(_POSIX_SOURCE) thr_settings.scheduling_policy = SCHED_OTHER; thr_settings.priority = 1; #endif // if defined(_POSIX_SOURCE) diff --git a/test/xtypes/TestPublisher.cpp b/test/xtypes/TestPublisher.cpp index 6c9ddd827bd..5076ee6eda4 100644 --- a/test/xtypes/TestPublisher.cpp +++ b/test/xtypes/TestPublisher.cpp @@ -17,24 +17,30 @@ */ #include "TestPublisher.h" -#include + +#include +#include + +#include + +#include + +#include #include -#include -#include +#include #include -#include #include -#include +#include +#include +#include +#include #include -#include #include +#include #include -#include #include -#include +#include #include -#include -#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::dds::xtypes; diff --git a/thirdparty/filewatch/FileWatch.hpp b/thirdparty/filewatch/FileWatch.hpp index 37c462762d9..8f4b6092b4f 100644 --- a/thirdparty/filewatch/FileWatch.hpp +++ b/thirdparty/filewatch/FileWatch.hpp @@ -25,6 +25,7 @@ #include +#include #include #ifdef _WIN32 @@ -151,12 +152,12 @@ namespace filewatch { std::atomic _destory = { false }; std::function _callback; - std::thread _watch_thread; + eprosima::thread _watch_thread; std::condition_variable _cv; std::mutex _callback_mutex; std::vector> _callback_information; - std::thread _callback_thread; + eprosima::thread _callback_thread; std::promise _running; From 8dd990895dcb56089b86cec15e94db06d02f1b95 Mon Sep 17 00:00:00 2001 From: EduPonz Date: Mon, 13 Nov 2023 15:20:40 +0100 Subject: [PATCH 9/9] Refs #19907: Add feature to versions.md Signed-off-by: EduPonz --- versions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/versions.md b/versions.md index 6351656f56f..88aac2e9ddb 100644 --- a/versions.md +++ b/versions.md @@ -1,6 +1,8 @@ Forthcoming ----------- +* Enable configuration of thread setting for all threads. + Version 2.12.0 --------------