Files
openpilot-evo/openpilot/selfdrive/ui/tests/test_soundd.py
T
Adeeb Shihadeh 0b7bd2561d unittest speedups (#38472)
* unittest speedups

* fix deleter test helper signature

* document small deleter test files

* test uploader clears locks on startup
2026-07-28 16:52:41 -07:00

33 lines
1.2 KiB
Python

import threading
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, check_selfdrive_timeout_alert
AudibleAlert = log.SelfdriveState.AudibleAlert
class TestSoundd(OpenpilotTestCase):
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']
received_at = sm.recv_time['selfdriveState']
clock = mocker.patch("openpilot.selfdrive.ui.soundd.time.monotonic", return_value=received_at + SELFDRIVE_STATE_TIMEOUT)
assert not check_selfdrive_timeout_alert(sm)
clock.return_value = received_at + SELFDRIVE_STATE_TIMEOUT + 0.1
assert check_selfdrive_timeout_alert(sm)
clock.return_value = received_at + SELFDRIVE_STATE_TIMEOUT + 10
assert not check_selfdrive_timeout_alert(sm)
# TODO: add test with micd for checking that soundd actually outputs sounds