|
| 1 | +# Copyright (c) 2022 by Apex.AI Inc. All rights reserved. |
| 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 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
| 17 | +import os |
| 18 | + |
| 19 | +import unittest |
| 20 | + |
| 21 | +import launch |
| 22 | +from launch_ros.substitutions import ExecutableInPackage |
| 23 | +import launch_testing |
| 24 | +import launch_testing.actions |
| 25 | +from launch_testing.asserts import assertSequentialStdout |
| 26 | + |
| 27 | +import pytest |
| 28 | + |
| 29 | +# @brief Test goal: "Integrationtest for the request response basic example of iceoryx" |
| 30 | +# @pre setup ROS2 launch executables for RouDi (debug mode) and the example processes |
| 31 | +# @post check if all applications return exitcode 0 (success) after test run |
| 32 | +@pytest.mark.launch_test |
| 33 | +def generate_test_description(): |
| 34 | + |
| 35 | + proc_env = os.environ.copy() |
| 36 | + colcon_prefix_path = os.environ.get('COLCON_PREFIX_PATH', '') |
| 37 | + executable_list = ['iox-cpp-request-response-untyped-client', 'iox-cpp-request-response-untyped-server'] |
| 38 | + process_list = [] |
| 39 | + |
| 40 | + for exec in executable_list: |
| 41 | + tmp_exec = os.path.join( |
| 42 | + colcon_prefix_path, |
| 43 | + 'example_request_response_basic/bin/', |
| 44 | + exec) |
| 45 | + tmp_process = launch.actions.ExecuteProcess( |
| 46 | + cmd=[tmp_exec], |
| 47 | + env=proc_env, output='screen') |
| 48 | + process_list.append(tmp_process) |
| 49 | + |
| 50 | + print("Process list:", process_list) |
| 51 | + |
| 52 | + roudi_executable = os.path.join( |
| 53 | + colcon_prefix_path, |
| 54 | + 'iceoryx_posh/bin/', |
| 55 | + 'iox-roudi' |
| 56 | + ) |
| 57 | + roudi_process = launch.actions.ExecuteProcess( |
| 58 | + cmd=[roudi_executable, '-l', 'debug'], |
| 59 | + env=proc_env, output='screen', |
| 60 | + sigterm_timeout='20') |
| 61 | + |
| 62 | + return launch.LaunchDescription([ |
| 63 | + process_list[0], |
| 64 | + process_list[1], |
| 65 | + roudi_process, |
| 66 | + launch_testing.actions.ReadyToTest() |
| 67 | + ]), {'iox-cpp-request-response-untyped-client': process_list[0], 'iox-cpp-request-response-untyped-server': process_list[1], |
| 68 | + 'roudi_process': roudi_process} |
| 69 | + |
| 70 | +# These tests will run concurrently with the dut process. After this test is done, |
| 71 | +# the launch system will shut down RouDi |
| 72 | + |
| 73 | + |
| 74 | +class TestRequestResponseUntypedExample(unittest.TestCase): |
| 75 | + def test_roudi_ready(self, proc_output): |
| 76 | + proc_output.assertWaitFor( |
| 77 | + 'RouDi is ready for clients', timeout=45, stream='stdout') |
| 78 | + |
| 79 | + def test_untyped_server_client_data_exchange(self, proc_output): |
| 80 | + proc_output.assertWaitFor( |
| 81 | + 'iox-cpp-request-response-client-untyped Send Request: 55 + 89', timeout=45, stream='stdout') |
| 82 | + proc_output.assertWaitFor( |
| 83 | + 'iox-cpp-request-response-server-untyped Got Request: 55 + 89', timeout=45, stream='stdout') |
| 84 | + |
| 85 | + proc_output.assertWaitFor( |
| 86 | + 'iox-cpp-request-response-server-untyped Send Response: 144', timeout=45, stream='stdout') |
| 87 | + proc_output.assertWaitFor( |
| 88 | + 'iox-cpp-request-response-client-untyped Got Response : 144', timeout=45, stream='stdout') |
| 89 | + |
| 90 | + |
| 91 | +# These tests run after shutdown and examine the stdout log |
| 92 | + |
| 93 | + |
| 94 | +@launch_testing.post_shutdown_test() |
| 95 | +class TestRequestResponseUntypedExampleExitCodes(unittest.TestCase): |
| 96 | + def test_exit_code(self, proc_info): |
| 97 | + launch_testing.asserts.assertExitCodes(proc_info) |
| 98 | + |
0 commit comments