|
|
@ -1,4 +1,5 @@ |
|
|
|
from parameterized import parameterized |
|
|
|
from parameterized import parameterized |
|
|
|
|
|
|
|
from types import SimpleNamespace |
|
|
|
|
|
|
|
|
|
|
|
from openpilot.selfdrive.car.can_definitions import CanData |
|
|
|
from openpilot.selfdrive.car.can_definitions import CanData |
|
|
|
from openpilot.selfdrive.car.car_helpers import FRAME_FINGERPRINT, can_fingerprint |
|
|
|
from openpilot.selfdrive.car.car_helpers import FRAME_FINGERPRINT, can_fingerprint |
|
|
@ -15,7 +16,12 @@ class TestCanFingerprint: |
|
|
|
for address, length in fingerprint.items() for src in (0, 1)] |
|
|
|
for address, length in fingerprint.items() for src in (0, 1)] |
|
|
|
|
|
|
|
|
|
|
|
fingerprint_iter = iter([can]) |
|
|
|
fingerprint_iter = iter([can]) |
|
|
|
car_fingerprint, finger = can_fingerprint(lambda: next(fingerprint_iter, [])) # noqa: B023 |
|
|
|
def drain(wait_for_one=False): |
|
|
|
|
|
|
|
ret = next(fingerprint_iter, [CanData(1, b'\x00', 128)]) # noqa: B023 |
|
|
|
|
|
|
|
return [ret] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logcan = SimpleNamespace(drain=drain) |
|
|
|
|
|
|
|
car_fingerprint, finger = can_fingerprint(logcan) |
|
|
|
|
|
|
|
|
|
|
|
assert car_fingerprint == car_model |
|
|
|
assert car_fingerprint == car_model |
|
|
|
assert finger[0] == fingerprint |
|
|
|
assert finger[0] == fingerprint |
|
|
@ -46,11 +52,12 @@ class TestCanFingerprint: |
|
|
|
with subtests.test(expected_frames=expected_frames, car_model=car_model): |
|
|
|
with subtests.test(expected_frames=expected_frames, car_model=car_model): |
|
|
|
frames = 0 |
|
|
|
frames = 0 |
|
|
|
|
|
|
|
|
|
|
|
def test(): |
|
|
|
def drain(wait_for_one=False): |
|
|
|
nonlocal frames |
|
|
|
nonlocal frames |
|
|
|
frames += 1 |
|
|
|
frames += 1 |
|
|
|
return can # noqa: B023 |
|
|
|
return [can] # noqa: B023 |
|
|
|
|
|
|
|
|
|
|
|
car_fingerprint, _ = can_fingerprint(test) |
|
|
|
logcan = SimpleNamespace(drain=drain) |
|
|
|
|
|
|
|
car_fingerprint, _ = can_fingerprint(logcan) |
|
|
|
assert car_fingerprint == car_model |
|
|
|
assert car_fingerprint == car_model |
|
|
|
assert frames == expected_frames + 2 # TODO: fix extra frames |
|
|
|
assert frames == expected_frames + 2 # TODO: fix extra frames |
|
|
|