Skip to content

Commit 5dbb9f0

Browse files
committed
Refs #23573, add blackbox tests for original writer info in ddspipe
Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
1 parent 4f70d05 commit 5dbb9f0

3 files changed

Lines changed: 104 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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,71 @@ void test_local_communication(
206206
router.stop();
207207
}
208208

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

211276
/**
@@ -322,6 +387,16 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynami
322387
true);
323388
}
324389

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

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ 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+
163+
164+
return writer_->write(&hello_, params);
165+
}
166+
155167
//! Dispose instance
156168
eprosima::fastdds::dds::ReturnCode_t dispose_key(
157169
MsgStruct msg);
@@ -162,6 +174,11 @@ class TestPublisher
162174
listener_.wait_discovery(n_subscribers);
163175
}
164176

177+
eprosima::fastdds::rtps::GUID_t original_writer_guid() const
178+
{
179+
return writer_->guid();
180+
}
181+
165182
private:
166183

167184
MsgStruct hello_;
@@ -357,6 +374,11 @@ class TestSubscriber
357374
return listener_.n_key_disposed;
358375
}
359376

377+
eprosima::fastdds::rtps::GUID_t original_writer_guid() const
378+
{
379+
return listener_.original_writer_guid;
380+
}
381+
360382
private:
361383

362384
eprosima::fastdds::dds::DomainParticipant* participant_;
@@ -424,6 +446,8 @@ class TestSubscriber
424446
{
425447
n_key_disposed++;
426448
}
449+
450+
original_writer_guid = info.original_writer_info.original_writer_guid();
427451
}
428452
}
429453

@@ -445,6 +469,9 @@ class TestSubscriber
445469
//! Placeholder where received data is stored
446470
MsgStruct msg_received;
447471

472+
//! Placeholder where original writer GUID is stored
473+
eprosima::fastdds::rtps::GUID_t original_writer_guid;
474+
448475
std::atomic<std::uint32_t> n_key_disposed;
449476

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

0 commit comments

Comments
 (0)