forked from realsenseai/realsense_mipi_platform_driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fps.py
More file actions
executable file
·94 lines (89 loc) · 2.41 KB
/
Copy pathtest_fps.py
File metadata and controls
executable file
·94 lines (89 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import subprocess
import pytest
import re
@pytest.mark.d457
@pytest.mark.parametrize("frames", {20})
@pytest.mark.parametrize("device", {'0', '2'})
def test_fps(device, frames):
try:
print(f"\nDevice: {device}")
formats = get_formats(device)
for w, h in formats:
print(f"format: {w}x{h}")
for FPS in formats[(w, h)]:
cmd = [ "v4l2-ctl",
f"-d{device}",
f"--set-fmt-video=width={w},height={h}",
]
subprocess.check_call(cmd)
cmd = [ "v4l2-ctl",
f"-d{device}",
"-p",
f"{FPS}",
]
subprocess.check_call(cmd)
cmd = [ "v4l2-ctl",
f"-d{device}",
"--stream-mmap",
"--stream-count",
f"{frames}",
"--verbose",
]
timeout = 5.0 * frames / FPS
output = subprocess.run(cmd,
check=True,
text=True,
capture_output=True,
timeout=timeout).stderr.splitlines()
last = None
kpi = 5 # [%]
for line in output:
m = re.search(r"cap dqbuf:.*seq:\s*(\d*)\s*bytesused:.*", line)
if m:
frame = int(m.group(1))
print(f"\t{frame}", end="")
if last:
assert frame > last, f"Repeated frame: {frame}"
assert (frame - last) < 3 , f"Frames dropped between: {last} and {frame}"
m = re.search(r"cap dqbuf:.*bytesused:.*fps:\s*(\d+\.\d+)\s*.*", line)
if m:
fps = float(m.group(1))
if last:
print(f"/{fps}", end="")
assert fps > FPS * (1 - kpi/100), f"FPS too low: {fps}/{FPS}"
assert fps < FPS * (1 + kpi/100), f"FPS too high: {fps}/{FPS}"
last = frame
print()
assert last, "No frames received"
except Exception as e:
assert False, "Exception caught during test: {}".format(e)
def get_formats(device):
try:
cmd = [ "v4l2-ctl",
"-d" + device,
"--list-formats-ext",
]
output = subprocess.run(cmd,
check=True,
text=True,
capture_output=True
).stdout.splitlines()
formats = {}
last = None
for line in output:
m = re.search(r"\s*Size: Discrete\s*(\d+)x(\d+)", line)
if m:
w = int(m.group(1))
h = int(m.group(2))
last = (w ,h)
if not last in formats:
formats[last] = set()
continue
m = re.search(r"\s*Interval: Discrete.*\((\d+\.\d+)\s+fps\)", line)
if m:
fps = float(m.group(1))
if last:
formats[last].add(fps)
return formats
except Exception as e:
assert False, "Exception caught @get_formats: {}".format(e)