test_onroad: run same checks on both EncodeIdx and CameraState (#34638)

* try this

* cleanup

* lil more

---------

Co-authored-by: Comma Device <device@comma.ai>
pull/34643/head^2
Adeeb Shihadeh 2 months ago committed by GitHub
parent bdf0b7b42e
commit d9a8fab3e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 52
      selfdrive/test/test_onroad.py

@ -337,34 +337,30 @@ class TestOnroad:
cam_states = ['roadCameraState', 'wideRoadCameraState', 'driverCameraState'] cam_states = ['roadCameraState', 'wideRoadCameraState', 'driverCameraState']
encode_cams = ['roadEncodeIdx', 'wideRoadEncodeIdx', 'driverEncodeIdx'] encode_cams = ['roadEncodeIdx', 'wideRoadEncodeIdx', 'driverEncodeIdx']
for cams in (cam_states, encode_cams): for cams in (cam_states, encode_cams):
# TODO: driverEncodeIdx has an issue that needs to be fixed with subtests.test(cams=cams):
if 'driverEncodeIdx' in cams: # sanity checks within a single cam
continue for cam in cams:
with subtests.test(test="frame_skips", camera=cam):
# sanity checks within a single cam assert set(np.diff(self.ts[cam]['frameId'])) == {1, }, "Frame ID skips"
for cam in cams:
with subtests.test(test="frame_skips", camera=cam): # EOF > SOF
print(self.ts[cam]['frameId']) eof_sof_diff = self.ts[cam]['timestampEof'] - self.ts[cam]['timestampSof']
assert set(np.diff(self.ts[cam]['frameId'])) == {1, }, "Frame ID skips" assert np.all(eof_sof_diff > 0)
assert np.all(eof_sof_diff < 50*1e6)
# EOF > SOF
eof_sof_diff = self.ts[cam]['timestampEof'] - self.ts[cam]['timestampSof'] # camerad guarantees that all cams start on the same frame ID
assert np.all(eof_sof_diff > 0) first_fid = {c: min(self.ts[c]['frameId']) for c in cams}
assert np.all(eof_sof_diff < 50*1e6) assert len(set(first_fid.values())) == 1, "Cameras don't start on same frame ID"
# camerad guarantees that all cams start on the same frame ID # we don't do a full segment rotation, so these might not match exactly
first_fid = {c: min(self.ts[c]['frameId']) for c in cams} last_fid = {c: max(self.ts[c]['frameId']) for c in cams}
assert len(set(first_fid.values())) == 1, "Cameras don't start on same frame ID" assert max(last_fid.values()) - min(last_fid.values()) < 10
# we don't do a full segment rotation, so these might not match exactly start, end = min(first_fid.values()), min(last_fid.values())
last_fid = {c: max(self.ts[c]['frameId']) for c in cams} for i in range(end-start):
assert max(last_fid.values()) - min(last_fid.values()) < 10 ts = {c: round(self.ts[c]['timestampSof'][i]/1e6, 1) for c in cams}
diff = (max(ts.values()) - min(ts.values()))
start, end = min(first_fid.values()), min(last_fid.values()) assert diff < 2, f"Cameras not synced properly: frame_id={start+i}, {diff=:.1f}ms, {ts=}"
for i in range(end-start):
ts = {c: round(self.ts[c]['timestampSof'][i]/1e6, 1) for c in cams}
diff = (max(ts.values()) - min(ts.values()))
assert diff < 2, f"Cameras not synced properly: frame_id={start+i}, {diff=:.1f}ms, {ts=}"
def test_mpc_execution_timings(self): def test_mpc_execution_timings(self):
result = "\n" result = "\n"

Loading…
Cancel
Save