Avoid repeated static Bolt and empty-fault classification in Card

This commit is contained in:
firestar5683
2026-10-31 08:11:52 -05:00
parent 731a9e6c79
commit 68fca49aab
5 changed files with 62 additions and 2 deletions
+8
View File
@@ -1,3 +1,4 @@
from opendbc.car.config_cache import cached_config
from dataclasses import dataclass, field, replace
from enum import Enum, IntFlag
from math import isfinite
@@ -933,6 +934,13 @@ def is_bolt_pedal_removed_profile(cp, *, stock_only=False):
def is_bolt_pedal_profile(cp, *, stock_only=False):
if cp.brand != 'gm' or cp.carFingerprint not in BOLT_PEDAL_WORDS:
return False
return _bolt_pedal_profile(cp, stock_only=stock_only)
@cached_config
def _bolt_pedal_profile(cp, *, stock_only=False):
"""Exact selected interceptor profile, including its startup authority reduction."""
if is_bolt_pedal_removed_profile(cp, stock_only=stock_only):
return True
+4 -1
View File
@@ -65,13 +65,16 @@ def _diagnostic_mask(cp):
def blocking_fault_mask(mask, cp):
try:
value = int(mask)
return value < 0 or value > 0xFFFFFFFF or bool(value & ~_diagnostic_mask(cp))
return value < 0 or value > 0xFFFFFFFF or bool(value and value & ~_diagnostic_mask(cp))
except (TypeError, ValueError, OverflowError):
return True
def blocking_fault_list(faults, cp):
try:
faults = tuple(faults)
if not faults:
return False
allowed = _diagnostic_mask(cp)
named = ((log.PandaState.FaultType.interruptRateCan1, 1 << 2),
(log.PandaState.FaultType.interruptRateCan2, 1 << 3),
@@ -0,0 +1,41 @@
"""Static Bolt classification stays exact after saved/manual profile changes."""
import pytest
from opendbc.car.gm.values import CAR, _bolt_pedal_profile, is_bolt_pedal_profile
from opendbc.car.gm.tests.test_bolt_pedal import params
from openpilot.starpilot.aol.tests.test_gm import _configurations
def test_all_existing_gm_profiles_match_without_cache():
for cp in _configurations():
for stock in (False, True):
expected = _bolt_pedal_profile.__wrapped__(cp, stock_only=stock)
assert is_bolt_pedal_profile(cp, stock_only=stock) == expected
assert is_bolt_pedal_profile(cp.as_reader(), stock_only=stock) == expected
assert _bolt_pedal_profile.cache_info().currsize <= 8
@pytest.mark.parametrize('field,value', [('brand', 'hyundai'), ('carFingerprint', 'unknown'), ('flags', 0),
('passive', True), ('dashcamOnly', True), ('notCar', True), ('pcmCruise', True),
('openpilotLongitudinalControl', False), ('alphaLongitudinalAvailable', True), ('networkLocation', 'gateway'),
('safetyParam', 0), ('safetyModel', 'noOutput'), ('safetyConfigs', [])])
def test_builder_and_reader_alias_requalify_after_mutation(field, value):
cp = params(CAR.CHEVROLET_BOLT_CC_2018_2021, pedal=True, camera=True)
alias = cp.as_reader()
assert is_bolt_pedal_profile(cp)
if field in ('safetyParam', 'safetyModel'):
setattr(cp.safetyConfigs[0], field, value)
else:
setattr(cp, field, value)
assert not _bolt_pedal_profile.__wrapped__(cp)
assert not is_bolt_pedal_profile(cp)
assert not is_bolt_pedal_profile(alias)
def test_other_brands_and_non_bolt_profiles_skip_serialization():
cp = params(CAR.CHEVROLET_BOLT_CC_2018_2021, pedal=True, camera=True)
for field, value in [('brand', 'hyundai'), ('brand', 'honda'), ('carFingerprint', 'unknown')]:
cp.brand = 'gm'
setattr(cp, field, value)
previous = _bolt_pedal_profile.cache_info()
assert not is_bolt_pedal_profile(cp)
assert _bolt_pedal_profile.cache_info() == previous
@@ -96,3 +96,11 @@ def test_malformed_torque_tuning_does_not_borrow_exemption(field):
cp.lateralTuning.torque.latAccelFactor = 1.
setattr(cp.lateralTuning.torque, field, float('nan'))
assert _diagnostic_mask(cp) == original_mask(cp) == 0
def test_empty_fault_reports_skip_all_vehicle_diagnostic_work():
cp, _ = owner('bolt')
with patch('openpilot.starpilot.aol.panda_faults._diagnostic_mask', side_effect=AssertionError('empty fault report')):
assert not blocking_fault_mask(0, cp)
for faults in ([], (), iter(())):
assert not blocking_fault_list(faults, cp)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "ef71deaf14fdac8142ecd52aad0b70bab7c5cc79b81ce899ba5b8bfa50c45fa8", "schema_version": 1}
{"protected_inventory_sha256": "b22ffad92c34c5e211191c3782f4ae02f0e7e2c80a08ee0ee1e0215b68cbbddf", "schema_version": 1}