From 3ddcb1d3841dc737e418dd7a81df938d12d7c176 Mon Sep 17 00:00:00 2001 From: Mateusz Palczuk Date: Tue, 12 Dec 2023 18:41:20 +0100 Subject: [PATCH 01/10] Add random_test_runner tests Signed-off-by: Mateusz Palczuk --- test_runner/random_test_runner/CMakeLists.txt | 10 +- test_runner/random_test_runner/package.xml | 1 + .../random_test_runner/test/CMakeLists.txt | 24 +++++ .../test/test_almost_standstill_metric.cpp | 64 ++++++++++++ .../test/test_data_types.cpp | 78 +++++++++++++++ .../test/test_ego_collision_metric.cpp | 98 +++++++++++++++++++ .../test/test_goal_reached_metric.cpp | 61 ++++++++++++ .../random_test_runner/test/test_utils.hpp | 50 ++++++++++ 8 files changed, 383 insertions(+), 3 deletions(-) create mode 100644 test_runner/random_test_runner/test/CMakeLists.txt create mode 100644 test_runner/random_test_runner/test/test_almost_standstill_metric.cpp create mode 100644 test_runner/random_test_runner/test/test_data_types.cpp create mode 100644 test_runner/random_test_runner/test/test_ego_collision_metric.cpp create mode 100644 test_runner/random_test_runner/test/test_goal_reached_metric.cpp create mode 100644 test_runner/random_test_runner/test/test_utils.hpp diff --git a/test_runner/random_test_runner/CMakeLists.txt b/test_runner/random_test_runner/CMakeLists.txt index d503ad51bd1..b8991b07e46 100644 --- a/test_runner/random_test_runner/CMakeLists.txt +++ b/test_runner/random_test_runner/CMakeLists.txt @@ -37,16 +37,15 @@ include(FindProtobuf REQUIRED) ament_auto_find_build_dependencies() -ament_auto_add_executable(random_test_runner +ament_auto_add_library(${PROJECT_NAME} SHARED src/data_types.cpp src/test_randomizer.cpp src/test_executor.cpp src/lanelet_utils.cpp src/random_test_runner.cpp - src/random_test_runner_node.cpp ) -target_link_libraries(random_test_runner +target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARY} ${YAML_CPP_LIBRARIES} pthread @@ -55,6 +54,10 @@ target_link_libraries(random_test_runner fmt ) +ament_auto_add_executable(${PROJECT_NAME}_node + src/${PROJECT_NAME}_node.cpp +) + install( DIRECTORY launch rviz include param DESTINATION share/${PROJECT_NAME} @@ -63,6 +66,7 @@ install( if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() + add_subdirectory(test) endif() ament_auto_package() diff --git a/test_runner/random_test_runner/package.xml b/test_runner/random_test_runner/package.xml index 48a3ef208ce..549bd883d07 100644 --- a/test_runner/random_test_runner/package.xml +++ b/test_runner/random_test_runner/package.xml @@ -20,6 +20,7 @@ ament_lint_auto ament_cmake_clang_format ament_cmake_copyright + ament_cmake_gtest ament_cmake_lint_cmake ament_cmake_pep257 ament_cmake_xmllint diff --git a/test_runner/random_test_runner/test/CMakeLists.txt b/test_runner/random_test_runner/test/CMakeLists.txt new file mode 100644 index 00000000000..bbb9fb1e4cb --- /dev/null +++ b/test_runner/random_test_runner/test/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright 2015 TIER IV, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +ament_add_gtest(test_almost_standstill_metric test_almost_standstill_metric.cpp) +ament_add_gtest(test_ego_collision_metric test_ego_collision_metric.cpp) +ament_add_gtest(test_goal_reached_metric test_goal_reached_metric.cpp) +ament_add_gtest(test_data_types test_data_types.cpp) +target_link_libraries(test_almost_standstill_metric ${PROJECT_NAME}) +target_link_libraries(test_ego_collision_metric ${PROJECT_NAME}) +target_link_libraries(test_goal_reached_metric ${PROJECT_NAME}) +target_link_libraries(test_data_types ${PROJECT_NAME}) diff --git a/test_runner/random_test_runner/test/test_almost_standstill_metric.cpp b/test_runner/random_test_runner/test/test_almost_standstill_metric.cpp new file mode 100644 index 00000000000..5905eac7363 --- /dev/null +++ b/test_runner/random_test_runner/test/test_almost_standstill_metric.cpp @@ -0,0 +1,64 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include + +#include "test_utils.hpp" + +TEST(Metrics, AlmostStandstillMetric_move) +{ + AlmostStandstillMetric metric; + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(0.0, 1.0, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(2.0, 1.0, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(4.0, 1.0, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(6.0, 1.0, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(8.0, 1.0, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(10.0, 1.0, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(12.0, 1.0, 0.0))); +} + +TEST(Metrics, AlmostStandstillMetric_almostStandstill) +{ + AlmostStandstillMetric metric; + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(0.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(2.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(4.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(6.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(8.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(10.0, 1e-3, 0.0))); + EXPECT_TRUE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(10.001, 1e-3, 0.0))); + EXPECT_TRUE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(12.0, 1e-3, 0.0))); +} + +TEST(Metrics, AlmostStandstillMetric_dataTimeout) +{ + AlmostStandstillMetric metric; + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(0.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(2.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(4.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(8.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(10.0, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(10.001, 1e-3, 0.0))); + EXPECT_FALSE(metric.isAlmostStandingStill(getCanonicalizedEntityStatus(12.0, 1e-3, 09.0))); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test_runner/random_test_runner/test/test_data_types.cpp b/test_runner/random_test_runner/test/test_data_types.cpp new file mode 100644 index 00000000000..6ce4a5fe5ef --- /dev/null +++ b/test_runner/random_test_runner/test/test_data_types.cpp @@ -0,0 +1,78 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include + +#include "test_utils.hpp" + +TEST(DataTypes, simulatorTypeFromString_correct) +{ + EXPECT_EQ( + simulatorTypeFromString("simple_sensor_simulator"), SimulatorType::SIMPLE_SENSOR_SIMULATOR); + EXPECT_EQ(simulatorTypeFromString("unity"), SimulatorType::UNITY); +} + +TEST(DataTypes, simulatorTypeFromString_incorrect) +{ + EXPECT_THROW(simulatorTypeFromString("unknown"), std::runtime_error); + EXPECT_THROW(simulatorTypeFromString("simple_sensor_simulator "), std::runtime_error); + EXPECT_THROW(simulatorTypeFromString(" simple_sensor_simulator"), std::runtime_error); + EXPECT_THROW(simulatorTypeFromString("unity "), std::runtime_error); + EXPECT_THROW(simulatorTypeFromString(" unity"), std::runtime_error); +} + +TEST(DataTypes, architectureTypeFromString_correct) +{ + EXPECT_EQ(architectureTypeFromString("awf/auto"), ArchitectureType::AWF_AUTO); + EXPECT_EQ(architectureTypeFromString("awf/universe"), ArchitectureType::AWF_UNIVERSE); + EXPECT_EQ(architectureTypeFromString("aawf/universe"), ArchitectureType::AWF_UNIVERSE); + EXPECT_EQ(architectureTypeFromString("awf/universee"), ArchitectureType::AWF_UNIVERSE); + EXPECT_EQ(architectureTypeFromString("awf/universe "), ArchitectureType::AWF_UNIVERSE); + EXPECT_EQ(architectureTypeFromString(" awf/universe"), ArchitectureType::AWF_UNIVERSE); + EXPECT_EQ(architectureTypeFromString(" awf/universe "), ArchitectureType::AWF_UNIVERSE); + EXPECT_EQ(architectureTypeFromString("tier4/proposal"), ArchitectureType::TIER4_PROPOSAL); +} + +TEST(DataTypes, architectureTypeFromString_incorrect) +{ + EXPECT_THROW(architectureTypeFromString("unknown"), std::runtime_error); + EXPECT_THROW(architectureTypeFromString("awf/auto "), std::runtime_error); + EXPECT_THROW(architectureTypeFromString(" awf/auto"), std::runtime_error); + EXPECT_THROW(architectureTypeFromString("tier4/proposal "), std::runtime_error); + EXPECT_THROW(architectureTypeFromString(" tier4/proposal"), std::runtime_error); +} + +TEST(DataTypes, stringFromArchitectureType_correct) +{ + EXPECT_EQ(stringFromArchitectureType(ArchitectureType::AWF_AUTO), "awf/auto"); + EXPECT_EQ(stringFromArchitectureType(ArchitectureType::AWF_UNIVERSE), "awf/universe"); + EXPECT_EQ(stringFromArchitectureType(ArchitectureType::TIER4_PROPOSAL), "tier4/proposal"); +} + +TEST(DataTypes, stringFromArchitectureType_incorrect) +{ + EXPECT_THROW(stringFromArchitectureType(static_cast(-1)), std::runtime_error); + EXPECT_THROW(stringFromArchitectureType(static_cast(3)), std::runtime_error); + EXPECT_THROW(stringFromArchitectureType(static_cast(4)), std::runtime_error); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test_runner/random_test_runner/test/test_ego_collision_metric.cpp b/test_runner/random_test_runner/test/test_ego_collision_metric.cpp new file mode 100644 index 00000000000..00348272ae5 --- /dev/null +++ b/test_runner/random_test_runner/test/test_ego_collision_metric.cpp @@ -0,0 +1,98 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include + +TEST(Metrics, EgoCollisionMetric_noCollision) +{ + EgoCollisionMetric metric; + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 0.4999)); +} + +TEST(Metrics, EgoCollisionMetric_collision) +{ + EgoCollisionMetric metric; + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.0)); + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.5001)); +} + +TEST(Metrics, EgoCollisionMetric_collisionOtherNPC) +{ + EgoCollisionMetric metric; + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.0)); + EXPECT_TRUE(metric.isThereEgosCollisionWith("other", 0.1)); + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.5001)); +} + +TEST(Metrics, EgoCollisionMetric_noCollisionUpdate) +{ + EgoCollisionMetric metric; + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 0.1)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 0.5999)); +} + +TEST(Metrics, EgoCollisionMetric_noCollisionUpdateOtherNPC) +{ + EgoCollisionMetric metric; + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 0.1)); + EXPECT_TRUE(metric.isThereEgosCollisionWith("other", 0.4)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 0.5999)); +} + +TEST(Metrics, EgoCollisionMetric_collisionUpdate) +{ + EgoCollisionMetric metric; + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 0.1)); + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.6001)); +} + +TEST(Metrics, EgoCollisionMetric_collisionUpdateOtherNPC) +{ + EgoCollisionMetric metric; + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 0.1)); + EXPECT_TRUE(metric.isThereEgosCollisionWith("other", 0.4)); + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.6001)); +} + +TEST(Metrics, EgoCollisionMetric_collisionAfterLongTime) +{ + EgoCollisionMetric metric; + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 0.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 0.5)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 1.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 1.5)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 2.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 2.5)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 3.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 3.5)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 4.0)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 4.5)); + EXPECT_FALSE(metric.isThereEgosCollisionWith("npc", 5.0)); + EXPECT_TRUE(metric.isThereEgosCollisionWith("npc", 6.0)); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test_runner/random_test_runner/test/test_goal_reached_metric.cpp b/test_runner/random_test_runner/test/test_goal_reached_metric.cpp new file mode 100644 index 00000000000..8b02235e024 --- /dev/null +++ b/test_runner/random_test_runner/test/test_goal_reached_metric.cpp @@ -0,0 +1,61 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include + +#include "test_utils.hpp" + +TEST(Metrics, GoalReachedMetric_noGoal) +{ + GoalReachedMetric metric; + EXPECT_FALSE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, 0.0))); +} + +TEST(Metrics, GoalReachedMetric_goalNotReached) +{ + GoalReachedMetric metric; + metric.setGoal(geometry_msgs::build() + .position(geometry_msgs::build().x(5.0).y(5.0).z(0.0)) + .orientation(geometry_msgs::msg::Quaternion())); + EXPECT_FALSE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, 0.0))); + EXPECT_FALSE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, 5.0))); + EXPECT_FALSE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, 0.0, 5.0))); + EXPECT_FALSE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, 5.0, 10.0))); + EXPECT_FALSE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, 10.0, 5.0))); +} + +TEST(Metrics, GoalReachedMetric_goalReached) +{ + GoalReachedMetric metric; + metric.setGoal(geometry_msgs::build() + .position(geometry_msgs::build().x(5.0).y(5.0).z(0.0)) + .orientation(geometry_msgs::msg::Quaternion())); + constexpr double a = std::sqrt(3.0) - 1e-3; + constexpr double less = 5.0 - a; + constexpr double more = 5.0 + a; + EXPECT_TRUE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, less, less))); + EXPECT_TRUE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, less, more))); + EXPECT_TRUE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, more, more))); + EXPECT_TRUE(metric.isGoalReached(getCanonicalizedEntityStatus(0.0, 0.0, more, less))); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test_runner/random_test_runner/test/test_utils.hpp b/test_runner/random_test_runner/test/test_utils.hpp new file mode 100644 index 00000000000..a257afa5d14 --- /dev/null +++ b/test_runner/random_test_runner/test/test_utils.hpp @@ -0,0 +1,50 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include +#include +#include + +traffic_simulator::CanonicalizedEntityStatus getCanonicalizedEntityStatus( + const double time, const double twist_x, const double x, const double y = 0.0, + const double z = 0.0, const std::string & name = "name") +{ + static const std::string path = + ament_index_cpp::get_package_share_directory("traffic_simulator") + "/map/lanelet2_map.osm"; + static const auto origin = geographic_msgs::build() + .latitude(35.61836750154) + .longitude(139.78066608243) + .altitude(0.0); + static const auto hdmap_utils_ptr = std::make_shared(path, origin); + + traffic_simulator::EntityStatus entity_status; + entity_status.type.type = traffic_simulator_msgs::msg::EntityType::VEHICLE; + entity_status.subtype.value = traffic_simulator_msgs::msg::EntitySubtype::CAR; + entity_status.time = time; + entity_status.name = name; + + traffic_simulator_msgs::msg::ActionStatus action_status; + action_status.current_action = std::string("action"); + action_status.twist.linear = + geometry_msgs::build().x(twist_x).y(0.0).z(0.0); + action_status.accel = geometry_msgs::msg::Accel(); + entity_status.action_status = action_status; + entity_status.pose.position.x = x; + entity_status.pose.position.y = y; + entity_status.pose.position.z = z; + entity_status.lanelet_pose_valid = false; + return traffic_simulator::CanonicalizedEntityStatus(entity_status, hdmap_utils_ptr); +} From 27e7730f7dee53e91ae631c461beb6b0bf28b00f Mon Sep 17 00:00:00 2001 From: Mateusz Palczuk Date: Wed, 13 Dec 2023 13:50:50 +0100 Subject: [PATCH 02/10] Add lanelet map and LaneletUtils tests Signed-off-by: Mateusz Palczuk --- test_runner/random_test_runner/CMakeLists.txt | 2 +- .../random_test_runner/test/CMakeLists.txt | 2 + .../test/expect_eq_macros.hpp | 54 + .../test/map/lanelet2_map.osm | 5346 ++++++++++++++ .../map/with_road_shoulder/lanelet2_map.osm | 6259 +++++++++++++++++ .../test/test_lanelet_utils.cpp | 275 + .../random_test_runner/test/test_utils.hpp | 11 +- 7 files changed, 11947 insertions(+), 2 deletions(-) create mode 100644 test_runner/random_test_runner/test/expect_eq_macros.hpp create mode 100644 test_runner/random_test_runner/test/map/lanelet2_map.osm create mode 100644 test_runner/random_test_runner/test/map/with_road_shoulder/lanelet2_map.osm create mode 100644 test_runner/random_test_runner/test/test_lanelet_utils.cpp diff --git a/test_runner/random_test_runner/CMakeLists.txt b/test_runner/random_test_runner/CMakeLists.txt index b8991b07e46..bf509d7c24e 100644 --- a/test_runner/random_test_runner/CMakeLists.txt +++ b/test_runner/random_test_runner/CMakeLists.txt @@ -59,7 +59,7 @@ ament_auto_add_executable(${PROJECT_NAME}_node ) install( - DIRECTORY launch rviz include param + DIRECTORY launch rviz include param test/map DESTINATION share/${PROJECT_NAME} ) diff --git a/test_runner/random_test_runner/test/CMakeLists.txt b/test_runner/random_test_runner/test/CMakeLists.txt index bbb9fb1e4cb..439025bb546 100644 --- a/test_runner/random_test_runner/test/CMakeLists.txt +++ b/test_runner/random_test_runner/test/CMakeLists.txt @@ -18,7 +18,9 @@ ament_add_gtest(test_almost_standstill_metric test_almost_standstill_metric.cpp) ament_add_gtest(test_ego_collision_metric test_ego_collision_metric.cpp) ament_add_gtest(test_goal_reached_metric test_goal_reached_metric.cpp) ament_add_gtest(test_data_types test_data_types.cpp) +ament_add_gtest(test_lanelet_utils test_lanelet_utils.cpp) target_link_libraries(test_almost_standstill_metric ${PROJECT_NAME}) target_link_libraries(test_ego_collision_metric ${PROJECT_NAME}) target_link_libraries(test_goal_reached_metric ${PROJECT_NAME}) target_link_libraries(test_data_types ${PROJECT_NAME}) +target_link_libraries(test_lanelet_utils ${PROJECT_NAME}) diff --git a/test_runner/random_test_runner/test/expect_eq_macros.hpp b/test_runner/random_test_runner/test/expect_eq_macros.hpp new file mode 100644 index 00000000000..38052da1a90 --- /dev/null +++ b/test_runner/random_test_runner/test/expect_eq_macros.hpp @@ -0,0 +1,54 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#ifndef RANDOM_TEST_RUNNER__TEST__EXPECT_EQ_MACROS_HPP_ +#define RANDOM_TEST_RUNNER__TEST__EXPECT_EQ_MACROS_HPP_ + +#include + +#include + +#define EXPECT_LANELET_POSE_NEAR(DATA0, DATA1, TOLERANCE) \ + EXPECT_EQ(DATA0.lanelet_id, DATA1.lanelet_id); \ + EXPECT_NEAR(DATA0.s, DATA1.s, TOLERANCE); + +#define EXPECT_POINT_EQ(DATA0, DATA1) \ + EXPECT_DOUBLE_EQ(DATA0.x, DATA1.x); \ + EXPECT_DOUBLE_EQ(DATA0.y, DATA1.y); \ + EXPECT_DOUBLE_EQ(DATA0.z, DATA1.z); + +#define EXPECT_POINT_NEAR(DATA0, DATA1, TOLERANCE) \ + EXPECT_NEAR(DATA0.x, DATA1.x, TOLERANCE); \ + EXPECT_NEAR(DATA0.y, DATA1.y, TOLERANCE); \ + EXPECT_NEAR(DATA0.z, DATA1.z, TOLERANCE); + +#define EXPECT_QUATERNION_EQ(DATA0, DATA1) \ + EXPECT_DOUBLE_EQ(DATA0.x, DATA1.x); \ + EXPECT_DOUBLE_EQ(DATA0.y, DATA1.y); \ + EXPECT_DOUBLE_EQ(DATA0.z, DATA1.z); \ + EXPECT_DOUBLE_EQ(DATA0.w, DATA1.w); + +#define EXPECT_QUATERNION_NEAR(DATA0, DATA1, TOLERANCE) \ + EXPECT_NEAR(DATA0.x, DATA1.x, TOLERANCE); \ + EXPECT_NEAR(DATA0.y, DATA1.y, TOLERANCE); \ + EXPECT_NEAR(DATA0.z, DATA1.z, TOLERANCE); \ + EXPECT_NEAR(DATA0.w, DATA1.w, TOLERANCE); + +#define EXPECT_POSE_NEAR(DATA0, DATA1, TOLERANCE) \ + EXPECT_POINT_NEAR(DATA0.position, DATA1.position, TOLERANCE); \ + EXPECT_QUATERNION_NEAR(DATA0.orientation, DATA1.orientation, TOLERANCE); + +#endif // RANDOM_TEST_RUNNER__TEST__EXPECT_EQ_MACROS_HPP_ diff --git a/test_runner/random_test_runner/test/map/lanelet2_map.osm b/test_runner/random_test_runner/test/map/lanelet2_map.osm new file mode 100644 index 00000000000..077647823b7 --- /dev/null +++ b/test_runner/random_test_runner/test/map/lanelet2_map.osm @@ -0,0 +1,5346 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test_runner/random_test_runner/test/map/with_road_shoulder/lanelet2_map.osm b/test_runner/random_test_runner/test/map/with_road_shoulder/lanelet2_map.osm new file mode 100644 index 00000000000..d7e7eed74fa --- /dev/null +++ b/test_runner/random_test_runner/test/map/with_road_shoulder/lanelet2_map.osm @@ -0,0 +1,6259 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test_runner/random_test_runner/test/test_lanelet_utils.cpp b/test_runner/random_test_runner/test/test_lanelet_utils.cpp new file mode 100644 index 00000000000..1f685ab44f8 --- /dev/null +++ b/test_runner/random_test_runner/test/test_lanelet_utils.cpp @@ -0,0 +1,275 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include + +#include "expect_eq_macros.hpp" +#include "test_utils.hpp" + +constexpr double EPS = 1e-6; + +LaneletUtils & getLaneletUtils() +{ + static const std::string path = + ament_index_cpp::get_package_share_directory("random_test_runner") + "/map/lanelet2_map.osm"; + static LaneletUtils utils(path); + return utils; +} + +TEST(LaneletUtils, initialize) +{ + const std::string path = + ament_index_cpp::get_package_share_directory("random_test_runner") + "/map/lanelet2_map.osm"; + EXPECT_NO_THROW(LaneletUtils utils(path)); +} + +TEST(LaneletUtils, computeDistance) +{ + traffic_simulator_msgs::msg::LaneletPose from = makeLaneletPose(34621, 0.0), + to = makeLaneletPose(34621, 1.0); + EXPECT_NEAR(1.0, getLaneletUtils().computeDistance(from, to), EPS); +} + +TEST(LaneletUtils, computeDistance_reverse) +{ + traffic_simulator_msgs::msg::LaneletPose from = makeLaneletPose(34621, 21.3), + to = makeLaneletPose(34621, 17.7); + EXPECT_NEAR(getLaneletUtils().computeDistance(from, to), 3.6, EPS); +} + +TEST(LaneletUtils, computeDistance_differentLanelet) +{ + traffic_simulator_msgs::msg::LaneletPose from = makeLaneletPose(34594, 15.0), + to = makeLaneletPose(34621, 5.0); + EXPECT_NEAR(getLaneletUtils().computeDistance(from, to), 10.032117179351, 1e-2); +} + +TEST(LaneletUtils, getOppositeLanelet) +{ + traffic_simulator_msgs::msg::LaneletPose pose = makeLaneletPose(34621, 5.0); + std::optional opposite = + getLaneletUtils().getOppositeLaneLet(pose); + EXPECT_TRUE(opposite); + EXPECT_LANELET_POSE_NEAR(opposite.value(), makeLaneletPose(34981, 3.611), 1e-2); +} + +TEST(LaneletUtils, getOppositeLanelet_notExisting) +{ + traffic_simulator_msgs::msg::LaneletPose pose = makeLaneletPose(1, 0.0); + std::optional opposite = + getLaneletUtils().getOppositeLaneLet(pose); + EXPECT_FALSE(opposite); +} + +TEST(LaneletUtils, getLanesWithinDistance_incorrectDistances) +{ + traffic_simulator_msgs::msg::LaneletPose pose = makeLaneletPose(34621, 5.0); + EXPECT_THROW(getLaneletUtils().getLanesWithinDistance(pose, 1.0, 0.0), std::runtime_error); +} +#include +TEST(LaneletUtils, getLanesWithinDistance_straightRoad) +{ + traffic_simulator_msgs::msg::LaneletPose pose = makeLaneletPose(34462, 15.0); + EXPECT_NO_THROW(getLaneletUtils().getLanesWithinDistance(pose, 0.0, 10.0)); + std::vector lanes = getLaneletUtils().getLanesWithinDistance(pose, 0.0, 10.0); + EXPECT_EQ(lanes.size(), size_t(4)); + EXPECT_EQ(lanes[0].lanelet_id, 34462); + EXPECT_EQ(lanes[1].lanelet_id, 34462); + EXPECT_EQ(lanes[2].lanelet_id, 34513); + EXPECT_EQ(lanes[3].lanelet_id, 34513); +} + +TEST(LaneletUtils, getLanesWithinDistance_intersection) +{ + traffic_simulator_msgs::msg::LaneletPose pose = makeLaneletPose(34621, 5.0); + EXPECT_NO_THROW(getLaneletUtils().getLanesWithinDistance(pose, 0.0, 10.0)); + std::vector lanes = getLaneletUtils().getLanesWithinDistance(pose, 0.0, 10.0); + EXPECT_EQ(lanes.size(), size_t(13)); + EXPECT_EQ(lanes[0].lanelet_id, 34585); + EXPECT_EQ(lanes[1].lanelet_id, 34594); + EXPECT_EQ(lanes[2].lanelet_id, 34621); + EXPECT_EQ(lanes[3].lanelet_id, 34621); + EXPECT_EQ(lanes[4].lanelet_id, 34636); + EXPECT_EQ(lanes[5].lanelet_id, 34642); + EXPECT_EQ(lanes[6].lanelet_id, 34645); + EXPECT_EQ(lanes[7].lanelet_id, 34651); + EXPECT_EQ(lanes[8].lanelet_id, 34976); + EXPECT_EQ(lanes[9].lanelet_id, 34981); + EXPECT_EQ(lanes[10].lanelet_id, 34981); + EXPECT_EQ(lanes[11].lanelet_id, 35001); + EXPECT_EQ(lanes[12].lanelet_id, 35051); +} + +TEST(LaneletUtils, getLaneletIds) +{ + EXPECT_NO_THROW(getLaneletUtils().getLaneletIds()); + const auto ids = getLaneletUtils().getLaneletIds(); + EXPECT_EQ(ids.size(), size_t(83)); + unsigned int idx = 0; + EXPECT_EQ(ids[idx++], 35051); + EXPECT_EQ(ids[idx++], 35036); + EXPECT_EQ(ids[idx++], 35001); + EXPECT_EQ(ids[idx++], 34850); + EXPECT_EQ(ids[idx++], 34786); + EXPECT_EQ(ids[idx++], 34783); + EXPECT_EQ(ids[idx++], 35031); + EXPECT_EQ(ids[idx++], 34777); + EXPECT_EQ(ids[idx++], 34774); + EXPECT_EQ(ids[idx++], 34768); + EXPECT_EQ(ids[idx++], 35016); + EXPECT_EQ(ids[idx++], 34762); + EXPECT_EQ(ids[idx++], 34603); + EXPECT_EQ(ids[idx++], 120659); + EXPECT_EQ(ids[idx++], 34426); + EXPECT_EQ(ids[idx++], 34591); + EXPECT_EQ(ids[idx++], 34795); + EXPECT_EQ(ids[idx++], 34414); + EXPECT_EQ(ids[idx++], 34579); + EXPECT_EQ(ids[idx++], 34756); + EXPECT_EQ(ids[idx++], 34576); + EXPECT_EQ(ids[idx++], 34780); + EXPECT_EQ(ids[idx++], 34399); + EXPECT_EQ(ids[idx++], 34753); + EXPECT_EQ(ids[idx++], 34570); + EXPECT_EQ(ids[idx++], 34564); + EXPECT_EQ(ids[idx++], 34741); + EXPECT_EQ(ids[idx++], 34976); + EXPECT_EQ(ids[idx++], 34468); + EXPECT_EQ(ids[idx++], 35026); + EXPECT_EQ(ids[idx++], 34645); + EXPECT_EQ(ids[idx++], 34465); + EXPECT_EQ(ids[idx++], 34642); + EXPECT_EQ(ids[idx++], 34585); + EXPECT_EQ(ids[idx++], 34789); + EXPECT_EQ(ids[idx++], 34408); + EXPECT_EQ(ids[idx++], 34498); + EXPECT_EQ(ids[idx++], 34675); + EXPECT_EQ(ids[idx++], 35046); + EXPECT_EQ(ids[idx++], 34792); + EXPECT_EQ(ids[idx++], 34411); + EXPECT_EQ(ids[idx++], 34392); + EXPECT_EQ(ids[idx++], 34510); + EXPECT_EQ(ids[idx++], 34438); + EXPECT_EQ(ids[idx++], 34615); + EXPECT_EQ(ids[idx++], 34495); + EXPECT_EQ(ids[idx++], 34672); + EXPECT_EQ(ids[idx++], 34621); + EXPECT_EQ(ids[idx++], 34594); + EXPECT_EQ(ids[idx++], 34507); + EXPECT_EQ(ids[idx++], 34684); + EXPECT_EQ(ids[idx++], 34420); + EXPECT_EQ(ids[idx++], 34423); + EXPECT_EQ(ids[idx++], 34981); + EXPECT_EQ(ids[idx++], 34600); + EXPECT_EQ(ids[idx++], 34462); + EXPECT_EQ(ids[idx++], 34385); + EXPECT_EQ(ids[idx++], 34639); + EXPECT_EQ(ids[idx++], 35021); + EXPECT_EQ(ids[idx++], 34513); + EXPECT_EQ(ids[idx++], 34690); + EXPECT_EQ(ids[idx++], 34441); + EXPECT_EQ(ids[idx++], 34606); + EXPECT_EQ(ids[idx++], 34624); + EXPECT_EQ(ids[idx++], 34630); + EXPECT_EQ(ids[idx++], 34633); + EXPECT_EQ(ids[idx++], 34636); + EXPECT_EQ(ids[idx++], 34648); + EXPECT_EQ(ids[idx++], 34651); + EXPECT_EQ(ids[idx++], 34654); + EXPECT_EQ(ids[idx++], 34666); + EXPECT_EQ(ids[idx++], 34678); + EXPECT_EQ(ids[idx++], 120660); + EXPECT_EQ(ids[idx++], 34681); + EXPECT_EQ(ids[idx++], 120545); + EXPECT_EQ(ids[idx++], 34693); + EXPECT_EQ(ids[idx++], 34696); + EXPECT_EQ(ids[idx++], 34705); + EXPECT_EQ(ids[idx++], 34708); + EXPECT_EQ(ids[idx++], 34744); + EXPECT_EQ(ids[idx++], 34750); + EXPECT_EQ(ids[idx++], 34378); + EXPECT_EQ(ids[idx++], 34759); +} + +TEST(LaneletUtils, toMapPose) +{ + const traffic_simulator_msgs::msg::LaneletPose pose = makeLaneletPose(34621, 10.0); + EXPECT_NO_THROW(getLaneletUtils().toMapPose(pose)); + EXPECT_POSE_NEAR( + getLaneletUtils().toMapPose(pose).pose, + geometry_msgs::build() + .position(geometry_msgs::build() + .x(3747.3511648127) + .y(73735.0699484234) + .z(0.3034051453)) + .orientation(geometry_msgs::build() + .x(0.0) + .y(0.0) + .z(-0.9719821398) + .w(0.2350547166)), + EPS); +} + +TEST(LaneletUtils, getRoute_turn) +{ + EXPECT_NO_THROW(getLaneletUtils().getRoute(34681, 34513)); + const std::vector route = getLaneletUtils().getRoute(34681, 34513); + EXPECT_EQ(route.size(), size_t(3)); + EXPECT_EQ(route[0], 34681); + EXPECT_EQ(route[1], 34684); + EXPECT_EQ(route[2], 34513); +} + +TEST(LaneletUtils, getRoute_intersection) +{ + EXPECT_NO_THROW(getLaneletUtils().getRoute(34600, 34621)); + const std::vector route = getLaneletUtils().getRoute(34600, 34621); + EXPECT_EQ(route.size(), size_t(3)); + EXPECT_EQ(route[0], 34600); + EXPECT_EQ(route[1], 34594); + EXPECT_EQ(route[2], 34621); +} + +TEST(LaneletUtils, getLaneletLength) +{ + EXPECT_NEAR(getLaneletUtils().getLaneletLength(34621), 49.9125380565, EPS); + EXPECT_NEAR(getLaneletUtils().getLaneletLength(34507), 55.4273243719, EPS); + EXPECT_NEAR(getLaneletUtils().getLaneletLength(34570), 19.5778003979, EPS); +} + +TEST(LaneletUtils, isInLanelet) +{ + // lanelet 34621 + EXPECT_TRUE(getLaneletUtils().isInLanelet(34621, 10.0)); + EXPECT_FALSE(getLaneletUtils().isInLanelet(34621, -1.0)); + EXPECT_FALSE(getLaneletUtils().isInLanelet(34621, 50.0)); + // lanelet 34507 + EXPECT_TRUE(getLaneletUtils().isInLanelet(34507, 10.0)); + EXPECT_FALSE(getLaneletUtils().isInLanelet(34507, -1.0)); + EXPECT_FALSE(getLaneletUtils().isInLanelet(34507, 56.0)); + // lanelet 34570 + EXPECT_TRUE(getLaneletUtils().isInLanelet(34570, 10.0)); + EXPECT_FALSE(getLaneletUtils().isInLanelet(34570, -1.0)); + EXPECT_FALSE(getLaneletUtils().isInLanelet(34570, 20.0)); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test_runner/random_test_runner/test/test_utils.hpp b/test_runner/random_test_runner/test/test_utils.hpp index a257afa5d14..272ef5a18e9 100644 --- a/test_runner/random_test_runner/test/test_utils.hpp +++ b/test_runner/random_test_runner/test/test_utils.hpp @@ -23,7 +23,7 @@ traffic_simulator::CanonicalizedEntityStatus getCanonicalizedEntityStatus( const double z = 0.0, const std::string & name = "name") { static const std::string path = - ament_index_cpp::get_package_share_directory("traffic_simulator") + "/map/lanelet2_map.osm"; + ament_index_cpp::get_package_share_directory("random_test_runner") + "/map/lanelet2_map.osm"; static const auto origin = geographic_msgs::build() .latitude(35.61836750154) .longitude(139.78066608243) @@ -48,3 +48,12 @@ traffic_simulator::CanonicalizedEntityStatus getCanonicalizedEntityStatus( entity_status.lanelet_pose_valid = false; return traffic_simulator::CanonicalizedEntityStatus(entity_status, hdmap_utils_ptr); } + +inline traffic_simulator_msgs::msg::LaneletPose makeLaneletPose( + const long int lane_id, const double s) +{ + traffic_simulator_msgs::msg::LaneletPose lanelet_pose; + lanelet_pose.lanelet_id = lane_id; + lanelet_pose.s = s; + return lanelet_pose; +} From 21886ea89f44145ce34e47772ca294adbd727e59 Mon Sep 17 00:00:00 2001 From: Mateusz Palczuk Date: Wed, 13 Dec 2023 15:01:48 +0100 Subject: [PATCH 03/10] Add Randomizers tests Signed-off-by: Mateusz Palczuk --- .../random_test_runner/test/CMakeLists.txt | 2 + .../test/expect_eq_macros.hpp | 4 + .../test/test_randomizers.cpp | 107 ++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 test_runner/random_test_runner/test/test_randomizers.cpp diff --git a/test_runner/random_test_runner/test/CMakeLists.txt b/test_runner/random_test_runner/test/CMakeLists.txt index 439025bb546..5dc44ad881e 100644 --- a/test_runner/random_test_runner/test/CMakeLists.txt +++ b/test_runner/random_test_runner/test/CMakeLists.txt @@ -19,8 +19,10 @@ ament_add_gtest(test_ego_collision_metric test_ego_collision_metric.cpp) ament_add_gtest(test_goal_reached_metric test_goal_reached_metric.cpp) ament_add_gtest(test_data_types test_data_types.cpp) ament_add_gtest(test_lanelet_utils test_lanelet_utils.cpp) +ament_add_gtest(test_randomizers test_randomizers.cpp) target_link_libraries(test_almost_standstill_metric ${PROJECT_NAME}) target_link_libraries(test_ego_collision_metric ${PROJECT_NAME}) target_link_libraries(test_goal_reached_metric ${PROJECT_NAME}) target_link_libraries(test_data_types ${PROJECT_NAME}) target_link_libraries(test_lanelet_utils ${PROJECT_NAME}) +target_link_libraries(test_randomizers ${PROJECT_NAME}) diff --git a/test_runner/random_test_runner/test/expect_eq_macros.hpp b/test_runner/random_test_runner/test/expect_eq_macros.hpp index 38052da1a90..09b44384136 100644 --- a/test_runner/random_test_runner/test/expect_eq_macros.hpp +++ b/test_runner/random_test_runner/test/expect_eq_macros.hpp @@ -51,4 +51,8 @@ EXPECT_POINT_NEAR(DATA0.position, DATA1.position, TOLERANCE); \ EXPECT_QUATERNION_NEAR(DATA0.orientation, DATA1.orientation, TOLERANCE); +#define EXPECT_IN_RANGE(VAL, MIN, MAX) \ + EXPECT_GE((VAL), (MIN)); \ + EXPECT_LE((VAL), (MAX)) + #endif // RANDOM_TEST_RUNNER__TEST__EXPECT_EQ_MACROS_HPP_ diff --git a/test_runner/random_test_runner/test/test_randomizers.cpp b/test_runner/random_test_runner/test/test_randomizers.cpp new file mode 100644 index 00000000000..01f4db18ada --- /dev/null +++ b/test_runner/random_test_runner/test/test_randomizers.cpp @@ -0,0 +1,107 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include + +#include "expect_eq_macros.hpp" + +TEST(Randomizers, LaneletIdRandomizer_generate255) +{ + RandomizationEnginePtr engine = std::make_shared(); + LaneletIdRandomizer rand(engine, 0, 255); + int sum = 0; + for (int i = 0; i < 1e+6; ++i) { + const auto generated = rand.generate(); + sum += generated; + EXPECT_IN_RANGE(generated, 0, 255); + } + EXPECT_NEAR(static_cast(sum) / 1e+6, 127.5, 1.0); +} + +TEST(Randomizers, LaneletIdRandomizer_generate10) +{ + RandomizationEnginePtr engine = std::make_shared(); + LaneletIdRandomizer rand(engine, 0, 10); + int sum = 0; + for (int i = 0; i < 1e+6; ++i) { + const auto generated = rand.generate(); + sum += generated; + EXPECT_IN_RANGE(generated, 0, 10); + } + EXPECT_NEAR(static_cast(sum) / 1e+6, 5.0, 0.1); +} + +TEST(Randomizers, LaneletIdRandomizer_setRange10) +{ + RandomizationEnginePtr engine = std::make_shared(); + LaneletIdRandomizer rand(engine, 0, 255); + rand.setRange(10, 20); + int sum = 0; + for (int i = 0; i < 1e+6; ++i) { + const auto generated = rand.generate(); + sum += generated; + EXPECT_IN_RANGE(generated, 10, 20); + } + EXPECT_NEAR(static_cast(sum) / 1e+6, 15.0, 0.1); +} + +TEST(Randomizers, SValueRandomizer_generate100) +{ + RandomizationEnginePtr engine = std::make_shared(); + SValueRandomizer rand(engine, 0.0, 100.0); + double sum = 0.0; + for (int i = 0; i < 1e+6; ++i) { + const auto generated = rand.generate(); + sum += generated; + EXPECT_IN_RANGE(generated, 0.0, 100.0); + } + EXPECT_NEAR(sum / 1e+6, 50.0, 1.0); +} + +TEST(Randomizers, SValueRandomizer_generate1) +{ + RandomizationEnginePtr engine = std::make_shared(); + SValueRandomizer rand(engine, 0.0, 1.0); + double sum = 0.0; + for (int i = 0; i < 1e+6; ++i) { + const auto generated = rand.generate(); + sum += generated; + EXPECT_IN_RANGE(generated, 0.0, 1.0); + } + EXPECT_NEAR(sum / 1e+6, 0.5, 0.1); +} + +TEST(Randomizers, SValueRandomizer_setRange1) +{ + RandomizationEnginePtr engine = std::make_shared(); + SValueRandomizer rand(engine, 0.0, 100.0); + rand.setRange(1.0, 2.0); + double sum = 0.0; + for (int i = 0; i < 1e+6; ++i) { + const auto generated = rand.generate(); + sum += generated; + EXPECT_IN_RANGE(generated, 1.0, 2.0); + } + EXPECT_NEAR(sum / 1e+6, 1.5, 0.1); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} From b11b8febfecfa945c0e24925264b778361b9f6f9 Mon Sep 17 00:00:00 2001 From: Mateusz Palczuk Date: Wed, 13 Dec 2023 15:17:08 +0100 Subject: [PATCH 04/10] Fix and add randomizer tests Signed-off-by: Mateusz Palczuk --- .../test/test_randomizers.cpp | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/test_runner/random_test_runner/test/test_randomizers.cpp b/test_runner/random_test_runner/test/test_randomizers.cpp index 01f4db18ada..171e0cf0c27 100644 --- a/test_runner/random_test_runner/test/test_randomizers.cpp +++ b/test_runner/random_test_runner/test/test_randomizers.cpp @@ -20,10 +20,10 @@ #include "expect_eq_macros.hpp" -TEST(Randomizers, LaneletIdRandomizer_generate255) +TEST(UniformRandomizer, int_generate255) { RandomizationEnginePtr engine = std::make_shared(); - LaneletIdRandomizer rand(engine, 0, 255); + UniformRandomizer rand(engine, 0, 255); int sum = 0; for (int i = 0; i < 1e+6; ++i) { const auto generated = rand.generate(); @@ -33,10 +33,10 @@ TEST(Randomizers, LaneletIdRandomizer_generate255) EXPECT_NEAR(static_cast(sum) / 1e+6, 127.5, 1.0); } -TEST(Randomizers, LaneletIdRandomizer_generate10) +TEST(UniformRandomizer, int_generate10) { RandomizationEnginePtr engine = std::make_shared(); - LaneletIdRandomizer rand(engine, 0, 10); + UniformRandomizer rand(engine, 0, 10); int sum = 0; for (int i = 0; i < 1e+6; ++i) { const auto generated = rand.generate(); @@ -46,10 +46,21 @@ TEST(Randomizers, LaneletIdRandomizer_generate10) EXPECT_NEAR(static_cast(sum) / 1e+6, 5.0, 0.1); } -TEST(Randomizers, LaneletIdRandomizer_setRange10) +TEST(UniformRandomizer, int_generate10seed) +{ + RandomizationEnginePtr engine = std::make_shared(1); + UniformRandomizer rand(engine, 0, 10); + EXPECT_EQ(rand.generate(), 4); + EXPECT_EQ(rand.generate(), 10); + EXPECT_EQ(rand.generate(), 7); + EXPECT_EQ(rand.generate(), 10); + EXPECT_EQ(rand.generate(), 0); +} + +TEST(UniformRandomizer, int_setRange10) { RandomizationEnginePtr engine = std::make_shared(); - LaneletIdRandomizer rand(engine, 0, 255); + UniformRandomizer rand(engine, 0, 255); rand.setRange(10, 20); int sum = 0; for (int i = 0; i < 1e+6; ++i) { @@ -60,10 +71,10 @@ TEST(Randomizers, LaneletIdRandomizer_setRange10) EXPECT_NEAR(static_cast(sum) / 1e+6, 15.0, 0.1); } -TEST(Randomizers, SValueRandomizer_generate100) +TEST(UniformRandomizer, double_generate100) { RandomizationEnginePtr engine = std::make_shared(); - SValueRandomizer rand(engine, 0.0, 100.0); + UniformRandomizer rand(engine, 0.0, 100.0); double sum = 0.0; for (int i = 0; i < 1e+6; ++i) { const auto generated = rand.generate(); @@ -73,10 +84,10 @@ TEST(Randomizers, SValueRandomizer_generate100) EXPECT_NEAR(sum / 1e+6, 50.0, 1.0); } -TEST(Randomizers, SValueRandomizer_generate1) +TEST(UniformRandomizer, double_generate1) { RandomizationEnginePtr engine = std::make_shared(); - SValueRandomizer rand(engine, 0.0, 1.0); + UniformRandomizer rand(engine, 0.0, 1.0); double sum = 0.0; for (int i = 0; i < 1e+6; ++i) { const auto generated = rand.generate(); @@ -86,10 +97,21 @@ TEST(Randomizers, SValueRandomizer_generate1) EXPECT_NEAR(sum / 1e+6, 0.5, 0.1); } -TEST(Randomizers, SValueRandomizer_setRange1) +TEST(UniformRandomizer, double_generate1seed) +{ + RandomizationEnginePtr engine = std::make_shared(1); + UniformRandomizer rand(engine, 0.0, 1.0); + EXPECT_NEAR(rand.generate(), 0.997185, 1e-6); + EXPECT_NEAR(rand.generate(), 0.932557, 1e-6); + EXPECT_NEAR(rand.generate(), 0.128124, 1e-6); + EXPECT_NEAR(rand.generate(), 0.999041, 1e-6); + EXPECT_NEAR(rand.generate(), 0.236089, 1e-6); +} + +TEST(UniformRandomizer, double_setRange1) { RandomizationEnginePtr engine = std::make_shared(); - SValueRandomizer rand(engine, 0.0, 100.0); + UniformRandomizer rand(engine, 0.0, 100.0); rand.setRange(1.0, 2.0); double sum = 0.0; for (int i = 0; i < 1e+6; ++i) { From f8a0636d8a8a1a586ca0d3d143c5a315ae11635a Mon Sep 17 00:00:00 2001 From: Mateusz Palczuk Date: Wed, 13 Dec 2023 17:06:11 +0100 Subject: [PATCH 05/10] Move helper function Signed-off-by: Mateusz Palczuk --- .../random_test_runner/test/test_lanelet_utils.cpp | 8 -------- test_runner/random_test_runner/test/test_utils.hpp | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test_runner/random_test_runner/test/test_lanelet_utils.cpp b/test_runner/random_test_runner/test/test_lanelet_utils.cpp index 1f685ab44f8..0171d21472c 100644 --- a/test_runner/random_test_runner/test/test_lanelet_utils.cpp +++ b/test_runner/random_test_runner/test/test_lanelet_utils.cpp @@ -23,14 +23,6 @@ constexpr double EPS = 1e-6; -LaneletUtils & getLaneletUtils() -{ - static const std::string path = - ament_index_cpp::get_package_share_directory("random_test_runner") + "/map/lanelet2_map.osm"; - static LaneletUtils utils(path); - return utils; -} - TEST(LaneletUtils, initialize) { const std::string path = diff --git a/test_runner/random_test_runner/test/test_utils.hpp b/test_runner/random_test_runner/test/test_utils.hpp index 272ef5a18e9..21ac31e9ffc 100644 --- a/test_runner/random_test_runner/test/test_utils.hpp +++ b/test_runner/random_test_runner/test/test_utils.hpp @@ -15,6 +15,7 @@ // Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. #include +#include #include #include @@ -57,3 +58,11 @@ inline traffic_simulator_msgs::msg::LaneletPose makeLaneletPose( lanelet_pose.s = s; return lanelet_pose; } + +LaneletUtils & getLaneletUtils() +{ + static const std::string path = + ament_index_cpp::get_package_share_directory("random_test_runner") + "/map/lanelet2_map.osm"; + static LaneletUtils utils(path); + return utils; +} From d7bfa9581fd772f28939eba16af4bdece38ee3f0 Mon Sep 17 00:00:00 2001 From: Mateusz Palczuk Date: Wed, 13 Dec 2023 17:10:12 +0100 Subject: [PATCH 06/10] Add TestRandomizer tests Signed-off-by: Mateusz Palczuk --- .../random_test_runner/test/CMakeLists.txt | 2 + .../test/expect_eq_macros.hpp | 5 + .../test/test_test_randomizer.cpp | 165 ++++++++++++++++++ .../random_test_runner/test/test_utils.hpp | 19 ++ 4 files changed, 191 insertions(+) create mode 100644 test_runner/random_test_runner/test/test_test_randomizer.cpp diff --git a/test_runner/random_test_runner/test/CMakeLists.txt b/test_runner/random_test_runner/test/CMakeLists.txt index 5dc44ad881e..84e547bcdde 100644 --- a/test_runner/random_test_runner/test/CMakeLists.txt +++ b/test_runner/random_test_runner/test/CMakeLists.txt @@ -20,9 +20,11 @@ ament_add_gtest(test_goal_reached_metric test_goal_reached_metric.cpp) ament_add_gtest(test_data_types test_data_types.cpp) ament_add_gtest(test_lanelet_utils test_lanelet_utils.cpp) ament_add_gtest(test_randomizers test_randomizers.cpp) +ament_add_gtest(test_test_randomizer test_test_randomizer.cpp) target_link_libraries(test_almost_standstill_metric ${PROJECT_NAME}) target_link_libraries(test_ego_collision_metric ${PROJECT_NAME}) target_link_libraries(test_goal_reached_metric ${PROJECT_NAME}) target_link_libraries(test_data_types ${PROJECT_NAME}) target_link_libraries(test_lanelet_utils ${PROJECT_NAME}) target_link_libraries(test_randomizers ${PROJECT_NAME}) +target_link_libraries(test_test_randomizer ${PROJECT_NAME}) diff --git a/test_runner/random_test_runner/test/expect_eq_macros.hpp b/test_runner/random_test_runner/test/expect_eq_macros.hpp index 09b44384136..b5995b0bab0 100644 --- a/test_runner/random_test_runner/test/expect_eq_macros.hpp +++ b/test_runner/random_test_runner/test/expect_eq_macros.hpp @@ -55,4 +55,9 @@ EXPECT_GE((VAL), (MIN)); \ EXPECT_LE((VAL), (MAX)) +#define EXPECT_NPC_DESCRIPTION_NEAR(DATA0, DATA1, TOLERANCE) \ + EXPECT_STREQ(DATA0.name.c_str(), DATA1.name.c_str()); \ + EXPECT_NEAR(DATA0.speed, DATA1.speed, TOLERANCE); \ + EXPECT_LANELET_POSE_NEAR(DATA0.start_position, DATA1.start_position, TOLERANCE); + #endif // RANDOM_TEST_RUNNER__TEST__EXPECT_EQ_MACROS_HPP_ diff --git a/test_runner/random_test_runner/test/test_test_randomizer.cpp b/test_runner/random_test_runner/test/test_test_randomizer.cpp new file mode 100644 index 00000000000..3110b21754b --- /dev/null +++ b/test_runner/random_test_runner/test/test_test_randomizer.cpp @@ -0,0 +1,165 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include +#include +#include + +#include "expect_eq_macros.hpp" +#include "test_utils.hpp" + +constexpr double EPS = 1e-6; + +TEST(TestRandomizer, initialize) +{ + TestSuiteParameters suite_params; + suite_params.ego_goal_lanelet_id = 1; + suite_params.ego_goal_partial_randomization = true; + TestCaseParameters case_params; + case_params.seed = 1; + TestRandomizer randomizer( + rclcpp::get_logger("test_randomizer"), suite_params, case_params, getLaneletUtilsPtr()); +} + +TEST(TestRandomizer, generate_10NPC) +{ + TestSuiteParameters suite_params; + suite_params.ego_goal_lanelet_id = 34621; + suite_params.ego_goal_partial_randomization = true; + TestCaseParameters case_params; + case_params.seed = 1; + rclcpp::Logger logger = rclcpp::get_logger("test_randomizer"); + logger.set_level(rclcpp::Logger::Level::Unset); + TestRandomizer randomizer(logger, suite_params, case_params, getLaneletUtilsPtr()); + + TestDescription description = randomizer.generate(); + // ego data + EXPECT_LANELET_POSE_NEAR( + description.ego_start_position, makeLaneletPose(34705, 6.2940393113), EPS); + EXPECT_LANELET_POSE_NEAR( + description.ego_goal_position, makeLaneletPose(34642, 9.6945373700), EPS); + EXPECT_POSE_NEAR( + description.ego_goal_pose, + geometry_msgs::build() + .position(geometry_msgs::build() + .x(3759.7298049304) + .y(73741.1526960728) + .z(0.0698702227)) + .orientation(geometry_msgs::build() + .x(0.0) + .y(0.0) + .z(-0.9854984261) + .w(0.1696845662)), + EPS); + // npc data + EXPECT_EQ(description.npcs_descriptions.size(), size_t(10)); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[0], + makeNPCDescription("npc0", 0.7308464889, makeLaneletPose(34624, 7.5543207194)), EPS) + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[1], + makeNPCDescription("npc1", 2.1743651011, makeLaneletPose(34642, 5.2207237465)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[2], + makeNPCDescription("npc2", 1.8113704071, makeLaneletPose(34786, 3.7184477027)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[3], + makeNPCDescription("npc3", 0.5684689900, makeLaneletPose(34615, 21.0757887426)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[4], + makeNPCDescription("npc4", 1.6430120231, makeLaneletPose(34684, 5.5834935067)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[5], + makeNPCDescription("npc5", 0.9952537087, makeLaneletPose(34690, 18.9720777813)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[6], + makeNPCDescription("npc6", 2.5068937586, makeLaneletPose(34762, 6.9548768523)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[7], + makeNPCDescription("npc7", 0.5976369610, makeLaneletPose(34976, 2.5577956602)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[8], + makeNPCDescription("npc8", 2.1763201035, makeLaneletPose(34621, 9.4524364223)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[9], + makeNPCDescription("npc9", 0.9938772341, makeLaneletPose(34708, 7.0635798983)), EPS); +} + +TEST(TestRandomizer, generate_8NPC) +{ + TestSuiteParameters suite_params; + suite_params.ego_goal_lanelet_id = 34468; + suite_params.ego_goal_partial_randomization = true; + suite_params.npcs_count = 8; + TestCaseParameters case_params; + case_params.seed = 1234; + TestRandomizer randomizer( + rclcpp::get_logger("test_randomizer"), suite_params, case_params, getLaneletUtilsPtr()); + + TestDescription description = randomizer.generate(); + // ego data + EXPECT_LANELET_POSE_NEAR( + description.ego_start_position, makeLaneletPose(34648, 11.3744011441), EPS); + EXPECT_LANELET_POSE_NEAR( + description.ego_goal_position, makeLaneletPose(34507, 55.3754803281), EPS); + EXPECT_POSE_NEAR( + description.ego_goal_pose, + geometry_msgs::build() + .position(geometry_msgs::build() + .x(3799.5102437521) + .y(73815.1830249432) + .z(-2.9975350010)) + .orientation(geometry_msgs::build() + .x(0.0) + .y(0.0) + .z(0.2345315792) + .w(0.9721085013)), + EPS); + // npc data + EXPECT_EQ(description.npcs_descriptions.size(), size_t(8)); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[0], + makeNPCDescription("npc0", 1.1814815242, makeLaneletPose(34648, 1.0719996393)), EPS) + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[1], + makeNPCDescription("npc1", 2.5379073352, makeLaneletPose(34441, 1.8085656480)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[2], + makeNPCDescription("npc2", 1.3945431898, makeLaneletPose(34783, 13.6066129043)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[3], + makeNPCDescription("npc3", 1.3275385670, makeLaneletPose(34411, 6.2502502346)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[4], + makeNPCDescription("npc4", 1.9029904729, makeLaneletPose(34606, 14.5456329040)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[5], + makeNPCDescription("npc5", 0.6884530926, makeLaneletPose(34507, 31.5435000028)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[6], + makeNPCDescription("npc6", 1.4844558761, makeLaneletPose(34783, 1.8243487931)), EPS); + EXPECT_NPC_DESCRIPTION_NEAR( + description.npcs_descriptions[7], + makeNPCDescription("npc7", 2.4718253580, makeLaneletPose(34603, 13.0118273897)), EPS); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test_runner/random_test_runner/test/test_utils.hpp b/test_runner/random_test_runner/test/test_utils.hpp index 21ac31e9ffc..e996904d49e 100644 --- a/test_runner/random_test_runner/test/test_utils.hpp +++ b/test_runner/random_test_runner/test/test_utils.hpp @@ -66,3 +66,22 @@ LaneletUtils & getLaneletUtils() static LaneletUtils utils(path); return utils; } + +std::shared_ptr getLaneletUtilsPtr() +{ + static const std::string path = + ament_index_cpp::get_package_share_directory("random_test_runner") + "/map/lanelet2_map.osm"; + static const auto utils = std::make_shared(path); + return utils; +} + +NPCDescription makeNPCDescription( + const std::string name, const double speed, + const traffic_simulator_msgs::msg::LaneletPose lanelet_pose) +{ + NPCDescription description; + description.name = name; + description.speed = speed; + description.start_position = lanelet_pose; + return description; +} \ No newline at end of file From b6ef03eecdbbbe75c113939074f3915243ebb2ed Mon Sep 17 00:00:00 2001 From: Mateusz Palczuk Date: Wed, 13 Dec 2023 17:52:59 +0100 Subject: [PATCH 07/10] Add some JunitXmlReporter tests Signed-off-by: Mateusz Palczuk --- .../random_test_runner/test/CMakeLists.txt | 2 + .../test/test_junit_xml_reporter.cpp | 127 ++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 test_runner/random_test_runner/test/test_junit_xml_reporter.cpp diff --git a/test_runner/random_test_runner/test/CMakeLists.txt b/test_runner/random_test_runner/test/CMakeLists.txt index 84e547bcdde..eb1381208af 100644 --- a/test_runner/random_test_runner/test/CMakeLists.txt +++ b/test_runner/random_test_runner/test/CMakeLists.txt @@ -21,6 +21,7 @@ ament_add_gtest(test_data_types test_data_types.cpp) ament_add_gtest(test_lanelet_utils test_lanelet_utils.cpp) ament_add_gtest(test_randomizers test_randomizers.cpp) ament_add_gtest(test_test_randomizer test_test_randomizer.cpp) +ament_add_gtest(test_junit_xml_reporter test_junit_xml_reporter.cpp) target_link_libraries(test_almost_standstill_metric ${PROJECT_NAME}) target_link_libraries(test_ego_collision_metric ${PROJECT_NAME}) target_link_libraries(test_goal_reached_metric ${PROJECT_NAME}) @@ -28,3 +29,4 @@ target_link_libraries(test_data_types ${PROJECT_NAME}) target_link_libraries(test_lanelet_utils ${PROJECT_NAME}) target_link_libraries(test_randomizers ${PROJECT_NAME}) target_link_libraries(test_test_randomizer ${PROJECT_NAME}) +target_link_libraries(test_junit_xml_reporter ${PROJECT_NAME}) diff --git a/test_runner/random_test_runner/test/test_junit_xml_reporter.cpp b/test_runner/random_test_runner/test/test_junit_xml_reporter.cpp new file mode 100644 index 00000000000..e01879974e0 --- /dev/null +++ b/test_runner/random_test_runner/test/test_junit_xml_reporter.cpp @@ -0,0 +1,127 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include + +#include "test_utils.hpp" + +std::string readFile(const std::string & path = "/tmp/result.junit.xml") +{ + std::ifstream file(path); + std::stringstream buffer; + buffer << file.rdbuf(); + return buffer.str(); +} + +TEST(JunitXmlReporter, reportCollision) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + testcase.reportCollision(makeNPCDescription("npc", 1.0, makeLaneletPose(123, 5.0)), 10.0); + + reporter.write(); + + std::string report = readFile(); + std::string ans = R"( + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + +TEST(JunitXmlReporter, reportStandStill) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + testcase.reportStandStill(); + + reporter.write(); + + std::string report = readFile(); + std::string ans = R"( + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + +TEST(JunitXmlReporter, reportTimeout) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + testcase.reportTimeout(); + + reporter.write(); + + std::string report = readFile(); + std::string ans = R"( + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + +TEST(JunitXmlReporter, reportException) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + testcase.reportException("exception_type", "Exception message"); + + reporter.write(); + + std::string report = readFile(); + std::string ans = R"( + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} From 52fdc0f6eafa1aef9888f708b85c81e0fa106236 Mon Sep 17 00:00:00 2001 From: Mateusz Palczuk Date: Thu, 14 Dec 2023 14:35:21 +0100 Subject: [PATCH 08/10] Add remaining JunitXmlReporter tests Signed-off-by: Mateusz Palczuk --- .../test/test_junit_xml_reporter.cpp | 198 ++++++++++++++++-- 1 file changed, 182 insertions(+), 16 deletions(-) diff --git a/test_runner/random_test_runner/test/test_junit_xml_reporter.cpp b/test_runner/random_test_runner/test/test_junit_xml_reporter.cpp index e01879974e0..969b2856eed 100644 --- a/test_runner/random_test_runner/test/test_junit_xml_reporter.cpp +++ b/test_runner/random_test_runner/test/test_junit_xml_reporter.cpp @@ -28,18 +28,27 @@ std::string readFile(const std::string & path = "/tmp/result.junit.xml") return buffer.str(); } +TEST(JunitXmlReporter, initialize) +{ + EXPECT_NO_THROW(JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter"))); + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + EXPECT_NO_THROW(reporter.init("/tmp")); + EXPECT_NO_THROW(reporter.spawnTestCase("testsuite", "testcase")); +} + TEST(JunitXmlReporter, reportCollision) { JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); reporter.init("/tmp"); JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); - testcase.reportCollision(makeNPCDescription("npc", 1.0, makeLaneletPose(123, 5.0)), 10.0); + EXPECT_NO_THROW( + testcase.reportCollision(makeNPCDescription("npc", 1.0, makeLaneletPose(123, 5.0)), 10.0)); - reporter.write(); + EXPECT_NO_THROW(reporter.write()); - std::string report = readFile(); - std::string ans = R"( + const std::string report = readFile(); + const std::string ans = R"( @@ -51,18 +60,45 @@ TEST(JunitXmlReporter, reportCollision) EXPECT_STREQ(report.c_str(), ans.c_str()); } +TEST(JunitXmlReporter, reportCollision_double) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + EXPECT_NO_THROW( + testcase.reportCollision(makeNPCDescription("npc1", 1.0, makeLaneletPose(123, 5.0)), 10.0)); + EXPECT_NO_THROW( + testcase.reportCollision(makeNPCDescription("npc2", 2.0, makeLaneletPose(321, 7.0)), 17.0)); + + EXPECT_NO_THROW(reporter.write()); + + const std::string report = readFile(); + const std::string ans = R"( + + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + TEST(JunitXmlReporter, reportStandStill) { JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); reporter.init("/tmp"); JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); - testcase.reportStandStill(); + EXPECT_NO_THROW(testcase.reportStandStill()); - reporter.write(); + EXPECT_NO_THROW(reporter.write()); - std::string report = readFile(); - std::string ans = R"( + const std::string report = readFile(); + const std::string ans = R"( @@ -74,18 +110,43 @@ TEST(JunitXmlReporter, reportStandStill) EXPECT_STREQ(report.c_str(), ans.c_str()); } +TEST(JunitXmlReporter, reportStandStill_double) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + EXPECT_NO_THROW(testcase.reportStandStill()); + EXPECT_NO_THROW(testcase.reportStandStill()); + + EXPECT_NO_THROW(reporter.write()); + + const std::string report = readFile(); + const std::string ans = R"( + + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + TEST(JunitXmlReporter, reportTimeout) { JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); reporter.init("/tmp"); JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); - testcase.reportTimeout(); + EXPECT_NO_THROW(testcase.reportTimeout()); - reporter.write(); + EXPECT_NO_THROW(reporter.write()); - std::string report = readFile(); - std::string ans = R"( + const std::string report = readFile(); + const std::string ans = R"( @@ -97,18 +158,43 @@ TEST(JunitXmlReporter, reportTimeout) EXPECT_STREQ(report.c_str(), ans.c_str()); } +TEST(JunitXmlReporter, reportTimeout_double) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + EXPECT_NO_THROW(testcase.reportTimeout()); + EXPECT_NO_THROW(testcase.reportTimeout()); + + EXPECT_NO_THROW(reporter.write()); + + const std::string report = readFile(); + const std::string ans = R"( + + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + TEST(JunitXmlReporter, reportException) { JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); reporter.init("/tmp"); JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); - testcase.reportException("exception_type", "Exception message"); + EXPECT_NO_THROW(testcase.reportException("exception_type", "Exception message")); - reporter.write(); + EXPECT_NO_THROW(reporter.write()); - std::string report = readFile(); - std::string ans = R"( + const std::string report = readFile(); + const std::string ans = R"( @@ -120,6 +206,86 @@ TEST(JunitXmlReporter, reportException) EXPECT_STREQ(report.c_str(), ans.c_str()); } +TEST(JunitXmlReporter, reportException_double) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + EXPECT_NO_THROW(testcase.reportException("exception_type1", "Exception message 1")); + EXPECT_NO_THROW(testcase.reportException("exception_type2", "Exception message 2")); + + EXPECT_NO_THROW(reporter.write()); + + const std::string report = readFile(); + const std::string ans = R"( + + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + +TEST(JunitXmlReporter, reportStandStillAndTimeout) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + EXPECT_NO_THROW(testcase.reportStandStill()); + EXPECT_NO_THROW(testcase.reportTimeout()); + + EXPECT_NO_THROW(reporter.write()); + + const std::string report = readFile(); + const std::string ans = R"( + + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + +TEST(JunitXmlReporter, reportAll) +{ + JunitXmlReporter reporter(rclcpp::get_logger("test_junit_xml_reporter")); + reporter.init("/tmp"); + JunitXmlReporterTestCase testcase = reporter.spawnTestCase("testsuite", "testcase"); + + EXPECT_NO_THROW( + testcase.reportCollision(makeNPCDescription("npc", 1.0, makeLaneletPose(123, 5.0)), 10.0)); + EXPECT_NO_THROW(testcase.reportStandStill()); + EXPECT_NO_THROW(testcase.reportTimeout()); + EXPECT_NO_THROW(testcase.reportException("test_exception", "The vehicle has collided with npc")); + + EXPECT_NO_THROW(reporter.write()); + + const std::string report = readFile(); + const std::string ans = R"( + + + + + + + + + + +)"; + EXPECT_STREQ(report.c_str(), ans.c_str()); +} + int main(int argc, char ** argv) { testing::InitGoogleTest(&argc, argv); From fce7b8943dac2417e48a74ba1da57044a4309dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lech?= Date: Thu, 14 Dec 2023 16:11:39 +0100 Subject: [PATCH 09/10] YamlTestParamsSaver tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Lech --- .../random_test_runner/test/CMakeLists.txt | 4 + .../test/test_yaml_test_params_saver.cpp | 435 ++++++++++++++++++ 2 files changed, 439 insertions(+) create mode 100644 test_runner/random_test_runner/test/test_yaml_test_params_saver.cpp diff --git a/test_runner/random_test_runner/test/CMakeLists.txt b/test_runner/random_test_runner/test/CMakeLists.txt index eb1381208af..20c29abbb47 100644 --- a/test_runner/random_test_runner/test/CMakeLists.txt +++ b/test_runner/random_test_runner/test/CMakeLists.txt @@ -22,6 +22,8 @@ ament_add_gtest(test_lanelet_utils test_lanelet_utils.cpp) ament_add_gtest(test_randomizers test_randomizers.cpp) ament_add_gtest(test_test_randomizer test_test_randomizer.cpp) ament_add_gtest(test_junit_xml_reporter test_junit_xml_reporter.cpp) +ament_add_gtest(test_yaml_test_params_saver test_yaml_test_params_saver.cpp) + target_link_libraries(test_almost_standstill_metric ${PROJECT_NAME}) target_link_libraries(test_ego_collision_metric ${PROJECT_NAME}) target_link_libraries(test_goal_reached_metric ${PROJECT_NAME}) @@ -30,3 +32,5 @@ target_link_libraries(test_lanelet_utils ${PROJECT_NAME}) target_link_libraries(test_randomizers ${PROJECT_NAME}) target_link_libraries(test_test_randomizer ${PROJECT_NAME}) target_link_libraries(test_junit_xml_reporter ${PROJECT_NAME}) +target_link_libraries(test_yaml_test_params_saver ${PROJECT_NAME}) + diff --git a/test_runner/random_test_runner/test/test_yaml_test_params_saver.cpp b/test_runner/random_test_runner/test/test_yaml_test_params_saver.cpp new file mode 100644 index 00000000000..bbd919d12c2 --- /dev/null +++ b/test_runner/random_test_runner/test/test_yaml_test_params_saver.cpp @@ -0,0 +1,435 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include + +#include "test_utils.hpp" + +std::string readFile(const std::string & path = "/tmp/result.yaml") +{ + std::ifstream file(path); + std::stringstream buffer; + buffer << file.rdbuf(); + return buffer.str(); +} + +void writeToFile(const std::string & data, const std::string & path = "/tmp/result.yaml") +{ + std::ofstream file; + file.open(path); + file << data; + file.close(); +} + +// TestSuiteParameters + +TEST(YamlTestParamsSaver, TestSuiteParameters_encode) +{ + YAML::convert convert; + auto rhs = TestSuiteParameters(); + auto node = convert.encode(rhs); + + EXPECT_STREQ(node["test_name"].as().c_str(), rhs.name.c_str()); + EXPECT_STREQ(node["map_name"].as().c_str(), rhs.map_name.c_str()); + EXPECT_DOUBLE_EQ(node["ego_goal_s"].as(), rhs.ego_goal_s); + EXPECT_EQ(node["ego_goal_lanelet_id"].as(), rhs.ego_goal_lanelet_id); + EXPECT_EQ(node["ego_goal_partial_randomization"].as(), rhs.ego_goal_partial_randomization); + EXPECT_DOUBLE_EQ( + node["ego_goal_partial_randomization_distance"].as(), + rhs.ego_goal_partial_randomization_distance); + EXPECT_EQ(node["npc_count"].as(), rhs.npcs_count); + EXPECT_DOUBLE_EQ(node["npc_min_speed"].as(), rhs.npc_min_speed); + EXPECT_DOUBLE_EQ(node["npc_max_speed"].as(), rhs.npc_max_speed); + EXPECT_DOUBLE_EQ( + node["npc_min_spawn_distance_from_ego"].as(), rhs.npc_min_spawn_distance_from_ego); + EXPECT_DOUBLE_EQ( + node["npc_max_spawn_distance_from_ego"].as(), rhs.npc_max_spawn_distance_from_ego); +} + +TEST(YamlTestParamsSaver, TestSuiteParameters_decodeMap) +{ + YAML::convert convert; + + auto rhs = TestSuiteParameters(); + auto node = YAML::Node(YAML::NodeType::Map); + + node["test_name"] = "random_test_1"; + node["map_name"] = "test_map_name"; + node["ego_goal_s"] = 15.5; + node["ego_goal_lanelet_id"] = 1600; + node["ego_goal_partial_randomization"] = true; + node["ego_goal_partial_randomization_distance"] = 100.0; + node["npc_count"] = 20; + node["npc_min_speed"] = 0.3; + node["npc_max_speed"] = 7.0; + node["npc_min_spawn_distance_from_ego"] = 10.1; + node["npc_max_spawn_distance_from_ego"] = 100.1; + + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, true); + EXPECT_STREQ(rhs.name.c_str(), node["test_name"].as().c_str()); + EXPECT_STREQ(rhs.map_name.c_str(), node["map_name"].as().c_str()); + EXPECT_DOUBLE_EQ(rhs.ego_goal_s, node["ego_goal_s"].as()); + EXPECT_EQ(rhs.ego_goal_lanelet_id, node["ego_goal_lanelet_id"].as()); + EXPECT_EQ(rhs.ego_goal_partial_randomization, node["ego_goal_partial_randomization"].as()); + EXPECT_DOUBLE_EQ( + rhs.ego_goal_partial_randomization_distance, + node["ego_goal_partial_randomization_distance"].as()); + EXPECT_EQ(rhs.npcs_count, node["npc_count"].as()); + EXPECT_DOUBLE_EQ(rhs.npc_min_speed, node["npc_min_speed"].as()); + EXPECT_DOUBLE_EQ(rhs.npc_max_speed, node["npc_max_speed"].as()); + EXPECT_DOUBLE_EQ( + rhs.npc_min_spawn_distance_from_ego, node["npc_min_spawn_distance_from_ego"].as()); + EXPECT_DOUBLE_EQ( + rhs.npc_max_spawn_distance_from_ego, node["npc_max_spawn_distance_from_ego"].as()); + + EXPECT_STREQ(rhs.name.c_str(), "random_test_1"); + EXPECT_STREQ(rhs.map_name.c_str(), "test_map_name"); + EXPECT_DOUBLE_EQ(rhs.ego_goal_s, 15.5); + EXPECT_EQ(rhs.ego_goal_lanelet_id, 1600); + EXPECT_EQ(rhs.ego_goal_partial_randomization, true); + EXPECT_DOUBLE_EQ(rhs.ego_goal_partial_randomization_distance, 100.0); + EXPECT_EQ(rhs.npcs_count, 20); + EXPECT_DOUBLE_EQ(rhs.npc_min_speed, 0.3); + EXPECT_DOUBLE_EQ(rhs.npc_max_speed, 7.0); + EXPECT_DOUBLE_EQ(rhs.npc_min_spawn_distance_from_ego, 10.1); + EXPECT_DOUBLE_EQ(rhs.npc_max_spawn_distance_from_ego, 100.1); +} + +TEST(YamlTestParamsSaver, TestSuiteParameters_decodeNull) +{ + YAML::convert convert; + + auto rhs = TestSuiteParameters(); + auto node = YAML::Node(YAML::NodeType::Null); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); +} + +TEST(YamlTestParamsSaver, TestSuiteParameters_decodeScalar) +{ + YAML::convert convert; + + auto rhs = TestSuiteParameters(); + auto node = YAML::Node(YAML::NodeType::Scalar); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); +} + +TEST(YamlTestParamsSaver, TestSuiteParameters_decodeSequence) +{ + YAML::convert convert; + + auto rhs = TestSuiteParameters(); + auto node = YAML::Node(YAML::NodeType::Sequence); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); +} + +TEST(YamlTestParamsSaver, TestSuiteParameters_decodeUndefined) +{ + YAML::convert convert; + + auto rhs = TestSuiteParameters(); + auto node = YAML::Node(YAML::NodeType::Undefined); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); +} + +TEST(YamlTestParamsSaver, TestSuiteParameters_decodeDefault) +{ + YAML::convert convert; + + auto rhs = TestSuiteParameters(); + auto node = YAML::Node(); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); +} + +// TestCaseParameters + +TEST(YamlTestParamsSaver, TestCaseParameters_encode) +{ + YAML::convert convert; + auto rhs = TestCaseParameters(); + auto node = convert.encode(rhs); + + EXPECT_EQ(node["seed"].as(), rhs.seed); +} + +TEST(YamlTestParamsSaver, TestCaseParameters_decodeMap) +{ + YAML::convert convert; + auto rhs = TestCaseParameters(); + auto node = YAML::Node(YAML::NodeType::Map); + + node["seed"] = 5; + + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, true); + EXPECT_EQ(rhs.seed, 5); +} + +TEST(YamlTestParamsSaver, TestCaseParameters_decodeNull) +{ + YAML::convert convert; + auto rhs = TestCaseParameters(); + rhs.seed = 10; + auto node = YAML::Node(YAML::NodeType::Null); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); + EXPECT_EQ(rhs.seed, 10); +} + +TEST(YamlTestParamsSaver, TestCaseParameters_decodeScalar) +{ + YAML::convert convert; + auto rhs = TestCaseParameters(); + rhs.seed = 10; + auto node = YAML::Node(YAML::NodeType::Scalar); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); + EXPECT_EQ(rhs.seed, 10); +} + +TEST(YamlTestParamsSaver, TestCaseParameters_decodeSequence) +{ + YAML::convert convert; + auto rhs = TestCaseParameters(); + rhs.seed = 10; + auto node = YAML::Node(YAML::NodeType::Sequence); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); + EXPECT_EQ(rhs.seed, 10); +} + +TEST(YamlTestParamsSaver, TestCaseParameters_decodeUndefined) +{ + YAML::convert convert; + auto rhs = TestCaseParameters(); + rhs.seed = 10; + auto node = YAML::Node(YAML::NodeType::Undefined); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); + EXPECT_EQ(rhs.seed, 10); +} + +TEST(YamlTestParamsSaver, TestCaseParameters_decodeDefault) +{ + YAML::convert convert; + auto rhs = TestCaseParameters(); + rhs.seed = 10; + auto node = YAML::Node(); + auto result = convert.decode(node, rhs); + + EXPECT_EQ(result, false); + EXPECT_EQ(rhs.seed, 10); +} + +TEST(YamlTestParamsSaver, YamlTestParamsIO_read) +{ + auto test_params_IO = YamlTestParamsIO(rclcpp::get_logger("yaml_test_params_saver"), "/tmp"); + std::string file_data = + "random_test:\n\ + test_name: random_test\n\ + map_name: kashiwanoha_map\n\ + ego_goal_s: 0\n\ + ego_goal_lanelet_id: -1\n\ + ego_goal_partial_randomization: false\n\ + ego_goal_partial_randomization_distance: 25\n\ + npc_count: 10\n\ + npc_min_speed: 0.5\n\ + npc_max_speed: 3\n\ + npc_min_spawn_distance_from_ego: 10\n\ + npc_max_spawn_distance_from_ego: 100\n\ + test_cases:\n\ + - seed: 121660883\n\ + - seed: 478515236\n\ + - seed: 3404285739\n\ + - seed: 1008004056\n\ + - seed: 2015958364"; + writeToFile(file_data); + auto result = test_params_IO.read(); + + EXPECT_STREQ(result.first.name.c_str(), "random_test"); + EXPECT_STREQ(result.first.map_name.c_str(), "kashiwanoha_map"); + EXPECT_DOUBLE_EQ(result.first.ego_goal_s, 0.0); + EXPECT_EQ(result.first.ego_goal_lanelet_id, -1); + EXPECT_FALSE(result.first.ego_goal_partial_randomization); + EXPECT_DOUBLE_EQ(result.first.ego_goal_partial_randomization_distance, 25.0); + EXPECT_EQ(result.first.npcs_count, 10); + EXPECT_DOUBLE_EQ(result.first.npc_min_speed, 0.5); + EXPECT_DOUBLE_EQ(result.first.npc_max_speed, 3.0); + EXPECT_DOUBLE_EQ(result.first.npc_min_spawn_distance_from_ego, 10.0); + EXPECT_DOUBLE_EQ(result.first.npc_max_spawn_distance_from_ego, 100.0); + + EXPECT_EQ(result.second[0].seed, 121660883); + EXPECT_EQ(result.second[1].seed, 478515236); + EXPECT_EQ(result.second[2].seed, 3404285739); + EXPECT_EQ(result.second[3].seed, 1008004056); + EXPECT_EQ(result.second[4].seed, 2015958364); +} + +TEST(YamlTestParamsSaver, YamlTestParamsIO_readTooManySuites) +{ + auto test_params_IO = YamlTestParamsIO(rclcpp::get_logger("yaml_test_params_saver"), "/tmp"); + std::string file_data = + "random_test1:\n\ + test_name: random_test\n\ + map_name: kashiwanoha_map\n\ + ego_goal_s: 0\n\ + ego_goal_lanelet_id: -1\n\ + ego_goal_partial_randomization: false\n\ + ego_goal_partial_randomization_distance: 25\n\ + npc_count: 10\n\ + npc_min_speed: 0.5\n\ + npc_max_speed: 3\n\ + npc_min_spawn_distance_from_ego: 10\n\ + npc_max_spawn_distance_from_ego: 100\n\ + test_cases:\n\ + - seed: 121660883\n\ + - seed: 478515236\n\ + - seed: 3404285739\n\ + - seed: 1008004056\n\ + - seed: 2015958364\n\ +random_test2:\n\ + test_name: random_test\n\ + map_name: kashiwanoha_map\n\ + ego_goal_s: 0\n\ + ego_goal_lanelet_id: -1\n\ + ego_goal_partial_randomization: false\n\ + ego_goal_partial_randomization_distance: 25\n\ + npc_count: 10\n\ + npc_min_speed: 0.5\n\ + npc_max_speed: 3\n\ + npc_min_spawn_distance_from_ego: 10\n\ + npc_max_spawn_distance_from_ego: 100\n\ + test_cases:\n\ + - seed: 121660883\n\ + - seed: 478515236\n\ + - seed: 3404285739\n\ + - seed: 1008004056\n\ + - seed: 2015958364"; + writeToFile(file_data); + + EXPECT_THROW(test_params_IO.read(), std::runtime_error); +} + +TEST(YamlTestParamsSaver, YamlTestParamsIO_writeSingle) +{ + auto test_params_IO = YamlTestParamsIO(rclcpp::get_logger("yaml_test_params_saver"), "/tmp"); + TestSuiteParameters suite_parameters; + TestCaseParameters test_case_parameters1; + TestCaseParameters test_case_parameters2; + test_case_parameters1.seed = 100; + test_case_parameters2.seed = 200; + test_params_IO.addTestSuite(suite_parameters, "Suite1"); + test_params_IO.addTestCase(test_case_parameters1, "Suite1"); + test_params_IO.addTestCase(test_case_parameters2, "Suite1"); + test_params_IO.write(); + + std::string expected_file_data = + "Suite1:\n\ + test_name: random_test\n\ + map_name: kashiwanoha_map\n\ + ego_goal_s: 0\n\ + ego_goal_lanelet_id: -1\n\ + ego_goal_partial_randomization: false\n\ + ego_goal_partial_randomization_distance: 30\n\ + npc_count: 10\n\ + npc_min_speed: 0.5\n\ + npc_max_speed: 3\n\ + npc_min_spawn_distance_from_ego: 10\n\ + npc_max_spawn_distance_from_ego: 100\n\ + test_cases:\n\ + - seed: 100\n\ + - seed: 200"; + + EXPECT_STREQ(readFile().c_str(), expected_file_data.c_str()); +} + +TEST(YamlTestParamsSaver, YamlTestParamsIO_writeMultiple) +{ + auto test_params_IO = YamlTestParamsIO(rclcpp::get_logger("yaml_test_params_saver"), "/tmp"); + TestSuiteParameters suite_parameters1; + TestSuiteParameters suite_parameters2; + + suite_parameters1.name = "random_test1"; + suite_parameters2.name = "random_test2"; + + TestCaseParameters test_case_parameters1; + TestCaseParameters test_case_parameters2; + test_case_parameters1.seed = 100; + test_case_parameters2.seed = 200; + test_params_IO.addTestSuite(suite_parameters1, "Suite1"); + test_params_IO.addTestSuite(suite_parameters2, "Suite2"); + + test_params_IO.addTestCase(test_case_parameters1, "Suite1"); + test_params_IO.addTestCase(test_case_parameters2, "Suite2"); + + test_params_IO.write(); + + std::string expected_file_data = + "Suite1:\n\ + test_name: random_test1\n\ + map_name: kashiwanoha_map\n\ + ego_goal_s: 0\n\ + ego_goal_lanelet_id: -1\n\ + ego_goal_partial_randomization: false\n\ + ego_goal_partial_randomization_distance: 30\n\ + npc_count: 10\n\ + npc_min_speed: 0.5\n\ + npc_max_speed: 3\n\ + npc_min_spawn_distance_from_ego: 10\n\ + npc_max_spawn_distance_from_ego: 100\n\ + test_cases:\n\ + - seed: 100\n\ +Suite2:\n\ + test_name: random_test2\n\ + map_name: kashiwanoha_map\n\ + ego_goal_s: 0\n\ + ego_goal_lanelet_id: -1\n\ + ego_goal_partial_randomization: false\n\ + ego_goal_partial_randomization_distance: 30\n\ + npc_count: 10\n\ + npc_min_speed: 0.5\n\ + npc_max_speed: 3\n\ + npc_min_spawn_distance_from_ego: 10\n\ + npc_max_spawn_distance_from_ego: 100\n\ + test_cases:\n\ + - seed: 200"; + + EXPECT_STREQ(readFile().c_str(), expected_file_data.c_str()); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} From 5c60ef4b3bdf7fa3dc04d79bf07b0c4b3a75e1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lech?= Date: Fri, 15 Dec 2023 13:24:04 +0100 Subject: [PATCH 10/10] TestExecutor tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Lech --- test_runner/random_test_runner/CMakeLists.txt | 1 - .../random_test_runner/random_test_runner.hpp | 4 +- .../random_test_runner/test_executor.hpp | 213 +++++++++++++++- test_runner/random_test_runner/package.xml | 1 + .../random_test_runner/src/test_executor.cpp | 228 ------------------ .../random_test_runner/test/CMakeLists.txt | 3 + .../test/test_data_types.cpp | 4 +- .../test/test_test_executor.cpp | 202 ++++++++++++++++ 8 files changed, 415 insertions(+), 241 deletions(-) delete mode 100644 test_runner/random_test_runner/src/test_executor.cpp create mode 100644 test_runner/random_test_runner/test/test_test_executor.cpp diff --git a/test_runner/random_test_runner/CMakeLists.txt b/test_runner/random_test_runner/CMakeLists.txt index bf509d7c24e..349a15df94d 100644 --- a/test_runner/random_test_runner/CMakeLists.txt +++ b/test_runner/random_test_runner/CMakeLists.txt @@ -40,7 +40,6 @@ ament_auto_find_build_dependencies() ament_auto_add_library(${PROJECT_NAME} SHARED src/data_types.cpp src/test_randomizer.cpp - src/test_executor.cpp src/lanelet_utils.cpp src/random_test_runner.cpp ) diff --git a/test_runner/random_test_runner/include/random_test_runner/random_test_runner.hpp b/test_runner/random_test_runner/include/random_test_runner/random_test_runner.hpp index b69bf50aee1..74b27ed9546 100644 --- a/test_runner/random_test_runner/include/random_test_runner/random_test_runner.hpp +++ b/test_runner/random_test_runner/include/random_test_runner/random_test_runner.hpp @@ -50,8 +50,8 @@ class RandomTestRunner : public rclcpp::Node std::random_device seed_randomization_device_; - std::vector test_executors_; - std::vector::iterator current_test_executor_; + std::vector> test_executors_; + std::vector>::iterator current_test_executor_; JunitXmlReporter error_reporter_; diff --git a/test_runner/random_test_runner/include/random_test_runner/test_executor.hpp b/test_runner/random_test_runner/include/random_test_runner/test_executor.hpp index 0f6be36379c..2255a105304 100644 --- a/test_runner/random_test_runner/include/random_test_runner/test_executor.hpp +++ b/test_runner/random_test_runner/include/random_test_runner/test_executor.hpp @@ -27,23 +27,220 @@ #include "random_test_runner/metrics/goal_reached_metric.hpp" #include "traffic_simulator/api/api.hpp" +const double test_timeout = 60.0; + +traffic_simulator_msgs::msg::VehicleParameters getVehicleParameters() +{ + traffic_simulator_msgs::msg::VehicleParameters parameters; + parameters.name = "vehicle.volkswagen.t"; + parameters.subtype.value = traffic_simulator_msgs::msg::EntitySubtype::CAR; + parameters.performance.max_speed = 69.444; + parameters.performance.max_acceleration = 200; + parameters.performance.max_deceleration = 10.0; + parameters.bounding_box.center.x = 1.5; + parameters.bounding_box.center.y = 0.0; + parameters.bounding_box.center.z = 0.9; + parameters.bounding_box.dimensions.x = 4.5; + parameters.bounding_box.dimensions.y = 2.1; + parameters.bounding_box.dimensions.z = 1.8; + parameters.axles.front_axle.max_steering = 0.5; + parameters.axles.front_axle.wheel_diameter = 0.6; + parameters.axles.front_axle.track_width = 1.8; + parameters.axles.front_axle.position_x = 3.1; + parameters.axles.front_axle.position_z = 0.3; + parameters.axles.rear_axle.max_steering = 0.0; + parameters.axles.rear_axle.wheel_diameter = 0.6; + parameters.axles.rear_axle.track_width = 1.8; + parameters.axles.rear_axle.position_x = 0.0; + parameters.axles.rear_axle.position_z = 0.3; + return parameters; +} + +template class TestExecutor { public: TestExecutor( - std::shared_ptr api, TestDescription description, + std::shared_ptr api, TestDescription description, JunitXmlReporterTestCase test_case_reporter, SimulatorType simulator_type, - ArchitectureType architecture_type, rclcpp::Logger logger); + ArchitectureType architecture_type, rclcpp::Logger logger) + : api_(std::move(api)), + test_description_(std::move(description)), + error_reporter_(std::move(test_case_reporter)), + simulator_type_(simulator_type), + architecture_type_(architecture_type), + logger_(logger) + { + } + + void initialize() + { + executeWithErrorHandling([this]() { + std::string message = fmt::format("Test description: {}", test_description_); + RCLCPP_INFO_STREAM(logger_, message); + scenario_completed_ = false; + + api_->updateFrame(); + + if (simulator_type_ == SimulatorType::SIMPLE_SENSOR_SIMULATOR) { + api_->spawn( + ego_name_, api_->canonicalize(test_description_.ego_start_position), + getVehicleParameters(), traffic_simulator::VehicleBehavior::autoware()); + api_->setEntityStatus( + ego_name_, api_->canonicalize(test_description_.ego_start_position), + traffic_simulator::helper::constructActionStatus()); + + if (architecture_type_ == ArchitectureType::AWF_UNIVERSE) { + api_->attachLidarSensor(traffic_simulator::helper::constructLidarConfiguration( + traffic_simulator::helper::LidarType::VLP16, ego_name_, + stringFromArchitectureType(architecture_type_))); + + double constexpr detection_update_duration = 0.1; + api_->attachDetectionSensor( + traffic_simulator::helper::constructDetectionSensorConfiguration( + ego_name_, stringFromArchitectureType(architecture_type_), + detection_update_duration)); + + api_->attachOccupancyGridSensor([&]() { + simulation_api_schema::OccupancyGridSensorConfiguration configuration; + configuration.set_architecture_type(stringFromArchitectureType(architecture_type_)); + configuration.set_entity(ego_name_); + configuration.set_filter_by_range(true); + configuration.set_height(200); + configuration.set_range(300); + configuration.set_resolution(0.5); + configuration.set_update_duration(0.1); + configuration.set_width(200); + return configuration; + }()); + + api_->asFieldOperatorApplication(ego_name_).template declare_parameter( + "allow_goal_modification", true); + } + + // XXX dirty hack: wait for autoware system to launch + // ugly but helps for now + std::this_thread::sleep_for(std::chrono::milliseconds{5000}); + + api_->requestAssignRoute( + ego_name_, std::vector({api_->canonicalize(test_description_.ego_goal_position)})); + api_->asFieldOperatorApplication(ego_name_).engage(); + + goal_reached_metric_.setGoal(test_description_.ego_goal_pose); + } + + for (size_t i = 0; i < test_description_.npcs_descriptions.size(); i++) { + const auto & npc_descr = test_description_.npcs_descriptions[i]; + api_->spawn( + npc_descr.name, api_->canonicalize(npc_descr.start_position), getVehicleParameters()); + api_->setEntityStatus( + npc_descr.name, api_->canonicalize(npc_descr.start_position), + traffic_simulator::helper::constructActionStatus(npc_descr.speed)); + api_->requestSpeedChange(npc_descr.name, npc_descr.speed, true); + } + }); + } + + void update() + { + executeWithErrorHandling([this]() { + if (!api_->isEgoSpawned() && !api_->isNpcLogicStarted()) { + api_->startNpcLogic(); + } + if ( + api_->isEgoSpawned() && !api_->isNpcLogicStarted() && + api_->asFieldOperatorApplication(api_->getEgoName()).engageable()) { + api_->startNpcLogic(); + } + + auto current_time = api_->getCurrentTime(); + + if (!std::isnan(current_time)) { + bool timeout_reached = current_time >= test_timeout; + if (timeout_reached) { + if (simulator_type_ == SimulatorType::SIMPLE_SENSOR_SIMULATOR) { + if (!goal_reached_metric_.isGoalReached(api_->getEntityStatus(ego_name_))) { + RCLCPP_INFO(logger_, "Timeout reached"); + error_reporter_.reportTimeout(); + } + } + scenario_completed_ = true; + + return; + } + } + + if (simulator_type_ == SimulatorType::SIMPLE_SENSOR_SIMULATOR) { + for (const auto & npc : test_description_.npcs_descriptions) { + if (api_->entityExists(npc.name) && api_->checkCollision(ego_name_, npc.name)) { + if (ego_collision_metric_.isThereEgosCollisionWith(npc.name, current_time)) { + std::string message = + fmt::format("New collision occurred between ego and {}", npc.name); + RCLCPP_INFO_STREAM(logger_, message); + error_reporter_.reportCollision(npc, current_time); + } + } + } + + if (almost_standstill_metric_.isAlmostStandingStill(api_->getEntityStatus(ego_name_))) { + RCLCPP_INFO(logger_, "Standstill duration exceeded"); + if (goal_reached_metric_.isGoalReached(api_->getEntityStatus(ego_name_))) { + RCLCPP_INFO(logger_, "Goal reached, standstill expected"); + } else { + error_reporter_.reportStandStill(); + } + scenario_completed_ = true; + } + } + + api_->updateFrame(); + }); + } + + void deinitialize() + { + executeWithErrorHandling([this]() { + std::string message = fmt::format("Deinitialize: {}", test_description_); + RCLCPP_INFO_STREAM(logger_, message); + + if (simulator_type_ == SimulatorType::SIMPLE_SENSOR_SIMULATOR) { + api_->despawn(ego_name_); + } + for (const auto & npc : test_description_.npcs_descriptions) { + api_->despawn(npc.name); + } + }); + } - void initialize(); - void update(); - void deinitialize(); - bool scenarioCompleted(); + bool scenarioCompleted() { return scenario_completed_; } private: - void executeWithErrorHandling(std::function && func); + void executeWithErrorHandling(std::function && func) + { + try { + func(); + } catch (const common::AutowareError & error) { + error_reporter_.reportException("autoware error", error.what()); + std::string message = fmt::format("common::AutowareError occurred: {}", error.what()); + RCLCPP_ERROR_STREAM(logger_, message); + scenario_completed_ = true; + } catch (const common::scenario_simulator_exception::Error & error) { + error_reporter_.reportException("scenario simulator error", error.what()); + std::string message = + fmt::format("common::scenario_simulator_exception::Error occurred: {}", error.what()); + RCLCPP_ERROR_STREAM(logger_, message); + scenario_completed_ = true; + } catch (const std::runtime_error & error) { + std::string message = fmt::format("std::runtime_error occurred: {}", error.what()); + RCLCPP_ERROR_STREAM(logger_, message); + scenario_completed_ = true; + } catch (...) { + RCLCPP_ERROR(logger_, "Unknown error occurred."); + scenario_completed_ = true; + } + } - std::shared_ptr api_; + std::shared_ptr api_; TestDescription test_description_; const std::string ego_name_ = "ego"; diff --git a/test_runner/random_test_runner/package.xml b/test_runner/random_test_runner/package.xml index 549bd883d07..588f6dfcc95 100644 --- a/test_runner/random_test_runner/package.xml +++ b/test_runner/random_test_runner/package.xml @@ -21,6 +21,7 @@ ament_cmake_clang_format ament_cmake_copyright ament_cmake_gtest + ament_cmake_gmock ament_cmake_lint_cmake ament_cmake_pep257 ament_cmake_xmllint diff --git a/test_runner/random_test_runner/src/test_executor.cpp b/test_runner/random_test_runner/src/test_executor.cpp deleted file mode 100644 index c2001a37b8c..00000000000 --- a/test_runner/random_test_runner/src/test_executor.cpp +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2015 TIER IV, Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. - -#include "random_test_runner/test_executor.hpp" - -#include - -#include "random_test_runner/file_interactions/junit_xml_reporter.hpp" -#include "random_test_runner/file_interactions/yaml_test_params_saver.hpp" - -const double test_timeout = 60.0; - -traffic_simulator_msgs::msg::VehicleParameters getVehicleParameters() -{ - traffic_simulator_msgs::msg::VehicleParameters parameters; - parameters.name = "vehicle.volkswagen.t"; - parameters.subtype.value = traffic_simulator_msgs::msg::EntitySubtype::CAR; - parameters.performance.max_speed = 69.444; - parameters.performance.max_acceleration = 200; - parameters.performance.max_deceleration = 10.0; - parameters.bounding_box.center.x = 1.5; - parameters.bounding_box.center.y = 0.0; - parameters.bounding_box.center.z = 0.9; - parameters.bounding_box.dimensions.x = 4.5; - parameters.bounding_box.dimensions.y = 2.1; - parameters.bounding_box.dimensions.z = 1.8; - parameters.axles.front_axle.max_steering = 0.5; - parameters.axles.front_axle.wheel_diameter = 0.6; - parameters.axles.front_axle.track_width = 1.8; - parameters.axles.front_axle.position_x = 3.1; - parameters.axles.front_axle.position_z = 0.3; - parameters.axles.rear_axle.max_steering = 0.0; - parameters.axles.rear_axle.wheel_diameter = 0.6; - parameters.axles.rear_axle.track_width = 1.8; - parameters.axles.rear_axle.position_x = 0.0; - parameters.axles.rear_axle.position_z = 0.3; - return parameters; -} - -TestExecutor::TestExecutor( - std::shared_ptr api, TestDescription description, - JunitXmlReporterTestCase test_case_reporter, SimulatorType simulator_type, - ArchitectureType architecture_type, rclcpp::Logger logger) -: api_(std::move(api)), - test_description_(std::move(description)), - error_reporter_(std::move(test_case_reporter)), - simulator_type_(simulator_type), - architecture_type_(architecture_type), - logger_(logger) -{ -} - -void TestExecutor::initialize() -{ - executeWithErrorHandling([this]() { - std::string message = fmt::format("Test description: {}", test_description_); - RCLCPP_INFO_STREAM(logger_, message); - scenario_completed_ = false; - - api_->updateFrame(); - - if (simulator_type_ == SimulatorType::SIMPLE_SENSOR_SIMULATOR) { - api_->spawn( - ego_name_, api_->canonicalize(test_description_.ego_start_position), getVehicleParameters(), - traffic_simulator::VehicleBehavior::autoware()); - api_->setEntityStatus( - ego_name_, api_->canonicalize(test_description_.ego_start_position), - traffic_simulator::helper::constructActionStatus()); - - if (architecture_type_ == ArchitectureType::AWF_UNIVERSE) { - api_->attachLidarSensor(traffic_simulator::helper::constructLidarConfiguration( - traffic_simulator::helper::LidarType::VLP16, ego_name_, - stringFromArchitectureType(architecture_type_))); - - double constexpr detection_update_duration = 0.1; - api_->attachDetectionSensor( - traffic_simulator::helper::constructDetectionSensorConfiguration( - ego_name_, stringFromArchitectureType(architecture_type_), detection_update_duration)); - - api_->attachOccupancyGridSensor([&]() { - simulation_api_schema::OccupancyGridSensorConfiguration configuration; - configuration.set_architecture_type(stringFromArchitectureType(architecture_type_)); - configuration.set_entity(ego_name_); - configuration.set_filter_by_range(true); - configuration.set_height(200); - configuration.set_range(300); - configuration.set_resolution(0.5); - configuration.set_update_duration(0.1); - configuration.set_width(200); - return configuration; - }()); - - api_->asFieldOperatorApplication(ego_name_).declare_parameter( - "allow_goal_modification", true); - } - - // XXX dirty hack: wait for autoware system to launch - // ugly but helps for now - std::this_thread::sleep_for(std::chrono::milliseconds{5000}); - - api_->requestAssignRoute( - ego_name_, std::vector( - {api_->canonicalize(test_description_.ego_goal_position)})); - api_->asFieldOperatorApplication(ego_name_).engage(); - - goal_reached_metric_.setGoal(test_description_.ego_goal_pose); - } - - for (size_t i = 0; i < test_description_.npcs_descriptions.size(); i++) { - const auto & npc_descr = test_description_.npcs_descriptions[i]; - api_->spawn( - npc_descr.name, api_->canonicalize(npc_descr.start_position), getVehicleParameters()); - api_->setEntityStatus( - npc_descr.name, api_->canonicalize(npc_descr.start_position), - traffic_simulator::helper::constructActionStatus(npc_descr.speed)); - api_->requestSpeedChange(npc_descr.name, npc_descr.speed, true); - } - }); -} - -void TestExecutor::update() -{ - executeWithErrorHandling([this]() { - if (!api_->isEgoSpawned() && !api_->isNpcLogicStarted()) { - api_->startNpcLogic(); - } - if ( - api_->isEgoSpawned() && !api_->isNpcLogicStarted() && - api_->asFieldOperatorApplication(api_->getEgoName()).engageable()) { - api_->startNpcLogic(); - } - - auto current_time = api_->getCurrentTime(); - - if (!std::isnan(current_time)) { - bool timeout_reached = current_time >= test_timeout; - if (timeout_reached) { - if (simulator_type_ == SimulatorType::SIMPLE_SENSOR_SIMULATOR) { - if (!goal_reached_metric_.isGoalReached(api_->getEntityStatus(ego_name_))) { - RCLCPP_INFO(logger_, "Timeout reached"); - error_reporter_.reportTimeout(); - } - } - scenario_completed_ = true; - return; - } - } - if (simulator_type_ == SimulatorType::SIMPLE_SENSOR_SIMULATOR) { - for (const auto & npc : test_description_.npcs_descriptions) { - if (api_->entityExists(npc.name) && api_->checkCollision(ego_name_, npc.name)) { - if (ego_collision_metric_.isThereEgosCollisionWith(npc.name, current_time)) { - std::string message = - fmt::format("New collision occurred between ego and {}", npc.name); - RCLCPP_INFO_STREAM(logger_, message); - error_reporter_.reportCollision(npc, current_time); - } - } - } - - if (almost_standstill_metric_.isAlmostStandingStill(api_->getEntityStatus(ego_name_))) { - RCLCPP_INFO(logger_, "Standstill duration exceeded"); - if (goal_reached_metric_.isGoalReached(api_->getEntityStatus(ego_name_))) { - RCLCPP_INFO(logger_, "Goal reached, standstill expected"); - } else { - error_reporter_.reportStandStill(); - } - scenario_completed_ = true; - } - } - - api_->updateFrame(); - }); -} - -void TestExecutor::deinitialize() -{ - executeWithErrorHandling([this]() { - std::string message = fmt::format("Deinitialize: {}", test_description_); - RCLCPP_INFO_STREAM(logger_, message); - - if (simulator_type_ == SimulatorType::SIMPLE_SENSOR_SIMULATOR) { - api_->despawn(ego_name_); - } - for (const auto & npc : test_description_.npcs_descriptions) { - api_->despawn(npc.name); - } - }); -} - -void TestExecutor::executeWithErrorHandling(std::function && func) -{ - try { - func(); - } catch (const common::AutowareError & error) { - error_reporter_.reportException("autoware error", error.what()); - std::string message = fmt::format("common::AutowareError occurred: {}", error.what()); - RCLCPP_ERROR_STREAM(logger_, message); - scenario_completed_ = true; - } catch (const common::scenario_simulator_exception::Error & error) { - error_reporter_.reportException("scenario simulator error", error.what()); - std::string message = - fmt::format("common::scenario_simulator_exception::Error occurred: {}", error.what()); - RCLCPP_ERROR_STREAM(logger_, message); - scenario_completed_ = true; - } catch (const std::runtime_error & error) { - std::string message = fmt::format("std::runtime_error occurred: {}", error.what()); - RCLCPP_ERROR_STREAM(logger_, message); - scenario_completed_ = true; - } catch (...) { - RCLCPP_ERROR(logger_, "Unknown error occurred."); - scenario_completed_ = true; - } -} - -bool TestExecutor::scenarioCompleted() { return scenario_completed_; } diff --git a/test_runner/random_test_runner/test/CMakeLists.txt b/test_runner/random_test_runner/test/CMakeLists.txt index 20c29abbb47..7ccd5ee44c0 100644 --- a/test_runner/random_test_runner/test/CMakeLists.txt +++ b/test_runner/random_test_runner/test/CMakeLists.txt @@ -23,6 +23,8 @@ ament_add_gtest(test_randomizers test_randomizers.cpp) ament_add_gtest(test_test_randomizer test_test_randomizer.cpp) ament_add_gtest(test_junit_xml_reporter test_junit_xml_reporter.cpp) ament_add_gtest(test_yaml_test_params_saver test_yaml_test_params_saver.cpp) +ament_add_gmock(test_test_executor test_test_executor.cpp) + target_link_libraries(test_almost_standstill_metric ${PROJECT_NAME}) target_link_libraries(test_ego_collision_metric ${PROJECT_NAME}) @@ -33,4 +35,5 @@ target_link_libraries(test_randomizers ${PROJECT_NAME}) target_link_libraries(test_test_randomizer ${PROJECT_NAME}) target_link_libraries(test_junit_xml_reporter ${PROJECT_NAME}) target_link_libraries(test_yaml_test_params_saver ${PROJECT_NAME}) +target_link_libraries(test_test_executor ${PROJECT_NAME}) diff --git a/test_runner/random_test_runner/test/test_data_types.cpp b/test_runner/random_test_runner/test/test_data_types.cpp index 6ce4a5fe5ef..d271ed262e6 100644 --- a/test_runner/random_test_runner/test/test_data_types.cpp +++ b/test_runner/random_test_runner/test/test_data_types.cpp @@ -40,8 +40,8 @@ TEST(DataTypes, architectureTypeFromString_correct) { EXPECT_EQ(architectureTypeFromString("awf/auto"), ArchitectureType::AWF_AUTO); EXPECT_EQ(architectureTypeFromString("awf/universe"), ArchitectureType::AWF_UNIVERSE); - EXPECT_EQ(architectureTypeFromString("aawf/universe"), ArchitectureType::AWF_UNIVERSE); - EXPECT_EQ(architectureTypeFromString("awf/universee"), ArchitectureType::AWF_UNIVERSE); + EXPECT_EQ(architectureTypeFromString("-awf/universe"), ArchitectureType::AWF_UNIVERSE); + EXPECT_EQ(architectureTypeFromString("awf/universe-"), ArchitectureType::AWF_UNIVERSE); EXPECT_EQ(architectureTypeFromString("awf/universe "), ArchitectureType::AWF_UNIVERSE); EXPECT_EQ(architectureTypeFromString(" awf/universe"), ArchitectureType::AWF_UNIVERSE); EXPECT_EQ(architectureTypeFromString(" awf/universe "), ArchitectureType::AWF_UNIVERSE); diff --git a/test_runner/random_test_runner/test/test_test_executor.cpp b/test_runner/random_test_runner/test/test_test_executor.cpp new file mode 100644 index 00000000000..cfaee437843 --- /dev/null +++ b/test_runner/random_test_runner/test/test_test_executor.cpp @@ -0,0 +1,202 @@ +// Copyright 2015 TIER IV, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Co-developed by TIER IV, Inc. and Robotec.AI sp. z o.o. + +#include + +#include + +class MockFieldOperatorApplication +{ +public: + MOCK_METHOD(void, declare_parameter_mock, (), ()); + MOCK_METHOD(bool, engageable, (), ()); + MOCK_METHOD(void, engage, (), ()); + + template + void declare_parameter(std::string, bool) + { + if constexpr (std::is_same_v) { + declare_parameter_mock(); + return; + } + throw std::runtime_error("Unexpected typename"); + } +}; + +struct DummyCanonicalizedLaneletPose +{ +}; + +class MockTrafficSimulatorAPI +{ +public: + traffic_simulator::EntityStatus entity_status_; + std::shared_ptr<::testing::StrictMock> + field_operator_application_mock = + std::make_shared<::testing::StrictMock>(); + + MOCK_METHOD(bool, updateFrame, (), ()); + MOCK_METHOD( + bool, spawn, + (const std::string &, DummyCanonicalizedLaneletPose, + const traffic_simulator_msgs::msg::VehicleParameters &, const std::string &), + ()); + MOCK_METHOD( + void, setEntityStatus, + (const std::string &, DummyCanonicalizedLaneletPose, + const traffic_simulator_msgs::msg::ActionStatus), + ()); + MOCK_METHOD(void, attachLidarSensor, (const simulation_api_schema::LidarConfiguration &), ()); + MOCK_METHOD( + void, attachDetectionSensor, (const simulation_api_schema::DetectionSensorConfiguration &), ()); + MOCK_METHOD( + bool, attachOccupancyGridSensor, (simulation_api_schema::OccupancyGridSensorConfiguration), ()); + MOCK_METHOD(void, asFieldOperatorApplicationMock, (const std::string &), ()); + MOCK_METHOD( + void, requestAssignRoute, (const std::string &, std::vector), + ()); + MOCK_METHOD( + DummyCanonicalizedLaneletPose, canonicalize, (const traffic_simulator::LaneletPose &), ()); + MOCK_METHOD( + void, spawn, + (const std::string &, DummyCanonicalizedLaneletPose, + const traffic_simulator_msgs::msg::VehicleParameters &), + ()); + MOCK_METHOD(void, requestSpeedChange, (const std::string &, double, bool), ()); + MOCK_METHOD(bool, isEgoSpawned, (), ()); + MOCK_METHOD(bool, isNpcLogicStarted, (), ()); + MOCK_METHOD(void, startNpcLogic, (), ()); + MOCK_METHOD(bool, despawn, (const std::string), ()); + MOCK_METHOD(std::string, getEgoName, (), ()); + MOCK_METHOD(double, getCurrentTime, (), ()); + MOCK_METHOD(void, getEntityStatusMock, (const std::string &), ()); + MOCK_METHOD(bool, entityExists, (const std::string &), ()); + MOCK_METHOD(bool, checkCollision, (const std::string &, const std::string &), ()); + + ::testing::StrictMock & asFieldOperatorApplication( + const std::string & name) + { + asFieldOperatorApplicationMock(name); + return *field_operator_application_mock; + } + + traffic_simulator::CanonicalizedEntityStatus getEntityStatus(const std::string & name) + { + getEntityStatusMock(name); + entity_status_.lanelet_pose_valid = false; + std::shared_ptr hd_map_utils_nullptr = nullptr; + return traffic_simulator::CanonicalizedEntityStatus(entity_status_, hd_map_utils_nullptr); + } + + void setEntityStatusNecessaryValues( + double time, geometry_msgs::msg::Pose map_pose, geometry_msgs::msg::Twist twist) + { + entity_status_.time = time; + entity_status_.pose = map_pose; + entity_status_.action_status.twist = twist; + } +}; + +TEST(TestExecutor, InitializeWithNoNPCs) +{ + ::testing::Sequence sequence; + auto MockAPI = std::make_shared<::testing::StrictMock>(); + + auto test_case = common::junit::SimpleTestCase("test_case"); + auto test_executor = TestExecutor( + MockAPI, TestDescription(), JunitXmlReporterTestCase(test_case), + SimulatorType::SIMPLE_SENSOR_SIMULATOR, ArchitectureType::AWF_UNIVERSE, + rclcpp::get_logger("test_executor_test")); + + EXPECT_CALL(*MockAPI, updateFrame).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, canonicalize).Times(1).InSequence(sequence); + EXPECT_CALL( + *MockAPI, spawn( + ::testing::A(), ::testing::A(), + ::testing::A(), + ::testing::A())) + .Times(1) + .InSequence(sequence); + EXPECT_CALL(*MockAPI, canonicalize).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, setEntityStatus).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, attachLidarSensor).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, attachDetectionSensor).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, attachOccupancyGridSensor).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, asFieldOperatorApplicationMock).Times(1).InSequence(sequence); + EXPECT_CALL(*(MockAPI->field_operator_application_mock), declare_parameter_mock) + .Times(1) + .InSequence(sequence); + EXPECT_CALL(*MockAPI, canonicalize).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, requestAssignRoute).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, asFieldOperatorApplicationMock).Times(1).InSequence(sequence); + EXPECT_CALL(*(MockAPI->field_operator_application_mock), engage).Times(1).InSequence(sequence); + + test_executor.initialize(); +} + +TEST(TestExecutor, UpdateNoNPCs) +{ + ::testing::Sequence sequence; + auto MockAPI = std::make_shared<::testing::StrictMock>(); + + auto test_case = common::junit::SimpleTestCase("test_case"); + auto test_executor = TestExecutor( + MockAPI, TestDescription(), JunitXmlReporterTestCase(test_case), + SimulatorType::SIMPLE_SENSOR_SIMULATOR, ArchitectureType::AWF_UNIVERSE, + rclcpp::get_logger("test_executor_test")); + + EXPECT_CALL(*MockAPI, isEgoSpawned) + .Times(1) + .InSequence(sequence) + .WillOnce(::testing::Return(false)); + EXPECT_CALL(*MockAPI, isNpcLogicStarted) + .Times(1) + .InSequence(sequence) + .WillOnce(::testing::Return(false)); + EXPECT_CALL(*MockAPI, startNpcLogic).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, isEgoSpawned) + .Times(1) + .InSequence(sequence) + .WillOnce(::testing::Return(false)); + EXPECT_CALL(*MockAPI, getCurrentTime) + .Times(1) + .InSequence(sequence) + .WillOnce(::testing::Return(1.0)); + EXPECT_CALL(*MockAPI, getEntityStatusMock).Times(1).InSequence(sequence); + EXPECT_CALL(*MockAPI, updateFrame).Times(1).InSequence(sequence); + + test_executor.update(); +} + +TEST(TestExecutor, DeinitializeWithNoNPCs) +{ + auto MockAPI = std::make_shared<::testing::StrictMock>(); + auto test_case = common::junit::SimpleTestCase("test_case"); + auto test_executor = TestExecutor( + MockAPI, TestDescription(), JunitXmlReporterTestCase(test_case), + SimulatorType::SIMPLE_SENSOR_SIMULATOR, ArchitectureType::AWF_UNIVERSE, + rclcpp::get_logger("test_executor_test")); + + EXPECT_CALL(*MockAPI, despawn("ego")).Times(1); + + test_executor.deinitialize(); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +}