Files
StarPilot/openpilot/selfdrive/ui/tests/test_soundd.py
T
firestar5683 a82935f326 User interfaces and Android Auto
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: pharmacomaniac <blittle65@gmail.com>

Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

61 lines
2.3 KiB
Python

import threading
import numpy as np
from openpilot.common.test import OpenpilotTestCase
from openpilot.cereal import log, messaging
from openpilot.cereal.messaging import SubMaster, PubMaster
from openpilot.selfdrive.ui.soundd import SELFDRIVE_STATE_TIMEOUT, Soundd, check_selfdrive_timeout_alert
AudibleAlert = log.SelfdriveState.AudibleAlert
class TestSoundd(OpenpilotTestCase):
def test_callback_defers_and_bounds_stream_status_logging(self, mocker):
soundd = Soundd.__new__(Soundd)
soundd.current_alert = AudibleAlert.none
soundd.current_volume = 0.1
soundd.loaded_sounds = {}
soundd.saved_volumes = {}
soundd.pending_stream_status = None
soundd.stream_status_count = 0
soundd.output_underflow_count = 0
soundd.reported_output_underflows = 0
soundd.stream_report_at = None
warning = mocker.patch("openpilot.selfdrive.ui.soundd.cloudlog.warning")
error = mocker.patch("openpilot.selfdrive.ui.soundd.cloudlog.error")
output = np.empty((8, 1), dtype=np.float32)
soundd.callback(output, 8, None, "first underflow")
soundd.callback(output, 8, None, "latest underflow")
assert np.array_equal(output, np.zeros_like(output))
warning.assert_not_called()
error.assert_not_called()
soundd.log_pending_stream_status()
warning.assert_called_once_with("soundd stream diagnostics: status=latest underflow status_callbacks=2 output_underflows=0")
soundd.log_pending_stream_status()
warning.assert_called_once()
error.assert_not_called()
def test_check_selfdrive_timeout_alert(self, mocker):
sm = SubMaster(['selfdriveState'])
pm = PubMaster(['selfdriveState'])
cs = messaging.new_message('selfdriveState')
cs.selfdriveState.enabled = True
threading.Timer(0.01, pm.send, args=("selfdriveState", cs)).start()
sm.update(100)
assert sm.updated['selfdriveState']
sm.recv_time['selfdriveState'] = 0
clock = mocker.patch("openpilot.selfdrive.ui.soundd.time.monotonic", return_value=SELFDRIVE_STATE_TIMEOUT)
assert not check_selfdrive_timeout_alert(sm)
clock.return_value = SELFDRIVE_STATE_TIMEOUT + 0.1
assert check_selfdrive_timeout_alert(sm)
clock.return_value = SELFDRIVE_STATE_TIMEOUT + 10
assert not check_selfdrive_timeout_alert(sm)
# TODO: add test with micd for checking that soundd actually outputs sounds