Skip to content

Commit 643f6ec

Browse files
authored
Message info with timestamps support in rcl (#619)
* Zero-initialize message_info prior to taking Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * Added test for timestamp presence Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * move message_info test to a new test file Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * Add conditional timestamp test to normal subscriber test Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * Remove dedicated timestamp test Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * Use rmw_time_point_value_t instead of rmw_time_t Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * Use rcutils for cross-platform compatibility. Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * Style fix. Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * More style fix. Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * test fastrtps_dynamic properly; also cmake linter error Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * Expect timestamps on cyclonedds as well Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]> * Distinguish received timestamp support. Signed-off-by: Luetkebohle Ingo (CR/AEX3) <[email protected]>
1 parent b343368 commit 643f6ec

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

rcl/src/rcl/subscription.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ rcl_take(
263263
// If message_info is NULL, use a place holder which can be discarded.
264264
rmw_message_info_t dummy_message_info;
265265
rmw_message_info_t * message_info_local = message_info ? message_info : &dummy_message_info;
266+
*message_info_local = rmw_get_zero_initialized_message_info();
266267
// Call rmw_take_with_info.
267268
bool taken = false;
268269
rmw_ret_t ret = rmw_take_with_info(
@@ -298,6 +299,7 @@ rcl_take_serialized_message(
298299
// If message_info is NULL, use a place holder which can be discarded.
299300
rmw_message_info_t dummy_message_info;
300301
rmw_message_info_t * message_info_local = message_info ? message_info : &dummy_message_info;
302+
*message_info_local = rmw_get_zero_initialized_message_info();
301303
// Call rmw_take_with_info.
302304
bool taken = false;
303305
rmw_ret_t ret = rmw_take_serialized_message_with_info(
@@ -335,6 +337,7 @@ rcl_take_loaned_message(
335337
// If message_info is NULL, use a place holder which can be discarded.
336338
rmw_message_info_t dummy_message_info;
337339
rmw_message_info_t * message_info_local = message_info ? message_info : &dummy_message_info;
340+
*message_info_local = rmw_get_zero_initialized_message_info();
338341
// Call rmw_take_with_info.
339342
bool taken = false;
340343
rmw_ret_t ret = rmw_take_loaned_message_with_info(

rcl/test/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ function(test_target_function)
205205
LIBRARIES ${PROJECT_NAME}
206206
AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" "test_msgs"
207207
)
208+
if(rmw_implementation STREQUAL "rmw_fastrtps_cpp" OR
209+
rmw_implementation STREQUAL "rmw_fastrtps_dynamic_cpp")
210+
message(STATUS "Enabling message timestamp test for ${rmw_implementation}")
211+
target_compile_definitions(test_subscription${target_suffix}
212+
PUBLIC "RMW_TIMESTAMPS_SUPPORTED=1" "RMW_RECEIVED_TIMESTAMP_SUPPORTED=1")
213+
else()
214+
if(rmw_implementation STREQUAL "rmw_cyclonedds_cpp")
215+
message(STATUS "Enabling only source timestamp test for ${rmw_implementation}")
216+
target_compile_definitions(test_subscription${target_suffix}
217+
PUBLIC "RMW_TIMESTAMPS_SUPPORTED=1")
218+
else()
219+
message(STATUS "Disabling message timestamp test for ${rmw_implementation}")
220+
endif()
221+
endif()
208222

209223
rcl_add_custom_gtest(test_events${target_suffix}
210224
SRCS rcl/test_events.cpp

rcl/test/rcl/test_subscription.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription
179179
// probably using the count_subscriptions busy wait mechanism
180180
// until then we will sleep for a short period of time
181181
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
182+
#ifdef RMW_TIMESTAMPS_SUPPORTED
183+
rcl_time_point_value_t pre_publish_time;
184+
EXPECT_EQ(
185+
RCUTILS_RET_OK,
186+
rcutils_system_time_now(&pre_publish_time)) << " could not get system time failed";
187+
#endif
182188
{
183189
test_msgs__msg__BasicTypes msg;
184190
test_msgs__msg__BasicTypes__init(&msg);
@@ -197,9 +203,25 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription
197203
{
198204
test_msgs__msg__BasicTypes__fini(&msg);
199205
});
200-
ret = rcl_take(&subscription, &msg, nullptr, nullptr);
206+
rmw_message_info_t message_info = rmw_get_zero_initialized_message_info();
207+
ret = rcl_take(&subscription, &msg, &message_info, nullptr);
201208
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
202209
ASSERT_EQ(42, msg.int64_value);
210+
#ifdef RMW_TIMESTAMPS_SUPPORTED
211+
EXPECT_NE(0u, message_info.source_timestamp);
212+
EXPECT_TRUE(pre_publish_time <= message_info.source_timestamp) <<
213+
pre_publish_time << " > " << message_info.source_timestamp;
214+
#ifdef RMW_RECEIVED_TIMESTAMP_SUPPORTED
215+
EXPECT_NE(0u, message_info.received_timestamp);
216+
EXPECT_TRUE(pre_publish_time <= message_info.received_timestamp);
217+
EXPECT_TRUE(message_info.source_timestamp <= message_info.received_timestamp);
218+
#else
219+
EXPECT_EQ(0u, message_info.received_timestamp);
220+
#endif
221+
#else
222+
EXPECT_EQ(0u, message_info.source_timestamp);
223+
EXPECT_EQ(0u, message_info.received_timestamp);
224+
#endif
203225
}
204226
}
205227

0 commit comments

Comments
 (0)