Skip to content

Commit

Permalink
ROS clock storage initially set to zero (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
sloretz authored Aug 21, 2018
1 parent adc0190 commit 3aebe9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rcl/src/rcl/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ rcl_ros_clock_init(
rcl_init_generic_clock(clock);
clock->data = allocator->allocate(sizeof(rcl_ros_clock_storage_t), allocator->state);
rcl_ros_clock_storage_t * storage = (rcl_ros_clock_storage_t *)clock->data;
// 0 is a special value meaning time has not been set
atomic_init(&(storage->current_time), 0);
storage->active = false;
clock->get_now = rcl_get_ros_time;
clock->type = RCL_ROS_TIME;
Expand Down
14 changes: 14 additions & 0 deletions rcl/test/rcl/test_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <thread>

#include "osrf_testing_tools_cpp/memory_tools/memory_tools.hpp"
#include "osrf_testing_tools_cpp/scope_exit.hpp"
#include "rcl/error_handling.h"
#include "rcl/time.h"

Expand Down Expand Up @@ -175,6 +176,19 @@ TEST_F(CLASSNAME(TestTimeFixture, RMW_IMPLEMENTATION), test_rcl_init_for_clock_a
EXPECT_EQ(retval, RCL_RET_OK) << rcl_get_error_string_safe();
}

TEST_F(CLASSNAME(TestTimeFixture, RMW_IMPLEMENTATION), test_ros_clock_initially_zero) {
rcl_allocator_t allocator = rcl_get_default_allocator();
rcl_clock_t ros_clock;
ASSERT_EQ(RCL_RET_OK, rcl_ros_clock_init(&ros_clock, &allocator)) << rcl_get_error_string_safe();
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
EXPECT_EQ(RCL_RET_OK, rcl_clock_fini(&ros_clock)) << rcl_get_error_string_safe();
});
ASSERT_EQ(RCL_RET_OK, rcl_enable_ros_time_override(&ros_clock)) << rcl_get_error_string_safe();
rcl_time_point_value_t query_now = 5;
ASSERT_EQ(RCL_RET_OK, rcl_clock_get_now(&ros_clock, &query_now)) << rcl_get_error_string_safe();
EXPECT_EQ(0, query_now);
}

TEST(CLASSNAME(rcl_time, RMW_IMPLEMENTATION), clock_validation) {
ASSERT_FALSE(rcl_clock_valid(NULL));
rcl_clock_t uninitialized;
Expand Down

0 comments on commit 3aebe9f

Please sign in to comment.