Skip to content

Commit

Permalink
Update test-timestamp-domain.py
Browse files Browse the repository at this point in the history
Not keep the frame in queue testing.
  • Loading branch information
Tamir91 committed Dec 21, 2022
1 parent bab0cec commit cc09237
Showing 1 changed file with 107 additions and 43 deletions.
150 changes: 107 additions & 43 deletions unit-tests/live/options/test-timestamp-domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def close_resources(sensor):
sensor.close()


def set_and_verify_timestamp_domain(sensor, frame_queue, global_time_enabled: bool):
def set_and_verify_timestamp_domain(sensor, frame_queue, global_time_enabled: bool, sleep_time: float = 0.1):
"""
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
"""
sensor.set_option(rs.option.global_time_enabled, global_time_enabled)
time.sleep(0.5) # Waiting for new frame from device. Need in case low FPS.
time.sleep(sleep_time) # Waiting for new frame from device. Need in case low FPS.
frame = frame_queue.wait_for_frame()

if not frame:
Expand All @@ -41,46 +41,110 @@ def set_and_verify_timestamp_domain(sensor, frame_queue, global_time_enabled: bo
test.check_equal(frame.get_frame_timestamp_domain(), expected_ts_domain)


device = test.find_first_device_or_exit()

# Depth sensor test
depth_frame_queue = rs.frame_queue(capacity=1, keep_frames=False)

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)
depth_sensor.start(depth_frame_queue)

# Test #1
test.start('Check setting global time domain: depth sensor - timestamp domain is OFF')
set_and_verify_timestamp_domain(depth_sensor, depth_frame_queue, False)
test.finish()

# Test #2
test.start('Check setting global time domain: depth sensor - timestamp domain is ON')
set_and_verify_timestamp_domain(depth_sensor, depth_frame_queue, True)
test.finish()

close_resources(depth_sensor)

# Color sensor test
color_frame_queue = rs.frame_queue(capacity=1, keep_frames=False)

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(color_frame_queue)

# Test #3
test.start('Check setting global time domain: color sensor - timestamp domain is OFF')
set_and_verify_timestamp_domain(color_sensor, color_frame_queue, False)
test.finish()

# Test #4
test.start('Check setting global time domain: color sensor - timestamp domain is ON')
set_and_verify_timestamp_domain(color_sensor, color_frame_queue, True)
test.finish()

close_resources(color_sensor)
def start_test(iteration: int = 1, queue_capacity: int = 1, sleep_time: float = 0.1):
"""
Body of test
"""
while iteration:
iteration -= 1
print("Iteration number: ", iteration)

device = test.find_first_device_or_exit()

# Depth sensor test
depth_frame_queue = rs.frame_queue(queue_capacity, keep_frames=False)

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)
depth_sensor.start(depth_frame_queue)

# Test #1
test.start('Check setting global time domain: depth sensor - timestamp domain is OFF')
set_and_verify_timestamp_domain(depth_sensor, depth_frame_queue, False, sleep_time)
test.finish()

# Test #2
test.start('Check setting global time domain: depth sensor - timestamp domain is ON')
set_and_verify_timestamp_domain(depth_sensor, depth_frame_queue, True, sleep_time)
test.finish()

close_resources(depth_sensor)

# Color sensor test
color_frame_queue = rs.frame_queue(queue_capacity, keep_frames=False)

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(color_frame_queue)

# Test #3
test.start('Check setting global time domain: color sensor - timestamp domain is OFF')
set_and_verify_timestamp_domain(color_sensor, color_frame_queue, False, sleep_time)
test.finish()

# Test #4
test.start('Check setting global time domain: color sensor - timestamp domain is ON')
set_and_verify_timestamp_domain(color_sensor, color_frame_queue, True, sleep_time)
test.finish()

close_resources(color_sensor)


print('queue=5, sleep=0.5:')
start_test(2, 5, 0.5)
print('queue=5, sleep=0.4:')
start_test(2, 5, 0.4)
print('queue=5, sleep=0.3:')
start_test(2, 5, 0.3)
print('queue=5, sleep=0.2:')
start_test(2, 5, 0.2)
print('queue=5, sleep=0.1:')
start_test(2, 5)

print('queue=4, sleep=0.5:')
start_test(2, 4, 0.5)
print('queue=4, sleep=0.4:')
start_test(2, 4, 0.4)
print('queue=4, sleep=0.3:')
start_test(2, 4, 0.3)
print('queue=4, sleep=0.2:')
start_test(2, 4, 0.2)
print('queue=4, sleep=0.1:')
start_test(2, 4)

print('queue=3, sleep=0.5:')
start_test(2, 3, 0.5)
print('queue=3, sleep=0.4:')
start_test(2, 3, 0.4)
print('queue=3, sleep=0.3:')
start_test(2, 3, 0.3)
print('queue=3, sleep=0.2:')
start_test(2, 3, 0.2)
print('queue=3, sleep=0.1:')
start_test(2, 3)

print('queue=2, sleep=0.5:')
start_test(2, 2, 0.5)
print('queue=2, sleep=0.4:')
start_test(2, 2, 0.4)
print('queue=2, sleep=0.3:')
start_test(2, 2, 0.3)
print('queue=2, sleep=0.2:')
start_test(2, 2, 0.2)
print('queue=2, sleep=0.1:')
start_test(2, 2)

print('queue=1, sleep=0.5:')
start_test(2, 1, 0.5)
print('queue=1, sleep=0.4:')
start_test(2, 1, 0.4)
print('queue=1, sleep=0.3:')
start_test(2, 1, 0.3)
print('queue=1, sleep=0.2:')
start_test(2, 1, 0.2)
print('queue=1, sleep=0.1:')
start_test(2, 1)

test.print_results_and_exit()

0 comments on commit cc09237

Please sign in to comment.