Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyundai CAN-FD: more complete tests #1133

Merged
merged 7 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/safety/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def test_tx_hook_on_wrong_safety_mode(self):
continue

# overlapping TX addrs, but they're not actuating messages for either car
if attr == 'TestHyundaiCanfdHDA2Long' and current_test.startswith('TestToyota'):
if attr == 'TestHyundaiCanfdHDA2LongEV' and current_test.startswith('TestToyota'):
tx = list(filter(lambda m: m[0] not in [0x160, ], tx))

# Volkswagen MQB longitudinal actuating message overlaps with the Subaru lateral actuating message
Expand Down
37 changes: 27 additions & 10 deletions tests/safety/test_hyundai_canfd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
from parameterized import parameterized_class
import unittest
from panda import Panda
from panda.tests.safety import libpandasafety_py
Expand Down Expand Up @@ -34,6 +35,7 @@ class TestHyundaiCanfdBase(HyundaiButtonBase, common.PandaSafetyTest, common.Dri
SCC_BUS = 2
STEER_BUS = 0
STEER_MSG = ""
GAS_MSG = ""
BUTTONS_TX_BUS = 1

@classmethod
Expand Down Expand Up @@ -61,7 +63,7 @@ def _user_brake_msg(self, brake):

def _user_gas_msg(self, gas):
values = {"ACCELERATOR_PEDAL": gas}
return self.packer.make_can_msg_panda("ACCELERATOR", self.PT_BUS, values)
return self.packer.make_can_msg_panda(self.GAS_MSG, self.PT_BUS, values)

def _pcm_status_msg(self, enable):
values = {"ACCMode": 1 if enable else 0}
Expand All @@ -77,7 +79,7 @@ def _button_msg(self, buttons, main_button=0, bus=None):
return self.packer.make_can_msg_panda("CRUISE_BUTTONS", bus, values)


class TestHyundaiCanfdHDA1(TestHyundaiCanfdBase):
class TestHyundaiCanfdHDA1Base(TestHyundaiCanfdBase):

TX_MSGS = [[0x12A, 0], [0x1A0, 1], [0x1CF, 0], [0x1E0, 0]]
RELAY_MALFUNCTION_ADDR = 0x12A
Expand All @@ -87,24 +89,37 @@ class TestHyundaiCanfdHDA1(TestHyundaiCanfdBase):

STEER_MSG = "LFA"
BUTTONS_TX_BUS = 2
safety_param: int

@classmethod
def setUpClass(cls):
if cls.__name__ in ("TestHyundaiCanfdHDA1", "TestHyundaiCanfdHDA1AltButtons") or cls.__name__.endswith('Base'):
cls.packer = None
cls.safety = None
raise unittest.SkipTest

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_HYBRID_GAS)
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, self.safety_param)
self.safety.init_tests()

def _user_gas_msg(self, gas):
values = {"ACCELERATOR_PEDAL": gas}
return self.packer.make_can_msg_panda("ACCELERATOR_ALT", self.PT_BUS, values)

@parameterized_class(("GAS_MSG", "safety_param"), [("ACCELERATOR", Panda.FLAG_HYUNDAI_EV_GAS), ("ACCELERATOR_ALT", Panda.FLAG_HYUNDAI_HYBRID_GAS)])
class TestHyundaiCanfdHDA1(TestHyundaiCanfdHDA1Base):
pass


@parameterized_class(("GAS_MSG", "safety_param"), [("ACCELERATOR", Panda.FLAG_HYUNDAI_EV_GAS), ("ACCELERATOR_ALT", Panda.FLAG_HYUNDAI_HYBRID_GAS)])
class TestHyundaiCanfdHDA1AltButtons(TestHyundaiCanfdHDA1Base):

class TestHyundaiCanfdHDA1AltButtons(TestHyundaiCanfdHDA1):
GAS_MSG = "ACCELERATOR"
safety_param: int

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_HYBRID_GAS | Panda.FLAG_HYUNDAI_CANFD_ALT_BUTTONS)
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_ALT_BUTTONS | self.safety_param)
self.safety.init_tests()

def _button_msg(self, buttons, main_button=0, bus=1):
Expand All @@ -124,7 +139,7 @@ def test_button_sends(self):
self.assertFalse(self._tx(self._button_msg(btn)))


class TestHyundaiCanfdHDA2(TestHyundaiCanfdBase):
class TestHyundaiCanfdHDA2EV(TestHyundaiCanfdBase):

TX_MSGS = [[0x50, 0], [0x1CF, 1], [0x2A4, 0]]
RELAY_MALFUNCTION_ADDR = 0x50
Expand All @@ -135,6 +150,7 @@ class TestHyundaiCanfdHDA2(TestHyundaiCanfdBase):
PT_BUS = 1
SCC_BUS = 1
STEER_MSG = "LKAS"
GAS_MSG = "ACCELERATOR"

def setUp(self):
self.packer = CANPackerPanda("hyundai_canfd")
Expand All @@ -143,7 +159,7 @@ def setUp(self):
self.safety.init_tests()


class TestHyundaiCanfdHDA2Long(HyundaiLongitudinalBase, TestHyundaiCanfdHDA2):
class TestHyundaiCanfdHDA2LongEV(HyundaiLongitudinalBase, TestHyundaiCanfdHDA2EV):

TX_MSGS = [[0x50, 0], [0x1CF, 1], [0x2A4, 0], [0x51, 0], [0x730, 1], [0x12a, 1], [0x160, 1],
[0x1e0, 1], [0x1a0, 1], [0x1ea, 1], [0x200, 1], [0x345, 1], [0x1da, 1]]
Expand All @@ -152,6 +168,7 @@ class TestHyundaiCanfdHDA2Long(HyundaiLongitudinalBase, TestHyundaiCanfdHDA2):
DISABLED_ECU_ACTUATION_MSG = (0x1a0, 1)

STEER_MSG = "LFA"
GAS_MSG = "ACCELERATOR"
STEER_BUS = 1

def setUp(self):
Expand Down