|
26 | 26 | Available tests:
|
27 | 27 |
|
28 | 28 | test_fastdds_installed
|
| 29 | + test_fastdds_version |
29 | 30 | test_fastdds_discovery
|
| 31 | + test_fastdds_discovery_run |
30 | 32 | test_fastdds_shm
|
| 33 | + test_fastdds_xml_validate |
| 34 | + test_ros_discovery |
31 | 35 |
|
32 | 36 | """
|
33 | 37 |
|
34 | 38 | import argparse
|
35 | 39 | import os
|
36 | 40 | import subprocess
|
| 41 | +import signal |
37 | 42 | import sys
|
38 | 43 | from pathlib import Path
|
| 44 | +try: # Try catch for new python dependency |
| 45 | + import psutil |
| 46 | +except ImportError: |
| 47 | + print( |
| 48 | + 'psutil module not found. ' |
| 49 | + 'Try to install running "pip install psutil"') |
| 50 | + sys.exit(1) |
39 | 51 |
|
40 | 52 |
|
41 | 53 | def setup_script_name():
|
@@ -121,6 +133,36 @@ def test_fastdds_discovery(install_path, setup_script_path):
|
121 | 133 | sys.exit(ret)
|
122 | 134 |
|
123 | 135 |
|
| 136 | +def test_fastdds_discovery_run(install_path, setup_script_path): |
| 137 | + """Test that discovery command runs.""" |
| 138 | + args = ' discovery -l 127.0.0.1' |
| 139 | + try: |
| 140 | + test_timeout = 10 |
| 141 | + process = subprocess.Popen( |
| 142 | + cmd(install_path=install_path, |
| 143 | + setup_script_path=setup_script_path, |
| 144 | + args=args), |
| 145 | + shell=True) |
| 146 | + ret = process.wait(timeout=test_timeout) |
| 147 | + # Manually set the error return code because we need the process to timeout |
| 148 | + ret = 3 |
| 149 | + except subprocess.TimeoutExpired: |
| 150 | + print(f'Timeout {test_timeout} expired. Test successful') |
| 151 | + try: |
| 152 | + # Need to kill all child processes to properly end the test |
| 153 | + parent = psutil.Process(process.pid) |
| 154 | + for child in parent.children(recursive=True): |
| 155 | + child.terminate() |
| 156 | + parent.terminate() |
| 157 | + ret = 0 |
| 158 | + except Exception as e: |
| 159 | + print(f"Error while ending child processes: {e}") |
| 160 | + |
| 161 | + if 0 != ret: |
| 162 | + print('test_fastdds_discovery_run FAILED') |
| 163 | + sys.exit(ret) |
| 164 | + |
| 165 | + |
124 | 166 | def test_ros_discovery(install_path, setup_script_path):
|
125 | 167 | """Test that discovery command runs."""
|
126 | 168 | args = ' -h'
|
@@ -200,6 +242,8 @@ def get_paths(install_path):
|
200 | 242 | lambda: test_fastdds_installed(fastdds_tool_path),
|
201 | 243 | 'test_fastdds_discovery': lambda: test_fastdds_discovery(
|
202 | 244 | fastdds_tool_path, setup_script_path),
|
| 245 | + 'test_fastdds_discovery_run': lambda: test_fastdds_discovery_run( |
| 246 | + fastdds_tool_path, setup_script_path), |
203 | 247 | 'test_ros_discovery':
|
204 | 248 | lambda: test_ros_discovery(ros_disc_tool_path, setup_script_path),
|
205 | 249 | 'test_fastdds_shm': lambda: test_fastdds_shm(fastdds_tool_path),
|
|
0 commit comments