From 9fb60cc40355295b128a59ccd7c39ca4c32500f7 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Fri, 19 Jun 2020 13:22:36 -0300 Subject: [PATCH 1/6] Add test_rmw_implementation package. Includes dummy init/shutdown test. Signed-off-by: Michel Hidalgo --- test_rmw_implementation/CMakeLists.txt | 45 +++++++++++++++++++ test_rmw_implementation/package.xml | 23 ++++++++++ .../test/test_init_shutdown.cpp | 41 +++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 test_rmw_implementation/CMakeLists.txt create mode 100644 test_rmw_implementation/package.xml create mode 100644 test_rmw_implementation/test/test_init_shutdown.cpp diff --git a/test_rmw_implementation/CMakeLists.txt b/test_rmw_implementation/CMakeLists.txt new file mode 100644 index 000000000..83fffb087 --- /dev/null +++ b/test_rmw_implementation/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.5) + +project(test_rmw_implementation) + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +find_package(ament_cmake REQUIRED) + +if(BUILD_TESTING) + find_package(ament_cmake_gtest REQUIRED) + find_package(osrf_testing_tools_cpp REQUIRED) + + find_package(rcutils REQUIRED) + find_package(rmw REQUIRED) + find_package(rmw_implementation REQUIRED) + find_package(rmw_implementation_cmake REQUIRED) + + macro(test_api) + find_package(${rmw_implementation} REQUIRED) + message(STATUS "Creating API tests for '${rmw_implementation}'") + set(rmw_implementation_env_var RMW_IMPLEMENTATION=${rmw_implementation}) + + ament_add_gtest(test_init_shutdown${target_suffix} + test/test_init_shutdown.cpp + ENV ${rmw_implementation_env_var} + ) + ament_target_dependencies(test_init_shutdown${target_suffix} + osrf_testing_tools_cpp rcutils rmw rmw_implementation + ) + endmacro() + + call_for_each_rmw_implementation(test_api) + + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() +endif() + +ament_package() diff --git a/test_rmw_implementation/package.xml b/test_rmw_implementation/package.xml new file mode 100644 index 000000000..98aecd1b7 --- /dev/null +++ b/test_rmw_implementation/package.xml @@ -0,0 +1,23 @@ + + + + test_rmw_implementation + 0.1.0 + Test suite for ROS middleware API. + Michel Hidalgo + Apache License 2.0 + + ament_cmake + rmw_implementation_cmake + + ament_lint_auto + ament_lint_common + osrf_testing_tools_cpp + rcutils + rmw + rmw_implementation + + + ament_cmake + + diff --git a/test_rmw_implementation/test/test_init_shutdown.cpp b/test_rmw_implementation/test/test_init_shutdown.cpp new file mode 100644 index 000000000..41ae17ef7 --- /dev/null +++ b/test_rmw_implementation/test/test_init_shutdown.cpp @@ -0,0 +1,41 @@ +// Copyright 2020 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 + +#include "osrf_testing_tools_cpp/scope_exit.hpp" + +#include "rcutils/allocator.h" +#include "rcutils/error_handling.h" + +#include "rmw/rmw.h" + + +TEST(TestInitShutdown, init_shutdown) { + rmw_context_t context = rmw_get_zero_initialized_context(); + rmw_init_options_t options = rmw_get_zero_initialized_init_options(); + rmw_ret_t ret = rmw_init_options_init(&options, rcutils_get_default_allocator()); + ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rmw_ret_t ret = rmw_init_options_fini(&options); + EXPECT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; + }); + + ret = rmw_init(&options, &context); + ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; + + ret = rmw_shutdown(&context); + EXPECT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; +} From 4a23529c8e145d51cfee647971f014463dee660c Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Fri, 19 Jun 2020 14:42:49 -0300 Subject: [PATCH 2/6] Finalize rmw context in test. Signed-off-by: Michel Hidalgo --- test_rmw_implementation/test/test_init_shutdown.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test_rmw_implementation/test/test_init_shutdown.cpp b/test_rmw_implementation/test/test_init_shutdown.cpp index 41ae17ef7..c7451adc8 100644 --- a/test_rmw_implementation/test/test_init_shutdown.cpp +++ b/test_rmw_implementation/test/test_init_shutdown.cpp @@ -35,6 +35,11 @@ TEST(TestInitShutdown, init_shutdown) { ret = rmw_init(&options, &context); ASSERT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( + { + rmw_ret_t ret = rmw_context_fini(&context); + EXPECT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; + }); ret = rmw_shutdown(&context); EXPECT_EQ(RMW_RET_OK, ret) << rcutils_get_error_string().str; From 228f34bbbffba532cc91a5edba2b20d107e4987c Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Fri, 19 Jun 2020 15:13:43 -0300 Subject: [PATCH 3/6] One fixture class per RMW implementation. Signed-off-by: Michel Hidalgo --- test_rmw_implementation/test/test_init_shutdown.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test_rmw_implementation/test/test_init_shutdown.cpp b/test_rmw_implementation/test/test_init_shutdown.cpp index c7451adc8..44a7e263f 100644 --- a/test_rmw_implementation/test/test_init_shutdown.cpp +++ b/test_rmw_implementation/test/test_init_shutdown.cpp @@ -21,8 +21,16 @@ #include "rmw/rmw.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(TestInitShutdown, init_shutdown) { +class CLASSNAME (TestInitShutdown, RMW_IMPLEMENTATION) : public ::testing::Test {}; + +TEST_F(TestInitShutdown, init_shutdown) { rmw_context_t context = rmw_get_zero_initialized_context(); rmw_init_options_t options = rmw_get_zero_initialized_init_options(); rmw_ret_t ret = rmw_init_options_init(&options, rcutils_get_default_allocator()); From 8be60020e5a606caf07abded8d2aa9d2cf4e6a94 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Fri, 19 Jun 2020 16:10:32 -0300 Subject: [PATCH 4/6] Actually use the fixture. Signed-off-by: Michel Hidalgo --- test_rmw_implementation/test/test_init_shutdown.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_rmw_implementation/test/test_init_shutdown.cpp b/test_rmw_implementation/test/test_init_shutdown.cpp index 44a7e263f..fa609268f 100644 --- a/test_rmw_implementation/test/test_init_shutdown.cpp +++ b/test_rmw_implementation/test/test_init_shutdown.cpp @@ -30,7 +30,7 @@ class CLASSNAME (TestInitShutdown, RMW_IMPLEMENTATION) : public ::testing::Test {}; -TEST_F(TestInitShutdown, init_shutdown) { +TEST_F(CLASSNAME (TestInitShutdown, RMW_IMPLEMENTATION), init_shutdown) { rmw_context_t context = rmw_get_zero_initialized_context(); rmw_init_options_t options = rmw_get_zero_initialized_init_options(); rmw_ret_t ret = rmw_init_options_init(&options, rcutils_get_default_allocator()); From d17d41f0b0a1e87f79b7439acf02b23ea91843bd Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Fri, 19 Jun 2020 17:15:59 -0300 Subject: [PATCH 5/6] Please linter. Signed-off-by: Michel Hidalgo --- test_rmw_implementation/test/test_init_shutdown.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_rmw_implementation/test/test_init_shutdown.cpp b/test_rmw_implementation/test/test_init_shutdown.cpp index fa609268f..6f47c0968 100644 --- a/test_rmw_implementation/test/test_init_shutdown.cpp +++ b/test_rmw_implementation/test/test_init_shutdown.cpp @@ -30,7 +30,7 @@ class CLASSNAME (TestInitShutdown, RMW_IMPLEMENTATION) : public ::testing::Test {}; -TEST_F(CLASSNAME (TestInitShutdown, RMW_IMPLEMENTATION), init_shutdown) { +TEST_F(CLASSNAME(TestInitShutdown, RMW_IMPLEMENTATION), init_shutdown) { rmw_context_t context = rmw_get_zero_initialized_context(); rmw_init_options_t options = rmw_get_zero_initialized_init_options(); rmw_ret_t ret = rmw_init_options_init(&options, rcutils_get_default_allocator()); From 7fde494797d323059592d3b2f8f8c4c916664c4b Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Fri, 19 Jun 2020 17:43:02 -0300 Subject: [PATCH 6/6] Add missing RMW_IMPLEMENTATION definitions Signed-off-by: Michel Hidalgo --- test_rmw_implementation/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_rmw_implementation/CMakeLists.txt b/test_rmw_implementation/CMakeLists.txt index 83fffb087..14ad1ba15 100644 --- a/test_rmw_implementation/CMakeLists.txt +++ b/test_rmw_implementation/CMakeLists.txt @@ -31,6 +31,8 @@ if(BUILD_TESTING) test/test_init_shutdown.cpp ENV ${rmw_implementation_env_var} ) + target_compile_definitions(test_init_shutdown${target_suffix} + PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}") ament_target_dependencies(test_init_shutdown${target_suffix} osrf_testing_tools_cpp rcutils rmw rmw_implementation )