Skip to content

Commit

Permalink
Add tests for ALT_BUTTONS w/ HDA2
Browse files Browse the repository at this point in the history
  • Loading branch information
ccdunder committed Dec 16, 2024
1 parent f254bbe commit de50eea
Showing 1 changed file with 86 additions and 103 deletions.
189 changes: 86 additions & 103 deletions tests/safety/test_hyundai_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class TestHyundaiCanfdBase(HyundaiButtonBase, common.PandaCarSafetyTest, common.DriverTorqueSteeringSafetyTest, common.SteerRequestCutSafetyTest):

SAFETY_PARAM = 0
TX_MSGS = [[0x50, 0], [0x1CF, 1], [0x2A4, 0]]
STANDSTILL_THRESHOLD = 12 # 0.375 kph
FWD_BLACKLISTED_ADDRS = {2: [0x50, 0x2a4]}
Expand Down Expand Up @@ -45,6 +45,12 @@ def setUpClass(cls):
cls.safety = None
raise unittest.SkipTest

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, self.SAFETY_PARAM)
self.safety.init_tests()

def _torque_driver_msg(self, torque):
values = {"STEERING_COL_TORQUE": torque}
return self.packer.make_can_msg_panda("MDPS", self.PT_BUS, values)
Expand Down Expand Up @@ -79,6 +85,29 @@ def _button_msg(self, buttons, main_button=0, bus=None):
return self.packer.make_can_msg_panda("CRUISE_BUTTONS", bus, values)


class HyundaiCanfdAltButtonsMixin:
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.SAFETY_PARAM |= Panda.FLAG_HYUNDAI_CANFD_ALT_BUTTONS

def _button_msg(self, buttons, main_button=0, bus=1):
values = {
"CRUISE_BUTTONS": buttons,
"ADAPTIVE_CRUISE_MAIN_BTN": main_button,
}
return self.packer.make_can_msg_panda("CRUISE_BUTTONS_ALT", self.PT_BUS, values)

def test_button_sends(self):
"""
No button send allowed with alt buttons.
"""
for enabled in (True, False):
for btn in range(8):
self.safety.set_controls_allowed(enabled)
self.assertFalse(self._tx(self._button_msg(btn)))


class TestHyundaiCanfdHDA1Base(TestHyundaiCanfdBase):

TX_MSGS = [[0x12A, 0], [0x1A0, 1], [0x1CF, 0], [0x1E0, 0]]
Expand All @@ -88,7 +117,6 @@ class TestHyundaiCanfdHDA1Base(TestHyundaiCanfdBase):

STEER_MSG = "LFA"
BUTTONS_TX_BUS = 2
SAFETY_PARAM: int

@classmethod
def setUpClass(cls):
Expand All @@ -98,12 +126,6 @@ def setUpClass(cls):
cls.safety = None
raise unittest.SkipTest

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, self.SAFETY_PARAM)
self.safety.init_tests()


@parameterized_class([
# Radar SCC, test with long flag to ensure flag is not respected until it is supported
Expand All @@ -129,71 +151,81 @@ class TestHyundaiCanfdHDA1(TestHyundaiCanfdHDA1Base):
{"GAS_MSG": ("ACCELERATOR", "ACCELERATOR_PEDAL"), "SCC_BUS": 2, "SAFETY_PARAM": Panda.FLAG_HYUNDAI_EV_GAS | Panda.FLAG_HYUNDAI_CAMERA_SCC},
{"GAS_MSG": ("ACCELERATOR_ALT", "ACCELERATOR_PEDAL"), "SCC_BUS": 2, "SAFETY_PARAM": Panda.FLAG_HYUNDAI_HYBRID_GAS | Panda.FLAG_HYUNDAI_CAMERA_SCC},
])
class TestHyundaiCanfdHDA1AltButtons(TestHyundaiCanfdHDA1Base):
class TestHyundaiCanfdHDA1AltButtons(HyundaiCanfdAltButtonsMixin, TestHyundaiCanfdHDA1Base):
pass

SAFETY_PARAM: int

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_ALT_BUTTONS | self.SAFETY_PARAM)
self.safety.init_tests()
# Tests HDA1 longitudinal for ICE, hybrid, EV
@parameterized_class([
# Camera SCC is the only supported configuration for HDA1 longitudinal, TODO: allow radar SCC
{"GAS_MSG": ("ACCELERATOR_BRAKE_ALT", "ACCELERATOR_PEDAL_PRESSED"), "SAFETY_PARAM": Panda.FLAG_HYUNDAI_LONG},
{"GAS_MSG": ("ACCELERATOR", "ACCELERATOR_PEDAL"), "SAFETY_PARAM": Panda.FLAG_HYUNDAI_LONG | Panda.FLAG_HYUNDAI_EV_GAS},
{"GAS_MSG": ("ACCELERATOR_ALT", "ACCELERATOR_PEDAL"), "SAFETY_PARAM": Panda.FLAG_HYUNDAI_LONG | Panda.FLAG_HYUNDAI_HYBRID_GAS},
])
class TestHyundaiCanfdHDA1Long(HyundaiLongitudinalBase, TestHyundaiCanfdHDA1Base):

def _button_msg(self, buttons, main_button=0, bus=1):
FWD_BLACKLISTED_ADDRS = {2: [0x12a, 0x1e0, 0x1a0]}

RELAY_MALFUNCTION_ADDRS = {0: (0x12A, 0x1a0)} # LFA, SCC_CONTROL

DISABLED_ECU_UDS_MSG = (0x730, 1)
DISABLED_ECU_ACTUATION_MSG = (0x1a0, 0)

STEER_MSG = "LFA"
STEER_BUS = 0
SCC_BUS = 2

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.SAFETY_PARAM |= Panda.FLAG_HYUNDAI_CAMERA_SCC
if cls.__name__ == "TestHyundaiCanfdHDA1Long":
cls.safety = None
raise unittest.SkipTest

def _accel_msg(self, accel, aeb_req=False, aeb_decel=0):
values = {
"CRUISE_BUTTONS": buttons,
"ADAPTIVE_CRUISE_MAIN_BTN": main_button,
"aReqRaw": accel,
"aReqValue": accel,
}
return self.packer.make_can_msg_panda("CRUISE_BUTTONS_ALT", self.PT_BUS, values)
return self.packer.make_can_msg_panda("SCC_CONTROL", 0, values)

def test_button_sends(self):
"""
No button send allowed with alt buttons.
"""
for enabled in (True, False):
for btn in range(8):
self.safety.set_controls_allowed(enabled)
self.assertFalse(self._tx(self._button_msg(btn)))
# no knockout
def test_tester_present_allowed(self):
pass


class TestHyundaiCanfdHDA2EV(TestHyundaiCanfdBase):
# ********************* HDA2 **********************

TX_MSGS = [[0x50, 0], [0x1CF, 1], [0x2A4, 0]]
RELAY_MALFUNCTION_ADDRS = {0: (0x50,)} # LKAS
FWD_BLACKLISTED_ADDRS = {2: [0x50, 0x2a4]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}

class TestHyundaiCanfdHDA2EVBase(TestHyundaiCanfdBase):
PT_BUS = 1
SCC_BUS = 1
STEER_MSG = "LKAS"
GAS_MSG = ("ACCELERATOR", "ACCELERATOR_PEDAL")
FWD_BUS_LOOKUP = {0: 2, 2: 0}

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_EV_GAS)
self.safety.init_tests()

class TestHyundaiCanfdHDA2EV(TestHyundaiCanfdHDA2EVBase):
TX_MSGS = [[0x50, 0], [0x1CF, 1], [0x2A4, 0]]
RELAY_MALFUNCTION_ADDRS = {0: (0x50,)}
FWD_BLACKLISTED_ADDRS = {2: [0x50, 0x2a4]}
STEER_MSG = "LKAS"
SAFETY_PARAM = Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_EV_GAS

# TODO: Handle ICE and HEV configurations once we see cars that use the new messages
class TestHyundaiCanfdHDA2EVAltSteering(TestHyundaiCanfdBase):

class TestHyundaiCanfdHDA2EVAltSteering(TestHyundaiCanfdHDA2EVBase):
TX_MSGS = [[0x110, 0], [0x1CF, 1], [0x362, 0]]
RELAY_MALFUNCTION_ADDRS = {0: (0x110,)} # LKAS_ALT
RELAY_MALFUNCTION_ADDRS = {0: (0x110,)}
FWD_BLACKLISTED_ADDRS = {2: [0x110, 0x362]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}

PT_BUS = 1
SCC_BUS = 1
STEER_MSG = "LKAS_ALT"
GAS_MSG = ("ACCELERATOR", "ACCELERATOR_PEDAL")
SAFETY_PARAM = Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_EV_GAS | Panda.FLAG_HYUNDAI_CANFD_HDA2_ALT_STEERING

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_EV_GAS |
Panda.FLAG_HYUNDAI_CANFD_HDA2_ALT_STEERING)
self.safety.init_tests()

class TestHyundaiCanfdHDA2EVAltButtons(HyundaiCanfdAltButtonsMixin, TestHyundaiCanfdHDA2EV):
pass

class TestHyundaiCanfdHDA2EVAltSteeringAltButtons(HyundaiCanfdAltButtonsMixin, TestHyundaiCanfdHDA2EVAltSteering):
pass


class TestHyundaiCanfdHDA2LongEV(HyundaiLongitudinalBase, TestHyundaiCanfdHDA2EV):
Expand All @@ -209,12 +241,7 @@ class TestHyundaiCanfdHDA2LongEV(HyundaiLongitudinalBase, TestHyundaiCanfdHDA2EV
STEER_MSG = "LFA"
GAS_MSG = ("ACCELERATOR", "ACCELERATOR_PEDAL")
STEER_BUS = 1

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_LONG | Panda.FLAG_HYUNDAI_EV_GAS)
self.safety.init_tests()
SAFETY_PARAM = Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_LONG | Panda.FLAG_HYUNDAI_EV_GAS

def _accel_msg(self, accel, aeb_req=False, aeb_decel=0):
values = {
Expand All @@ -224,49 +251,5 @@ def _accel_msg(self, accel, aeb_req=False, aeb_decel=0):
return self.packer.make_can_msg_panda("SCC_CONTROL", 1, values)


# Tests HDA1 longitudinal for ICE, hybrid, EV
@parameterized_class([
# Camera SCC is the only supported configuration for HDA1 longitudinal, TODO: allow radar SCC
{"GAS_MSG": ("ACCELERATOR_BRAKE_ALT", "ACCELERATOR_PEDAL_PRESSED"), "SAFETY_PARAM": Panda.FLAG_HYUNDAI_LONG},
{"GAS_MSG": ("ACCELERATOR", "ACCELERATOR_PEDAL"), "SAFETY_PARAM": Panda.FLAG_HYUNDAI_LONG | Panda.FLAG_HYUNDAI_EV_GAS},
{"GAS_MSG": ("ACCELERATOR_ALT", "ACCELERATOR_PEDAL"), "SAFETY_PARAM": Panda.FLAG_HYUNDAI_LONG | Panda.FLAG_HYUNDAI_HYBRID_GAS},
])
class TestHyundaiCanfdHDA1Long(HyundaiLongitudinalBase, TestHyundaiCanfdHDA1Base):

FWD_BLACKLISTED_ADDRS = {2: [0x12a, 0x1e0, 0x1a0]}

RELAY_MALFUNCTION_ADDRS = {0: (0x12A, 0x1a0)} # LFA, SCC_CONTROL

DISABLED_ECU_UDS_MSG = (0x730, 1)
DISABLED_ECU_ACTUATION_MSG = (0x1a0, 0)

STEER_MSG = "LFA"
STEER_BUS = 0
SCC_BUS = 2

@classmethod
def setUpClass(cls):
if cls.__name__ == "TestHyundaiCanfdHDA1Long":
cls.safety = None
raise unittest.SkipTest

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpanda_py.libpanda
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CAMERA_SCC | self.SAFETY_PARAM)
self.safety.init_tests()

def _accel_msg(self, accel, aeb_req=False, aeb_decel=0):
values = {
"aReqRaw": accel,
"aReqValue": accel,
}
return self.packer.make_can_msg_panda("SCC_CONTROL", 0, values)

# no knockout
def test_tester_present_allowed(self):
pass


if __name__ == "__main__":
unittest.main()
unittest.main()

0 comments on commit de50eea

Please sign in to comment.