Drops legacy launch API usage. (#387)
* Drops legacy launch API usage. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Adds launch_testing as test dependency. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
This commit is contained in:
parent
b0a124dcf6
commit
e133167524
3 changed files with 40 additions and 32 deletions
|
@ -36,7 +36,7 @@
|
||||||
<test_depend>ament_lint_common</test_depend>
|
<test_depend>ament_lint_common</test_depend>
|
||||||
<test_depend>rmw</test_depend>
|
<test_depend>rmw</test_depend>
|
||||||
<test_depend>rmw_implementation_cmake</test_depend>
|
<test_depend>rmw_implementation_cmake</test_depend>
|
||||||
<test_depend>launch</test_depend>
|
<test_depend>launch_testing</test_depend>
|
||||||
<test_depend>osrf_testing_tools_cpp</test_depend>
|
<test_depend>osrf_testing_tools_cpp</test_depend>
|
||||||
<test_depend>test_msgs</test_depend>
|
<test_depend>test_msgs</test_depend>
|
||||||
|
|
||||||
|
|
|
@ -2,35 +2,40 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from launch.legacy import LaunchDescriptor
|
from launch import LaunchDescription
|
||||||
from launch.legacy.launcher import DefaultLauncher
|
from launch import LaunchService
|
||||||
|
from launch.actions import ExecuteProcess
|
||||||
|
from launch_testing import LaunchTestService
|
||||||
|
|
||||||
|
|
||||||
def launch_test(
|
def launch_test(
|
||||||
rmw_implementation_env=None, rcl_assert_rmw_id_matches_env=None, expect_failure=False
|
rmw_implementation_env=None, rcl_assert_rmw_id_matches_env=None, expect_failure=False
|
||||||
):
|
):
|
||||||
ld = LaunchDescriptor()
|
launch_test = LaunchTestService()
|
||||||
|
launch_description = LaunchDescription()
|
||||||
|
|
||||||
env = dict(os.environ)
|
env = dict(os.environ)
|
||||||
if rmw_implementation_env is not None:
|
if rmw_implementation_env is not None:
|
||||||
env['RMW_IMPLEMENTATION'] = rmw_implementation_env
|
env['RMW_IMPLEMENTATION'] = rmw_implementation_env
|
||||||
if rcl_assert_rmw_id_matches_env is not None:
|
if rcl_assert_rmw_id_matches_env is not None:
|
||||||
env['RCL_ASSERT_RMW_ID_MATCHES'] = rcl_assert_rmw_id_matches_env
|
env['RCL_ASSERT_RMW_ID_MATCHES'] = rcl_assert_rmw_id_matches_env
|
||||||
|
|
||||||
ld.add_process(
|
launch_test.add_test_action(
|
||||||
cmd=['@TEST_RMW_IMPL_ID_CHECK_EXECUTABLE_NAME@'],
|
launch_description, ExecuteProcess(
|
||||||
name='@TEST_RMW_IMPL_ID_CHECK_EXECUTABLE_NAME@',
|
cmd=['@TEST_RMW_IMPL_ID_CHECK_EXECUTABLE_NAME@'],
|
||||||
env=env,
|
name='@TEST_RMW_IMPL_ID_CHECK_EXECUTABLE_NAME@',
|
||||||
|
env=env,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
launcher = DefaultLauncher()
|
launch_service = LaunchService()
|
||||||
launcher.add_launch_descriptor(ld)
|
launch_service.include_launch_description(launch_description)
|
||||||
rc = launcher.launch()
|
rc = launch_test.run(launch_service)
|
||||||
|
|
||||||
if expect_failure:
|
if expect_failure:
|
||||||
assert rc != 0, 'The executable did not fail as expected.'
|
assert rc != 0, 'The executable did not fail as expected.'
|
||||||
else:
|
else:
|
||||||
assert rc == 0, "The executable failed with exit code '" + str(rc) + "'. "
|
assert rc == 0, "The executable failed with exit code '" + str(rc) + "'. "
|
||||||
|
|
||||||
|
|
||||||
def test_rmw_implementation_env():
|
def test_rmw_implementation_env():
|
||||||
|
@ -71,6 +76,6 @@ def test_both():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_rmw_impl_env()
|
test_rmw_implementation_env()
|
||||||
test_rcl_assert_rmw_id_matches_env()
|
test_rcl_assert_rmw_id_matches_env()
|
||||||
test_both()
|
test_both()
|
||||||
|
|
|
@ -1,29 +1,32 @@
|
||||||
# generated from rcl/test/test_two_executables.py.in
|
# generated from rcl/test/test_two_executables.py.in
|
||||||
|
|
||||||
from launch.legacy import LaunchDescriptor
|
from launch import LaunchDescription
|
||||||
from launch.legacy.exit_handler import ignore_signal_exit_handler
|
from launch import LaunchService
|
||||||
from launch.legacy.exit_handler import primary_exit_handler
|
from launch.actions import ExecuteProcess
|
||||||
from launch.legacy.launcher import DefaultLauncher
|
from launch_testing import LaunchTestService
|
||||||
|
|
||||||
|
|
||||||
def @TEST_NAME@():
|
def @TEST_NAME@():
|
||||||
ld = LaunchDescriptor()
|
launch_test = LaunchTestService()
|
||||||
|
launch_description = LaunchDescription()
|
||||||
|
|
||||||
ld.add_process(
|
launch_test.add_fixture_action(
|
||||||
cmd=['@TEST_EXECUTABLE1@'],
|
launch_description, ExecuteProcess(
|
||||||
name='@TEST_EXECUTABLE1_NAME@',
|
cmd=['@TEST_EXECUTABLE1@'],
|
||||||
exit_handler=ignore_signal_exit_handler,
|
name='@TEST_EXECUTABLE1_NAME@',
|
||||||
|
), exit_allowed=True
|
||||||
)
|
)
|
||||||
|
|
||||||
ld.add_process(
|
launch_test.add_test_action(
|
||||||
cmd=['@TEST_EXECUTABLE2@', '@TEST_EXECUTABLE1_NAME@'],
|
launch_description, ExecuteProcess(
|
||||||
name='@TEST_EXECUTABLE2_NAME@',
|
cmd=['@TEST_EXECUTABLE2@', '@TEST_EXECUTABLE1_NAME@'],
|
||||||
exit_handler=primary_exit_handler,
|
name='@TEST_EXECUTABLE2_NAME@',
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
launcher = DefaultLauncher()
|
launch_service = LaunchService()
|
||||||
launcher.add_launch_descriptor(ld)
|
launch_service.include_launch_description(launch_description)
|
||||||
rc = launcher.launch()
|
rc = launch_test.run(launch_service)
|
||||||
|
|
||||||
assert rc == 0, "The launch file failed with exit code '" + str(rc) + "'. "
|
assert rc == 0, "The launch file failed with exit code '" + str(rc) + "'. "
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue