safety tests: rename interceptor message functions (#900)

This commit is contained in:
Shane Smiskol 2022-04-01 19:14:41 -07:00 committed by GitHub
parent 560bcc4063
commit 94bfed6d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 34 deletions

View File

@ -61,43 +61,47 @@ class InterceptorSafetyTest(PandaSafetyTestBase):
raise unittest.SkipTest
@abc.abstractmethod
def _interceptor_msg(self, gas, addr):
def _interceptor_gas_cmd(self, gas):
pass
@abc.abstractmethod
def _interceptor_user_gas(self, gas):
pass
def test_prev_gas_interceptor(self):
self._rx(self._interceptor_msg(0x0, 0x201))
self._rx(self._interceptor_user_gas(0x0))
self.assertFalse(self.safety.get_gas_interceptor_prev())
self._rx(self._interceptor_msg(0x1000, 0x201))
self._rx(self._interceptor_user_gas(0x1000))
self.assertTrue(self.safety.get_gas_interceptor_prev())
self._rx(self._interceptor_msg(0x0, 0x201))
self._rx(self._interceptor_user_gas(0x0))
self.safety.set_gas_interceptor_detected(False)
def test_disengage_on_gas_interceptor(self):
for g in range(0, 0x1000):
self._rx(self._interceptor_msg(0, 0x201))
self._rx(self._interceptor_user_gas(0))
self.safety.set_controls_allowed(True)
self._rx(self._interceptor_msg(g, 0x201))
self._rx(self._interceptor_user_gas(g))
remain_enabled = g <= self.INTERCEPTOR_THRESHOLD
self.assertEqual(remain_enabled, self.safety.get_controls_allowed())
self._rx(self._interceptor_msg(0, 0x201))
self._rx(self._interceptor_user_gas(0))
self.safety.set_gas_interceptor_detected(False)
def test_alternative_experience_no_disengage_on_gas_interceptor(self):
self.safety.set_controls_allowed(True)
self.safety.set_alternative_experience(ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS)
for g in range(0, 0x1000):
self._rx(self._interceptor_msg(g, 0x201))
self._rx(self._interceptor_user_gas(g))
self.assertTrue(self.safety.get_controls_allowed())
self._rx(self._interceptor_msg(0, 0x201))
self._rx(self._interceptor_user_gas(0))
self.safety.set_gas_interceptor_detected(False)
self.safety.set_alternative_experience(ALTERNATIVE_EXPERIENCE.DEFAULT)
def test_allow_engage_with_gas_interceptor_pressed(self):
self._rx(self._interceptor_msg(0x1000, 0x201))
self._rx(self._interceptor_user_gas(0x1000))
self.safety.set_controls_allowed(1)
self._rx(self._interceptor_msg(0x1000, 0x201))
self._rx(self._interceptor_user_gas(0x1000))
self.assertTrue(self.safety.get_controls_allowed())
self._rx(self._interceptor_msg(0, 0x201))
self._rx(self._interceptor_user_gas(0))
def test_gas_interceptor_safety_check(self):
for gas in np.arange(0, 4000, 100):
@ -107,7 +111,7 @@ class InterceptorSafetyTest(PandaSafetyTestBase):
send = True
else:
send = gas == 0
self.assertEqual(send, self._tx(self._interceptor_msg(gas, 0x200)))
self.assertEqual(send, self._tx(self._interceptor_gas_cmd(gas)))
class TorqueSteeringSafetyTest(PandaSafetyTestBase):

View File

@ -19,6 +19,16 @@ HONDA_NIDEC = 0
HONDA_BOSCH = 1
def interceptor_msg(gas, addr):
to_send = make_msg(0, addr, 6)
gas2 = gas * 2
to_send[0].data[0] = (gas & 0xFF00) >> 8
to_send[0].data[1] = gas & 0xFF
to_send[0].data[2] = (gas2 & 0xFF00) >> 8
to_send[0].data[3] = gas2 & 0xFF
return to_send
# Honda safety has several different configurations tested here:
# * Nidec
# * normal
@ -300,15 +310,11 @@ class TestHondaNidecSafetyBase(HondaBase):
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_NIDEC, 0)
self.safety.init_tests_honda()
# Honda gas gains are the different
def _interceptor_msg(self, gas, addr):
to_send = make_msg(0, addr, 6)
gas2 = gas * 2
to_send[0].data[0] = (gas & 0xFF00) >> 8
to_send[0].data[1] = gas & 0xFF
to_send[0].data[2] = (gas2 & 0xFF00) >> 8
to_send[0].data[3] = gas2 & 0xFF
return to_send
def _interceptor_gas_cmd(self, gas):
return interceptor_msg(gas, 0x200)
def _interceptor_user_gas(self, gas):
return interceptor_msg(gas, 0x201)
def _send_brake_msg(self, brake):
values = {"COMPUTER_BRAKE": brake}
@ -358,14 +364,14 @@ class TestHondaNidecSafetyBase(HondaBase):
for mode in [ALTERNATIVE_EXPERIENCE.DEFAULT, ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS]:
self.safety.set_alternative_experience(mode)
# gas_interceptor_prev > INTERCEPTOR_THRESHOLD
self._rx(self._interceptor_msg(self.INTERCEPTOR_THRESHOLD + 1, 0x201))
self._rx(self._interceptor_msg(self.INTERCEPTOR_THRESHOLD + 1, 0x201))
self._rx(self._interceptor_user_gas(self.INTERCEPTOR_THRESHOLD + 1))
self._rx(self._interceptor_user_gas(self.INTERCEPTOR_THRESHOLD + 1))
allow_ctrl = mode == ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS
self.safety.set_controls_allowed(1)
self.safety.set_honda_fwd_brake(False)
self.assertEqual(allow_ctrl, self._tx(self._send_brake_msg(self.MAX_BRAKE)))
self.assertEqual(allow_ctrl, self._tx(self._interceptor_msg(self.INTERCEPTOR_THRESHOLD, 0x200)))
self.assertEqual(allow_ctrl, self._tx(self._interceptor_gas_cmd(self.INTERCEPTOR_THRESHOLD)))
self.assertEqual(allow_ctrl, self._tx(self._send_steer_msg(0x1000)))
# reset status
@ -373,7 +379,7 @@ class TestHondaNidecSafetyBase(HondaBase):
self.safety.set_alternative_experience(ALTERNATIVE_EXPERIENCE.DEFAULT)
self._tx(self._send_brake_msg(0))
self._tx(self._send_steer_msg(0))
self._tx(self._interceptor_msg(0, 0x200))
self._tx(self._interceptor_gas_cmd(0))
self.safety.set_gas_interceptor_detected(False)

View File

@ -10,6 +10,16 @@ from panda.tests.safety.common import CANPackerPanda, make_msg, ALTERNATIVE_EXPE
MAX_ACCEL = 2.0
MIN_ACCEL = -3.5
def interceptor_msg(gas, addr):
to_send = make_msg(0, addr, 6)
to_send[0].data[0] = (gas & 0xFF00) >> 8
to_send[0].data[1] = gas & 0xFF
to_send[0].data[2] = (gas & 0xFF00) >> 8
to_send[0].data[3] = gas & 0xFF
return to_send
class TestToyotaSafety(common.PandaSafetyTest, common.InterceptorSafetyTest,
common.TorqueSteeringSafetyTest):
@ -72,14 +82,11 @@ class TestToyotaSafety(common.PandaSafetyTest, common.InterceptorSafetyTest,
values = {"CRUISE_ACTIVE": enable}
return self.packer.make_can_msg_panda("PCM_CRUISE", 0, values)
# Toyota gas gains are the same
def _interceptor_msg(self, gas, addr):
to_send = make_msg(0, addr, 6)
to_send[0].data[0] = (gas & 0xFF00) >> 8
to_send[0].data[1] = gas & 0xFF
to_send[0].data[2] = (gas & 0xFF00) >> 8
to_send[0].data[3] = gas & 0xFF
return to_send
def _interceptor_gas_cmd(self, gas):
return interceptor_msg(gas, 0x200)
def _interceptor_user_gas(self, gas):
return interceptor_msg(gas, 0x201)
def test_block_aeb(self):
for controls_allowed in (True, False):