Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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/include/rcl/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ rcl_timer_reset(rcl_timer_t * timer);
* \param[inout] timer handle to the timer object
* \return pointer to the allocator, or `NULL` if an error occurred
*/
RCL_PUBLIC
RCL_WARN_UNUSED
const rcl_allocator_t *
rcl_timer_get_allocator(const rcl_timer_t * timer);

Expand Down
48 changes: 48 additions & 0 deletions rcl/test/rcl/test_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,46 @@ class TestTimerFixture : public ::testing::Test
}
};

static uint8_t times_called = 0;
static void callback_function(rcl_timer_t * timer, int64_t last_call)
{
(void) timer;
(void) last_call;
times_called++;
}
static rcl_timer_callback_t timer_callback_test = &callback_function;

class TestPreInitTimer : public TestTimerFixture
{
public:
rcl_clock_t clock;
rcl_allocator_t allocator;
rcl_timer_t timer;

void SetUp() override
{
TestTimerFixture::SetUp();
rcl_ret_t ret;
allocator = rcl_get_default_allocator();
timer = rcl_get_zero_initialized_timer();
ASSERT_EQ(
RCL_RET_OK,
rcl_clock_init(RCL_ROS_TIME, &clock, &allocator)) << rcl_get_error_string().str;

ret = rcl_timer_init(
&timer, &clock, this->context_ptr, RCL_S_TO_NS(1), timer_callback_test,
rcl_get_default_allocator());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

void TearDown() override
{
EXPECT_EQ(RCL_RET_OK, rcl_timer_fini(&timer)) << rcl_get_error_string().str;
EXPECT_EQ(RCL_RET_OK, rcl_clock_fini(&clock)) << rcl_get_error_string().str;
TestTimerFixture::TearDown();
}
};

TEST_F(TestTimerFixture, test_two_timers) {
rcl_ret_t ret;

Expand Down Expand Up @@ -512,3 +552,11 @@ TEST_F(TestTimerFixture, test_ros_time_wakes_wait) {
EXPECT_TRUE(timer_was_ready);
EXPECT_LT(finish - start, std::chrono::milliseconds(100));
}

TEST_F(TestPreInitTimer, test_timer_get_allocator) {
const rcl_allocator_t * allocator_returned;
allocator_returned = rcl_timer_get_allocator(&timer);
EXPECT_TRUE(rcutils_allocator_is_valid(allocator_returned));

EXPECT_EQ(NULL, rcl_timer_get_allocator(nullptr));
}