Skip to content

Commit

Permalink
retry thrice finding devices with Ykush reset
Browse files Browse the repository at this point in the history
  • Loading branch information
administrator committed Sep 8, 2024
1 parent 2855e41 commit f62e29c
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions realsense2_camera/test/live_camera/rosci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' ))
Expand All @@ -50,15 +52,15 @@ 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):
cmd = ['pytest-3']
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']
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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 = []
Expand Down Expand Up @@ -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 )

0 comments on commit f62e29c

Please sign in to comment.