Skip to content

Commit

Permalink
PR IntelRealSense#12642 from Nir-Az: Enhance metadata test to verify …
Browse files Browse the repository at this point in the history
…sensor timestamp
  • Loading branch information
Nir-Az authored Feb 8, 2024
2 parents 69e1d41 + b80034c commit 5f083eb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions unit-tests/live/metadata/test-alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import time

# test:device each(D400*)
# test:device each(D500*)


import pyrealsense2 as rs
from rspy import test, log
Expand Down Expand Up @@ -57,6 +59,27 @@ def append_testing_profiles(dev) -> None:
testing_profiles[p] = s


def are_metadata_values_different(metadata_type_1, metadata_type_2, number_frames_to_test=50) -> bool:
"""
Check that the given 2 metadata types values are different, it is handy when we expect different timetags / counters and such
:param metadata_type_1: first values that we need to check
:param metadata_type_2: second values that we need to check
:param number_frames_to_test: amount frames that we want to test
:return: true if values are always different
"""
global frame_queue

while number_frames_to_test > 0:
f = frame_queue.wait_for_frame()
current_md_1_value = f.get_frame_metadata(metadata_type_1)
current_md_2_value = f.get_frame_metadata(metadata_type_2)
if current_md_1_value == current_md_2_value:
return False

number_frames_to_test -= 1

return True

def is_value_keep_increasing(metadata_value, number_frames_to_test=50) -> bool:
"""
Check that a given counter in metadata increases
Expand All @@ -74,6 +97,7 @@ def is_value_keep_increasing(metadata_value, number_frames_to_test=50) -> bool:
if prev_metadata_value >= current_value:
return False

prev_metadata_value = current_value
number_frames_to_test -= 1

return True
Expand Down Expand Up @@ -106,6 +130,19 @@ def is_value_keep_increasing(metadata_value, number_frames_to_test=50) -> bool:
test.check(is_value_keep_increasing(rs.frame_metadata_value.frame_timestamp))
test.finish()

# Test #3 Increasing sensor timestamp
if is_frame_support_metadata(frame_queue.wait_for_frame(), rs.frame_metadata_value.sensor_timestamp):
test.start('Verifying increasing sensor timestamp for profile ', profile)
test.check(is_value_keep_increasing(rs.frame_metadata_value.sensor_timestamp))
test.finish()

# On D457, sensor timestamp == frame timestamp, so we ignore it
camera_name = device.get_info(rs.camera_info.name)
if 'D457' not in camera_name:
test.start('Verifying sensor timestamp is different than frame timestamp for profile ', profile)
test.check(are_metadata_values_different(rs.frame_metadata_value.frame_timestamp, rs.frame_metadata_value.sensor_timestamp))
test.finish()

close_resources(sensor)
time.sleep(0.3) # better sleep before stopping/starting streaming, so we can let the device recover properly.

Expand Down

0 comments on commit 5f083eb

Please sign in to comment.