camerad frame lag/drop jenkins tests (#19945)

* clean up test

* not needed for now

* this be enough

* comment this out

* clean up

* adjust tolerance

* use sof on tici

Co-authored-by: Comma Device <device@comma.ai>
pull/2614/head^2
ZwX1616 2021-01-28 14:21:59 -08:00 committed by GitHub
parent 8605ba8ab9
commit 1a95127b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 17 deletions

3
Jenkinsfile vendored
View File

@ -150,7 +150,7 @@ pipeline {
["test boardd loopback", "nosetests -s selfdrive/boardd/tests/test_boardd_loopback.py"],
["test loggerd", "python selfdrive/loggerd/tests/test_loggerd.py"],
["test encoder", "python selfdrive/loggerd/tests/test_encoder.py"],
//["test camerad", "SEND_REAR=1 SEND_FRONT=1 python selfdrive/camerad/test/test_camerad.py"], // wait for shelf refactor
["test camerad", "python selfdrive/camerad/test/test_camerad.py"],
//["test updater", "python installer/updater/test_updater.py"],
])
}
@ -162,6 +162,7 @@ pipeline {
["build", "SCONS_CACHE=1 scons -j16"],
["test loggerd", "python selfdrive/loggerd/tests/test_loggerd.py"],
["test encoder", "python selfdrive/loggerd/tests/test_encoder.py"],
["test camerad", "python selfdrive/camerad/test/test_camerad.py"],
])
}
}

View File

@ -1,7 +1,5 @@
#!/usr/bin/env python3
import os
import random
import time
import unittest
import numpy as np
@ -13,9 +11,9 @@ from selfdrive.camerad.snapshot.snapshot import get_snapshots
# only tests for EON and TICI
from selfdrive.hardware import EON, TICI
TEST_TIMESPAN = random.randint(60, 180) # seconds
TEST_TIMESPAN = 30 # random.randint(60, 180) # seconds
SKIP_FRAME_TOLERANCE = 0
FRAME_COUNT_TOLERANCE = 1 # over the whole test time
LAG_FRAME_TOLERANCE = 2 # ms
FPS_BASELINE = 20
CAMERAS = {
@ -33,8 +31,8 @@ class TestCamerad(unittest.TestCase):
if not (EON or TICI):
raise unittest.SkipTest
assert "SEND_REAR" in os.environ
assert "SEND_FRONT" in os.environ
# assert "SEND_REAR" in os.environ
# assert "SEND_FRONT" in os.environ
def _numpy_bgr2gray(self, im):
ret = np.clip(im[:,:,0] * 0.114 + im[:,:,1] * 0.587 + im[:,:,2] * 0.299, 0, 255).astype(np.uint8)
@ -74,6 +72,7 @@ class TestCamerad(unittest.TestCase):
print([i_median, i_mean])
return med_ex[0] < i_median < med_ex[1] and mean_ex[0] < i_mean < mean_ex[1]
@unittest.skip # skip for now
@with_processes(['camerad'])
def test_camera_operation(self):
print("checking image outputs")
@ -104,25 +103,29 @@ class TestCamerad(unittest.TestCase):
sm = messaging.SubMaster([socket_name for socket_name in CAMERAS])
last_frame_id = dict.fromkeys(CAMERAS, None)
start_frame_id = dict.fromkeys(CAMERAS, None)
start_time_milli = int(round(time.time() * 1000))
while int(round(time.time() * 1000)) - start_time_milli < (TEST_TIMESPAN+1) * 1000:
last_ts = dict.fromkeys(CAMERAS, None)
start_time_sec = time.time()
while time.time()- start_time_sec < TEST_TIMESPAN:
sm.update()
for camera in CAMERAS:
if sm.updated[camera]:
if start_frame_id[camera] is None:
start_frame_id[camera] = last_frame_id[camera] = sm[camera].frameId
ct = (sm[camera].timestampEof if not TICI else sm[camera].timestampSof) / 1e6
if last_frame_id[camera] is None:
last_frame_id[camera] = sm[camera].frameId
last_ts[camera] = ct
continue
dfid = sm[camera].frameId - last_frame_id[camera]
self.assertTrue(abs(dfid - 1) <= SKIP_FRAME_TOLERANCE)
self.assertTrue(abs(dfid - 1) <= SKIP_FRAME_TOLERANCE, "%s frame id diff is %d" % (camera, dfid))
dts = ct - last_ts[camera]
self.assertTrue(abs(dts - (1000/CAMERAS[camera])) < LAG_FRAME_TOLERANCE, "%s frame t(ms) diff is %f" % (camera, dts))
last_frame_id[camera] = sm[camera].frameId
last_ts[camera] = ct
time.sleep(0.01)
for camera in CAMERAS:
print(camera, (last_frame_id[camera] - start_frame_id[camera]))
self.assertTrue(abs((last_frame_id[camera] - start_frame_id[camera]) - TEST_TIMESPAN*CAMERAS[camera]) <= FRAME_COUNT_TOLERANCE)
if __name__ == "__main__":
unittest.main()