From d9a8fab3e63ad92de1fffc960b314d4bd86d78fc Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 20 Feb 2025 15:46:19 -0800 Subject: [PATCH] test_onroad: run same checks on both EncodeIdx and CameraState (#34638) * try this * cleanup * lil more --------- Co-authored-by: Comma Device --- selfdrive/test/test_onroad.py | 52 ++++++++++++++++------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index 8caa618e51..0bc13a9351 100644 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -337,34 +337,30 @@ class TestOnroad: cam_states = ['roadCameraState', 'wideRoadCameraState', 'driverCameraState'] encode_cams = ['roadEncodeIdx', 'wideRoadEncodeIdx', 'driverEncodeIdx'] for cams in (cam_states, encode_cams): - # TODO: driverEncodeIdx has an issue that needs to be fixed - if 'driverEncodeIdx' in cams: - continue - - # sanity checks within a single cam - for cam in cams: - with subtests.test(test="frame_skips", camera=cam): - print(self.ts[cam]['frameId']) - assert set(np.diff(self.ts[cam]['frameId'])) == {1, }, "Frame ID skips" - - # EOF > SOF - eof_sof_diff = self.ts[cam]['timestampEof'] - self.ts[cam]['timestampSof'] - assert np.all(eof_sof_diff > 0) - assert np.all(eof_sof_diff < 50*1e6) - - # camerad guarantees that all cams start on the same frame ID - first_fid = {c: min(self.ts[c]['frameId']) for c in cams} - assert len(set(first_fid.values())) == 1, "Cameras don't start on same frame ID" - - # we don't do a full segment rotation, so these might not match exactly - last_fid = {c: max(self.ts[c]['frameId']) for c in cams} - assert max(last_fid.values()) - min(last_fid.values()) < 10 - - start, end = min(first_fid.values()), min(last_fid.values()) - 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=}" + with subtests.test(cams=cams): + # sanity checks within a single cam + for cam in cams: + with subtests.test(test="frame_skips", camera=cam): + assert set(np.diff(self.ts[cam]['frameId'])) == {1, }, "Frame ID skips" + + # EOF > SOF + eof_sof_diff = self.ts[cam]['timestampEof'] - self.ts[cam]['timestampSof'] + assert np.all(eof_sof_diff > 0) + assert np.all(eof_sof_diff < 50*1e6) + + # camerad guarantees that all cams start on the same frame ID + first_fid = {c: min(self.ts[c]['frameId']) for c in cams} + assert len(set(first_fid.values())) == 1, "Cameras don't start on same frame ID" + + # we don't do a full segment rotation, so these might not match exactly + last_fid = {c: max(self.ts[c]['frameId']) for c in cams} + assert max(last_fid.values()) - min(last_fid.values()) < 10 + + start, end = min(first_fid.values()), min(last_fid.values()) + 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): result = "\n"