mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-09 15:53:43 +08:00
9fb45b315a
# Conflicts: # README.md # docs/CARS.md # opendbc_repo # tinygrad_repo # tools/release/build_release.sh # tools/release/build_stripped.sh
60 lines
1.9 KiB
Python
60 lines
1.9 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']
|
|
|
|
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)
|
|
|
|
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
|