From 9c42ff23aea25dc78e7c3e6eba76b41e0130f26e Mon Sep 17 00:00:00 2001 From: Eduardo Ponz Segrelles Date: Fri, 22 Mar 2024 11:20:04 +0100 Subject: [PATCH] Run Github Ubuntu CI on PRs (#4598) * Refs #20679: Run Github Ubuntu CI on PRs Signed-off-by: EduPonz * Refs #20679: Fix remaining hidden overloads Signed-off-by: EduPonz * Refs #20679: Run CI on PRs to intermediate branches Signed-off-by: EduPonz --------- Signed-off-by: EduPonz (cherry picked from commit 7154a57a039297c3fd2bc10130033db11bb88e0e) # Conflicts: # .github/workflows/address-sanitizers.yaml # .github/workflows/documentation-tests.yaml # .github/workflows/mac-ci.yml # .github/workflows/thread-sanitizer.yaml # .github/workflows/windows-ci.yml # src/cpp/fastdds/domain/DomainParticipantImpl.hpp # src/cpp/statistics/rtps/monitor-service/MonitorServiceListener.hpp # test/blackbox/common/BlackboxTestsDiscovery.cpp --- .github/workflows/address-sanitizers.yaml | 3 + .github/workflows/documentation-tests.yaml | 3 + .github/workflows/mac-ci.yml | 3 + .github/workflows/thread-sanitizer.yaml | 3 + .github/workflows/ubuntu-ci.yml | 6 + .github/workflows/windows-ci.yml | 3 + .../fastrtps/subscriber/SubscriberHistory.h | 4 + .../fastdds/domain/DomainParticipantImpl.hpp | 56 ++++++++ src/cpp/fastdds/publisher/DataWriterImpl.hpp | 4 + src/cpp/fastdds/subscriber/DataReaderImpl.hpp | 4 + .../participant/ParticipantImpl.h | 6 + .../publisher/PublisherImpl.h | 4 + .../subscriber/SubscriberImpl.h | 4 + src/cpp/rtps/DataSharing/ReaderPool.hpp | 2 + src/cpp/rtps/DataSharing/WriterPool.hpp | 2 + .../builtin/discovery/participant/PDPClient.h | 2 + .../discovery/participant/PDPServer.hpp | 2 + .../history/BasicPayloadPool_impl/Base.hpp | 2 + .../PreallocatedWithRealloc.hpp | 2 + .../history/TopicPayloadPool_impl/Dynamic.hpp | 4 + .../TopicPayloadPool_impl/DynamicReusable.hpp | 4 + .../TopicPayloadPool_impl/Preallocated.hpp | 2 + .../PreallocatedWithRealloc.hpp | 2 + .../rtps/transport/TCPTransportInterface.h | 2 + .../rtps/transport/UDPTransportInterface.h | 2 + .../transport/shared_mem/SharedMemTransport.h | 2 + .../MonitorServiceListener.hpp | 83 +++++++++++ .../common/BlackboxTestsDiscovery.cpp | 134 ++++++++++++++++++ 28 files changed, 350 insertions(+) create mode 100644 src/cpp/statistics/rtps/monitor-service/MonitorServiceListener.hpp diff --git a/.github/workflows/address-sanitizers.yaml b/.github/workflows/address-sanitizers.yaml index 71f345ea70d..a9f6a34d776 100644 --- a/.github/workflows/address-sanitizers.yaml +++ b/.github/workflows/address-sanitizers.yaml @@ -13,8 +13,11 @@ on: default: '2.6.x' pull_request: +<<<<<<< HEAD branches: - '2.6.x' +======= +>>>>>>> 7154a57a0 (Run Github Ubuntu CI on PRs (#4598)) paths-ignore: - '**.md' - '**.txt' diff --git a/.github/workflows/documentation-tests.yaml b/.github/workflows/documentation-tests.yaml index e9f835980bc..c4908faa588 100644 --- a/.github/workflows/documentation-tests.yaml +++ b/.github/workflows/documentation-tests.yaml @@ -9,8 +9,11 @@ on: default: '2.6.x' pull_request: +<<<<<<< HEAD branches: - '2.6.x' +======= +>>>>>>> 7154a57a0 (Run Github Ubuntu CI on PRs (#4598)) paths-ignore: - '**.md' - '**.txt' diff --git a/.github/workflows/mac-ci.yml b/.github/workflows/mac-ci.yml index 14152386b71..6b3f6af5f9b 100644 --- a/.github/workflows/mac-ci.yml +++ b/.github/workflows/mac-ci.yml @@ -25,8 +25,11 @@ on: required: true pull_request: +<<<<<<< HEAD branches: - '2.6.x' +======= +>>>>>>> 7154a57a0 (Run Github Ubuntu CI on PRs (#4598)) paths-ignore: - '**.md' - '**.txt' diff --git a/.github/workflows/thread-sanitizer.yaml b/.github/workflows/thread-sanitizer.yaml index 50b250803c3..26e613c0449 100644 --- a/.github/workflows/thread-sanitizer.yaml +++ b/.github/workflows/thread-sanitizer.yaml @@ -16,8 +16,11 @@ on: type: string pull_request: +<<<<<<< HEAD branches: - '2.6.x' +======= +>>>>>>> 7154a57a0 (Run Github Ubuntu CI on PRs (#4598)) paths-ignore: - '**.md' - '**.txt' diff --git a/.github/workflows/ubuntu-ci.yml b/.github/workflows/ubuntu-ci.yml index ae94ed5ec5e..edbb6f4cdc6 100644 --- a/.github/workflows/ubuntu-ci.yml +++ b/.github/workflows/ubuntu-ci.yml @@ -24,6 +24,12 @@ on: type: string required: true + pull_request: + paths-ignore: + - '**.md' + - '**.txt' + - '!**/CMakeLists.txt' + concurrency: group: ${{ github.workflow }} cancel-in-progress: true diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.yml index dbd7222410d..595491c4eb7 100644 --- a/.github/workflows/windows-ci.yml +++ b/.github/workflows/windows-ci.yml @@ -25,8 +25,11 @@ on: required: true pull_request: +<<<<<<< HEAD branches: - '2.6.x' +======= +>>>>>>> 7154a57a0 (Run Github Ubuntu CI on PRs (#4598)) paths-ignore: - '**.md' - '**.txt' diff --git a/include/fastrtps/subscriber/SubscriberHistory.h b/include/fastrtps/subscriber/SubscriberHistory.h index be94ed6a291..eba33252b01 100644 --- a/include/fastrtps/subscriber/SubscriberHistory.h +++ b/include/fastrtps/subscriber/SubscriberHistory.h @@ -179,6 +179,10 @@ class SubscriberHistory : public rtps::ReaderHistory private: + using rtps::ReaderHistory::completed_change; + using rtps::ReaderHistory::received_change; + using rtps::ReaderHistory::remove_change_nts; + using t_m_Inst_Caches = std::map; //!Map where keys are instance handles and values vectors of cache changes diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp index c03b7009a5a..e742d00c192 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp @@ -525,6 +525,62 @@ class DomainParticipantImpl class MyRTPSParticipantListener : public fastrtps::rtps::RTPSParticipantListener { +<<<<<<< HEAD +======= + struct Sentry + { + Sentry( + MyRTPSParticipantListener* listener) + : listener_(listener) + , on_guard_(false) + { + std::lock_guard _(listener_->participant_->mtx_gs_); + if (listener_ != nullptr && listener_->participant_ != nullptr && + listener_->participant_->listener_ != nullptr && + listener_->participant_->participant_ != nullptr) + { + if (listener_->callback_counter_ >= 0) + { + ++listener_->callback_counter_; + on_guard_ = true; + } + } + } + + ~Sentry() + { + if (on_guard_) + { + bool notify = false; + { + std::lock_guard lock(listener_->participant_->mtx_gs_); + assert( + listener_ != nullptr && listener_->participant_ != nullptr && listener_->participant_->listener_ != nullptr && + listener_->participant_->participant_ != nullptr); + --listener_->callback_counter_; + notify = !listener_->callback_counter_; + } + if (notify) + { + listener_->participant_->cv_gs_.notify_all(); + } + } + } + + operator bool () const + { + return on_guard_; + } + + MyRTPSParticipantListener* listener_ = nullptr; + bool on_guard_; + }; + + using fastrtps::rtps::RTPSParticipantListener::onParticipantDiscovery; + using fastrtps::rtps::RTPSParticipantListener::onReaderDiscovery; + using fastrtps::rtps::RTPSParticipantListener::onWriterDiscovery; + +>>>>>>> 7154a57a0 (Run Github Ubuntu CI on PRs (#4598)) public: MyRTPSParticipantListener( diff --git a/src/cpp/fastdds/publisher/DataWriterImpl.hpp b/src/cpp/fastdds/publisher/DataWriterImpl.hpp index a964bced935..934bdae9243 100644 --- a/src/cpp/fastdds/publisher/DataWriterImpl.hpp +++ b/src/cpp/fastdds/publisher/DataWriterImpl.hpp @@ -378,6 +378,10 @@ class DataWriterImpl : protected rtps::IReaderDataFilter const fastrtps::rtps::ReaderProxyData* reader_info) override; DataWriterImpl* data_writer_; + + private: + + using fastrtps::rtps::WriterListener::onWriterMatched; } writer_listener_; diff --git a/src/cpp/fastdds/subscriber/DataReaderImpl.hpp b/src/cpp/fastdds/subscriber/DataReaderImpl.hpp index 64555bdf322..b7915393be1 100644 --- a/src/cpp/fastdds/subscriber/DataReaderImpl.hpp +++ b/src/cpp/fastdds/subscriber/DataReaderImpl.hpp @@ -389,6 +389,10 @@ class DataReaderImpl int32_t sample_lost_since_last_update) override; DataReaderImpl* data_reader_; + + private: + + using fastrtps::rtps::ReaderListener::onReaderMatched; } reader_listener_; diff --git a/src/cpp/fastrtps_deprecated/participant/ParticipantImpl.h b/src/cpp/fastrtps_deprecated/participant/ParticipantImpl.h index 37ba3eabf96..a0165ac0c75 100644 --- a/src/cpp/fastrtps_deprecated/participant/ParticipantImpl.h +++ b/src/cpp/fastrtps_deprecated/participant/ParticipantImpl.h @@ -233,6 +233,12 @@ class ParticipantImpl ParticipantImpl* mp_participantimpl; + private: + + using rtps::RTPSParticipantListener::onParticipantDiscovery; + using rtps::RTPSParticipantListener::onReaderDiscovery; + using rtps::RTPSParticipantListener::onWriterDiscovery; + } m_rtps_listener; diff --git a/src/cpp/fastrtps_deprecated/publisher/PublisherImpl.h b/src/cpp/fastrtps_deprecated/publisher/PublisherImpl.h index b86a83fea6c..ca0db2822b0 100644 --- a/src/cpp/fastrtps_deprecated/publisher/PublisherImpl.h +++ b/src/cpp/fastrtps_deprecated/publisher/PublisherImpl.h @@ -243,6 +243,10 @@ class PublisherImpl const LivelinessLostStatus& status) override; PublisherImpl* mp_publisherImpl; + + private: + + using rtps::WriterListener::onWriterMatched; } m_writerListener; diff --git a/src/cpp/fastrtps_deprecated/subscriber/SubscriberImpl.h b/src/cpp/fastrtps_deprecated/subscriber/SubscriberImpl.h index 18ed81d8f99..49429570bfd 100644 --- a/src/cpp/fastrtps_deprecated/subscriber/SubscriberImpl.h +++ b/src/cpp/fastrtps_deprecated/subscriber/SubscriberImpl.h @@ -221,6 +221,10 @@ class SubscriberImpl rtps::RTPSReader* reader, const LivelinessChangedStatus& status) override; SubscriberImpl* mp_subscriberImpl; + + private: + + using rtps::ReaderListener::onReaderMatched; } m_readerListener; diff --git a/src/cpp/rtps/DataSharing/ReaderPool.hpp b/src/cpp/rtps/DataSharing/ReaderPool.hpp index ccd53e459e0..4b7cdec25a6 100644 --- a/src/cpp/rtps/DataSharing/ReaderPool.hpp +++ b/src/cpp/rtps/DataSharing/ReaderPool.hpp @@ -283,6 +283,8 @@ class ReaderPool : public DataSharingPayloadPool private: + using DataSharingPayloadPool::init_shared_memory; + bool is_volatile_; //< Whether the reader is volatile or not uint64_t next_payload_; //< Index of the next history position to read SequenceNumber_t last_sn_; //< Sequence number of the last read payload diff --git a/src/cpp/rtps/DataSharing/WriterPool.hpp b/src/cpp/rtps/DataSharing/WriterPool.hpp index 48ca6c31638..44c84be3641 100644 --- a/src/cpp/rtps/DataSharing/WriterPool.hpp +++ b/src/cpp/rtps/DataSharing/WriterPool.hpp @@ -353,6 +353,8 @@ class WriterPool : public DataSharingPayloadPool private: + using DataSharingPayloadPool::init_shared_memory; + octet* payloads_pool_; //< Shared pool of payloads uint32_t max_data_size_; //< Maximum size of the serialized payload data diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.h b/src/cpp/rtps/builtin/discovery/participant/PDPClient.h index e7053c3f1e4..fa0e76253f1 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.h +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.h @@ -173,6 +173,8 @@ class PDPClient : public PDP private: + using PDP::announceParticipantState; + /** * Manually match the local PDP reader with the PDP writer of a given server. The function is * not thread safe (nts) in the sense that it does not take the PDP mutex. It does however take diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp index 0a4ad9b98ba..73e932d28fc 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp @@ -312,6 +312,8 @@ class PDPServer : public fastrtps::rtps::PDP private: + using fastrtps::rtps::PDP::announceParticipantState; + #if HAVE_SECURITY /** * Returns whether discovery should be secured diff --git a/src/cpp/rtps/history/BasicPayloadPool_impl/Base.hpp b/src/cpp/rtps/history/BasicPayloadPool_impl/Base.hpp index 76fa7e42f14..b483b3b548d 100644 --- a/src/cpp/rtps/history/BasicPayloadPool_impl/Base.hpp +++ b/src/cpp/rtps/history/BasicPayloadPool_impl/Base.hpp @@ -18,6 +18,8 @@ class BaseImpl : public IPayloadPool { +public: + bool get_payload( uint32_t size, CacheChange_t& cache_change) override diff --git a/src/cpp/rtps/history/BasicPayloadPool_impl/PreallocatedWithRealloc.hpp b/src/cpp/rtps/history/BasicPayloadPool_impl/PreallocatedWithRealloc.hpp index e54c2a3ca2f..730d06f3933 100644 --- a/src/cpp/rtps/history/BasicPayloadPool_impl/PreallocatedWithRealloc.hpp +++ b/src/cpp/rtps/history/BasicPayloadPool_impl/PreallocatedWithRealloc.hpp @@ -39,5 +39,7 @@ class Impl : public BaseImpl private: + using BaseImpl::get_payload; + uint32_t min_payload_size_; }; diff --git a/src/cpp/rtps/history/TopicPayloadPool_impl/Dynamic.hpp b/src/cpp/rtps/history/TopicPayloadPool_impl/Dynamic.hpp index 889dd3b12ae..258a9baa685 100644 --- a/src/cpp/rtps/history/TopicPayloadPool_impl/Dynamic.hpp +++ b/src/cpp/rtps/history/TopicPayloadPool_impl/Dynamic.hpp @@ -86,6 +86,10 @@ class DynamicTopicPayloadPool : public TopicPayloadPool return DYNAMIC_RESERVE_MEMORY_MODE; } +private: + + using TopicPayloadPool::get_payload; + }; } // namespace rtps diff --git a/src/cpp/rtps/history/TopicPayloadPool_impl/DynamicReusable.hpp b/src/cpp/rtps/history/TopicPayloadPool_impl/DynamicReusable.hpp index 3cc7b54f789..3d04330c0f6 100644 --- a/src/cpp/rtps/history/TopicPayloadPool_impl/DynamicReusable.hpp +++ b/src/cpp/rtps/history/TopicPayloadPool_impl/DynamicReusable.hpp @@ -41,6 +41,10 @@ class DynamicReusableTopicPayloadPool : public TopicPayloadPool return DYNAMIC_REUSABLE_MEMORY_MODE; } +private: + + using TopicPayloadPool::get_payload; + }; } // namespace rtps diff --git a/src/cpp/rtps/history/TopicPayloadPool_impl/Preallocated.hpp b/src/cpp/rtps/history/TopicPayloadPool_impl/Preallocated.hpp index aa4bc67fff1..99ed905664c 100644 --- a/src/cpp/rtps/history/TopicPayloadPool_impl/Preallocated.hpp +++ b/src/cpp/rtps/history/TopicPayloadPool_impl/Preallocated.hpp @@ -80,6 +80,8 @@ class PreallocatedTopicPayloadPool : public TopicPayloadPool private: + using TopicPayloadPool::get_payload; + uint32_t payload_size_; uint32_t minimum_pool_size_; //< Minimum initial pool size (sum of all histories) }; diff --git a/src/cpp/rtps/history/TopicPayloadPool_impl/PreallocatedWithRealloc.hpp b/src/cpp/rtps/history/TopicPayloadPool_impl/PreallocatedWithRealloc.hpp index 75e0cf1c68d..d8ed34b41e2 100644 --- a/src/cpp/rtps/history/TopicPayloadPool_impl/PreallocatedWithRealloc.hpp +++ b/src/cpp/rtps/history/TopicPayloadPool_impl/PreallocatedWithRealloc.hpp @@ -80,6 +80,8 @@ class PreallocatedReallocTopicPayloadPool : public TopicPayloadPool private: + using TopicPayloadPool::get_payload; + uint32_t min_payload_size_; uint32_t minimum_pool_size_; //< Minimum initial pool size (sum of all histories) }; diff --git a/src/cpp/rtps/transport/TCPTransportInterface.h b/src/cpp/rtps/transport/TCPTransportInterface.h index 5ae4acc66c8..79352fc9494 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.h +++ b/src/cpp/rtps/transport/TCPTransportInterface.h @@ -71,6 +71,8 @@ class TCPTransportInterface : public TransportInterface std::atomic alive_; + using TransportInterface::transform_remote_locator; + protected: std::vector current_interfaces_; diff --git a/src/cpp/rtps/transport/UDPTransportInterface.h b/src/cpp/rtps/transport/UDPTransportInterface.h index 48cfd68a89c..6205830f4c6 100644 --- a/src/cpp/rtps/transport/UDPTransportInterface.h +++ b/src/cpp/rtps/transport/UDPTransportInterface.h @@ -38,6 +38,8 @@ class UDPTransportInterface : public TransportInterface { friend class UDPSenderResource; + using TransportInterface::transform_remote_locator; + public: ~UDPTransportInterface() override; diff --git a/src/cpp/rtps/transport/shared_mem/SharedMemTransport.h b/src/cpp/rtps/transport/shared_mem/SharedMemTransport.h index 63f79172527..7640da86ad1 100644 --- a/src/cpp/rtps/transport/shared_mem/SharedMemTransport.h +++ b/src/cpp/rtps/transport/shared_mem/SharedMemTransport.h @@ -194,6 +194,8 @@ class SharedMemTransport : public TransportInterface private: + using TransportInterface::transform_remote_locator; + //! Constructor with no descriptor is necessary for implementations derived from this class. SharedMemTransport(); diff --git a/src/cpp/statistics/rtps/monitor-service/MonitorServiceListener.hpp b/src/cpp/statistics/rtps/monitor-service/MonitorServiceListener.hpp new file mode 100644 index 00000000000..358c9f963d7 --- /dev/null +++ b/src/cpp/statistics/rtps/monitor-service/MonitorServiceListener.hpp @@ -0,0 +1,83 @@ +// 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 MonitorServiceListener.hpp + */ + +#ifndef _STATISTICS_RTPS_MONITOR_SERVICE_MONITORSERVICELISTENER_HPP_ +#define _STATISTICS_RTPS_MONITOR_SERVICE_MONITORSERVICELISTENER_HPP_ + + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace statistics { +namespace rtps { + +class MonitorService; + +#ifdef FASTDDS_STATISTICS + +class MonitorServiceListener : + public fastrtps::rtps::WriterListener, + public IStatusObserver, + public IConnectionsObserver, + public IProxyObserver +{ + +public: + + MonitorServiceListener( + MonitorService* ms); + + bool on_local_entity_status_change( + const fastrtps::rtps::GUID_t& guid, + const uint32_t& id) const override; + + bool on_local_entity_change( + const fastrtps::rtps::GUID_t& guid, + bool is_alive) const override; + + bool on_local_entity_connections_change( + const fastrtps::rtps::GUID_t& guid) const override; + + void onWriterMatched( + fastrtps::rtps::RTPSWriter* writer, + fastrtps::rtps::MatchingInfo& info) override; + + void onWriterChangeReceivedByAll( + fastrtps::rtps::RTPSWriter* writer, + fastrtps::rtps::CacheChange_t* change) override; + +protected: + + MonitorService* monitor_srv_; + +private: + + using fastrtps::rtps::WriterListener::onWriterMatched; + +}; + +#endif // FASTDDS_STATISTICS + +} // namespace rtps +} // namespace statistics +} // namespace fastdds +} // namespace eprosima + +#endif // _STATISTICS_RTPS_MONITOR_SERVICE_MONITORSERVICELISTENER_HPP_ diff --git a/test/blackbox/common/BlackboxTestsDiscovery.cpp b/test/blackbox/common/BlackboxTestsDiscovery.cpp index 646bb8d1ba9..3b3b7f3c041 100644 --- a/test/blackbox/common/BlackboxTestsDiscovery.cpp +++ b/test/blackbox/common/BlackboxTestsDiscovery.cpp @@ -1741,3 +1741,137 @@ TEST(Discovery, MulticastInitialPeer) writer.wait_discovery(); reader.wait_discovery(); } +<<<<<<< HEAD +======= + +//! Regression test for redmine issue 17162 +TEST(Discovery, MultipleXMLProfileLoad) +{ + // These test may fail because one of the participants disappear before the other has found it. + // Thus, use condition variable so threads only finish once the discovery has taken place. + std::condition_variable cv; + std::mutex cv_mtx; + std::atomic n_discoveries(0); + + auto participant_creation_reader = [&]() + { + PubSubReader participant(TEST_TOPIC_NAME); + participant.init(); + participant.wait_discovery(); + + // Notify discovery has happen + { + std::unique_lock lock(cv_mtx); + n_discoveries++; + } + cv.notify_all(); + + std::unique_lock lock(cv_mtx); + cv.wait( + lock, + [&]() + { + return n_discoveries >= 2; + } + ); + }; + + auto participant_creation_writer = [&]() + { + PubSubWriter participant(TEST_TOPIC_NAME); + participant.init(); + participant.wait_discovery(); + + // Notify discovery has happen + { + std::unique_lock lock(cv_mtx); + n_discoveries++; + } + cv.notify_all(); + + std::unique_lock lock(cv_mtx); + cv.wait( + lock, + [&]() + { + return n_discoveries >= 2; + } + ); + }; + + // Start thread creating second participant + std::thread thr_reader(participant_creation_reader); + std::thread thr_writer(participant_creation_writer); + + thr_reader.join(); + thr_writer.join(); +} + +//! Regression test for redmine issue 20641 +TEST(Discovery, discovery_cyclone_participant_with_custom_pid) +{ + using namespace eprosima::fastdds::dds; + using namespace eprosima::fastrtps::rtps; + + /* Custom participant listener to count number of discovered participants */ + class DiscoveryListener : public DomainParticipantListener + { + public: + + void on_participant_discovery( + DomainParticipant*, + ParticipantDiscoveryInfo&& info) override + { + if (ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT == info.status) + { + discovered_participants_++; + } + else if (ParticipantDiscoveryInfo::REMOVED_PARTICIPANT == info.status) + { + discovered_participants_--; + } + } + + uint8_t discovered_participants() const + { + return discovered_participants_; + } + + private: + + using DomainParticipantListener::on_participant_discovery; + + std::atomic discovered_participants_{0}; + }; + + /* Create a datagram injection transport */ + using eprosima::fastdds::rtps::DatagramInjectionTransportDescriptor; + using eprosima::fastdds::rtps::DatagramInjectionTransport; + auto low_level_transport = std::make_shared(); + auto transport = std::make_shared(low_level_transport); + + /* Disable builtin transport and add custom one */ + DomainParticipantQos participant_qos = PARTICIPANT_QOS_DEFAULT; + participant_qos.transport().use_builtin_transports = false; + participant_qos.transport().user_transports.clear(); + participant_qos.transport().user_transports.push_back(transport); + + /* Create participant with custom transport and listener */ + DiscoveryListener listener; + uint32_t domain_id = static_cast(GET_PID()) % 230; + DomainParticipantFactory* factory = DomainParticipantFactory::get_instance(); + DomainParticipant* participant = factory->create_participant(domain_id, participant_qos, &listener); + ASSERT_NE(nullptr, participant); + + /* Inject a Cyclone DDS Data(p) with a custom PID that we also use */ + auto receivers = transport->get_receivers(); + ASSERT_FALSE(receivers.empty()); + DatagramInjectionTransport::deliver_datagram_from_file(receivers, "datagrams/20641.bin"); + + /* Assert that the participant is discovered */ + ASSERT_EQ(listener.discovered_participants(), 1u); + + /* Clean up */ + factory->delete_participant(participant); +} +>>>>>>> 7154a57a0 (Run Github Ubuntu CI on PRs (#4598))