Skip to content

Commit

Permalink
Initialize service timestamps to 0 and test. (#642)
Browse files Browse the repository at this point in the history
Signed-off-by: Luetkebohle Ingo (CR/AEX3) <ingo.luetkebohle@de.bosch.com>
  • Loading branch information
iluetkeb authored May 5, 2020
1 parent 47501d1 commit 1eee2f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions rcl/src/rcl/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ rcl_take_response_with_info(
RCL_CHECK_ARGUMENT_FOR_NULL(ros_response, RCL_RET_INVALID_ARGUMENT);

bool taken = false;
request_header->source_timestamp = 0;
request_header->received_timestamp = 0;
if (rmw_take_response(
client->impl->rmw_handle, request_header, ros_response, &taken) != RMW_RET_OK)
{
Expand Down
22 changes: 20 additions & 2 deletions rcl/test/rcl/test_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ TEST_F(CLASSNAME(TestServiceFixture, RMW_IMPLEMENTATION), test_service_nominal)
client_request.uint8_value = 1;
client_request.uint32_value = 2;
int64_t sequence_number;
rcutils_time_point_value_t start_timestamp;
// take timestamp before sending request
EXPECT_EQ(RCUTILS_RET_OK, rcutils_system_time_now(&start_timestamp));
ret = rcl_send_request(&client, &client_request, &sequence_number);
EXPECT_EQ(sequence_number, 1);
test_msgs__srv__BasicTypes_Request__fini(&client_request);
Expand Down Expand Up @@ -211,8 +214,22 @@ TEST_F(CLASSNAME(TestServiceFixture, RMW_IMPLEMENTATION), test_service_nominal)

EXPECT_EQ(1, service_request.uint8_value);
EXPECT_EQ(2UL, service_request.uint32_value);
#ifdef RMW_TIMESTAMPS_SUPPORTED
EXPECT_GE(header.source_timestamp, start_timestamp);
#ifdef RMW_RECEIVED_TIMESTAMP_SUPPORTED
EXPECT_GE(header.received_timestamp, start_timestamp);
EXPECT_GE(header.received_timestamp, header.source_timestamp);
#else
EXPECT_EQ(0u, header.received_timestamp);
#endif
#else
EXPECT_EQ(0u, header.source_timestamp);
EXPECT_EQ(0u, header.received_timestamp);
#endif
// Simulate a response callback by summing the request and send the response..
service_response.uint64_value = service_request.uint8_value + service_request.uint32_value;
// take new timestamp before sending response
EXPECT_EQ(RCUTILS_RET_OK, rcutils_system_time_now(&start_timestamp));
ret = rcl_send_response(&service, &header.request_id, &service_response);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
test_msgs__srv__BasicTypes_Request__fini(&service_request);
Expand All @@ -229,9 +246,10 @@ TEST_F(CLASSNAME(TestServiceFixture, RMW_IMPLEMENTATION), test_service_nominal)
EXPECT_EQ(client_response.uint64_value, 3ULL);
EXPECT_EQ(header.request_id.sequence_number, 1);
#ifdef RMW_TIMESTAMPS_SUPPORTED
EXPECT_NE(0u, header.source_timestamp);
EXPECT_GE(header.source_timestamp, start_timestamp);
#ifdef RMW_RECEIVED_TIMESTAMP_SUPPORTED
EXPECT_NE(0u, header.received_timestamp);
EXPECT_GE(header.received_timestamp, start_timestamp);
EXPECT_GE(header.received_timestamp, header.source_timestamp);
#else
EXPECT_EQ(0u, header.received_timestamp);
#endif
Expand Down

0 comments on commit 1eee2f2

Please sign in to comment.