Skip to content

Commit

Permalink
Add another controller for better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Dec 11, 2024
1 parent 1527fd9 commit 7ac28e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
joint_names: ["joint1"]
param1: 1.0
param2: 2.0

wildcard_ctrl_3:
ros__parameters:
param3: 3.0
35 changes: 25 additions & 10 deletions controller_manager/test/test_spawner_unspawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,13 @@ TEST_F(TestLoadController, spawner_test_with_wildcard_entries_with_no_ctrl_name)
// Provide controller type via the parsed file
EXPECT_EQ(
call_spawner(
"wildcard_ctrl_1 wildcard_ctrl_2 -c test_controller_manager --controller-manager-timeout 1.0 "
"wildcard_ctrl_1 wildcard_ctrl_2 wildcard_ctrl_3 -c test_controller_manager "
"--controller-manager-timeout 1.0 "
"-p " +
test_file_path),
0);

auto verify_ctrl_parameter = [](const auto & ctrl_node)
auto verify_ctrl_parameter = [](const auto & ctrl_node, bool has_param_3)
{
if (!ctrl_node->has_parameter("joint_names"))
{
Expand All @@ -401,25 +402,39 @@ TEST_F(TestLoadController, spawner_test_with_wildcard_entries_with_no_ctrl_name)
ctrl_node->declare_parameter("param2", -10.0);
}
ASSERT_THAT(ctrl_node->get_parameter("param2").as_double(), 2.0);

if (!ctrl_node->has_parameter("param3"))
{
ctrl_node->declare_parameter("param3", -10.0);
}
ASSERT_THAT(ctrl_node->get_parameter("param3").as_double(), has_param_3 ? 3.0 : -10.0);
};

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

auto wildcard_ctrl_1 = cm_->get_loaded_controllers()[0];
ASSERT_EQ(wildcard_ctrl_1.info.name, "wildcard_ctrl_2");
ASSERT_EQ(wildcard_ctrl_1.info.type, test_controller::TEST_CONTROLLER_CLASS_NAME);
auto wildcard_ctrl_3 = cm_->get_loaded_controllers()[0];
ASSERT_EQ(wildcard_ctrl_3.info.name, "wildcard_ctrl_3");
ASSERT_EQ(wildcard_ctrl_3.info.type, test_controller::TEST_CONTROLLER_CLASS_NAME);
ASSERT_EQ(
wildcard_ctrl_1.c->get_lifecycle_state().id(),
wildcard_ctrl_3.c->get_lifecycle_state().id(),
lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
verify_ctrl_parameter(wildcard_ctrl_1.c->get_node());
verify_ctrl_parameter(wildcard_ctrl_3.c->get_node(), true);

auto wildcard_ctrl_2 = cm_->get_loaded_controllers()[1];
ASSERT_EQ(wildcard_ctrl_2.info.name, "wildcard_ctrl_1");
ASSERT_EQ(wildcard_ctrl_2.info.name, "wildcard_ctrl_2");
ASSERT_EQ(wildcard_ctrl_2.info.type, test_controller::TEST_CONTROLLER_CLASS_NAME);
ASSERT_EQ(
wildcard_ctrl_2.c->get_lifecycle_state().id(),
lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
verify_ctrl_parameter(wildcard_ctrl_2.c->get_node());
verify_ctrl_parameter(wildcard_ctrl_2.c->get_node(), false);

auto wildcard_ctrl_1 = cm_->get_loaded_controllers()[2];
ASSERT_EQ(wildcard_ctrl_1.info.name, "wildcard_ctrl_1");
ASSERT_EQ(wildcard_ctrl_1.info.type, test_controller::TEST_CONTROLLER_CLASS_NAME);
ASSERT_EQ(
wildcard_ctrl_1.c->get_lifecycle_state().id(),
lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE);
verify_ctrl_parameter(wildcard_ctrl_1.c->get_node(), false);
}

TEST_F(TestLoadController, unload_on_kill)
Expand Down

0 comments on commit 7ac28e8

Please sign in to comment.