Skip to content

Commit 5be12d0

Browse files
committed
case-lib: apause: Make sure the PCM is running before pausing
This change addresses the following error seen when doing pause with the multiple-pause-resume test: aplay: do_pause:1586: pause push error: File descriptor in bad state When an xrun happens during the test, the application tries to recover from the xrun by preparing and restarting the stream. There could be a race between when this happens and when the script tries to pause the stream. To avoid this, make sure that the stream state is RUNNING before going ahead with the pause. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent 5124961 commit 5be12d0

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

case-lib/apause.exp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ proc cr_to_lf {arg} {
107107
#
108108
# arecord $cmd_opts -D $dev -r $rate -c $channel -f $fmt -vv -i $file_name ...
109109
log 0 "$argv0 spawning: $argv"
110+
111+
set device [lindex $argv 2]
112+
set command [lindex $argv 0]
113+
114+
# Determine direction based on the command
115+
if {$command eq "aplay"} {
116+
set direction "p" ; # Playback
117+
} else {
118+
set direction "c" ; # Capture
119+
}
120+
121+
# parse the card number and device
122+
if {![regexp {hw:(\d+),(\d+)} $device match card_number device_id]} {
123+
log 0 "ERROR: Failed to parse hw string: $hw_string"
124+
}
125+
126+
set pcm_status_file "/proc/asound/card${card_number}/pcm${device_id}${direction}/sub0/status"
127+
128+
if {![file exists $pcm_status_file]} {
129+
log 0 "ERROR: PCM status file not found: $pcm_status_file"
130+
exit 1
131+
}
132+
110133
spawn {*}$argv
111134
set start_time_ms [clock milliseconds]; # re-adjust
112135
set last_space_time 0 ; # could not resist that name
@@ -218,6 +241,25 @@ expect {
218241
log 1 "($pauses_counter/$repeat_count) Found volume ### | __%, active for $_record_for ms"
219242

220243
set _delay [substract_time_since_last_space $_record_for]
244+
245+
# wait 50ms for the PCM status to be RUNNING before pausing
246+
# this is to make sure that in the case of an xrun the application
247+
# successfully recovers and restarts the stream.
248+
set max_attempts 50
249+
set attempt 0
250+
while {$attempt < $max_attempts} {
251+
set pcm_status [exec cat $pcm_status_file]
252+
if {[regexp {state:\s*RUNNING} $pcm_status]} {
253+
break
254+
}
255+
incr attempt
256+
after 1
257+
}
258+
if {$attempt >= $max_attempts} {
259+
log 0 "ERROR: timeout waiting for PCM status to be RUNNING before pause"
260+
exit 1
261+
}
262+
221263
after $_delay "press_space; set state pause_requested"
222264
log 3 "last_space_time=$last_space_time; timer in $_delay"
223265

0 commit comments

Comments
 (0)