f8e13417f2
date: 2026-08-15T14:20:10 master commit: d48cfa730bf21593b684efeaf3fd8940695e1dea
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
import threading
|
|
import time
|
|
|
|
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', 'selfdriveStateSP'])
|
|
pm = PubMaster(['selfdriveState', 'selfdriveStateSP'])
|
|
|
|
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)
|
|
|
|
def test_check_selfdrive_timeout_alert_mads_lateral_only(self):
|
|
sm = SubMaster(['selfdriveState', 'selfdriveStateSP'])
|
|
pm = PubMaster(['selfdriveState', 'selfdriveStateSP'])
|
|
|
|
for _ in range(100):
|
|
cs = messaging.new_message('selfdriveState')
|
|
cs.selfdriveState.enabled = False
|
|
|
|
ss_sp = messaging.new_message('selfdriveStateSP')
|
|
ss_sp.selfdriveStateSP.mads.enabled = True
|
|
|
|
pm.send("selfdriveState", cs)
|
|
pm.send("selfdriveStateSP", ss_sp)
|
|
|
|
time.sleep(0.01)
|
|
|
|
sm.update(0)
|
|
|
|
assert not check_selfdrive_timeout_alert(sm)
|
|
|
|
for _ in range(SELFDRIVE_STATE_TIMEOUT * 110):
|
|
sm.update(0)
|
|
time.sleep(0.01)
|
|
|
|
assert check_selfdrive_timeout_alert(sm)
|
|
|
|
# TODO: add test with micd for checking that soundd actually outputs sounds
|