Skip to content

Commit 9e3f516

Browse files
tests: add parametrize to test_car_interfaces
1 parent 2bd28e0 commit 9e3f516

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

opendbc/car/tests/test_car_interfaces.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import math
3+
import pytest
34
from collections.abc import Callable
45
from typing import Any
56
from functools import lru_cache
@@ -12,27 +13,39 @@
1213

1314
MAX_EXAMPLES = int(os.environ.get('MAX_EXAMPLES', '15'))
1415

16+
CAR_CHUNK_SIZE = int(os.environ.get('CAR_CHUNK_SIZE', '4'))
17+
CAR_BATCHES = int(os.environ.get('CAR_BATCHES', '128')) # overprovisioned
18+
1519

1620
@lru_cache(maxsize=1)
1721
def _get_all_ecus():
18-
"""Lazy loader for ALL_ECUS"""
19-
from opendbc.car.fingerprints import FW_VERSIONS
20-
from opendbc.car.fw_versions import FW_QUERY_CONFIGS
22+
"""Lazy loader for ALL_ECUS"""
23+
from opendbc.car.fingerprints import FW_VERSIONS
24+
from opendbc.car.fw_versions import FW_QUERY_CONFIGS
2125

22-
all_ecus = {ecu for ecus in FW_VERSIONS.values() for ecu in ecus.keys()}
23-
all_ecus |= {ecu for config in FW_QUERY_CONFIGS.values() for ecu in config.extra_ecus}
24-
return all_ecus
26+
all_ecus = {ecu for ecus in FW_VERSIONS.values() for ecu in ecus.keys()}
27+
all_ecus |= {ecu for config in FW_QUERY_CONFIGS.values() for ecu in config.extra_ecus}
28+
return all_ecus
2529

2630

2731
@lru_cache(maxsize=1)
2832
def _get_all_requests():
29-
"""Lazy loader for ALL_REQUESTS"""
30-
from opendbc.car.fw_versions import FW_QUERY_CONFIGS
31-
return {tuple(r.request) for config in FW_QUERY_CONFIGS.values() for r in config.requests}
33+
"""Lazy loader for ALL_REQUESTS"""
34+
from opendbc.car.fw_versions import FW_QUERY_CONFIGS
35+
return {tuple(r.request) for config in FW_QUERY_CONFIGS.values() for r in config.requests}
36+
37+
38+
@pytest.fixture(scope="session")
39+
def _platform_list():
40+
from opendbc.car.values import PLATFORMS
41+
return sorted(PLATFORMS)
3242

3343

3444
class TestCarInterfaces:
35-
def test_car_interfaces(self, subtests):
45+
_PARAM_RANGE = range(CAR_BATCHES)
46+
47+
@pytest.mark.parametrize("car_batch_idx", _PARAM_RANGE)
48+
def test_car_interfaces(self, car_batch_idx, _platform_list, subtests):
3649
import hypothesis.strategies as st
3750
from hypothesis import Phase, given, settings
3851
from opendbc.car.interfaces import CarInterfaceBase
@@ -137,8 +150,13 @@ def run_car_interface_test(data, car_name: str):
137150
rr = radar_interface.update(cans)
138151
assert rr is None or len(rr.errors) > 0
139152

140-
from opendbc.car.values import PLATFORMS
141-
for car_name in sorted(PLATFORMS):
153+
start = car_batch_idx * CAR_CHUNK_SIZE
154+
end = start + CAR_CHUNK_SIZE
155+
car_batch = _platform_list[start:end]
156+
if not car_batch:
157+
pytest.skip(f"No cars in batch {car_batch_idx}")
158+
159+
for car_name in car_batch:
142160
with subtests.test(car_name=car_name):
143161
run_car_interface_test(car_name=car_name)
144162

0 commit comments

Comments
 (0)