use class inheritance to define test specific safety variables

This commit is contained in:
Shane Smiskol 2022-03-26 00:20:01 -07:00
parent 97e25284ee
commit 734efd96f3
4 changed files with 31 additions and 34 deletions

View File

@ -10,12 +10,14 @@ from panda.tests.safety import libpandasafety_py
MAX_WRONG_COUNTERS = 5 MAX_WRONG_COUNTERS = 5
class ALTERNATIVE_EXPERIENCE: class ALTERNATIVE_EXPERIENCE:
DEFAULT = 0 DEFAULT = 0
DISABLE_DISENGAGE_ON_GAS = 1 DISABLE_DISENGAGE_ON_GAS = 1
DISABLE_STOCK_AEB = 2 DISABLE_STOCK_AEB = 2
RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX = 8 RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX = 8
def package_can_msg(msg): def package_can_msg(msg):
addr, _, dat, bus = msg addr, _, dat, bus = msg
ret = libpandasafety_py.ffi.new('CANPacket_t *') ret = libpandasafety_py.ffi.new('CANPacket_t *')
@ -27,9 +29,11 @@ def package_can_msg(msg):
return ret return ret
def make_msg(bus, addr, length=8): def make_msg(bus, addr, length=8):
return package_can_msg([addr, 0, b'\x00' * length, bus]) return package_can_msg([addr, 0, b'\x00' * length, bus])
class CANPackerPanda(CANPacker): class CANPackerPanda(CANPacker):
def make_can_msg_panda(self, name_or_addr, bus, values, counter=-1, fix_checksum=None): def make_can_msg_panda(self, name_or_addr, bus, values, counter=-1, fix_checksum=None):
msg = self.make_can_msg(name_or_addr, bus, values, counter=-1) msg = self.make_can_msg(name_or_addr, bus, values, counter=-1)
@ -37,13 +41,26 @@ class CANPackerPanda(CANPacker):
msg = fix_checksum(msg) msg = fix_checksum(msg)
return package_can_msg(msg) return package_can_msg(msg)
class PandaSafetyTestBase(unittest.TestCase): class PandaSafetyTestBase(unittest.TestCase):
SAFETY_PARAM = 0
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
if cls.__name__ == "PandaSafetyTestBase": if cls.__name__ == "PandaSafetyTestBase":
cls.safety = None cls.safety = None
raise unittest.SkipTest raise unittest.SkipTest
def setUp(self):
self.packer = CANPackerPanda(self.DBC)
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(self.SAFETY_MODE, self.SAFETY_PARAM)
if 'Honda' in self.__class__.__name__:
self.safety._init_tests_honda()
else:
self.safety.init_tests()
def _rx(self, msg): def _rx(self, msg):
return self.safety.safety_rx_hook(msg) return self.safety.safety_rx_hook(msg)

View File

@ -288,18 +288,15 @@ class TestHondaNidecSafetyBase(HondaBase):
INTERCEPTOR_THRESHOLD = 344 INTERCEPTOR_THRESHOLD = 344
DBC = "honda_civic_touring_2016_can_generated"
SAFETY_MODE = Panda.SAFETY_HONDA_NIDEC
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
if cls.__name__ == "TestHondaNidecSafetyBase": if cls.__name__ == "TestHondaNidecSafetyBase":
cls.safety = None cls.safety = None
raise unittest.SkipTest raise unittest.SkipTest
def setUp(self):
self.packer = CANPackerPanda("honda_civic_touring_2016_can_generated")
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_NIDEC, 0)
self.safety.init_tests_honda()
# Honda gas gains are the different # Honda gas gains are the different
def _interceptor_msg(self, gas, addr): def _interceptor_msg(self, gas, addr):
to_send = make_msg(0, addr, 6) to_send = make_msg(0, addr, 6)
@ -398,11 +395,9 @@ class TestHondaNidecAltSafety(TestHondaNidecSafety):
""" """
Covers the Honda Nidec safety mode with alt SCM messages Covers the Honda Nidec safety mode with alt SCM messages
""" """
def setUp(self):
self.packer = CANPackerPanda("acura_ilx_2016_can_generated") DBC = "acura_ilx_2016_can_generated"
self.safety = libpandasafety_py.libpandasafety SAFETY_PARAM = Panda.FLAG_HONDA_NIDEC_ALT
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_NIDEC, Panda.FLAG_HONDA_NIDEC_ALT)
self.safety.init_tests_honda()
def _acc_state_msg(self, main_on): def _acc_state_msg(self, main_on):
values = {"MAIN_ON": main_on, "COUNTER": self.cnt_acc_state % 4} values = {"MAIN_ON": main_on, "COUNTER": self.cnt_acc_state % 4}
@ -419,11 +414,6 @@ class TestHondaNidecAltInterceptorSafety(TestHondaNidecSafety, common.Intercepto
""" """
Covers the Honda Nidec safety mode with alt SCM messages and gas interceptor Covers the Honda Nidec safety mode with alt SCM messages and gas interceptor
""" """
def setUp(self):
self.packer = CANPackerPanda("acura_ilx_2016_can_generated")
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_NIDEC, Panda.FLAG_HONDA_NIDEC_ALT)
self.safety.init_tests_honda()
def _acc_state_msg(self, main_on): def _acc_state_msg(self, main_on):
values = {"MAIN_ON": main_on, "COUNTER": self.cnt_acc_state % 4} values = {"MAIN_ON": main_on, "COUNTER": self.cnt_acc_state % 4}
@ -447,6 +437,9 @@ class TestHondaBoschSafetyBase(HondaBase):
TX_MSGS = [[0xE4, 0], [0xE5, 0], [0x296, 1], [0x33D, 0], [0x33DA, 0], [0x33DB, 0]] TX_MSGS = [[0xE4, 0], [0xE5, 0], [0x296, 1], [0x33D, 0], [0x33DA, 0], [0x33DB, 0]]
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D, 0x33DA, 0x33DB]} FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D, 0x33DA, 0x33DB]}
DBC = "honda_accord_2018_can_generated"
SAFETY_MODE = Panda.SAFETY_HONDA_BOSCH
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
if cls.__name__ == "TestHondaBoschSafetyBase": if cls.__name__ == "TestHondaBoschSafetyBase":
@ -454,10 +447,6 @@ class TestHondaBoschSafetyBase(HondaBase):
cls.safety = None cls.safety = None
raise unittest.SkipTest raise unittest.SkipTest
def setUp(self):
self.packer = CANPackerPanda("honda_accord_2018_can_generated")
self.safety = libpandasafety_py.libpandasafety
def _alt_brake_msg(self, brake): def _alt_brake_msg(self, brake):
values = {"BRAKE_PRESSED": brake, "COUNTER": self.cnt_brake % 4} values = {"BRAKE_PRESSED": brake, "COUNTER": self.cnt_brake % 4}
self.__class__.cnt_brake += 1 self.__class__.cnt_brake += 1
@ -491,10 +480,6 @@ class TestHondaBoschSafety(HondaPcmEnableBase, TestHondaBoschSafetyBase):
""" """
Covers the Honda Bosch safety mode with stock longitudinal Covers the Honda Bosch safety mode with stock longitudinal
""" """
def setUp(self):
super().setUp()
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH, 0)
self.safety.init_tests_honda()
def test_spam_cancel_safety_check(self): def test_spam_cancel_safety_check(self):
self.safety.set_controls_allowed(0) self.safety.set_controls_allowed(0)
@ -518,10 +503,7 @@ class TestHondaBoschLongSafety(HondaButtonEnableBase, TestHondaBoschSafetyBase):
TX_MSGS = [[0xE4, 1], [0x1DF, 1], [0x1EF, 1], [0x1FA, 1], [0x30C, 1], [0x33D, 1], [0x33DA, 1], [0x33DB, 1], [0x39F, 1], [0x18DAB0F1, 1]] TX_MSGS = [[0xE4, 1], [0x1DF, 1], [0x1EF, 1], [0x1FA, 1], [0x30C, 1], [0x33D, 1], [0x33DA, 1], [0x33DB, 1], [0x39F, 1], [0x18DAB0F1, 1]]
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D, 0x33DA, 0x33DB]} FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D, 0x33DA, 0x33DB]}
def setUp(self): SAFETY_PARAM = Panda.FLAG_HONDA_BOSCH_LONG
super().setUp()
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH, Panda.FLAG_HONDA_BOSCH_LONG)
self.safety.init_tests_honda()
def _send_gas_brake_msg(self, gas, accel): def _send_gas_brake_msg(self, gas, accel):
values = { values = {

View File

@ -33,11 +33,9 @@ class TestToyotaSafety(common.PandaSafetyTest, common.InterceptorSafetyTest,
TORQUE_MEAS_TOLERANCE = 1 # toyota safety adds one to be conversative for rounding TORQUE_MEAS_TOLERANCE = 1 # toyota safety adds one to be conversative for rounding
EPS_SCALE = 0.73 EPS_SCALE = 0.73
def setUp(self): DBC = 'toyota_nodsu_pt_generated'
self.packer = CANPackerPanda("toyota_nodsu_pt_generated") SAFETY_MODE = Panda.SAFETY_TOYOTA
self.safety = libpandasafety_py.libpandasafety SAFETY_PARAM = 73
self.safety.set_safety_hooks(Panda.SAFETY_TOYOTA, 73)
self.safety.init_tests()
def _torque_meas_msg(self, torque): def _torque_meas_msg(self, torque):
values = {"STEER_TORQUE_EPS": (torque/self.EPS_SCALE)} values = {"STEER_TORQUE_EPS": (torque/self.EPS_SCALE)}