Skip to content

Commit

Permalink
get_fw_versions: test the full stack (#33156)
Browse files Browse the repository at this point in the history
* add the test

fix

* bump

* not sure why mypy didn't catch this
  • Loading branch information
sshane authored Jul 31, 2024
1 parent 1dd8bdc commit ebff7ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion panda
Submodule panda updated 1 files
+2 −2 python/uds.py
6 changes: 2 additions & 4 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class LatControlInputs(NamedTuple):
aego: float


SendCan = tuple[int, bytes, int]
TorqueFromLateralAccelCallbackType = Callable[[LatControlInputs, car.CarParams.LateralTorqueTuning, float, float, bool, bool], float]


Expand Down Expand Up @@ -109,7 +110,7 @@ def __init__(self, CP, CarController, CarState):
dbc_name = "" if self.cp is None else self.cp.dbc_name
self.CC: CarControllerBase = CarController(dbc_name, CP, self.VM)

def apply(self, c: car.CarControl, now_nanos: int) -> tuple[car.CarControl.Actuators, list[tuple[int, int, bytes, int]]]:
def apply(self, c: car.CarControl, now_nanos: int) -> tuple[car.CarControl.Actuators, list[SendCan]]:
return self.CC.update(c, self.CS, now_nanos)

@staticmethod
Expand Down Expand Up @@ -462,9 +463,6 @@ def get_loopback_can_parser(CP):
return None


SendCan = tuple[int, int, bytes, int]


class CarControllerBase(ABC):
def __init__(self, dbc_name: str, CP, VM):
self.CP = CP
Expand Down
20 changes: 19 additions & 1 deletion selfdrive/car/tests/test_fw_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from parameterized import parameterized

from cereal import car
from openpilot.selfdrive.car import make_can_msg
from openpilot.selfdrive.car.car_helpers import interfaces
from openpilot.selfdrive.car.fingerprints import FW_VERSIONS
from openpilot.selfdrive.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_present_ecus
from openpilot.selfdrive.car.vin import get_vin
from openpilot.selfdrive.pandad import can_list_to_can_capnp

CarFw = car.CarParams.CarFw
Ecu = car.CarParams.Ecu
Expand All @@ -19,7 +21,8 @@

class FakeSocket:
def receive(self, non_blocking=False):
pass
return (can_list_to_can_capnp([make_can_msg(random.randint(0x600, 0x800), b'\x00' * 8, 0)])
if random.uniform(0, 1) > 0.5 else None)

def send(self, msg):
pass
Expand Down Expand Up @@ -313,3 +316,18 @@ def test_fw_query_timing(self, subtests, mocker):
total_time = round(total_times[num_pandas], 2)
self._assert_timing(total_time, total_ref_time[num_pandas])
print(f'all brands, total FW query time={total_time} seconds')

def test_get_fw_versions(self, subtests, mocker):
# some coverage on IsoTpParallelQuery and panda UDS library
# TODO: replace this with full fingerprint simulation testing
# https://github.com/commaai/panda/pull/1329

def fake_cloudlog_exception(*args, **kwargs):
raise

mocker.patch("openpilot.selfdrive.car.fw_versions.set_obd_multiplexing", lambda *args: None)
mocker.patch("openpilot.common.swaglog.cloudlog.exception", fake_cloudlog_exception)
fake_socket = FakeSocket()
for brand in FW_QUERY_CONFIGS.keys():
with subtests.test(brand=brand):
get_fw_versions(fake_socket, fake_socket, brand, num_pandas=1)

0 comments on commit ebff7ca

Please sign in to comment.