refactor init to not be global (#336)
* refactor init to not be global Signed-off-by: William Woodall <william@osrfoundation.org> * style changes Signed-off-by: William Woodall <william@osrfoundation.org> * refactor to hide use of C11 atomics in implementation Signed-off-by: William Woodall <william@osrfoundation.org> * fix new action tests Signed-off-by: William Woodall <william@osrfoundation.org> * use alternative atomic init for Windows support * updates after rebase Signed-off-by: William Woodall <william@osrfoundation.org> * cleanup rmw_init_options before copying Signed-off-by: William Woodall <william@osrfoundation.org> * fix two bugs in new init code * relax validity checks in a few places to facilitate post shutdown cleanup Signed-off-by: William Woodall <william@osrfoundation.org> * fixing tests for new API behavior Signed-off-by: William Woodall <william@osrfoundation.org> * to allocator -> to allocate * acutally call rmw_shutdown() and address review comments Signed-off-by: William Woodall <william@osrfoundation.org>
This commit is contained in:
parent
dfaa412bbf
commit
97ad0013e2
55 changed files with 1951 additions and 629 deletions
|
@ -77,6 +77,7 @@ install(TARGETS ${PROJECT_NAME}
|
|||
if(BUILD_TESTING)
|
||||
find_package(ament_cmake_gtest REQUIRED)
|
||||
find_package(ament_lint_auto REQUIRED)
|
||||
find_package(osrf_testing_tools_cpp REQUIRED)
|
||||
find_package(test_msgs REQUIRED)
|
||||
ament_lint_auto_find_test_dependencies()
|
||||
ament_find_gtest()
|
||||
|
@ -87,6 +88,7 @@ if(BUILD_TESTING)
|
|||
if(TARGET test_action_client)
|
||||
target_include_directories(test_action_client PUBLIC
|
||||
include
|
||||
${osrf_testing_tools_cpp_INCLUDE_DIRS}
|
||||
)
|
||||
target_link_libraries(test_action_client
|
||||
${PROJECT_NAME}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<test_depend>ament_cmake_gtest</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>osrf_testing_tools_cpp</test_depend>
|
||||
<test_depend>test_msgs</test_depend>
|
||||
|
||||
<export>
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "rcl/error_handling.h"
|
||||
#include "rcl/rcl.h"
|
||||
|
||||
#include "osrf_testing_tools_cpp/scope_exit.hpp"
|
||||
#include "test_msgs/action/fibonacci.h"
|
||||
|
||||
class TestActionClientBaseFixture : public ::testing::Test
|
||||
|
@ -26,12 +27,22 @@ class TestActionClientBaseFixture : public ::testing::Test
|
|||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
rcl_ret_t ret = rcl_init(0, nullptr, rcl_get_default_allocator());
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
rcl_ret_t ret;
|
||||
{
|
||||
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
||||
ret = rcl_init_options_init(&init_options, rcl_get_default_allocator());
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
|
||||
EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str;
|
||||
});
|
||||
this->context = rcl_get_zero_initialized_context();
|
||||
ret = rcl_init(0, nullptr, &init_options, &this->context);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
}
|
||||
this->node = rcl_get_zero_initialized_node();
|
||||
rcl_node_options_t node_options = rcl_node_get_default_options();
|
||||
const char * node_name = "test_action_client_node";
|
||||
ret = rcl_node_init(&this->node, node_name, "", &node_options);
|
||||
ret = rcl_node_init(&this->node, node_name, "", &this->context, &node_options);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
}
|
||||
|
||||
|
@ -39,10 +50,11 @@ protected:
|
|||
{
|
||||
rcl_ret_t ret = rcl_node_fini(&this->node);
|
||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
ret = rcl_shutdown();
|
||||
ret = rcl_shutdown(&this->context);
|
||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
}
|
||||
|
||||
rcl_context_t context;
|
||||
rcl_node_t node;
|
||||
};
|
||||
|
||||
|
|
|
@ -37,11 +37,16 @@ protected:
|
|||
void SetUp() override
|
||||
{
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
rcl_ret_t ret = rcl_init(0, nullptr, allocator);
|
||||
rcl_ret_t ret;
|
||||
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
||||
ret = rcl_init_options_init(&init_options, allocator);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
context = rcl_get_zero_initialized_context();
|
||||
ret = rcl_init(0, nullptr, &init_options, &context);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
this->node = rcl_get_zero_initialized_node();
|
||||
rcl_node_options_t node_options = rcl_node_get_default_options();
|
||||
ret = rcl_node_init(&this->node, "test_action_communication_node", "", &node_options);
|
||||
ret = rcl_node_init(&this->node, "test_action_communication_node", "", &context, &node_options);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
ret = rcl_clock_init(RCL_STEADY_TIME, &this->clock, &allocator);
|
||||
const rosidl_action_type_support_t * ts = ROSIDL_GET_ACTION_TYPE_SUPPORT(
|
||||
|
@ -107,11 +112,11 @@ protected:
|
|||
ret = rcl_action_client_fini(&this->action_client, &this->node);
|
||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||
ret = rcl_node_fini(&this->node);
|
||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||
ret = rcl_shutdown();
|
||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
ret = rcl_wait_set_fini(&this->wait_set);
|
||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||
ret = rcl_shutdown(&context);
|
||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||
rcl_reset_error();
|
||||
}
|
||||
|
||||
|
@ -131,6 +136,7 @@ protected:
|
|||
|
||||
rcl_action_client_t action_client;
|
||||
rcl_action_server_t action_server;
|
||||
rcl_context_t context;
|
||||
rcl_node_t node;
|
||||
rcl_clock_t clock;
|
||||
|
||||
|
|
|
@ -26,12 +26,17 @@
|
|||
TEST(TestActionServerInitFini, test_action_server_init_fini)
|
||||
{
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
rcl_ret_t ret = rcl_init(0, nullptr, allocator);
|
||||
rcl_ret_t ret;
|
||||
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
||||
ret = rcl_init_options_init(&init_options, allocator);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
rcl_context_t context = rcl_get_zero_initialized_context();
|
||||
ret = rcl_init(0, nullptr, &init_options, &context);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
|
||||
rcl_node_t node = rcl_get_zero_initialized_node();
|
||||
rcl_node_options_t node_options = rcl_node_get_default_options();
|
||||
ret = rcl_node_init(&node, "test_action_server_node", "", &node_options);
|
||||
ret = rcl_node_init(&node, "test_action_server_node", "", &context, &node_options);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
rcl_clock_t clock;
|
||||
ret = rcl_clock_init(RCL_STEADY_TIME, &clock, &allocator);
|
||||
|
@ -133,7 +138,7 @@ TEST(TestActionServerInitFini, test_action_server_init_fini)
|
|||
ret = rcl_node_fini(&node);
|
||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
|
||||
ret = rcl_shutdown();
|
||||
ret = rcl_shutdown(&context);
|
||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
}
|
||||
|
||||
|
@ -143,11 +148,16 @@ protected:
|
|||
void SetUp() override
|
||||
{
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
rcl_ret_t ret = rcl_init(0, nullptr, allocator);
|
||||
rcl_ret_t ret;
|
||||
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
|
||||
ret = rcl_init_options_init(&init_options, allocator);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
context = rcl_get_zero_initialized_context();
|
||||
ret = rcl_init(0, nullptr, &init_options, &context);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
this->node = rcl_get_zero_initialized_node();
|
||||
rcl_node_options_t node_options = rcl_node_get_default_options();
|
||||
ret = rcl_node_init(&this->node, "test_action_server_node", "", &node_options);
|
||||
ret = rcl_node_init(&this->node, "test_action_server_node", "", &context, &node_options);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
ret = rcl_clock_init(RCL_ROS_TIME, &this->clock, &allocator);
|
||||
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
|
@ -170,7 +180,7 @@ protected:
|
|||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||
ret = rcl_node_fini(&this->node);
|
||||
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||
ret = rcl_shutdown();
|
||||
ret = rcl_shutdown(&context);
|
||||
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||
}
|
||||
|
||||
|
@ -189,6 +199,7 @@ protected:
|
|||
}
|
||||
|
||||
rcl_action_server_t action_server;
|
||||
rcl_context_t context;
|
||||
rcl_node_t node;
|
||||
rcl_clock_t clock;
|
||||
}; // class TestActionServer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue