Skip to content

Commit

Permalink
PR #3200 from kadiredd: retry thrice finding devices with Ykush reset
Browse files Browse the repository at this point in the history
  • Loading branch information
SamerKhshiboun authored Sep 9, 2024
2 parents 2855e41 + 667b23c commit d11c181
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions realsense2_camera/test/live_camera/rosci.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,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 +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:
Expand All @@ -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):
Expand All @@ -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 = []
Expand Down Expand Up @@ -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 )

0 comments on commit d11c181

Please sign in to comment.