def test_fw_request_ecu_whitelist(self): passed = True brands = set(r.brand for r in REQUESTS) versions = get_interface_attr('FW_VERSIONS') for brand in brands: whitelisted_ecus = [ ecu for r in REQUESTS for ecu in r.whitelist_ecus if r.brand == brand ] brand_ecus = set([ fw[0] for car_fw in versions[brand].values() for fw in car_fw ]) # each ecu in brand's fw versions needs to be whitelisted at least once ecus_not_whitelisted = set(brand_ecus) - set(whitelisted_ecus) if len(whitelisted_ecus) and len(ecus_not_whitelisted): ecu_strings = ", ".join( [f'Ecu.{ECU_NAME[ecu]}' for ecu in ecus_not_whitelisted]) print( f'{brand.title()}: FW query whitelist missing ecus: {ecu_strings}' ) passed = False self.assertTrue( passed, "Not all ecus in FW versions found in query whitelists")
def get_tier_car_info() -> Dict[Tier, List[CarInfo]]: tier_car_info: Dict[Tier, List[CarInfo]] = {tier: [] for tier in Tier} for models in get_interface_attr("CAR_INFO").values(): for model, car_info in models.items(): # Hyundai exception: those with radar have openpilot longitudinal fingerprint = {0: {}, 1: {HKG_RADAR_START_ADDR: 8}, 2: {}, 3: {}} CP = interfaces[model][0].get_params(model, fingerprint=fingerprint, disable_radar=True) if CP.dashcamOnly: continue # A platform can include multiple car models if not isinstance(car_info, list): car_info = (car_info, ) for _car_info in car_info: _car_info.init(CP, non_tested_cars, ALL_FOOTNOTES) tier_car_info[_car_info.tier].append(_car_info) # Sort cars by make and model + year for tier, cars in tier_car_info.items(): tier_car_info[tier] = natsorted(cars, key=lambda car: (car.make + car.model).lower()) return tier_car_info
def get_all_car_info() -> List[CarInfo]: all_car_info: List[CarInfo] = [] footnotes = get_all_footnotes() for model, car_info in get_interface_attr("CAR_INFO", combine_brands=True).items(): # Hyundai exception: those with radar have openpilot longitudinal fingerprint = gen_empty_fingerprint() fingerprint[1] = {HKG_RADAR_START_ADDR: 8} CP = interfaces[model][0].get_params(model, fingerprint=fingerprint, disable_radar=True) if CP.dashcamOnly or car_info is None: continue # A platform can include multiple car models if not isinstance(car_info, list): car_info = (car_info, ) for _car_info in car_info: if not hasattr(_car_info, "row"): _car_info.init(CP, footnotes) all_car_info.append(_car_info) # Sort cars by make and model + year sorted_cars: List[CarInfo] = natsorted(all_car_info, key=lambda car: car.name.lower()) return sorted_cars
def get_all_car_info() -> List[CarInfo]: all_car_info: List[CarInfo] = [] for model, car_info in get_interface_attr("CAR_INFO", combine_brands=True).items(): # Hyundai exception: those with radar have openpilot longitudinal fingerprint = {0: {}, 1: {HKG_RADAR_START_ADDR: 8}, 2: {}, 3: {}} CP = interfaces[model][0].get_params(model, fingerprint=fingerprint, disable_radar=True) if CP.dashcamOnly or car_info is None: continue # A platform can include multiple car models if not isinstance(car_info, list): car_info = (car_info, ) for _car_info in car_info: all_car_info.append( _car_info.init(CP, non_tested_cars, ALL_FOOTNOTES)) # Sort cars by make and model + year sorted_cars: List[CarInfo] = natsorted(all_car_info, key=lambda car: (car.make + car.model).lower()) return sorted_cars
def test_missing_car_info(self): all_car_info_platforms = get_interface_attr( "CAR_INFO", combine_brands=True).keys() for platform in sorted(interfaces.keys()): with self.subTest(platform=platform): self.assertTrue( platform in all_car_info_platforms, "Platform: {} doesn't exist in CarInfo".format(platform))
def test_missing_car_info(self): all_car_info_platforms = [ p for i in get_interface_attr("CAR_INFO").values() for p in i ] for platform in sorted(interfaces.keys()): if platform not in all_car_info_platforms: self.fail( "Platform: {} doesn't exist in CarInfo".format(platform))
def get_all_footnotes() -> Dict[Enum, int]: all_footnotes = [] for _, footnotes in get_interface_attr("Footnote").items(): if footnotes is not None: all_footnotes += footnotes return {fn: idx + 1 for idx, fn in enumerate(all_footnotes)}
#!/usr/bin/env python3 import random import unittest from parameterized import parameterized from cereal import car from selfdrive.car.car_helpers import get_interface_attr, interfaces from selfdrive.car.fingerprints import FW_VERSIONS from selfdrive.car.fw_versions import REQUESTS, match_fw_to_car CarFw = car.CarParams.CarFw Ecu = car.CarParams.Ecu ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()} VERSIONS = get_interface_attr("FW_VERSIONS", ignore_none=True) class TestFwFingerprint(unittest.TestCase): def assertFingerprints(self, candidates, expected): candidates = list(candidates) self.assertEqual(len(candidates), 1, f"got more than one candidate: {candidates}") self.assertEqual(candidates[0], expected) @parameterized.expand([(b, c, e[c]) for b, e in VERSIONS.items() for c in e]) def test_fw_fingerprint(self, brand, car_model, ecus): CP = car.CarParams.new_message() for _ in range(200): fw = [] for ecu, fw_versions in ecus.items(): ecu_name, addr, sub_addr = ecu fw.append({"ecu": ecu_name, "fwVersion": random.choice(fw_versions), 'brand': brand,
def get_all_footnotes() -> Dict[Enum, int]: all_footnotes = [] for footnotes in get_interface_attr("Footnote", ignore_none=True).values(): all_footnotes.extend(footnotes) return {fn: idx + 1 for idx, fn in enumerate(all_footnotes)}