some clean up from merge

pull/28641/head
Shane Smiskol 2 years ago
parent 796b4bfc3b
commit 36e519debd
  1. 33
      selfdrive/car/toyota/tests/test_toyota.py
  2. 16
      selfdrive/car/toyota/values.py

@ -16,8 +16,6 @@ from openpilot.selfdrive.car.toyota.values import CAR, DBC, TSS2_CAR, ANGLE_CONT
Ecu = car.CarParams.Ecu
ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()}
ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()}
class TestToyotaInterfaces(unittest.TestCase):
def test_car_sets(self):
@ -52,14 +50,14 @@ class TestToyotaInterfaces(unittest.TestCase):
class TestToyotaFingerprint(unittest.TestCase):
# @settings(max_examples=100)
# @given(data=st.data())
# def test_platform_codes_fuzzy_fw(self, data):
# fw_strategy = st.lists(st.binary())
# fws = data.draw(fw_strategy)
# get_platform_codes(fws)
def test_fw_pattern(self):
@settings(max_examples=100)
@given(data=st.data())
def test_platform_codes_fuzzy_fw(self, data):
fw_strategy = st.lists(st.binary())
fws = data.draw(fw_strategy)
get_platform_codes(fws)
def test_fw_pattern_new(self):
"""Asserts all ECUs can be parsed"""
for car_model, ecus in FW_VERSIONS.items():
for ecu, fws in ecus.items():
@ -198,21 +196,6 @@ class TestToyotaFingerprint(unittest.TestCase):
self.assertEqual(platforms_with_shared_codes, excluded_platforms, (len(platforms_with_shared_codes), len(FW_VERSIONS)))
@settings(max_examples=100)
@given(data=st.data())
def test_platform_codes_fuzzy_fw(self, data):
fw_strategy = st.lists(st.binary())
fws = data.draw(fw_strategy)
get_platform_codes(fws)
def test_fw_pattern(self):
"""Asserts all ECUs can be parsed"""
for ecus in FW_VERSIONS.values():
for fws in ecus.values():
for fw in fws:
ret = get_platform_codes([fw])
self.assertTrue(len(ret))
if __name__ == "__main__":
unittest.main()

@ -250,14 +250,10 @@ def get_platform_codes(fw_versions: List[bytes]) -> Set[Tuple[bytes, Optional[by
fw = fw[1:]
# fw length should be multiple of 16 bytes (per chunk, even if no length code), skip parsing if unexpected length
if length_code * 16 != len(fw):
if length_code * FW_CHUNK_LEN != len(fw):
continue
chunks = [fw[16 * i:16 * i + 16].strip(b'\x00 ') for i in range(length_code)]
# Ensure not all empty bytes
if not len(chunks):
continue
chunks = [fw[FW_CHUNK_LEN * i:FW_CHUNK_LEN * i + FW_CHUNK_LEN].strip(b'\x00 ') for i in range(length_code)]
# only first is considered for now since second is commonly shared (TODO: understand that)
first_chunk = chunks[0]
@ -267,8 +263,8 @@ def get_platform_codes(fw_versions: List[bytes]) -> Set[Tuple[bytes, Optional[by
fw_match = SHORT_FW_PATTERN.search(first_chunk)
if fw_match is not None:
platform, major_version, sub_version = fw_match.groups()
codes.add((b'-'.join((platform, major_version)), sub_version))
# print('platform code, version', platform, major_version, sub_version)
codes.add((platform + b'-' + major_version, sub_version))
elif len(first_chunk) == 10:
# print('medium fw', fw)
@ -276,7 +272,7 @@ def get_platform_codes(fw_versions: List[bytes]) -> Set[Tuple[bytes, Optional[by
if fw_match is not None:
part, platform, major_version, sub_version = fw_match.groups()
# print(part, platform, major_version, sub_version)
codes.add((part + b'-' + platform + b'-' + major_version, sub_version))
codes.add((b'-'.join((part, platform, major_version)), sub_version))
elif len(first_chunk) == 12:
# print(LONG_FW_PATTERN)
@ -286,7 +282,7 @@ def get_platform_codes(fw_versions: List[bytes]) -> Set[Tuple[bytes, Optional[by
# print('got long match!')
part, platform, major_version, sub_version = fw_match.groups()
# print(first_chunk, fw_match, fw_match.groups())
codes.add((part + b'-' + platform + b'-' + major_version, sub_version))
codes.add((b'-'.join((part, platform, major_version)), sub_version))
return codes
@ -437,8 +433,6 @@ FW_QUERY_CONFIG = FwQueryConfig(
match_fw_to_car_fuzzy=match_fw_to_car_fuzzy,
)
# FW_PATTERN = re.compile(b'[0-9]{4}[0-9A-Z][0-9A-Z]')
FW_VERSIONS = {
CAR.AVALON: {
(Ecu.abs, 0x7b0, None): [

Loading…
Cancel
Save