Skip to content

Commit

Permalink
Improve rcl clock test coverage.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Jun 12, 2020
1 parent 7723308 commit 97d3414
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 150 deletions.
16 changes: 8 additions & 8 deletions rcl/src/rcl/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,8 @@ rcl_ros_clock_fini(
return RCL_RET_ERROR;
}
rcl_clock_generic_fini(clock);
if (!clock->data) {
RCL_SET_ERROR_MSG("clock data invalid");
return RCL_RET_ERROR;
}
clock->allocator.deallocate((rcl_ros_clock_storage_t *)clock->data, clock->allocator.state);
clock->allocator.deallocate(clock->data, clock->allocator.state);
clock->data = NULL;
return RCL_RET_OK;
}

Expand Down Expand Up @@ -366,6 +363,10 @@ rcl_set_ros_time_override(
}
rcl_time_jump_t time_jump;
rcl_ros_clock_storage_t * storage = (rcl_ros_clock_storage_t *)clock->data;
if (!storage) {
RCL_SET_ERROR_MSG("Clock storage is not initialized, cannot enable override.");
return RCL_RET_ERROR;
}
if (storage->active) {
time_jump.clock_change = RCL_ROS_TIME_NO_CHANGE;
rcl_time_point_value_t current_time;
Expand Down Expand Up @@ -453,19 +454,18 @@ rcl_clock_remove_jump_callback(
}

// Shrink size of the callback array
if (clock->num_jump_callbacks == 1) {
if (clock->num_jump_callbacks-- == 1) {
clock->allocator.deallocate(clock->jump_callbacks, clock->allocator.state);
clock->jump_callbacks = NULL;
} else {
rcl_jump_callback_info_t * callbacks = clock->allocator.reallocate(
clock->jump_callbacks, sizeof(rcl_jump_callback_info_t) * (clock->num_jump_callbacks - 1),
clock->jump_callbacks, sizeof(rcl_jump_callback_info_t) * clock->num_jump_callbacks,
clock->allocator.state);
if (NULL == callbacks) {
RCL_SET_ERROR_MSG("Failed to shrink jump callbacks");
return RCL_RET_BAD_ALLOC;
}
clock->jump_callbacks = callbacks;
}
--(clock->num_jump_callbacks);
return RCL_RET_OK;
}
Loading

0 comments on commit 97d3414

Please sign in to comment.