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

refactor(test_utils): move to common folder #7158

Merged
1 change: 1 addition & 0 deletions common/.pages
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ nav:
- 'Testing Libraries':
- 'autoware_testing': common/autoware_testing/design/autoware_testing-design
- 'fake_test_node': common/fake_test_node/design/fake_test_node-design
- 'Test Utils': common/autoware_test_utils
- 'Common Libraries':
- 'autoware_auto_common':
- 'comparisons': common/autoware_auto_common/design/comparisons
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.14)
project(planning_test_utils)
project(autoware_test_utils)

find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_add_library(planning_test_utils SHARED
src/planning_test_utils.cpp)
ament_auto_add_library(autoware_test_utils SHARED
src/autoware_test_utils.cpp)

ament_auto_add_library(mock_data_parser SHARED
src/mock_data_parser.cpp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The objective of the `test_utils` is to develop a unit testing library for the A

## Available Maps

The following maps are available [here](https://github.com/autowarefoundation/autoware.universe/tree/main/planning/planning_test_utils/test_map)
The following maps are available [here](https://github.com/autowarefoundation/autoware.universe/tree/main/planning/autoware_test_utils/test_map)

### Common

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef PLANNING_TEST_UTILS__PLANNING_TEST_UTILS_HPP_
#define PLANNING_TEST_UTILS__PLANNING_TEST_UTILS_HPP_
#ifndef AUTOWARE_TEST_UTILS__AUTOWARE_TEST_UTILS_HPP_
#define AUTOWARE_TEST_UTILS__AUTOWARE_TEST_UTILS_HPP_

#include "ament_index_cpp/get_package_share_directory.hpp"
#include "rclcpp/rclcpp.hpp"
Expand Down Expand Up @@ -54,7 +54,7 @@
#include <utility>
#include <vector>

namespace test_utils
namespace autoware::test_utils
{
using autoware_adapi_v1_msgs::msg::OperationModeState;
using autoware_map_msgs::msg::LaneletMapBin;
Expand Down Expand Up @@ -191,7 +191,7 @@ LaneletMapBin make_map_bin_msg(
* @brief Creates a LaneletMapBin message using a predefined Lanelet2 map file.
*
* This function loads a lanelet2_map.osm from the test_map folder in the
* planning_test_utils package, overwrites the centerline with a resolution of 5.0,
* autoware_test_utils package, overwrites the centerline with a resolution of 5.0,
* and converts the map to a LaneletMapBin message.
*
* @return A LaneletMapBin message containing the map data.
Expand Down Expand Up @@ -299,7 +299,7 @@ void updateNodeOptions(
* @brief Loads a PathWithLaneId message from a YAML file.
*
* This function loads a PathWithLaneId message from a YAML file located in the
* planning_test_utils package.
* autoware_test_utils package.
*
* @return A PathWithLaneId message containing the loaded data.
*/
Expand Down Expand Up @@ -468,15 +468,15 @@ void publishToTargetNode(
throw std::runtime_error(std::string("Topic name for ") + typeid(data).name() + " is empty");
}

test_utils::setPublisher<T>(test_node, topic_name, publisher);
autoware::test_utils::setPublisher<T>(test_node, topic_name, publisher);
publisher->publish(data);

if (target_node->count_subscribers(topic_name) == 0) {
throw std::runtime_error("No subscriber for " + topic_name);
}
test_utils::spinSomeNodes(test_node, target_node, repeat_count);
autoware::test_utils::spinSomeNodes(test_node, target_node, repeat_count);
}

} // namespace test_utils
} // namespace autoware::test_utils

#endif // PLANNING_TEST_UTILS__PLANNING_TEST_UTILS_HPP_
#endif // AUTOWARE_TEST_UTILS__AUTOWARE_TEST_UTILS_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef PLANNING_TEST_UTILS__MOCK_DATA_PARSER_HPP_
#define PLANNING_TEST_UTILS__MOCK_DATA_PARSER_HPP_
#ifndef AUTOWARE_TEST_UTILS__MOCK_DATA_PARSER_HPP_
#define AUTOWARE_TEST_UTILS__MOCK_DATA_PARSER_HPP_

#include <autoware_planning_msgs/msg/lanelet_primitive.hpp>
#include <autoware_planning_msgs/msg/lanelet_route.hpp>
Expand All @@ -25,7 +25,7 @@
#include <string>
#include <vector>

namespace test_utils
namespace autoware::test_utils
{
using autoware_planning_msgs::msg::LaneletPrimitive;
using autoware_planning_msgs::msg::LaneletRoute;
Expand All @@ -41,6 +41,6 @@ std::vector<LaneletPrimitive> parse_lanelet_primitives(const YAML::Node & node);
std::vector<LaneletSegment> parse_segments(const YAML::Node & node);

LaneletRoute parse_lanelet_route_file(const std::string & filename);
} // namespace test_utils
} // namespace autoware::test_utils

#endif // PLANNING_TEST_UTILS__MOCK_DATA_PARSER_HPP_
#endif // AUTOWARE_TEST_UTILS__MOCK_DATA_PARSER_HPP_
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>planning_test_utils</name>
<name>autoware_test_utils</name>
<version>0.1.0</version>
<description>ROS 2 node for testing interface of the nodes in planning module</description>
<maintainer email="[email protected]">Kyoichi Sugahara</maintainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 TIER IV, Inc.

Check warning on line 1 in common/autoware_test_utils/src/autoware_test_utils.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Primitive Obsession

In this module, 60.0% of all function arguments are primitive types, threshold = 30.0%. The functions in this file have too many primitive types (e.g. int, double, float) in their function argument lists. Using many primitive types lead to the code smell Primitive Obsession. Avoid adding more primitive arguments.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,18 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "planning_test_utils/planning_test_utils.hpp"
namespace test_utils
#include "autoware_test_utils/autoware_test_utils.hpp"
namespace autoware::test_utils
{

geometry_msgs::msg::Pose createPose(
double x, double y, double z, double roll, double pitch, double yaw)
{
geometry_msgs::msg::Pose p;
p.position = createPoint(x, y, z);
p.orientation = createQuaternionFromRPY(roll, pitch, yaw);
return p;
}

Check warning on line 26 in common/autoware_test_utils/src/autoware_test_utils.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Excess Number of Function Arguments

createPose has 6 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

geometry_msgs::msg::Pose createPose(const std::array<double, 4> & pose3d)
{
Expand Down Expand Up @@ -122,9 +122,9 @@

LaneletMapBin makeMapBinMsg()
{
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto lanelet2_path = planning_test_utils_dir + "/test_map/lanelet2_map.osm";
const auto autoware_test_utils_dir =
ament_index_cpp::get_package_share_directory("autoware_test_utils");
const auto lanelet2_path = autoware_test_utils_dir + "/test_map/lanelet2_map.osm";
double center_line_resolution = 5.0;

return make_map_bin_msg(lanelet2_path, center_line_resolution);
Expand All @@ -147,7 +147,7 @@
const auto shift_y = shift * std::cos(yaw);
const std::array<double, 4> start_pose{
3722.16015625 + shift_x, 73723.515625 + shift_y, 0.233112560494183, yaw};
current_odometry.pose.pose = test_utils::createPose(start_pose);
current_odometry.pose.pose = autoware::test_utils::createPose(start_pose);
current_odometry.header.frame_id = "map";
return current_odometry;
}
Expand Down Expand Up @@ -251,9 +251,9 @@

PathWithLaneId loadPathWithLaneIdInYaml()
{
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto yaml_path = planning_test_utils_dir + "/config/path_with_lane_id_data.yaml";
const auto autoware_test_utils_dir =
ament_index_cpp::get_package_share_directory("autoware_test_utils");
const auto yaml_path = autoware_test_utils_dir + "/config/path_with_lane_id_data.yaml";
YAML::Node yaml_node = YAML::LoadFile(yaml_path);
PathWithLaneId path_msg;

Expand Down Expand Up @@ -311,4 +311,4 @@
return path_msg;
}

} // namespace test_utils
} // namespace autoware::test_utils
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "planning_test_utils/mock_data_parser.hpp"
#include "autoware_test_utils/mock_data_parser.hpp"

#include <rclcpp/logging.hpp>

Expand All @@ -27,7 +27,7 @@
#include <string>
#include <vector>

namespace test_utils
namespace autoware::test_utils
{
Pose parse_pose(const YAML::Node & node)
{
Expand Down Expand Up @@ -85,8 +85,8 @@ LaneletRoute parse_lanelet_route_file(const std::string & filename)
lanelet_route.goal_pose = (config["goal_pose"]) ? parse_pose(config["goal_pose"]) : Pose();
lanelet_route.segments = parse_segments(config["segments"]);
} catch (const std::exception & e) {
RCLCPP_DEBUG(rclcpp::get_logger("planning_test_utils"), "Exception caught: %s", e.what());
RCLCPP_DEBUG(rclcpp::get_logger("autoware_test_utils"), "Exception caught: %s", e.what());
}
return lanelet_route;
}
} // namespace test_utils
} // namespace autoware::test_utils
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

// Assuming the parseRouteFile function is in 'RouteHandler.h'
#include "ament_index_cpp/get_package_share_directory.hpp"
#include "planning_test_utils/mock_data_parser.hpp"
#include "autoware_test_utils/mock_data_parser.hpp"

namespace test_utils
namespace autoware::test_utils
{
// Example YAML structure as a string for testing
const char g_complete_yaml[] = R"(
Expand Down Expand Up @@ -94,10 +94,10 @@ TEST(ParseFunctions, CompleteYAMLTest)

TEST(ParseFunction, CompleteFromFilename)
{
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto autoware_test_utils_dir =
ament_index_cpp::get_package_share_directory("autoware_test_utils");
const auto parser_test_route =
planning_test_utils_dir + "/test_data/lanelet_route_parser_test.yaml";
autoware_test_utils_dir + "/test_data/lanelet_route_parser_test.yaml";

const auto lanelet_route = parse_lanelet_route_file(parser_test_route);
EXPECT_DOUBLE_EQ(lanelet_route.start_pose.position.x, 1.0);
Expand Down Expand Up @@ -132,4 +132,4 @@ TEST(ParseFunction, CompleteFromFilename)
EXPECT_EQ(segment1.primitives[3].id, 88);
EXPECT_EQ(segment1.primitives[3].primitive_type, "lane");
}
} // namespace test_utils
} // namespace autoware::test_utils
1 change: 0 additions & 1 deletion planning/.pages
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ nav:
- 'Planning Debug Tools':
- 'About Planning Debug Tools': https://github.com/autowarefoundation/autoware_tools/tree/main/planning/planning_debug_tools
- 'Stop Reason Visualizer': https://github.com/autowarefoundation/autoware_tools/blob/main/planning/planning_debug_tools/doc-stop-reason-visualizer.md
- 'Planning Test Utils': planning/planning_test_utils
- 'Planning Test Manager': planning/autoware_planning_test_manager
- 'Planning Topic Converter': planning/autoware_planning_topic_converter
- 'Planning Validator': planning/autoware_planning_validator
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

#include <ament_index_cpp/get_package_share_directory.hpp>
#include <autoware_planning_test_manager/autoware_planning_test_manager.hpp>
#include <planning_test_utils/planning_test_utils.hpp>
#include <autoware_test_utils/autoware_test_utils.hpp>

#include <gtest/gtest.h>

#include <cmath>
#include <vector>

using autoware::behavior_path_planner::BehaviorPathPlannerNode;
using planning_test_utils::PlanningInterfaceTestManager;
using autoware::planning_test_manager::PlanningInterfaceTestManager;

std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
{
Expand All @@ -44,10 +44,10 @@ std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
std::shared_ptr<BehaviorPathPlannerNode> generateNode()
{
auto node_options = rclcpp::NodeOptions{};
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto autoware_test_utils_dir =
ament_index_cpp::get_package_share_directory("autoware_test_utils");
const auto behavior_path_planner_dir =
ament_index_cpp::get_package_share_directory("behavior_path_planner");
ament_index_cpp::get_package_share_directory("autoware_behavior_path_planner");
const auto behavior_path_lane_change_module_dir =
ament_index_cpp::get_package_share_directory("autoware_behavior_path_lane_change_module");

Expand All @@ -58,10 +58,10 @@ std::shared_ptr<BehaviorPathPlannerNode> generateNode()
params.emplace_back("launch_modules", module_names);
node_options.parameter_overrides(params);

test_utils::updateNodeOptions(
node_options, {planning_test_utils_dir + "/config/test_common.param.yaml",
planning_test_utils_dir + "/config/test_nearest_search.param.yaml",
planning_test_utils_dir + "/config/test_vehicle_info.param.yaml",
autoware::test_utils::updateNodeOptions(
node_options, {autoware_test_utils_dir + "/config/test_common.param.yaml",
autoware_test_utils_dir + "/config/test_nearest_search.param.yaml",
autoware_test_utils_dir + "/config/test_vehicle_info.param.yaml",
behavior_path_planner_dir + "/config/behavior_path_planner.param.yaml",
behavior_path_planner_dir + "/config/drivable_area_expansion.param.yaml",
behavior_path_planner_dir + "/config/scene_module_manager.param.yaml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

#include <ament_index_cpp/get_package_share_directory.hpp>
#include <autoware_planning_test_manager/autoware_planning_test_manager.hpp>
#include <planning_test_utils/planning_test_utils.hpp>
#include <autoware_test_utils/autoware_test_utils.hpp>

#include <vector>

using autoware::behavior_path_planner::BehaviorPathPlannerNode;
using planning_test_utils::PlanningInterfaceTestManager;
using autoware::planning_test_manager::PlanningInterfaceTestManager;

std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
{
Expand All @@ -41,10 +41,10 @@ std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
std::shared_ptr<BehaviorPathPlannerNode> generateNode()
{
auto node_options = rclcpp::NodeOptions{};
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto autoware_test_utils_dir =
ament_index_cpp::get_package_share_directory("autoware_test_utils");
const auto behavior_path_planner_dir =
ament_index_cpp::get_package_share_directory("behavior_path_planner");
ament_index_cpp::get_package_share_directory("autoware_behavior_path_planner");

std::vector<std::string> module_names;
module_names.emplace_back("autoware::behavior_path_planner::DynamicAvoidanceModuleManager");
Expand All @@ -53,10 +53,10 @@ std::shared_ptr<BehaviorPathPlannerNode> generateNode()
params.emplace_back("launch_modules", module_names);
node_options.parameter_overrides(params);

test_utils::updateNodeOptions(
node_options, {planning_test_utils_dir + "/config/test_common.param.yaml",
planning_test_utils_dir + "/config/test_nearest_search.param.yaml",
planning_test_utils_dir + "/config/test_vehicle_info.param.yaml",
autoware::test_utils::updateNodeOptions(
node_options, {autoware_test_utils_dir + "/config/test_common.param.yaml",
autoware_test_utils_dir + "/config/test_nearest_search.param.yaml",
autoware_test_utils_dir + "/config/test_vehicle_info.param.yaml",
behavior_path_planner_dir + "/config/behavior_path_planner.param.yaml",
behavior_path_planner_dir + "/config/drivable_area_expansion.param.yaml",
behavior_path_planner_dir + "/config/scene_module_manager.param.yaml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
#include "ament_index_cpp/get_package_share_directory.hpp"
#include "autoware_behavior_path_planner/behavior_path_planner_node.hpp"
#include "autoware_planning_test_manager/autoware_planning_test_manager.hpp"
#include "planning_test_utils/planning_test_utils.hpp"
#include "autoware_test_utils/autoware_test_utils.hpp"

#include <gtest/gtest.h>

#include <cmath>
#include <vector>

using autoware::behavior_path_planner::BehaviorPathPlannerNode;
using planning_test_utils::PlanningInterfaceTestManager;
using autoware::planning_test_manager::PlanningInterfaceTestManager;

std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
{
Expand All @@ -43,10 +43,10 @@ std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
std::shared_ptr<BehaviorPathPlannerNode> generateNode()
{
auto node_options = rclcpp::NodeOptions{};
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto autoware_test_utils_dir =
ament_index_cpp::get_package_share_directory("autoware_test_utils");
const auto behavior_path_planner_dir =
ament_index_cpp::get_package_share_directory("behavior_path_planner");
ament_index_cpp::get_package_share_directory("autoware_behavior_path_planner");
const auto behavior_path_lane_change_module_dir =
ament_index_cpp::get_package_share_directory("autoware_behavior_path_lane_change_module");

Expand All @@ -60,11 +60,11 @@ std::shared_ptr<BehaviorPathPlannerNode> generateNode()
params.emplace_back("launch_modules", module_names);
node_options.parameter_overrides(params);

test_utils::updateNodeOptions(
autoware::test_utils::updateNodeOptions(
node_options, {
planning_test_utils_dir + "/config/test_common.param.yaml",
planning_test_utils_dir + "/config/test_nearest_search.param.yaml",
planning_test_utils_dir + "/config/test_vehicle_info.param.yaml",
autoware_test_utils_dir + "/config/test_common.param.yaml",
autoware_test_utils_dir + "/config/test_nearest_search.param.yaml",
autoware_test_utils_dir + "/config/test_vehicle_info.param.yaml",
behavior_path_planner_dir + "/config/behavior_path_planner.param.yaml",
behavior_path_planner_dir + "/config/drivable_area_expansion.param.yaml",
behavior_path_planner_dir + "/config/scene_module_manager.param.yaml",
Expand Down
Loading
Loading