From 67cacfa101d2726f5f417c0244da3b98432cfe7e Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Wed, 2 Oct 2024 20:18:22 -0700 Subject: [PATCH] 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,)}