mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-25 12:02:05 +08:00
Add unittest for alert callbacks (#24551)
add alert callback test
old-commit-hash: 31af13101b
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user