From df36a12543faeff0c8efe85695cfd0ecdb266bc1 Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Mon, 17 Nov 2025 13:03:10 +0100 Subject: [PATCH 1/4] Fix flakytest due to dirty memory Signed-off-by: Emilio Cuesta --- .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp index 63dfcf064..304283715 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -208,7 +208,7 @@ void test_local_communication( template void test_original_writer_forwarding( - DdsRouterConfiguration ddsrouter_configuration) + DdsRouterConfiguration ddsrouter_configuration, int case_number) { INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); @@ -234,36 +234,45 @@ void test_original_writer_forwarding( router.start(); // CASE 1: Send message without original_writer_param, should be set to writers guid - sent_msg.index(++samples_sent); - ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK); - // Watiting for the message to be received - while (samples_received.load() < 1) + if (case_number == 1) { + sent_msg.index(++samples_sent); + ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK); + // Watiting for the message to be received + while (samples_received.load() < 1) + { + } + ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); } - ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); // CASE 2: Send message with original_writer_param set to some value, value must be kept - sent_msg.index(++samples_sent); - eprosima::fastdds::rtps::WriteParams params_with_og_writer; - eprosima::fastdds::rtps::GUID_t guid({}, 0x12345678); - params_with_og_writer.original_writer_info().original_writer_guid(guid); - ASSERT_EQ(publisher.publish_with_params(sent_msg, params_with_og_writer), eprosima::fastdds::dds::RETCODE_OK); - // Waiting for the message to be received - while (samples_received.load() < 2) + if (case_number == 2) { + sent_msg.index(++samples_sent); + eprosima::fastdds::rtps::WriteParams params_with_og_writer; + eprosima::fastdds::rtps::GUID_t guid({}, 0x12345678); + params_with_og_writer.original_writer_info().original_writer_guid(guid); + ASSERT_EQ(publisher.publish_with_params(sent_msg, params_with_og_writer), eprosima::fastdds::dds::RETCODE_OK); + // Waiting for the message to be received + while (samples_received.load() < 1) + { + } + ASSERT_EQ(subscriber.original_writer_guid(), guid); } - ASSERT_EQ(subscriber.original_writer_guid(), guid); // CASE 3: Send message with original_writer_param set to unknown, should be set to other value - sent_msg.index(++samples_sent); - eprosima::fastdds::rtps::WriteParams params; - params.original_writer_info(eprosima::fastdds::rtps::OriginalWriterInfo::unknown()); - ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK); - // Waiting for the message to be received - while (samples_received.load() < 3) + if (case_number == 3) { + sent_msg.index(++samples_sent); + eprosima::fastdds::rtps::WriteParams params; + params.original_writer_info(eprosima::fastdds::rtps::OriginalWriterInfo::unknown()); + ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK); + // Waiting for the message to be received + while (samples_received.load() < 1) + { + } + ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); } - ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); router.stop(); } @@ -391,7 +400,11 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynami TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding) { test::test_original_writer_forwarding( - test::dds_test_simple_configuration()); + test::dds_test_simple_configuration(), 1); + test::test_original_writer_forwarding( + test::dds_test_simple_configuration(), 2); + test::test_original_writer_forwarding( + test::dds_test_simple_configuration(), 3); } int main( From bb92bb5a59475072ee395d82ae344053ed5cca3f Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Mon, 17 Nov 2025 14:08:41 +0100 Subject: [PATCH 2/4] uncrustify Signed-off-by: Emilio Cuesta --- .../test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp index 304283715..5357b60d7 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -208,7 +208,8 @@ void test_local_communication( template void test_original_writer_forwarding( - DdsRouterConfiguration ddsrouter_configuration, int case_number) + DdsRouterConfiguration ddsrouter_configuration, + int case_number) { INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); From 9b816939bb9d48abc0a7fe071183b6c4a0761285 Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Tue, 18 Nov 2025 10:44:42 +0100 Subject: [PATCH 3/4] Separating og writer test into three specific tests Signed-off-by: Emilio Cuesta --- .../ddsrouter_core/dds/local/CMakeLists.txt | 4 +- .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 170 +++++++++++++----- 2 files changed, 127 insertions(+), 47 deletions(-) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt index cfc405722..9332e0f0f 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt @@ -38,7 +38,9 @@ set(TEST_LIST end_to_end_local_communication_high_throughput end_to_end_local_communication_transient_local end_to_end_local_communication_transient_local_disable_dynamic_discovery, - end_to_end_local_communication_original_writer_forwarding) + end_to_end_local_communication_original_writer_forwarding_unset, + end_to_end_local_communication_original_writer_forwarding_populated, + end_to_end_local_communication_original_writer_forwarding_unknown) set(TEST_NEEDED_SOURCES ) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp index 5357b60d7..a8fc1216f 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -206,10 +206,13 @@ void test_local_communication( router.stop(); } +/** + * This test checks that, when the original writer parameter is not set by a writer, + * the router still sets it to the original writer's GUID when forwarding the message. + */ template -void test_original_writer_forwarding( - DdsRouterConfiguration ddsrouter_configuration, - int case_number) +void test_original_writer_forwarding_unset( + DdsRouterConfiguration ddsrouter_configuration) { INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); @@ -234,46 +237,105 @@ void test_original_writer_forwarding( DdsRouter router(ddsrouter_configuration); router.start(); - // CASE 1: Send message without original_writer_param, should be set to writers guid - if (case_number == 1) - { - sent_msg.index(++samples_sent); - ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK); - // Watiting for the message to be received - while (samples_received.load() < 1) - { - } - ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); - } + // CASE: Send message without original_writer_param, it should be set to the original writers guid + // in the router either way + sent_msg.index(++samples_sent); + ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK); + // Watiting for the message to be received + while (samples_received.load() < 1); + + ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); + + router.stop(); +} - // CASE 2: Send message with original_writer_param set to some value, value must be kept - if (case_number == 2) +/** + * This test checks that, when the original writer parameter is populated by a writer and + * is not equal to unknown, the router keeps that value when forwarding the message. + */ +template +void test_original_writer_forwarding_populated( + DdsRouterConfiguration ddsrouter_configuration) +{ + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + uint32_t samples_sent = 0; + std::atomic samples_received(0); + + MsgStruct sent_msg; + MsgStructType type; + std::string msg_str; + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; + sent_msg.message(msg_str); + // Create DDS Publisher in domain 0 + TestPublisher publisher(type.is_compute_key_provided); + + ASSERT_TRUE(publisher.init(0)); + + // Create DDS Subscriber in domain 1 + TestSubscriber subscriber(type.is_compute_key_provided, true); + ASSERT_TRUE(subscriber.init(1, &sent_msg, &samples_received)); + + // Create DdsRouter entity + DdsRouter router(ddsrouter_configuration); + router.start(); + + // CASE: Send message with original_writer_param set to some value distinct to unknown, value must be kept + sent_msg.index(++samples_sent); + eprosima::fastdds::rtps::WriteParams params_with_og_writer; + eprosima::fastdds::rtps::GUID_t guid({}, 0x12345678); + params_with_og_writer.original_writer_info().original_writer_guid(guid); + ASSERT_EQ(publisher.publish_with_params(sent_msg, params_with_og_writer), eprosima::fastdds::dds::RETCODE_OK); + // Waiting for the message to be received + while (samples_received.load() < 1) { - sent_msg.index(++samples_sent); - eprosima::fastdds::rtps::WriteParams params_with_og_writer; - eprosima::fastdds::rtps::GUID_t guid({}, 0x12345678); - params_with_og_writer.original_writer_info().original_writer_guid(guid); - ASSERT_EQ(publisher.publish_with_params(sent_msg, params_with_og_writer), eprosima::fastdds::dds::RETCODE_OK); - // Waiting for the message to be received - while (samples_received.load() < 1) - { - } - ASSERT_EQ(subscriber.original_writer_guid(), guid); } + ASSERT_EQ(subscriber.original_writer_guid(), guid); + + router.stop(); +} - // CASE 3: Send message with original_writer_param set to unknown, should be set to other value - if (case_number == 3) +/** + * This test checks that, when the original writer parameter is populated by a writer and + * is equal to unknown, the router populates it with the original writer's GUID when forwarding the message. + */ +template +void test_original_writer_forwarding_unknown( + DdsRouterConfiguration ddsrouter_configuration) +{ + INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0); + + uint32_t samples_sent = 0; + std::atomic samples_received(0); + + MsgStruct sent_msg; + MsgStructType type; + std::string msg_str; + msg_str += "Testing DdsRouter Blackbox Local Communication ..."; + sent_msg.message(msg_str); + // Create DDS Publisher in domain 0 + TestPublisher publisher(type.is_compute_key_provided); + + ASSERT_TRUE(publisher.init(0)); + + // Create DDS Subscriber in domain 1 + TestSubscriber subscriber(type.is_compute_key_provided, true); + ASSERT_TRUE(subscriber.init(1, &sent_msg, &samples_received)); + + // Create DdsRouter entity + DdsRouter router(ddsrouter_configuration); + router.start(); + + // CASE: Send message with original_writer_param set to unknown, should be set to other value + sent_msg.index(++samples_sent); + eprosima::fastdds::rtps::WriteParams params; + params.original_writer_info(eprosima::fastdds::rtps::OriginalWriterInfo::unknown()); + ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK); + // Waiting for the message to be received + while (samples_received.load() < 1) { - sent_msg.index(++samples_sent); - eprosima::fastdds::rtps::WriteParams params; - params.original_writer_info(eprosima::fastdds::rtps::OriginalWriterInfo::unknown()); - ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK); - // Waiting for the message to be received - while (samples_received.load() < 1) - { - } - ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); } + ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid()); router.stop(); } @@ -395,17 +457,33 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynami } /** - * Test original writer forwarding in HelloWorld topic between two DDS participants created in different domains, - * by using a router with two Simple Participants at each domain. + * This test checks that, when the original writer parameter is not set by a writer, + * the router still sets it to the original writer's GUID when forwarding the message. */ -TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding) +TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_unset) { - test::test_original_writer_forwarding( - test::dds_test_simple_configuration(), 1); - test::test_original_writer_forwarding( - test::dds_test_simple_configuration(), 2); - test::test_original_writer_forwarding( - test::dds_test_simple_configuration(), 3); + test::test_original_writer_forwarding_unset( + test::dds_test_simple_configuration()); +} + +/** + * This test checks that, when the original writer parameter is populated by a writer and + * is not equal to unknown, the router keeps that value when forwarding the message. + */ +TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_populated) +{ + test::test_original_writer_forwarding_populated( + test::dds_test_simple_configuration()); +} + +/** + * This test checks that, when the original writer parameter is populated by a writer and + * is equal to unknown, the router populates it with the original writer's GUID when forwarding the message. + */ +TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding_unknown) +{ + test::test_original_writer_forwarding_unknown( + test::dds_test_simple_configuration()); } int main( From 2eb958e9be8e694d0d9c548722367c33fcd0b74f Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Tue, 18 Nov 2025 10:52:33 +0100 Subject: [PATCH 4/4] uncrustify Signed-off-by: Emilio Cuesta --- .../test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp index a8fc1216f..f61c954a0 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -242,7 +242,9 @@ void test_original_writer_forwarding_unset( sent_msg.index(++samples_sent); ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK); // Watiting for the message to be received - while (samples_received.load() < 1); + while (samples_received.load() < 1) + { + } ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());