From 89e6598ad284ff69a4ab39bf6dda317cf4832f55 Mon Sep 17 00:00:00 2001 From: Christopher Wecht Date: Tue, 6 Dec 2022 12:57:34 +0100 Subject: [PATCH] ResourceManager doesn't always log an error on shutdown anymore (#867) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christopher Wecht Co-authored-by: Denis Štogl --- hardware_interface/src/resource_manager.cpp | 2 +- .../test/test_resource_manager.cpp | 28 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/hardware_interface/src/resource_manager.cpp b/hardware_interface/src/resource_manager.cpp index 2b0308b16e..7e88cca9b5 100644 --- a/hardware_interface/src/resource_manager.cpp +++ b/hardware_interface/src/resource_manager.cpp @@ -266,7 +266,7 @@ class ResourceStorage { bool result = trigger_and_print_hardware_state_transition( std::bind(&HardwareT::shutdown, &hardware), "shutdown", hardware.get_name(), - lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED); + lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED); if (result) { diff --git a/hardware_interface/test/test_resource_manager.cpp b/hardware_interface/test/test_resource_manager.cpp index 8600575ff6..59257f4edc 100644 --- a/hardware_interface/test/test_resource_manager.cpp +++ b/hardware_interface/test/test_resource_manager.cpp @@ -78,7 +78,7 @@ class TestableResourceManager : public hardware_interface::ResourceManager } }; -void set_components_state( +std::vector set_components_state( TestableResourceManager & rm, const std::vector & components, const uint8_t state_id, const std::string & state_name) { @@ -87,17 +87,20 @@ void set_components_state( { int_components = {"TestActuatorHardware", "TestSensorHardware", "TestSystemHardware"}; } + std::vector results; for (const auto & component : int_components) { rclcpp_lifecycle::State state(state_id, state_name); - rm.set_component_state(component, state); + const auto result = rm.set_component_state(component, state); + results.push_back(result); } + return results; } auto configure_components = [](TestableResourceManager & rm, const std::vector & components = {}) { - set_components_state( + return set_components_state( rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, hardware_interface::lifecycle_state_names::INACTIVE); }; @@ -105,7 +108,7 @@ auto configure_components = auto activate_components = [](TestableResourceManager & rm, const std::vector & components = {}) { - set_components_state( + return set_components_state( rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE, hardware_interface::lifecycle_state_names::ACTIVE); }; @@ -113,7 +116,7 @@ auto activate_components = auto deactivate_components = [](TestableResourceManager & rm, const std::vector & components = {}) { - set_components_state( + return set_components_state( rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, hardware_interface::lifecycle_state_names::INACTIVE); }; @@ -121,7 +124,7 @@ auto deactivate_components = auto cleanup_components = [](TestableResourceManager & rm, const std::vector & components = {}) { - set_components_state( + return set_components_state( rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED, hardware_interface::lifecycle_state_names::UNCONFIGURED); }; @@ -129,7 +132,7 @@ auto cleanup_components = auto shutdown_components = [](TestableResourceManager & rm, const std::vector & components = {}) { - set_components_state( + return set_components_state( rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED, hardware_interface::lifecycle_state_names::FINALIZED); }; @@ -534,7 +537,7 @@ TEST_F(ResourceManagerTest, lifecycle_all_resources) hardware_interface::lifecycle_state_names::UNCONFIGURED); } - configure_components(rm); + ASSERT_THAT(configure_components(rm), ::testing::Each(hardware_interface::return_type::OK)); { auto status_map = rm.get_components_status(); EXPECT_EQ( @@ -557,7 +560,7 @@ TEST_F(ResourceManagerTest, lifecycle_all_resources) hardware_interface::lifecycle_state_names::INACTIVE); } - activate_components(rm); + ASSERT_THAT(activate_components(rm), ::testing::Each(hardware_interface::return_type::OK)); { auto status_map = rm.get_components_status(); EXPECT_EQ( @@ -580,7 +583,7 @@ TEST_F(ResourceManagerTest, lifecycle_all_resources) hardware_interface::lifecycle_state_names::ACTIVE); } - deactivate_components(rm); + ASSERT_THAT(deactivate_components(rm), ::testing::Each(hardware_interface::return_type::OK)); { auto status_map = rm.get_components_status(); EXPECT_EQ( @@ -603,7 +606,7 @@ TEST_F(ResourceManagerTest, lifecycle_all_resources) hardware_interface::lifecycle_state_names::INACTIVE); } - cleanup_components(rm); + ASSERT_THAT(cleanup_components(rm), ::testing::Each(hardware_interface::return_type::OK)); { auto status_map = rm.get_components_status(); EXPECT_EQ( @@ -626,7 +629,7 @@ TEST_F(ResourceManagerTest, lifecycle_all_resources) hardware_interface::lifecycle_state_names::UNCONFIGURED); } - shutdown_components(rm); + ASSERT_THAT(shutdown_components(rm), ::testing::Each(hardware_interface::return_type::OK)); { auto status_map = rm.get_components_status(); EXPECT_EQ( @@ -838,7 +841,6 @@ TEST_F(ResourceManagerTest, lifecycle_individual_resources) hardware_interface::lifecycle_state_names::FINALIZED); } - // TODO(destogl): Watch-out this fails in output, why is this not caught?!!! shutdown_components(rm, {TEST_SENSOR_HARDWARE_NAME}); { auto status_map = rm.get_components_status();