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

ROS clock storage initially set to zero #283

Merged
merged 1 commit into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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