Skip to content

Commit

Permalink
refactor(test_utils): move to common folder
Browse files Browse the repository at this point in the history
Signed-off-by: Zulfaqar Azmi <[email protected]>
  • Loading branch information
zulfaqar-azmi-t4 committed May 29, 2024
1 parent 57d6df8 commit 74d8207
Show file tree
Hide file tree
Showing 46 changed files with 120 additions and 134 deletions.
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/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(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(test_utils SHARED
src/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/test_utils/test_map)

### Common

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
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 TEST_UTILS__MOCK_DATA_PARSER_HPP_
#define TEST_UTILS__MOCK_DATA_PARSER_HPP_

#include <autoware_planning_msgs/msg/lanelet_primitive.hpp>
#include <autoware_planning_msgs/msg/lanelet_route.hpp>
Expand Down Expand Up @@ -43,4 +43,4 @@ std::vector<LaneletSegment> parse_segments(const YAML::Node & node);
LaneletRoute parse_lanelet_route_file(const std::string & filename);
} // namespace test_utils

#endif // PLANNING_TEST_UTILS__MOCK_DATA_PARSER_HPP_
#endif // TEST_UTILS__MOCK_DATA_PARSER_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__PLANNING_TEST_UTILS_HPP_
#define PLANNING_TEST_UTILS__PLANNING_TEST_UTILS_HPP_
#ifndef TEST_UTILS__TEST_UTILS_HPP_
#define TEST_UTILS__TEST_UTILS_HPP_

#include "ament_index_cpp/get_package_share_directory.hpp"
#include "rclcpp/rclcpp.hpp"
Expand Down Expand Up @@ -191,7 +191,7 @@ HADMapBin make_map_bin_msg(
* @brief Creates a HADMapBin 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,
* test_utils package, overwrites the centerline with a resolution of 5.0,
* and converts the map to a HADMapBin message.
*
* @return A HADMapBin 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.
* test_utils package.
*
* @return A PathWithLaneId message containing the loaded data.
*/
Expand Down Expand Up @@ -479,4 +479,4 @@ void publishToTargetNode(

} // namespace test_utils

#endif // PLANNING_TEST_UTILS__PLANNING_TEST_UTILS_HPP_
#endif // TEST_UTILS__TEST_UTILS_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>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
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 "test_utils/mock_data_parser.hpp"

#include <rclcpp/logging.hpp>

Expand Down Expand Up @@ -85,7 +85,7 @@ 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("test_utils"), "Exception caught: %s", e.what());
}
return lanelet_route;
}
Expand Down
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/planning_test_utils.hpp"
#include "test_utils/test_utils.hpp"
namespace test_utils
{

Expand Down Expand Up @@ -121,9 +121,8 @@ HADMapBin make_map_bin_msg(const std::string & absolute_path, const double cente

HADMapBin 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 test_utils_dir = ament_index_cpp::get_package_share_directory("test_utils");
const auto lanelet2_path = 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 Down Expand Up @@ -250,9 +249,8 @@ void updateNodeOptions(

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 test_utils_dir = ament_index_cpp::get_package_share_directory("test_utils");
const auto yaml_path = test_utils_dir + "/config/path_with_lane_id_data.yaml";
YAML::Node yaml_node = YAML::LoadFile(yaml_path);
PathWithLaneId path_msg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

// 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 "test_utils/mock_data_parser.hpp"

namespace test_utils
{
Expand Down Expand Up @@ -94,10 +94,8 @@ TEST(ParseFunctions, CompleteYAMLTest)

TEST(ParseFunction, CompleteFromFilename)
{
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto parser_test_route =
planning_test_utils_dir + "/test_data/lanelet_route_parser_test.yaml";
const auto test_utils_dir = ament_index_cpp::get_package_share_directory("test_utils");
const auto parser_test_route = 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
File renamed without changes.
File renamed without changes.
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_planning_test_manager/autoware_planning_test_manager.hpp"
#include "behavior_path_planner/behavior_path_planner_node.hpp"
#include "planning_test_utils/planning_test_utils.hpp"
#include "test_utils/test_utils.hpp"

#include <gtest/gtest.h>

#include <cmath>
#include <vector>

using autoware_planning_test_manager::PlanningInterfaceTestManager;
using ::behavior_path_planner::BehaviorPathPlannerNode;
using planning_test_utils::PlanningInterfaceTestManager;

std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
{
Expand Down
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 <test_utils/test_utils.hpp>

#include <gtest/gtest.h>

#include <cmath>
#include <vector>

using autoware::behavior_velocity_planner::BehaviorVelocityPlannerNode;
using planning_test_utils::PlanningInterfaceTestManager;
using autoware_planning_test_manager::PlanningInterfaceTestManager;

std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
{
Expand Down
8 changes: 4 additions & 4 deletions planning/autoware_planning_test_manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ TEST(PlanningModuleInterfaceTest, NodeTestWithExceptionTrajectory)
rclcpp::init(0, nullptr);

// instantiate test_manager with PlanningInterfaceTestManager type
auto test_manager = std::make_shared<planning_test_utils::PlanningInterfaceTestManager>();
auto test_manager = std::make_shared<autoware_planning_test_manager::PlanningInterfaceTestManager>();

// get package directories for necessary configuration files
const auto planning_test_utils_dir =
ament_index_cpp::get_package_share_directory("planning_test_utils");
const auto test_utils_dir =
ament_index_cpp::get_package_share_directory("test_utils");
const auto target_node_dir =
ament_index_cpp::get_package_share_directory("target_node");

// set arguments to get the config file
node_options.arguments(
{"--ros-args", "--params-file",
planning_test_utils_dir + "/config/test_vehicle_info.param.yaml", "--params-file",
test_utils_dir + "/config/test_vehicle_info.param.yaml", "--params-file",
planning_validator_dir + "/config/planning_validator.param.yaml"});

// instantiate the TargetNode with node_options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#include <memory>
#include <string>

namespace planning_test_utils
namespace autoware_planning_test_manager
{
using autoware_adapi_v1_msgs::msg::OperationModeState;
using autoware_auto_mapping_msgs::msg::HADMapBin;
Expand Down Expand Up @@ -264,6 +264,6 @@ class PlanningInterfaceTestManager
void publishAbnormalPath(rclcpp::Node::SharedPtr target_node, std::string topic_name);
}; // class PlanningInterfaceTestManager

} // namespace planning_test_utils
} // namespace autoware_planning_test_manager

#endif // AUTOWARE_PLANNING_TEST_MANAGER__AUTOWARE_PLANNING_TEST_MANAGER_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#ifndef AUTOWARE_PLANNING_TEST_MANAGER__AUTOWARE_PLANNING_TEST_MANAGER_UTILS_HPP_
#define AUTOWARE_PLANNING_TEST_MANAGER__AUTOWARE_PLANNING_TEST_MANAGER_UTILS_HPP_
#include <planning_test_utils/planning_test_utils.hpp>
#include <route_handler/route_handler.hpp>
#include <test_utils/test_utils.hpp>

#include <autoware_planning_msgs/msg/lanelet_route.hpp>
#include <geometry_msgs/msg/pose.hpp>
Expand Down
2 changes: 1 addition & 1 deletion planning/autoware_planning_test_manager/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<depend>lanelet2_io</depend>
<depend>motion_utils</depend>
<depend>nav_msgs</depend>
<depend>planning_test_utils</depend>
<depend>rclcpp</depend>
<depend>route_handler</depend>
<depend>test_utils</depend>
<depend>tf2_msgs</depend>
<depend>tf2_ros</depend>
<depend>tier4_api_msgs</depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

#include <autoware_planning_test_manager/autoware_planning_test_manager.hpp>
#include <autoware_planning_test_manager/autoware_planning_test_manager_utils.hpp>
#include <planning_test_utils/planning_test_utils.hpp>
#include <test_utils/test_utils.hpp>
#include <tier4_autoware_utils/geometry/geometry.hpp>

namespace planning_test_utils
namespace autoware_planning_test_manager
{

PlanningInterfaceTestManager::PlanningInterfaceTestManager()
Expand Down Expand Up @@ -455,4 +455,4 @@ int PlanningInterfaceTestManager::getReceivedTopicNum()
return count_;
}

} // namespace planning_test_utils
} // namespace autoware_planning_test_manager
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<depend>lanelet2_extension</depend>
<depend>motion_utils</depend>
<depend>nav_msgs</depend>
<depend>planning_test_utils</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>route_handler</depend>
<depend>std_msgs</depend>
<depend>test_utils</depend>
<depend>tier4_autoware_utils</depend>
<depend>tier4_planning_msgs</depend>

Expand Down
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 <test_utils/test_utils.hpp>

#include <gtest/gtest.h>

#include <cmath>
#include <vector>

using autoware_planning_test_manager::PlanningInterfaceTestManager;
using behavior_path_planner::BehaviorPathPlannerNode;
using planning_test_utils::PlanningInterfaceTestManager;

std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
{
Expand All @@ -44,8 +44,7 @@ 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 test_utils_dir = ament_index_cpp::get_package_share_directory("test_utils");
const auto behavior_path_planner_dir =
ament_index_cpp::get_package_share_directory("behavior_path_planner");
const auto behavior_path_lane_change_module_dir =
Expand All @@ -60,9 +59,9 @@ std::shared_ptr<BehaviorPathPlannerNode> generateNode()

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",
{test_utils_dir + "/config/test_common.param.yaml",
test_utils_dir + "/config/test_nearest_search.param.yaml",
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 <test_utils/test_utils.hpp>

#include <vector>

using autoware_planning_test_manager::PlanningInterfaceTestManager;
using behavior_path_planner::BehaviorPathPlannerNode;
using planning_test_utils::PlanningInterfaceTestManager;

std::shared_ptr<PlanningInterfaceTestManager> generateTestManager()
{
Expand All @@ -41,8 +41,7 @@ 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 test_utils_dir = ament_index_cpp::get_package_share_directory("test_utils");
const auto behavior_path_planner_dir =
ament_index_cpp::get_package_share_directory("behavior_path_planner");

Expand All @@ -54,9 +53,9 @@ std::shared_ptr<BehaviorPathPlannerNode> generateNode()
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",
node_options, {test_utils_dir + "/config/test_common.param.yaml",
test_utils_dir + "/config/test_nearest_search.param.yaml",
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

0 comments on commit 74d8207

Please sign in to comment.