|
| 1 | +# Copyright 2016 Open Source Robotics Foundation, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import os |
| 16 | + |
| 17 | +from launch.legacy import LaunchDescriptor |
| 18 | +from launch.legacy.exit_handler import ignore_exit_handler |
| 19 | +from launch.legacy.exit_handler import primary_ignore_returncode_exit_handler |
| 20 | +from launch.legacy.launcher import DefaultLauncher |
| 21 | +from launch.legacy.output_handler import ConsoleOutput |
| 22 | +from launch_testing import create_handler |
| 23 | + |
| 24 | + |
| 25 | +def setup(): |
| 26 | + os.environ['OSPL_VERBOSITY'] = '8' # 8 = OS_NONE |
| 27 | + # bare minimum formatting for console output matching |
| 28 | + os.environ['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = '{message}' |
| 29 | + |
| 30 | + |
| 31 | +def test_reliable_qos(): |
| 32 | + pub_executable_args = ['-r', '1', '-s', '0', '-b', '-f', '5'] |
| 33 | + sub_executable_args = ['-r', '1', '-s', '0'] |
| 34 | + _test_executables(pub_executable_args, sub_executable_args) |
| 35 | + |
| 36 | + |
| 37 | +def _test_executables(publisher_executable_args, subscriber_executable_args): |
| 38 | + output_handlers = [] |
| 39 | + launch_descriptor = LaunchDescriptor() |
| 40 | + |
| 41 | + rmw_implementation = @rmw_implementation@ |
| 42 | + env = dict(os.environ) |
| 43 | + env['RMW_IMPLEMENTATION'] = rmw_implementation |
| 44 | + env['PYTHONUNBUFFERED'] = '1' |
| 45 | + |
| 46 | + # Launch the process that will receive the images. |
| 47 | + # This is the process that gets to decide when to tear the launcher down. |
| 48 | + # It will exit when the regex for receiving images is matched. |
| 49 | + showimage_executable = @showimage_py_exe@ |
| 50 | + showimage_output_file = @showimage_py_outfile@ |
| 51 | + showimage_name = 'test_showimage_py' |
| 52 | + showimage_handler = create_handler( |
| 53 | + showimage_name, launch_descriptor, showimage_output_file, exit_on_match=True, |
| 54 | + filtered_rmw_implementation=rmw_implementation) |
| 55 | + assert showimage_handler, 'Cannot find appropriate handler for %s' % showimage_output_file |
| 56 | + output_handlers.append(showimage_handler) |
| 57 | + |
| 58 | + command = [showimage_executable] |
| 59 | + command.extend(subscriber_executable_args) |
| 60 | + launch_descriptor.add_process( |
| 61 | + cmd=command, |
| 62 | + name=showimage_name, |
| 63 | + exit_handler=primary_ignore_returncode_exit_handler, |
| 64 | + output_handlers=[showimage_handler, ConsoleOutput()], |
| 65 | + env=env, |
| 66 | + ) |
| 67 | + |
| 68 | + # Launch the process that will publish the images. |
| 69 | + # This process will be exited when the launcher is torn down. |
| 70 | + cam2image_executable = @cam2image_py_exe@ |
| 71 | + cam2image_output_file = @cam2image_py_outfile@ |
| 72 | + cam2image_name = 'test_cam2image_py' |
| 73 | + cam2image_handler = create_handler( |
| 74 | + cam2image_name, launch_descriptor, cam2image_output_file, exit_on_match=False, |
| 75 | + filtered_rmw_implementation=rmw_implementation) |
| 76 | + assert cam2image_handler, 'Cannot find appropriate handler for %s' % cam2image_output_file |
| 77 | + output_handlers.append(cam2image_handler) |
| 78 | + |
| 79 | + command = [cam2image_executable] |
| 80 | + command.extend(publisher_executable_args) |
| 81 | + launch_descriptor.add_process( |
| 82 | + cmd=command, |
| 83 | + name=cam2image_name, |
| 84 | + exit_handler=ignore_exit_handler, |
| 85 | + output_handlers=[cam2image_handler, ConsoleOutput()], |
| 86 | + env=env, |
| 87 | + ) |
| 88 | + |
| 89 | + launcher = DefaultLauncher() |
| 90 | + launcher.add_launch_descriptor(launch_descriptor) |
| 91 | + rc = launcher.launch() |
| 92 | + |
| 93 | + assert rc == 0, \ |
| 94 | + "The launch file failed with exit code '" + str(rc) + "'. " |
| 95 | + |
| 96 | + # Check that the output received by the handlers is what was expected. |
| 97 | + for handler in output_handlers: |
| 98 | + handler.check() |
| 99 | + |
| 100 | + |
| 101 | +if __name__ == '__main__': |
| 102 | + test_reliable_qos() |
0 commit comments