From 878decf916ae417831480b81663af3df9b163c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Fr=C3=B6hlich?= Date: Thu, 25 Jan 2024 19:47:11 +0100 Subject: [PATCH 1/4] Move `test_components` to own package (#1325) (cherry picked from commit 0bdcd414c7ab8091f3e1b8d9b73a91c778388e82) # Conflicts: # .github/workflows/ci-coverage-build.yml # controller_manager/package.xml # hardware_interface/CMakeLists.txt --- .github/workflows/ci-coverage-build.yml | 4 ++ .github/workflows/ci-ros-lint.yml | 2 + controller_manager/package.xml | 5 ++ hardware_interface/CMakeLists.txt | 6 +++ hardware_interface_testing/CMakeLists.txt | 46 +++++++++++++++++++ hardware_interface_testing/README.md | 4 ++ hardware_interface_testing/package.xml | 25 ++++++++++ .../test/test_components/test_actuator.cpp | 0 .../test/test_components/test_components.xml | 0 .../test/test_components/test_sensor.cpp | 0 .../test/test_components/test_system.cpp | 0 .../test/test_resource_manager.cpp | 0 .../test/test_resource_manager.hpp | 0 ...esource_manager_prepare_perform_switch.cpp | 0 14 files changed, 92 insertions(+) create mode 100644 hardware_interface_testing/CMakeLists.txt create mode 100644 hardware_interface_testing/README.md create mode 100644 hardware_interface_testing/package.xml rename {hardware_interface => hardware_interface_testing}/test/test_components/test_actuator.cpp (100%) rename {hardware_interface => hardware_interface_testing}/test/test_components/test_components.xml (100%) rename {hardware_interface => hardware_interface_testing}/test/test_components/test_sensor.cpp (100%) rename {hardware_interface => hardware_interface_testing}/test/test_components/test_system.cpp (100%) rename {hardware_interface => hardware_interface_testing}/test/test_resource_manager.cpp (100%) rename {hardware_interface => hardware_interface_testing}/test/test_resource_manager.hpp (100%) rename {hardware_interface => hardware_interface_testing}/test/test_resource_manager_prepare_perform_switch.cpp (100%) diff --git a/.github/workflows/ci-coverage-build.yml b/.github/workflows/ci-coverage-build.yml index 6f6dd69391..c4b4e8e517 100644 --- a/.github/workflows/ci-coverage-build.yml +++ b/.github/workflows/ci-coverage-build.yml @@ -31,9 +31,13 @@ jobs: controller_manager controller_manager_msgs hardware_interface +<<<<<<< HEAD ros2controlcli ros2_control ros2_control_test_assets +======= + hardware_interface_testing +>>>>>>> 0bdcd41 (Move `test_components` to own package (#1325)) transmission_interface vcs-repo-file-url: | diff --git a/.github/workflows/ci-ros-lint.yml b/.github/workflows/ci-ros-lint.yml index 5146786e8a..d89046fc51 100644 --- a/.github/workflows/ci-ros-lint.yml +++ b/.github/workflows/ci-ros-lint.yml @@ -24,6 +24,7 @@ jobs: controller_manager controller_manager_msgs hardware_interface + hardware_interface_testing ros2controlcli ros2_control ros2_control_test_assets @@ -49,6 +50,7 @@ jobs: controller_manager controller_manager_msgs hardware_interface + hardware_interface_testing ros2controlcli ros2_control ros2_control_test_assets diff --git a/controller_manager/package.xml b/controller_manager/package.xml index 10c3be6ac1..d2fb3c4b53 100644 --- a/controller_manager/package.xml +++ b/controller_manager/package.xml @@ -28,6 +28,11 @@ std_msgs ament_cmake_gmock +<<<<<<< HEAD +======= + hardware_interface_testing + ros2_control_test_assets +>>>>>>> 0bdcd41 (Move `test_components` to own package (#1325)) ament_cmake diff --git a/hardware_interface/CMakeLists.txt b/hardware_interface/CMakeLists.txt index e0ba861193..98f3a485cf 100644 --- a/hardware_interface/CMakeLists.txt +++ b/hardware_interface/CMakeLists.txt @@ -138,6 +138,7 @@ if(BUILD_TESTING) target_link_libraries(test_component_parser ${PROJECT_NAME}) ament_target_dependencies(test_component_parser ros2_control_test_assets) +<<<<<<< HEAD add_library(test_components SHARED test/test_components/test_actuator.cpp test/test_components/test_sensor.cpp @@ -151,6 +152,8 @@ if(BUILD_TESTING) pluginlib_export_plugin_description_file( ${PROJECT_NAME} test/test_components/test_components.xml) +======= +>>>>>>> 0bdcd41 (Move `test_components` to own package (#1325)) add_library(test_hardware_components SHARED test/test_hardware_components/test_single_joint_actuator.cpp test/test_hardware_components/test_force_torque_sensor.cpp @@ -167,6 +170,7 @@ if(BUILD_TESTING) ${PROJECT_NAME} test/test_hardware_components/test_hardware_components.xml ) +<<<<<<< HEAD ament_add_gmock(test_resource_manager test/test_resource_manager.cpp) target_link_libraries(test_resource_manager ${PROJECT_NAME}) ament_target_dependencies(test_resource_manager ros2_control_test_assets) @@ -175,6 +179,8 @@ if(BUILD_TESTING) target_link_libraries(test_resource_manager_prepare_perform_switch hardware_interface) ament_target_dependencies(test_resource_manager_prepare_perform_switch ros2_control_test_assets) +======= +>>>>>>> 0bdcd41 (Move `test_components` to own package (#1325)) ament_add_gmock(test_generic_system test/mock_components/test_generic_system.cpp) target_include_directories(test_generic_system PRIVATE include) target_link_libraries(test_generic_system ${PROJECT_NAME}) diff --git a/hardware_interface_testing/CMakeLists.txt b/hardware_interface_testing/CMakeLists.txt new file mode 100644 index 0000000000..8e88a677bf --- /dev/null +++ b/hardware_interface_testing/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.16) +project(hardware_interface_testing LANGUAGES CXX) + +if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") + add_compile_options(-Wall -Wextra -Werror=conversion -Werror=unused-but-set-variable -Werror=return-type -Werror=shadow) +endif() + +set(THIS_PACKAGE_INCLUDE_DEPENDS + control_msgs + hardware_interface + lifecycle_msgs + pluginlib + rclcpp_lifecycle + ros2_control_test_assets +) + +find_package(ament_cmake REQUIRED) +foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS}) + find_package(${Dependency} REQUIRED) +endforeach() + +add_library(test_components SHARED +test/test_components/test_actuator.cpp +test/test_components/test_sensor.cpp +test/test_components/test_system.cpp) +ament_target_dependencies(test_components hardware_interface pluginlib ros2_control_test_assets) +install(TARGETS test_components +DESTINATION lib +) +pluginlib_export_plugin_description_file( +hardware_interface test/test_components/test_components.xml) + +if(BUILD_TESTING) + + find_package(ament_cmake_gmock REQUIRED) + + ament_add_gmock(test_resource_manager test/test_resource_manager.cpp) + ament_target_dependencies(test_resource_manager hardware_interface ros2_control_test_assets) + + ament_add_gmock(test_resource_manager_prepare_perform_switch test/test_resource_manager_prepare_perform_switch.cpp) + ament_target_dependencies(test_resource_manager_prepare_perform_switch hardware_interface ros2_control_test_assets) + +endif() + +ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS}) +ament_package() diff --git a/hardware_interface_testing/README.md b/hardware_interface_testing/README.md new file mode 100644 index 0000000000..cba28d74a5 --- /dev/null +++ b/hardware_interface_testing/README.md @@ -0,0 +1,4 @@ +# hardware_interface_testing + +This package contains a set of hardware interfaces and controllers that can be used for other +packages to test their functionality. diff --git a/hardware_interface_testing/package.xml b/hardware_interface_testing/package.xml new file mode 100644 index 0000000000..841c77626f --- /dev/null +++ b/hardware_interface_testing/package.xml @@ -0,0 +1,25 @@ + + + hardware_interface_testing + 0.0.0 + ros2_control hardware interface testing + Bence Magyar + Denis Štogl + Christoph Froehlich + Apache License 2.0 + + ament_cmake + + control_msgs + hardware_interface + lifecycle_msgs + pluginlib + rclcpp_lifecycle + ros2_control_test_assets + + ament_cmake_gmock + + + ament_cmake + + diff --git a/hardware_interface/test/test_components/test_actuator.cpp b/hardware_interface_testing/test/test_components/test_actuator.cpp similarity index 100% rename from hardware_interface/test/test_components/test_actuator.cpp rename to hardware_interface_testing/test/test_components/test_actuator.cpp diff --git a/hardware_interface/test/test_components/test_components.xml b/hardware_interface_testing/test/test_components/test_components.xml similarity index 100% rename from hardware_interface/test/test_components/test_components.xml rename to hardware_interface_testing/test/test_components/test_components.xml diff --git a/hardware_interface/test/test_components/test_sensor.cpp b/hardware_interface_testing/test/test_components/test_sensor.cpp similarity index 100% rename from hardware_interface/test/test_components/test_sensor.cpp rename to hardware_interface_testing/test/test_components/test_sensor.cpp diff --git a/hardware_interface/test/test_components/test_system.cpp b/hardware_interface_testing/test/test_components/test_system.cpp similarity index 100% rename from hardware_interface/test/test_components/test_system.cpp rename to hardware_interface_testing/test/test_components/test_system.cpp diff --git a/hardware_interface/test/test_resource_manager.cpp b/hardware_interface_testing/test/test_resource_manager.cpp similarity index 100% rename from hardware_interface/test/test_resource_manager.cpp rename to hardware_interface_testing/test/test_resource_manager.cpp diff --git a/hardware_interface/test/test_resource_manager.hpp b/hardware_interface_testing/test/test_resource_manager.hpp similarity index 100% rename from hardware_interface/test/test_resource_manager.hpp rename to hardware_interface_testing/test/test_resource_manager.hpp diff --git a/hardware_interface/test/test_resource_manager_prepare_perform_switch.cpp b/hardware_interface_testing/test/test_resource_manager_prepare_perform_switch.cpp similarity index 100% rename from hardware_interface/test/test_resource_manager_prepare_perform_switch.cpp rename to hardware_interface_testing/test/test_resource_manager_prepare_perform_switch.cpp From 224f6c8e1a137532f479877007a2dc217c18d723 Mon Sep 17 00:00:00 2001 From: "Dr. Denis" Date: Fri, 26 Jan 2024 16:38:24 +0100 Subject: [PATCH 2/4] Resolve conflicts --- .github/workflows/ci-coverage-build.yml | 3 --- controller_manager/package.xml | 3 --- 2 files changed, 6 deletions(-) diff --git a/.github/workflows/ci-coverage-build.yml b/.github/workflows/ci-coverage-build.yml index c4b4e8e517..61e9a05b01 100644 --- a/.github/workflows/ci-coverage-build.yml +++ b/.github/workflows/ci-coverage-build.yml @@ -31,13 +31,10 @@ jobs: controller_manager controller_manager_msgs hardware_interface -<<<<<<< HEAD ros2controlcli ros2_control ros2_control_test_assets -======= hardware_interface_testing ->>>>>>> 0bdcd41 (Move `test_components` to own package (#1325)) transmission_interface vcs-repo-file-url: | diff --git a/controller_manager/package.xml b/controller_manager/package.xml index d2fb3c4b53..69aa9760bf 100644 --- a/controller_manager/package.xml +++ b/controller_manager/package.xml @@ -28,11 +28,8 @@ std_msgs ament_cmake_gmock -<<<<<<< HEAD -======= hardware_interface_testing ros2_control_test_assets ->>>>>>> 0bdcd41 (Move `test_components` to own package (#1325)) ament_cmake From e112ab862e12abf42a272787e61c341eb0749fd4 Mon Sep 17 00:00:00 2001 From: "Dr. Denis" Date: Fri, 26 Jan 2024 16:39:14 +0100 Subject: [PATCH 3/4] Resolve conflicts --- hardware_interface/CMakeLists.txt | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/hardware_interface/CMakeLists.txt b/hardware_interface/CMakeLists.txt index 98f3a485cf..5892f0c3b3 100644 --- a/hardware_interface/CMakeLists.txt +++ b/hardware_interface/CMakeLists.txt @@ -138,22 +138,6 @@ if(BUILD_TESTING) target_link_libraries(test_component_parser ${PROJECT_NAME}) ament_target_dependencies(test_component_parser ros2_control_test_assets) -<<<<<<< HEAD - add_library(test_components SHARED - test/test_components/test_actuator.cpp - test/test_components/test_sensor.cpp - test/test_components/test_system.cpp) - target_link_libraries(test_components ${PROJECT_NAME}) - ament_target_dependencies(test_components - pluginlib) - install(TARGETS test_components - DESTINATION lib - ) - pluginlib_export_plugin_description_file( - ${PROJECT_NAME} test/test_components/test_components.xml) - -======= ->>>>>>> 0bdcd41 (Move `test_components` to own package (#1325)) add_library(test_hardware_components SHARED test/test_hardware_components/test_single_joint_actuator.cpp test/test_hardware_components/test_force_torque_sensor.cpp @@ -169,18 +153,6 @@ if(BUILD_TESTING) pluginlib_export_plugin_description_file( ${PROJECT_NAME} test/test_hardware_components/test_hardware_components.xml ) - -<<<<<<< HEAD - ament_add_gmock(test_resource_manager test/test_resource_manager.cpp) - target_link_libraries(test_resource_manager ${PROJECT_NAME}) - ament_target_dependencies(test_resource_manager ros2_control_test_assets) - - ament_add_gmock(test_resource_manager_prepare_perform_switch test/test_resource_manager_prepare_perform_switch.cpp) - target_link_libraries(test_resource_manager_prepare_perform_switch hardware_interface) - ament_target_dependencies(test_resource_manager_prepare_perform_switch ros2_control_test_assets) - -======= ->>>>>>> 0bdcd41 (Move `test_components` to own package (#1325)) ament_add_gmock(test_generic_system test/mock_components/test_generic_system.cpp) target_include_directories(test_generic_system PRIVATE include) target_link_libraries(test_generic_system ${PROJECT_NAME}) From 3bb868a3770bda5969fe207be891e6f436133834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Denis=20=C5=A0togl?= Date: Fri, 26 Jan 2024 16:51:51 +0100 Subject: [PATCH 4/4] Avoid shadowing and small cosmetic changes. --- hardware_interface_testing/CMakeLists.txt | 10 +-- .../test/test_resource_manager.cpp | 64 +++++++++---------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/hardware_interface_testing/CMakeLists.txt b/hardware_interface_testing/CMakeLists.txt index 8e88a677bf..ec6d591dee 100644 --- a/hardware_interface_testing/CMakeLists.txt +++ b/hardware_interface_testing/CMakeLists.txt @@ -20,18 +20,18 @@ foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS}) endforeach() add_library(test_components SHARED -test/test_components/test_actuator.cpp -test/test_components/test_sensor.cpp -test/test_components/test_system.cpp) + test/test_components/test_actuator.cpp + test/test_components/test_sensor.cpp + test/test_components/test_system.cpp +) ament_target_dependencies(test_components hardware_interface pluginlib ros2_control_test_assets) install(TARGETS test_components -DESTINATION lib + DESTINATION lib ) pluginlib_export_plugin_description_file( hardware_interface test/test_components/test_components.xml) if(BUILD_TESTING) - find_package(ament_cmake_gmock REQUIRED) ament_add_gmock(test_resource_manager test/test_resource_manager.cpp) diff --git a/hardware_interface_testing/test/test_resource_manager.cpp b/hardware_interface_testing/test/test_resource_manager.cpp index 90b2643d7f..90129f9f64 100644 --- a/hardware_interface_testing/test/test_resource_manager.cpp +++ b/hardware_interface_testing/test/test_resource_manager.cpp @@ -232,73 +232,73 @@ TEST_F(ResourceManagerTest, resource_claiming) // Activate components to get all interfaces available activate_components(rm); - const auto key = "joint1/position"; - EXPECT_TRUE(rm.command_interface_is_available(key)); - EXPECT_FALSE(rm.command_interface_is_claimed(key)); + const auto command_interface = "joint1/position"; + EXPECT_TRUE(rm.command_interface_is_available(command_interface)); + EXPECT_FALSE(rm.command_interface_is_claimed(command_interface)); { - auto position_command_interface = rm.claim_command_interface(key); - EXPECT_TRUE(rm.command_interface_is_available(key)); - EXPECT_TRUE(rm.command_interface_is_claimed(key)); + auto position_command_interface = rm.claim_command_interface(command_interface); + EXPECT_TRUE(rm.command_interface_is_available(command_interface)); + EXPECT_TRUE(rm.command_interface_is_claimed(command_interface)); { - EXPECT_ANY_THROW(rm.claim_command_interface(key)); - EXPECT_TRUE(rm.command_interface_is_available(key)); + EXPECT_ANY_THROW(rm.claim_command_interface(command_interface)); + EXPECT_TRUE(rm.command_interface_is_available(command_interface)); } } - EXPECT_TRUE(rm.command_interface_is_available(key)); - EXPECT_FALSE(rm.command_interface_is_claimed(key)); + EXPECT_TRUE(rm.command_interface_is_available(command_interface)); + EXPECT_FALSE(rm.command_interface_is_claimed(command_interface)); // command interfaces can only be claimed once - for (const auto & key : + for (const auto & interface_key : {"joint1/position", "joint1/position", "joint1/position", "joint2/velocity", "joint3/velocity"}) { { - auto interface = rm.claim_command_interface(key); - EXPECT_TRUE(rm.command_interface_is_available(key)); - EXPECT_TRUE(rm.command_interface_is_claimed(key)); + auto interface = rm.claim_command_interface(interface_key); + EXPECT_TRUE(rm.command_interface_is_available(interface_key)); + EXPECT_TRUE(rm.command_interface_is_claimed(interface_key)); { - EXPECT_ANY_THROW(rm.claim_command_interface(key)); - EXPECT_TRUE(rm.command_interface_is_available(key)); + EXPECT_ANY_THROW(rm.claim_command_interface(interface_key)); + EXPECT_TRUE(rm.command_interface_is_available(interface_key)); } } - EXPECT_TRUE(rm.command_interface_is_available(key)); - EXPECT_FALSE(rm.command_interface_is_claimed(key)); + EXPECT_TRUE(rm.command_interface_is_available(interface_key)); + EXPECT_FALSE(rm.command_interface_is_claimed(interface_key)); } // TODO(destogl): This claim test is not true.... can not be... // state interfaces can be claimed multiple times - for (const auto & key : + for (const auto & interface_key : {"joint1/position", "joint1/velocity", "sensor1/velocity", "joint2/position", "joint3/position"}) { { - EXPECT_TRUE(rm.state_interface_is_available(key)); - auto interface = rm.claim_state_interface(key); + EXPECT_TRUE(rm.state_interface_is_available(interface_key)); + auto interface = rm.claim_state_interface(interface_key); { - EXPECT_TRUE(rm.state_interface_is_available(key)); - EXPECT_NO_THROW(rm.claim_state_interface(key)); + EXPECT_TRUE(rm.state_interface_is_available(interface_key)); + EXPECT_NO_THROW(rm.claim_state_interface(interface_key)); } } } std::vector interfaces; const auto interface_names = {"joint1/position", "joint2/velocity", "joint3/velocity"}; - for (const auto & key : interface_names) + for (const auto & interface : interface_names) { - EXPECT_TRUE(rm.command_interface_is_available(key)); - interfaces.emplace_back(rm.claim_command_interface(key)); + EXPECT_TRUE(rm.command_interface_is_available(interface)); + interfaces.emplace_back(rm.claim_command_interface(interface)); } - for (const auto & key : interface_names) + for (const auto & interface : interface_names) { - EXPECT_TRUE(rm.command_interface_is_available(key)); - EXPECT_TRUE(rm.command_interface_is_claimed(key)); + EXPECT_TRUE(rm.command_interface_is_available(interface)); + EXPECT_TRUE(rm.command_interface_is_claimed(interface)); } interfaces.clear(); - for (const auto & key : interface_names) + for (const auto & interface : interface_names) { - EXPECT_TRUE(rm.command_interface_is_available(key)); - EXPECT_FALSE(rm.command_interface_is_claimed(key)); + EXPECT_TRUE(rm.command_interface_is_available(interface)); + EXPECT_FALSE(rm.command_interface_is_claimed(interface)); } }