FW tests: use subtests (#25598)

Use subtests for FW tests

Use subtests for FW tests
old-commit-hash: a548e1b909
taco
Shane Smiskol 3 years ago committed by GitHub
parent a2d87101c7
commit 3a077f081a
  1. 48
      selfdrive/car/tests/test_fw_fingerprint.py

@ -37,44 +37,34 @@ class TestFwFingerprint(unittest.TestCase):
self.assertFingerprints(matches, car_model)
def test_no_duplicate_fw_versions(self):
passed = True
for car_model, ecus in FW_VERSIONS.items():
for ecu, ecu_fw in ecus.items():
duplicates = {fw for fw in ecu_fw if ecu_fw.count(fw) > 1}
if len(duplicates):
print(car_model, ECU_NAME[ecu[0]], duplicates)
passed = False
self.assertTrue(passed, "Duplicate FW versions found")
with self.subTest(car_model=car_model):
for ecu, ecu_fw in ecus.items():
with self.subTest(ecu):
duplicates = {fw for fw in ecu_fw if ecu_fw.count(fw) > 1}
self.assertFalse(len(duplicates), f"{car_model}: Duplicate FW versions: Ecu.{ECU_NAME[ecu[0]]}, {duplicates}")
def test_blacklisted_ecus(self):
passed = True
blacklisted_addrs = (0x7c4, 0x7d0) # includes A/C ecu and an unknown ecu
for car_model, ecus in FW_VERSIONS.items():
CP = interfaces[car_model][0].get_params(car_model)
if CP.carName == 'subaru':
for ecu in ecus.keys():
if ecu[1] in blacklisted_addrs:
print(f'{car_model}: Blacklisted ecu: (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])})')
passed = False
self.assertTrue(passed, "Blacklisted FW versions found")
with self.subTest(car_model=car_model):
CP = interfaces[car_model][0].get_params(car_model)
if CP.carName == 'subaru':
for ecu in ecus.keys():
self.assertNotIn(ecu[1], blacklisted_addrs, f'{car_model}: Blacklisted ecu: (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])})')
def test_fw_request_ecu_whitelist(self):
passed = True
brands = set(r.brand for r in REQUESTS)
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])
for brand in set(r.brand for r in REQUESTS):
with self.subTest(brand=brand):
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
# each ecu in brand's fw versions needs to be whitelisted at least once
ecus_not_whitelisted = set(brand_ecus) - set(whitelisted_ecus)
self.assertTrue(passed, "Not all ecus in FW versions found in query whitelists")
ecu_strings = ", ".join([f'Ecu.{ECU_NAME[ecu]}' for ecu in ecus_not_whitelisted])
self.assertFalse(len(whitelisted_ecus) and len(ecus_not_whitelisted),
f'{brand.title()}: FW query whitelist missing ecus: {ecu_strings}')
if __name__ == "__main__":

Loading…
Cancel
Save