Skip to content

Commit d9e3acd

Browse files
committed
fps evaluation
1 parent b8a7a7d commit d9e3acd

1 file changed

Lines changed: 69 additions & 17 deletions

File tree

test/test_fps.py

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,85 @@
33
import re
44

55
@pytest.mark.d457
6+
@pytest.mark.parametrize("frames", {20})
67
@pytest.mark.parametrize("device", {'0', '2'})
7-
@pytest.mark.parametrize("frames", {'100'})
8-
@pytest.mark.parametrize("timeout", {10})
9-
def test_fps(device, frames, timeout):
8+
def test_fps(device, frames):
9+
try:
10+
print(f"Device: {device}")
11+
formats = get_formats(device)
12+
for w, h in formats:
13+
print(f"format: {w}x{h}")
14+
for FPS in formats[(w, h)]:
15+
cmd = [ "v4l2-ctl",
16+
f"-d{device}",
17+
f"--set-fmt-video=width={w},height={h}",
18+
]
19+
subprocess.check_call(cmd)
20+
cmd = [ "v4l2-ctl",
21+
f"-d{device}",
22+
"-p",
23+
f"{FPS}",
24+
]
25+
subprocess.check_call(cmd)
26+
cmd = [ "v4l2-ctl",
27+
f"-d{device}",
28+
"--stream-mmap",
29+
"--stream-count",
30+
f"{frames}",
31+
"--verbose",
32+
]
33+
timeout = 5.0 * frames / FPS
34+
output = subprocess.run(cmd,
35+
check=True,
36+
text=True,
37+
capture_output=True,
38+
timeout=timeout).stderr.splitlines()
39+
last = None
40+
for line in output:
41+
m = re.search(r"cap dqbuf:.*seq:\s*(\d*)\s*bytesused:.*fps:\s*(\d+\.\d+)\s*.*", line)
42+
if m:
43+
frame = int(m.group(1))
44+
fps = float(m.group(2))
45+
if last:
46+
print(f"\tframe: {frame}/{last}, fps: {fps}")
47+
assert frame != last, f"Repeated frame: {frame}"
48+
assert frame == last+1, f"Frame dropped between: {last} and {frame}"
49+
assert FPS/1.1 < fps and fps < FPS *1.1, f"FPS out of margin: {fps}/{FPS}"
50+
last = frame
51+
assert last, "No frames received"
52+
53+
except Exception as e:
54+
assert False, "Exception caught during test: {}".format(e)
55+
56+
def get_formats(device):
1057
try:
1158
cmd = [ "v4l2-ctl",
1259
"-d" + device,
13-
"--stream-mmap",
14-
"--stream-count",
15-
frames,
16-
"--verbose"]
60+
"--list-formats-ext",
61+
]
1762
output = subprocess.run(cmd,
1863
check=True,
1964
text=True,
20-
capture_output=True,
21-
timeout=timeout).stderr.splitlines()
65+
capture_output=True
66+
).stdout.splitlines()
67+
formats = {}
2268
last = None
2369
for line in output:
24-
m = re.search(r"cap dqbuf:.*seq:\s*(\d*)\s*bytesused:.*fps:\s*(\d+\.\d+)\s*.*", line)
70+
m = re.search(r"\s*Size: Discrete\s*(\d+)x(\d+)", line)
71+
if m:
72+
w = int(m.group(1))
73+
h = int(m.group(2))
74+
last = (w ,h)
75+
if not last in formats:
76+
formats[last] = set()
77+
continue
78+
m = re.search(r"\s*Interval: Discrete.*\((\d+\.\d+)\s+fps\)", line)
2579
if m:
26-
frame = int(m.group(1))
27-
fps = float(m.group(2))
80+
fps = float(m.group(1))
2881
if last:
29-
print(f"frame: {frame}/{last}, fps: {fps}")
30-
assert frame != last, f"Repeated frame: {frame}"
31-
assert frame == last+1, f"Frame droped between: {last} and {frame}"
32-
last = frame
82+
formats[last].add(fps)
83+
return formats
3384

3485
except Exception as e:
35-
assert False, "Exception caught during test: {}".format(e)
86+
assert False, "Exception caught @get_formats: {}".format(e)
87+

0 commit comments

Comments
 (0)