diff --git a/selfdrive/car/tests/test_fw_fingerprint.py b/selfdrive/car/tests/test_fw_fingerprint.py index e9f23145cd..54f27479d8 100755 --- a/selfdrive/car/tests/test_fw_fingerprint.py +++ b/selfdrive/car/tests/test_fw_fingerprint.py @@ -7,13 +7,12 @@ 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 FW_QUERY_CONFIGS, match_fw_to_car +from selfdrive.car.fw_versions import FW_QUERY_CONFIGS, VERSIONS, 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): diff --git a/selfdrive/car/tests/test_fw_fingerprint_metrics.py b/selfdrive/car/tests/test_fw_fingerprint_metrics.py new file mode 100755 index 0000000000..67c1438724 --- /dev/null +++ b/selfdrive/car/tests/test_fw_fingerprint_metrics.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +import random +import unittest +from collections import defaultdict +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 FW_QUERY_CONFIGS, VERSIONS, match_fw_to_car + +CarFw = car.CarParams.CarFw +Ecu = car.CarParams.Ecu + +ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()} + + +class TestFwFingerprint(unittest.TestCase): + # TODO: test multiple pandas + @parameterized.expand([(1,), (2,)]) + def test_fw_query_metrics(self, num_pandas): + for brand, config in FW_QUERY_CONFIGS.items(): + with self.subTest(brand=brand, num_pandas=num_pandas): + requests = [r for r in config.requests if r.bus <= num_pandas * 4 - 1] + multi_panda_requests = [r for r in config.requests if r.bus > 3] + + if not len(multi_panda_requests) and num_pandas > 1: + raise unittest.SkipTest("No multi-panda FW queries") + + total_time = 0 + obd_multiplexing = config.requests[0].obd_multiplexing # only count OBD multiplexing transitions + for r in requests: + total_time += 0.1 + + if r.obd_multiplexing != obd_multiplexing and r.bus % 4 == 1: + obd_multiplexing = r.obd_multiplexing + total_time += 0.1 + + total_time = round(total_time, 2) + self.assertLessEqual(total_time, 1.1) + print(f'{brand=}, {num_pandas=}, {len(requests)=}, total FW query time={total_time} seconds') + + +if __name__ == "__main__": + unittest.main() diff --git a/selfdrive/debug/test_fw_query_on_routes.py b/selfdrive/debug/test_fw_query_on_routes.py index dc6688324f..0bb9aa5e54 100755 --- a/selfdrive/debug/test_fw_query_on_routes.py +++ b/selfdrive/debug/test_fw_query_on_routes.py @@ -8,13 +8,11 @@ import traceback from tqdm import tqdm from tools.lib.logreader import LogReader from tools.lib.route import Route -from selfdrive.car.interfaces import get_interface_attr from selfdrive.car.car_helpers import interface_names -from selfdrive.car.fw_versions import match_fw_to_car +from selfdrive.car.fw_versions import VERSIONS, match_fw_to_car NO_API = "NO_API" in os.environ -VERSIONS = get_interface_attr('FW_VERSIONS', ignore_none=True) SUPPORTED_BRANDS = VERSIONS.keys() SUPPORTED_CARS = [brand for brand in SUPPORTED_BRANDS for brand in interface_names[brand]] UNKNOWN_BRAND = "unknown"