Skip to content

Commit

Permalink
check-pause-release-suspend-resume: move the code to a function
Browse files Browse the repository at this point in the history
Code cleanup, move the code to a function to
make the code easy to understand and maintain.

Signed-off-by: Keqiao Zhang <[email protected]>
  • Loading branch information
keqiaozhang committed Mar 29, 2022
1 parent 56b3f3b commit b7454ba
Showing 1 changed file with 113 additions and 99 deletions.
212 changes: 113 additions & 99 deletions test-case/check-pause-release-suspend-resume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ OPT_HAS_ARG['T']=1 OPT_VAL['T']=""
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'

func_opt_parse_option "$@"

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
parse_param()
{
func_opt_parse_option $@

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 @@ -104,95 +106,107 @@ case $test_mode in
*)
die "Invalid test mode: $test_mode. Accepted test mode: playback; capture"
;;
esac

# only run suspend/resume once for each loop.
# Use system default value if no sleep type is specified
if [ -n "${OPT_VAL['T']}" ]; then
sleep_opts="-l 1 -T ${OPT_VAL['T']}"
else
sleep_opts="-l 1"
fi

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


logger_disabled || func_lib_start_log_collect

setup_kernel_check_point

func_pipeline_export "$tplg" "type:$test_mode & ${OPT_VAL['P']}"

for idx in $(seq 0 $((PIPELINE_COUNT - 1)))
do
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
esac

# only run suspend/resume once for each loop.
# Use system default value if no sleep type is specified
if [ -n "${OPT_VAL['T']}" ]; then
sleep_opts="-l 1 -T ${OPT_VAL['T']}"
else
sleep_opts="-l 1"
fi

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

run_test()
{
for idx in $(seq 0 $((PIPELINE_COUNT - 1)))
do
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

ret=$?
if [ $ret -ne 0 ]; then
sof-process-kill.sh || dlogw "sof-process-kill.sh failed"
exit $ret
fi
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"
done
ret=$?
if [ $ret -ne 0 ]; then
sof-process-kill.sh || dlogw "sof-process-kill.sh failed"
exit $ret
fi
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" || die "Caught error in kernel log"
done
}

main()
{
parse_param "$@"

logger_disabled || func_lib_start_log_collect

setup_kernel_check_point

func_pipeline_export "$tplg" "type:$test_mode & ${OPT_VAL['P']}"

run_test
}

main "$@"

0 comments on commit b7454ba

Please sign in to comment.