Skip to content

Commit

Permalink
PR #13684 from AviaAv: enable dds devices on run-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir-Az authored Feb 2, 2025
2 parents fc3ae5c + 86d2176 commit 172c11e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 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()
is_dds = dev.supports(rs.camera_info.connection_type) and dev.get_info(rs.camera_info.connection_type) == "DDS"
import subprocess
run_time_stopwatch = Stopwatch()
run_time_threshold = 2
run_time_threshold = 5 if is_dds else 2 # currently, DDS devices take longer time to complete rs_enumerate_devices
p = subprocess.run( [rs_enumerate_devices],
stdout=None,
stderr=subprocess.STDOUT,
Expand Down
34 changes: 26 additions & 8 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 @@ -72,6 +72,13 @@ def __init__( self, sn, dev ):
self._product_line = dev.get_info( rs.camera_info.product_line )
self._physical_port = dev.supports( rs.camera_info.physical_port ) and dev.get_info( rs.camera_info.physical_port ) or None

if dev.supports(rs.camera_info.connection_type):
self._connection_type = dev.get_info(rs.camera_info.connection_type)
self._is_dds = self._connection_type == "DDS"
else:
log.w("connection_type is not supported! Assuming not a dds device")
self._is_dds = False

self._usb_location = None
try:
self._usb_location = _get_usb_location(self._physical_port)
Expand Down Expand Up @@ -120,6 +127,10 @@ def handle( self ):
def enabled( self ):
return self._removed is False

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


def wait_until_all_ports_disabled( timeout = 5 ):
"""
Expand Down Expand Up @@ -207,6 +218,7 @@ def query( monitor_changes=True, hub_reset=False, recycle_ports=True, disable_dd
:param recycle_ports: True to recycle all ports before querying devices; False to leave as-is
:param hub_reset: Whether we want to reset the hub - this might be a better way to
recycle the ports in certain cases that leave the ports in a bad state
:param disable_dds: Whether we want to see dds devices or not
"""
global rs
if not rs:
Expand Down Expand Up @@ -267,15 +279,16 @@ 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 ):
log.d( 'device removed:', device.serial_number )
device._removed = True
device._dev = None
log.d( 'device removed:', device.serial_number )
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._removed = False
device._dev = handle # Because it has a new handle!
device._removed = False
else:
# shouldn't see new devices...
log.d( 'new device detected!?' )
Expand Down Expand Up @@ -538,6 +551,8 @@ def enable_only( serial_numbers, recycle = False, timeout = MAX_ENUMERATION_TIME
#
else:
log.d( 'no hub; ports left as-is' )
# even without reset, enable_only should wait for the devices to be available again
_wait_for(serial_numbers, timeout=timeout)


def enable_all():
Expand Down Expand Up @@ -618,16 +633,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
"""
# we can wait for usb and dds devices to be removed, but not for mipi devices
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
8 changes: 4 additions & 4 deletions unit-tests/run-unit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ def test_wrapper( test, configuration=None, repetition=1, serial_numbers=None ):
if pyrs:
sys.path.insert( 1, pyrs_path ) # Make sure we pick up the right pyrealsense2!
from rspy import devices

devices.query( hub_reset = hub_reset ) #resets the device
disable_dds = "dds" not in context
devices.query( hub_reset = hub_reset, disable_dds=disable_dds ) #resets the device
devices.map_unknown_ports()
#
# Under a development environment (i.e., without a hub), we may only have one device connected
Expand Down 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 172c11e

Please sign in to comment.