From 796ec03c08863165d25a7392c75da1d2fe0e13c5 Mon Sep 17 00:00:00 2001 From: Tamir <1hotlev@gmail.com> Date: Thu, 29 Sep 2022 11:23:24 +0300 Subject: [PATCH] test changed second time according instructions #10925 --- .../live/options/test-timestamp-domain.py | 97 ++++++++----------- 1 file changed, 38 insertions(+), 59 deletions(-) diff --git a/unit-tests/live/options/test-timestamp-domain.py b/unit-tests/live/options/test-timestamp-domain.py index 56421584fe..d26453bbed 100644 --- a/unit-tests/live/options/test-timestamp-domain.py +++ b/unit-tests/live/options/test-timestamp-domain.py @@ -9,109 +9,88 @@ from rspy import test -def get_connected_device(): - """ - Get first connected device - :return: connected device - """ - dev = None - try: - context = rs.context() - dev = context.devices[0] - except Exception as ex: - print('Exception: Failed to find connected device. ', str(ex)) - return dev - - def close_resources(sensor): """ Stop and Close sensor. - :param: sensor of device + :sensor: sensor of device """ if len(sensor.get_active_streams()) > 0: sensor.stop() sensor.close() -def start_sensor_test(sensor, global_time_enabled: int): +def set_and_verify_timestamp_domain(sensor, global_time_enabled: bool): """ - Perform depth sensor test according given global time - :global_time_enabled int: 1 - time is enabled, 0 - time disabled + Perform sensor (depth or color) test according given global time + :sensor: depth or color sensor in device + :global_time_enabled bool: True - timestamp is enabled otherwise false """ - - if global_time_enabled not in [0, 1]: - raise ValueError(f'Invalid parameter in start depth test: {global_time_enabled}. Only 1 or 0 are valid.') + global frame_queue try: - sensor.set_option(rs.option.global_time_enabled, global_time_enabled) - time.sleep(2) - + sensor.set_option(rs.option.global_time_enabled, 1 if global_time_enabled else 0) + time.sleep(0.7) frame = frame_queue.wait_for_frame() - if global_time_enabled == 0 and sensor.get_option(rs.option.global_time_enabled) == 0: - test.check_equal(frame.get_frame_timestamp_domain(), rs.timestamp_domain.hardware_clock) + if frame_queue is None or frame_queue.size() == 0: + test.fail() + + expected_ts_domain = rs.timestamp_domain.global_time if global_time_enabled else \ + rs.timestamp_domain.hardware_clock - elif global_time_enabled == 1 and sensor.get_option(rs.option.global_time_enabled) == 1: - test.check_equal(frame.get_frame_timestamp_domain(), - rs.timestamp_domain.global_time) + test.check_equal(sensor.get_option(rs.option.global_time_enabled), 1 if global_time_enabled else 0) + test.check_equal(frame.get_frame_timestamp_domain(), expected_ts_domain) except Exception as exc: print(str(exc)) + test.fail() depth_sensor = None color_sensor = None try: - device = get_connected_device() - depth_sensor = device.first_depth_sensor() - color_sensor = device.first_color_sensor() - - depth_profile = next(p for p in depth_sensor.profiles if p.fps() == 30 - and p.stream_type() == rs.stream.depth - and p.format() == rs.format.z16 - and p.as_video_stream_profile().width() == 640 - and p.as_video_stream_profile().height() == 480) - - color_profile = next(p for p in color_sensor.profiles if p.fps() == 30 - and p.stream_type() == rs.stream.color - and p.format() == rs.format.yuyv - and p.as_video_stream_profile().width() == 640 - and p.as_video_stream_profile().height() == 480) + frame_queue = rs.frame_queue(capacity=5, keep_frames=False) + device = test.find_first_device_or_exit() + # Depth sensor test + depth_sensor = device.first_depth_sensor() + depth_profile = next(p for p in depth_sensor.profiles if p.stream_type() == rs.stream.depth) depth_sensor.open(depth_profile) - color_sensor.open(color_profile) - frame_queue = rs.frame_queue(capacity=10, keep_frames=False) - depth_sensor.start(frame_queue) # Test #1 - test.start('Start depth sensor test: global time disabled') - start_sensor_test(depth_sensor, 0) + test.start('Check setting global time domain: depth sensor - timestamp domain is OFF') + set_and_verify_timestamp_domain(depth_sensor, False) test.finish() # Test #2 - test.start('Start depth sensor test: global time enabled') - start_sensor_test(depth_sensor, 1) + test.start('Check setting global time domain: depth sensor - timestamp domain is ON') + set_and_verify_timestamp_domain(depth_sensor, True) test.finish() close_resources(depth_sensor) + + # Color sensor test + color_sensor = device.first_color_sensor() + color_profile = next(p for p in color_sensor.profiles if p.stream_type() == rs.stream.color) + color_sensor.open(color_profile) color_sensor.start(frame_queue) # Test #3 - test.start('Start color sensor test: global time disabled') - start_sensor_test(color_sensor, 0) + test.start('Check setting global time domain: color sensor - timestamp domain is OFF') + set_and_verify_timestamp_domain(color_sensor, False) test.finish() # Test #4 - test.start('Start color sensor test: global time enabled') - start_sensor_test(color_sensor, 1) + test.start('Check setting global time domain: color sensor - timestamp domain is ON') + set_and_verify_timestamp_domain(color_sensor, True) test.finish() -except ValueError as v: - print(str(v)) + test.print_results_and_exit() + except Exception as e: - print("The device found has no depth sensor or ", str(e)) + print(str(e)) + test.fail() finally: - # close_resources(depth_sensor) close_resources(color_sensor)