Files
sunnypilot/selfdrive/controls/tests/test_startup.py
Adeeb Shihadeh 05eb44115e cereal cleanup part 2 (#20092)
* car stuff

* thermal

* Revert "car stuff"

This reverts commit 77fd1c65ebd01abfa8493ae12c9e6b14f7ada976.

* panda state

* camera stuff

* start deg

* most is building

* builds

* planner + controls run

* fix up paramsd

* cleanup

* process replay passes

* fix webcam build

* camerad

* no more frame

* thermald

* ui

* paramsd

* camera replay

* fix long tests

* fix camerad tests

* maxSteeringAngle

* bump cereal

* more frame

* cereal master
old-commit-hash: 312b681a46
2021-02-16 21:39:32 -08:00

80 lines
2.6 KiB
Python
Executable File

#!/usr/bin/env python3
import time
import unittest
from parameterized import parameterized
from cereal import log, car
import cereal.messaging as messaging
from common.params import Params
from selfdrive.boardd.boardd_api_impl import can_list_to_can_capnp # pylint: disable=no-name-in-module,import-error
from selfdrive.car.fingerprints import _FINGERPRINTS
from selfdrive.car.hyundai.values import CAR as HYUNDAI
from selfdrive.car.mazda.values import CAR as MAZDA
from selfdrive.controls.lib.events import EVENT_NAME
from selfdrive.test.helpers import with_processes
EventName = car.CarEvent.EventName
class TestStartup(unittest.TestCase):
@parameterized.expand([
# TODO: test EventName.startup for release branches
# officially supported car
(EventName.startupMaster, HYUNDAI.SONATA, False),
(EventName.startupMaster, HYUNDAI.SONATA, True),
# community supported car
(EventName.startupMaster, HYUNDAI.KIA_STINGER, True),
(EventName.communityFeatureDisallowed, HYUNDAI.KIA_STINGER, False),
# dashcamOnly car
(EventName.startupNoControl, MAZDA.CX5, True),
(EventName.startupNoControl, MAZDA.CX5, False),
# unrecognized car
(EventName.startupNoCar, None, True),
(EventName.startupNoCar, None, False),
])
@with_processes(['controlsd'])
def test_startup_alert(self, expected_event, car, toggle_enabled):
# TODO: this should be done without any real sockets
controls_sock = messaging.sub_sock("controlsState")
pm = messaging.PubMaster(['can', 'pandaState'])
params = Params()
params.clear_all()
params.put("Passive", b"0")
params.put("OpenpilotEnabledToggle", b"1")
params.put("CommunityFeaturesToggle", b"1" if toggle_enabled else b"0")
time.sleep(2) # wait for controlsd to be ready
msg = messaging.new_message('pandaState')
msg.pandaState.pandaType = log.PandaState.PandaType.uno
pm.send('pandaState', msg)
# fingerprint
if car is None:
finger = {addr: 1 for addr in range(1, 100)}
else:
finger = _FINGERPRINTS[car][0]
for _ in range(500):
msgs = [[addr, 0, b'\x00'*length, 0] for addr, length in finger.items()]
pm.send('can', can_list_to_can_capnp(msgs))
time.sleep(0.01)
msgs = messaging.drain_sock(controls_sock)
if len(msgs):
event_name = msgs[0].controlsState.alertType.split("/")[0]
self.assertEqual(EVENT_NAME[expected_event], event_name,
f"expected {EVENT_NAME[expected_event]} for '{car}', got {event_name}")
break
else:
self.fail(f"failed to fingerprint {car}")
if __name__ == "__main__":
unittest.main()