Skip to content

Commit ce615f7

Browse files
committed
Update test-fps.py to use fps_helper.measure_fps()
1 parent affee70 commit ce615f7

File tree

1 file changed

+9
-52
lines changed

1 file changed

+9
-52
lines changed

unit-tests/live/frames/test-fps.py

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,11 @@
1111
from rspy import test, log
1212
import time
1313
import platform
14+
import fps_helper
1415

1516
# Start depth + color streams and measure frame frequency using sensor API.
1617
# Verify that actual fps is as requested
1718

18-
global first_frame_seconds
19-
20-
def measure_fps(sensor, profile, seconds_to_count_frames = 10):
21-
"""
22-
Wait a few seconds to be sure that frames are at steady state after start
23-
Count number of received frames for seconds_to_count_frames seconds and compare actual fps to requested fps
24-
"""
25-
seconds_till_steady_state = 4
26-
27-
steady_state = False
28-
first_frame_received = False
29-
frames_received = 0
30-
first_frame_stopwatch = Stopwatch()
31-
prev_frame_number = 0
32-
33-
def frame_cb(frame):
34-
global first_frame_seconds
35-
nonlocal steady_state, frames_received, first_frame_received, prev_frame_number
36-
current_frame_number = frame.get_frame_number()
37-
if not first_frame_received:
38-
first_frame_seconds = first_frame_stopwatch.get_elapsed()
39-
first_frame_received = True
40-
else:
41-
if current_frame_number > prev_frame_number + 1:
42-
log.w( f'Frame drop detected. Current frame number {current_frame_number} previous was {prev_frame_number}' )
43-
if steady_state:
44-
frames_received += 1
45-
prev_frame_number = current_frame_number
46-
47-
sensor.open(profile)
48-
sensor.start(frame_cb)
49-
first_frame_stopwatch.reset()
50-
51-
time.sleep(seconds_till_steady_state)
52-
53-
steady_state = True
54-
55-
time.sleep(seconds_to_count_frames) # Time to count frames
56-
57-
steady_state = False # Stop counting
58-
59-
sensor.stop()
60-
sensor.close()
61-
62-
fps = frames_received / seconds_to_count_frames
63-
return fps
64-
65-
6619
delta_Hz = 1
6720
tested_fps = [5, 6, 15, 30, 60, 90]
6821
time_to_test_fps = [25, 20, 13, 10, 5, 4]
@@ -96,8 +49,10 @@ def frame_cb(frame):
9649
except StopIteration:
9750
log.i("Requested fps: {:.1f} [Hz], not supported".format(requested_fps))
9851
else:
99-
fps = measure_fps(ds, dp, time_to_test_fps[i])
100-
log.i("Requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]. Time to first frame {:.6f}".format(requested_fps, fps, first_frame_seconds))
52+
fps_helper.TIME_TO_COUNT_FRAMES = time_to_test_fps[i]
53+
fps_dict = fps_helper.measure_fps({ds: [dp]})
54+
fps = fps_dict.get(dp.stream_name(), 0)
55+
log.i("Requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]".format(requested_fps, fps))
10156
delta_Hz = requested_fps * 0.05 # Validation KPI is 5%
10257
test.check(fps <= (requested_fps + delta_Hz) and fps >= (requested_fps - delta_Hz))
10358
test.finish()
@@ -133,8 +88,10 @@ def frame_cb(frame):
13388
except StopIteration:
13489
log.i("Requested fps: {:.1f} [Hz], not supported".format(requested_fps))
13590
else:
136-
fps = measure_fps(cs, cp, time_to_test_fps[i])
137-
log.i("Requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]. Time to first frame {:.6f}".format(requested_fps, fps, first_frame_seconds))
91+
fps_helper.TIME_TO_COUNT_FRAMES = time_to_test_fps[i]
92+
fps_dict = fps_helper.measure_fps({cs: [cp]})
93+
fps = fps_dict.get(cp.stream_name(), 0)
94+
log.i("Requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]".format(requested_fps, fps))
13895
delta_Hz = requested_fps * (0.10 if requested_fps == 5 else 0.05) # Validation KPI is 5% for all non 5 FPS rate
13996
test.check(fps <= (requested_fps + delta_Hz) and fps >= (requested_fps - delta_Hz))
14097

0 commit comments

Comments
 (0)