diff --git a/.github/workflows/reusable-ubuntu-ci.yml b/.github/workflows/reusable-ubuntu-ci.yml index 6414e02194f..a3e1b4c1c73 100644 --- a/.github/workflows/reusable-ubuntu-ci.yml +++ b/.github/workflows/reusable-ubuntu-ci.yml @@ -97,7 +97,11 @@ jobs: colcon_meta_file: ${{ github.workspace }}/src/fastrtps/.github/workflows/config/ci.meta colcon_build_args: ${{ inputs.colcon-args }} cmake_args: ${{ inputs.cmake-args }} +<<<<<<< HEAD cmake_args_default: -DCMAKE_CXX_FLAGS="-Werror -Wall" +======= + cmake_args_default: -DCMAKE_CXX_FLAGS="-Werror -Wall -Wextra -Wpedantic -Wunused-value -Woverloaded-virtual" -DFASTDDS_EXAMPLE_TESTS=ON +>>>>>>> 63cc242b2 (Fix hidden overloaded virtual methods (#4516)) cmake_build_type: ${{ matrix.cmake-build-type }} workspace: ${{ github.workspace }} diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.h b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.h new file mode 100644 index 00000000000..82bbfd6ee47 --- /dev/null +++ b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.h @@ -0,0 +1,126 @@ +// Copyright 2021 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 DiscoveryServerPublisher.h + * + */ + +#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERPUBLISHER_H_ +#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERPUBLISHER_H_ + +#include + +#include +#include +#include + +#include "types/HelloWorldPubSubTypes.h" +#include "common.h" + +/** + * Class used to group into a single working unit a Publisher with a DataWriter, its listener, and a TypeSupport member + * corresponding to the HelloWorld datatype + */ +class HelloWorldPublisher +{ +public: + + HelloWorldPublisher(); + + virtual ~HelloWorldPublisher(); + + //! Initialize the publisher + bool init( + const std::string& topic_name, + const std::string& server_address, + unsigned short server_port, + unsigned short server_id, + TransportKind transport); + + //! Publish a sample + void publish(); + + //! Run for number samples, publish every sleep seconds + void run( + uint32_t number, + uint32_t sleep); + + //! Return the current state of execution + static bool is_stopped(); + + //! Trigger the end of execution + static void stop(); + +private: + + HelloWorld hello_; + + eprosima::fastdds::dds::DomainParticipant* participant_; + + eprosima::fastdds::dds::Publisher* publisher_; + + eprosima::fastdds::dds::Topic* topic_; + + eprosima::fastdds::dds::DataWriter* writer_; + + eprosima::fastdds::dds::TypeSupport type_; + + /** + * Class handling discovery events + */ + class PubListener : public eprosima::fastdds::dds::DomainParticipantListener + { + public: + + PubListener() + : matched_(0) + { + } + + ~PubListener() override + { + } + + //! Callback executed when a DataReader is matched or unmatched + void on_publication_matched( + eprosima::fastdds::dds::DataWriter* writer, + const eprosima::fastdds::dds::PublicationMatchedStatus& info) override; + + //! Callback executed when a DomainParticipant is discovered, dropped or removed + void on_participant_discovery( + eprosima::fastdds::dds::DomainParticipant* /*participant*/, + eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) override; + + private: + + using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; + + //! Number of DataReaders matched to the associated DataWriter + std::atomic matched_; + } + listener_; + + //! Run thread for number samples, publish every sleep seconds + void runThread( + uint32_t number, + uint32_t sleep); + + //! Member used for control flow purposes + static std::atomic stop_; +}; + + + +#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERPUBLISHER_H_ */ diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.h b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.h new file mode 100644 index 00000000000..566dd904826 --- /dev/null +++ b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.h @@ -0,0 +1,106 @@ +// Copyright 2021 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 DiscoveryServerServer.h + * + */ + +#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSERVER_H_ +#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSERVER_H_ + +#include +#include +#include + +#include +#include + +#include "common.h" + +/** + * Class with a partipant configured to function as server in the Discovery Server mechanism + */ +class DiscoveryServer +{ +public: + + DiscoveryServer(); + + virtual ~DiscoveryServer(); + + //! Initialize the server + bool init( + const std::string& server_address, + unsigned short server_port, + unsigned short server_id, + TransportKind transport, + bool has_connection_server, + const std::string& connection_server_address, + unsigned short connection_server_port, + unsigned short connection_server_id); + + //! Run + void run( + unsigned int timeout); + + //! Return the current state of execution + static bool is_stopped(); + + //! Trigger the end of execution + static void stop(); + +private: + + eprosima::fastdds::dds::DomainParticipant* participant_; + + /** + * Class handling discovery events + */ + class ServerListener : public eprosima::fastdds::dds::DomainParticipantListener + { + public: + + ServerListener() + { + } + + ~ServerListener() override + { + } + + //! Callback executed when a DomainParticipant is discovered, dropped or removed + void on_participant_discovery( + eprosima::fastdds::dds::DomainParticipant* /*participant*/, + eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) override; + + private: + + using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; + } + listener_; + + //! Member used for control flow purposes + static std::atomic stop_; + + //! Protects terminate condition variable + static std::mutex terminate_cv_mtx_; + + //! Waits during execution until SIGINT or max_messages_ samples are received + static std::condition_variable terminate_cv_; +}; + + + +#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSERVER_H_ */ diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.h b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.h new file mode 100644 index 00000000000..21cfed4832f --- /dev/null +++ b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.h @@ -0,0 +1,140 @@ +// Copyright 2021 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 DiscoveryServerSubscriber.h + * + */ + +#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSUBSCRIBER_H_ +#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSUBSCRIBER_H_ + +#include +#include +#include + +#include +#include +#include + +#include "types/HelloWorldPubSubTypes.h" +#include "common.h" + +/** + * Class used to group into a single working unit a Subscriber with a DataReader, its listener, and a TypeSupport member + * corresponding to the HelloWorld datatype + */ +class HelloWorldSubscriber +{ +public: + + HelloWorldSubscriber(); + + virtual ~HelloWorldSubscriber(); + + //! Initialize the subscriber + bool init( + const std::string& topic_name, + uint32_t max_messages, + const std::string& server_address, + unsigned short server_port, + unsigned short server_id, + TransportKind transport); + + //! RUN the subscriber until number samples are received + void run( + uint32_t number); + + //! Return the current state of execution + static bool is_stopped(); + + //! Trigger the end of execution + static void stop(); + +private: + + eprosima::fastdds::dds::DomainParticipant* participant_; + + eprosima::fastdds::dds::Subscriber* subscriber_; + + eprosima::fastdds::dds::Topic* topic_; + + eprosima::fastdds::dds::DataReader* reader_; + + eprosima::fastdds::dds::TypeSupport type_; + + /** + * Class handling discovery and dataflow events + */ + class SubListener : public eprosima::fastdds::dds::DomainParticipantListener + { + public: + + SubListener() + : matched_(0) + , samples_(0) + , max_messages_(0) + { + } + + ~SubListener() override + { + } + + //! Set the maximum number of messages to receive before exiting + void set_max_messages( + uint32_t max_messages); + + //! Callback executed when a new sample is received + void on_data_available( + eprosima::fastdds::dds::DataReader* reader) override; + + //! Callback executed when a DataWriter is matched or unmatched + void on_subscription_matched( + eprosima::fastdds::dds::DataReader* reader, + const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override; + + //! Callback executed when a DomainParticipant is discovered, dropped or removed + void on_participant_discovery( + eprosima::fastdds::dds::DomainParticipant* /*participant*/, + eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) override; + + private: + + using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; + + HelloWorld hello_; + + //! Number of DataWriters matched to the associated DataReader + int matched_; + + //! Number of samples received + uint32_t samples_; + + //! Number of messages to be received before triggering termination of execution + uint32_t max_messages_; + } + listener_; + + //! Member used for control flow purposes + static std::atomic stop_; + + //! Protects terminate condition variable + static std::mutex terminate_cv_mtx_; + + //! Waits during execution until SIGINT or max_messages_ samples are received + static std::condition_variable terminate_cv_; +}; + +#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSUBSCRIBER_H_ */ diff --git a/examples/cpp/dds/LivelinessQoS/LivelinessSubscriber.h b/examples/cpp/dds/LivelinessQoS/LivelinessSubscriber.h index 2dc110e0fe9..154decdf689 100644 --- a/examples/cpp/dds/LivelinessQoS/LivelinessSubscriber.h +++ b/examples/cpp/dds/LivelinessQoS/LivelinessSubscriber.h @@ -101,9 +101,15 @@ class LivelinessSubscriber class PartListener : public eprosima::fastdds::dds::DomainParticipantListener { + public: + virtual void on_participant_discovery( eprosima::fastdds::dds::DomainParticipant* participant, eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) override; + + private: + + using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; }; PartListener part_listener_; diff --git a/examples/cpp/rtps/Persistent/TestReaderPersistent.h b/examples/cpp/rtps/Persistent/TestReaderPersistent.h index b23b1e49399..b55f4aa9cdc 100644 --- a/examples/cpp/rtps/Persistent/TestReaderPersistent.h +++ b/examples/cpp/rtps/Persistent/TestReaderPersistent.h @@ -66,6 +66,10 @@ class TestReaderPersistent uint32_t n_received; uint32_t n_matched; + + private: + + using eprosima::fastrtps::rtps::ReaderListener::onReaderMatched; } m_listener; }; diff --git a/examples/cpp/rtps/Persistent/TestWriterPersistent.h b/examples/cpp/rtps/Persistent/TestWriterPersistent.h index 41b00ef7c6c..6ea3716369f 100644 --- a/examples/cpp/rtps/Persistent/TestWriterPersistent.h +++ b/examples/cpp/rtps/Persistent/TestWriterPersistent.h @@ -62,6 +62,10 @@ class TestWriterPersistent } int n_matched; + + private: + + using eprosima::fastrtps::rtps::WriterListener::onWriterMatched; } m_listener; }; diff --git a/examples/cpp/rtps/Registered/TestReaderRegistered.h b/examples/cpp/rtps/Registered/TestReaderRegistered.h index 207b54254da..3c1799b7654 100644 --- a/examples/cpp/rtps/Registered/TestReaderRegistered.h +++ b/examples/cpp/rtps/Registered/TestReaderRegistered.h @@ -66,6 +66,10 @@ class TestReaderRegistered uint32_t n_received; uint32_t n_matched; + + private: + + using eprosima::fastrtps::rtps::ReaderListener::onReaderMatched; } m_listener; }; diff --git a/examples/cpp/rtps/Registered/TestWriterRegistered.h b/examples/cpp/rtps/Registered/TestWriterRegistered.h index 7263ee013c1..110d176e4a4 100644 --- a/examples/cpp/rtps/Registered/TestWriterRegistered.h +++ b/examples/cpp/rtps/Registered/TestWriterRegistered.h @@ -62,6 +62,10 @@ class TestWriterRegistered } int n_matched; + + private: + + using eprosima::fastrtps::rtps::WriterListener::onWriterMatched; } m_listener; }; diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.h b/src/cpp/rtps/builtin/discovery/participant/PDPClient.h index e7053c3f1e4..6baae742c8d 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.h +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.h @@ -109,8 +109,8 @@ class PDPClient : public PDP */ void announceParticipantState( bool new_change, - bool dispose = false, - WriteParams& wparams = WriteParams::WRITE_PARAM_DEFAULT) override; + bool dispose, + WriteParams& wparams) override; /** * These methods wouldn't be needed under perfect server operation diff --git a/src/cpp/rtps/builtin/discovery/participant/timedevent/DSClientEvent.cpp b/src/cpp/rtps/builtin/discovery/participant/timedevent/DSClientEvent.cpp index 4621a6adaf4..deb44928545 100644 --- a/src/cpp/rtps/builtin/discovery/participant/timedevent/DSClientEvent.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/timedevent/DSClientEvent.cpp @@ -90,7 +90,8 @@ bool DSClientEvent::event() // This marks to announceParticipantState that the announcement is only meant for missing servers, // so it is not a periodic announcement mp_PDP->_serverPing = true; - mp_PDP->announceParticipantState(false); + WriteParams __wp = WriteParams::write_params_default(); + mp_PDP->announceParticipantState(false, false, __wp); EPROSIMA_LOG_INFO(CLIENT_PDP_THREAD, "Client " << mp_PDP->getRTPSParticipant()->getGuid() << " PDP announcement"); } diff --git a/test/blackbox/api/dds-pim/PubSubParticipant.hpp b/test/blackbox/api/dds-pim/PubSubParticipant.hpp index 180edcdeca9..7eb510fec9f 100644 --- a/test/blackbox/api/dds-pim/PubSubParticipant.hpp +++ b/test/blackbox/api/dds-pim/PubSubParticipant.hpp @@ -192,6 +192,8 @@ class PubSubParticipant private: + using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; + ParticipantListener& operator =( const ParticipantListener&) = delete; PubSubParticipant* participant_; diff --git a/test/blackbox/api/dds-pim/PubSubReader.hpp b/test/blackbox/api/dds-pim/PubSubReader.hpp index 977714c09f3..e89d8479ff4 100644 --- a/test/blackbox/api/dds-pim/PubSubReader.hpp +++ b/test/blackbox/api/dds-pim/PubSubReader.hpp @@ -142,6 +142,9 @@ class PubSubReader private: + using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; + using eprosima::fastdds::dds::DomainParticipantListener::on_publisher_discovery; + ParticipantListener& operator =( const ParticipantListener&) = delete; PubSubReader& reader_; diff --git a/test/blackbox/api/dds-pim/PubSubWriter.hpp b/test/blackbox/api/dds-pim/PubSubWriter.hpp index 4f1eab7bdd9..26b3552cbf1 100644 --- a/test/blackbox/api/dds-pim/PubSubWriter.hpp +++ b/test/blackbox/api/dds-pim/PubSubWriter.hpp @@ -156,6 +156,10 @@ class PubSubWriter private: + using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; + using eprosima::fastdds::dds::DomainParticipantListener::on_publisher_discovery; + using eprosima::fastdds::dds::DomainParticipantListener::on_subscriber_discovery; + ParticipantListener& operator =( const ParticipantListener&) = delete; diff --git a/test/blackbox/api/dds-pim/PubSubWriterReader.hpp b/test/blackbox/api/dds-pim/PubSubWriterReader.hpp index ab9b4a80d5e..c81ba1a0701 100644 --- a/test/blackbox/api/dds-pim/PubSubWriterReader.hpp +++ b/test/blackbox/api/dds-pim/PubSubWriterReader.hpp @@ -168,6 +168,10 @@ class PubSubWriterReader private: + using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; + using eprosima::fastdds::dds::DomainParticipantListener::on_publisher_discovery; + using eprosima::fastdds::dds::DomainParticipantListener::on_subscriber_discovery; + //! Mutex guarding all info collections mutable std::mutex info_mutex_; //! The discovered participants excluding the participant this listener is listening to diff --git a/test/blackbox/common/DDSBlackboxTestsBasic.cpp b/test/blackbox/common/DDSBlackboxTestsBasic.cpp index 1510051e447..32ebb797d19 100644 --- a/test/blackbox/common/DDSBlackboxTestsBasic.cpp +++ b/test/blackbox/common/DDSBlackboxTestsBasic.cpp @@ -477,8 +477,10 @@ TEST(DDSBasic, PidRelatedSampleIdentity) TEST(DDSBasic, IgnoreParticipant) { - struct IgnoringDomainParticipantListener : public DomainParticipantListener + class IgnoringDomainParticipantListener : public DomainParticipantListener { + public: + std::atomic_int num_matched{0}; std::atomic_int num_ignored{0}; @@ -505,6 +507,9 @@ TEST(DDSBasic, IgnoreParticipant) } } + private: + + using DomainParticipantListener::on_participant_discovery; }; // Set DomainParticipantFactory to create disabled entities DomainParticipantFactoryQos factory_qos; diff --git a/test/blackbox/common/DDSBlackboxTestsDataRepresentationQos.cpp b/test/blackbox/common/DDSBlackboxTestsDataRepresentationQos.cpp new file mode 100644 index 00000000000..6181f8c465d --- /dev/null +++ b/test/blackbox/common/DDSBlackboxTestsDataRepresentationQos.cpp @@ -0,0 +1,158 @@ +// 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 "BlackboxTests.hpp" + +#include +#include + +#include + +#include + +#include "PubSubReader.hpp" +#include "PubSubWriter.hpp" + +#include + +using namespace eprosima::fastdds::dds; + +#if FASTCDR_VERSION_MAJOR > 1 + +class MockHelloWorldPubSubType : public HelloWorldPubSubType +{ +public: + + bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + DataRepresentationId_t data_representation) override + { + last_data_representation = data_representation; + + return HelloWorldPubSubType::serialize(data, payload, data_representation); + } + + bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + void* data) override + { + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN); + + // Deserialize encapsulation. + deser.read_encapsulation(); + + last_encoding = deser.get_encoding_flag(); + + return HelloWorldPubSubType::deserialize(payload, data); + } + + static eprosima::fastcdr::EncodingAlgorithmFlag last_encoding; + + static DataRepresentationId_t last_data_representation; + +private: + + using HelloWorldPubSubType::serialize; +}; + +eprosima::fastcdr::EncodingAlgorithmFlag +MockHelloWorldPubSubType::last_encoding {eprosima::fastcdr::EncodingAlgorithmFlag::PL_CDR}; + +DataRepresentationId_t MockHelloWorldPubSubType::last_data_representation { XML_DATA_REPRESENTATION}; + +using DataRepresentationQosVector = std::vector; + +class DataRepresentationQosCompatibility : public ::testing::TestWithParam> +{ +}; + + +DataRepresentationQosVector EMPTY_VECTOR {}; +DataRepresentationQosVector XCDR_VECTOR {XCDR_DATA_REPRESENTATION}; +DataRepresentationQosVector XCDR2_VECTOR {XCDR2_DATA_REPRESENTATION}; +DataRepresentationQosVector BOTH_XCDR_VECTOR {XCDR_DATA_REPRESENTATION, XCDR2_DATA_REPRESENTATION}; + +TEST_P(DataRepresentationQosCompatibility, check_compatibility) +{ + PubSubWriter writer(TEST_TOPIC_NAME); + PubSubReader reader(TEST_TOPIC_NAME); + + writer.data_representation(std::get<0>(GetParam())).init(); + reader.reliability(RELIABLE_RELIABILITY_QOS).data_representation(std::get<1>(GetParam())).init(); + + ASSERT_TRUE(reader.isInitialized()); + ASSERT_TRUE(writer.isInitialized()); + + if (std::get<2>(GetParam())) + { + writer.wait_discovery(); + reader.wait_discovery(); + + auto data = default_helloworld_data_generator(); + + reader.startReception(data); + // Send data + writer.send(data); + // In this test all data should be sent. + ASSERT_TRUE(data.empty()); + // Block reader until reception finished or timeout. + reader.block_for_all(); + + MockHelloWorldPubSubType* writer_type = + dynamic_cast(writer.get_type_support().get()); + MockHelloWorldPubSubType* reader_type = + dynamic_cast(reader.get_type_support().get()); + ASSERT_EQ(std::get<3>(GetParam()), writer_type->last_data_representation); + ASSERT_EQ(std::get<4>(GetParam()), reader_type->last_encoding); + } + else + { + writer.wait_incompatible_qos(); + reader.wait_incompatible_qos(); + + ASSERT_EQ(DATAREPRESENTATION_QOS_POLICY_ID, writer.last_incompatible_qos()); + ASSERT_EQ(DATAREPRESENTATION_QOS_POLICY_ID, reader.last_incompatible_qos()); + } +} + +INSTANTIATE_TEST_SUITE_P( + DataRepresentationQos, + DataRepresentationQosCompatibility, + ::testing::Values( + std::make_tuple(EMPTY_VECTOR, EMPTY_VECTOR, true, XCDR_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR), + std::make_tuple(EMPTY_VECTOR, XCDR_VECTOR, true, XCDR_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR), + std::make_tuple(EMPTY_VECTOR, XCDR2_VECTOR, false, XCDR_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR), + std::make_tuple(EMPTY_VECTOR, BOTH_XCDR_VECTOR, true, XCDR_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR), + std::make_tuple(XCDR_VECTOR, EMPTY_VECTOR, true, XCDR_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR), + std::make_tuple(XCDR_VECTOR, XCDR_VECTOR, true, XCDR_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR), + std::make_tuple(XCDR_VECTOR, XCDR2_VECTOR, false, XCDR_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR), + std::make_tuple(XCDR_VECTOR, BOTH_XCDR_VECTOR, true, XCDR_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR), + std::make_tuple(XCDR2_VECTOR, EMPTY_VECTOR, false, XCDR2_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR2), + std::make_tuple(XCDR2_VECTOR, XCDR_VECTOR, false, XCDR2_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR2), + std::make_tuple(XCDR2_VECTOR, XCDR2_VECTOR, true, XCDR2_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR2), + std::make_tuple(XCDR2_VECTOR, BOTH_XCDR_VECTOR, true, XCDR2_DATA_REPRESENTATION, eprosima::fastcdr::PLAIN_CDR2) + )); + +#endif // FASTCDR_VERSION_MAJOR > 1 diff --git a/test/blackbox/common/DDSBlackboxTestsDiscovery.cpp b/test/blackbox/common/DDSBlackboxTestsDiscovery.cpp index d19b8f2074a..7126257e0b4 100644 --- a/test/blackbox/common/DDSBlackboxTestsDiscovery.cpp +++ b/test/blackbox/common/DDSBlackboxTestsDiscovery.cpp @@ -448,6 +448,8 @@ TEST(DDSDiscovery, ParticipantProxyPhysicalData) private: + using DomainParticipantListener::on_participant_discovery; + std::condition_variable* cv_; std::mutex* mtx_; @@ -595,6 +597,8 @@ TEST(DDSDiscovery, DDSDiscoveryDoesNotDropUDPLocator) struct CustomDomainParticipantListener : public DomainParticipantListener { + using DomainParticipantListener::on_participant_discovery; + std::mutex mtx; std::condition_variable cv; GUID_t guid; @@ -1603,3 +1607,142 @@ TEST(DDSDiscovery, WaitSetMatchedStatus) test_DDSDiscovery_WaitSetMatchedStatus(false); test_DDSDiscovery_WaitSetMatchedStatus(true); } +<<<<<<< HEAD +======= + +// Regression test for redmine issue 20409 +TEST(DDSDiscovery, DataracePDP) +{ + using namespace eprosima; + using namespace eprosima::fastdds::dds; + using namespace eprosima::fastdds::rtps; + + class CustomDomainParticipantListener : public DomainParticipantListener + { + public: + + using DomainParticipantListener::on_participant_discovery; + + CustomDomainParticipantListener() + : DomainParticipantListener() + , discovery_future(discovery_promise.get_future()) + , destruction_future(destruction_promise.get_future()) + , undiscovery_future(undiscovery_promise.get_future()) + { + } + + void on_participant_discovery( + DomainParticipant* /*participant*/, + eprosima::fastrtps::rtps::ParticipantDiscoveryInfo&& info) override + { + if (info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) + { + try + { + discovery_promise.set_value(); + } + catch (std::future_error&) + { + // do nothing + } + destruction_future.wait(); + } + else if (info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT || + info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT) + { + try + { + undiscovery_promise.set_value(); + } + catch (std::future_error&) + { + // do nothing + } + } + } + + std::promise discovery_promise; + std::future discovery_future; + + std::promise destruction_promise; + std::future destruction_future; + + std::promise undiscovery_promise; + std::future undiscovery_future; + }; + + // Disable intraprocess + auto settings = fastrtps::xmlparser::XMLProfileManager::library_settings(); + auto prev_intraprocess_delivery = settings.intraprocess_delivery; + settings.intraprocess_delivery = fastrtps::INTRAPROCESS_OFF; + fastrtps::xmlparser::XMLProfileManager::library_settings(settings); + + // DDS Domain Id + const unsigned int DOMAIN_ID = (uint32_t)GET_PID() % 230; + + // This is a non deterministic test, so we will run it several times to increase probability of data race detection + // if it exists. + const unsigned int N_ITER = 10; + unsigned int iter_idx = 0; + while (iter_idx < N_ITER) + { + iter_idx++; + + DomainParticipantQos qos; + qos.transport().use_builtin_transports = false; + auto udp_transport = std::make_shared(); + qos.transport().user_transports.push_back(udp_transport); + + // Create discoverer participant (the one where a data race on PDP might occur) + CustomDomainParticipantListener participant_listener; + DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(DOMAIN_ID, qos, + &participant_listener); + + DomainParticipantQos aux_qos; + aux_qos.transport().use_builtin_transports = false; + auto aux_udp_transport = std::make_shared(); + aux_qos.transport().user_transports.push_back(aux_udp_transport); + + // Create auxiliary participant to be discovered + aux_qos.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(1, 0); + aux_qos.wire_protocol().builtin.discovery_config.leaseDuration = Duration_t(1, 10); + DomainParticipant* aux_participant = DomainParticipantFactory::get_instance()->create_participant(DOMAIN_ID, + aux_qos); + + // Wait for discovery + participant_listener.discovery_future.wait(); + + // Shutdown auxiliary participant's network, so it will be removed after lease duration + test_UDPv4Transport::test_UDPv4Transport_ShutdownAllNetwork = true; + DomainParticipantFactory::get_instance()->delete_participant(aux_participant); + std::this_thread::sleep_for(std::chrono::milliseconds(1500)); // Wait for longer than lease duration + + try + { + // NOTE: at this point, the discoverer participant is stuck in a UDP discovery thread (unicast or multicast). + // At the same time, the events thread is stuck at PDP::remove_remote_participant (lease duration expired + // and so the discovered participant is removed), trying to acquire the callback mutex taken by the + // discovery thread. + + // If we now signal the discovery thread to continue, a data race might occur if the received + // ParticipantProxyData, which is further being processed in the discovery thread (assignRemoteEndpoints), + // gets deleted/cleared by the events thread at the same time. + // Note that a similar situation might arise in other scenarios, such as on the concurrent reception of a + // data P and data uP each on a different thread (unicast and multicast), however these are harder to + // reproduce in a regression test. + participant_listener.destruction_promise.set_value(); + } + catch (std::future_error&) + { + // do nothing + } + + participant_listener.undiscovery_future.wait(); + DomainParticipantFactory::get_instance()->delete_participant(participant); + } + + // Reestablish previous intraprocess configuration + settings.intraprocess_delivery = prev_intraprocess_delivery; + fastrtps::xmlparser::XMLProfileManager::library_settings(settings); +} +>>>>>>> 63cc242b2 (Fix hidden overloaded virtual methods (#4516)) diff --git a/test/blackbox/common/DDSBlackboxTestsFindTopic.cpp b/test/blackbox/common/DDSBlackboxTestsFindTopic.cpp index eb207896720..ce274a7aab7 100644 --- a/test/blackbox/common/DDSBlackboxTestsFindTopic.cpp +++ b/test/blackbox/common/DDSBlackboxTestsFindTopic.cpp @@ -49,8 +49,10 @@ class DDSFindTopicTest : public testing::Test /** * A dummy type support class. */ - struct TestType : public TopicDataType + class TestType : public TopicDataType { + public: + TestType() : TopicDataType() { @@ -96,6 +98,10 @@ class DDSFindTopicTest : public testing::Test return false; } + private: + + using TopicDataType::getSerializedSizeProvider; + using TopicDataType::serialize; }; public: diff --git a/test/blackbox/common/RTPSWithRegistrationReader.hpp b/test/blackbox/common/RTPSWithRegistrationReader.hpp index dc12c4c9b04..08ce30251a8 100644 --- a/test/blackbox/common/RTPSWithRegistrationReader.hpp +++ b/test/blackbox/common/RTPSWithRegistrationReader.hpp @@ -110,6 +110,8 @@ class RTPSWithRegistrationReader private: + using eprosima::fastrtps::rtps::ReaderListener::onReaderMatched; + Listener& operator =( const Listener&) = delete; diff --git a/test/blackbox/common/RTPSWithRegistrationWriter.hpp b/test/blackbox/common/RTPSWithRegistrationWriter.hpp index c24c2ca322b..358813f1116 100644 --- a/test/blackbox/common/RTPSWithRegistrationWriter.hpp +++ b/test/blackbox/common/RTPSWithRegistrationWriter.hpp @@ -97,6 +97,8 @@ class RTPSWithRegistrationWriter private: + using eprosima::fastrtps::rtps::WriterListener::onWriterMatched; + Listener& operator =( const Listener&) = delete; diff --git a/test/dds/communication/PublisherDynamic.cpp b/test/dds/communication/PublisherDynamic.cpp index b58edf411ec..a9585151827 100644 --- a/test/dds/communication/PublisherDynamic.cpp +++ b/test/dds/communication/PublisherDynamic.cpp @@ -114,6 +114,8 @@ class ParListener : public DomainParticipantListener private: + using DomainParticipantListener::on_participant_discovery; + bool exit_on_lost_liveliness_; }; diff --git a/test/dds/communication/PublisherModule.hpp b/test/dds/communication/PublisherModule.hpp index 91b04db5e54..fb144821a0a 100644 --- a/test/dds/communication/PublisherModule.hpp +++ b/test/dds/communication/PublisherModule.hpp @@ -85,6 +85,8 @@ class PublisherModule private: + using DomainParticipantListener::on_participant_discovery; + std::mutex mutex_; std::condition_variable cv_; unsigned int matched_ = 0; diff --git a/test/dds/communication/SubscriberDynamic.cpp b/test/dds/communication/SubscriberDynamic.cpp index f3276601d90..dae0f6cd866 100644 --- a/test/dds/communication/SubscriberDynamic.cpp +++ b/test/dds/communication/SubscriberDynamic.cpp @@ -150,6 +150,8 @@ class ParListener : public DomainParticipantListener private: + using DomainParticipantListener::on_participant_discovery; + std::promise is_worth_a_type_; }; diff --git a/test/dds/communication/SubscriberModule.hpp b/test/dds/communication/SubscriberModule.hpp index 9b7751452e1..e8559128440 100644 --- a/test/dds/communication/SubscriberModule.hpp +++ b/test/dds/communication/SubscriberModule.hpp @@ -92,6 +92,8 @@ class SubscriberModule private: + using DomainParticipantListener::on_participant_discovery; + std::mutex mutex_; std::condition_variable cv_; const uint32_t publishers_ = 0; diff --git a/test/dds/communication/security/PublisherModule.hpp b/test/dds/communication/security/PublisherModule.hpp new file mode 100644 index 00000000000..fb144821a0a --- /dev/null +++ b/test/dds/communication/security/PublisherModule.hpp @@ -0,0 +1,108 @@ +// Copyright 2021 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 Publisher.hpp + */ + +#ifndef TEST_DDS_COMMUNICATION_PUBLISHERMODULE_HPP +#define TEST_DDS_COMMUNICATION_PUBLISHERMODULE_HPP + +#include +#include +#include +#include + +#include "types/FixedSizedPubSubTypes.h" +#include "types/HelloWorldPubSubTypes.h" + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +class PublisherModule + : public DomainParticipantListener +{ +public: + + PublisherModule( + bool exit_on_lost_liveliness, + bool fixed_type = false, + bool zero_copy = false) + : exit_on_lost_liveliness_(exit_on_lost_liveliness) + , fixed_type_(zero_copy || fixed_type) // If zero copy active, fixed type is required + , zero_copy_(zero_copy) + { + } + + ~PublisherModule(); + + void on_publication_matched( + DataWriter* /*publisher*/, + const PublicationMatchedStatus& info) override; + + /** + * This method is called when a new Participant is discovered, or a previously discovered participant + * changes its QOS or is removed. + * @param p Pointer to the Participant + * @param info DiscoveryInfo. + */ + void on_participant_discovery( + DomainParticipant* /*participant*/, + fastrtps::rtps::ParticipantDiscoveryInfo&& info) override; + +#if HAVE_SECURITY + void onParticipantAuthentication( + DomainParticipant* participant, + fastrtps::rtps::ParticipantAuthenticationInfo&& info) override; +#endif // if HAVE_SECURITY + + bool init( + uint32_t seed, + const std::string& magic); + + void wait_discovery( + uint32_t how_many); + + void run( + uint32_t samples, + uint32_t loops = 0, + uint32_t interval = 250); + +private: + + using DomainParticipantListener::on_participant_discovery; + + std::mutex mutex_; + std::condition_variable cv_; + unsigned int matched_ = 0; + bool exit_on_lost_liveliness_ = false; + bool fixed_type_ = false; + bool zero_copy_ = false; + bool run_ = true; + DomainParticipant* participant_ = nullptr; + TypeSupport type_; + Publisher* publisher_ = nullptr; + DataWriter* writer_ = nullptr; + Topic* topic_ = nullptr; +}; + +} // dds +} // fastdds +} // eprosima + +#endif // TEST_DDS_COMMUNICATION_PUBLISHERMODULE_HPP diff --git a/test/dds/communication/security/SubscriberModule.hpp b/test/dds/communication/security/SubscriberModule.hpp new file mode 100644 index 00000000000..980c6c5acc6 --- /dev/null +++ b/test/dds/communication/security/SubscriberModule.hpp @@ -0,0 +1,116 @@ +// Copyright 2021 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 SubscriberModule.hpp + * + */ +#ifndef TEST_COMMUNICATION_SUBSCRIBER_HPP +#define TEST_COMMUNICATION_SUBSCRIBER_HPP + +#include +#include +#include +#include + +#include "types/FixedSizedPubSubTypes.h" +#include "types/HelloWorldPubSubTypes.h" + +#include +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +class SubscriberModule + : public DomainParticipantListener +{ +public: + + SubscriberModule( + const uint32_t publishers, + const uint32_t max_number_samples, + bool fixed_type = false, + bool zero_copy = false, + bool die_on_data_received = false) + : publishers_(publishers) + , max_number_samples_(max_number_samples) + , fixed_type_(zero_copy || fixed_type) // If zero copy active, fixed type is required + , zero_copy_(zero_copy) + , die_on_data_received_(die_on_data_received) + { + } + + ~SubscriberModule(); + + void on_participant_discovery( + DomainParticipant* /*participant*/, + fastrtps::rtps::ParticipantDiscoveryInfo&& info) override; + +#if HAVE_SECURITY + void onParticipantAuthentication( + DomainParticipant* /*participant*/, + fastrtps::rtps::ParticipantAuthenticationInfo&& info) override; +#endif // if HAVE_SECURITY + + void on_subscription_matched( + DataReader* /*reader*/, + const SubscriptionMatchedStatus& info) override; + + void on_data_available( + DataReader* reader) override; + + void on_liveliness_changed( + DataReader* /*reader*/, + const eprosima::fastdds::dds::LivelinessChangedStatus& status) override; + + bool init( + uint32_t seed, + const std::string& magic); + + bool run( + bool notexit); + + bool run_for( + bool notexit, + const std::chrono::milliseconds& timeout); + +private: + + using DomainParticipantListener::on_participant_discovery; + + std::mutex mutex_; + std::condition_variable cv_; + const uint32_t publishers_ = 0; + const uint32_t max_number_samples_ = 0; + std::map number_samples_; + bool fixed_type_ = false; + bool zero_copy_ = false; + bool run_ = true; + DomainParticipant* participant_ = nullptr; + TypeSupport type_; + Subscriber* subscriber_ = nullptr; + DataReader* reader_ = nullptr; + Topic* topic_ = nullptr; + bool die_on_data_received_ = false; +}; + +} // dds +} // fastdds +} // eprosima + +#endif // TEST_COMMUNICATION_SUBSCRIBER_HPP diff --git a/test/dds/discovery/ParticipantModule.hpp b/test/dds/discovery/ParticipantModule.hpp index dc7d190bef3..53073911104 100644 --- a/test/dds/discovery/ParticipantModule.hpp +++ b/test/dds/discovery/ParticipantModule.hpp @@ -52,6 +52,8 @@ class ParticipantModule : public DomainParticipantListener private: + using DomainParticipantListener::on_participant_discovery; + unsigned int matched_ = 0; DomainParticipant* participant_ = nullptr; DiscoveryProtocol_t discovery_protocol_; diff --git a/test/performance/latency/LatencyTestTypes.hpp b/test/performance/latency/LatencyTestTypes.hpp index b288cd8b6fa..a675110fcbf 100644 --- a/test/performance/latency/LatencyTestTypes.hpp +++ b/test/performance/latency/LatencyTestTypes.hpp @@ -142,6 +142,10 @@ class LatencyDataType : public eprosima::fastdds::dds::TopicDataType // Name static const std::string type_name_; + +private: + + using eprosima::fastrtps::TopicDataType::is_plain; }; enum TESTCOMMAND : uint32_t diff --git a/test/performance/throughput/ThroughputTypes.hpp b/test/performance/throughput/ThroughputTypes.hpp index d62abd894ae..1ff9f06a2ac 100644 --- a/test/performance/throughput/ThroughputTypes.hpp +++ b/test/performance/throughput/ThroughputTypes.hpp @@ -179,6 +179,10 @@ class ThroughputDataType : public eprosima::fastrtps::TopicDataType // Name static const std::string type_name_; + +private: + + using eprosima::fastrtps::TopicDataType::is_plain; }; enum e_Command : uint32_t diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index e5077ffbb4e..c3741815c60 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -219,6 +219,9 @@ class LoanableTopicDataTypeMock : public TopicDataType return true; } +private: + + using TopicDataType::is_plain; }; class BarType @@ -2403,6 +2406,8 @@ class CustomListener2 : public DomainParticipantListener { public: + using DomainParticipantListener::on_participant_discovery; + CustomListener2() : future_(promise_.get_future()) { diff --git a/test/unittest/dds/publisher/DataWriterTests.cpp b/test/unittest/dds/publisher/DataWriterTests.cpp index 6d49620d227..224c09be10b 100644 --- a/test/unittest/dds/publisher/DataWriterTests.cpp +++ b/test/unittest/dds/publisher/DataWriterTests.cpp @@ -346,6 +346,10 @@ TEST(DataWriterTests, get_guid) fastrtps::rtps::GUID_t guid; std::mutex mutex; std::condition_variable cv; + + private: + + using DomainParticipantListener::on_publisher_discovery; } discovery_listener; @@ -1276,6 +1280,7 @@ class LoanableTypeSupport : public TopicDataType public: typedef LoanableType type; + using TopicDataType::is_plain; LoanableTypeSupport() : TopicDataType() @@ -1432,6 +1437,8 @@ class LoanableTypeSupportTesting : public LoanableTypeSupport { public: + using LoanableTypeSupport::is_plain; + bool is_plain_result = true; bool construct_sample_result = true; diff --git a/test/unittest/dds/publisher/PublisherTests.cpp b/test/unittest/dds/publisher/PublisherTests.cpp index d1671125c29..253a41e3780 100644 --- a/test/unittest/dds/publisher/PublisherTests.cpp +++ b/test/unittest/dds/publisher/PublisherTests.cpp @@ -161,6 +161,9 @@ class LoanableTopicDataTypeMock : public TopicDataType return true; } +private: + + using TopicDataType::is_plain; }; diff --git a/test/unittest/dds/status/ListenerTests.cpp b/test/unittest/dds/status/ListenerTests.cpp index ed4c3e962b1..61afbb40dcf 100644 --- a/test/unittest/dds/status/ListenerTests.cpp +++ b/test/unittest/dds/status/ListenerTests.cpp @@ -535,6 +535,10 @@ class TopicDataTypeMock : public TopicDataType return true; } +private: + + using TopicDataType::getSerializedSizeProvider; + using TopicDataType::serialize; }; class UserListeners : public ::testing::Test diff --git a/test/unittest/dds/subscriber/DataReaderHistoryTests.cpp b/test/unittest/dds/subscriber/DataReaderHistoryTests.cpp index fdc09b2f87d..5efd99bf2b6 100644 --- a/test/unittest/dds/subscriber/DataReaderHistoryTests.cpp +++ b/test/unittest/dds/subscriber/DataReaderHistoryTests.cpp @@ -21,14 +21,21 @@ class TestType : public TopicDataType void* data, eprosima::fastrtps::rtps::SerializedPayload_t* payload)); + MOCK_METHOD3(serialize, bool( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + DataRepresentationId_t data_representation)); + MOCK_METHOD2(deserialize, bool( eprosima::fastrtps::rtps::SerializedPayload_t* payload, void* data)); + MOCK_METHOD2(getSerializedSizeProvider, std::function ( + void* data, DataRepresentationId_t data_representation)); + MOCK_METHOD1(getSerializedSizeProvider, std::function ( void* data)); - MOCK_METHOD0(createData, void* ()); MOCK_METHOD1(deleteData, void( diff --git a/test/unittest/dds/subscriber/DataReaderTests.cpp b/test/unittest/dds/subscriber/DataReaderTests.cpp index abbc7a82762..fc397cce942 100644 --- a/test/unittest/dds/subscriber/DataReaderTests.cpp +++ b/test/unittest/dds/subscriber/DataReaderTests.cpp @@ -588,6 +588,10 @@ TEST_F(DataReaderTests, get_guid) GUID_t guid; std::mutex mutex; std::condition_variable cv; + + private: + + using DomainParticipantListener::on_subscriber_discovery; } discovery_listener; diff --git a/test/unittest/dds/subscriber/FooBoundedTypeSupport.hpp b/test/unittest/dds/subscriber/FooBoundedTypeSupport.hpp index ec83066fa40..3f3cdb4a113 100644 --- a/test/unittest/dds/subscriber/FooBoundedTypeSupport.hpp +++ b/test/unittest/dds/subscriber/FooBoundedTypeSupport.hpp @@ -144,6 +144,9 @@ class FooBoundedTypeSupport : public TopicDataType return false; } +private: + + using TopicDataType::is_plain; }; } // namespace dds diff --git a/test/unittest/dds/subscriber/FooTypeSupport.hpp b/test/unittest/dds/subscriber/FooTypeSupport.hpp index c85faf50c98..bcf70414eb7 100644 --- a/test/unittest/dds/subscriber/FooTypeSupport.hpp +++ b/test/unittest/dds/subscriber/FooTypeSupport.hpp @@ -169,6 +169,9 @@ class FooTypeSupport : public TopicDataType return true; } +private: + + using TopicDataType::is_plain; }; } // namespace dds diff --git a/test/unittest/dds/topic/TopicTests.cpp b/test/unittest/dds/topic/TopicTests.cpp index a5bb4c4aa9f..7f004619090 100644 --- a/test/unittest/dds/topic/TopicTests.cpp +++ b/test/unittest/dds/topic/TopicTests.cpp @@ -124,6 +124,10 @@ class TopicDataTypeMock : public TopicDataType return true; } +private: + + using TopicDataType::getSerializedSizeProvider; + using TopicDataType::serialize; }; TEST(TopicTests, ChangeTopicQos) diff --git a/test/unittest/statistics/dds/StatisticsDomainParticipantStatusQueryableTests.cpp b/test/unittest/statistics/dds/StatisticsDomainParticipantStatusQueryableTests.cpp new file mode 100644 index 00000000000..09558402292 --- /dev/null +++ b/test/unittest/statistics/dds/StatisticsDomainParticipantStatusQueryableTests.cpp @@ -0,0 +1,349 @@ +// 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 +#include +#include +#include +#include +#include +#include + +#include "../../logging/mock/MockConsumer.h" + +using eprosima::fastrtps::types::ReturnCode_t; + +constexpr const char* TEST_TOPIC = "test_topic"; + +class TopicDataTypeMock : public eprosima::fastdds::dds::TopicDataType +{ +public: + + TopicDataTypeMock() + : TopicDataType() + { + m_typeSize = 4u; + setName("footype"); + } + + bool serialize( + void* /*data*/, + eprosima::fastrtps::rtps::SerializedPayload_t* /*payload*/) override + { + return true; + } + + bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* /*payload*/, + void* /*data*/) override + { + return true; + } + + std::function getSerializedSizeProvider( + void* /*data*/) override + { + return []()->uint32_t + { + return 0; + }; + } + + void* createData() override + { + return nullptr; + } + + void deleteData( + void* /*data*/) override + { + } + + bool getKey( + void* /*data*/, + eprosima::fastrtps::rtps::InstanceHandle_t* /*ihandle*/, + bool /*force_md5*/) override + { + return true; + } + + void clearName() + { + setName(""); + } + +private: + + using eprosima::fastdds::dds::TopicDataType::getSerializedSizeProvider; + using eprosima::fastdds::dds::TopicDataType::serialize; +}; + +namespace eprosima { +namespace fastdds { +namespace statistics { +namespace dds { + +class StatisticsDomainParticipantStatusQueryableTests : public ::testing::Test +{ +public: + + void helper_block_for_at_least_entries( + uint32_t amount) + { + mock_consumer_->wait_for_at_least_entries(amount); + } + + eprosima::fastdds::dds::MockConsumer* mock_consumer_; + +}; + +class DomainParticipantImplTest : public DomainParticipantImpl +{ +public: + + eprosima::fastdds::dds::Publisher* get_builtin_publisher() const + { + return builtin_publisher_; + } + + PublisherImpl* get_builtin_publisher_impl() const + { + return builtin_publisher_impl_; + } + + bool monitoring_status( + fastrtps::rtps::GUID_t guid, + uint32_t status_id, + fastdds::statistics::rtps::DDSEntityStatus*& status) + { + return get_monitoring_status(guid, status_id, status); + } + +}; + +class DomainParticipantTest : public eprosima::fastdds::dds::DomainParticipant +{ +public: + + eprosima::fastdds::dds::DomainParticipantImpl* get_impl() const + { + return impl_; + } + +}; + +TEST_F(StatisticsDomainParticipantStatusQueryableTests, istatus_queryable_get_incompatible_qos) +{ +#ifdef FASTDDS_STATISTICS + // Create DomainParticipant + eprosima::fastdds::dds::DomainParticipant* participant = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()-> + create_participant(0, eprosima::fastdds::dds::PARTICIPANT_QOS_DEFAULT); + ASSERT_NE(participant, nullptr); + + DomainParticipant* statistics_participant = DomainParticipant::narrow(participant); + ASSERT_NE(statistics_participant, nullptr); + + DomainParticipantTest* participant_test = static_cast(participant); + ASSERT_NE(nullptr, participant_test); + DomainParticipantImplTest* statistics_participant_impl_test = static_cast( + participant_test->get_impl()); + + ASSERT_NE(nullptr, statistics_participant_impl_test); + + fastdds::dds::TypeSupport type(new TopicDataTypeMock()); + type.register_type(statistics_participant); + + auto publisher = participant_test->create_publisher(fastdds::dds::PUBLISHER_QOS_DEFAULT); + auto topic = participant_test->create_topic(TEST_TOPIC, "footype", fastdds::dds::TOPIC_QOS_DEFAULT); + + //! Create DataWriters + EXPECT_CALL(*publisher, create_datawriter_mock()).WillRepeatedly(testing::Return(false)); + EXPECT_CALL(*statistics_participant_impl_test, delete_topic_mock()).WillRepeatedly(testing::Return(false)); + auto dw1 = publisher->create_datawriter(topic, fastdds::dds::DATAWRITER_QOS_DEFAULT); + auto dw2 = publisher->create_datawriter(topic, fastdds::dds::DATAWRITER_QOS_DEFAULT); + + //! Insert some QoS incompatibilities + auto pub_impl = publisher->get_impl(); + auto statistics_pub_impl = static_cast(pub_impl); + + statistics_pub_impl->insert_policy_violation(dw1->guid(), fastdds::dds::RELIABILITY_QOS_POLICY_ID); + statistics_pub_impl->insert_policy_violation(dw2->guid(), fastdds::dds::RELIABILITY_QOS_POLICY_ID); + + fastdds::statistics::rtps::DDSEntityStatus* incomp_qos_status_dw_1, * incomp_qos_status_dw_2; + incomp_qos_status_dw_1 = new fastdds::statistics::rtps::DDSEntityStatus; + incomp_qos_status_dw_2 = new fastdds::statistics::rtps::DDSEntityStatus; + ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw1->guid(), 2, incomp_qos_status_dw_1)); + ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw2->guid(), 2, incomp_qos_status_dw_2)); + + //! Expect incompatibilities + ASSERT_EQ(1u, static_cast(incomp_qos_status_dw_1)->total_count); + ASSERT_EQ(1u, static_cast(incomp_qos_status_dw_2)->total_count); + ASSERT_EQ(1u, incomp_qos_status_dw_1->policies[fastdds::dds::RELIABILITY_QOS_POLICY_ID].count); + ASSERT_EQ(1u, incomp_qos_status_dw_2->policies[fastdds::dds::RELIABILITY_QOS_POLICY_ID].count); + + statistics_pub_impl->delete_datawriters(); + topic->get_impl()->dereference(); + topic->get_impl()->dereference(); + statistics_participant->delete_topic(topic); + statistics_participant->delete_publisher(publisher); + statistics_participant->delete_contained_entities(); + + delete incomp_qos_status_dw_1; + delete incomp_qos_status_dw_2; + +#endif // FASTDDS_STATISTICS +} + +TEST_F(StatisticsDomainParticipantStatusQueryableTests, istatus_queryable_get_liveliness_lost_status) +{ +#ifdef FASTDDS_STATISTICS + // Create DomainParticipant + eprosima::fastdds::dds::DomainParticipant* participant = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()-> + create_participant(0, eprosima::fastdds::dds::PARTICIPANT_QOS_DEFAULT); + ASSERT_NE(participant, nullptr); + + DomainParticipant* statistics_participant = DomainParticipant::narrow(participant); + ASSERT_NE(statistics_participant, nullptr); + + DomainParticipantTest* participant_test = static_cast(participant); + ASSERT_NE(nullptr, participant_test); + DomainParticipantImplTest* statistics_participant_impl_test = static_cast( + participant_test->get_impl()); + + ASSERT_NE(nullptr, statistics_participant_impl_test); + + fastdds::dds::TypeSupport type(new TopicDataTypeMock()); + type.register_type(statistics_participant); + + auto publisher = participant_test->create_publisher(fastdds::dds::PUBLISHER_QOS_DEFAULT); + auto topic = participant_test->create_topic(TEST_TOPIC, "footype", fastdds::dds::TOPIC_QOS_DEFAULT); + + //! Create DataWriters + EXPECT_CALL(*publisher, create_datawriter_mock()).WillRepeatedly(testing::Return(false)); + EXPECT_CALL(*statistics_participant_impl_test, delete_topic_mock()).WillRepeatedly(testing::Return(false)); + auto dw1 = publisher->create_datawriter(topic, fastdds::dds::DATAWRITER_QOS_DEFAULT); + auto dw2 = publisher->create_datawriter(topic, fastdds::dds::DATAWRITER_QOS_DEFAULT); + + //! Insert some QoS incompatibilities + auto pub_impl = publisher->get_impl(); + auto statistics_pub_impl = static_cast(pub_impl); + + statistics_pub_impl->insert_policy_violation(dw1->guid(), fastdds::dds::LIVELINESS_QOS_POLICY_ID); + statistics_pub_impl->insert_policy_violation(dw2->guid(), fastdds::dds::LIVELINESS_QOS_POLICY_ID); + + rtps::DDSEntityStatus* liv_lost_status_dw_1, * liv_lost_status_dw_2; + liv_lost_status_dw_1 = new fastdds::statistics::rtps::DDSEntityStatus; + liv_lost_status_dw_2 = new fastdds::statistics::rtps::DDSEntityStatus; + ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw1->guid(), 4, liv_lost_status_dw_1)); + ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw2->guid(), 4, liv_lost_status_dw_2)); + + //! Expect incompatibilities + ASSERT_EQ(1, static_cast(liv_lost_status_dw_1)->total_count); + ASSERT_EQ(1, static_cast(liv_lost_status_dw_2)->total_count); + + statistics_pub_impl->delete_datawriters(); + topic->get_impl()->dereference(); + topic->get_impl()->dereference(); + statistics_participant->delete_topic(topic); + statistics_participant->delete_publisher(publisher); + statistics_participant->delete_contained_entities(); + + delete liv_lost_status_dw_1; + delete liv_lost_status_dw_2; + +#endif // FASTDDS_STATISTICS +} + +TEST_F(StatisticsDomainParticipantStatusQueryableTests, istatus_queryable_get_deadline_missed_status) +{ +#ifdef FASTDDS_STATISTICS + // Create DomainParticipant + eprosima::fastdds::dds::DomainParticipant* participant = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()-> + create_participant(0, eprosima::fastdds::dds::PARTICIPANT_QOS_DEFAULT); + ASSERT_NE(participant, nullptr); + + DomainParticipant* statistics_participant = DomainParticipant::narrow(participant); + ASSERT_NE(statistics_participant, nullptr); + + DomainParticipantTest* participant_test = static_cast(participant); + ASSERT_NE(nullptr, participant_test); + DomainParticipantImplTest* statistics_participant_impl_test = static_cast( + participant_test->get_impl()); + + ASSERT_NE(nullptr, statistics_participant_impl_test); + + fastdds::dds::TypeSupport type(new TopicDataTypeMock()); + type.register_type(statistics_participant); + + auto publisher = participant_test->create_publisher(fastdds::dds::PUBLISHER_QOS_DEFAULT); + auto topic = participant_test->create_topic(TEST_TOPIC, "footype", fastdds::dds::TOPIC_QOS_DEFAULT); + + //! Create DataWriters + EXPECT_CALL(*publisher, create_datawriter_mock()).WillRepeatedly(testing::Return(false)); + EXPECT_CALL(*statistics_participant_impl_test, delete_topic_mock()).WillRepeatedly(testing::Return(false)); + auto dw1 = publisher->create_datawriter(topic, fastdds::dds::DATAWRITER_QOS_DEFAULT); + auto dw2 = publisher->create_datawriter(topic, fastdds::dds::DATAWRITER_QOS_DEFAULT); + + //! Insert some QoS incompatibilities + auto pub_impl = publisher->get_impl(); + auto statistics_pub_impl = static_cast(pub_impl); + + statistics_pub_impl->insert_policy_violation(dw1->guid(), fastdds::dds::DEADLINE_QOS_POLICY_ID); + statistics_pub_impl->insert_policy_violation(dw2->guid(), fastdds::dds::DEADLINE_QOS_POLICY_ID); + + rtps::DDSEntityStatus* deadline_missed_status_dw_1, * deadline_missed_status_dw_2; + deadline_missed_status_dw_1 = new rtps::DDSEntityStatus; + deadline_missed_status_dw_2 = new rtps::DDSEntityStatus; + ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw1->guid(), 6, deadline_missed_status_dw_1)); + ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw2->guid(), 6, deadline_missed_status_dw_2)); + + //! Expect incompatibilities + ASSERT_EQ(1u, static_cast(deadline_missed_status_dw_1)->total_count); + ASSERT_EQ(1u, static_cast(deadline_missed_status_dw_2)->total_count); + + statistics_pub_impl->delete_datawriters(); + topic->get_impl()->dereference(); + topic->get_impl()->dereference(); + statistics_participant->delete_topic(topic); + statistics_participant->delete_publisher(publisher); + statistics_participant->delete_contained_entities(); + + delete deadline_missed_status_dw_1; + delete deadline_missed_status_dw_2; + +#endif // FASTDDS_STATISTICS +} + +} // dds +} // statistics +} // fastdds +} // eprosima + +int main( + int argc, + char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/unittest/statistics/dds/StatisticsDomainParticipantTests.cpp b/test/unittest/statistics/dds/StatisticsDomainParticipantTests.cpp index 50fc6ef1239..aaa34188199 100644 --- a/test/unittest/statistics/dds/StatisticsDomainParticipantTests.cpp +++ b/test/unittest/statistics/dds/StatisticsDomainParticipantTests.cpp @@ -130,6 +130,10 @@ class TopicDataTypeMock : public eprosima::fastdds::dds::TopicDataType return true; } +private: + + using eprosima::fastdds::dds::TopicDataType::getSerializedSizeProvider; + using eprosima::fastdds::dds::TopicDataType::serialize; }; class StatisticsDomainParticipantTests : public ::testing::Test