|
| 1 | +# License: Apache 2.0. See LICENSE file in root directory. |
| 2 | +# Copyright(c) 2025 RealSense Inc. All Rights Reserved. |
| 3 | + |
| 4 | +import time |
| 5 | +import pyrealsense2 as rs |
| 6 | +from rspy import log, test |
| 7 | + |
| 8 | +MAX_TRIES = 3 |
| 9 | +DISCONNECT_TIMEOUT_SEC = 2 |
| 10 | + |
| 11 | + |
| 12 | +dev, ctx = test.find_first_device_or_exit() |
| 13 | +hub = rs.device_hub(ctx) |
| 14 | + |
| 15 | +# -------- Basic functionality -------- |
| 16 | +test.start("device_hub: wait_for_device & is_connected") |
| 17 | +try: |
| 18 | + dev_from_hub = hub.wait_for_device() |
| 19 | + test.check(dev_from_hub is not None, "wait_for_device() did not return a device") |
| 20 | + test.check(hub.is_connected(dev_from_hub), "Device should be reported as connected") |
| 21 | +except: |
| 22 | + test.unexpected_exception() |
| 23 | +test.finish() |
| 24 | + |
| 25 | +# -------- Disconnect detection via hardware reset -------- |
| 26 | +test.start("device_hub: detect disconnect after hardware_reset") |
| 27 | +caught_once = False |
| 28 | + |
| 29 | +for attempt in range(1, MAX_TRIES + 1): |
| 30 | + try: |
| 31 | + log.i(f"Attempt {attempt}/{MAX_TRIES}: issuing hardware_reset()") |
| 32 | + dev.hardware_reset() |
| 33 | + |
| 34 | + # Wait until hub reports this handle as disconnected |
| 35 | + t = time.time() |
| 36 | + while time.time() - t < DISCONNECT_TIMEOUT_SEC: |
| 37 | + if not hub.is_connected(dev): |
| 38 | + caught_once = True |
| 39 | + break |
| 40 | + |
| 41 | + if caught_once: |
| 42 | + break |
| 43 | + |
| 44 | + except: |
| 45 | + test.unexpected_exception() |
| 46 | + |
| 47 | +test.check(caught_once, f"Failed to observe a disconnect in {MAX_TRIES} hardware reset attempt(s)") |
| 48 | +test.finish() |
| 49 | + |
| 50 | +test.print_results_and_exit() |
0 commit comments