From 4d09eebcec0ef2db85cd1061911a50dc8546ea99 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Thu, 20 Jun 2024 15:50:21 -0500 Subject: [PATCH] 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__':