From 4d09eebcec0ef2db85cd1061911a50dc8546ea99 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Thu, 20 Jun 2024 15:50:21 -0500 Subject: [PATCH 1/3] Call `gz sim` directly without shell=True for a clean exit Signed-off-by: Addisu Z. Taddese --- .../localization/test_localization_launch.py | 17 +++++------------ .../src/system/test_system_launch.py | 14 ++++---------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/nav2_system_tests/src/localization/test_localization_launch.py b/nav2_system_tests/src/localization/test_localization_launch.py index e56ca77986..8313a56328 100755 --- a/nav2_system_tests/src/localization/test_localization_launch.py +++ b/nav2_system_tests/src/localization/test_localization_launch.py @@ -27,14 +27,11 @@ import launch_ros.actions from launch_testing.legacy import LaunchTestService -from nav2_simple_commander.utils import kill_os_processes - def main(argv=sys.argv[1:]): testExecutable = os.getenv('TEST_EXECUTABLE') sim_dir = get_package_share_directory('nav2_minimal_tb3_sim') nav2_bringup_dir = get_package_share_directory('nav2_bringup') - ros_gz_sim_dir = get_package_share_directory('ros_gz_sim') world_sdf_xacro = os.path.join(sim_dir, 'worlds', 'tb3_sandbox.sdf.xacro') robot_sdf = os.path.join(sim_dir, 'urdf', 'gz_waffle.sdf') @@ -53,12 +50,10 @@ def main(argv=sys.argv[1:]): str(Path(os.path.join(sim_dir)).parent.resolve()) ) - start_gazebo_server = IncludeLaunchDescription( - PythonLaunchDescriptionSource( - os.path.join(ros_gz_sim_dir, 'launch', 'gz_sim.launch.py') - ), - launch_arguments={'gz_args': ['-r -s ', world_sdf_xacro]}.items(), - ) + start_gazebo_server = ExecuteProcess( + cmd=['gz', 'sim', '-r', '-s', world_sdf_xacro], + output='screen', + ), spawn_robot = IncludeLaunchDescription( PythonLaunchDescriptionSource( @@ -122,9 +117,7 @@ def main(argv=sys.argv[1:]): lts.add_test_action(ld, test1_action) ls = LaunchService(argv=argv) ls.include_launch_description(ld) - return_code = lts.run(ls) - kill_os_processes('gz sim') - return return_code + return lts.run(ls) if __name__ == '__main__': diff --git a/nav2_system_tests/src/system/test_system_launch.py b/nav2_system_tests/src/system/test_system_launch.py index a644072ebb..c2ec84b7b9 100755 --- a/nav2_system_tests/src/system/test_system_launch.py +++ b/nav2_system_tests/src/system/test_system_launch.py @@ -35,13 +35,11 @@ from launch_testing.legacy import LaunchTestService from nav2_common.launch import RewrittenYaml -from nav2_simple_commander.utils import kill_os_processes def generate_launch_description(): sim_dir = get_package_share_directory('nav2_minimal_tb3_sim') nav2_bringup_dir = get_package_share_directory('nav2_bringup') - ros_gz_sim_dir = get_package_share_directory('ros_gz_sim') world_sdf_xacro = os.path.join(sim_dir, 'worlds', 'tb3_sandbox.sdf.xacro') robot_sdf = os.path.join(sim_dir, 'urdf', 'gz_waffle.sdf') @@ -97,11 +95,9 @@ def generate_launch_description(): 'GZ_SIM_RESOURCE_PATH', str(Path(os.path.join(sim_dir)).parent.resolve()) ), - IncludeLaunchDescription( - PythonLaunchDescriptionSource( - os.path.join(ros_gz_sim_dir, 'launch', 'gz_sim.launch.py') - ), - launch_arguments={'gz_args': ['-r -s ', world_sdf_xacro]}.items(), + ExecuteProcess( + cmd=['gz', 'sim', '-r', '-s', world_sdf_xacro], + output='screen', ), IncludeLaunchDescription( PythonLaunchDescriptionSource( @@ -168,9 +164,7 @@ def main(argv=sys.argv[1:]): lts.add_test_action(ld, test1_action) ls = LaunchService(argv=argv) ls.include_launch_description(ld) - return_code = lts.run(ls) - kill_os_processes('gz sim') - return return_code + return lts.run(ls) if __name__ == '__main__': From 45a8888f7d70f39668bdc79eb53795080b787895 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Fri, 21 Jun 2024 15:28:58 -0500 Subject: [PATCH 2/3] Update all affected tests Signed-off-by: Addisu Z. Taddese --- .../src/system/test_system_with_obstacle_launch.py | 14 ++++---------- .../src/system/test_wrong_init_pose_launch.py | 14 ++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/nav2_system_tests/src/system/test_system_with_obstacle_launch.py b/nav2_system_tests/src/system/test_system_with_obstacle_launch.py index fb4468afef..9c05400fc3 100755 --- a/nav2_system_tests/src/system/test_system_with_obstacle_launch.py +++ b/nav2_system_tests/src/system/test_system_with_obstacle_launch.py @@ -35,13 +35,11 @@ from launch_testing.legacy import LaunchTestService from nav2_common.launch import RewrittenYaml -from nav2_simple_commander.utils import kill_os_processes def generate_launch_description(): sim_dir = get_package_share_directory('nav2_minimal_tb3_sim') nav2_bringup_dir = get_package_share_directory('nav2_bringup') - ros_gz_sim_dir = get_package_share_directory('ros_gz_sim') nav2_system_tests_dir = get_package_share_directory('nav2_system_tests') world_sdf_xacro = os.path.join(sim_dir, 'worlds', 'tb3_sandbox.sdf.xacro') @@ -100,11 +98,9 @@ def generate_launch_description(): 'GZ_SIM_RESOURCE_PATH', str(Path(os.path.join(sim_dir)).parent.resolve()) ), - IncludeLaunchDescription( - PythonLaunchDescriptionSource( - os.path.join(ros_gz_sim_dir, 'launch', 'gz_sim.launch.py') - ), - launch_arguments={'gz_args': ['-r -s ', world_sdf_xacro]}.items(), + ExecuteProcess( + cmd=['gz', 'sim', '-r', '-s', world_sdf_xacro], + output='screen', ), IncludeLaunchDescription( PythonLaunchDescriptionSource( @@ -181,9 +177,7 @@ def main(argv=sys.argv[1:]): lts.add_test_action(ld, test1_action) ls = LaunchService(argv=argv) ls.include_launch_description(ld) - return_code = lts.run(ls) - kill_os_processes('gz sim') - return return_code + return lts.run(ls) if __name__ == '__main__': diff --git a/nav2_system_tests/src/system/test_wrong_init_pose_launch.py b/nav2_system_tests/src/system/test_wrong_init_pose_launch.py index b0e2322692..d02462bef5 100755 --- a/nav2_system_tests/src/system/test_wrong_init_pose_launch.py +++ b/nav2_system_tests/src/system/test_wrong_init_pose_launch.py @@ -34,13 +34,11 @@ from launch_testing.legacy import LaunchTestService from nav2_common.launch import RewrittenYaml -from nav2_simple_commander.utils import kill_os_processes def generate_launch_description(): sim_dir = get_package_share_directory('nav2_minimal_tb3_sim') nav2_bringup_dir = get_package_share_directory('nav2_bringup') - ros_gz_sim_dir = get_package_share_directory('ros_gz_sim') world_sdf_xacro = os.path.join(sim_dir, 'worlds', 'tb3_sandbox.sdf.xacro') robot_sdf = os.path.join(sim_dir, 'urdf', 'gz_waffle.sdf') @@ -96,11 +94,9 @@ def generate_launch_description(): 'GZ_SIM_RESOURCE_PATH', str(Path(os.path.join(sim_dir)).parent.resolve()) ), - IncludeLaunchDescription( - PythonLaunchDescriptionSource( - os.path.join(ros_gz_sim_dir, 'launch', 'gz_sim.launch.py') - ), - launch_arguments={'gz_args': ['-r -s ', world_sdf_xacro]}.items(), + ExecuteProcess( + cmd=['gz', 'sim', '-r', '-s', world_sdf_xacro], + output='screen', ), IncludeLaunchDescription( PythonLaunchDescriptionSource( @@ -167,9 +163,7 @@ def main(argv=sys.argv[1:]): lts.add_test_action(ld, test1_action) ls = LaunchService(argv=argv) ls.include_launch_description(ld) - return_code = lts.run(ls) - kill_os_processes('gz sim') - return return_code + return lts.run(ls) if __name__ == '__main__': From 45820c3cedc68b10a32d9d23bc7edb2f41e140a7 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Fri, 21 Jun 2024 15:29:11 -0500 Subject: [PATCH 3/3] Remove unused file Signed-off-by: Addisu Z. Taddese --- .../nav2_simple_commander/utils.py | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 nav2_simple_commander/nav2_simple_commander/utils.py diff --git a/nav2_simple_commander/nav2_simple_commander/utils.py b/nav2_simple_commander/nav2_simple_commander/utils.py deleted file mode 100644 index d363901020..0000000000 --- a/nav2_simple_commander/nav2_simple_commander/utils.py +++ /dev/null @@ -1,55 +0,0 @@ -#! /usr/bin/env python3 -# Copyright 2024 Open Navigation LLC -# Copyright 2024 Stevedan Ogochukwu Omodolor Omodia -# -# 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. - -"""General utility functions.""" - -import os -import signal -import subprocess - - -def find_os_processes(name): - """Find all the processes that are running gz sim.""" - ps_output = subprocess.check_output(['ps', 'aux'], text=True) - ps_lines = ps_output.split('\n') - gz_sim_processes = [] - for line in ps_lines: - if name in line: - columns = line.split() - pid = columns[1] - command = ' '.join(columns[10:]) - if command.startswith(name): - gz_sim_processes.append((pid, command)) - return gz_sim_processes - - -def kill_process(pid): - """Kill a process with a given PID.""" - try: - os.kill(int(pid), signal.SIGKILL) - print(f'Successfully killed process with PID: {pid}') - except Exception as e: - print(f'Failed to kill process with PID: {pid}. Error: {e}') - - -def kill_os_processes(name): - """Kill all processes that are running with name.""" - processes = find_os_processes(name) - if processes: - for pid, _ in processes: - kill_process(pid) - else: - print(f'No processes found starting with {name}')