diff --git a/tests/safety/common.py b/tests/safety/common.py index 70d1f392f..e1723bb29 100644 --- a/tests/safety/common.py +++ b/tests/safety/common.py @@ -916,20 +916,16 @@ class PandaCarSafetyTest(PandaSafetyTest): # each car has an addr that is used to detect relay malfunction # if that addr is seen on specified bus, triggers the relay malfunction # protection logic: both tx_hook and fwd_hook are expected to return failure - self.assertFalse(self.safety.get_relay_malfunction()) - for bus in range(3): - for addr in self.SCANNED_ADDRS: + for relay_malfunction_bus, relay_malfunction_addrs in self.RELAY_MALFUNCTION_ADDRS.items(): + for relay_malfunction_addr in relay_malfunction_addrs: + self.assertFalse(self.safety.get_relay_malfunction()) + self._rx(make_msg(relay_malfunction_bus, relay_malfunction_addr, 8)) + self.assertTrue(self.safety.get_relay_malfunction()) + for bus in range(3): + for addr in self.SCANNED_ADDRS: + self.assertEqual(-1, self._tx(make_msg(bus, addr, 8))) + self.assertEqual(-1, self.safety.safety_fwd_hook(bus, addr)) self.safety.set_relay_malfunction(False) - self._rx(make_msg(bus, addr, 8)) - should_relay_malfunction = addr in self.RELAY_MALFUNCTION_ADDRS.get(bus, ()) - self.assertEqual(should_relay_malfunction, self.safety.get_relay_malfunction(), (bus, addr)) - - # test relay malfunction protection logic - self.safety.set_relay_malfunction(True) - for bus in range(3): - for addr in self.SCANNED_ADDRS: - self.assertEqual(-1, self._tx(make_msg(bus, addr, 8)), (bus, addr)) - self.assertEqual(-1, self.safety.safety_fwd_hook(bus, addr), (bus, addr)) def test_prev_gas(self): self.assertFalse(self.safety.get_gas_pressed_prev())