Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceManager doesn't always log an error on shutdown anymore #867

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion hardware_interface/src/resource_manager.cpp
Expand Up @@ -268,7 +268,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)
{
Expand Down
28 changes: 15 additions & 13 deletions hardware_interface/test/test_resource_manager.cpp
Expand Up @@ -78,7 +78,7 @@ class TestableResourceManager : public hardware_interface::ResourceManager
}
};

void set_components_state(
std::vector<hardware_interface::return_type> set_components_state(
TestableResourceManager & rm, const std::vector<std::string> & components, const uint8_t state_id,
const std::string & state_name)
{
Expand All @@ -87,49 +87,52 @@ void set_components_state(
{
int_components = {"TestActuatorHardware", "TestSensorHardware", "TestSystemHardware"};
}
std::vector<hardware_interface::return_type> 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<std::string> & components = {})
{
set_components_state(
return set_components_state(
rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE,
hardware_interface::lifecycle_state_names::INACTIVE);
};

auto activate_components =
[](TestableResourceManager & rm, const std::vector<std::string> & components = {})
{
set_components_state(
return set_components_state(
rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE,
hardware_interface::lifecycle_state_names::ACTIVE);
};

auto deactivate_components =
[](TestableResourceManager & rm, const std::vector<std::string> & components = {})
{
set_components_state(
return set_components_state(
rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE,
hardware_interface::lifecycle_state_names::INACTIVE);
};

auto cleanup_components =
[](TestableResourceManager & rm, const std::vector<std::string> & components = {})
{
set_components_state(
return set_components_state(
rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED,
hardware_interface::lifecycle_state_names::UNCONFIGURED);
};

auto shutdown_components =
[](TestableResourceManager & rm, const std::vector<std::string> & components = {})
{
set_components_state(
return set_components_state(
rm, components, lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED,
hardware_interface::lifecycle_state_names::FINALIZED);
};
Expand Down Expand Up @@ -533,7 +536,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(
Expand All @@ -556,7 +559,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(
Expand All @@ -579,7 +582,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(
Expand All @@ -602,7 +605,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(
Expand All @@ -625,7 +628,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(
Expand Down Expand Up @@ -837,7 +840,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();
Expand Down