Skip to content

Commit 37fc242

Browse files
authored
refactor(behavior_path_planner): common test functions (#9963)
* feat: common test code in behavior_path_planner Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * deal with other modules Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * fix typo Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * update Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> --------- Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
1 parent 4b16661 commit 37fc242

File tree

10 files changed

+214
-513
lines changed

10 files changed

+214
-513
lines changed

planning/behavior_path_planner/autoware_behavior_path_avoidance_by_lane_change_module/test/test_behavior_path_planner_node_interface.cpp

+11-79
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "autoware/behavior_path_planner/behavior_path_planner_node.hpp"
16-
17-
#include <ament_index_cpp/get_package_share_directory.hpp>
18-
#include <autoware_planning_test_manager/autoware_planning_test_manager.hpp>
19-
#include <autoware_test_utils/autoware_test_utils.hpp>
15+
#include "autoware/behavior_path_planner/test_utils.hpp"
2016

2117
#include <gtest/gtest.h>
2218

@@ -25,84 +21,18 @@
2521
#include <string>
2622
#include <vector>
2723

28-
using autoware::behavior_path_planner::BehaviorPathPlannerNode;
29-
using autoware::planning_test_manager::PlanningInterfaceTestManager;
30-
31-
std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
32-
{
33-
auto test_manager = std::make_shared<PlanningInterfaceTestManager>();
34-
35-
// set subscriber with topic name: behavior_path_planner → test_node_
36-
test_manager->setPathWithLaneIdSubscriber("behavior_path_planner/output/path");
37-
38-
// set behavior_path_planner's input topic name(this topic is changed to test node)
39-
test_manager->setRouteInputTopicName("behavior_path_planner/input/route");
40-
41-
test_manager->setInitialPoseTopicName("behavior_path_planner/input/odometry");
42-
43-
return test_manager;
44-
}
45-
46-
std::shared_ptr<BehaviorPathPlannerNode> generateNode()
47-
{
48-
auto node_options = rclcpp::NodeOptions{};
49-
const auto autoware_test_utils_dir =
50-
ament_index_cpp::get_package_share_directory("autoware_test_utils");
51-
const auto behavior_path_planner_dir =
52-
ament_index_cpp::get_package_share_directory("autoware_behavior_path_planner");
53-
const auto behavior_path_lane_change_module_dir =
54-
ament_index_cpp::get_package_share_directory("autoware_behavior_path_lane_change_module");
55-
56-
std::vector<std::string> module_names;
57-
module_names.emplace_back("autoware::behavior_path_planner::AvoidanceByLaneChangeModuleManager");
58-
59-
std::vector<rclcpp::Parameter> params;
60-
params.emplace_back("launch_modules", module_names);
61-
node_options.parameter_overrides(params);
62-
63-
autoware::test_utils::updateNodeOptions(
64-
node_options, {autoware_test_utils_dir + "/config/test_common.param.yaml",
65-
autoware_test_utils_dir + "/config/test_nearest_search.param.yaml",
66-
autoware_test_utils_dir + "/config/test_vehicle_info.param.yaml",
67-
behavior_path_planner_dir + "/config/behavior_path_planner.param.yaml",
68-
behavior_path_planner_dir + "/config/drivable_area_expansion.param.yaml",
69-
behavior_path_planner_dir + "/config/scene_module_manager.param.yaml",
70-
behavior_path_lane_change_module_dir + "/config/lane_change.param.yaml",
71-
ament_index_cpp::get_package_share_directory(
72-
"autoware_behavior_path_static_obstacle_avoidance_module") +
73-
"/config/static_obstacle_avoidance.param.yaml",
74-
ament_index_cpp::get_package_share_directory(
75-
"autoware_behavior_path_avoidance_by_lane_change_module") +
76-
"/config/avoidance_by_lane_change.param.yaml"});
77-
78-
return std::make_shared<BehaviorPathPlannerNode>(node_options);
79-
}
80-
81-
void publishMandatoryTopics(
82-
std::shared_ptr<PlanningInterfaceTestManager> test_manager,
83-
std::shared_ptr<BehaviorPathPlannerNode> test_target_node)
84-
{
85-
// publish necessary topics from test_manager
86-
test_manager->publishInitialPose(test_target_node, "behavior_path_planner/input/odometry");
87-
test_manager->publishAcceleration(test_target_node, "behavior_path_planner/input/accel");
88-
test_manager->publishPredictedObjects(test_target_node, "behavior_path_planner/input/perception");
89-
test_manager->publishOccupancyGrid(
90-
test_target_node, "behavior_path_planner/input/occupancy_grid_map");
91-
test_manager->publishLaneDrivingScenario(
92-
test_target_node, "behavior_path_planner/input/scenario");
93-
test_manager->publishMap(test_target_node, "behavior_path_planner/input/vector_map");
94-
test_manager->publishCostMap(test_target_node, "behavior_path_planner/input/costmap");
95-
test_manager->publishOperationModeState(test_target_node, "system/operation_mode/state");
96-
test_manager->publishLateralOffset(
97-
test_target_node, "behavior_path_planner/input/lateral_offset");
98-
}
24+
using autoware::behavior_path_planner::generateNode;
25+
using autoware::behavior_path_planner::generateTestManager;
26+
using autoware::behavior_path_planner::publishMandatoryTopics;
9927

10028
TEST(PlanningModuleInterfaceTest, NodeTestWithExceptionRoute)
10129
{
10230
rclcpp::init(0, nullptr);
103-
auto test_manager = generateTestManager();
104-
auto test_target_node = generateNode();
10531

32+
auto test_manager = generateTestManager();
33+
auto test_target_node = generateNode(
34+
{"lane_change", "static_obstacle_avoidance", "avoidance_by_lane_change"},
35+
{"autoware::behavior_path_planner::AvoidanceByLaneChangeModuleManager"});
10636
publishMandatoryTopics(test_manager, test_target_node);
10737

10838
// test for normal trajectory
@@ -119,7 +49,9 @@ TEST(PlanningModuleInterfaceTest, NodeTestWithOffTrackEgoPose)
11949
rclcpp::init(0, nullptr);
12050

12151
auto test_manager = generateTestManager();
122-
auto test_target_node = generateNode();
52+
auto test_target_node = generateNode(
53+
{"lane_change", "static_obstacle_avoidance", "avoidance_by_lane_change"},
54+
{"autoware::behavior_path_planner::AvoidanceByLaneChangeModuleManager"});
12355
publishMandatoryTopics(test_manager, test_target_node);
12456

12557
// test for normal trajectory

planning/behavior_path_planner/autoware_behavior_path_dynamic_obstacle_avoidance_module/test/test_behavior_path_planner_node_interface.cpp

+10-72
Original file line numberDiff line numberDiff line change
@@ -12,87 +12,23 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "autoware/behavior_path_planner/behavior_path_planner_node.hpp"
16-
17-
#include <ament_index_cpp/get_package_share_directory.hpp>
18-
#include <autoware_planning_test_manager/autoware_planning_test_manager.hpp>
19-
#include <autoware_test_utils/autoware_test_utils.hpp>
15+
#include "autoware/behavior_path_planner/test_utils.hpp"
2016

2117
#include <memory>
2218
#include <string>
2319
#include <vector>
2420

25-
using autoware::behavior_path_planner::BehaviorPathPlannerNode;
26-
using autoware::planning_test_manager::PlanningInterfaceTestManager;
27-
28-
std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
29-
{
30-
auto test_manager = std::make_shared<PlanningInterfaceTestManager>();
31-
32-
// set subscriber with topic name: behavior_path_planner → test_node_
33-
test_manager->setPathWithLaneIdSubscriber("behavior_path_planner/output/path");
34-
35-
// set behavior_path_planner's input topic name(this topic is changed to test node)
36-
test_manager->setRouteInputTopicName("behavior_path_planner/input/route");
37-
38-
test_manager->setInitialPoseTopicName("behavior_path_planner/input/odometry");
39-
40-
return test_manager;
41-
}
42-
43-
std::shared_ptr<BehaviorPathPlannerNode> generateNode()
44-
{
45-
auto node_options = rclcpp::NodeOptions{};
46-
const auto autoware_test_utils_dir =
47-
ament_index_cpp::get_package_share_directory("autoware_test_utils");
48-
const auto behavior_path_planner_dir =
49-
ament_index_cpp::get_package_share_directory("autoware_behavior_path_planner");
50-
51-
std::vector<std::string> module_names;
52-
module_names.emplace_back("autoware::behavior_path_planner::DynamicAvoidanceModuleManager");
53-
54-
std::vector<rclcpp::Parameter> params;
55-
params.emplace_back("launch_modules", module_names);
56-
node_options.parameter_overrides(params);
57-
58-
autoware::test_utils::updateNodeOptions(
59-
node_options, {autoware_test_utils_dir + "/config/test_common.param.yaml",
60-
autoware_test_utils_dir + "/config/test_nearest_search.param.yaml",
61-
autoware_test_utils_dir + "/config/test_vehicle_info.param.yaml",
62-
behavior_path_planner_dir + "/config/behavior_path_planner.param.yaml",
63-
behavior_path_planner_dir + "/config/drivable_area_expansion.param.yaml",
64-
behavior_path_planner_dir + "/config/scene_module_manager.param.yaml",
65-
ament_index_cpp::get_package_share_directory(
66-
"autoware_behavior_path_dynamic_obstacle_avoidance_module") +
67-
"/config/dynamic_obstacle_avoidance.param.yaml"});
68-
69-
return std::make_shared<BehaviorPathPlannerNode>(node_options);
70-
}
71-
72-
void publishMandatoryTopics(
73-
std::shared_ptr<PlanningInterfaceTestManager> test_manager,
74-
std::shared_ptr<BehaviorPathPlannerNode> test_target_node)
75-
{
76-
// publish necessary topics from test_manager
77-
test_manager->publishInitialPose(test_target_node, "behavior_path_planner/input/odometry");
78-
test_manager->publishAcceleration(test_target_node, "behavior_path_planner/input/accel");
79-
test_manager->publishPredictedObjects(test_target_node, "behavior_path_planner/input/perception");
80-
test_manager->publishOccupancyGrid(
81-
test_target_node, "behavior_path_planner/input/occupancy_grid_map");
82-
test_manager->publishLaneDrivingScenario(
83-
test_target_node, "behavior_path_planner/input/scenario");
84-
test_manager->publishMap(test_target_node, "behavior_path_planner/input/vector_map");
85-
test_manager->publishCostMap(test_target_node, "behavior_path_planner/input/costmap");
86-
test_manager->publishOperationModeState(test_target_node, "system/operation_mode/state");
87-
test_manager->publishLateralOffset(
88-
test_target_node, "behavior_path_planner/input/lateral_offset");
89-
}
21+
using autoware::behavior_path_planner::generateNode;
22+
using autoware::behavior_path_planner::generateTestManager;
23+
using autoware::behavior_path_planner::publishMandatoryTopics;
9024

9125
TEST(PlanningModuleInterfaceTest, NodeTestWithExceptionRoute)
9226
{
9327
rclcpp::init(0, nullptr);
9428
auto test_manager = generateTestManager();
95-
auto test_target_node = generateNode();
29+
auto test_target_node = generateNode(
30+
{"dynamic_obstacle_avoidance"},
31+
{"autoware::behavior_path_planner::DynamicObstacleAvoidanceModuleManager"});
9632

9733
publishMandatoryTopics(test_manager, test_target_node);
9834

@@ -110,7 +46,9 @@ TEST(PlanningModuleInterfaceTest, NodeTestWithOffTrackEgoPose)
11046
rclcpp::init(0, nullptr);
11147

11248
auto test_manager = generateTestManager();
113-
auto test_target_node = generateNode();
49+
auto test_target_node = generateNode(
50+
{"dynamic_obstacle_avoidance"},
51+
{"autoware::behavior_path_planner::DynamicObstacleAvoidanceModuleManager"});
11452
publishMandatoryTopics(test_manager, test_target_node);
11553

11654
// test for normal trajectory

planning/behavior_path_planner/autoware_behavior_path_external_request_lane_change_module/test/test_behavior_path_planner_node_interface.cpp

+13-77
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "ament_index_cpp/get_package_share_directory.hpp"
16-
#include "autoware/behavior_path_planner/behavior_path_planner_node.hpp"
17-
#include "autoware_planning_test_manager/autoware_planning_test_manager.hpp"
18-
#include "autoware_test_utils/autoware_test_utils.hpp"
15+
#include "autoware/behavior_path_planner/test_utils.hpp"
1916

2017
#include <gtest/gtest.h>
2118

@@ -24,83 +21,19 @@
2421
#include <string>
2522
#include <vector>
2623

27-
using autoware::behavior_path_planner::BehaviorPathPlannerNode;
28-
using autoware::planning_test_manager::PlanningInterfaceTestManager;
29-
30-
std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
31-
{
32-
auto test_manager = std::make_shared<PlanningInterfaceTestManager>();
33-
34-
// set subscriber with topic name: behavior_path_planner → test_node_
35-
test_manager->setPathWithLaneIdSubscriber("behavior_path_planner/output/path");
36-
37-
// set behavior_path_planner's input topic name(this topic is changed to test node)
38-
test_manager->setRouteInputTopicName("behavior_path_planner/input/route");
39-
40-
test_manager->setInitialPoseTopicName("behavior_path_planner/input/odometry");
41-
42-
return test_manager;
43-
}
44-
45-
std::shared_ptr<BehaviorPathPlannerNode> generateNode()
46-
{
47-
auto node_options = rclcpp::NodeOptions{};
48-
const auto autoware_test_utils_dir =
49-
ament_index_cpp::get_package_share_directory("autoware_test_utils");
50-
const auto behavior_path_planner_dir =
51-
ament_index_cpp::get_package_share_directory("autoware_behavior_path_planner");
52-
const auto behavior_path_lane_change_module_dir =
53-
ament_index_cpp::get_package_share_directory("autoware_behavior_path_lane_change_module");
54-
55-
std::vector<std::string> module_names;
56-
module_names.emplace_back(
57-
"autoware::behavior_path_planner::ExternalRequestLaneChangeRightModuleManager");
58-
module_names.emplace_back(
59-
"autoware::behavior_path_planner::ExternalRequestLaneChangeLeftModuleManager");
60-
61-
std::vector<rclcpp::Parameter> params;
62-
params.emplace_back("launch_modules", module_names);
63-
node_options.parameter_overrides(params);
64-
65-
autoware::test_utils::updateNodeOptions(
66-
node_options, {
67-
autoware_test_utils_dir + "/config/test_common.param.yaml",
68-
autoware_test_utils_dir + "/config/test_nearest_search.param.yaml",
69-
autoware_test_utils_dir + "/config/test_vehicle_info.param.yaml",
70-
behavior_path_planner_dir + "/config/behavior_path_planner.param.yaml",
71-
behavior_path_planner_dir + "/config/drivable_area_expansion.param.yaml",
72-
behavior_path_planner_dir + "/config/scene_module_manager.param.yaml",
73-
behavior_path_lane_change_module_dir + "/config/lane_change.param.yaml",
74-
});
75-
76-
return std::make_shared<BehaviorPathPlannerNode>(node_options);
77-
}
78-
79-
void publishMandatoryTopics(
80-
std::shared_ptr<PlanningInterfaceTestManager> test_manager,
81-
std::shared_ptr<BehaviorPathPlannerNode> test_target_node)
82-
{
83-
// publish necessary topics from test_manager
84-
test_manager->publishInitialPose(test_target_node, "behavior_path_planner/input/odometry");
85-
test_manager->publishAcceleration(test_target_node, "behavior_path_planner/input/accel");
86-
test_manager->publishPredictedObjects(test_target_node, "behavior_path_planner/input/perception");
87-
test_manager->publishOccupancyGrid(
88-
test_target_node, "behavior_path_planner/input/occupancy_grid_map");
89-
test_manager->publishLaneDrivingScenario(
90-
test_target_node, "behavior_path_planner/input/scenario");
91-
test_manager->publishMap(test_target_node, "behavior_path_planner/input/vector_map");
92-
test_manager->publishCostMap(test_target_node, "behavior_path_planner/input/costmap");
93-
test_manager->publishOperationModeState(test_target_node, "system/operation_mode/state");
94-
test_manager->publishLateralOffset(
95-
test_target_node, "behavior_path_planner/input/lateral_offset");
96-
}
24+
using autoware::behavior_path_planner::generateNode;
25+
using autoware::behavior_path_planner::generateTestManager;
26+
using autoware::behavior_path_planner::publishMandatoryTopics;
9727

9828
TEST(PlanningModuleInterfaceTest, NodeTestWithExceptionRoute)
9929
{
10030
rclcpp::init(0, nullptr);
101-
auto test_manager = generateTestManager();
102-
auto test_target_node = generateNode();
10331

32+
auto test_manager = generateTestManager();
33+
auto test_target_node = generateNode(
34+
{"lane_change"},
35+
{"autoware::behavior_path_planner::ExternalRequestLaneChangeRightModuleManager",
36+
"autoware::behavior_path_planner::ExternalRequestLaneChangeLeftModuleManager"});
10437
publishMandatoryTopics(test_manager, test_target_node);
10538

10639
// test for normal trajectory
@@ -117,7 +50,10 @@ TEST(PlanningModuleInterfaceTest, NodeTestWithOffTrackEgoPose)
11750
rclcpp::init(0, nullptr);
11851

11952
auto test_manager = generateTestManager();
120-
auto test_target_node = generateNode();
53+
auto test_target_node = generateNode(
54+
{"lane_change"},
55+
{"autoware::behavior_path_planner::ExternalRequestLaneChangeRightModuleManager",
56+
"autoware::behavior_path_planner::ExternalRequestLaneChangeLeftModuleManager"});
12157
publishMandatoryTopics(test_manager, test_target_node);
12258

12359
// test for normal trajectory

0 commit comments

Comments
 (0)