Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FW query timing test: mock get_data function for timeout #29712

Merged
merged 20 commits into from
Dec 12, 2023
Merged
24 changes: 16 additions & 8 deletions selfdrive/car/tests/test_fw_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
from collections import defaultdict
from parameterized import parameterized
from unittest import mock
import threading

from cereal import car
Expand Down Expand Up @@ -176,7 +177,7 @@ def test_fw_requests(self):

class TestFwFingerprintTiming(unittest.TestCase):
N: int = 5
TOL: float = 0.12
TOL: float = 0.1

@staticmethod
def _run_thread(thread: threading.Thread) -> float:
Expand All @@ -191,12 +192,19 @@ def _run_thread(thread: threading.Thread) -> float:
return time.perf_counter() - t

def _benchmark_brand(self, brand, num_pandas):
fake_socket = FakeSocket()
brand_time = 0
for _ in range(self.N):
thread = threading.Thread(target=get_fw_versions, args=(fake_socket, fake_socket, brand),
kwargs=dict(num_pandas=num_pandas))
brand_time += self._run_thread(thread)
def fake_get_data(_, timeout):
nonlocal fake_timeout_time
fake_timeout_time += timeout
return {}

with mock.patch("openpilot.selfdrive.car.isotp_parallel_query.IsoTpParallelQuery.get_data", fake_get_data):
fake_socket = FakeSocket()
brand_time = 0
for _ in range(self.N):
fake_timeout_time = 0
thread = threading.Thread(target=get_fw_versions, args=(fake_socket, fake_socket, brand),
kwargs=dict(num_pandas=num_pandas))
brand_time += self._run_thread(thread) + fake_timeout_time

return brand_time / self.N

Expand Down Expand Up @@ -227,7 +235,7 @@ def test_startup_timing(self):

@pytest.mark.timeout(60)
def test_fw_query_timing(self):
total_ref_time = 6.41
total_ref_time = 6.58
brand_ref_times = {
1: {
'body': 0.11,
Expand Down