Preserve Mazda lateral authority through Cancel deadline overlap

This commit is contained in:
firestar5683
2026-11-23 12:31:11 -06:00
parent d197e09d3b
commit f29ab3c676
3 changed files with 66 additions and 1 deletions
@@ -1602,6 +1602,12 @@ class SelfdriveD:
previous=decision, source_ns=source_ns, now_ns=now_ns, axis_session_id=self.aol_session_id,
cancel_samples=getattr(self, 'car_state_envelopes', ())):
user_disable = any(event.userDisable and event.name != EventName.buttonCancel for event in self.events.to_msg())
if user_disable and fresh_successor and decision.lateral_active and not decision.longitudinal_active and self.CP.brand == 'mazda':
from openpilot.starpilot.car.mazda.aol import physical_cancel_lateral_allowed
native = current_native(self.sm, self.CP, now_ns=now_ns, axis_session_id=self.aol_session_id)
if physical_cancel_lateral_allowed(self.CP, CS, intent, native, settings=self.aol_settings,
previous=decision, source_ns=source_ns, now_ns=now_ns, axis_session_id=self.aol_session_id):
user_disable = any(event.userDisable and event.name != EventName.buttonCancel for event in self.events.to_msg())
if user_disable and fresh_successor and self.ford_source_deadline_supported():
from openpilot.starpilot.car.ford.aol import physical_cancel_lateral_allowed
native = current_native(self.sm, self.CP, now_ns=now_ns, axis_session_id=self.aol_session_id)
@@ -0,0 +1,59 @@
from contextlib import ExitStack
from unittest import mock
import pytest
from opendbc.car import gen_empty_fingerprint
from opendbc.car.mazda.interface import CarInterface
from opendbc.car.mazda.values import CAR
from openpilot.cereal import log
from openpilot.common.prefix import OpenpilotPrefix
from openpilot.starpilot.aol.intent import read_settings
from openpilot.starpilot.aol.tests import test_ioniq_availability as fixture
from openpilot.starpilot.aol.tests.test_input_deadline_continuity import BASE, intent
@pytest.mark.parametrize('profile', [CAR.MAZDA_CX5, CAR.MAZDA_CX5_2022, CAR.MAZDA_CX9_2021])
@pytest.mark.parametrize('pulse', ['physical_cancel', 'permanent_eps', 'native_denied', 'driver_disarm', 'native_reordered'])
def test_mazda_cancel_after_previous_axis_deadline(profile, pulse):
with OpenpilotPrefix(), ExitStack() as cleanup:
case = fixture.IoniqAvailabilityTests(methodName='runTest')
cleanup.callback(case.doCleanups)
cp = CarInterface.get_params(profile, gen_empty_fingerprint(), [], False, False, False)
sd, _, drive = case._authority_callers(True, cp=cp, genuine_events=True)
sd.aol_settings = read_settings(sd.params)
state = fixture.car_state()
state.cruiseState.available = state.cruiseState.enabled = True
options = {'observed_state': state, 'native_request_long': False, 'long_allowed': False, 'panda_controls_allowed': True}
drive(0, **options)
prior, _, command = drive(2, state_stamp=BASE, offset_ns=6_066_613, intent_message=intent(BASE, 3), **options)
assert prior.lateralActive and command.latActive and not command.longActive
assert prior.validUntilMonoTime == BASE + 36_066_613
cancel_ns = BASE + 11_869_375
now = [BASE + 18_554_693]
state.buttonEvents = [{'type': 'cancel', 'pressed': True}]
if pulse == 'permanent_eps':
state.steerFaultPermanent = True
if pulse == 'native_denied':
options['allowed'] = False
publish = sd.publish_axis_proof
def publish_after_deadline(*args, **kwargs):
now[0] = prior.validUntilMonoTime + 320_000
return publish(*args, **kwargs)
offset_ns = -21_445_307 if pulse == 'native_reordered' else -1_445_307
with mock.patch('openpilot.selfdrive.selfdrived.selfdrived.time.monotonic_ns', side_effect=lambda: now[0]), \
mock.patch.object(sd, 'publish_axis_proof', side_effect=publish_after_deadline) as published:
axis, _, command = drive(4, state_stamp=cancel_ns, offset_ns=offset_ns,
intent_message=intent(cancel_ns, 4, latched=pulse != 'driver_disarm'), **options)
assert published.called
assert not command.longActive and not sd.enabled
if pulse == 'physical_cancel':
assert log.OnroadEvent.EventName.buttonCancel in sd.events.names
assert log.OnroadEvent.EventName.controlsMismatch not in sd.events.names
assert not sd.aol_authority_lost
assert axis.sourceCarStateMonoTime == cancel_ns and axis.lateralActive and command.latActive
else:
assert not axis.lateralActive and not command.latActive
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "d99e2885e775ca43cbf6c44120ac59d9ac08d235ddfbf2aaff0f243f185a321a", "schema_version": 1}
{"protected_inventory_sha256": "fcfbc1af4b5534aa28c75925e17ed6c025e49c0a25bd31b985261f37584e4cfe", "schema_version": 1}