Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message info with timestamps support in rcl #619

Merged
merged 12 commits into from
Apr 23, 2020
3 changes: 3 additions & 0 deletions rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ rcl_take(
// If message_info is NULL, use a place holder which can be discarded.
rmw_message_info_t dummy_message_info;
rmw_message_info_t * message_info_local = message_info ? message_info : &dummy_message_info;
*message_info_local = rmw_get_zero_initialized_message_info();
// Call rmw_take_with_info.
bool taken = false;
rmw_ret_t ret = rmw_take_with_info(
Expand Down Expand Up @@ -298,6 +299,7 @@ rcl_take_serialized_message(
// If message_info is NULL, use a place holder which can be discarded.
rmw_message_info_t dummy_message_info;
rmw_message_info_t * message_info_local = message_info ? message_info : &dummy_message_info;
*message_info_local = rmw_get_zero_initialized_message_info();
// Call rmw_take_with_info.
bool taken = false;
rmw_ret_t ret = rmw_take_serialized_message_with_info(
Expand Down Expand Up @@ -335,6 +337,7 @@ rcl_take_loaned_message(
// If message_info is NULL, use a place holder which can be discarded.
rmw_message_info_t dummy_message_info;
rmw_message_info_t * message_info_local = message_info ? message_info : &dummy_message_info;
*message_info_local = rmw_get_zero_initialized_message_info();
// Call rmw_take_with_info.
bool taken = false;
rmw_ret_t ret = rmw_take_loaned_message_with_info(
Expand Down
6 changes: 6 additions & 0 deletions rcl/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ function(test_target_function)
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "osrf_testing_tools_cpp" "test_msgs"
)
if(rmw_implementation STREQUAL "rmw_fastrtps_cpp")
message(STATUS "Enabling message timestamp test for ${rmw_implementation}")
target_compile_definitions(test_subscription${target_suffix} PUBLIC "RMW_TIMESTAMPS_SUPPORTED=1")
else()
message(STATUS "Disabling message timestamp test for ${rmw_implementation}")
endif()

iluetkeb marked this conversation as resolved.
Show resolved Hide resolved
rcl_add_custom_gtest(test_events${target_suffix}
SRCS rcl/test_events.cpp
Expand Down
18 changes: 17 additions & 1 deletion rcl/test/rcl/test_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription
// probably using the count_subscriptions busy wait mechanism
// until then we will sleep for a short period of time
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
#ifdef RMW_TIMESTAMPS_SUPPORTED
rcl_time_point_value_t pre_publish_time;
EXPECT_EQ(0, rcutils_system_time_now(&pre_publish_time)) << " could not get system time failed";
iluetkeb marked this conversation as resolved.
Show resolved Hide resolved
#endif
{
test_msgs__msg__BasicTypes msg;
test_msgs__msg__BasicTypes__init(&msg);
Expand All @@ -197,9 +201,21 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription
{
test_msgs__msg__BasicTypes__fini(&msg);
});
ret = rcl_take(&subscription, &msg, nullptr, nullptr);
rmw_message_info_t message_info = rmw_get_zero_initialized_message_info();
ret = rcl_take(&subscription, &msg, &message_info, nullptr);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ASSERT_EQ(42, msg.int64_value);
#ifdef RMW_TIMESTAMPS_SUPPORTED
EXPECT_NE(0u, message_info.source_timestamp);
EXPECT_TRUE(pre_publish_time <= message_info.source_timestamp) <<
pre_publish_time << " > " << message_info.source_timestamp;
EXPECT_NE(0u, message_info.received_timestamp);
EXPECT_TRUE(pre_publish_time <= message_info.received_timestamp);
EXPECT_TRUE(message_info.source_timestamp <= message_info.received_timestamp);
#else
EXPECT_EQ(0u, message_info.source_timestamp);
EXPECT_EQ(0u, message_info.received_timestamp);
#endif
iluetkeb marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down