safety tests: rename gas/brake message functions (#893)

* _brake_msg and _gas_msg were confusing

* use class inheritance to define test specific safety variables

* Revert "use class inheritance to define test specific safety variables"

This reverts commit 734efd96f3.

* common function to set up each test

fix honda

* Revert "common function to set up each test"

This reverts commit fe4e71b3c6.

* rename related function

* formatting

* consistent name

* revert this change
This commit is contained in:
Shane Smiskol 2022-03-28 13:13:27 -07:00 committed by GitHub
parent 31d70299ae
commit 79145f9e5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 73 additions and 73 deletions

View File

@ -266,7 +266,7 @@ class PandaSafetyTest(PandaSafetyTestBase):
raise unittest.SkipTest
@abc.abstractmethod
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
pass
@abc.abstractmethod
@ -274,7 +274,7 @@ class PandaSafetyTest(PandaSafetyTestBase):
pass
@abc.abstractmethod
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
pass
@abc.abstractmethod
@ -332,36 +332,36 @@ class PandaSafetyTest(PandaSafetyTestBase):
def test_prev_gas(self):
self.assertFalse(self.safety.get_gas_pressed_prev())
for pressed in [self.GAS_PRESSED_THRESHOLD + 1, 0]:
self._rx(self._gas_msg(pressed))
self._rx(self._user_gas_msg(pressed))
self.assertEqual(bool(pressed), self.safety.get_gas_pressed_prev())
def test_allow_engage_with_gas_pressed(self):
self._rx(self._gas_msg(1))
self._rx(self._user_gas_msg(1))
self.safety.set_controls_allowed(True)
self._rx(self._gas_msg(1))
self._rx(self._user_gas_msg(1))
self.assertTrue(self.safety.get_controls_allowed())
self._rx(self._gas_msg(1))
self._rx(self._user_gas_msg(1))
self.assertTrue(self.safety.get_controls_allowed())
def test_disengage_on_gas(self):
self._rx(self._gas_msg(0))
self._rx(self._user_gas_msg(0))
self.safety.set_controls_allowed(True)
self._rx(self._gas_msg(self.GAS_PRESSED_THRESHOLD + 1))
self._rx(self._user_gas_msg(self.GAS_PRESSED_THRESHOLD + 1))
self.assertFalse(self.safety.get_controls_allowed())
def test_alternative_experience_no_disengage_on_gas(self):
self._rx(self._gas_msg(0))
self._rx(self._user_gas_msg(0))
self.safety.set_controls_allowed(True)
self.safety.set_alternative_experience(ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS)
self._rx(self._gas_msg(self.GAS_PRESSED_THRESHOLD + 1))
self._rx(self._user_gas_msg(self.GAS_PRESSED_THRESHOLD + 1))
self.assertTrue(self.safety.get_controls_allowed())
def test_prev_brake(self):
self.assertFalse(self.safety.get_brake_pressed_prev())
for pressed in [True, False]:
self._rx(self._brake_msg(not pressed))
self._rx(self._user_brake_msg(not pressed))
self.assertEqual(not pressed, self.safety.get_brake_pressed_prev())
self._rx(self._brake_msg(pressed))
self._rx(self._user_brake_msg(pressed))
self.assertEqual(pressed, self.safety.get_brake_pressed_prev())
def test_enable_control_allowed_from_cruise(self):
@ -385,26 +385,26 @@ class PandaSafetyTest(PandaSafetyTestBase):
def test_allow_brake_at_zero_speed(self):
# Brake was already pressed
self._rx(self._speed_msg(0))
self._rx(self._brake_msg(1))
self._rx(self._user_brake_msg(1))
self.safety.set_controls_allowed(1)
self._rx(self._brake_msg(1))
self._rx(self._user_brake_msg(1))
self.assertTrue(self.safety.get_controls_allowed())
self._rx(self._brake_msg(0))
self._rx(self._user_brake_msg(0))
self.assertTrue(self.safety.get_controls_allowed())
# rising edge of brake should disengage
self._rx(self._brake_msg(1))
self._rx(self._user_brake_msg(1))
self.assertFalse(self.safety.get_controls_allowed())
self._rx(self._brake_msg(0)) # reset no brakes
self._rx(self._user_brake_msg(0)) # reset no brakes
def test_not_allow_brake_when_moving(self):
# Brake was already pressed
self._rx(self._brake_msg(1))
self._rx(self._user_brake_msg(1))
self.safety.set_controls_allowed(1)
self._rx(self._speed_msg(self.STANDSTILL_THRESHOLD))
self._rx(self._brake_msg(1))
self._rx(self._user_brake_msg(1))
self.assertTrue(self.safety.get_controls_allowed())
self._rx(self._speed_msg(self.STANDSTILL_THRESHOLD + 1))
self._rx(self._brake_msg(1))
self._rx(self._user_brake_msg(1))
self.assertFalse(self.safety.get_controls_allowed())
self._rx(self._speed_msg(0))

View File

@ -45,12 +45,12 @@ class TestChryslerSafety(common.PandaSafetyTest, common.TorqueSteeringSafetyTest
values = {"SPEED_LEFT": speed, "SPEED_RIGHT": speed}
return self.packer.make_can_msg_panda("SPEED_1", 0, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"ACCEL_134": gas, "COUNTER": self.cnt_gas % 16}
self.__class__.cnt_gas += 1
return self.packer.make_can_msg_panda("ACCEL_GAS_134", 0, values)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"BRAKE_PRESSED_2": 5 if brake else 0,
"COUNTER": self.cnt_brake % 16}
self.__class__.cnt_brake += 1

View File

@ -65,11 +65,11 @@ class TestGmSafety(common.PandaSafetyTest):
values = {"ACCButtons": buttons}
return self.packer.make_can_msg_panda("ASCMSteeringButton", 0, values)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"Brake_Pressed": 1 if brake else 0}
return self.packer.make_can_msg_panda("ECMEngineStatus", 0, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"AcceleratorPedal2": 1 if gas else 0}
return self.packer.make_can_msg_panda("AcceleratorPedal2", 0, values)
@ -222,10 +222,10 @@ class TestGmSafety(common.PandaSafetyTest):
if pedal == 'brake':
# brake_pressed_prev and vehicle_moving
self._rx(self._speed_msg(100))
self._rx(self._brake_msg(MAX_BRAKE))
self._rx(self._user_brake_msg(MAX_BRAKE))
elif pedal == 'gas':
# gas_pressed_prev
self._rx(self._gas_msg(MAX_GAS))
self._rx(self._user_gas_msg(MAX_GAS))
self.safety.set_controls_allowed(1)
self.assertFalse(self._tx(self._send_brake_msg(MAX_BRAKE)))
@ -238,9 +238,9 @@ class TestGmSafety(common.PandaSafetyTest):
self._tx(self._torque_msg(0))
if pedal == 'brake':
self._rx(self._speed_msg(0))
self._rx(self._brake_msg(0))
self._rx(self._user_brake_msg(0))
elif pedal == 'gas':
self._rx(self._gas_msg(0))
self._rx(self._user_gas_msg(0))
def test_tx_hook_on_pedal_pressed_on_alternative_gas_experience(self):
for pedal in ['brake', 'gas']:
@ -248,11 +248,11 @@ class TestGmSafety(common.PandaSafetyTest):
if pedal == 'brake':
# brake_pressed_prev and vehicle_moving
self._rx(self._speed_msg(100))
self._rx(self._brake_msg(MAX_BRAKE))
self._rx(self._user_brake_msg(MAX_BRAKE))
allow_ctrl = False
elif pedal == 'gas':
# gas_pressed_prev
self._rx(self._gas_msg(MAX_GAS))
self._rx(self._user_gas_msg(MAX_GAS))
allow_ctrl = True
self.safety.set_controls_allowed(1)
@ -267,9 +267,9 @@ class TestGmSafety(common.PandaSafetyTest):
self._tx(self._torque_msg(0))
if pedal == 'brake':
self._rx(self._speed_msg(0))
self._rx(self._brake_msg(0))
self._rx(self._user_brake_msg(0))
elif pedal == 'gas':
self._rx(self._gas_msg(0))
self._rx(self._user_gas_msg(0))
if __name__ == "__main__":

View File

@ -91,7 +91,7 @@ class HondaButtonEnableBase(common.PandaSafetyTest):
if msg == "btn":
to_push = self._button_msg(Btn.SET)
if msg == "gas":
to_push = self._gas_msg(0)
to_push = self._user_gas_msg(0)
if msg == "speed":
to_push = self._speed_msg(0)
self.assertTrue(self._rx(to_push))
@ -113,11 +113,11 @@ class HondaButtonEnableBase(common.PandaSafetyTest):
self.safety.set_controls_allowed(1)
self._rx(self._button_msg(Btn.SET))
self._rx(self._speed_msg(0))
self._rx(self._gas_msg(0))
self._rx(self._user_gas_msg(0))
else:
self.assertFalse(self._rx(self._button_msg(Btn.SET)))
self.assertFalse(self._rx(self._speed_msg(0)))
self.assertFalse(self._rx(self._gas_msg(0)))
self.assertFalse(self._rx(self._user_gas_msg(0)))
self.assertFalse(self.safety.get_controls_allowed())
# restore counters for future tests with a couple of good messages
@ -125,7 +125,7 @@ class HondaButtonEnableBase(common.PandaSafetyTest):
self.safety.set_controls_allowed(1)
self._rx(self._button_msg(Btn.SET))
self._rx(self._speed_msg(0))
self._rx(self._gas_msg(0))
self._rx(self._user_gas_msg(0))
self._rx(self._button_msg(Btn.SET, main_on=True))
self.assertTrue(self.safety.get_controls_allowed())
@ -137,10 +137,10 @@ class HondaButtonEnableBase(common.PandaSafetyTest):
if pedal == 'brake':
# brake_pressed_prev and vehicle_moving
self._rx(self._speed_msg(100))
self._rx(self._brake_msg(1))
self._rx(self._user_brake_msg(1))
elif pedal == 'gas':
# gas_pressed_prev
self._rx(self._gas_msg(1))
self._rx(self._user_gas_msg(1))
allow_ctrl = mode == ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS
self.safety.set_controls_allowed(1)
@ -158,9 +158,9 @@ class HondaButtonEnableBase(common.PandaSafetyTest):
self._tx(self._send_steer_msg(0))
if pedal == 'brake':
self._rx(self._speed_msg(0))
self._rx(self._brake_msg(0))
self._rx(self._user_brake_msg(0))
elif pedal == 'gas':
self._rx(self._gas_msg(0))
self._rx(self._user_gas_msg(0))
class HondaPcmEnableBase(common.PandaSafetyTest):
@ -251,10 +251,10 @@ class HondaBase(common.PandaSafetyTest):
self.__class__.cnt_button += 1
return self.packer.make_can_msg_panda("SCM_BUTTONS", self.PT_BUS, values)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
return self._powertrain_data_msg(brake_pressed=brake)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
return self._powertrain_data_msg(gas_pressed=gas)
def _send_steer_msg(self, steer):
@ -267,7 +267,7 @@ class HondaBase(common.PandaSafetyTest):
def test_disengage_on_brake(self):
self.safety.set_controls_allowed(1)
self._rx(self._brake_msg(1))
self._rx(self._user_brake_msg(1))
self.assertFalse(self.safety.get_controls_allowed())
def test_steer_safety_check(self):

View File

@ -82,12 +82,12 @@ class TestHyundaiSafety(common.PandaSafetyTest):
values = {"CF_Clu_CruiseSwState": buttons}
return self.packer.make_can_msg_panda("CLU11", 0, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"CF_Ems_AclAct": gas, "AliveCounter": self.cnt_gas % 4}
self.__class__.cnt_gas += 1
return self.packer.make_can_msg_panda("EMS16", 0, values, fix_checksum=checksum)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"DriverBraking": brake, "AliveCounterTCS": self.cnt_brake % 8}
self.__class__.cnt_brake += 1
return self.packer.make_can_msg_panda("TCS13", 0, values, fix_checksum=checksum)
@ -238,7 +238,7 @@ class TestHyundaiLegacySafetyEV(TestHyundaiSafety):
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_LEGACY, 1)
self.safety.init_tests()
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"Accel_Pedal_Pos": gas}
return self.packer.make_can_msg_panda("E_EMS11", 0, values, fix_checksum=checksum)
@ -250,7 +250,7 @@ class TestHyundaiLegacySafetyHEV(TestHyundaiSafety):
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_LEGACY, 2)
self.safety.init_tests()
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"CR_Vcu_AccPedDep_Pos": gas}
return self.packer.make_can_msg_panda("E_EMS11", 0, values, fix_checksum=checksum)

View File

@ -47,11 +47,11 @@ class TestMazdaSafety(common.PandaSafetyTest):
values = {"SPEED": speed}
return self.packer.make_can_msg_panda("ENGINE_DATA", 0, values)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"BRAKE_ON": brake}
return self.packer.make_can_msg_panda("PEDALS", 0, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"PEDAL_GAS": gas}
return self.packer.make_can_msg_panda("ENGINE_DATA", 0, values)

View File

@ -56,11 +56,11 @@ class TestNissanSafety(common.PandaSafetyTest):
values = {"WHEEL_SPEED_%s" % s: speed * 3.6 for s in ["RR", "RL"]}
return self.packer.make_can_msg_panda("WHEEL_SPEEDS_REAR", 0, values)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"USER_BRAKE_PRESSED": brake}
return self.packer.make_can_msg_panda("DOORS_LIGHTS", 1, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"GAS_PEDAL": gas}
return self.packer.make_can_msg_panda("GAS_PEDAL", 0, values)
@ -149,11 +149,11 @@ class TestNissanLeafSafety(TestNissanSafety):
self.safety.set_safety_hooks(Panda.SAFETY_NISSAN, 0)
self.safety.init_tests()
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"USER_BRAKE_PRESSED": brake}
return self.packer.make_can_msg_panda("CRUISE_THROTTLE", 0, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"GAS_PEDAL": gas}
return self.packer.make_can_msg_panda("CRUISE_THROTTLE", 0, values)

View File

@ -53,7 +53,7 @@ class TestSubaruSafety(common.PandaSafetyTest):
self.__class__.cnt_speed += 1
return self.packer.make_can_msg_panda("Wheel_Speeds", 0, values)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"Brake": brake, "Counter": self.cnt_brake % 4}
self.__class__.cnt_brake += 1
return self.packer.make_can_msg_panda("Brake_Status", 0, values)
@ -62,7 +62,7 @@ class TestSubaruSafety(common.PandaSafetyTest):
values = {"LKAS_Output": torque}
return self.packer.make_can_msg_panda("ES_LKAS", 0, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"Throttle_Pedal": gas, "Counter": self.cnt_gas % 4}
self.__class__.cnt_gas += 1
return self.packer.make_can_msg_panda("Throttle", 0, values)

View File

@ -46,7 +46,7 @@ class TestSubaruLegacySafety(common.PandaSafetyTest):
values = {s: speed*0.0592 for s in ["FR", "FL", "RR", "RL"]}
return self.packer.make_can_msg_panda("Wheel_Speeds", 0, values)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"Brake_Pedal": brake}
return self.packer.make_can_msg_panda("Brake_Pedal", 0, values)
@ -54,7 +54,7 @@ class TestSubaruLegacySafety(common.PandaSafetyTest):
values = {"LKAS_Command": torque}
return self.packer.make_can_msg_panda("ES_LKAS", 0, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"Throttle_Pedal": gas, "Counter": self.cnt_gas % 4}
self.__class__.cnt_gas += 1
return self.packer.make_can_msg_panda("Throttle", 0, values)

View File

@ -55,11 +55,11 @@ class TestTeslaSafety(common.PandaSafetyTest):
values = {"DI_vehicleSpeed": speed / 0.447}
return self.packer.make_can_msg_panda("DI_torque2", 0, values)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"driverBrakeStatus": 2 if brake else 1}
return self.packer.make_can_msg_panda("BrakeMessage", 0, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"DI_pedalPos": gas}
return self.packer.make_can_msg_panda("DI_torque1", 0, values)

View File

@ -59,11 +59,11 @@ class TestToyotaSafety(common.PandaSafetyTest, common.InterceptorSafetyTest,
values = {("WHEEL_SPEED_%s" % n): speed for n in ["FR", "FL", "RR", "RL"]}
return self.packer.make_can_msg_panda("WHEEL_SPEEDS", 0, values)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"BRAKE_PRESSED": brake}
return self.packer.make_can_msg_panda("BRAKE_MODULE", 0, values)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
cruise_active = self.safety.get_controls_allowed()
values = {"GAS_RELEASED": not gas, "CRUISE_ACTIVE": cruise_active}
return self.packer.make_can_msg_panda("PCM_CRUISE", 0, values)

View File

@ -54,13 +54,13 @@ class TestVolkswagenMqbSafety(common.PandaSafetyTest):
return self.packer.make_can_msg_panda("ESP_19", 0, values)
# Brake light switch _esp_05_msg
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
values = {"ESP_Fahrer_bremst": brake, "COUNTER": self.cnt_esp_05 % 16}
self.__class__.cnt_esp_05 += 1
return self.packer.make_can_msg_panda("ESP_05", 0, values)
# Driver throttle input
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"MO_Fahrpedalrohwert_01": gas, "COUNTER": self.cnt_motor_20 % 16}
self.__class__.cnt_motor_20 += 1
return self.packer.make_can_msg_panda("Motor_20", 0, values)
@ -207,11 +207,11 @@ class TestVolkswagenMqbSafety(common.PandaSafetyTest):
if msg == MSG_LH_EPS_03:
to_push = self._lh_eps_03_msg(0)
if msg == MSG_ESP_05:
to_push = self._brake_msg(False)
to_push = self._user_brake_msg(False)
if msg == MSG_TSK_06:
to_push = self._pcm_status_msg(True)
if msg == MSG_MOTOR_20:
to_push = self._gas_msg(0)
to_push = self._user_gas_msg(0)
self.assertTrue(self._rx(to_push))
to_push[0].data[4] ^= 0xFF
self.assertFalse(self._rx(to_push))
@ -227,23 +227,23 @@ class TestVolkswagenMqbSafety(common.PandaSafetyTest):
if i < MAX_WRONG_COUNTERS:
self.safety.set_controls_allowed(1)
self._rx(self._lh_eps_03_msg(0))
self._rx(self._brake_msg(False))
self._rx(self._user_brake_msg(False))
self._rx(self._pcm_status_msg(True))
self._rx(self._gas_msg(0))
self._rx(self._user_gas_msg(0))
else:
self.assertFalse(self._rx(self._lh_eps_03_msg(0)))
self.assertFalse(self._rx(self._brake_msg(False)))
self.assertFalse(self._rx(self._user_brake_msg(False)))
self.assertFalse(self._rx(self._pcm_status_msg(True)))
self.assertFalse(self._rx(self._gas_msg(0)))
self.assertFalse(self._rx(self._user_gas_msg(0)))
self.assertFalse(self.safety.get_controls_allowed())
# restore counters for future tests with a couple of good messages
for i in range(2):
self.safety.set_controls_allowed(1)
self._rx(self._lh_eps_03_msg(0))
self._rx(self._brake_msg(False))
self._rx(self._user_brake_msg(False))
self._rx(self._pcm_status_msg(True))
self._rx(self._gas_msg(0))
self._rx(self._user_gas_msg(0))
self.assertTrue(self.safety.get_controls_allowed())

View File

@ -63,7 +63,7 @@ class TestVolkswagenPqSafety(common.PandaSafetyTest):
return self.packer.make_can_msg_panda("Bremse_1", 0, values)
# Brake light switch (shared message Motor_2)
def _brake_msg(self, brake):
def _user_brake_msg(self, brake):
# since this signal is used for engagement status, preserve current state
return self._motor_2_msg(brake_pressed=brake, cruise_engaged=self.safety.get_controls_allowed())
@ -100,7 +100,7 @@ class TestVolkswagenPqSafety(common.PandaSafetyTest):
return self.packer.make_can_msg_panda("Motor_2", 0, values)
# Driver throttle input (Motor_3)
def _gas_msg(self, gas):
def _user_gas_msg(self, gas):
values = {"Fahrpedal_Rohsignal": gas}
return self.packer.make_can_msg_panda("Motor_3", 0, values)