From c29166e94a941eba83b79d0aa1d4f5551fa3d7d0 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Tue, 1 Oct 2024 18:46:02 -0700 Subject: [PATCH 1/7] vm --- tests/safety/test_chrysler.py | 97 ++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 18 deletions(-) diff --git a/tests/safety/test_chrysler.py b/tests/safety/test_chrysler.py index 5bbb6dd103..47d9c25bdc 100755 --- a/tests/safety/test_chrysler.py +++ b/tests/safety/test_chrysler.py @@ -6,29 +6,19 @@ from panda.tests.safety.common import CANPackerPanda -class TestChryslerSafety(common.PandaCarSafetyTest, common.MotorTorqueSteeringSafetyTest): - TX_MSGS = [[0x23B, 0], [0x292, 0], [0x2A6, 0]] +class TestChryslerSafetyBase(common.PandaCarSafetyTest, common.MotorTorqueSteeringSafetyTest): STANDSTILL_THRESHOLD = 0 RELAY_MALFUNCTION_ADDRS = {0: (0x292,)} - FWD_BLACKLISTED_ADDRS = {2: [0x292, 0x2A6]} FWD_BUS_LOOKUP = {0: 2, 2: 0} - MAX_RATE_UP = 3 - MAX_RATE_DOWN = 3 - MAX_TORQUE = 261 MAX_RT_DELTA = 112 RT_INTERVAL = 250000 MAX_TORQUE_ERROR = 80 - LKAS_ACTIVE_VALUE = 1 - - DAS_BUS = 0 - - def setUp(self): - self.packer = CANPackerPanda("chrysler_pacifica_2017_hybrid_generated") - self.safety = libpanda_py.libpanda - self.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, 0) - self.safety.init_tests() + @classmethod + def setUpClass(cls): + if cls.__name__ == "TestChryslerSafetyBase": + raise unittest.SkipTest def _button_msg(self, cancel=False, resume=False): values = {"ACC_Cancel": cancel, "ACC_Resume": resume} @@ -72,8 +62,80 @@ def test_buttons(self): self.assertFalse(self._tx(self._button_msg(cancel=True, resume=True))) self.assertFalse(self._tx(self._button_msg(cancel=False, resume=False))) +class TestChryslerPacificaSafety(TestChryslerSafetyBase): + TX_MSGS = [[0x23B, 0], [0x292, 0], [0x2A6, 0]] + STANDSTILL_THRESHOLD = 0 + RELAY_MALFUNCTION_ADDRS = {0: (0x292,)} + FWD_BLACKLISTED_ADDRS = {2: [0x292, 0x2A6]} + FWD_BUS_LOOKUP = {0: 2, 2: 0} -class TestChryslerRamDTSafety(TestChryslerSafety): + MAX_RATE_UP = 3 + MAX_RATE_DOWN = 3 + MAX_TORQUE = 261 + MAX_RT_DELTA = 112 + + LKAS_ACTIVE_VALUE = 1 + + DAS_BUS = 0 + + def setUp(self): + self.packer = CANPackerPanda("chrysler_pacifica_2017_hybrid_generated") + self.safety = libpanda_py.libpanda + self.safety.set_safety_hooks(Panda.SAFETY_CHRYSLER, 0) + self.safety.init_tests() + + def _speed_msg(self, speed): + values = {"SPEED_LEFT": speed, "SPEED_RIGHT": speed} + return self.packer.make_can_msg_panda("SPEED_1", 0, values) + + # test correctness of lshift and rshift operators for setting vehicle_moving + def test_rx_hook_vehicle_moving(self): + self.assertFalse(self.safety.get_vehicle_moving()) + + # speed_l byte 0 + msg = self._speed_msg(0) + msg[0].data[0] = 15; + self.assertTrue(self._rx(msg)) + self.assertTrue(self.safety.get_vehicle_moving()) + + # speed_l byte 1 + msg = self._speed_msg(0) + msg[0].data[1] = 8; + self.assertTrue(self._rx(msg)) + self.assertFalse(self.safety.get_vehicle_moving()) + + # speed_r byte 2 + msg = self._speed_msg(0) + msg[0].data[2] = 15; + self.assertTrue(self._rx(msg)) + self.assertTrue(self.safety.get_vehicle_moving()) + + # speed_r byte 3 + msg = self._speed_msg(0) + msg[0].data[3] = 8; + self.assertTrue(self._rx(msg)) + self.assertFalse(self.safety.get_vehicle_moving()) + +class TestChryslerRamSafetyBase(TestChryslerSafetyBase): + @classmethod + def setUpClass(cls): + if cls.__name__ == "TestChryslerRamSafetyBase": + raise unittest.SkipTest + + def test_rx_hook_vehicle_moving(self): + self.assertFalse(self.safety.get_vehicle_moving()) + + self.assertTrue(self._rx(self._speed_msg(1))) + self.assertTrue(self.safety.get_vehicle_moving()) + + self.assertTrue(self._rx(self._speed_msg(0))) + self.assertFalse(self.safety.get_vehicle_moving()) + + # test 4th bytes = 1, 5th bytes = 0 + self.assertTrue(self._rx(self._speed_msg(2))) + self.assertTrue(self.safety.get_vehicle_moving()) + +class TestChryslerRamDTSafety(TestChryslerRamSafetyBase): TX_MSGS = [[0xB1, 2], [0xA6, 0], [0xFA, 0]] RELAY_MALFUNCTION_ADDRS = {0: (0xA6,)} FWD_BLACKLISTED_ADDRS = {2: [0xA6, 0xFA]} @@ -96,7 +158,7 @@ def _speed_msg(self, speed): values = {"Vehicle_Speed": speed} return self.packer.make_can_msg_panda("ESP_8", 0, values) -class TestChryslerRamHDSafety(TestChryslerSafety): +class TestChryslerRamHDSafety(TestChryslerRamSafetyBase): TX_MSGS = [[0x275, 0], [0x276, 0], [0x23A, 2]] RELAY_MALFUNCTION_ADDRS = {0: (0x276,)} FWD_BLACKLISTED_ADDRS = {2: [0x275, 0x276]} @@ -120,6 +182,5 @@ def _speed_msg(self, speed): values = {"Vehicle_Speed": speed} return self.packer.make_can_msg_panda("ESP_8", 0, values) - if __name__ == "__main__": unittest.main() From 087f8e3f834efbdbf84b62f7ffe5f90d1464d6d2 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Tue, 1 Oct 2024 19:15:25 -0700 Subject: [PATCH 2/7] fix --- tests/safety/test_chrysler.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/safety/test_chrysler.py b/tests/safety/test_chrysler.py index 47d9c25bdc..ef5ad0a9d6 100755 --- a/tests/safety/test_chrysler.py +++ b/tests/safety/test_chrysler.py @@ -94,25 +94,25 @@ def test_rx_hook_vehicle_moving(self): # speed_l byte 0 msg = self._speed_msg(0) - msg[0].data[0] = 15; + msg[0].data[0] = 15 self.assertTrue(self._rx(msg)) self.assertTrue(self.safety.get_vehicle_moving()) # speed_l byte 1 msg = self._speed_msg(0) - msg[0].data[1] = 8; + msg[0].data[1] = 8 self.assertTrue(self._rx(msg)) self.assertFalse(self.safety.get_vehicle_moving()) # speed_r byte 2 msg = self._speed_msg(0) - msg[0].data[2] = 15; + msg[0].data[2] = 15 self.assertTrue(self._rx(msg)) self.assertTrue(self.safety.get_vehicle_moving()) # speed_r byte 3 msg = self._speed_msg(0) - msg[0].data[3] = 8; + msg[0].data[3] = 8 self.assertTrue(self._rx(msg)) self.assertFalse(self.safety.get_vehicle_moving()) @@ -122,6 +122,7 @@ def setUpClass(cls): if cls.__name__ == "TestChryslerRamSafetyBase": raise unittest.SkipTest + # test correctness of lshift and rshift operators for setting vehicle_moving def test_rx_hook_vehicle_moving(self): self.assertFalse(self.safety.get_vehicle_moving()) From 51e6ce1391f5b3bd33924167084d0623e879c1f6 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Tue, 1 Oct 2024 19:16:12 -0700 Subject: [PATCH 3/7] static --- tests/safety/test_chrysler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/safety/test_chrysler.py b/tests/safety/test_chrysler.py index ef5ad0a9d6..e3922f1773 100755 --- a/tests/safety/test_chrysler.py +++ b/tests/safety/test_chrysler.py @@ -121,7 +121,7 @@ class TestChryslerRamSafetyBase(TestChryslerSafetyBase): def setUpClass(cls): if cls.__name__ == "TestChryslerRamSafetyBase": raise unittest.SkipTest - + # test correctness of lshift and rshift operators for setting vehicle_moving def test_rx_hook_vehicle_moving(self): self.assertFalse(self.safety.get_vehicle_moving()) @@ -183,5 +183,6 @@ def _speed_msg(self, speed): values = {"Vehicle_Speed": speed} return self.packer.make_can_msg_panda("ESP_8", 0, values) + if __name__ == "__main__": unittest.main() From e7a95d8d3de8f15505c83dc85f43027bcddef426 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Wed, 2 Oct 2024 11:08:53 -0700 Subject: [PATCH 4/7] clean --- tests/safety/test_chrysler.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/safety/test_chrysler.py b/tests/safety/test_chrysler.py index e3922f1773..3288c569ea 100755 --- a/tests/safety/test_chrysler.py +++ b/tests/safety/test_chrysler.py @@ -8,7 +8,6 @@ class TestChryslerSafetyBase(common.PandaCarSafetyTest, common.MotorTorqueSteeringSafetyTest): STANDSTILL_THRESHOLD = 0 - RELAY_MALFUNCTION_ADDRS = {0: (0x292,)} FWD_BUS_LOOKUP = {0: 2, 2: 0} MAX_RT_DELTA = 112 @@ -64,15 +63,12 @@ def test_buttons(self): class TestChryslerPacificaSafety(TestChryslerSafetyBase): TX_MSGS = [[0x23B, 0], [0x292, 0], [0x2A6, 0]] - STANDSTILL_THRESHOLD = 0 RELAY_MALFUNCTION_ADDRS = {0: (0x292,)} FWD_BLACKLISTED_ADDRS = {2: [0x292, 0x2A6]} - FWD_BUS_LOOKUP = {0: 2, 2: 0} MAX_RATE_UP = 3 MAX_RATE_DOWN = 3 MAX_TORQUE = 261 - MAX_RT_DELTA = 112 LKAS_ACTIVE_VALUE = 1 From 67cacfa101d2726f5f417c0244da3b98432cfe7e Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Wed, 2 Oct 2024 20:18:22 -0700 Subject: [PATCH 5/7] full coverage --- board/safety/safety_chrysler.h | 8 ++++---- tests/safety/test_chrysler.py | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 631dbecde9..858fc62e69 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -83,12 +83,12 @@ static void chrysler_rx_hook(const CANPacket_t *to_push) { // TODO: use the same message for both // update vehicle moving if ((chrysler_platform != CHRYSLER_PACIFICA) && (bus == 0) && (addr == chrysler_addrs->ESP_8)) { - vehicle_moving = ((GET_BYTE(to_push, 4) << 8) + GET_BYTE(to_push, 5)) != 0U; + vehicle_moving = (GET_BYTE(to_push, 4) != 0) || (GET_BYTE(to_push, 5) != 0U); } if ((chrysler_platform == CHRYSLER_PACIFICA) && (bus == 0) && (addr == 514)) { - int speed_l = (GET_BYTE(to_push, 0) << 4) + (GET_BYTE(to_push, 1) >> 4); - int speed_r = (GET_BYTE(to_push, 2) << 4) + (GET_BYTE(to_push, 3) >> 4); - vehicle_moving = (speed_l != 0) || (speed_r != 0); + bool speed_l = ((GET_BYTE(to_push, 0) << 4) != 0) || ((GET_BYTE(to_push, 1) >> 4) != 0); + bool speed_r = ((GET_BYTE(to_push, 2) << 4) != 0) || ((GET_BYTE(to_push, 3) >> 4) != 0); + vehicle_moving = speed_l || speed_r; } // exit controls on rising edge of gas press diff --git a/tests/safety/test_chrysler.py b/tests/safety/test_chrysler.py index 3288c569ea..473501a66a 100755 --- a/tests/safety/test_chrysler.py +++ b/tests/safety/test_chrysler.py @@ -84,7 +84,6 @@ def _speed_msg(self, speed): values = {"SPEED_LEFT": speed, "SPEED_RIGHT": speed} return self.packer.make_can_msg_panda("SPEED_1", 0, values) - # test correctness of lshift and rshift operators for setting vehicle_moving def test_rx_hook_vehicle_moving(self): self.assertFalse(self.safety.get_vehicle_moving()) @@ -118,20 +117,25 @@ def setUpClass(cls): if cls.__name__ == "TestChryslerRamSafetyBase": raise unittest.SkipTest - # test correctness of lshift and rshift operators for setting vehicle_moving def test_rx_hook_vehicle_moving(self): self.assertFalse(self.safety.get_vehicle_moving()) - self.assertTrue(self._rx(self._speed_msg(1))) - self.assertTrue(self.safety.get_vehicle_moving()) - + # test 4th bytes = 0, 5th bytes = 0 self.assertTrue(self._rx(self._speed_msg(0))) self.assertFalse(self.safety.get_vehicle_moving()) + # test 4th bytes = 0, 5th bytes = 128 + self.assertTrue(self._rx(self._speed_msg(1))) + self.assertTrue(self.safety.get_vehicle_moving()) + # test 4th bytes = 1, 5th bytes = 0 self.assertTrue(self._rx(self._speed_msg(2))) self.assertTrue(self.safety.get_vehicle_moving()) + # test 4th bytes = 1, 5th bytes = 128 + self.assertTrue(self._rx(self._speed_msg(3))) + self.assertTrue(self.safety.get_vehicle_moving()) + class TestChryslerRamDTSafety(TestChryslerRamSafetyBase): TX_MSGS = [[0xB1, 2], [0xA6, 0], [0xFA, 0]] RELAY_MALFUNCTION_ADDRS = {0: (0xA6,)} From b2850cc6e0106df2e99ca80ab18028174eadd9cd Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Wed, 2 Oct 2024 20:21:46 -0700 Subject: [PATCH 6/7] u --- board/safety/safety_chrysler.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 858fc62e69..02e87fd0f1 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -83,11 +83,11 @@ static void chrysler_rx_hook(const CANPacket_t *to_push) { // TODO: use the same message for both // update vehicle moving if ((chrysler_platform != CHRYSLER_PACIFICA) && (bus == 0) && (addr == chrysler_addrs->ESP_8)) { - vehicle_moving = (GET_BYTE(to_push, 4) != 0) || (GET_BYTE(to_push, 5) != 0U); + vehicle_moving = (GET_BYTE(to_push, 4) != 0U) || (GET_BYTE(to_push, 5) != 0U); } if ((chrysler_platform == CHRYSLER_PACIFICA) && (bus == 0) && (addr == 514)) { - bool speed_l = ((GET_BYTE(to_push, 0) << 4) != 0) || ((GET_BYTE(to_push, 1) >> 4) != 0); - bool speed_r = ((GET_BYTE(to_push, 2) << 4) != 0) || ((GET_BYTE(to_push, 3) >> 4) != 0); + bool speed_l = ((GET_BYTE(to_push, 0) << 4) != 0U) || ((GET_BYTE(to_push, 1) >> 4) != 0U); + bool speed_r = ((GET_BYTE(to_push, 2) << 4) != 0U) || ((GET_BYTE(to_push, 3) >> 4) != 0U); vehicle_moving = speed_l || speed_r; } From 3c98cda5bbb3149b50edc464ea20f8a43ea62ac4 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Wed, 2 Oct 2024 21:47:47 -0700 Subject: [PATCH 7/7] rename --- board/safety/safety_chrysler.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 02e87fd0f1..42ad0df7e4 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -86,9 +86,9 @@ static void chrysler_rx_hook(const CANPacket_t *to_push) { vehicle_moving = (GET_BYTE(to_push, 4) != 0U) || (GET_BYTE(to_push, 5) != 0U); } if ((chrysler_platform == CHRYSLER_PACIFICA) && (bus == 0) && (addr == 514)) { - bool speed_l = ((GET_BYTE(to_push, 0) << 4) != 0U) || ((GET_BYTE(to_push, 1) >> 4) != 0U); - bool speed_r = ((GET_BYTE(to_push, 2) << 4) != 0U) || ((GET_BYTE(to_push, 3) >> 4) != 0U); - vehicle_moving = speed_l || speed_r; + bool speed_l_non_zero = ((GET_BYTE(to_push, 0) << 4) != 0U) || ((GET_BYTE(to_push, 1) >> 4) != 0U); + bool speed_r_non_zero = ((GET_BYTE(to_push, 2) << 4) != 0U) || ((GET_BYTE(to_push, 3) >> 4) != 0U); + vehicle_moving = speed_l_non_zero || speed_r_non_zero; } // exit controls on rising edge of gas press