Skip to content

Commit 02d155f

Browse files
temp
1 parent 9e3f516 commit 02d155f

File tree

6 files changed

+188
-88
lines changed

6 files changed

+188
-88
lines changed

opendbc/car/ford/tests/test_ford.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import random
22
from collections.abc import Iterable
3-
4-
from hypothesis import settings, given, strategies as st
5-
from parameterized import parameterized
3+
import pytest
64

75
from opendbc.car.structs import CarParams
8-
from opendbc.car.fw_versions import build_fw_dict
9-
from opendbc.car.ford.values import CAR, FW_QUERY_CONFIG, FW_PATTERN, get_platform_codes
10-
from opendbc.car.ford.fingerprints import FW_VERSIONS
116

127
Ecu = CarParams.Ecu
138

@@ -42,39 +37,50 @@
4237

4338
class TestFordFW:
4439
def test_fw_query_config(self):
40+
from opendbc.car.ford.values import FW_QUERY_CONFIG
4541
for (ecu, addr, subaddr) in FW_QUERY_CONFIG.extra_ecus:
4642
assert ecu in ECU_ADDRESSES, "Unknown ECU"
4743
assert addr == ECU_ADDRESSES[ecu], "ECU address mismatch"
4844
assert subaddr is None, "Unexpected ECU subaddress"
4945

50-
@parameterized.expand(FW_VERSIONS.items())
51-
def test_fw_versions(self, car_model: str, fw_versions: dict[tuple[int, int, int | None], Iterable[bytes]]):
52-
for (ecu, addr, subaddr), fws in fw_versions.items():
53-
assert ecu in ECU_PART_NUMBER, "Unexpected ECU"
54-
assert addr == ECU_ADDRESSES[ecu], "ECU address mismatch"
55-
assert subaddr is None, "Unexpected ECU subaddress"
46+
def test_fw_versions(self):
47+
from opendbc.car.ford.values import FW_PATTERN, get_platform_codes
48+
from opendbc.car.ford.fingerprints import FW_VERSIONS
5649

57-
for fw in fws:
58-
assert len(fw) == 24, "Expected ECU response to be 24 bytes"
50+
for car_model, fw_versions in FW_VERSIONS.items():
51+
for (ecu, addr, subaddr), fws in fw_versions.items():
52+
assert ecu in ECU_PART_NUMBER, "Unexpected ECU"
53+
assert addr == ECU_ADDRESSES[ecu], "ECU address mismatch"
54+
assert subaddr is None, "Unexpected ECU subaddress"
5955

60-
match = FW_PATTERN.match(fw)
61-
assert match is not None, f"Unable to parse FW: {fw!r}"
62-
if match:
63-
part_number = match.group("part_number")
64-
assert part_number in ECU_PART_NUMBER[ecu], f"Unexpected part number for {fw!r}"
56+
for fw in fws:
57+
assert len(fw) == 24, "Expected ECU response to be 24 bytes"
6558

66-
codes = get_platform_codes([fw])
67-
assert 1 == len(codes), f"Unable to parse FW: {fw!r}"
59+
match = FW_PATTERN.match(fw)
60+
assert match is not None, f"Unable to parse FW: {fw!r}"
61+
if match:
62+
part_number = match.group("part_number")
63+
assert part_number in ECU_PART_NUMBER[ecu], f"Unexpected part number for {fw!r}"
6864

69-
@settings(max_examples=100)
70-
@given(data=st.data())
71-
def test_platform_codes_fuzzy_fw(self, data):
65+
codes = get_platform_codes([fw])
66+
assert 1 == len(codes), f"Unable to parse FW: {fw!r}"
67+
68+
def test_platform_codes_fuzzy_fw(self):
7269
"""Ensure function doesn't raise an exception"""
73-
fw_strategy = st.lists(st.binary())
74-
fws = data.draw(fw_strategy)
75-
get_platform_codes(fws)
70+
from hypothesis import settings, given, strategies as st
71+
72+
@settings(max_examples=100)
73+
@given(data=st.data())
74+
def _test_impl(data):
75+
from opendbc.car.ford.values import get_platform_codes
76+
fw_strategy = st.lists(st.binary())
77+
fws = data.draw(fw_strategy)
78+
get_platform_codes(fws)
79+
80+
_test_impl()
7681

7782
def test_platform_codes_spot_check(self):
83+
from opendbc.car.ford.values import get_platform_codes
7884
# Asserts basic platform code parsing behavior for a few cases
7985
results = get_platform_codes([
8086
b"JX6A-14C204-BPL\x00\x00\x00\x00\x00\x00\x00\x00\x00",
@@ -85,6 +91,10 @@ def test_platform_codes_spot_check(self):
8591
assert results == {(b"X6A", b"J"), (b"Z6T", b"N"), (b"J6T", b"P"), (b"B5A", b"L")}
8692

8793
def test_fuzzy_match(self):
94+
from opendbc.car.ford.values import FW_QUERY_CONFIG
95+
from opendbc.car.fw_versions import build_fw_dict
96+
from opendbc.car.ford.fingerprints import FW_VERSIONS
97+
8898
for platform, fw_by_addr in FW_VERSIONS.items():
8999
# Ensure there's no overlaps in platform codes
90100
for _ in range(20):
@@ -100,6 +110,7 @@ def test_fuzzy_match(self):
100110
assert matches == {platform}
101111

102112
def test_match_fw_fuzzy(self):
113+
from opendbc.car.ford.values import CAR, FW_QUERY_CONFIG
103114
offline_fw = {
104115
(Ecu.eps, 0x730, None): [
105116
b"L1MC-14D003-AJ\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",

opendbc/car/hyundai/tests/test_hyundai.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
from hypothesis import settings, given, strategies as st
2-
31
import pytest
42

53
from opendbc.car import gen_empty_fingerprint
64
from opendbc.car.structs import CarParams
7-
from opendbc.car.fw_versions import build_fw_dict
8-
from opendbc.car.hyundai.interface import CarInterface
95
from opendbc.car.hyundai.hyundaicanfd import CanBus
10-
from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR
116
from opendbc.car.hyundai.values import CAMERA_SCC_CAR, CANFD_CAR, CAN_GEARS, CAR, CHECKSUM, DATE_FW_ECUS, \
127
HYBRID_CAR, EV_CAR, FW_QUERY_CONFIG, LEGACY_SAFETY_MODE_CAR, CANFD_FUZZY_WHITELIST, \
138
UNSUPPORTED_LONGITUDINAL_CAR, PLATFORM_CODE_ECUS, HYUNDAI_VERSION_REQUEST_LONG, \
149
HyundaiFlags, get_platform_codes, HyundaiSafetyFlags
15-
from opendbc.car.hyundai.fingerprints import FW_VERSIONS
1610

1711
Ecu = CarParams.Ecu
1812

@@ -45,6 +39,8 @@
4539

4640
class TestHyundaiFingerprint:
4741
def test_feature_detection(self):
42+
from opendbc.car.hyundai.interface import CarInterface
43+
from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR
4844
# LKA steering
4945
for lka_steering in (True, False):
5046
fingerprint = gen_empty_fingerprint()
@@ -63,6 +59,8 @@ def test_feature_detection(self):
6359
assert CP.radarUnavailable != radar
6460

6561
def test_alternate_limits(self):
62+
from opendbc.car.hyundai.interface import CarInterface
63+
6664
# Alternate lateral control limits, for high torque cars, verify Panda safety mode flag is set
6765
fingerprint = gen_empty_fingerprint()
6866
for car_model in CAR:
@@ -83,6 +81,8 @@ def test_hybrid_ev_sets(self):
8381
assert CANFD_CAR & HYBRID_CAR == set(), "Hard coding CAN FD cars as hybrid is no longer supported"
8482

8583
def test_canfd_ecu_whitelist(self):
84+
from opendbc.car.hyundai.fingerprints import FW_VERSIONS
85+
8686
# Asserts only expected Ecus can exist in database for CAN-FD cars
8787
for car_model in CANFD_CAR:
8888
ecus = {fw[0] for fw in FW_VERSIONS[car_model].keys()}
@@ -92,6 +92,8 @@ def test_canfd_ecu_whitelist(self):
9292
f"{car_model}: Car model has unexpected ECUs: {ecu_strings}"
9393

9494
def test_blacklisted_parts(self, subtests):
95+
from opendbc.car.hyundai.fingerprints import FW_VERSIONS
96+
9597
# Asserts no ECUs known to be shared across platforms exist in the database.
9698
# Tucson having Santa Cruz camera and EPS for example
9799
for car_model, ecus in FW_VERSIONS.items():
@@ -106,6 +108,8 @@ def test_blacklisted_parts(self, subtests):
106108
assert not part.startswith(b'CW'), "Car has bad part number"
107109

108110
def test_correct_ecu_response_database(self, subtests):
111+
from opendbc.car.hyundai.fingerprints import FW_VERSIONS
112+
109113
"""
110114
Assert standard responses for certain ECUs, since they can
111115
respond to multiple queries with different data
@@ -117,15 +121,22 @@ def test_correct_ecu_response_database(self, subtests):
117121
assert all(fw.startswith(expected_fw_prefix) for fw in fws), \
118122
f"FW from unexpected request in database: {(ecu, fws)}"
119123

120-
@settings(max_examples=100)
121-
@given(data=st.data())
122-
def test_platform_codes_fuzzy_fw(self, data):
124+
def test_platform_codes_fuzzy_fw(self):
125+
from hypothesis import settings, given, strategies as st
126+
123127
"""Ensure function doesn't raise an exception"""
124-
fw_strategy = st.lists(st.binary())
125-
fws = data.draw(fw_strategy)
126-
get_platform_codes(fws)
128+
@settings(max_examples=100)
129+
@given(data=st.data())
130+
def _test_impl(data):
131+
fw_strategy = st.lists(st.binary())
132+
fws = data.draw(fw_strategy)
133+
get_platform_codes(fws)
134+
135+
_test_impl()
127136

128137
def test_expected_platform_codes(self, subtests):
138+
from opendbc.car.hyundai.fingerprints import FW_VERSIONS
139+
129140
# Ensures we don't accidentally add multiple platform codes for a car unless it is intentional
130141
for car_model, ecus in FW_VERSIONS.items():
131142
with subtests.test(car_model=car_model.value):
@@ -145,6 +156,8 @@ def test_expected_platform_codes(self, subtests):
145156
# Tests for platform codes, part numbers, and FW dates which Hyundai will use to fuzzy
146157
# fingerprint in the absence of full FW matches:
147158
def test_platform_code_ecus_available(self, subtests):
159+
from opendbc.car.hyundai.fingerprints import FW_VERSIONS
160+
148161
# TODO: add queries for these non-CAN FD cars to get EPS
149162
no_eps_platforms = CANFD_CAR | {CAR.KIA_SORENTO, CAR.KIA_OPTIMA_G4, CAR.KIA_OPTIMA_G4_FL, CAR.KIA_OPTIMA_H,
150163
CAR.KIA_OPTIMA_H_G4_FL, CAR.HYUNDAI_SONATA_LF, CAR.HYUNDAI_TUCSON, CAR.GENESIS_G90, CAR.GENESIS_G80, CAR.HYUNDAI_ELANTRA}
@@ -160,6 +173,8 @@ def test_platform_code_ecus_available(self, subtests):
160173
assert platform_code_ecu in [e[0] for e in ecus]
161174

162175
def test_fw_format(self, subtests):
176+
from opendbc.car.hyundai.fingerprints import FW_VERSIONS
177+
163178
# Asserts:
164179
# - every supported ECU FW version returns one platform code
165180
# - every supported ECU FW version has a part number
@@ -219,6 +234,9 @@ def test_platform_codes_spot_check(self):
219234
(b"ON-S9100", b"190405"), (b"ON-S9100", b"190720")}
220235

221236
def test_fuzzy_excluded_platforms(self):
237+
from opendbc.car.hyundai.fingerprints import FW_VERSIONS
238+
from opendbc.car.fw_versions import build_fw_dict
239+
222240
# Asserts a list of platforms that will not fuzzy fingerprint with platform codes due to them being shared.
223241
# This list can be shrunk as we combine platforms and detect features
224242
excluded_platforms = {

opendbc/car/toyota/tests/test_toyota.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
from hypothesis import given, settings, strategies as st
2-
31
from opendbc.car import Bus
42
from opendbc.car.structs import CarParams
5-
from opendbc.car.fw_versions import build_fw_dict
6-
from opendbc.car.toyota.fingerprints import FW_VERSIONS
7-
from opendbc.car.toyota.values import CAR, DBC, TSS2_CAR, ANGLE_CONTROL_CAR, RADAR_ACC_CAR, SECOC_CAR, \
8-
FW_QUERY_CONFIG, PLATFORM_CODE_ECUS, FUZZY_EXCLUDED_PLATFORMS, \
9-
get_platform_codes
103

114
Ecu = CarParams.Ecu
125

@@ -18,22 +11,28 @@ def check_fw_version(fw_version: bytes) -> bool:
1811

1912
class TestToyotaInterfaces:
2013
def test_car_sets(self):
14+
from opendbc.car.toyota.values import TSS2_CAR, ANGLE_CONTROL_CAR, RADAR_ACC_CAR
2115
assert len(ANGLE_CONTROL_CAR - TSS2_CAR) == 0
2216
assert len(RADAR_ACC_CAR - TSS2_CAR) == 0
2317

2418
def test_lta_platforms(self):
2519
# At this time, only RAV4 2023 is expected to use LTA/angle control
20+
from opendbc.car.toyota.values import CAR, ANGLE_CONTROL_CAR
2621
assert ANGLE_CONTROL_CAR == {CAR.TOYOTA_RAV4_TSS2_2023}
2722

2823
def test_tss2_dbc(self):
2924
# We make some assumptions about TSS2 platforms,
3025
# like looking up certain signals only in this DBC
26+
from opendbc.car.toyota.values import DBC, TSS2_CAR, SECOC_CAR
3127
for car_model, dbc in DBC.items():
3228
if car_model in TSS2_CAR and car_model not in SECOC_CAR:
3329
assert dbc[Bus.pt] == "toyota_nodsu_pt_generated"
3430

3531
def test_essential_ecus(self, subtests):
3632
# Asserts standard ECUs exist for each platform
33+
from opendbc.car.toyota.values import CAR
34+
from opendbc.car.toyota.fingerprints import FW_VERSIONS
35+
3736
common_ecus = {Ecu.fwdRadar, Ecu.fwdCamera}
3837
for car_model, ecus in FW_VERSIONS.items():
3938
with subtests.test(car_model=car_model.value):
@@ -55,6 +54,9 @@ def test_essential_ecus(self, subtests):
5554
class TestToyotaFingerprint:
5655
def test_non_essential_ecus(self, subtests):
5756
# Ensures only the cars that have multiple engine ECUs are in the engine non-essential ECU list
57+
from opendbc.car.toyota.fingerprints import FW_VERSIONS
58+
from opendbc.car.toyota.values import FW_QUERY_CONFIG
59+
5860
for car_model, ecus in FW_VERSIONS.items():
5961
with subtests.test(car_model=car_model.value):
6062
engine_ecus = {ecu for ecu in ecus if ecu[0] == Ecu.engine}
@@ -63,6 +65,8 @@ def test_non_essential_ecus(self, subtests):
6365

6466
def test_valid_fw_versions(self, subtests):
6567
# Asserts all FW versions are valid
68+
from opendbc.car.toyota.fingerprints import FW_VERSIONS
69+
6670
for car_model, ecus in FW_VERSIONS.items():
6771
with subtests.test(car_model=car_model.value):
6872
for fws in ecus.values():
@@ -71,15 +75,24 @@ def test_valid_fw_versions(self, subtests):
7175

7276
# Tests for part numbers, platform codes, and sub-versions which Toyota will use to fuzzy
7377
# fingerprint in the absence of full FW matches:
74-
@settings(max_examples=100)
75-
@given(data=st.data())
76-
def test_platform_codes_fuzzy_fw(self, data):
77-
fw_strategy = st.lists(st.binary())
78-
fws = data.draw(fw_strategy)
79-
get_platform_codes(fws)
78+
def test_platform_codes_fuzzy_fw(self):
79+
from hypothesis import given, settings, strategies as st
80+
from opendbc.car.toyota.values import get_platform_codes
81+
82+
@settings(max_examples=100)
83+
@given(data=st.data())
84+
def _test_impl(data):
85+
fw_strategy = st.lists(st.binary())
86+
fws = data.draw(fw_strategy)
87+
get_platform_codes(fws)
88+
89+
_test_impl()
8090

8191
def test_platform_code_ecus_available(self, subtests):
8292
# Asserts ECU keys essential for fuzzy fingerprinting are available on all platforms
93+
from opendbc.car.toyota.values import CAR, PLATFORM_CODE_ECUS
94+
from opendbc.car.toyota.fingerprints import FW_VERSIONS
95+
8396
for car_model, ecus in FW_VERSIONS.items():
8497
with subtests.test(car_model=car_model.value):
8598
for platform_code_ecu in PLATFORM_CODE_ECUS:
@@ -94,6 +107,8 @@ def test_fw_format(self, subtests):
94107
# - every supported ECU FW version returns one platform code
95108
# - every supported ECU FW version has a part number
96109
# - expected parsing of ECU sub-versions
110+
from opendbc.car.toyota.values import PLATFORM_CODE_ECUS, get_platform_codes
111+
from opendbc.car.toyota.fingerprints import FW_VERSIONS
97112

98113
for car_model, ecus in FW_VERSIONS.items():
99114
with subtests.test(car_model=car_model.value):
@@ -116,6 +131,8 @@ def test_fw_format(self, subtests):
116131

117132
def test_platform_codes_spot_check(self):
118133
# Asserts basic platform code parsing behavior for a few cases
134+
from opendbc.car.toyota.values import get_platform_codes
135+
119136
results = get_platform_codes([
120137
b"F152607140\x00\x00\x00\x00\x00\x00",
121138
b"F152607171\x00\x00\x00\x00\x00\x00",
@@ -147,6 +164,10 @@ def test_platform_codes_spot_check(self):
147164

148165
def test_fuzzy_excluded_platforms(self):
149166
# Asserts a list of platforms that will not fuzzy fingerprint with platform codes due to them being shared.
167+
from opendbc.car.fw_versions import build_fw_dict
168+
from opendbc.car.toyota.fingerprints import FW_VERSIONS
169+
from opendbc.car.toyota.values import FW_QUERY_CONFIG, FUZZY_EXCLUDED_PLATFORMS
170+
150171
platforms_with_shared_codes = set()
151172
for platform, fw_by_addr in FW_VERSIONS.items():
152173
car_fw = []

0 commit comments

Comments
 (0)