Skip to content

Commit

Permalink
test(nebula_ros): add smoke tests (#240)
Browse files Browse the repository at this point in the history
* test(nebula_ros): add smoke test for every sensor

Signed-off-by: Max SCHMELLER <[email protected]>

* temp: only Hesai smoke tests

Signed-off-by: Max SCHMELLER <[email protected]>

* temp(nebula_tests): run nebula_tests on changes to nebula_ros, nebula_hw_interfaces too

Signed-off-by: Max SCHMELLER <[email protected]>

* chore(cspell): add CMake's `TOLOWER` keyword to dictionary

Signed-off-by: Max SCHMELLER <[email protected]>

* test(nebula_ros): add smoke test for XT16

Signed-off-by: Max SCHMELLER <[email protected]>

* chore(nebula_ros): better wording

Signed-off-by: Max SCHMELLER <[email protected]>

---------

Signed-off-by: Max SCHMELLER <[email protected]>
  • Loading branch information
mojomex authored Feb 4, 2025
1 parent 48d9ab9 commit 324d721
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"stds",
"struct",
"structs",
"TOLOWER",
"UDP_SEQ",
"usec",
"vccint",
Expand Down
12 changes: 12 additions & 0 deletions nebula_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 Pandar40P Pandar64 PandarQT64 PandarQT128 Pandar128E4X PandarAT128 PandarXT16 PandarXT32 PandarXT32M)
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}")
Expand Down
2 changes: 2 additions & 0 deletions nebula_ros/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>ros_environment</buildtool_depend>
<buildtool_depend>ros_testing</buildtool_depend>

<depend>continental_msgs</depend>
<depend>continental_srvs</depend>
Expand All @@ -34,6 +35,7 @@

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ros_testing</test_depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
56 changes: 56 additions & 0 deletions nebula_ros/test/smoke_test.py
Original file line number Diff line number Diff line change
@@ -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 coming online."""
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 exceeded ({}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 TestCleanShutdown(unittest.TestCase):
def test_exit_code(self, proc_info):
launch_testing.asserts.assertExitCodes(proc_info)
2 changes: 2 additions & 0 deletions nebula_tests/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<depend>diagnostic_updater</depend>
<depend>nebula_common</depend>
<depend>nebula_decoders</depend>
<depend>nebula_hw_interfaces</depend>
<depend>nebula_ros</depend>
<depend>rosbag2_cpp</depend>

<test_depend>ament_cmake_gtest</test_depend>
Expand Down

0 comments on commit 324d721

Please sign in to comment.