From 2027765bd0618d93684b8e9f8556732827b13774 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Fri, 15 Nov 2019 01:03:34 -0800 Subject: [PATCH] relay malfunction test centralized --- tests/safety/common.py | 4 ++- tests/safety/test_chrysler.py | 32 +++++++++------------- tests/safety/test_honda.py | 46 ++++++++++++++------------------ tests/safety/test_honda_bosch.py | 26 +++++++----------- tests/safety/test_hyundai.py | 32 +++++++++------------- tests/safety/test_subaru.py | 28 ++++++++----------- tests/safety/test_toyota.py | 40 ++++++++++++--------------- tests/safety/test_volkswagen.py | 28 ++++++++----------- 8 files changed, 98 insertions(+), 138 deletions(-) diff --git a/tests/safety/common.py b/tests/safety/common.py index 6759d435b97fad..f3b347a1d512af 100644 --- a/tests/safety/common.py +++ b/tests/safety/common.py @@ -10,10 +10,12 @@ def make_msg(bus, addr, length): def test_relay_malfunction(test, addr): # input is a test class and the address that, if seen on bus 0, triggers - # the relay_malfunction logic + # the relay_malfunction protection logic: both tx_hook and fwd_hook are + # expected to return failure test.assertFalse(test.safety.get_relay_malfunction()) test.safety.safety_rx_hook(make_msg(0, addr, 8)) test.assertTrue(test.safety.get_relay_malfunction()) for a in range(1, 0x800): for b in range(0, 3): test.assertFalse(test.safety.safety_tx_hook(make_msg(b, a, 8))) + test.assertEqual(-1, test.safety.safety_fwd_hook(b, make_msg(b, a, 8))) diff --git a/tests/safety/test_chrysler.py b/tests/safety/test_chrysler.py index fa32c8e7d8d708..0b88eae21b656e 100755 --- a/tests/safety/test_chrysler.py +++ b/tests/safety/test_chrysler.py @@ -179,25 +179,19 @@ def test_torque_measurements(self): def test_fwd_hook(self): buss = list(range(0x0, 0x3)) msgs = list(range(0x1, 0x800)) - relay_malfunction = [0, 1] - - for rm in relay_malfunction: - self.safety.set_relay_malfunction(rm) - blocked_msgs = [658, 678] - for b in buss: - for m in msgs: - if not rm: - if b == 0: - fwd_bus = 2 - elif b == 1: - fwd_bus = -1 - elif b == 2: - fwd_bus = -1 if m in blocked_msgs else 0 - else: - fwd_bus = -1 - - # assume len 8 - self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) + + blocked_msgs = [658, 678] + for b in buss: + for m in msgs: + if b == 0: + fwd_bus = 2 + elif b == 1: + fwd_bus = -1 + elif b == 2: + fwd_bus = -1 if m in blocked_msgs else 0 + + # assume len 8 + self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) if __name__ == "__main__": diff --git a/tests/safety/test_honda.py b/tests/safety/test_honda.py index 0cdb1e1d6d662e..65449a7447a589 100755 --- a/tests/safety/test_honda.py +++ b/tests/safety/test_honda.py @@ -254,36 +254,30 @@ def test_fwd_hook(self): buss = list(range(0x0, 0x3)) msgs = list(range(0x1, 0x800)) long_controls_allowed = [0, 1] - relay_malfunction = [0, 1] fwd_brake = [False, True] self.safety.set_honda_bosch_hardware(0) - for rm in relay_malfunction: - self.safety.set_relay_malfunction(rm) - for f in fwd_brake: - self.safety.set_honda_fwd_brake(f) - for l in long_controls_allowed: - self.safety.set_long_controls_allowed(l) - blocked_msgs = [0xE4, 0x194, 0x33D] - if l: - blocked_msgs += [0x30C, 0x39F] - if not f: - blocked_msgs += [0x1FA] - for b in buss: - for m in msgs: - if not rm: - if b == 0: - fwd_bus = 2 - elif b == 1: - fwd_bus = -1 - elif b == 2: - fwd_bus = -1 if m in blocked_msgs else 0 - else: - fwd_bus = -1 - - # assume len 8 - self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) + for f in fwd_brake: + self.safety.set_honda_fwd_brake(f) + for l in long_controls_allowed: + self.safety.set_long_controls_allowed(l) + blocked_msgs = [0xE4, 0x194, 0x33D] + if l: + blocked_msgs += [0x30C, 0x39F] + if not f: + blocked_msgs += [0x1FA] + for b in buss: + for m in msgs: + if b == 0: + fwd_bus = 2 + elif b == 1: + fwd_bus = -1 + elif b == 2: + fwd_bus = -1 if m in blocked_msgs else 0 + + # assume len 8 + self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) self.safety.set_long_controls_allowed(True) self.safety.set_honda_fwd_brake(False) diff --git a/tests/safety/test_honda_bosch.py b/tests/safety/test_honda_bosch.py index 58299921974a6e..09ef109efd521b 100755 --- a/tests/safety/test_honda_bosch.py +++ b/tests/safety/test_honda_bosch.py @@ -21,25 +21,19 @@ def test_fwd_hook(self): bus_rdr_cam = 2 if has_relay else 1 bus_rdr_car = 0 if has_relay else 2 bus_pt = 1 if has_relay else 0 - relay_malfunction = [0, 1] blocked_msgs = [0xE4, 0x33D] - for rm in relay_malfunction: - self.safety.set_relay_malfunction(rm) - for b in buss: - for m in msgs: - if not rm: - if b == bus_pt: - fwd_bus = -1 - elif b == bus_rdr_cam: - fwd_bus = -1 if m in blocked_msgs else bus_rdr_car - elif b == bus_rdr_car: - fwd_bus = bus_rdr_cam - else: - fwd_bus = -1 + for b in buss: + for m in msgs: + if b == bus_pt: + fwd_bus = -1 + elif b == bus_rdr_cam: + fwd_bus = -1 if m in blocked_msgs else bus_rdr_car + elif b == bus_rdr_car: + fwd_bus = bus_rdr_cam - # assume len 8 - self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) + # assume len 8 + self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) if __name__ == "__main__": diff --git a/tests/safety/test_hyundai.py b/tests/safety/test_hyundai.py index f5cdc7374c0701..d0b57477aea723 100644 --- a/tests/safety/test_hyundai.py +++ b/tests/safety/test_hyundai.py @@ -189,25 +189,19 @@ def test_fwd_hook(self): buss = list(range(0x0, 0x3)) msgs = list(range(0x1, 0x800)) - relay_malfunction = [0, 1] - - for rm in relay_malfunction: - self.safety.set_relay_malfunction(rm) - blocked_msgs = [832] - for b in buss: - for m in msgs: - if not rm: - if b == 0: - fwd_bus = 2 - elif b == 1: - fwd_bus = -1 - elif b == 2: - fwd_bus = -1 if m in blocked_msgs else 0 - else: - fwd_bus = -1 - - # assume len 8 - self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) + + blocked_msgs = [832] + for b in buss: + for m in msgs: + if b == 0: + fwd_bus = 2 + elif b == 1: + fwd_bus = -1 + elif b == 2: + fwd_bus = -1 if m in blocked_msgs else 0 + + # assume len 8 + self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) if __name__ == "__main__": diff --git a/tests/safety/test_subaru.py b/tests/safety/test_subaru.py index 4c2ccb1252cc3e..c7d5be92c25fc4 100644 --- a/tests/safety/test_subaru.py +++ b/tests/safety/test_subaru.py @@ -175,23 +175,17 @@ def test_fwd_hook(self): buss = list(range(0x0, 0x3)) msgs = list(range(0x1, 0x800)) blocked_msgs = [290, 356, 545, 802] - relay_malfunction = [0, 1] - for rm in relay_malfunction: - self.safety.set_relay_malfunction(rm) - for b in buss: - for m in msgs: - if not rm: - if b == 0: - fwd_bus = 2 - elif b == 1: - fwd_bus = -1 - elif b == 2: - fwd_bus = -1 if m in blocked_msgs else 0 - else: - fwd_bus = -1 - - # assume len 8 - self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) + for b in buss: + for m in msgs: + if b == 0: + fwd_bus = 2 + elif b == 1: + fwd_bus = -1 + elif b == 2: + fwd_bus = -1 if m in blocked_msgs else 0 + + # assume len 8 + self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) if __name__ == "__main__": diff --git a/tests/safety/test_toyota.py b/tests/safety/test_toyota.py index 085e5dcb35fa82..2134d82091891e 100644 --- a/tests/safety/test_toyota.py +++ b/tests/safety/test_toyota.py @@ -282,29 +282,23 @@ def test_fwd_hook(self): buss = list(range(0x0, 0x3)) msgs = list(range(0x1, 0x800)) long_controls_allowed = [0, 1] - relay_malfunction = [0, 1] - - for rm in relay_malfunction: - self.safety.set_relay_malfunction(rm) - for lca in long_controls_allowed: - self.safety.set_long_controls_allowed(lca) - blocked_msgs = [0x2E4, 0x412, 0x191] - if lca: - blocked_msgs += [0x343] - for b in buss: - for m in msgs: - if not rm: - if b == 0: - fwd_bus = 2 - elif b == 1: - fwd_bus = -1 - elif b == 2: - fwd_bus = -1 if m in blocked_msgs else 0 - else: - fwd_bus = -1 - - # assume len 8 - self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) + + for lca in long_controls_allowed: + self.safety.set_long_controls_allowed(lca) + blocked_msgs = [0x2E4, 0x412, 0x191] + if lca: + blocked_msgs += [0x343] + for b in buss: + for m in msgs: + if b == 0: + fwd_bus = 2 + elif b == 1: + fwd_bus = -1 + elif b == 2: + fwd_bus = -1 if m in blocked_msgs else 0 + + # assume len 8 + self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) self.safety.set_long_controls_allowed(True) diff --git a/tests/safety/test_volkswagen.py b/tests/safety/test_volkswagen.py index a629af6dfd548e..6e0c14da07703a 100644 --- a/tests/safety/test_volkswagen.py +++ b/tests/safety/test_volkswagen.py @@ -227,23 +227,17 @@ def test_fwd_hook(self): msgs = list(range(0x1, 0x800)) blocked_msgs_0to2 = [] blocked_msgs_2to0 = [0x126, 0x397] - relay_malfunction = [0, 1] - for rm in relay_malfunction: - self.safety.set_relay_malfunction(rm) - for b in buss: - for m in msgs: - if not rm: - if b == 0: - fwd_bus = -1 if m in blocked_msgs_0to2 else 2 - elif b == 1: - fwd_bus = -1 - elif b == 2: - fwd_bus = -1 if m in blocked_msgs_2to0 else 0 - else: - fwd_bus = -1 - - # assume len 8 - self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) + for b in buss: + for m in msgs: + if b == 0: + fwd_bus = -1 if m in blocked_msgs_0to2 else 2 + elif b == 1: + fwd_bus = -1 + elif b == 2: + fwd_bus = -1 if m in blocked_msgs_2to0 else 0 + + # assume len 8 + self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(b, make_msg(b, m, 8))) if __name__ == "__main__":