diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index fe7876d1b2..23d1687770 100644 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -23,7 +23,6 @@ from openpilot.selfdrive.test.helpers import set_params_enabled, release_only from openpilot.system.hardware import HARDWARE from openpilot.system.hardware.hw import Paths from openpilot.tools.lib.logreader import LogReader -from openpilot.tools.lib.log_time_series import msgs_to_time_series """ CPU usage budget @@ -120,8 +119,7 @@ class TestOnroad: if "DEBUG" in os.environ: segs = filter(lambda x: os.path.exists(os.path.join(x, "rlog.zst")), Path(Paths.log_root()).iterdir()) segs = sorted(segs, key=lambda x: x.stat().st_mtime) - cls.lr = list(LogReader(os.path.join(segs[-1], "rlog.zst"))) - cls.ts = msgs_to_time_series(cls.lr) + cls.lr = list(LogReader(os.path.join(segs[-3], "rlog.zst"))) return # setup env @@ -175,8 +173,7 @@ class TestOnroad: cls.lrs = [list(LogReader(os.path.join(str(s), "rlog.zst"))) for s in cls.segments] - cls.lr = cls.lrs[0] - cls.ts = msgs_to_time_series(cls.lr) + cls.lr = list(LogReader(os.path.join(str(cls.segments[0]), "rlog.zst"))) cls.log_path = cls.segments[0] cls.log_sizes = {} @@ -201,7 +198,7 @@ class TestOnroad: assert len(msgs) >= math.floor(SERVICE_LIST[s].frequency*int(TEST_DURATION*0.8)) def test_manager_starting_time(self): - st = self.ts['managerState']['t'][0] + st = self.msgs['managerState'][0].logMonoTime / 1e9 assert (st - self.manager_st) < 10, f"manager.py took {st - self.manager_st}s to publish the first 'managerState' msg" def test_cloudlog_size(self): @@ -229,7 +226,7 @@ class TestOnroad: result += "-------------- UI Draw Timing ------------------\n" result += "------------------------------------------------\n" - ts = self.ts['uiDebug']['drawTimeMillis'] + ts = [m.uiDebug.drawTimeMillis for m in self.msgs['uiDebug']] result += f"min {min(ts):.2f}ms\n" result += f"max {max(ts):.2f}ms\n" result += f"std {np.std(ts):.2f}ms\n" @@ -322,7 +319,7 @@ class TestOnroad: result += "----------------- SOF Timing ------------------\n" result += "------------------------------------------------\n" for name in ['roadCameraState', 'wideRoadCameraState', 'driverCameraState']: - ts = self.ts[name]['timestampSof'] + ts = [getattr(m, m.which()).timestampSof for m in self.lr if name in m.which()] d_ms = np.diff(ts) / 1e6 d50 = np.abs(d_ms-50) result += f"{name} sof delta vs 50ms: min {min(d50):.2f}ms\n" @@ -341,30 +338,33 @@ class TestOnroad: # 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" + cam_log = [getattr(x, x.which()) for x in self.msgs[cam]] + assert set(np.diff([x.frameId for x in cam_log])) == {1, }, "Frame ID skips" # EOF > SOF - eof_sof_diff = self.ts[cam]['timestampEof'] - self.ts[cam]['timestampSof'] + eof_sof_diff = np.array([x.timestampEof - x.timestampSof for x in cam_log]) assert np.all(eof_sof_diff > 0) assert np.all(eof_sof_diff < 50*1e6) - first_fid = {c: min(self.ts[c]['frameId']) for c in cams} + fid = {c: [getattr(m, m.which()).frameId for m in self.msgs[c]] for c in cams} + first_fid = [min(x) for x in fid.values()] if cam.endswith('CameraState'): # camerad guarantees that all cams start on frame ID 0 # (note loggerd also needs to start up fast enough to catch it) - assert set(first_fid.values()) == {0, }, "Cameras don't start on frame ID 0" + assert set(first_fid) == {0, }, "Cameras don't start on frame ID 0" else: # encoder guarantees all cams start on the same frame ID - assert len(set(first_fid.values())) == 1, "Cameras don't start on same frame ID" + assert len(set(first_fid)) == 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 + last_fid = [max(x) for x in fid.values()] + assert max(last_fid) - min(last_fid) < 10 - start, end = min(first_fid.values()), min(last_fid.values()) + start, end = min(first_fid), min(last_fid) + all_ts = [[getattr(m, m.which()).timestampSof for m in self.msgs[c]] for c in cams] 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())) + ts = [round(x[i]/1e6, 1) for x in all_ts] + diff = max(ts) - min(ts) assert diff < 2, f"Cameras not synced properly: frame_id={start+i}, {diff=:.1f}ms, {ts=}" def test_mpc_execution_timings(self): @@ -438,7 +438,12 @@ class TestOnroad: @release_only def test_startup(self): - startup_alert = self.ts['selfdriveState']['alertText1'][0] + startup_alert = None + for msg in self.lrs[0]: + # can't use onroadEvents because the first msg can be dropped while loggerd is starting up + if msg.which() == "selfdriveState": + startup_alert = msg.selfdriveState.alertText1 + break expected = EVENTS[log.OnroadEvent.EventName.startup][ET.PERMANENT].alert_text_1 assert startup_alert == expected, "wrong startup alert"