Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check-pause-release-suspend-resume: timing fixes + switch to sof-tplgreader #885

Closed
wants to merge 7 commits into from
208 changes: 112 additions & 96 deletions test-case/check-pause-release-suspend-resume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,50 @@ set -e
## * No unexpected errors should be present in dmesg during or after test
## completion.

source $(dirname ${BASH_SOURCE[0]})/../case-lib/lib.sh
# shellcheck source=case-lib/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh

OPT_NAME['m']='mode' OPT_DESC['m']='test mode. Example: playback; capture'
OPT_HAS_ARG['m']=1 OPT_VAL['m']='playback'
CASEDIR=$(dirname "${BASH_SOURCE[0]}")

OPT_NAME['p']='pcm' OPT_DESC['p']='audio pcm. Example: hw:0,0'
OPT_HAS_ARG['p']=1 OPT_VAL['p']='hw:0,0'
OPT_NAME['m']='mode' OPT_DESC['m']='test mode. Example: playback; capture'
OPT_HAS_ARG['m']=1 OPT_VAL['m']='playback'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all these whitespace changes in this area. They make it impossible to find the real changes.
https://wiki.openstack.org/wiki/GitCommitMessages#Things_to_avoid_when_creating_commits

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answering myself: reviewing commits individually avoids this problem.


OPT_NAME['f']='fmt' OPT_DESC['f']='audio format value'
OPT_HAS_ARG['f']=1 OPT_VAL['f']='S16_LE'
OPT_NAME['F']='file' OPT_DESC['F']='file name. Example: /dev/zero; /dev/null'
OPT_HAS_ARG['F']=1 OPT_VAL['F']=''

OPT_NAME['c']='channel' OPT_DESC['c']='audio channel count'
OPT_HAS_ARG['c']=1 OPT_VAL['c']='2'
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
OPT_HAS_ARG['l']=1 OPT_VAL['l']=5

OPT_NAME['r']='rate' OPT_DESC['r']='audio rate'
OPT_HAS_ARG['r']=1 OPT_VAL['r']='48000'
OPT_NAME['i']='interval' OPT_DESC['i']='interval before checking the aplay/arecord status after pause/release'
OPT_HAS_ARG['i']=1 OPT_VAL['i']='500'

OPT_NAME['F']='file' OPT_DESC['F']='file name. Example: /dev/zero; /dev/null'
OPT_HAS_ARG['F']=1 OPT_VAL['F']=''
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1

OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
OPT_HAS_ARG['l']=1 OPT_VAL['l']=5
OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG'
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"

OPT_NAME['i']='sleep-period' OPT_DESC['i']='sleep period of aplay, unit is ms'
OPT_HAS_ARG['i']=1 OPT_VAL['i']='100'
OPT_NAME['P']='filter_string' OPT_DESC['P']='run this case on specified pipelines'
OPT_HAS_ARG['P']=1 OPT_VAL['P']='id:any'

OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
OPT_NAME['T']='type' OPT_DESC['T']="specify the sleep type for suspend/resume:s2idle/deep"
OPT_HAS_ARG['T']=1 OPT_VAL['T']=""

func_opt_parse_option "$@"
OPT_NAME['d']='delay' OPT_DESC['d']='delay time before pausing aplay/arecord process, unit is ms'
OPT_HAS_ARG['d']=1 OPT_VAL['d']='2000'

pcm=${OPT_VAL['p']}
fmt=${OPT_VAL['f']}
channel=${OPT_VAL['c']}
rate=${OPT_VAL['r']}
repeat_count=${OPT_VAL['l']}
sleep_period=${OPT_VAL['i']}
test_mode=${OPT_VAL['m']}
file_name=${OPT_VAL['F']}
parse_param()
{
func_opt_parse_option "$@"

case $test_mode in
repeat_count=${OPT_VAL['l']}
interval=${OPT_VAL['i']}
test_mode=${OPT_VAL['m']}
file_name=${OPT_VAL['F']}
tplg=${OPT_VAL['t']}
delay=${OPT_VAL['d']}

case $test_mode in
"playback")
cmd=aplay
dummy_file=/dev/zero
Expand All @@ -103,82 +106,95 @@ case $test_mode in
*)
die "Invalid test mode: $test_mode. Accepted test mode: playback; capture"
;;
esac

[[ -z $file_name ]] && file_name=$dummy_file


logger_disabled || func_lib_start_log_collect
esac

setup_kernel_check_point
# only run suspend/resume once for each loop.
# Use system default value if no sleep type is specified
sleep_opts="-l 1"
[ -z "${OPT_VAL['T']}" ] || sleep_opts+=" -T ${OPT_VAL['T']}"

dlogi "Entering audio stream expect script with: $cmd -D $pcm -r $rate -c $channel -f $fmt -vv -i $dummy_file -q"
dlogi "Will enter suspend-resume cycle during paused period of audio stream process"
[[ -z "$file_name" ]] && file_name="$dummy_file"
}

rm -rf /tmp/sof-test.lock
run_test()
{
channel=$(func_pipeline_parse_value "$idx" channel)
rate=$(func_pipeline_parse_value "$idx" rate)
fmt=$(func_pipeline_parse_value "$idx" fmt)
dev=$(func_pipeline_parse_value "$idx" dev)

dlogi "Entering audio stream expect script with: $cmd -D $dev -r $rate -c $channel -f $fmt -vv -i $file_name -q"
dlogi "Will enter suspend-resume cycle during paused period of audio stream process"

# expect is tcl language script
# catch: Evaluate script and trap exceptional returns
# after ms: Ms must be an integer giving a time in milliseconds.
# The command sleeps for ms milliseconds and then returns.
expect <<AUDIO
spawn $cmd -D $dev -r $rate -c $channel -f $fmt -vv -i $file_name -q
set i 1
expect {
"#*+*\%" {
# audio stream (aplay or arecord) is active now and playing
# delay time before pausing aplay/arecord process
after $delay
puts "\r===== (\$i/$repeat_count) pb_pbm: Pause $cmd, then wait for ===== "
puts "\r(\$i/$repeat_count) pb_pbm: $interval ms after pause"
send " "
after $interval
puts "Finished sleep. Confirming $cmd is paused."
# check audio stream status --- R == paused, else == not paused
set retval [catch { exec ps -C $cmd -o state --no-header } state]
puts "$cmd state = \$state"
if {[string equal \$state "R"] != 0} {
puts "$cmd is paused, will now enter suspend-resume cycle"
} else {
puts "$cmd is not paused. Exiting test and failing."
exit 1
}
# enter suspend-resume cycle once per pause instance
set retval [catch { exec bash $CASEDIR/check-suspend-resume.sh $sleep_opts } msg]
# prints logs from suspend-resume test
puts \$msg
puts "Finished suspend-resume test"
if { \$retval } {
puts "suspend resume cycle has failed."
set error_code [lindex \$::errorCode {2}]
puts "errorCode was: \$error_code"
exit 1
}
# sucessful suspend/resume cycle, now release audio stream
puts "\r(\$i/$repeat_count) pb_pbm: Release $cmd, then wait for"
puts "\r(\$i/$repeat_count) pb_pbm: $interval ms after resume"
send " "
after $interval
puts "Finished sleep after resume"
incr i
if { \$i > $repeat_count } { exit 0 }
exp_continue
}
}
AUDIO
}

# expect is tcl language script
# catch: Evaluate script and trap exceptional returns
# after ms: Ms must be an integer giving a time in milliseconds.
# The command sleeps for ms milliseconds and then returns.
expect <<AUDIO
spawn $cmd -D $pcm -r $rate -c $channel -f $fmt -vv -i $dummy_file -q
set i 1
set sleep_t $sleep_period
expect {
"#*+*\%" {
#audio stream (aplay or arecord) is active now and playing
puts "\r===== (\$i/$repeat_count) pb_pbm: Pause $cmd, then wait for ===== "
puts "\r(\$i/$repeat_count) pb_pbm: $sleep_t ms after pause"
send " "
after \$sleep_t
puts "Finished sleep. Confirming $cmd is paused."
main()
{
parse_param "$@"

#check audio stream status --- R == paused, else == not paused
set retval [catch { exec ps -C $cmd -o state --no-header } state]
puts "$cmd state = \$state"
logger_disabled || func_lib_start_log_collect

if {[string equal \$state "R"] != 0} {
puts "$cmd is paused, will now enter suspend-resume cycle"
} else {
puts "$cmd is not paused. Exiting test and failing."
exit 1
}
setup_kernel_check_point

#enter suspend-resume cycle once per pause instance
set retval [catch { exec bash check-suspend-resume.sh -l 1 } msg]
func_pipeline_export "$tplg" "type:$test_mode & ${OPT_VAL['P']}"

#prints logs from suspend-resume test
puts \$msg
puts "Finished suspend-resume test"
if { \$retval } {
puts "suspend resume cycle has failed."
set error_code [lindex \$::errorCode {2}]
puts "errorCode was: \$error_code"
for idx in $(seq 0 $((PIPELINE_COUNT - 1)))
do
run_test || {
sof-process-kill.sh || dlogw "sof-process-kill.sh cleanup failed"
exit 1
}

#sucessful suspend/resume cycle, now release audio stream
puts "\r(\$i/$repeat_count) pb_pbm: Release $cmd, then wait for"
puts "\r(\$i/$repeat_count) pb_pbm: \$sleep_t ms after resume"
send " "
after \$sleep_t

puts "Finished sleep after resume"
incr i
if { \$i > $repeat_count } { exit 0 }
exp_continue
}
done
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"
}
AUDIO

ret=$?
#flush the output
echo
if [ $ret -ne 0 ]; then
sof-process-kill.sh
[[ $? -ne 0 ]] && dlogw "Kill process catch error"
exit $ret
fi
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT"
exit $?
main "$@"
12 changes: 11 additions & 1 deletion test-case/run-all-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ kmod-load-unload
kmod-load-unload-after-playback
suspend-resume
suspend-resume-with-playback
suspend-resume-with-capture"
suspend-resume-with-capture
pause-release-suspend-resume-with-playback
pause-release-suspend-resume-with-capture"

# Requires Octave
testlist="$testlist volume_levels"
Expand Down Expand Up @@ -295,6 +297,14 @@ test_suspend-resume-with-capture()
{
"$mydir"/check-suspend-resume-with-audio.sh -l "$small_loop" -m capture
}
test_pause-release-suspend-resume-with-playback()
{
"$mydir"/check-pause-release-suspend-resume.sh -l "$small_loop" -m playback
}
test_pause-release-suspend-resume-with-capture()
{
"$mydir"/check-pause-release-suspend-resume.sh -l "$small_loop" -m capture
}

usage()
{
Expand Down