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

Add more parameter overriding tests from parsing multiple parameter files #1899

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions controller_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ if(BUILD_TESTING)
install(FILES test/test_controller_spawner_with_type.yaml
DESTINATION test)

install(FILES test/test_controller_overriding_parameters.yaml
DESTINATION test)

ament_add_gmock(test_hardware_management_srvs
test/test_hardware_management_srvs.cpp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ctrl_with_parameters_and_type:
ros__parameters:
interface_name: "impedance"
joint_offset: 0.2
joint_names: ["joint10"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ctrl_with_parameters_and_type:
ros__parameters:
type: "controller_manager/test_controller"
joint_names: ["joint0"]
interface_name: "position"

/**:
chainable_ctrl_with_parameters_and_type:
Expand Down
114 changes: 114 additions & 0 deletions controller_manager/test/test_spawner_unspawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ TEST_F(TestLoadController, spawner_test_with_params_file_string_parameter)
ASSERT_THAT(
ctrl_node->get_parameter("joint_names").as_string_array(),
std::vector<std::string>({"joint0"}));

if (!ctrl_node->has_parameter("interface_name"))
{
ctrl_node->declare_parameter("interface_name", "invalid_interface");
}
ASSERT_EQ(ctrl_node->get_parameter("interface_name").as_string(), "position");
}

TEST_F(TestLoadController, spawner_test_type_in_params_file)
Expand Down Expand Up @@ -397,6 +403,114 @@ TEST_F(TestLoadController, unload_on_kill_activate_as_group)
ASSERT_EQ(cm_->get_loaded_controllers().size(), 0ul);
}

TEST_F(TestLoadController, spawner_test_to_check_parameter_overriding)
{
const std::string main_test_file_path =
ament_index_cpp::get_package_prefix("controller_manager") +
"/test/test_controller_spawner_with_type.yaml";
const std::string overriding_test_file_path =
ament_index_cpp::get_package_prefix("controller_manager") +
"/test/test_controller_overriding_parameters.yaml";

ControllerManagerRunner cm_runner(this);
EXPECT_EQ(
call_spawner(
"ctrl_with_parameters_and_type --load-only -c "
"test_controller_manager -p " +
main_test_file_path + " -p " + overriding_test_file_path),
0);

ASSERT_EQ(cm_->get_loaded_controllers().size(), 1ul);

auto ctrl_with_parameters_and_type = cm_->get_loaded_controllers()[0];
ASSERT_EQ(ctrl_with_parameters_and_type.info.name, "ctrl_with_parameters_and_type");
ASSERT_EQ(ctrl_with_parameters_and_type.info.type, test_controller::TEST_CONTROLLER_CLASS_NAME);
ASSERT_EQ(
ctrl_with_parameters_and_type.c->get_lifecycle_state().id(),
lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED);
ASSERT_THAT(
cm_->get_parameter("ctrl_with_parameters_and_type.params_file").as_string_array(),
std::vector<std::string>({main_test_file_path, overriding_test_file_path}));
auto ctrl_node = ctrl_with_parameters_and_type.c->get_node();
ASSERT_THAT(
ctrl_with_parameters_and_type.info.parameters_files,
std::vector<std::string>({main_test_file_path, overriding_test_file_path}));
if (!ctrl_node->has_parameter("joint_names"))
{
ctrl_node->declare_parameter("joint_names", std::vector<std::string>({"random_joint"}));
}
ASSERT_THAT(
ctrl_node->get_parameter("joint_names").as_string_array(),
std::vector<std::string>({"joint10"}));

if (!ctrl_node->has_parameter("interface_name"))
{
ctrl_node->declare_parameter("interface_name", "invalid_interface");
}
ASSERT_EQ(ctrl_node->get_parameter("interface_name").as_string(), "impedance")
<< "The parameter should be overridden";

if (!ctrl_node->has_parameter("joint_offset"))
{
ctrl_node->declare_parameter("joint_offset", -M_PI);
}
ASSERT_EQ(ctrl_node->get_parameter("joint_offset").as_double(), 0.2);
}

TEST_F(TestLoadController, spawner_test_to_check_parameter_overriding_reverse)
{
const std::string main_test_file_path =
ament_index_cpp::get_package_prefix("controller_manager") +
"/test/test_controller_overriding_parameters.yaml";
const std::string overriding_test_file_path =
ament_index_cpp::get_package_prefix("controller_manager") +
"/test/test_controller_spawner_with_type.yaml";

ControllerManagerRunner cm_runner(this);
EXPECT_EQ(
call_spawner(
"ctrl_with_parameters_and_type --load-only -c "
"test_controller_manager -p " +
main_test_file_path + " -p " + overriding_test_file_path),
0);

ASSERT_EQ(cm_->get_loaded_controllers().size(), 1ul);

auto ctrl_with_parameters_and_type = cm_->get_loaded_controllers()[0];
ASSERT_EQ(ctrl_with_parameters_and_type.info.name, "ctrl_with_parameters_and_type");
ASSERT_EQ(ctrl_with_parameters_and_type.info.type, test_controller::TEST_CONTROLLER_CLASS_NAME);
ASSERT_EQ(
ctrl_with_parameters_and_type.c->get_lifecycle_state().id(),
lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED);
ASSERT_THAT(
cm_->get_parameter("ctrl_with_parameters_and_type.params_file").as_string_array(),
std::vector<std::string>({main_test_file_path, overriding_test_file_path}));
auto ctrl_node = ctrl_with_parameters_and_type.c->get_node();
ASSERT_THAT(
ctrl_with_parameters_and_type.info.parameters_files,
std::vector<std::string>({main_test_file_path, overriding_test_file_path}));
if (!ctrl_node->has_parameter("joint_names"))
{
ctrl_node->declare_parameter("joint_names", std::vector<std::string>({"random_joint"}));
}
ASSERT_THAT(
ctrl_node->get_parameter("joint_names").as_string_array(),
std::vector<std::string>({"joint0"}));

if (!ctrl_node->has_parameter("interface_name"))
{
ctrl_node->declare_parameter("interface_name", "invalid_interface");
}
ASSERT_EQ(ctrl_node->get_parameter("interface_name").as_string(), "position")
<< "The parameter should be overridden";

if (!ctrl_node->has_parameter("joint_offset"))
{
ctrl_node->declare_parameter("joint_offset", -M_PI);
}
ASSERT_EQ(ctrl_node->get_parameter("joint_offset").as_double(), 0.2);
}

TEST_F(TestLoadController, spawner_test_fallback_controllers)
{
const std::string test_file_path = ament_index_cpp::get_package_prefix("controller_manager") +
Expand Down