Improve wait sets test coverage. (#683)
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
This commit is contained in:
parent
a4aa379d35
commit
b254630a6a
1 changed files with 68 additions and 0 deletions
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
#include "rcutils/logging_macros.h"
|
#include "rcutils/logging_macros.h"
|
||||||
|
|
||||||
|
#include "./allocator_testing_utils.h"
|
||||||
|
|
||||||
#ifdef RMW_IMPLEMENTATION
|
#ifdef RMW_IMPLEMENTATION
|
||||||
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
|
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
|
||||||
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
|
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
|
||||||
|
@ -36,7 +38,11 @@
|
||||||
# define CLASSNAME(NAME, SUFFIX) NAME
|
# define CLASSNAME(NAME, SUFFIX) NAME
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
#define TOLERANCE RCL_MS_TO_NS(6)
|
#define TOLERANCE RCL_MS_TO_NS(6)
|
||||||
|
#else
|
||||||
|
#define TOLERANCE RCL_MS_TO_NS(15)
|
||||||
|
#endif
|
||||||
|
|
||||||
class CLASSNAME (WaitSetTestFixture, RMW_IMPLEMENTATION) : public ::testing::Test
|
class CLASSNAME (WaitSetTestFixture, RMW_IMPLEMENTATION) : public ::testing::Test
|
||||||
{
|
{
|
||||||
|
@ -86,6 +92,25 @@ TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), wait_set_is_valid) {
|
||||||
EXPECT_FALSE(rcl_wait_set_is_valid(&wait_set));
|
EXPECT_FALSE(rcl_wait_set_is_valid(&wait_set));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), test_failed_resize) {
|
||||||
|
// Initialize a wait set with a subscription and then resize it to zero.
|
||||||
|
rcl_allocator_t allocator = get_failing_allocator();
|
||||||
|
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||||
|
set_failing_allocator_is_failing(allocator, false);
|
||||||
|
rcl_ret_t ret =
|
||||||
|
rcl_wait_set_init(&wait_set, 1, 1, 1, 1, 1, 0, context_ptr, allocator);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
|
||||||
|
set_failing_allocator_is_failing(allocator, true);
|
||||||
|
ret = rcl_wait_set_resize(&wait_set, 0, 1, 0, 0, 0, 0);
|
||||||
|
EXPECT_EQ(RCL_RET_BAD_ALLOC, ret);
|
||||||
|
rcl_reset_error();
|
||||||
|
|
||||||
|
set_failing_allocator_is_failing(allocator, false);
|
||||||
|
ret = rcl_wait_set_fini(&wait_set);
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), test_resize_to_zero) {
|
TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), test_resize_to_zero) {
|
||||||
// Initialize a wait set with a subscription and then resize it to zero.
|
// Initialize a wait set with a subscription and then resize it to zero.
|
||||||
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||||
|
@ -257,6 +282,49 @@ TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), zero_timeout_triggered
|
||||||
EXPECT_LE(diff, TOLERANCE);
|
EXPECT_LE(diff, TOLERANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test rcl_wait with a timeout value and an overrun timer
|
||||||
|
TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), zero_timeout_overrun_timer) {
|
||||||
|
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||||
|
rcl_ret_t ret =
|
||||||
|
rcl_wait_set_init(&wait_set, 0, 0, 1, 0, 0, 0, context_ptr, rcl_get_default_allocator());
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
ret = rcl_wait_set_fini(&wait_set);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
});
|
||||||
|
rcl_clock_t clock;
|
||||||
|
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||||
|
ret = rcl_clock_init(RCL_STEADY_TIME, &clock, &allocator);
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
ret = rcl_clock_fini(&clock);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
});
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
|
||||||
|
rcl_timer_t timer = rcl_get_zero_initialized_timer();
|
||||||
|
ret = rcl_timer_init(
|
||||||
|
&timer, &clock, this->context_ptr, 0, nullptr, rcl_get_default_allocator());
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
|
||||||
|
{
|
||||||
|
ret = rcl_timer_fini(&timer);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
});
|
||||||
|
ret = rcl_wait_set_add_timer(&wait_set, &timer, NULL);
|
||||||
|
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
|
||||||
|
// Time spent during wait should be negligible, definitely less than the given timeout
|
||||||
|
std::chrono::steady_clock::time_point before_sc = std::chrono::steady_clock::now();
|
||||||
|
ret = rcl_wait(&wait_set, RCL_MS_TO_NS(100));
|
||||||
|
std::chrono::steady_clock::time_point after_sc = std::chrono::steady_clock::now();
|
||||||
|
// We don't expect a timeout here (since the guard condition had already been triggered)
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
int64_t diff = std::chrono::duration_cast<std::chrono::nanoseconds>(after_sc - before_sc).count();
|
||||||
|
EXPECT_LE(diff, RCL_MS_TO_NS(50));
|
||||||
|
}
|
||||||
|
|
||||||
// Check that a canceled timer doesn't wake up rcl_wait
|
// Check that a canceled timer doesn't wake up rcl_wait
|
||||||
TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), canceled_timer) {
|
TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), canceled_timer) {
|
||||||
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue