diff --git a/realsense2_camera/test/live_camera/rosci.py b/realsense2_camera/test/live_camera/rosci.py index 5fb98c155..d6acd50c3 100755 --- a/realsense2_camera/test/live_camera/rosci.py +++ b/realsense2_camera/test/live_camera/rosci.py @@ -50,7 +50,7 @@ def usage(): print( ' --device <> Run only on the specified device(s); list of devices separated by ',', No white spaces' ) print( ' e.g.: --device=d455,d435i,d585 (or) --device d455,d435i,d585 ') print( ' Note: if --device option not used, tests run on all connected devices ') - + sys.exit( 2 ) def command(dev_name, test=None): @@ -58,7 +58,7 @@ def command(dev_name, test=None): cmd += ['-s'] cmd += ['-m', ''.join(dev_name)] if test: - cmd += ['-k', f'{test}'] + cmd += ['-k', f'{test}'] cmd += [''.join(dir_live_tests)] cmd += ['--debug'] cmd += [f'--junit-xml={logdir}/{dev_name.upper()}_pytest.xml'] @@ -70,7 +70,7 @@ def run_test(cmd, test=None, dev_name=None, stdout=None, append =False): if test: stdout = stdout + os.sep + str(dev_name.upper()) + '_' + test + '.log' else: - stdout = stdout + os.sep + str(dev_name.upper()) + '_' + 'full.log' + stdout = stdout + os.sep + str(dev_name.upper()) + '_' + 'full.log' if stdout is None: sys.stdout.flush() elif stdout and stdout != subprocess.PIPE: @@ -93,10 +93,10 @@ def run_test(cmd, test=None, dev_name=None, stdout=None, append =False): except Exception as e: log.e("---Test Failed---") log.w( "Error Exception:\n ",e ) - + finally: if handle: - handle.close() + handle.close() junit_xml_parsing(f'{dev_name.upper()}_pytest.xml') def junit_xml_parsing(xml_file): @@ -121,24 +121,29 @@ def junit_xml_parsing(xml_file): new_xml = xml_file.split('.')[0] tree.write(f'{logdir}/{new_xml}_refined.xml') -def find_devices_run_tests(): - global logdir, device_set +def find_devices_run_tests(): + from rspy import devices + global logdir, device_set, _device_by_sn + max_retry = 3 try: os.makedirs( logdir, exist_ok=True ) - - from rspy import devices + #Update dict '_device_by_sn' from devices module of rspy - devices.query( hub_reset = hub_reset ) - global _device_by_sn + while(max_retry and not devices._device_by_sn): + subprocess.run('ykushcmd ykush3 --reset', shell=True) + time.sleep(2.0) + devices.query( hub_reset = hub_reset ) + max_retry -= 1 + if not devices._device_by_sn: assert False, 'No Camera device detected!' else: - connected_devices = [device.name for device in devices._device_by_sn.values()] - log.i('Connected devices:', connected_devices) - + connected_devices = [device.name for device in devices._device_by_sn.values()] + log.i('Connected devices:', connected_devices) + testname = regex if regex else None - + if device_set: #Loop in for user specified devices and run tests only on them devices_not_found = [] @@ -183,7 +188,7 @@ def find_devices_run_tests(): regex = arg elif opt == '--device': device_set = arg.split(',') - + find_devices_run_tests() sys.exit( 0 )