From f6f0674d1986af6690fc50a523d7f8c25e77238c Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 21 Aug 2024 00:58:28 -0700 Subject: [PATCH] tests: some speed optimizations (#1181) * mock sleep via monotonic * rm * no need to generate 8 buses * this doesn't actually make a big diff * lower loop * can reduce * here too * Revert "here too" This reverts commit 06b4cadd5488e639c9beffa77256e52bbd72c84a. * Revert "can reduce" This reverts commit 55cae021bcba20bb0022f78e1307ded886fc07e7. --- opendbc/car/tests/test_fw_fingerprint.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/opendbc/car/tests/test_fw_fingerprint.py b/opendbc/car/tests/test_fw_fingerprint.py index 8e966df5c4..aabdaa4ce6 100644 --- a/opendbc/car/tests/test_fw_fingerprint.py +++ b/opendbc/car/tests/test_fw_fingerprint.py @@ -9,7 +9,7 @@ from opendbc.car.structs import CarParams from opendbc.car.fingerprints import FW_VERSIONS from opendbc.car.fw_versions import ESSENTIAL_ECUS, FW_QUERY_CONFIGS, FUZZY_EXCLUDE_ECUS, VERSIONS, build_fw_dict, \ - match_fw_to_car, get_brand_ecu_matches, get_fw_versions, get_fw_versions_ordered, get_present_ecus + match_fw_to_car, get_brand_ecu_matches, get_fw_versions, get_present_ecus from opendbc.car.vin import get_vin CarFw = CarParams.CarFw @@ -26,7 +26,7 @@ def assertFingerprints(self, candidates, expected): def test_exact_match(self, brand, car_model, ecus, test_non_essential): config = FW_QUERY_CONFIGS[brand] CP = CarParams() - for _ in range(100): + for _ in range(20): fw = [] for ecu, fw_versions in ecus.items(): # Assume non-essential ECUs apply to all cars, so we catch cases where Car A with @@ -316,8 +316,15 @@ def test_get_fw_versions(self, subtests, mocker): def fake_carlog_exception(*args, **kwargs): raise + t = 0 + + def fake_monotonic(): + nonlocal t + t += 0.0001 + return t + mocker.patch("opendbc.car.carlog.exception", fake_carlog_exception) - get_fw_versions_ordered(self.fake_can_recv, self.fake_can_send, lambda obd: None, '0' * 17, set()) + mocker.patch("time.monotonic", fake_monotonic) for brand in FW_QUERY_CONFIGS.keys(): with subtests.test(brand=brand): get_fw_versions(self.fake_can_recv, self.fake_can_send, lambda obd: None, brand)