From 40b65325f00d0944d76cf3c95f96c23b164fc688 Mon Sep 17 00:00:00 2001 From: Max SCHMELLER Date: Wed, 27 Nov 2024 21:20:03 +0900 Subject: [PATCH 1/4] test(nebula_ros): add smoke test for every sensor Signed-off-by: Max SCHMELLER --- nebula_ros/CMakeLists.txt | 12 ++++++++ nebula_ros/package.xml | 2 ++ nebula_ros/test/smoke_test.py | 56 +++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 nebula_ros/test/smoke_test.py diff --git a/nebula_ros/CMakeLists.txt b/nebula_ros/CMakeLists.txt index 709de2025..6caba4845 100644 --- a/nebula_ros/CMakeLists.txt +++ b/nebula_ros/CMakeLists.txt @@ -224,7 +224,19 @@ install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME}) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) + find_package(ros_testing REQUIRED) + ament_lint_auto_find_test_dependencies() + + foreach(MODEL VLP16 VLP32 VLS128 Pandar40P Pandar64 PandarQT64 PandarQT128 Pandar128E4X PandarAT128 PandarXT32 PandarXT32M ARS548 SRR520 Helios Bpearl) + string(TOLOWER ${MODEL}_smoke_test test_name) + add_ros_test( + test/smoke_test.py + TARGET ${test_name} + ARGS "launch_file_path:=${PROJECT_SOURCE_DIR}/launch/nebula_launch.py" "sensor_model:=${MODEL}" + TIMEOUT "10" + ) + endforeach() endif() ament_export_include_directories("include/${PROJECT_NAME}") diff --git a/nebula_ros/package.xml b/nebula_ros/package.xml index 3a97db1f6..334a5f3da 100644 --- a/nebula_ros/package.xml +++ b/nebula_ros/package.xml @@ -11,6 +11,7 @@ ament_cmake_auto ros_environment + ros_testing continental_msgs continental_srvs @@ -34,6 +35,7 @@ ament_cmake_gtest ament_lint_auto + ros_testing ament_cmake diff --git a/nebula_ros/test/smoke_test.py b/nebula_ros/test/smoke_test.py new file mode 100644 index 000000000..7e6484723 --- /dev/null +++ b/nebula_ros/test/smoke_test.py @@ -0,0 +1,56 @@ +import time +import unittest + +from launch import LaunchContext +from launch import LaunchDescription +from launch.actions import IncludeLaunchDescription +from launch.actions import OpaqueFunction +from launch.launch_description_sources import PythonLaunchDescriptionSource +from launch.substitutions import LaunchConfiguration +import launch_testing +import launch_testing.actions +import launch_testing.asserts +import pytest +import rclpy + + +def resolve_launch_file(context: LaunchContext, *args, **kwargs): + sensor_model = LaunchConfiguration("sensor_model").perform(context) + launch_file_path = LaunchConfiguration("launch_file_path").perform(context) + + return [ + IncludeLaunchDescription( + PythonLaunchDescriptionSource(launch_file_path), + launch_arguments=[("sensor_model", sensor_model), ("launch_hw", "false")], + ) + ] + + +@pytest.mark.launch_test +def generate_test_description(): + return LaunchDescription( + [OpaqueFunction(function=resolve_launch_file), launch_testing.actions.ReadyToTest()] + ) + + +class DummyTest(unittest.TestCase): + def test_wait_for_node_ready(self): + """Waiting for the node is ready.""" + rclpy.init() + test_node = rclpy.create_node("test_node") + # Wait until both dummy node "test_node" and real tested node are registered and then kill + # both of them, if tested node does not register within `timeout` seconds test will fail + start_time = time.time() + timeout = 2 # seconds + timeout_msg = "Smoke test timeout has been reached ({}s)".format(timeout) + print("waiting for Nodes to be ready") + while len(test_node.get_node_names()) < 2: + assert time.time() - start_time < timeout, timeout_msg + time.sleep(0.1) + rclpy.shutdown() + + +@launch_testing.post_shutdown_test() +class TestYourNodeShutdown(unittest.TestCase): + def test_exit_code(self, proc_info): + launch_testing.asserts.assertExitCodes(proc_info) From e981de2f53d721478f2c2ad1bda9414f8b1af832 Mon Sep 17 00:00:00 2001 From: Max SCHMELLER Date: Wed, 27 Nov 2024 21:36:27 +0900 Subject: [PATCH 2/4] temp: only Hesai smoke tests Signed-off-by: Max SCHMELLER --- nebula_ros/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nebula_ros/CMakeLists.txt b/nebula_ros/CMakeLists.txt index 6caba4845..b13cf4006 100644 --- a/nebula_ros/CMakeLists.txt +++ b/nebula_ros/CMakeLists.txt @@ -228,7 +228,7 @@ if(BUILD_TESTING) ament_lint_auto_find_test_dependencies() - foreach(MODEL VLP16 VLP32 VLS128 Pandar40P Pandar64 PandarQT64 PandarQT128 Pandar128E4X PandarAT128 PandarXT32 PandarXT32M ARS548 SRR520 Helios Bpearl) + foreach(MODEL Pandar40P Pandar64 PandarQT64 PandarQT128 Pandar128E4X PandarAT128 PandarXT32 PandarXT32M) string(TOLOWER ${MODEL}_smoke_test test_name) add_ros_test( test/smoke_test.py From 6dee292c08bc892e4b6ec9948243f9762c32bd2a Mon Sep 17 00:00:00 2001 From: Max SCHMELLER Date: Wed, 27 Nov 2024 21:54:11 +0900 Subject: [PATCH 3/4] temp(nebula_tests): run nebula_tests on changes to nebula_ros, nebula_hw_interfaces too Signed-off-by: Max SCHMELLER --- nebula_tests/package.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nebula_tests/package.xml b/nebula_tests/package.xml index f593b2e01..92d5456ee 100644 --- a/nebula_tests/package.xml +++ b/nebula_tests/package.xml @@ -15,6 +15,8 @@ diagnostic_updater nebula_common nebula_decoders + nebula_hw_interfaces + nebula_ros rosbag2_cpp ament_cmake_gtest From ad35b0139dc11ea6fce11b05d95fcf777713805e Mon Sep 17 00:00:00 2001 From: Max SCHMELLER Date: Mon, 2 Dec 2024 16:28:51 +0900 Subject: [PATCH 4/4] chore(cspell): add CMake's `TOLOWER` keyword to dictionary Signed-off-by: Max SCHMELLER --- .cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.cspell.json b/.cspell.json index f305225f6..20174f922 100644 --- a/.cspell.json +++ b/.cspell.json @@ -49,6 +49,7 @@ "stds", "struct", "structs", + "TOLOWER", "UDP_SEQ", "usec", "vccint",