Skip to content

Commit

Permalink
enable dds devices on run-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AviaAv committed Jan 15, 2025
1 parent f36d92a commit b7b0870
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 3 additions & 1 deletion unit-tests/live/tools/test-enumerate-devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
rs_enumerate_devices = repo.find_built_exe( 'tools/enumerate-devices', 'rs-enumerate-devices' )
test.check(rs_enumerate_devices)
if rs_enumerate_devices:
dev, ctx = test.find_first_device_or_exit()
camera_name = dev.get_info(rs.camera_info.name)
import subprocess
run_time_stopwatch = Stopwatch()
run_time_threshold = 2
run_time_threshold = 2 if 'D555' not in camera_name else 5
p = subprocess.run( [rs_enumerate_devices],
stdout=None,
stderr=subprocess.STDOUT,
Expand Down
38 changes: 27 additions & 11 deletions unit-tests/py/rspy/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def usage():
pyrs_dir = repo.find_pyrs_dir()
sys.path.insert( 1, pyrs_dir )

MAX_ENUMERATION_TIME = 10 # [sec]
MAX_ENUMERATION_TIME = 15 # [sec]

# We need both pyrealsense2 and hub. We can work without hub, but
# without pyrealsense2 no devices at all will be returned.
from rspy import device_hub
try:
import pyrealsense2 as rs
log.d( rs )
hub = device_hub.create()
hub = device_hub.create() # if there's no hub, this will hold None
sys.path = sys.path[:-1] # remove what we added
except ModuleNotFoundError:
log.w( 'No pyrealsense2 library is available! Running as if no cameras available...' )
Expand Down Expand Up @@ -73,8 +73,13 @@ def __init__( self, sn, dev ):
self._physical_port = dev.supports( rs.camera_info.physical_port ) and dev.get_info( rs.camera_info.physical_port ) or None

self._usb_location = None
self._is_dds = False
try:
self._usb_location = _get_usb_location(self._physical_port)
if self._physical_port.startswith('realsense/'):
self._is_dds = True
# not trying to _get_usb_location as dds devices don't have it
else:
self._usb_location = _get_usb_location(self._physical_port)
except Exception as e:
log.e('Failed to get usb location:', e)
self._port = None
Expand Down Expand Up @@ -118,7 +123,11 @@ def handle( self ):

@property
def enabled( self ):
return self._removed is False
return self._removed is False and self._dev is not None

@property
def is_dds(self):
return self._is_dds


def wait_until_all_ports_disabled( timeout = 5 ):
Expand Down Expand Up @@ -223,7 +232,7 @@ def query( monitor_changes=True, hub_reset=False, recycle_ports=True ):
#
# Get all devices, and store by serial-number
global _device_by_sn, _context, _port_to_sn
_context = rs.context( { 'dds': False } )
_context = rs.context( { 'dds': { "enabled" : True } } )
_device_by_sn = dict()
try:
log.debug_indent()
Expand Down Expand Up @@ -264,13 +273,15 @@ def _device_change_callback( info ):
global _device_by_sn
for device in _device_by_sn.values():
if device.enabled and info.was_removed( device.handle ):
device._dev = None
log.d( 'device removed:', device.serial_number )
device._removed = True
for handle in info.get_new_devices():
sn = handle.get_info( rs.camera_info.firmware_update_id )
log.d( 'device added:', sn, handle )
if sn in _device_by_sn:
device = _device_by_sn[sn]
device._dev = None # in case we get handle between the next 2 lines, it might still be the old one
device._removed = False
device._dev = handle # Because it has a new handle!
else:
Expand Down Expand Up @@ -526,8 +537,7 @@ def enable_only( serial_numbers, recycle = False, timeout = MAX_ENUMERATION_TIME
else:
#
hub.enable_ports( ports, disable_other_ports = True )
#
_wait_for( serial_numbers, timeout = timeout )
#
#
elif recycle:
#
Expand All @@ -536,6 +546,9 @@ def enable_only( serial_numbers, recycle = False, timeout = MAX_ENUMERATION_TIME
else:
log.d( 'no hub; ports left as-is' )

# doesn't matter what it did, enable_only should wait for the devices to be available again
_wait_for(serial_numbers, timeout=timeout)


def enable_all():
"""
Expand Down Expand Up @@ -615,16 +628,19 @@ def hw_reset( serial_numbers, timeout = MAX_ENUMERATION_TIME ):
:param timeout: Maximum # of seconds to wait for the devices to come back online
:return: True if all devices have come back online before timeout
"""
# for usb and dds devices, we can wait until they're removed
removable_devs_sns = {sn for sn in serial_numbers if
_device_by_sn[sn].port is not None or _device_by_sn[sn].is_dds}

usb_serial_numbers = { sn for sn in serial_numbers if _device_by_sn[sn].port is not None }

_wait_for(serial_numbers, timeout=timeout) # make sure devices are added before doing hw reset
for sn in serial_numbers:
dev = get( sn ).handle
dev.hardware_reset()
#

if usb_serial_numbers:
_wait_until_removed( usb_serial_numbers )
if removable_devs_sns:
_wait_until_removed( removable_devs_sns )
# if relevant, we need to handle case where we have both removable and non-removable devices
else:
# normally we will get here with a mipi device,
# we want to allow some time for the device to reinitialize as it was not disconnected
Expand Down
4 changes: 2 additions & 2 deletions unit-tests/run-unit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ def test_wrapper( test, configuration=None, repetition=1, serial_numbers=None ):
try:
log.d( 'configuration:', configuration_str( configuration, repetition, sns=serial_numbers ) )
log.debug_indent()
if not no_reset:
devices.enable_only( serial_numbers, recycle=True )
should_reset = not no_reset
devices.enable_only( serial_numbers, recycle=should_reset )
except RuntimeError as e:
log.w( log.red + test.name + log.reset + ': ' + str( e ) )
else:
Expand Down

0 comments on commit b7b0870

Please sign in to comment.