GM: clean up longitudinal safety test (#1573)

* clean up gm long safety test

* move to long base

* common brake
This commit is contained in:
Shane Smiskol 2023-08-10 23:49:28 -07:00 committed by GitHub
parent 25f1444d73
commit 61590b681a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 32 deletions

View File

@ -17,6 +17,11 @@ class Buttons:
class GmLongitudinalBase(common.PandaSafetyTest):
# pylint: disable=no-member,abstract-method
MAX_GAS = 0
MAX_REGEN = 0
INACTIVE_REGEN = 0
MAX_BRAKE = 400
PCM_CRUISE = False # openpilot can control the PCM state if longitudinal
def test_set_resume_buttons(self):
@ -41,6 +46,24 @@ class GmLongitudinalBase(common.PandaSafetyTest):
self._rx(self._button_msg(Buttons.CANCEL))
self.assertFalse(self.safety.get_controls_allowed())
def test_brake_safety_check(self):
for enabled in [0, 1]:
for b in range(0, 500):
self.safety.set_controls_allowed(enabled)
if abs(b) > self.MAX_BRAKE or (not enabled and b != 0):
self.assertFalse(self._tx(self._send_brake_msg(b)))
else:
self.assertTrue(self._tx(self._send_brake_msg(b)))
def test_gas_safety_check(self):
# Block if enabled and out of actuation range, disabled and not inactive regen, or if stock longitudinal
for enabled in [0, 1]:
for gas_regen in range(0, 2 ** 12 - 1):
self.safety.set_controls_allowed(enabled)
should_tx = ((enabled and self.MAX_REGEN <= gas_regen <= self.MAX_GAS) or
gas_regen == self.INACTIVE_REGEN)
self.assertEqual(should_tx, self._tx(self._send_gas_msg(gas_regen)), (enabled, gas_regen))
# override these tests from PandaSafetyTest, GM longitudinal uses button enable
def test_disable_control_allowed_from_cruise(self):
pass
@ -70,11 +93,6 @@ class TestGmSafetyBase(common.PandaSafetyTest, common.DriverTorqueSteeringSafety
DRIVER_TORQUE_ALLOWANCE = 65
DRIVER_TORQUE_FACTOR = 4
MAX_GAS = 0
MAX_REGEN = 0
INACTIVE_REGEN = 0
MAX_BRAKE = 0
PCM_CRUISE = True # openpilot is tied to the PCM state if not longitudinal
@classmethod
@ -138,24 +156,6 @@ class TestGmSafetyBase(common.PandaSafetyTest, common.DriverTorqueSteeringSafety
values = {"ACCButtons": buttons}
return self.packer.make_can_msg_panda("ASCMSteeringButton", self.BUTTONS_BUS, values)
def test_brake_safety_check(self):
for enabled in [0, 1]:
for b in range(0, 500):
self.safety.set_controls_allowed(enabled)
if abs(b) > self.MAX_BRAKE or (not enabled and b != 0):
self.assertFalse(self._tx(self._send_brake_msg(b)))
else:
self.assertTrue(self._tx(self._send_brake_msg(b)))
def test_gas_safety_check(self):
# Block if enabled and out of actuation range, disabled and not inactive regen, or if stock longitudinal
for enabled in [0, 1]:
for gas_regen in range(0, 2 ** 12 - 1):
self.safety.set_controls_allowed(enabled)
should_tx = ((enabled and self.MAX_REGEN <= gas_regen <= self.MAX_GAS) or
gas_regen == self.INACTIVE_REGEN)
self.assertEqual(should_tx, self._tx(self._send_gas_msg(gas_regen)), (enabled, gas_regen))
class TestGmAscmSafety(GmLongitudinalBase, TestGmSafetyBase):
TX_MSGS = [[384, 0], [1033, 0], [1034, 0], [715, 0], [880, 0], # pt bus
@ -169,7 +169,6 @@ class TestGmAscmSafety(GmLongitudinalBase, TestGmSafetyBase):
MAX_GAS = 3072
MAX_REGEN = 1404
INACTIVE_REGEN = 1404
MAX_BRAKE = 400
def setUp(self):
self.packer = CANPackerPanda("gm_global_a_powertrain_generated")
@ -222,13 +221,6 @@ class TestGmCameraSafety(TestGmCameraSafetyBase):
self._rx(self._pcm_status_msg(enabled))
self.assertEqual(enabled, self._tx(self._button_msg(Buttons.CANCEL)))
# GM Cam safety mode does not allow longitudinal messages
def test_brake_safety_check(self):
pass
def test_gas_safety_check(self):
pass
class TestGmCameraLongitudinalSafety(GmLongitudinalBase, TestGmCameraSafetyBase):
TX_MSGS = [[384, 0], [789, 0], [715, 0], [880, 0], # pt bus
@ -239,7 +231,6 @@ class TestGmCameraLongitudinalSafety(GmLongitudinalBase, TestGmCameraSafetyBase)
MAX_GAS = 3400
MAX_REGEN = 1514
INACTIVE_REGEN = 1554
MAX_BRAKE = 400
def setUp(self):
self.packer = CANPackerPanda("gm_global_a_powertrain_generated")