Skip to content

Commit

Permalink
relay malfunction test centralized
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed Nov 15, 2019
1 parent 8af1a01 commit 2027765
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 138 deletions.
4 changes: 3 additions & 1 deletion tests/safety/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
32 changes: 13 additions & 19 deletions tests/safety/test_chrysler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
46 changes: 20 additions & 26 deletions tests/safety/test_honda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 10 additions & 16 deletions tests/safety/test_honda_bosch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
32 changes: 13 additions & 19 deletions tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
28 changes: 11 additions & 17 deletions tests/safety/test_subaru.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
40 changes: 17 additions & 23 deletions tests/safety/test_toyota.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 11 additions & 17 deletions tests/safety/test_volkswagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 2027765

Please sign in to comment.