Merge pull request #36 from ros2/resize_to_zero
Add fix and regression test for resize to zero bug
This commit is contained in:
commit
6a1ca6ef6d
3 changed files with 67 additions and 1 deletions
|
@ -293,6 +293,7 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al
|
||||||
return RCL_RET_OK; \
|
return RCL_RET_OK; \
|
||||||
} \
|
} \
|
||||||
rcl_allocator_t allocator = wait_set->impl->allocator; \
|
rcl_allocator_t allocator = wait_set->impl->allocator; \
|
||||||
|
wait_set->size_of_ ## Type ## s = 0; \
|
||||||
if (size == 0) { \
|
if (size == 0) { \
|
||||||
if (wait_set->Type ## s) { \
|
if (wait_set->Type ## s) { \
|
||||||
allocator.deallocate((void *)wait_set->Type ## s, allocator.state); \
|
allocator.deallocate((void *)wait_set->Type ## s, allocator.state); \
|
||||||
|
@ -300,7 +301,6 @@ rcl_wait_set_get_allocator(const rcl_wait_set_t * wait_set, rcl_allocator_t * al
|
||||||
} \
|
} \
|
||||||
ExtraDealloc \
|
ExtraDealloc \
|
||||||
} else { \
|
} else { \
|
||||||
wait_set->size_of_ ## Type ## s = 0; \
|
|
||||||
wait_set->Type ## s = (const rcl_ ## Type ## _t * *)allocator.reallocate( \
|
wait_set->Type ## s = (const rcl_ ## Type ## _t * *)allocator.reallocate( \
|
||||||
(void *)wait_set->Type ## s, sizeof(rcl_ ## Type ## _t *) * size, allocator.state); \
|
(void *)wait_set->Type ## s, sizeof(rcl_ ## Type ## _t *) * size, allocator.state); \
|
||||||
RCL_CHECK_FOR_NULL_WITH_MSG( \
|
RCL_CHECK_FOR_NULL_WITH_MSG( \
|
||||||
|
|
|
@ -100,6 +100,14 @@ function(test_target_function)
|
||||||
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
||||||
AMENT_DEPENDENCIES ${rmw_implementation} "std_msgs"
|
AMENT_DEPENDENCIES ${rmw_implementation} "std_msgs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
rcl_add_custom_gtest(test_wait${target_suffix}
|
||||||
|
SRCS rcl/test_wait.cpp
|
||||||
|
ENV ${extra_test_env}
|
||||||
|
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
|
||||||
|
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
||||||
|
AMENT_DEPENDENCIES ${rmw_implementation}
|
||||||
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
call_for_each_rmw_implementation(test_target)
|
call_for_each_rmw_implementation(test_target)
|
||||||
|
|
58
rcl/test/rcl/test_wait.cpp
Normal file
58
rcl/test/rcl/test_wait.cpp
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// Copyright 2016 Open Source Robotics Foundation, Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "rcl/rcl.h"
|
||||||
|
#include "rcl/error_handling.h"
|
||||||
|
#include "rcl/wait.h"
|
||||||
|
|
||||||
|
#ifdef RMW_IMPLEMENTATION
|
||||||
|
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
|
||||||
|
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
|
||||||
|
#else
|
||||||
|
# define CLASSNAME(NAME, SUFFIX) NAME
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
TEST(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), test_resize_to_zero) {
|
||||||
|
// Initialize a waitset with a subscription and then resize it to zero.
|
||||||
|
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||||
|
rcl_ret_t ret = rcl_wait_set_init(&wait_set, 1, 0, 0, 0, 0, rcl_get_default_allocator());
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe();
|
||||||
|
|
||||||
|
ret = rcl_wait_set_resize_subscriptions(&wait_set, 0);
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe();
|
||||||
|
|
||||||
|
EXPECT_EQ(wait_set.size_of_subscriptions, 0);
|
||||||
|
|
||||||
|
ret = rcl_wait_set_fini(&wait_set);
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), test_clear) {
|
||||||
|
// Initialize a waitset with a subscription and then resize it to zero.
|
||||||
|
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||||
|
rcl_ret_t ret = rcl_wait_set_init(&wait_set, 1, 0, 0, 0, 0, rcl_get_default_allocator());
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe();
|
||||||
|
|
||||||
|
ret = rcl_wait_set_clear_subscriptions(&wait_set);
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe();
|
||||||
|
|
||||||
|
EXPECT_EQ(wait_set.size_of_subscriptions, 0);
|
||||||
|
|
||||||
|
ret = rcl_wait_set_fini(&wait_set);
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue