Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate launch tests to new launch_testing features & API #179

Merged
merged 3 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,38 @@ endif()

macro(targets)
configure_file(
test/test_dynamic_bridge.py.in
test_dynamic_bridge${target_suffix}.py.genexp
test/test_topics_across_dynamic_bridge.py.in
test_topics_across_dynamic_bridge${target_suffix}.py.genexp
@ONLY
)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_dynamic_bridge${target_suffix}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/test_dynamic_bridge${target_suffix}.py.genexp"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_topics_across_dynamic_bridge${target_suffix}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/test_topics_across_dynamic_bridge${target_suffix}.py.genexp"
)
ament_add_pytest_test(test_dynamic_bridge${target_suffix}
"${CMAKE_CURRENT_BINARY_DIR}/test_dynamic_bridge${target_suffix}_$<CONFIG>.py"
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/test_topics_across_dynamic_bridge${target_suffix}_$<CONFIG>.py"
TARGET test_topics_across_dynamic_bridge${target_suffix}
ENV RMW_IMPLEMENTAION=${rmw_implementaion}
TIMEOUT 60)

configure_file(
test/test_services_across_dynamic_bridge.py.in
test_services_across_dynamic_bridge${target_suffix}.py.genexp
@ONLY
)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_services_across_dynamic_bridge${target_suffix}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/test_services_across_dynamic_bridge${target_suffix}.py.genexp"
)
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/test_services_across_dynamic_bridge${target_suffix}_$<CONFIG>.py"
TARGET test_services_across_dynamic_bridge${target_suffix}
ENV RMW_IMPLEMENTAION=${rmw_implementaion}
TIMEOUT 60)
endmacro()

if(TEST_ROS1_BRIDGE)
find_package(ament_cmake_pytest REQUIRED)
find_package(launch_testing_ament_cmake REQUIRED)

add_executable(test_ros1_client "test/test_ros1_client.cpp")
ament_target_dependencies(test_ros1_client "ros1_roscpp")
Expand Down
3 changes: 2 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
<exec_depend>rcutils</exec_depend>
<exec_depend>std_msgs</exec_depend>

<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>demo_nodes_cpp</test_depend>
<test_depend>diagnostic_msgs</test_depend>
<test_depend>launch</test_depend>
<test_depend>launch_testing</test_depend>
<test_depend>launch_testing_ament_cmake</test_depend>
<test_depend>launch_testing_ros</test_depend>
<test_depend>ros2run</test_depend>

<group_depend>rosidl_interface_packages</group_depend>
Expand Down
195 changes: 0 additions & 195 deletions test/test_dynamic_bridge.py.in

This file was deleted.

87 changes: 87 additions & 0 deletions test/test_services_across_dynamic_bridge.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2016 Open Source Robotics Foundation, 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 unittest

from launch import LaunchDescription
from launch.actions import ExecuteProcess
from launch.actions import OpaqueFunction

import launch_testing


TEST_BRIDGE_ROS1_ENV = '@TEST_BRIDGE_ROS1_ENV@'
TEST_BRIDGE_ROSCORE = '@TEST_BRIDGE_ROSCORE@'
TEST_BRIDGE_ROS1_CLIENT = '@TEST_BRIDGE_ROS1_CLIENT@'
TEST_BRIDGE_ROS1_SERVER = '@TEST_BRIDGE_ROS1_SERVER@'
TEST_BRIDGE_DYNAMIC_BRIDGE = '@TEST_BRIDGE_DYNAMIC_BRIDGE@'
TEST_BRIDGE_ROS2_CLIENT = '@TEST_BRIDGE_ROS2_CLIENT@'
TEST_BRIDGE_ROS2_SERVER = '@TEST_BRIDGE_ROS2_SERVER@'


@launch_testing.parametrize('test_name,server_cmd,client_cmd', [
('ros1_server_ros2_client_across_dynamic_bridge',
[TEST_BRIDGE_ROS1_ENV, TEST_BRIDGE_ROS1_SERVER],
[TEST_BRIDGE_ROS2_CLIENT]),
('ros2_server_ros1_client_across_dynamic_bridge',
[TEST_BRIDGE_ROS2_SERVER],
[TEST_BRIDGE_ROS1_ENV, TEST_BRIDGE_ROS1_CLIENT]),
])
def generate_test_description(test_name, server_cmd, client_cmd, ready_fn):
launch_description = LaunchDescription()

# ROS 1 core
launch_description.add_action(ExecuteProcess(
cmd=[TEST_BRIDGE_ROS1_ENV, TEST_BRIDGE_ROSCORE],
name=test_name + '__roscore',
))

# dynamic bridge
rosbridge_process = ExecuteProcess(
cmd=[TEST_BRIDGE_ROS1_ENV, TEST_BRIDGE_DYNAMIC_BRIDGE],
name=test_name + '__dynamic_bridge',
)
launch_description.add_action(rosbridge_process)

server_process = ExecuteProcess(
cmd=server_cmd, name=test_name + '__server',
)
launch_description.add_action(server_process)

client_process = ExecuteProcess(
cmd=client_cmd, name=test_name + '__client',
)
launch_description.add_action(client_process)

launch_description.add_action(
OpaqueFunction(function=lambda context: ready_fn())
)
return launch_description, locals()


class TestServicesAcrossDynamicBridge(unittest.TestCase):
def test_client_process_terminates_after_a_finite_amount_of_time(self, client_process):
"""Test that the client executables terminates after a finite amount of time."""
self.proc_info.assertWaitForShutdown(process=client_process, timeout=30)


@launch_testing.post_shutdown_test()
class TestServicesAcrossDynamicBridgeAfterShutdown(unittest.TestCase):

def test_processes_finished_gracefully(self, proc_info, rosbridge_process,
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
server_process, client_process):
"""Test that both executables finished gracefully."""
launch_testing.asserts.assertExitCodes(proc_info, process=rosbridge_process)
launch_testing.asserts.assertExitCodes(proc_info, process=server_process)
launch_testing.asserts.assertExitCodes(proc_info, process=client_process)
Loading