From 4c910acd059e566c433ff3fd9bb9d83e1daf1e64 Mon Sep 17 00:00:00 2001 From: Maxime CLEMENT <78338830+maxime-clem@users.noreply.github.com> Date: Thu, 9 Jun 2022 11:01:30 +0900 Subject: [PATCH] test(map_loader): add launch test for the 'lanelet2_map_loader' node (#1056) Signed-off-by: Maxime CLEMENT Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> --- map/map_loader/CMakeLists.txt | 11 ++ map/map_loader/package.xml | 1 + map/map_loader/test/data/test_map.osm | 146 ++++++++++++++++++ .../test/lanelet2_map_loader_launch.test.py | 61 ++++++++ 4 files changed, 219 insertions(+) create mode 100644 map/map_loader/test/data/test_map.osm create mode 100644 map/map_loader/test/lanelet2_map_loader_launch.test.py diff --git a/map/map_loader/CMakeLists.txt b/map/map_loader/CMakeLists.txt index 244880dadeb69..49d294ff1bb79 100644 --- a/map/map_loader/CMakeLists.txt +++ b/map/map_loader/CMakeLists.txt @@ -39,6 +39,17 @@ rclcpp_components_register_node(lanelet2_map_visualization_node EXECUTABLE lanelet2_map_visualization ) +if(BUILD_TESTING) + add_ros_test( + test/lanelet2_map_loader_launch.test.py + TIMEOUT "30" + ) + install(DIRECTORY + test/data/ + DESTINATION share/${PROJECT_NAME}/test/data/ + ) +endif() + install(PROGRAMS script/map_hash_generator DESTINATION lib/${PROJECT_NAME} diff --git a/map/map_loader/package.xml b/map/map_loader/package.xml index aa345d6a153f6..a2afc96c24e50 100644 --- a/map/map_loader/package.xml +++ b/map/map_loader/package.xml @@ -27,6 +27,7 @@ ament_lint_auto autoware_lint_common + ros_testing ament_cmake diff --git a/map/map_loader/test/data/test_map.osm b/map/map_loader/test/data/test_map.osm new file mode 100644 index 0000000000000..406cd85c151ea --- /dev/null +++ b/map/map_loader/test/data/test_map.osm @@ -0,0 +1,146 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/map/map_loader/test/lanelet2_map_loader_launch.test.py b/map/map_loader/test/lanelet2_map_loader_launch.test.py new file mode 100644 index 0000000000000..75abe2164ca04 --- /dev/null +++ b/map/map_loader/test/lanelet2_map_loader_launch.test.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +# Copyright 2022 TIER IV, Inc. +# +# 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. + +import os +import unittest + +from ament_index_python import get_package_share_directory +import launch +from launch import LaunchDescription +from launch_ros.actions import Node +import launch_testing +import pytest + + +@pytest.mark.launch_test +def generate_test_description(): + + lanelet2_map_path = os.path.join( + get_package_share_directory("map_loader"), "test/data/test_map.osm" + ) + + lanelet2_map_loader = Node( + package="map_loader", + executable="lanelet2_map_loader", + parameters=[{"lanelet2_map_path": lanelet2_map_path}], + ) + + context = {} + + return ( + LaunchDescription( + [ + lanelet2_map_loader, + # Start test after 1s - gives time for the map_loader to finish initialization + launch.actions.TimerAction( + period=1.0, actions=[launch_testing.actions.ReadyToTest()] + ), + ] + ), + context, + ) + + +@launch_testing.post_shutdown_test() +class TestProcessOutput(unittest.TestCase): + def test_exit_code(self, proc_info): + # Check that process exits with code 0: no error + launch_testing.asserts.assertExitCodes(proc_info)