From f62e29cc30bd54e07be27f3d631a8e8be0ad5072 Mon Sep 17 00:00:00 2001 From: administrator Date: Sun, 8 Sep 2024 07:56:36 +0300 Subject: [PATCH 1/2] retry thrice finding devices with Ykush reset --- realsense2_camera/test/live_camera/rosci.py | 39 ++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/realsense2_camera/test/live_camera/rosci.py b/realsense2_camera/test/live_camera/rosci.py index 5fb98c1554..b403b397d6 100755 --- a/realsense2_camera/test/live_camera/rosci.py +++ b/realsense2_camera/test/live_camera/rosci.py @@ -25,6 +25,8 @@ #For running this script locally #Extract the root where both realsense-ros and librealsense are cloned ws_local = '/'.join(os.path.abspath( __file__ ).split( os.path.sep )[0:-5]) + print("##Check point") + print(ws_local) #expected to have 'librealsense' repo in parallel to 'realsense-ros' assert os.path.exists( os.path.join(ws_local, 'librealsense')), f" 'librealsense' doesn't exist at {ws_local} " sys.path.append( os.path.join( ws_local, 'librealsense/unit-tests/py' )) @@ -50,7 +52,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 +60,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 +72,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 +95,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 +123,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 +190,7 @@ def find_devices_run_tests(): regex = arg elif opt == '--device': device_set = arg.split(',') - + find_devices_run_tests() sys.exit( 0 ) From 667b23caa998ddefb95299f54ecf4b8c8196ca92 Mon Sep 17 00:00:00 2001 From: administrator Date: Sun, 8 Sep 2024 08:07:00 +0300 Subject: [PATCH 2/2] retry thrice finding devices with Ykush reset --- realsense2_camera/test/live_camera/rosci.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/realsense2_camera/test/live_camera/rosci.py b/realsense2_camera/test/live_camera/rosci.py index b403b397d6..d6acd50c35 100755 --- a/realsense2_camera/test/live_camera/rosci.py +++ b/realsense2_camera/test/live_camera/rosci.py @@ -25,8 +25,6 @@ #For running this script locally #Extract the root where both realsense-ros and librealsense are cloned ws_local = '/'.join(os.path.abspath( __file__ ).split( os.path.sep )[0:-5]) - print("##Check point") - print(ws_local) #expected to have 'librealsense' repo in parallel to 'realsense-ros' assert os.path.exists( os.path.join(ws_local, 'librealsense')), f" 'librealsense' doesn't exist at {ws_local} " sys.path.append( os.path.join( ws_local, 'librealsense/unit-tests/py' ))