Files
StarPilot/openpilot/starpilot/replay/tests/test_display_clock.py
T
firestar5683 e9dd458699 Replay
Provide route replay, log migration and recorded vehicle fixtures for regression checks.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Kacper Rączy <gfw.kra@gmail.com>
Co-authored-by: YassineYousfi <yyousfi1@binghamton.edu>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
2026-10-14 20:02:39 -05:00

40 lines
1.8 KiB
Python

from pathlib import Path
import tempfile
import uuid
from openpilot.tools.replay.display_clock import DisplayClockReader, MAGIC, RECORD, VALID
def test_device_context_enables_owned_clock_and_opens_late_publisher(monkeypatch):
monkeypatch.setattr('openpilot.tools.replay.display_clock.sys.platform', 'darwin')
prefix = 'replay-' + uuid.uuid4().hex
with tempfile.TemporaryDirectory(prefix='replay-clock-'):
directory = Path('/tmp') / ('msgq_' + prefix)
directory.mkdir(mode=0o700)
path = directory / 'display-clock'
env = {'SP_REPLAY_CONTEXT': '1', 'OPENPILOT_PREFIX': prefix, 'SP_REPLAY_CLOCK_PATH': str(path)}
reader = DisplayClockReader(env)
try:
assert DisplayClockReader.enabled(env)
assert not reader.sample(10_000_000_000).valid
path.write_bytes(RECORD.pack(2, MAGIC, 1, VALID, 1, 100_000_000_000, 10_000_000_000, 1, 0, 10_000_000_000, 0))
path.chmod(0o600)
assert reader.sample(10_300_000_000).valid is False # the heartbeat expired, even for a new mapping
sample = reader.sample(10_000_000_000)
assert sample.valid and sample.now_ns == 100_000_000_000
reader.close()
assert reader.sample(10_000_000_000).valid is False
finally:
reader.close()
path.unlink(missing_ok=True)
directory.rmdir()
def test_device_context_does_not_weaken_prefix_or_path():
expected = '/dev/shm/msgq_replay-test/display-clock'
good = {'SP_REPLAY_CONTEXT': '1', 'OPENPILOT_PREFIX': 'replay-test', 'SP_REPLAY_CLOCK_PATH': expected}
assert DisplayClockReader.enabled(good)
for change in ({'OPENPILOT_PREFIX': 'd'}, {'OPENPILOT_PREFIX': '../replay-test'},
{'SP_REPLAY_CLOCK_PATH': '/data/params/d'}, {'SP_REPLAY_CONTEXT': '0'}):
assert not DisplayClockReader.enabled(good | change)