@@ -155,6 +155,80 @@ audio_timeout_run() {
155155 done
156156 wait " $pid " ; return $?
157157}
158+
159+ # Function: setup_overlay_audio_environment
160+ # Purpose: Configure audio environment for overlay builds (audioreach-based)
161+ # Returns: 0 on success, 1 on failure
162+ # Usage: Call early in audio test initialization, before backend detection
163+
164+ setup_overlay_audio_environment () {
165+ # Detect overlay build
166+ if ! lsmod 2> /dev/null | awk ' $1 ~ /^audioreach/ { found=1; exit } END { exit !found }' ; then
167+ log_info " Base build detected (no audioreach modules), skipping overlay setup"
168+ return 0
169+ fi
170+
171+ log_info " Overlay build detected (audioreach modules present), configuring environment..."
172+
173+ # Check root permissions
174+ if [ " $( id -u) " -ne 0 ]; then
175+ log_fail " Overlay audio setup requires root permissions"
176+ return 1
177+ fi
178+
179+ # Configure DMA heap permissions
180+ if [ -e /dev/dma_heap/system ]; then
181+ log_info " Setting permissions on /dev/dma_heap/system"
182+ chmod 666 /dev/dma_heap/system || {
183+ log_fail " Failed to chmod /dev/dma_heap/system"
184+ return 1
185+ }
186+ else
187+ log_warn " /dev/dma_heap/system not found, skipping chmod"
188+ fi
189+
190+ # Check systemctl availability
191+ if ! command -v systemctl > /dev/null 2>&1 ; then
192+ log_fail " systemctl not available, cannot restart pipewire"
193+ return 1
194+ fi
195+
196+ # Restart PipeWire
197+ log_info " Restarting pipewire service..."
198+ if ! systemctl restart pipewire 2> /dev/null; then
199+ log_fail " Failed to restart pipewire service"
200+ return 1
201+ fi
202+
203+ # Wait for PipeWire with polling (max 60s, check every 2s)
204+ log_info " Waiting for pipewire to be ready..."
205+ max_wait=60
206+ elapsed=0
207+ poll_interval=2
208+
209+ while [ $elapsed -lt $max_wait ]; do
210+ # Check if pipewire process is running
211+ if pgrep -x pipewire > /dev/null 2>&1 ; then
212+ # Verify wpctl can communicate
213+ if command -v wpctl > /dev/null 2>&1 && wpctl status > /dev/null 2>&1 ; then
214+ log_pass " PipeWire is ready (took ${elapsed} s)"
215+ return 0
216+ fi
217+ fi
218+
219+ sleep $poll_interval
220+ elapsed=$(( elapsed + poll_interval))
221+
222+ if [ $(( elapsed % 10 )) -eq 0 ]; then
223+ log_info " Still waiting for pipewire... (${elapsed} s/${max_wait} s)"
224+ fi
225+ done
226+
227+ # Timeout reached
228+ log_fail " PipeWire failed to become ready within ${max_wait} s"
229+ log_fail " Check 'systemctl status pipewire' and 'journalctl -u pipewire' for details"
230+ return 1
231+ }
158232
159233# ---------- PipeWire: sinks (playback) ----------
160234pw_default_speakers () {
0 commit comments