From 07301a008e8a472e819a18a1a991742944c90049 Mon Sep 17 00:00:00 2001 From: Zhang Keqiao Date: Sun, 27 Sep 2020 14:49:02 +0800 Subject: [PATCH 1/3] case-lib: add nocodec mode check and wav file upload functions add 2 functions to lib.sh. The first is to check whether sof is running in nocodec mode. The second is to add a function to upload wav files. Signed-off-by: Zhang Keqiao --- case-lib/lib.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/case-lib/lib.sh b/case-lib/lib.sh index de53bc2c..48b887ec 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -252,6 +252,19 @@ func_lib_get_tplg_path() return 0 } +func_nocodec_mode() +{ + uname -r |grep -q "nocodec" +} + +func_upload_wav_file() +{ + local dir=$1 + local file=$2 + + find "$dir" -maxdepth 1 -type f -name "$file" -size +0 -exec cp {} "$LOG_ROOT/" \; +} + die() { dloge "$@" From 7b7199aeef204400a23e02a8e22b1dc4ebc41596 Mon Sep 17 00:00:00 2001 From: Zhang Keqiao Date: Mon, 26 Oct 2020 16:28:00 +0800 Subject: [PATCH 2/3] test-case: remove plughw and refine check-alsabat.sh remove use of plughw to run alsabat test at hw level driectly without any conversions done by alsa-lib and refine the script. Signed-off-by: Zhang Keqiao --- test-case/check-alsabat.sh | 75 ++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/test-case/check-alsabat.sh b/test-case/check-alsabat.sh index 9245f9a7..20d8a4c7 100755 --- a/test-case/check-alsabat.sh +++ b/test-case/check-alsabat.sh @@ -18,7 +18,12 @@ # remove the existing alsabat wav files rm -f /tmp/bat.wav.* -source $(dirname ${BASH_SOURCE[0]})/../case-lib/lib.sh +libdir=$(dirname "${BASH_SOURCE[0]}") +# shellcheck source=case-lib/lib.sh +source "$libdir"/../case-lib/lib.sh + +OPT_OPT_lst['t']='tplg' OPT_DESC_lst['t']='tplg file, default value is env TPLG: $''TPLG' +OPT_PARM_lst['t']=1 OPT_VALUE_lst['t']="$TPLG" OPT_OPT_lst['p']='pcm_p' OPT_DESC_lst['p']='pcm for playback. Example: hw:0,0' OPT_PARM_lst['p']=1 OPT_VALUE_lst['p']='' @@ -29,7 +34,7 @@ OPT_PARM_lst['c']=1 OPT_VALUE_lst['c']='' OPT_OPT_lst['f']='frequency' OPT_DESC_lst['f']='target frequency' OPT_PARM_lst['f']=1 OPT_VALUE_lst['f']=997 -OPT_OPT_lst['n']='frames' OPT_DESC_lst['n']='test frames' +OPT_OPT_lst['n']='frames' OPT_DESC_lst['n']='test frames' OPT_PARM_lst['n']=1 OPT_VALUE_lst['n']=240000 OPT_OPT_lst['s']='sof-logger' OPT_DESC_lst['s']="Open sof-logger trace the data will store at $LOG_ROOT" @@ -37,6 +42,7 @@ OPT_PARM_lst['s']=0 OPT_VALUE_lst['s']=1 func_opt_parse_option "$@" +tplg=${OPT_VALUE_lst['t']} pcm_p=${OPT_VALUE_lst['p']} pcm_c=${OPT_VALUE_lst['c']} frequency=${OPT_VALUE_lst['f']} @@ -48,19 +54,16 @@ then exit 2 fi +pcmid_p=${pcm_p:-1} + [[ ${OPT_VALUE_lst['s']} -eq 1 ]] && func_lib_start_log_collect -function __upload_wav_file -{ - # upload the alsabat wav file - for file in /tmp/bat.wav.* - do - size=`ls -l $file | awk '{print $5}'` - if [[ $size -gt 0 ]]; then - cp $file $LOG_ROOT/ - fi - done -} +func_pipeline_export "$tplg" "type:playback & id:$pcmid_p" + +# parser the parameters of the specified playback pipeline +channel=$(func_pipeline_parse_value 0 ch_max) +rate=$(func_pipeline_parse_value 0 rate) +fmts=$(func_pipeline_parse_value 0 fmts) # check the PCMs before alsabat test dlogi "check the PCMs before alsabat test" @@ -68,19 +71,37 @@ dlogi "check the PCMs before alsabat test" [[ $(arecord -Dplug$pcm_c -d 1 /dev/null -q) ]] && die "Failed to capture on PCM: $pcm_c" # alsabat test -# different PCMs may support different audio formats(like samplerate, channel-counting, etc.). -# use plughw to do the audio format conversions. So we don't need to specify them for each PCM. -dlogc "alsabat -Pplug$pcm_p --standalone -n $frames -F $frequency" -alsabat -Pplug$pcm_p --standalone -n $frames -F $frequency & -# playback may have low latency, add one second delay to aviod recording zero at beginning. -sleep 1 -dlogc "alsabat -Cplug$pcm_c -F $frequency" -alsabat -Cplug$pcm_c -F $frequency - -# upload failed wav file -if [[ $? != 0 ]]; then - __upload_wav_file - exit 1 -fi +for format in $fmts + do + if [ "$format" == "S24_LE" ]; then + dlogi "S24_LE is not supported, skip to test this format" + continue + fi + + dlogc "alsabat -P $pcm_p --standalone -n $frames -F $frequency -c $channel -r $rate -f $format" + alsabat -P "$pcm_p" --standalone -n "$frames" -F "$frequency" -c "$channel" -r "$rate" \ + -f "$format" & alsabatPID=$! + # playback may have low latency, add one second delay to aviod recording zero at beginning. + sleep 1 + + if func_nocodec_mode; then + format_c=$format + channel_c=$channel + else + # USB sound card only supports 1 channel S16_LE format. + format_c=S16_LE + channel_c=1 + fi + + dlogc "alsabat -C $pcm_c -F $frequency -f $format_c -c $channel_c -r $rate" + alsabat -C "$pcm_c" -F "$frequency" -f "$format_c" -c "$channel_c" -r "$rate" || { + func_upload_wav_file "/tmp" "bat.wav.*" || true + exit 1 + } + # check the alsabat -P exit code + if ! wait $alsabatPID; then + die "alsabat -P failure" + fi +done exit 0 From b2313f2dfedb7552e44891fdb9fc1243346833c3 Mon Sep 17 00:00:00 2001 From: Zhang Keqiao Date: Mon, 26 Oct 2020 16:29:06 +0800 Subject: [PATCH 3/3] test-case: fix the shellcheck warning and Logic issue Use double quote to prevent globbing and fix the logic issue or die will never be executed. Signed-off-by: Zhang Keqiao --- test-case/check-alsabat.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-case/check-alsabat.sh b/test-case/check-alsabat.sh index 20d8a4c7..10a3b27d 100755 --- a/test-case/check-alsabat.sh +++ b/test-case/check-alsabat.sh @@ -67,8 +67,8 @@ fmts=$(func_pipeline_parse_value 0 fmts) # check the PCMs before alsabat test dlogi "check the PCMs before alsabat test" -[[ $(aplay -Dplug$pcm_p -d 1 /dev/zero -q) ]] && die "Failed to play on PCM: $pcm_p" -[[ $(arecord -Dplug$pcm_c -d 1 /dev/null -q) ]] && die "Failed to capture on PCM: $pcm_c" +aplay -Dplug"$pcm_p" -d 1 /dev/zero -q || die "Failed to play on PCM: $pcm_p" +arecord -Dplug"$pcm_c" -d 1 /dev/null -q || die "Failed to capture on PCM: $pcm_c" # alsabat test for format in $fmts