Verify System and Driver Critical Sounds

This commit is contained in:
firestar5683
2026-11-28 11:58:37 -06:00
parent 2a95f6473e
commit dcce4eee55
@@ -6,12 +6,16 @@ from unittest.mock import patch
import numpy as np
from openpilot.selfdrive.ui.soundd import (ALERT_VOLUME_KEYS, AudibleAlert, CRITICAL_MAX,
from openpilot.selfdrive.ui.soundd import (ALERT_VOLUME_KEYS, AudibleAlert, CRITICAL_MAX, SYSTEM_CRITICAL_MAX,
Soundd, sound_list)
from openpilot.starpilot.audio.alert_volume import AUTO
WARNINGS = (AudibleAlert.warningSoft, AudibleAlert.warningImmediate)
WARNINGS = {
AudibleAlert.warningSoft: SYSTEM_CRITICAL_MAX,
AudibleAlert.warningImmediate: CRITICAL_MAX,
AudibleAlert.warningImmediateSystem: SYSTEM_CRITICAL_MAX,
}
def soundd(alert, *, builtin=False, saved=AUTO):
@@ -22,7 +26,8 @@ def soundd(alert, *, builtin=False, saved=AUTO):
owner.ramp_start_time = 0.
owner.pending_stop = False
owner.loaded_sounds = {key: np.array([.2, .4, .2, 0.], dtype=np.float32) for key in sound_list}
owner.loaded_sounds[CRITICAL_MAX] = np.array([.1, .2, .3, .2, 0., 0.], dtype=np.float32)
for sound in WARNINGS.values():
owner.loaded_sounds[sound] = np.array([.1, .2, .3, .2, 0., 0.], dtype=np.float32)
owner.pack_loader = Mock(is_builtin=Mock(return_value=builtin))
owner.saved_volumes = dict.fromkeys(ALERT_VOLUME_KEYS.values(), saved)
return owner
@@ -40,7 +45,7 @@ class TestCriticalMerge(TestCase):
owner.update_critical_sound(7.999)
assert owner.current_sound == alert
owner.update_critical_sound(8.)
assert owner.current_alert == alert and owner.current_sound == CRITICAL_MAX
assert owner.current_alert == alert and owner.current_sound == WARNINGS[alert]
assert owner.current_sound_frame == 0
np.testing.assert_allclose(owner.get_sound_data(1), [.1])
owner.update_critical_sound(9.)
@@ -57,7 +62,7 @@ class TestCriticalMerge(TestCase):
for frame in (0, 4, 6, 12):
with self.subTest(alert=alert, frame=frame):
owner = soundd(alert)
owner.current_sound = CRITICAL_MAX
owner.current_sound = WARNINGS[alert]
owner.current_sound_frame = frame
owner.current_volume = 1.
owner.update_alert(AudibleAlert.none)
@@ -74,7 +79,7 @@ class TestCriticalMerge(TestCase):
for alert in WARNINGS:
with self.subTest(alert=alert):
owner = soundd(alert)
owner.current_sound = CRITICAL_MAX
owner.current_sound = WARNINGS[alert]
owner.current_sound_frame = 1
owner.current_volume = 1.
owner.update_alert(AudibleAlert.none)
@@ -102,10 +107,10 @@ class TestCriticalMerge(TestCase):
owner.update_alert(alert)
assert not owner.pending_stop and owner.current_sound_frame == 1
owner.update_critical_sound(8.)
assert owner.current_sound == CRITICAL_MAX and owner.current_sound_frame == 0
assert owner.current_sound == WARNINGS[alert] and owner.current_sound_frame == 0
owner.current_sound_frame = 2
owner.update_alert(AudibleAlert.none)
other = WARNINGS[1] if alert == WARNINGS[0] else WARNINGS[0]
other = next(warning for warning in WARNINGS if warning != alert)
with patch("openpilot.selfdrive.ui.soundd.time.monotonic", return_value=20.):
owner.update_alert(other)
assert owner.current_alert == owner.current_sound == other