Add unittest for alert callbacks (#24551)

add alert callback test
pull/24544/head
Willem Melching 3 years ago committed by GitHub
parent b9c350bf98
commit 31af13101b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      selfdrive/controls/tests/test_alerts.py
  2. 2
      selfdrive/test/process_replay/process_replay.py

@ -10,6 +10,7 @@ from common.basedir import BASEDIR
from common.params import Params
from selfdrive.controls.lib.events import Alert, EVENTS, ET
from selfdrive.controls.lib.alertmanager import set_offroad_alert
from selfdrive.test.process_replay.process_replay import FakeSubMaster, CONFIGS
AlertSize = log.ControlsState.AlertSize
@ -19,8 +20,7 @@ OFFROAD_ALERTS_PATH = os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offro
ALERTS = []
for event_types in EVENTS.values():
for alert in event_types.values():
if isinstance(alert, Alert):
ALERTS.append(alert)
ALERTS.append(alert)
class TestAlerts(unittest.TestCase):
@ -30,6 +30,11 @@ class TestAlerts(unittest.TestCase):
with open(OFFROAD_ALERTS_PATH) as f:
cls.offroad_alerts = json.loads(f.read())
# Create fake objects for callback
cls.CP = car.CarParams.new_message()
cfg = [c for c in CONFIGS if c.proc_name == 'controlsd'][0]
cls.sm = FakeSubMaster(cfg.pub_sub.keys())
def test_events_defined(self):
# Ensure all events in capnp schema are defined in events.py
events = car.CarEvent.EventName.schema.enumerants
@ -59,6 +64,9 @@ class TestAlerts(unittest.TestCase):
}
for alert in ALERTS:
if not isinstance(alert, Alert):
alert = alert(self.CP, self.sm, metric=False, soft_disable_time=100)
# for full size alerts, both text fields wrap the text,
# so it's unlikely that they would go past the max width
if alert.alert_size in (AlertSize.none, AlertSize.full):

@ -242,7 +242,7 @@ CONFIGS = [
pub_sub={
"can": ["controlsState", "carState", "carControl", "sendcan", "carEvents", "carParams"],
"deviceState": [], "pandaStates": [], "peripheralState": [], "liveCalibration": [], "driverMonitoringState": [], "longitudinalPlan": [], "lateralPlan": [], "liveLocationKalman": [], "liveParameters": [], "radarState": [],
"modelV2": [], "driverCameraState": [], "roadCameraState": [], "managerState": [],
"modelV2": [], "driverCameraState": [], "roadCameraState": [], "managerState": [], "testJoystick": [],
},
ignore=["logMonoTime", "valid", "controlsState.startMonoTime", "controlsState.cumLagMs"],
init_callback=fingerprint,

Loading…
Cancel
Save