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

test car models: check that all msgs sent are sent by the car #30094

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions selfdrive/car/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ def setUpClass(cls):
car_fw = []
can_msgs = []
cls.elm_frame = None
fingerprint = defaultdict(dict)
cls.fingerprint = defaultdict(dict)
for i in range(2):
# emulate closed relay
cls.fingerprint[(i*4)+2] = cls.fingerprint[i*4]
experimental_long = False
enabled_toggle = True
dashcam_only = False
Expand All @@ -120,7 +123,11 @@ def setUpClass(cls):
if len(can_msgs) <= FRAME_FINGERPRINT:
for m in msg.can:
if m.src < 64:
fingerprint[m.src][m.address] = len(m.dat)
cls.fingerprint[m.src][m.address] = len(m.dat)
#if (m.src % 4) in (0, 2):
# # relay is closed during fingerprinting, so emulate that
# src = (m.src // 4) + (0 if m.src % 4 == 2 else 2)
# cls.fingerprint[src][m.address] = len(m.dat)

elif msg.which() == "carParams":
car_fw = msg.carParams.carFw
Expand Down Expand Up @@ -156,7 +163,7 @@ def setUpClass(cls):
cls.can_msgs = sorted(can_msgs, key=lambda msg: msg.logMonoTime)

cls.CarInterface, cls.CarController, cls.CarState = interfaces[cls.car_model]
cls.CP = cls.CarInterface.get_params(cls.car_model, fingerprint, car_fw, experimental_long, docs=False)
cls.CP = cls.CarInterface.get_params(cls.car_model, cls.fingerprint, car_fw, experimental_long, docs=False)
assert cls.CP
assert cls.CP.carFingerprint == cls.car_model

Expand Down Expand Up @@ -202,7 +209,25 @@ def test_car_interface(self):

for i, msg in enumerate(self.can_msgs):
CS = self.CI.update(CC, (msg.as_builder().to_bytes(),))
self.CI.apply(CC, msg.logMonoTime)
_, sendcan = self.CI.apply(CC, msg.logMonoTime)

#from pprint import pprint
#pprint(self.fingerprint)

# ensure we don't send anything that the car doesn't send
for msg in sendcan:
addr, _, dat, bus = msg

# exception: comma pedal
if addr == 0x200:
continue

# exception: unplugged DSU
if addr in (835, 1041, 1042, 0x128, 321, 352, 353, 643, 742, 743, 836, 830, 869, 870, 1227, 1136):
continue

assert addr in self.fingerprint[bus].keys()
assert len(dat) == self.fingerprint[bus][addr]

if CS.canValid:
can_valid = True
Expand Down
Loading