Files
firestar5683 a82935f326 User interfaces and Android Auto
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: pharmacomaniac <blittle65@gmail.com>

Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

56 lines
2.5 KiB
Python

"""Native UI state/cache integration in an isolated process; no drawing or devices."""
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
from openpilot.common.basedir import BASEDIR
class TestUICacheState(unittest.TestCase):
def test_lost_or_unqualified_cache_clears_displayed_vehicle_capability(self):
ipc_root = '/tmp' if sys.platform == 'darwin' else '/dev/shm'
with tempfile.TemporaryDirectory() as temporary, tempfile.TemporaryDirectory(prefix='msgq_cache-test-', dir=ipc_root) as ipc:
environment = dict(os.environ, PARAMS_ROOT=str(Path(temporary) / 'params'),
OPENPILOT_PREFIX=Path(ipc).name.removeprefix('msgq_'))
if sys.platform == 'darwin':
# The macOS wheel has no headless extension. Import its native backend
# without opening a window; this test never initializes drawing.
environment.pop('RAYLIB_BACKEND', None)
script = '''
from unittest.mock import patch
from opendbc.car.structs import car
from openpilot.common.params import Params
from openpilot.starpilot.schema_cache import put_cache
from openpilot.selfdrive.ui.ui_state import ui_state
params = Params()
cp = car.CarParams.new_message(openpilotLongitudinalControl=True, alphaLongitudinalAvailable=False)
with patch.object(ui_state, 'chestnut_compiled', True):
put_cache(params, 'CarParamsPersistent', cp, block=True)
ui_state.update_params()
assert ui_state.CP is not None and ui_state.has_longitudinal_control
params.remove('CarParamsPersistent')
ui_state.update_params()
assert ui_state.CP is None and not ui_state.has_longitudinal_control
params.put('CarParamsPersistent', cp.to_bytes(), block=True)
ui_state.update_params()
assert ui_state.CP is None and not ui_state.has_longitudinal_control
put_cache(params, 'CarParamsPersistent', cp, block=True)
ui_state.update_params()
assert ui_state.has_longitudinal_control
params.put('CarParamsPersistent', b'damaged-cache', block=True)
ui_state.update_params()
assert ui_state.CP is None and not ui_state.has_longitudinal_control
assert params.get('CarParamsPersistent') == b'damaged-cache'
assert ui_state._params_thread is None and not ui_state.prime_state._running
'''
result = subprocess.run([sys.executable, '-c', script], cwd=BASEDIR, env=environment, capture_output=True, text=True, timeout=30)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
if __name__ == '__main__':
unittest.main()