panda/tests/safety/common.py

28 lines
1.0 KiB
Python
Raw Normal View History

2019-11-15 01:52:34 -07:00
from panda.tests.safety import libpandasafety_py
def make_msg(bus, addr, length):
to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
to_send[0].RIR = addr << 21
to_send[0].RDTR = length
to_send[0].RDTR = bus << 4
return to_send
def test_relay_malfunction(test, addr):
# input is a test class and the address that, if seen on bus 0, triggers
2019-11-15 02:03:34 -07:00
# the relay_malfunction protection logic: both tx_hook and fwd_hook are
# expected to return failure
test.assertFalse(test.safety.get_relay_malfunction())
2019-11-15 01:52:34 -07:00
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):
2019-11-15 01:52:34 -07:00
test.assertFalse(test.safety.safety_tx_hook(make_msg(b, a, 8)))
2019-11-15 02:03:34 -07:00
test.assertEqual(-1, test.safety.safety_fwd_hook(b, make_msg(b, a, 8)))
2019-11-15 02:12:54 -07:00
def test_manually_enable_controls_allowed(test):
test.safety.set_controls_allowed(1)
test.assertTrue(test.safety.get_controls_allowed())
test.safety.set_controls_allowed(0)
test.assertFalse(test.safety.get_controls_allowed())