From 1eee2f25153879aaa7fd545796b628e3e62a706c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20L=C3=BCtkebohle?= Date: Tue, 5 May 2020 14:48:27 +0200 Subject: [PATCH] Initialize service timestamps to 0 and test. (#642) Signed-off-by: Luetkebohle Ingo (CR/AEX3) --- rcl/src/rcl/client.c | 2 ++ rcl/test/rcl/test_service.cpp | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/rcl/src/rcl/client.c b/rcl/src/rcl/client.c index ea2d2dd18..9bf70dc4a 100644 --- a/rcl/src/rcl/client.c +++ b/rcl/src/rcl/client.c @@ -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) { diff --git a/rcl/test/rcl/test_service.cpp b/rcl/test/rcl/test_service.cpp index b141ae6a8..7a2db37c6 100644 --- a/rcl/test/rcl/test_service.cpp +++ b/rcl/test/rcl/test_service.cpp @@ -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); @@ -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); @@ -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