Skip to content

Commit f5bca80

Browse files
Add blackbox tests for original_writer_info forwarding in ddspipe (#525)
* Refs #23573, add blackbox tests for original writer info in ddspipe Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Refs #23573, applying changes and uncrustify Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Refs #23573, applying las change Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Fix infinite loop on original_writer test Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> * Regulating GUID access by using a mutex in original_writer_tests Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com> --------- Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
1 parent 4f70d05 commit f5bca80

3 files changed

Lines changed: 107 additions & 1 deletion

File tree

ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ set(TEST_LIST
3737
end_to_end_local_communication_high_size
3838
end_to_end_local_communication_high_throughput
3939
end_to_end_local_communication_transient_local
40-
end_to_end_local_communication_transient_local_disable_dynamic_discovery)
40+
end_to_end_local_communication_transient_local_disable_dynamic_discovery,
41+
end_to_end_local_communication_original_writer_forwarding)
4142

4243
set(TEST_NEEDED_SOURCES
4344
)

ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,68 @@ void test_local_communication(
206206
router.stop();
207207
}
208208

209+
template <class MsgStruct, class MsgStructType>
210+
void test_original_writer_forwarding(
211+
DdsRouterConfiguration ddsrouter_configuration)
212+
{
213+
INSTANTIATE_LOG_TESTER(eprosima::utils::Log::Kind::Error, 0, 0);
214+
215+
uint32_t samples_sent = 0;
216+
std::atomic<uint32_t> samples_received(0);
217+
218+
MsgStruct sent_msg;
219+
MsgStructType type;
220+
std::string msg_str;
221+
msg_str += "Testing DdsRouter Blackbox Local Communication ...";
222+
sent_msg.message(msg_str);
223+
// Create DDS Publisher in domain 0
224+
TestPublisher<MsgStruct> publisher(type.is_compute_key_provided);
225+
226+
ASSERT_TRUE(publisher.init(0));
227+
228+
// Create DDS Subscriber in domain 1
229+
TestSubscriber<MsgStruct> subscriber(type.is_compute_key_provided, true);
230+
ASSERT_TRUE(subscriber.init(1, &sent_msg, &samples_received));
231+
232+
// Create DdsRouter entity
233+
DdsRouter router(ddsrouter_configuration);
234+
router.start();
235+
236+
// CASE 1: Send message without original_writer_param, should be set to writers guid
237+
sent_msg.index(++samples_sent);
238+
ASSERT_EQ(publisher.publish(sent_msg), eprosima::fastdds::dds::RETCODE_OK);
239+
// Watiting for the message to be received
240+
while (samples_received.load() < 1)
241+
{
242+
}
243+
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
244+
245+
// CASE 2: Send message with original_writer_param set to some value, value must be kept
246+
sent_msg.index(++samples_sent);
247+
eprosima::fastdds::rtps::WriteParams params_with_og_writer;
248+
eprosima::fastdds::rtps::GUID_t guid({}, 0x12345678);
249+
params_with_og_writer.original_writer_info().original_writer_guid(guid);
250+
ASSERT_EQ(publisher.publish_with_params(sent_msg, params_with_og_writer), eprosima::fastdds::dds::RETCODE_OK);
251+
// Waiting for the message to be received
252+
while (samples_received.load() < 2)
253+
{
254+
}
255+
ASSERT_EQ(subscriber.original_writer_guid(), guid);
256+
257+
// CASE 3: Send message with original_writer_param set to unknown, should be set to other value
258+
sent_msg.index(++samples_sent);
259+
eprosima::fastdds::rtps::WriteParams params;
260+
params.original_writer_info(eprosima::fastdds::rtps::OriginalWriterInfo::unknown());
261+
ASSERT_EQ(publisher.publish_with_params(sent_msg, params), eprosima::fastdds::dds::RETCODE_OK);
262+
// Waiting for the message to be received
263+
while (samples_received.load() < 3)
264+
{
265+
}
266+
ASSERT_EQ(subscriber.original_writer_guid(), publisher.original_writer_guid());
267+
268+
router.stop();
269+
}
270+
209271
} /* namespace test */
210272

211273
/**
@@ -322,6 +384,16 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynami
322384
true);
323385
}
324386

387+
/**
388+
* Test original writer forwarding in HelloWorld topic between two DDS participants created in different domains,
389+
* by using a router with two Simple Participants at each domain.
390+
*/
391+
TEST(DDSTestLocal, end_to_end_local_communication_original_writer_forwarding)
392+
{
393+
test::test_original_writer_forwarding<HelloWorld, HelloWorldPubSubType>(
394+
test::dds_test_simple_configuration());
395+
}
396+
325397
int main(
326398
int argc,
327399
char** argv)

ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/test_participants.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ class TestPublisher
152152
return writer_->write(&hello_);
153153
}
154154

155+
//! Publish a sample with parameters
156+
eprosima::fastdds::dds::ReturnCode_t publish_with_params(
157+
MsgStruct msg,
158+
eprosima::fastdds::rtps::WriteParams params)
159+
{
160+
hello_.index(msg.index());
161+
hello_.message(msg.message());
162+
return writer_->write(&hello_, params);
163+
}
164+
155165
//! Dispose instance
156166
eprosima::fastdds::dds::ReturnCode_t dispose_key(
157167
MsgStruct msg);
@@ -162,6 +172,11 @@ class TestPublisher
162172
listener_.wait_discovery(n_subscribers);
163173
}
164174

175+
eprosima::fastdds::rtps::GUID_t original_writer_guid() const
176+
{
177+
return writer_->guid();
178+
}
179+
165180
private:
166181

167182
MsgStruct hello_;
@@ -357,6 +372,13 @@ class TestSubscriber
357372
return listener_.n_key_disposed;
358373
}
359374

375+
eprosima::fastdds::rtps::GUID_t original_writer_guid()
376+
{
377+
std::lock_guard<std::mutex> lock(listener_.original_writer_guid_mtx);
378+
eprosima::fastdds::rtps::GUID_t guid = listener_.original_writer_guid;
379+
return guid;
380+
}
381+
360382
private:
361383

362384
eprosima::fastdds::dds::DomainParticipant* participant_;
@@ -424,6 +446,11 @@ class TestSubscriber
424446
{
425447
n_key_disposed++;
426448
}
449+
450+
{
451+
std::lock_guard<std::mutex> lock(original_writer_guid_mtx);
452+
original_writer_guid = info.original_writer_info.original_writer_guid();
453+
}
427454
}
428455
}
429456

@@ -445,6 +472,12 @@ class TestSubscriber
445472
//! Placeholder where received data is stored
446473
MsgStruct msg_received;
447474

475+
//! Placeholder where original writer GUID is stored
476+
eprosima::fastdds::rtps::GUID_t original_writer_guid;
477+
478+
//! Protects original_writer_guid
479+
std::mutex original_writer_guid_mtx;
480+
448481
std::atomic<std::uint32_t> n_key_disposed;
449482

450483
//! Reference to the sample sent by the publisher

0 commit comments

Comments
 (0)