mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-11 09:03:41 +08:00
7461f70fdb
# Conflicts: # README.md # SConstruct # conftest.py # docs/CARS.md # msgq_repo # opendbc_repo # openpilot/common/params_keys.h # openpilot/common/params_pyx.pyx # openpilot/common/tests/test_swaglog.cc # openpilot/selfdrive/car/card.py # openpilot/selfdrive/car/tests/test_car_interfaces.py # openpilot/selfdrive/car/tests/test_cruise_speed.py # openpilot/selfdrive/car/tests/test_models.py # openpilot/selfdrive/controls/controlsd.py # openpilot/selfdrive/controls/lib/latcontrol_torque.py # openpilot/selfdrive/controls/lib/longitudinal_planner.py # openpilot/selfdrive/controls/plannerd.py # openpilot/selfdrive/controls/radard.py # openpilot/selfdrive/controls/tests/test_longcontrol.py # openpilot/selfdrive/locationd/torqued.py # openpilot/selfdrive/modeld/modeld.py # openpilot/selfdrive/monitoring/dmonitoringd.py # openpilot/selfdrive/monitoring/test_monitoring.py # openpilot/selfdrive/selfdrived/selfdrived.py # openpilot/selfdrive/selfdrived/tests/test_alertmanager.py # openpilot/selfdrive/test/longitudinal_maneuvers/plant.py # openpilot/selfdrive/test/process_replay/migration.py # openpilot/selfdrive/test/process_replay/process_replay.py # openpilot/selfdrive/ui/feedback/feedbackd.py # openpilot/selfdrive/ui/layouts/settings/device.py # openpilot/selfdrive/ui/layouts/settings/toggles.py # openpilot/selfdrive/ui/mici/layouts/onboarding.py # openpilot/selfdrive/ui/onroad/augmented_road_view.py # openpilot/selfdrive/ui/tests/test_soundd.py # openpilot/selfdrive/ui/translations/app.pot # openpilot/selfdrive/ui/translations/app_de.po # openpilot/selfdrive/ui/translations/app_en.po # openpilot/selfdrive/ui/translations/app_es.po # openpilot/selfdrive/ui/translations/app_fr.po # openpilot/selfdrive/ui/translations/app_ja.po # openpilot/selfdrive/ui/translations/app_ko.po # openpilot/selfdrive/ui/translations/app_pt-BR.po # openpilot/selfdrive/ui/translations/app_th.po # openpilot/selfdrive/ui/translations/app_tr.po # openpilot/selfdrive/ui/translations/app_uk.po # openpilot/selfdrive/ui/translations/app_zh-CHS.po # openpilot/selfdrive/ui/translations/app_zh-CHT.po # openpilot/system/athena/athenad.py # openpilot/system/hardware/hardwared.py # openpilot/system/loggerd/deleter.py # openpilot/system/manager/process_config.py # openpilot/system/ui/lib/application.py # panda # pyproject.toml # tinygrad_repo # uv.lock
97 lines
3.0 KiB
Python
97 lines
3.0 KiB
Python
import copy
|
|
import json
|
|
import os
|
|
import random
|
|
|
|
from openpilot.common.test import OpenpilotTestCase
|
|
from openpilot.cereal import log
|
|
from opendbc.car.structs import car
|
|
from openpilot.cereal.messaging import SubMaster
|
|
from openpilot.common.basedir import BASEDIR
|
|
from openpilot.common.params import Params
|
|
from openpilot.selfdrive.selfdrived.events import Alert, EVENTS, ET
|
|
from openpilot.selfdrive.selfdrived.alertmanager import set_offroad_alert
|
|
from openpilot.selfdrive.test.process_replay.process_replay import CONFIGS
|
|
|
|
AlertSize = log.SelfdriveState.AlertSize
|
|
|
|
OFFROAD_ALERTS_PATH = os.path.join(BASEDIR, "openpilot/selfdrive/selfdrived/alerts_offroad.json")
|
|
|
|
# TODO: add callback alerts
|
|
ALERTS = []
|
|
for event_types in EVENTS.values():
|
|
for alert in event_types.values():
|
|
ALERTS.append(alert)
|
|
|
|
|
|
class TestAlerts(OpenpilotTestCase):
|
|
|
|
@classmethod
|
|
def setup_class(cls):
|
|
with open(OFFROAD_ALERTS_PATH) as f:
|
|
cls.offroad_alerts = json.loads(f.read())
|
|
|
|
# Create fake objects for callback
|
|
cls.CS = car.CarState.new_message()
|
|
cls.CP = car.CarParams.new_message()
|
|
cfg = [c for c in CONFIGS if c.proc_name == 'selfdrived'][0]
|
|
cls.sm = SubMaster(cfg.pubs)
|
|
|
|
def test_events_defined(self):
|
|
# Ensure all events in capnp schema are defined in events.py
|
|
events = log.OnroadEvent.EventName.schema.enumerants
|
|
|
|
for name, e in events.items():
|
|
if not name.endswith("DEPRECATED") and not name.startswith("eventReserved"):
|
|
fail_msg = f"{name} @{e} not in EVENTS"
|
|
assert e in EVENTS.keys(), fail_msg
|
|
|
|
def test_alert_sanity_check(self):
|
|
for event_types in EVENTS.values():
|
|
for event_type, a in event_types.items():
|
|
# TODO: add callback alerts
|
|
if not isinstance(a, Alert):
|
|
continue
|
|
|
|
if a.alert_size == AlertSize.none:
|
|
assert len(a.alert_text_1) == 0
|
|
assert len(a.alert_text_2) == 0
|
|
elif a.alert_size == AlertSize.small:
|
|
assert len(a.alert_text_1) > 0
|
|
assert len(a.alert_text_2) == 0
|
|
elif a.alert_size == AlertSize.mid:
|
|
assert len(a.alert_text_1) > 0
|
|
assert len(a.alert_text_2) > 0
|
|
else:
|
|
assert len(a.alert_text_1) > 0
|
|
|
|
assert a.duration >= 0.
|
|
|
|
if event_type not in (ET.WARNING, ET.PERMANENT, ET.PRE_ENABLE):
|
|
assert a.creation_delay == 0.
|
|
|
|
def test_offroad_alerts(self):
|
|
params = Params()
|
|
for a in self.offroad_alerts:
|
|
# set the alert
|
|
alert = copy.copy(self.offroad_alerts[a])
|
|
set_offroad_alert(a, True)
|
|
alert['extra'] = ''
|
|
assert alert == params.get(a)
|
|
|
|
# then delete it
|
|
set_offroad_alert(a, False)
|
|
assert params.get(a) is None
|
|
|
|
def test_offroad_alerts_extra_text(self):
|
|
params = Params()
|
|
for i in range(50):
|
|
# set the alert
|
|
a = random.choice(list(self.offroad_alerts))
|
|
alert = self.offroad_alerts[a]
|
|
set_offroad_alert(a, True, extra_text="a"*i)
|
|
|
|
written_alert = params.get(a)
|
|
assert "a"*i == written_alert['extra']
|
|
assert alert["text"] == written_alert['text']
|