From 090d010be0c628c24bb007c376d438a678e86182 Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Fri, 13 Dec 2024 12:41:05 +0100 Subject: [PATCH 1/2] Refs #22463: Add test to check proper link between python and cpp files Signed-off-by: cferreiragonz --- .github/workflows/reusable-ubuntu-ci.yml | 2 +- test/system/tools/fastdds/CMakeLists.txt | 1 + test/system/tools/fastdds/tests.py | 44 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable-ubuntu-ci.yml b/.github/workflows/reusable-ubuntu-ci.yml index 2468dd4a483..c179c934368 100644 --- a/.github/workflows/reusable-ubuntu-ci.yml +++ b/.github/workflows/reusable-ubuntu-ci.yml @@ -199,7 +199,7 @@ jobs: - name: Install Python dependencies uses: eProsima/eProsima-CI/ubuntu/install_python_packages@v0 with: - packages: vcstool xmlschema + packages: vcstool xmlschema psutil - name: Setup CCache uses: eProsima/eProsima-CI/external/setup-ccache-action@v0 diff --git a/test/system/tools/fastdds/CMakeLists.txt b/test/system/tools/fastdds/CMakeLists.txt index e991b76a70c..2021a4ab032 100644 --- a/test/system/tools/fastdds/CMakeLists.txt +++ b/test/system/tools/fastdds/CMakeLists.txt @@ -28,6 +28,7 @@ if(Python3_Interpreter_FOUND) test_fastdds_installed test_fastdds_version test_fastdds_discovery + test_fastdds_discovery_run test_ros_discovery test_fastdds_shm test_fastdds_xml_validate diff --git a/test/system/tools/fastdds/tests.py b/test/system/tools/fastdds/tests.py index f9365136fd5..217e4cfa7da 100644 --- a/test/system/tools/fastdds/tests.py +++ b/test/system/tools/fastdds/tests.py @@ -26,16 +26,28 @@ Available tests: test_fastdds_installed + test_fastdds_version test_fastdds_discovery + test_fastdds_discovery_run test_fastdds_shm + test_fastdds_xml_validate + test_ros_discovery """ import argparse import os import subprocess +import signal import sys from pathlib import Path +try: # Try catch for new python dependency + import psutil +except ImportError: + print( + 'psutil module not found. ' + 'Try to install running "pip install psutil"') + sys.exit(1) def setup_script_name(): @@ -128,6 +140,36 @@ def test_fastdds_discovery(install_path, setup_script_path): sys.exit(ret) +def test_fastdds_discovery_run(install_path, setup_script_path): + """Test that discovery command runs.""" + args = ' discovery -l 127.0.0.1' + try: + test_timeout = 10 + process = subprocess.Popen( + cmd(install_path=install_path, + setup_script_path=setup_script_path, + args=args), + shell=True) + ret = process.wait(timeout=test_timeout) + # Manually set the error return code because we need the process to timeout + ret = 3 + except subprocess.TimeoutExpired: + print(f'Timeout {test_timeout} expired. Test successful') + try: + # Need to kill all child processes to properly end the test + parent = psutil.Process(process.pid) + for child in parent.children(recursive=True): + child.terminate() + parent.terminate() + ret = 0 + except Exception as e: + print(f"Error while ending child processes: {e}") + + if 0 != ret: + print('test_fastdds_discovery_run FAILED') + sys.exit(ret) + + def test_ros_discovery(install_path, setup_script_path): """Test that discovery command runs.""" args = ' -h' @@ -209,6 +251,8 @@ def get_paths(install_path): lambda: test_fastdds_version(fastdds_tool_path), 'test_fastdds_discovery': lambda: test_fastdds_discovery( fastdds_tool_path, setup_script_path), + 'test_fastdds_discovery_run': lambda: test_fastdds_discovery_run( + fastdds_tool_path, setup_script_path), 'test_ros_discovery': lambda: test_ros_discovery(ros_disc_tool_path, setup_script_path), 'test_fastdds_shm': lambda: test_fastdds_shm(fastdds_tool_path), From 1a5cf4e800f822c65ac98474b835bc314352b3c7 Mon Sep 17 00:00:00 2001 From: cferreiragonz Date: Fri, 13 Dec 2024 12:41:59 +0100 Subject: [PATCH 2/2] Refs #22463: Remove .bat.in and call .exe from python Signed-off-by: cferreiragonz --- tools/fastdds/discovery/parser.py | 11 ++++++++--- tools/fds/CMakeLists.txt | 2 +- tools/fds/fast-discovery-server.bat.in | 15 --------------- 3 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 tools/fds/fast-discovery-server.bat.in diff --git a/tools/fastdds/discovery/parser.py b/tools/fastdds/discovery/parser.py index 2d57f5d0b29..08b68f3f24f 100644 --- a/tools/fastdds/discovery/parser.py +++ b/tools/fastdds/discovery/parser.py @@ -94,9 +94,14 @@ def __find_tool_path(self): elif os.name == 'nt': ret = tool_path / 'fast-discovery-server.exe' if not os.path.exists(ret): - ret = tool_path / 'fast-discovery-server.bat' - if not os.path.exists(ret): - print('fast-discovery-server tool not installed') + exe_files = [f for f in tool_path.glob('*.exe') if re.match(r'fast-discovery-server.*\.exe$', f.name)] + if len(exe_files) == 0: + print("Unable to find fast-discovery-server tool. Check installation") + elif len(exe_files) == 1: + ret = exe_files[0] + print(f'[PYTHON] Found executable: {ret}') + else: + print('Multiple candidates for fast-discovery-server.exe. Check installation') sys.exit(1) else: print(f'{os.name} not supported') diff --git a/tools/fds/CMakeLists.txt b/tools/fds/CMakeLists.txt index 007033f63c1..0059845ba41 100644 --- a/tools/fds/CMakeLists.txt +++ b/tools/fds/CMakeLists.txt @@ -107,7 +107,7 @@ install(EXPORT ${PROJECT_NAME}-targets if( WIN32 ) # Use powershell to generate the link install( - CODE "execute_process( COMMAND PowerShell -Command \"if( test-path ${PROJECT_NAME}.exe -PathType Leaf ) { rm ${PROJECT_NAME}.exe } ; New-Item -ItemType SymbolicLink -Target $ -Path ${PROJECT_NAME}.exe \" ERROR_QUIET RESULTS_VARIABLE SYMLINK_FAILED WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR}\") \n if( SYMLINK_FAILED ) \n message(STATUS \"Windows requires admin installation rights to create symlinks. A bat script will be provided instead.\") \n set(FAST_SERVER_BINARY_NAME $) \n configure_file(${CMAKE_CURRENT_LIST_DIR}/fast-discovery-server.bat.in ${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR}${MSVCARCH_DIR_EXTENSION}/${PROJECT_NAME}.bat @ONLY) \n endif()" + CODE "execute_process( COMMAND PowerShell -Command \"if( test-path ${PROJECT_NAME}.exe -PathType Leaf ) { rm ${PROJECT_NAME}.exe } ; New-Item -ItemType SymbolicLink -Target $ -Path ${PROJECT_NAME}.exe \" ERROR_QUIET RESULTS_VARIABLE SYMLINK_FAILED WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR}\") \n if( SYMLINK_FAILED ) \n message(STATUS \"Windows requires admin installation rights to create symlinks. Build again with privileges to create symlink. Tool will try to find executable if no symlink is found.\") \n endif()" COMPONENT discovery) else() # Use ln to create the symbolic link. We remove the version from the file name but keep the debug suffix diff --git a/tools/fds/fast-discovery-server.bat.in b/tools/fds/fast-discovery-server.bat.in deleted file mode 100644 index a62744006b3..00000000000 --- a/tools/fds/fast-discovery-server.bat.in +++ /dev/null @@ -1,15 +0,0 @@ -@echo off -rem This batch file simplifies fast-discovery-server tool scripting use by -rem offering a version independent name. It will be generated only if an unprivileged -rem installation prevents symlink creation. - -rem Bypass "Terminate Batch Job" prompt. -if "%~1"=="-FIXED_CTRL_C" ( - REM Remove the -FIXED_CTRL_C parameter - SHIFT - "%~dp0@FAST_SERVER_BINARY_NAME@" %* -) ELSE ( - REM Run the batch with