-
Notifications
You must be signed in to change notification settings - Fork 181
Improve wait sets test coverage. #683
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,14 +29,20 @@ | |
|
|
||
| #include "rcutils/logging_macros.h" | ||
|
|
||
| #include "./allocator_testing_utils.h" | ||
|
|
||
| #ifdef RMW_IMPLEMENTATION | ||
| # define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX | ||
| # define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX) | ||
| #else | ||
| # define CLASSNAME(NAME, SUFFIX) NAME | ||
| #endif | ||
|
|
||
| #ifndef _WIN32 | ||
| #define TOLERANCE RCL_MS_TO_NS(6) | ||
| #else | ||
| #define TOLERANCE RCL_MS_TO_NS(15) | ||
| #endif | ||
|
|
||
| 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)); | ||
| } | ||
|
|
||
| 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) { | ||
| // 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(); | ||
|
|
@@ -257,6 +282,50 @@ TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), zero_timeout_triggered | |
| EXPECT_LE(diff, TOLERANCE); | ||
| } | ||
|
|
||
| // Test rcl_wait with a negative timeout value (blocking ferver) 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. | ||
|
||
| int64_t timeout = -1; | ||
| std::chrono::steady_clock::time_point before_sc = std::chrono::steady_clock::now(); | ||
| ret = rcl_wait(&wait_set, timeout); | ||
| 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, TOLERANCE); | ||
| } | ||
|
|
||
| // Check that a canceled timer doesn't wake up rcl_wait | ||
| TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), canceled_timer) { | ||
| rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See e7ce68a.