Files
StarPilot/openpilot/starpilot/bluetooth/tests/test_startup_admission.py
T
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

71 lines
3.0 KiB
Python

"""Actual radio writer survives manager admission in a separate process."""
import os
import subprocess
import sys
from pathlib import Path
import pytest
from openpilot.common.params import Params, ParamKeyFlag
from openpilot.starpilot.bluetooth.radio_preference import RadioPreference
from openpilot.starpilot.state_migration import MigrationRequired, prepare_manager_start
SECOND_START = '''
import sys
from pathlib import Path
from openpilot.common.params import Params
from openpilot.starpilot.state_migration import prepare_manager_start
params = Params()
prepare_manager_start(params, Path(sys.argv[1]), dry_run=True)
prepare_manager_start(params, Path(sys.argv[1]))
'''
def test_actual_radio_writer_is_registered_and_second_start_preserves_value(tmp_path):
params_root = tmp_path / 'params'
params = Params(str(params_root))
storage = tmp_path / 'recovery'
preference = RadioPreference(Path(params.get_param_path('BluetoothEnabled')))
assert 'BluetoothEnabled' in {key.decode() if isinstance(key, bytes) else key for key in params.all_keys()}
assert params.get_default_value('BluetoothEnabled') is None
prepare_manager_start(params, storage)
assert not preference.path.exists()
for enabled in (True, False):
change = preference.begin(enabled)
change.apply()
expected = b'1' if enabled else b'0'
assert params.get('BluetoothEnabled') is enabled
assert preference.path.read_bytes() == expected
for flag in (ParamKeyFlag.CLEAR_ON_MANAGER_START, ParamKeyFlag.CLEAR_ON_ONROAD_TRANSITION,
ParamKeyFlag.CLEAR_ON_OFFROAD_TRANSITION, ParamKeyFlag.CLEAR_ON_IGNITION_ON,
ParamKeyFlag.DEVELOPMENT_ONLY):
params.clear_all(flag)
assert preference.path.read_bytes() == expected
subprocess.run([sys.executable, '-c', SECOND_START, str(storage)],
env=dict(os.environ, PARAMS_ROOT=str(params_root)), check=True)
assert preference.path.read_bytes() == expected
assert preference.enabled() is enabled
def test_legacy_newline_radio_semantics_and_unrelated_unknown_guard(tmp_path):
params = Params(str(tmp_path / 'params'))
storage = tmp_path / 'recovery'
prepare_manager_start(params, storage)
preference = RadioPreference(Path(params.get_param_path('BluetoothEnabled')))
preference.path.write_bytes(b'1\n\n')
assert preference.enabled()
subprocess.run([sys.executable, '-c', SECOND_START, str(storage)],
env=dict(os.environ, PARAMS_ROOT=str(tmp_path / 'params')), check=True)
assert preference.path.read_bytes() == b'1\n\n'
change = preference.begin(False)
change.apply()
assert change.rollback()
assert preference.path.read_bytes() == b'1\n\n'
unknown = Path(params.get_param_path()) / 'UnregisteredRadioRegression'
unknown.write_bytes(b'preserve')
with pytest.raises(MigrationRequired, match='unknown saved keys'):
prepare_manager_start(params, storage, dry_run=True)
assert unknown.read_bytes() == b'preserve'
assert preference.path.read_bytes() == b'1\n\n'