fix car test routes typing (#31773)

* Fix typing

* and fix test_car_model

* fix
pull/31776/head
Justin Newberry 1 year ago committed by GitHub
parent 9cb256891f
commit a919d27afc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      selfdrive/car/tests/routes.py
  2. 25
      selfdrive/car/tests/test_models.py
  3. 6
      tools/car_porting/test_car_model.py

@ -10,6 +10,7 @@ from openpilot.selfdrive.car.nissan.values import CAR as NISSAN
from openpilot.selfdrive.car.mazda.values import CAR as MAZDA from openpilot.selfdrive.car.mazda.values import CAR as MAZDA
from openpilot.selfdrive.car.subaru.values import CAR as SUBARU from openpilot.selfdrive.car.subaru.values import CAR as SUBARU
from openpilot.selfdrive.car.toyota.values import CAR as TOYOTA from openpilot.selfdrive.car.toyota.values import CAR as TOYOTA
from openpilot.selfdrive.car.values import Platform
from openpilot.selfdrive.car.volkswagen.values import CAR as VOLKSWAGEN from openpilot.selfdrive.car.volkswagen.values import CAR as VOLKSWAGEN
from openpilot.selfdrive.car.tesla.values import CAR as TESLA from openpilot.selfdrive.car.tesla.values import CAR as TESLA
from openpilot.selfdrive.car.body.values import CAR as COMMA from openpilot.selfdrive.car.body.values import CAR as COMMA
@ -29,7 +30,7 @@ non_tested_cars = [
class CarTestRoute(NamedTuple): class CarTestRoute(NamedTuple):
route: str route: str
car_model: str | None car_model: Platform | None
segment: int | None = None segment: int | None = None

@ -19,6 +19,7 @@ from openpilot.selfdrive.car.fingerprints import all_known_cars
from openpilot.selfdrive.car.car_helpers import FRAME_FINGERPRINT, interfaces from openpilot.selfdrive.car.car_helpers import FRAME_FINGERPRINT, interfaces
from openpilot.selfdrive.car.honda.values import CAR as HONDA, HondaFlags from openpilot.selfdrive.car.honda.values import CAR as HONDA, HondaFlags
from openpilot.selfdrive.car.tests.routes import non_tested_cars, routes, CarTestRoute from openpilot.selfdrive.car.tests.routes import non_tested_cars, routes, CarTestRoute
from openpilot.selfdrive.car.values import PLATFORMS, Platform
from openpilot.selfdrive.controls.controlsd import Controls from openpilot.selfdrive.controls.controlsd import Controls
from openpilot.selfdrive.test.helpers import read_segment_list from openpilot.selfdrive.test.helpers import read_segment_list
from openpilot.system.hardware.hw import DEFAULT_DOWNLOAD_CACHE_ROOT from openpilot.system.hardware.hw import DEFAULT_DOWNLOAD_CACHE_ROOT
@ -64,7 +65,7 @@ def get_test_cases() -> list[tuple[str, CarTestRoute | None]]:
@pytest.mark.slow @pytest.mark.slow
@pytest.mark.shared_download_cache @pytest.mark.shared_download_cache
class TestCarModelBase(unittest.TestCase): class TestCarModelBase(unittest.TestCase):
car_model: str | None = None platform: Platform | None = None
test_route: CarTestRoute | None = None test_route: CarTestRoute | None = None
test_route_on_bucket: bool = True # whether the route is on the preserved CI bucket test_route_on_bucket: bool = True # whether the route is on the preserved CI bucket
@ -93,8 +94,8 @@ class TestCarModelBase(unittest.TestCase):
car_fw = msg.carParams.carFw car_fw = msg.carParams.carFw
if msg.carParams.openpilotLongitudinalControl: if msg.carParams.openpilotLongitudinalControl:
experimental_long = True experimental_long = True
if cls.car_model is None and not cls.ci: if cls.platform is None and not cls.ci:
cls.car_model = msg.carParams.carFingerprint cls.platform = PLATFORMS.get(msg.carParams.carFingerprint)
# Log which can frame the panda safety mode left ELM327, for CAN validity checks # Log which can frame the panda safety mode left ELM327, for CAN validity checks
elif msg.which() == 'pandaStates': elif msg.which() == 'pandaStates':
@ -155,15 +156,11 @@ class TestCarModelBase(unittest.TestCase):
if cls.__name__ == 'TestCarModel' or cls.__name__.endswith('Base'): if cls.__name__ == 'TestCarModel' or cls.__name__.endswith('Base'):
raise unittest.SkipTest raise unittest.SkipTest
if 'FILTER' in os.environ:
if not cls.car_model.startswith(tuple(os.environ.get('FILTER').split(','))):
raise unittest.SkipTest
if cls.test_route is None: if cls.test_route is None:
if cls.car_model in non_tested_cars: if cls.platform in non_tested_cars:
print(f"Skipping tests for {cls.car_model}: missing route") print(f"Skipping tests for {cls.platform}: missing route")
raise unittest.SkipTest raise unittest.SkipTest
raise Exception(f"missing test route for {cls.car_model}") raise Exception(f"missing test route for {cls.platform}")
car_fw, can_msgs, experimental_long = cls.get_testing_data() car_fw, can_msgs, experimental_long = cls.get_testing_data()
@ -172,10 +169,10 @@ class TestCarModelBase(unittest.TestCase):
cls.can_msgs = sorted(can_msgs, key=lambda msg: msg.logMonoTime) cls.can_msgs = sorted(can_msgs, key=lambda msg: msg.logMonoTime)
cls.CarInterface, cls.CarController, cls.CarState = interfaces[cls.car_model] cls.CarInterface, cls.CarController, cls.CarState = interfaces[cls.platform]
cls.CP = cls.CarInterface.get_params(cls.car_model, cls.fingerprint, car_fw, experimental_long, docs=False) cls.CP = cls.CarInterface.get_params(cls.platform, cls.fingerprint, car_fw, experimental_long, docs=False)
assert cls.CP assert cls.CP
assert cls.CP.carFingerprint == cls.car_model assert cls.CP.carFingerprint == cls.platform
os.environ["COMMA_CACHE"] = DEFAULT_DOWNLOAD_CACHE_ROOT os.environ["COMMA_CACHE"] = DEFAULT_DOWNLOAD_CACHE_ROOT
@ -478,7 +475,7 @@ class TestCarModelBase(unittest.TestCase):
"This is fine to fail for WIP car ports, just let us know and we can upload your routes to the CI bucket.") "This is fine to fail for WIP car ports, just let us know and we can upload your routes to the CI bucket.")
@parameterized_class(('car_model', 'test_route'), get_test_cases()) @parameterized_class(('platform', 'test_route'), get_test_cases())
@pytest.mark.xdist_group_class_property('test_route') @pytest.mark.xdist_group_class_property('test_route')
class TestCarModel(TestCarModelBase): class TestCarModel(TestCarModelBase):
pass pass

@ -5,6 +5,7 @@ import unittest
from openpilot.selfdrive.car.tests.routes import CarTestRoute from openpilot.selfdrive.car.tests.routes import CarTestRoute
from openpilot.selfdrive.car.tests.test_models import TestCarModel from openpilot.selfdrive.car.tests.test_models import TestCarModel
from openpilot.selfdrive.car.values import PLATFORMS
from openpilot.tools.lib.route import SegmentName from openpilot.tools.lib.route import SegmentName
@ -31,7 +32,10 @@ if __name__ == "__main__":
route_or_segment_name = SegmentName(args.route_or_segment_name.strip(), allow_route_name=True) route_or_segment_name = SegmentName(args.route_or_segment_name.strip(), allow_route_name=True)
segment_num = route_or_segment_name.segment_num if route_or_segment_name.segment_num != -1 else None segment_num = route_or_segment_name.segment_num if route_or_segment_name.segment_num != -1 else None
test_route = CarTestRoute(route_or_segment_name.route_name.canonical_name, args.car, segment=segment_num)
platform = PLATFORMS.get(args.car)
test_route = CarTestRoute(route_or_segment_name.route_name.canonical_name, platform, segment=segment_num)
test_suite = create_test_models_suite([test_route], ci=args.ci) test_suite = create_test_models_suite([test_route], ci=args.ci)
unittest.TextTestRunner().run(test_suite) unittest.TextTestRunner().run(test_suite)

Loading…
Cancel
Save