From bd98fe6031b0d831db25491f3d59a133c02c2055 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 27 Apr 2020 15:27:28 -0700 Subject: [PATCH] safety tests: use shorter function name --- tests/safety/test_chrysler.py | 56 +++++++++--------- tests/safety/test_gm.py | 94 +++++++++++++++--------------- tests/safety/test_hyundai.py | 44 +++++++------- tests/safety/test_nissan.py | 32 +++++----- tests/safety/test_subaru.py | 38 ++++++------ tests/safety/test_volkswagen_pq.py | 78 ++++++++++++------------- 6 files changed, 171 insertions(+), 171 deletions(-) diff --git a/tests/safety/test_chrysler.py b/tests/safety/test_chrysler.py index a969d1cc1e3b2b..a6d89d840e16ec 100755 --- a/tests/safety/test_chrysler.py +++ b/tests/safety/test_chrysler.py @@ -118,29 +118,29 @@ def test_steer_safety_check(self): self.safety.set_controls_allowed(enabled) self._set_prev_torque(t) if abs(t) > MAX_STEER or (not enabled and abs(t) > 0): - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertFalse(self._tx(self._torque_msg(t))) else: - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertTrue(self._tx(self._torque_msg(t))) # TODO: why does chrysler check if moving? def test_disengage_on_gas(self): self.safety.set_controls_allowed(1) - self.safety.safety_rx_hook(self._speed_msg(2.2)) - self.safety.safety_rx_hook(self._gas_msg(1)) + self._rx(self._speed_msg(2.2)) + self._rx(self._gas_msg(1)) self.assertTrue(self.safety.get_controls_allowed()) - self.safety.safety_rx_hook(self._gas_msg(0)) - self.safety.safety_rx_hook(self._speed_msg(2.3)) - self.safety.safety_rx_hook(self._gas_msg(1)) + self._rx(self._gas_msg(0)) + self._rx(self._speed_msg(2.3)) + self._rx(self._gas_msg(1)) self.assertFalse(self.safety.get_controls_allowed()) def test_non_realtime_limit_up(self): self.safety.set_controls_allowed(True) self._set_prev_torque(0) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP))) + self.assertTrue(self._tx(self._torque_msg(MAX_RATE_UP))) self._set_prev_torque(0) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP + 1))) + self.assertFalse(self._tx(self._torque_msg(MAX_RATE_UP + 1))) def test_non_realtime_limit_down(self): self.safety.set_controls_allowed(True) @@ -149,12 +149,12 @@ def test_non_realtime_limit_down(self): torque_meas = MAX_STEER - MAX_TORQUE_ERROR - 20 self.safety.set_chrysler_torque_meas(torque_meas, torque_meas) self.safety.set_chrysler_desired_torque_last(MAX_STEER) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_STEER - MAX_RATE_DOWN))) + self.assertTrue(self._tx(self._torque_msg(MAX_STEER - MAX_RATE_DOWN))) self.safety.set_chrysler_rt_torque_last(MAX_STEER) self.safety.set_chrysler_torque_meas(torque_meas, torque_meas) self.safety.set_chrysler_desired_torque_last(MAX_STEER) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(MAX_STEER - MAX_RATE_DOWN + 1))) + self.assertFalse(self._tx(self._torque_msg(MAX_STEER - MAX_RATE_DOWN + 1))) def test_exceed_torque_sensor(self): self.safety.set_controls_allowed(True) @@ -163,9 +163,9 @@ def test_exceed_torque_sensor(self): self._set_prev_torque(0) for t in np.arange(0, MAX_TORQUE_ERROR + 2, 2): # step needs to be smaller than MAX_TORQUE_ERROR t *= sign - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertTrue(self._tx(self._torque_msg(t))) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_TORQUE_ERROR + 2)))) + self.assertFalse(self._tx(self._torque_msg(sign * (MAX_TORQUE_ERROR + 2)))) def test_realtime_limit_up(self): self.safety.set_controls_allowed(True) @@ -176,36 +176,36 @@ def test_realtime_limit_up(self): for t in np.arange(0, MAX_RT_DELTA+1, 1): t *= sign self.safety.set_chrysler_torque_meas(t, t) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._torque_msg(t))) + self.assertFalse(self._tx(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) self._set_prev_torque(0) for t in np.arange(0, MAX_RT_DELTA+1, 1): t *= sign self.safety.set_chrysler_torque_meas(t, t) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertTrue(self._tx(self._torque_msg(t))) # Increase timer to update rt_torque_last self.safety.set_timer(RT_INTERVAL + 1) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * MAX_RT_DELTA))) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._torque_msg(sign * MAX_RT_DELTA))) + self.assertTrue(self._tx(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) def test_torque_measurements(self): - self.safety.safety_rx_hook(self._torque_meas_msg(50)) - self.safety.safety_rx_hook(self._torque_meas_msg(-50)) - self.safety.safety_rx_hook(self._torque_meas_msg(0)) - self.safety.safety_rx_hook(self._torque_meas_msg(0)) - self.safety.safety_rx_hook(self._torque_meas_msg(0)) - self.safety.safety_rx_hook(self._torque_meas_msg(0)) + self._rx(self._torque_meas_msg(50)) + self._rx(self._torque_meas_msg(-50)) + self._rx(self._torque_meas_msg(0)) + self._rx(self._torque_meas_msg(0)) + self._rx(self._torque_meas_msg(0)) + self._rx(self._torque_meas_msg(0)) self.assertEqual(-50, self.safety.get_chrysler_torque_meas_min()) self.assertEqual(50, self.safety.get_chrysler_torque_meas_max()) - self.safety.safety_rx_hook(self._torque_meas_msg(0)) + self._rx(self._torque_meas_msg(0)) self.assertEqual(0, self.safety.get_chrysler_torque_meas_max()) self.assertEqual(-50, self.safety.get_chrysler_torque_meas_min()) - self.safety.safety_rx_hook(self._torque_meas_msg(0)) + self._rx(self._torque_meas_msg(0)) self.assertEqual(0, self.safety.get_chrysler_torque_meas_max()) self.assertEqual(0, self.safety.get_chrysler_torque_meas_min()) @@ -213,9 +213,9 @@ def test_cancel_button(self): CANCEL = 1 for b in range(0, 0x1ff): if b == CANCEL: - self.assertTrue(self.safety.safety_tx_hook(self._button_msg(b))) + self.assertTrue(self._tx(self._button_msg(b))) else: - self.assertFalse(self.safety.safety_tx_hook(self._button_msg(b))) + self.assertFalse(self._tx(self._button_msg(b))) if __name__ == "__main__": diff --git a/tests/safety/test_gm.py b/tests/safety/test_gm.py index 4ca8ae7727cc9f..ad54f4f94d3853 100644 --- a/tests/safety/test_gm.py +++ b/tests/safety/test_gm.py @@ -81,19 +81,19 @@ def _torque_msg(self, torque): def test_resume_button(self): RESUME_BTN = 2 self.safety.set_controls_allowed(0) - self.safety.safety_rx_hook(self._button_msg(RESUME_BTN)) + self._rx(self._button_msg(RESUME_BTN)) self.assertTrue(self.safety.get_controls_allowed()) def test_set_button(self): SET_BTN = 3 self.safety.set_controls_allowed(0) - self.safety.safety_rx_hook(self._button_msg(SET_BTN)) + self._rx(self._button_msg(SET_BTN)) self.assertTrue(self.safety.get_controls_allowed()) def test_cancel_button(self): CANCEL_BTN = 6 self.safety.set_controls_allowed(1) - self.safety.safety_rx_hook(self._button_msg(CANCEL_BTN)) + self._rx(self._button_msg(CANCEL_BTN)) self.assertFalse(self.safety.get_controls_allowed()) def test_brake_safety_check(self): @@ -101,18 +101,18 @@ def test_brake_safety_check(self): for b in range(0, 500): self.safety.set_controls_allowed(enabled) if abs(b) > MAX_BRAKE or (not enabled and b != 0): - self.assertFalse(self.safety.safety_tx_hook(self._send_brake_msg(b))) + self.assertFalse(self._tx(self._send_brake_msg(b))) else: - self.assertTrue(self.safety.safety_tx_hook(self._send_brake_msg(b))) + self.assertTrue(self._tx(self._send_brake_msg(b))) def test_gas_safety_check(self): for enabled in [0, 1]: for g in range(0, 2**12-1): self.safety.set_controls_allowed(enabled) if abs(g) > MAX_GAS or (not enabled and g != MAX_REGEN): - self.assertFalse(self.safety.safety_tx_hook(self._send_gas_msg(g))) + self.assertFalse(self._tx(self._send_gas_msg(g))) else: - self.assertTrue(self.safety.safety_tx_hook(self._send_gas_msg(g))) + self.assertTrue(self._tx(self._send_gas_msg(g))) def test_steer_safety_check(self): for enabled in [0, 1]: @@ -120,24 +120,24 @@ def test_steer_safety_check(self): self.safety.set_controls_allowed(enabled) self._set_prev_torque(t) if abs(t) > MAX_STEER or (not enabled and abs(t) > 0): - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertFalse(self._tx(self._torque_msg(t))) else: - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertTrue(self._tx(self._torque_msg(t))) def test_non_realtime_limit_up(self): self.safety.set_gm_torque_driver(0, 0) self.safety.set_controls_allowed(True) self._set_prev_torque(0) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP))) + self.assertTrue(self._tx(self._torque_msg(MAX_RATE_UP))) self._set_prev_torque(0) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(-MAX_RATE_UP))) + self.assertTrue(self._tx(self._torque_msg(-MAX_RATE_UP))) self._set_prev_torque(0) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP + 1))) + self.assertFalse(self._tx(self._torque_msg(MAX_RATE_UP + 1))) self.safety.set_controls_allowed(True) self._set_prev_torque(0) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(-MAX_RATE_UP - 1))) + self.assertFalse(self._tx(self._torque_msg(-MAX_RATE_UP - 1))) def test_non_realtime_limit_down(self): self.safety.set_gm_torque_driver(0, 0) @@ -151,10 +151,10 @@ def test_against_torque_driver(self): t *= -sign self.safety.set_gm_torque_driver(t, t) self._set_prev_torque(MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_STEER * sign))) + self.assertTrue(self._tx(self._torque_msg(MAX_STEER * sign))) self.safety.set_gm_torque_driver(DRIVER_TORQUE_ALLOWANCE + 1, DRIVER_TORQUE_ALLOWANCE + 1) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(-MAX_STEER))) + self.assertFalse(self._tx(self._torque_msg(-MAX_STEER))) # spot check some individual cases for sign in [-1, 1]: @@ -163,20 +163,20 @@ def test_against_torque_driver(self): delta = 1 * sign self._set_prev_torque(torque_desired) self.safety.set_gm_torque_driver(-driver_torque, -driver_torque) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(torque_desired))) + self.assertTrue(self._tx(self._torque_msg(torque_desired))) self._set_prev_torque(torque_desired + delta) self.safety.set_gm_torque_driver(-driver_torque, -driver_torque) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(torque_desired + delta))) + self.assertFalse(self._tx(self._torque_msg(torque_desired + delta))) self._set_prev_torque(MAX_STEER * sign) self.safety.set_gm_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg((MAX_STEER - MAX_RATE_DOWN) * sign))) + self.assertTrue(self._tx(self._torque_msg((MAX_STEER - MAX_RATE_DOWN) * sign))) self._set_prev_torque(MAX_STEER * sign) self.safety.set_gm_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(0))) + self.assertTrue(self._tx(self._torque_msg(0))) self._set_prev_torque(MAX_STEER * sign) self.safety.set_gm_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg((MAX_STEER - MAX_RATE_DOWN + 1) * sign))) + self.assertFalse(self._tx(self._torque_msg((MAX_STEER - MAX_RATE_DOWN + 1) * sign))) def test_realtime_limits(self): @@ -188,73 +188,73 @@ def test_realtime_limits(self): self.safety.set_gm_torque_driver(0, 0) for t in np.arange(0, MAX_RT_DELTA, 1): t *= sign - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._torque_msg(t))) + self.assertFalse(self._tx(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) self._set_prev_torque(0) for t in np.arange(0, MAX_RT_DELTA, 1): t *= sign - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertTrue(self._tx(self._torque_msg(t))) # Increase timer to update rt_torque_last self.safety.set_timer(RT_INTERVAL + 1) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA - 1)))) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._torque_msg(sign * (MAX_RT_DELTA - 1)))) + self.assertTrue(self._tx(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) def test_tx_hook_on_pedal_pressed(self): for pedal in ['brake', 'gas']: if pedal == 'brake': # brake_pressed_prev and honda_moving - self.safety.safety_rx_hook(self._speed_msg(100)) - self.safety.safety_rx_hook(self._brake_msg(MAX_BRAKE)) + self._rx(self._speed_msg(100)) + self._rx(self._brake_msg(MAX_BRAKE)) elif pedal == 'gas': # gas_pressed_prev - self.safety.safety_rx_hook(self._gas_msg(MAX_GAS)) + self._rx(self._gas_msg(MAX_GAS)) self.safety.set_controls_allowed(1) - self.assertFalse(self.safety.safety_tx_hook(self._send_brake_msg(MAX_BRAKE))) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP))) - self.assertFalse(self.safety.safety_tx_hook(self._send_gas_msg(MAX_GAS))) + self.assertFalse(self._tx(self._send_brake_msg(MAX_BRAKE))) + self.assertFalse(self._tx(self._torque_msg(MAX_RATE_UP))) + self.assertFalse(self._tx(self._send_gas_msg(MAX_GAS))) # reset status self.safety.set_controls_allowed(0) - self.safety.safety_tx_hook(self._send_brake_msg(0)) - self.safety.safety_tx_hook(self._torque_msg(0)) + self._tx(self._send_brake_msg(0)) + self._tx(self._torque_msg(0)) if pedal == 'brake': - self.safety.safety_rx_hook(self._speed_msg(0)) - self.safety.safety_rx_hook(self._brake_msg(0)) + self._rx(self._speed_msg(0)) + self._rx(self._brake_msg(0)) elif pedal == 'gas': - self.safety.safety_rx_hook(self._gas_msg(0)) + self._rx(self._gas_msg(0)) def test_tx_hook_on_pedal_pressed_on_unsafe_gas_mode(self): for pedal in ['brake', 'gas']: self.safety.set_unsafe_mode(UNSAFE_MODE.DISABLE_DISENGAGE_ON_GAS) if pedal == 'brake': # brake_pressed_prev and honda_moving - self.safety.safety_rx_hook(self._speed_msg(100)) - self.safety.safety_rx_hook(self._brake_msg(MAX_BRAKE)) + self._rx(self._speed_msg(100)) + self._rx(self._brake_msg(MAX_BRAKE)) allow_ctrl = False elif pedal == 'gas': # gas_pressed_prev - self.safety.safety_rx_hook(self._gas_msg(MAX_GAS)) + self._rx(self._gas_msg(MAX_GAS)) allow_ctrl = True self.safety.set_controls_allowed(1) - self.assertEqual(allow_ctrl, self.safety.safety_tx_hook(self._send_brake_msg(MAX_BRAKE))) - self.assertEqual(allow_ctrl, self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP))) - self.assertEqual(allow_ctrl, self.safety.safety_tx_hook(self._send_gas_msg(MAX_GAS))) + self.assertEqual(allow_ctrl, self._tx(self._send_brake_msg(MAX_BRAKE))) + self.assertEqual(allow_ctrl, self._tx(self._torque_msg(MAX_RATE_UP))) + self.assertEqual(allow_ctrl, self._tx(self._send_gas_msg(MAX_GAS))) # reset status self.safety.set_controls_allowed(0) self.safety.set_unsafe_mode(UNSAFE_MODE.DEFAULT) - self.safety.safety_tx_hook(self._send_brake_msg(0)) - self.safety.safety_tx_hook(self._torque_msg(0)) + self._tx(self._send_brake_msg(0)) + self._tx(self._torque_msg(0)) if pedal == 'brake': - self.safety.safety_rx_hook(self._speed_msg(0)) - self.safety.safety_rx_hook(self._brake_msg(0)) + self._rx(self._speed_msg(0)) + self._rx(self._brake_msg(0)) elif pedal == 'gas': - self.safety.safety_rx_hook(self._gas_msg(0)) + self._rx(self._gas_msg(0)) if __name__ == "__main__": unittest.main() diff --git a/tests/safety/test_hyundai.py b/tests/safety/test_hyundai.py index 673770bde11647..0e63aa38c6877a 100644 --- a/tests/safety/test_hyundai.py +++ b/tests/safety/test_hyundai.py @@ -71,24 +71,24 @@ def test_steer_safety_check(self): self.safety.set_controls_allowed(enabled) self._set_prev_torque(t) if abs(t) > MAX_STEER or (not enabled and abs(t) > 0): - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertFalse(self._tx(self._torque_msg(t))) else: - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertTrue(self._tx(self._torque_msg(t))) def test_non_realtime_limit_up(self): self.safety.set_hyundai_torque_driver(0, 0) self.safety.set_controls_allowed(True) self._set_prev_torque(0) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP))) + self.assertTrue(self._tx(self._torque_msg(MAX_RATE_UP))) self._set_prev_torque(0) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(-MAX_RATE_UP))) + self.assertTrue(self._tx(self._torque_msg(-MAX_RATE_UP))) self._set_prev_torque(0) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP + 1))) + self.assertFalse(self._tx(self._torque_msg(MAX_RATE_UP + 1))) self.safety.set_controls_allowed(True) self._set_prev_torque(0) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(-MAX_RATE_UP - 1))) + self.assertFalse(self._tx(self._torque_msg(-MAX_RATE_UP - 1))) def test_non_realtime_limit_down(self): self.safety.set_hyundai_torque_driver(0, 0) @@ -102,10 +102,10 @@ def test_against_torque_driver(self): t *= -sign self.safety.set_hyundai_torque_driver(t, t) self._set_prev_torque(MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_STEER * sign))) + self.assertTrue(self._tx(self._torque_msg(MAX_STEER * sign))) self.safety.set_hyundai_torque_driver(DRIVER_TORQUE_ALLOWANCE + 1, DRIVER_TORQUE_ALLOWANCE + 1) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(-MAX_STEER))) + self.assertFalse(self._tx(self._torque_msg(-MAX_STEER))) # spot check some individual cases for sign in [-1, 1]: @@ -114,20 +114,20 @@ def test_against_torque_driver(self): delta = 1 * sign self._set_prev_torque(torque_desired) self.safety.set_hyundai_torque_driver(-driver_torque, -driver_torque) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(torque_desired))) + self.assertTrue(self._tx(self._torque_msg(torque_desired))) self._set_prev_torque(torque_desired + delta) self.safety.set_hyundai_torque_driver(-driver_torque, -driver_torque) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(torque_desired + delta))) + self.assertFalse(self._tx(self._torque_msg(torque_desired + delta))) self._set_prev_torque(MAX_STEER * sign) self.safety.set_hyundai_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg((MAX_STEER - MAX_RATE_DOWN) * sign))) + self.assertTrue(self._tx(self._torque_msg((MAX_STEER - MAX_RATE_DOWN) * sign))) self._set_prev_torque(MAX_STEER * sign) self.safety.set_hyundai_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(0))) + self.assertTrue(self._tx(self._torque_msg(0))) self._set_prev_torque(MAX_STEER * sign) self.safety.set_hyundai_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg((MAX_STEER - MAX_RATE_DOWN + 1) * sign))) + self.assertFalse(self._tx(self._torque_msg((MAX_STEER - MAX_RATE_DOWN + 1) * sign))) def test_realtime_limits(self): @@ -139,18 +139,18 @@ def test_realtime_limits(self): self.safety.set_hyundai_torque_driver(0, 0) for t in np.arange(0, MAX_RT_DELTA, 1): t *= sign - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._torque_msg(t))) + self.assertFalse(self._tx(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) self._set_prev_torque(0) for t in np.arange(0, MAX_RT_DELTA, 1): t *= sign - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertTrue(self._tx(self._torque_msg(t))) # Increase timer to update rt_torque_last self.safety.set_timer(RT_INTERVAL + 1) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA - 1)))) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._torque_msg(sign * (MAX_RT_DELTA - 1)))) + self.assertTrue(self._tx(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) def test_spam_cancel_safety_check(self): @@ -158,12 +158,12 @@ def test_spam_cancel_safety_check(self): SET_BTN = 2 CANCEL_BTN = 4 self.safety.set_controls_allowed(0) - self.assertTrue(self.safety.safety_tx_hook(self._button_msg(CANCEL_BTN))) - self.assertFalse(self.safety.safety_tx_hook(self._button_msg(RESUME_BTN))) - self.assertFalse(self.safety.safety_tx_hook(self._button_msg(SET_BTN))) + self.assertTrue(self._tx(self._button_msg(CANCEL_BTN))) + self.assertFalse(self._tx(self._button_msg(RESUME_BTN))) + self.assertFalse(self._tx(self._button_msg(SET_BTN))) # do not block resume if we are engaged already self.safety.set_controls_allowed(1) - self.assertTrue(self.safety.safety_tx_hook(self._button_msg(RESUME_BTN))) + self.assertTrue(self._tx(self._button_msg(RESUME_BTN))) if __name__ == "__main__": diff --git a/tests/safety/test_nissan.py b/tests/safety/test_nissan.py index cbcdd28fc80e2f..853899ae789ff0 100644 --- a/tests/safety/test_nissan.py +++ b/tests/safety/test_nissan.py @@ -41,7 +41,7 @@ def _set_prev_angle(self, t): def _angle_meas_msg_array(self, angle): for i in range(6): - self.safety.safety_rx_hook(self._angle_meas_msg(angle)) + self._rx(self._angle_meas_msg(angle)) def _pcm_status_msg(self, enabled): values = {"CRUISE_ENABLED": enabled} @@ -82,68 +82,68 @@ def test_angle_cmd_when_enabled(self): # first test against false positives self._angle_meas_msg_array(a) - self.safety.safety_rx_hook(self._speed_msg(s)) + self._rx(self._speed_msg(s)) self._set_prev_angle(a) self.safety.set_controls_allowed(1) # Stay within limits # Up - self.assertEqual(True, self.safety.safety_tx_hook(self._lkas_control_msg(a + sign(a) * max_delta_up, 1))) + self.assertEqual(True, self._tx(self._lkas_control_msg(a + sign(a) * max_delta_up, 1))) self.assertTrue(self.safety.get_controls_allowed()) # Don't change - self.assertEqual(True, self.safety.safety_tx_hook(self._lkas_control_msg(a, 1))) + self.assertEqual(True, self._tx(self._lkas_control_msg(a, 1))) self.assertTrue(self.safety.get_controls_allowed()) # Down - self.assertEqual(True, self.safety.safety_tx_hook(self._lkas_control_msg(a - sign(a) * max_delta_down, 1))) + self.assertEqual(True, self._tx(self._lkas_control_msg(a - sign(a) * max_delta_down, 1))) self.assertTrue(self.safety.get_controls_allowed()) # Inject too high rates # Up - self.assertEqual(False, self.safety.safety_tx_hook(self._lkas_control_msg(a + sign(a) * (max_delta_up + 1), 1))) + self.assertEqual(False, self._tx(self._lkas_control_msg(a + sign(a) * (max_delta_up + 1), 1))) self.assertFalse(self.safety.get_controls_allowed()) # Don't change self.safety.set_controls_allowed(1) self._set_prev_angle(a) self.assertTrue(self.safety.get_controls_allowed()) - self.assertEqual(True, self.safety.safety_tx_hook(self._lkas_control_msg(a, 1))) + self.assertEqual(True, self._tx(self._lkas_control_msg(a, 1))) self.assertTrue(self.safety.get_controls_allowed()) # Down - self.assertEqual(False, self.safety.safety_tx_hook(self._lkas_control_msg(a - sign(a) * (max_delta_down + 1), 1))) + self.assertEqual(False, self._tx(self._lkas_control_msg(a - sign(a) * (max_delta_down + 1), 1))) self.assertFalse(self.safety.get_controls_allowed()) # Check desired steer should be the same as steer angle when controls are off self.safety.set_controls_allowed(0) - self.assertEqual(True, self.safety.safety_tx_hook(self._lkas_control_msg(a, 0))) + self.assertEqual(True, self._tx(self._lkas_control_msg(a, 0))) def test_angle_cmd_when_disabled(self): self.safety.set_controls_allowed(0) self._set_prev_angle(0) - self.assertFalse(self.safety.safety_tx_hook(self._lkas_control_msg(0, 1))) + self.assertFalse(self._tx(self._lkas_control_msg(0, 1))) self.assertFalse(self.safety.get_controls_allowed()) def test_acc_buttons(self): self.safety.set_controls_allowed(1) - self.safety.safety_tx_hook(self._acc_button_cmd(cancel=1)) + self._tx(self._acc_button_cmd(cancel=1)) self.assertTrue(self.safety.get_controls_allowed()) - self.safety.safety_tx_hook(self._acc_button_cmd(propilot=1)) + self._tx(self._acc_button_cmd(propilot=1)) self.assertFalse(self.safety.get_controls_allowed()) self.safety.set_controls_allowed(1) - self.safety.safety_tx_hook(self._acc_button_cmd(flw_dist=1)) + self._tx(self._acc_button_cmd(flw_dist=1)) self.assertFalse(self.safety.get_controls_allowed()) self.safety.set_controls_allowed(1) - self.safety.safety_tx_hook(self._acc_button_cmd(_set=1)) + self._tx(self._acc_button_cmd(_set=1)) self.assertFalse(self.safety.get_controls_allowed()) self.safety.set_controls_allowed(1) - self.safety.safety_tx_hook(self._acc_button_cmd(res=1)) + self._tx(self._acc_button_cmd(res=1)) self.assertFalse(self.safety.get_controls_allowed()) self.safety.set_controls_allowed(1) - self.safety.safety_tx_hook(self._acc_button_cmd()) + self._tx(self._acc_button_cmd()) self.assertFalse(self.safety.get_controls_allowed()) diff --git a/tests/safety/test_subaru.py b/tests/safety/test_subaru.py index fe74c0e26fc730..4243b5e1ebd4b0 100644 --- a/tests/safety/test_subaru.py +++ b/tests/safety/test_subaru.py @@ -74,8 +74,8 @@ def _pcm_status_msg(self, cruise): def _set_torque_driver(self, min_t, max_t): for i in range(0, 5): - self.safety.safety_rx_hook(self._torque_driver_msg(min_t)) - self.safety.safety_rx_hook(self._torque_driver_msg(max_t)) + self._rx(self._torque_driver_msg(min_t)) + self._rx(self._torque_driver_msg(max_t)) def test_steer_safety_check(self): for enabled in [0, 1]: @@ -83,22 +83,22 @@ def test_steer_safety_check(self): self.safety.set_controls_allowed(enabled) self._set_prev_torque(t) block = abs(t) > MAX_STEER or (not enabled and abs(t) > 0) - self.assertEqual(not block, self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertEqual(not block, self._tx(self._torque_msg(t))) def test_non_realtime_limit_up(self): self._set_torque_driver(0, 0) self.safety.set_controls_allowed(True) self._set_prev_torque(0) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP))) + self.assertTrue(self._tx(self._torque_msg(MAX_RATE_UP))) self._set_prev_torque(0) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(-MAX_RATE_UP))) + self.assertTrue(self._tx(self._torque_msg(-MAX_RATE_UP))) self._set_prev_torque(0) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(MAX_RATE_UP + 1))) + self.assertFalse(self._tx(self._torque_msg(MAX_RATE_UP + 1))) self.safety.set_controls_allowed(True) self._set_prev_torque(0) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(-MAX_RATE_UP - 1))) + self.assertFalse(self._tx(self._torque_msg(-MAX_RATE_UP - 1))) def test_non_realtime_limit_down(self): self._set_torque_driver(0, 0) @@ -112,10 +112,10 @@ def test_against_torque_driver(self): t *= -sign self._set_torque_driver(t, t) self._set_prev_torque(MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(MAX_STEER * sign))) + self.assertTrue(self._tx(self._torque_msg(MAX_STEER * sign))) self._set_torque_driver(DRIVER_TORQUE_ALLOWANCE + 1, DRIVER_TORQUE_ALLOWANCE + 1) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(-MAX_STEER))) + self.assertFalse(self._tx(self._torque_msg(-MAX_STEER))) # arbitrary high driver torque to ensure max steer torque is allowed max_driver_torque = int(MAX_STEER / DRIVER_TORQUE_FACTOR + DRIVER_TORQUE_ALLOWANCE + 1) @@ -127,20 +127,20 @@ def test_against_torque_driver(self): delta = 1 * sign self._set_prev_torque(torque_desired) self._set_torque_driver(-driver_torque, -driver_torque) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(torque_desired))) + self.assertTrue(self._tx(self._torque_msg(torque_desired))) self._set_prev_torque(torque_desired + delta) self._set_torque_driver(-driver_torque, -driver_torque) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(torque_desired + delta))) + self.assertFalse(self._tx(self._torque_msg(torque_desired + delta))) self._set_prev_torque(MAX_STEER * sign) self._set_torque_driver(-max_driver_torque * sign, -max_driver_torque * sign) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg((MAX_STEER - MAX_RATE_DOWN) * sign))) + self.assertTrue(self._tx(self._torque_msg((MAX_STEER - MAX_RATE_DOWN) * sign))) self._set_prev_torque(MAX_STEER * sign) self._set_torque_driver(-max_driver_torque * sign, -max_driver_torque * sign) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(0))) + self.assertTrue(self._tx(self._torque_msg(0))) self._set_prev_torque(MAX_STEER * sign) self._set_torque_driver(-max_driver_torque * sign, -max_driver_torque * sign) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg((MAX_STEER - MAX_RATE_DOWN + 1) * sign))) + self.assertFalse(self._tx(self._torque_msg((MAX_STEER - MAX_RATE_DOWN + 1) * sign))) def test_realtime_limits(self): @@ -152,18 +152,18 @@ def test_realtime_limits(self): self._set_torque_driver(0, 0) for t in np.arange(0, MAX_RT_DELTA, 1): t *= sign - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) - self.assertFalse(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._torque_msg(t))) + self.assertFalse(self._tx(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) self._set_prev_torque(0) for t in np.arange(0, MAX_RT_DELTA, 1): t *= sign - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(t))) + self.assertTrue(self._tx(self._torque_msg(t))) # Increase timer to update rt_torque_last self.safety.set_timer(RT_INTERVAL + 1) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA - 1)))) - self.assertTrue(self.safety.safety_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._torque_msg(sign * (MAX_RT_DELTA - 1)))) + self.assertTrue(self._tx(self._torque_msg(sign * (MAX_RT_DELTA + 1)))) class TestSubaruLegacySafety(TestSubaruSafety): diff --git a/tests/safety/test_volkswagen_pq.py b/tests/safety/test_volkswagen_pq.py index 91054084f7debd..dc59218610bca6 100644 --- a/tests/safety/test_volkswagen_pq.py +++ b/tests/safety/test_volkswagen_pq.py @@ -124,16 +124,16 @@ def _gra_neu_msg(self, bit): def test_sample_speed(self): # Stationary - self.safety.safety_rx_hook(self._speed_msg(0)) + self._rx(self._speed_msg(0)) self.assertEqual(0, self.safety.get_volkswagen_moving()) # 1 km/h, just under 0.3 m/s safety grace threshold - self.safety.safety_rx_hook(self._speed_msg(1)) + self._rx(self._speed_msg(1)) self.assertEqual(0, self.safety.get_volkswagen_moving()) # 2 km/h, just over 0.3 m/s safety grace threshold - self.safety.safety_rx_hook(self._speed_msg(2)) + self._rx(self._speed_msg(2)) self.assertEqual(1, self.safety.get_volkswagen_moving()) # 144 km/h, openpilot V_CRUISE_MAX - self.safety.safety_rx_hook(self._speed_msg(144)) + self._rx(self._speed_msg(144)) self.assertEqual(1, self.safety.get_volkswagen_moving()) def test_steer_safety_check(self): @@ -142,36 +142,36 @@ def test_steer_safety_check(self): self.safety.set_controls_allowed(enabled) self._set_prev_torque(t) if abs(t) > MAX_STEER or (not enabled and abs(t) > 0): - self.assertFalse(self.safety.safety_tx_hook(self._hca_1_msg(t))) + self.assertFalse(self._tx(self._hca_1_msg(t))) else: - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(t))) + self.assertTrue(self._tx(self._hca_1_msg(t))) def test_spam_cancel_safety_check(self): BIT_CANCEL = 9 BIT_SET = 16 BIT_RESUME = 17 self.safety.set_controls_allowed(0) - self.assertTrue(self.safety.safety_tx_hook(self._gra_neu_msg(BIT_CANCEL))) - self.assertFalse(self.safety.safety_tx_hook(self._gra_neu_msg(BIT_RESUME))) - self.assertFalse(self.safety.safety_tx_hook(self._gra_neu_msg(BIT_SET))) + self.assertTrue(self._tx(self._gra_neu_msg(BIT_CANCEL))) + self.assertFalse(self._tx(self._gra_neu_msg(BIT_RESUME))) + self.assertFalse(self._tx(self._gra_neu_msg(BIT_SET))) # do not block resume if we are engaged already self.safety.set_controls_allowed(1) - self.assertTrue(self.safety.safety_tx_hook(self._gra_neu_msg(BIT_RESUME))) + self.assertTrue(self._tx(self._gra_neu_msg(BIT_RESUME))) def test_non_realtime_limit_up(self): self.safety.set_volkswagen_torque_driver(0, 0) self.safety.set_controls_allowed(True) self._set_prev_torque(0) - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(MAX_RATE_UP))) + self.assertTrue(self._tx(self._hca_1_msg(MAX_RATE_UP))) self._set_prev_torque(0) - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(-MAX_RATE_UP))) + self.assertTrue(self._tx(self._hca_1_msg(-MAX_RATE_UP))) self._set_prev_torque(0) - self.assertFalse(self.safety.safety_tx_hook(self._hca_1_msg(MAX_RATE_UP + 1))) + self.assertFalse(self._tx(self._hca_1_msg(MAX_RATE_UP + 1))) self.safety.set_controls_allowed(True) self._set_prev_torque(0) - self.assertFalse(self.safety.safety_tx_hook(self._hca_1_msg(-MAX_RATE_UP - 1))) + self.assertFalse(self._tx(self._hca_1_msg(-MAX_RATE_UP - 1))) def test_non_realtime_limit_down(self): self.safety.set_volkswagen_torque_driver(0, 0) @@ -185,10 +185,10 @@ def test_against_torque_driver(self): t *= -sign self.safety.set_volkswagen_torque_driver(t, t) self._set_prev_torque(MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(MAX_STEER * sign))) + self.assertTrue(self._tx(self._hca_1_msg(MAX_STEER * sign))) self.safety.set_volkswagen_torque_driver(DRIVER_TORQUE_ALLOWANCE + 1, DRIVER_TORQUE_ALLOWANCE + 1) - self.assertFalse(self.safety.safety_tx_hook(self._hca_1_msg(-MAX_STEER))) + self.assertFalse(self._tx(self._hca_1_msg(-MAX_STEER))) # spot check some individual cases for sign in [-1, 1]: @@ -197,20 +197,20 @@ def test_against_torque_driver(self): delta = 1 * sign self._set_prev_torque(torque_desired) self.safety.set_volkswagen_torque_driver(-driver_torque, -driver_torque) - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(torque_desired))) + self.assertTrue(self._tx(self._hca_1_msg(torque_desired))) self._set_prev_torque(torque_desired + delta) self.safety.set_volkswagen_torque_driver(-driver_torque, -driver_torque) - self.assertFalse(self.safety.safety_tx_hook(self._hca_1_msg(torque_desired + delta))) + self.assertFalse(self._tx(self._hca_1_msg(torque_desired + delta))) self._set_prev_torque(MAX_STEER * sign) self.safety.set_volkswagen_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg((MAX_STEER - MAX_RATE_DOWN) * sign))) + self.assertTrue(self._tx(self._hca_1_msg((MAX_STEER - MAX_RATE_DOWN) * sign))) self._set_prev_torque(MAX_STEER * sign) self.safety.set_volkswagen_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(0))) + self.assertTrue(self._tx(self._hca_1_msg(0))) self._set_prev_torque(MAX_STEER * sign) self.safety.set_volkswagen_torque_driver(-MAX_STEER * sign, -MAX_STEER * sign) - self.assertFalse(self.safety.safety_tx_hook(self._hca_1_msg((MAX_STEER - MAX_RATE_DOWN + 1) * sign))) + self.assertFalse(self._tx(self._hca_1_msg((MAX_STEER - MAX_RATE_DOWN + 1) * sign))) def test_realtime_limits(self): self.safety.set_controls_allowed(True) @@ -221,35 +221,35 @@ def test_realtime_limits(self): self.safety.set_volkswagen_torque_driver(0, 0) for t in np.arange(0, MAX_RT_DELTA, 1): t *= sign - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(t))) - self.assertFalse(self.safety.safety_tx_hook(self._hca_1_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._hca_1_msg(t))) + self.assertFalse(self._tx(self._hca_1_msg(sign * (MAX_RT_DELTA + 1)))) self._set_prev_torque(0) for t in np.arange(0, MAX_RT_DELTA, 1): t *= sign - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(t))) + self.assertTrue(self._tx(self._hca_1_msg(t))) # Increase timer to update rt_torque_last self.safety.set_timer(RT_INTERVAL + 1) - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(sign * (MAX_RT_DELTA - 1)))) - self.assertTrue(self.safety.safety_tx_hook(self._hca_1_msg(sign * (MAX_RT_DELTA + 1)))) + self.assertTrue(self._tx(self._hca_1_msg(sign * (MAX_RT_DELTA - 1)))) + self.assertTrue(self._tx(self._hca_1_msg(sign * (MAX_RT_DELTA + 1)))) def test_torque_measurements(self): - self.safety.safety_rx_hook(self._lenkhilfe_3_msg(50)) - self.safety.safety_rx_hook(self._lenkhilfe_3_msg(-50)) - self.safety.safety_rx_hook(self._lenkhilfe_3_msg(0)) - self.safety.safety_rx_hook(self._lenkhilfe_3_msg(0)) - self.safety.safety_rx_hook(self._lenkhilfe_3_msg(0)) - self.safety.safety_rx_hook(self._lenkhilfe_3_msg(0)) + self._rx(self._lenkhilfe_3_msg(50)) + self._rx(self._lenkhilfe_3_msg(-50)) + self._rx(self._lenkhilfe_3_msg(0)) + self._rx(self._lenkhilfe_3_msg(0)) + self._rx(self._lenkhilfe_3_msg(0)) + self._rx(self._lenkhilfe_3_msg(0)) self.assertEqual(-50, self.safety.get_volkswagen_torque_driver_min()) self.assertEqual(50, self.safety.get_volkswagen_torque_driver_max()) - self.safety.safety_rx_hook(self._lenkhilfe_3_msg(0)) + self._rx(self._lenkhilfe_3_msg(0)) self.assertEqual(0, self.safety.get_volkswagen_torque_driver_max()) self.assertEqual(-50, self.safety.get_volkswagen_torque_driver_min()) - self.safety.safety_rx_hook(self._lenkhilfe_3_msg(0)) + self._rx(self._lenkhilfe_3_msg(0)) self.assertEqual(0, self.safety.get_volkswagen_torque_driver_max()) self.assertEqual(0, self.safety.get_volkswagen_torque_driver_min()) @@ -262,9 +262,9 @@ def test_rx_hook(self): self.safety.set_controls_allowed(1) if msg == MSG_LENKHILFE_3: to_push = self._lenkhilfe_3_msg(0) - self.assertTrue(self.safety.safety_rx_hook(to_push)) + self.assertTrue(self._rx(to_push)) to_push[0].RDHR ^= 0xFF - self.assertFalse(self.safety.safety_rx_hook(to_push)) + self.assertFalse(self._rx(to_push)) self.assertFalse(self.safety.get_controls_allowed()) # counter @@ -273,15 +273,15 @@ def test_rx_hook(self): self.__class__.cnt_lenkhilfe_3 += 1 if i < MAX_WRONG_COUNTERS: self.safety.set_controls_allowed(1) - self.safety.safety_rx_hook(self._lenkhilfe_3_msg(0)) + self._rx(self._lenkhilfe_3_msg(0)) else: - self.assertFalse(self.safety.safety_rx_hook(self._lenkhilfe_3_msg(0))) + self.assertFalse(self._rx(self._lenkhilfe_3_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.safety.safety_rx_hook(self._lenkhilfe_3_msg(0)) + self._rx(self._lenkhilfe_3_msg(0)) self.assertTrue(self.safety.get_controls_allowed())