|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +## |
| 4 | +## Case Name: check-xrun-injection |
| 5 | +## Preconditions: |
| 6 | +## Need to enable CONFIG_SND_PCM_XRUN_DEBUG in kenrel config |
| 7 | +## Description: |
| 8 | +## check xrun injection during playback/capture |
| 9 | +## default duration is 10s |
| 10 | +## default interval time of xrun injection is 0.5s |
| 11 | +## Case step: |
| 12 | +## 1. Parse TPLG file to get pipeline |
| 13 | +## 2. Specify the audio parameters |
| 14 | +## 3. Run aplay or arecord on each pipeline with parameters |
| 15 | +## 4. do xrun injection during playback or capture |
| 16 | +## Expect result: |
| 17 | +## The return value of aplay/arecord should be 0 |
| 18 | +## |
| 19 | + |
| 20 | +source $(dirname ${BASH_SOURCE[0]})/../case-lib/lib.sh |
| 21 | + |
| 22 | +OPT_OPT_lst['t']='tplg' OPT_DESC_lst['t']='tplg file, default value is env TPLG: $TPLG' |
| 23 | +OPT_PARM_lst['t']=1 OPT_VALUE_lst['t']="$TPLG" |
| 24 | + |
| 25 | +OPT_OPT_lst['d']='duration' OPT_DESC_lst['d']='aplay/arecord duration in second' |
| 26 | +OPT_PARM_lst['d']=1 OPT_VALUE_lst['d']=10 |
| 27 | + |
| 28 | +OPT_OPT_lst['i']='interval' OPT_DESC_lst['i']='interval time of xrun injection' |
| 29 | +OPT_PARM_lst['i']=1 OPT_VALUE_lst['i']=0.5 |
| 30 | + |
| 31 | +OPT_OPT_lst['s']='sof-logger' OPT_DESC_lst['s']="Open sof-logger trace the data will store at $LOG_ROOT" |
| 32 | +OPT_PARM_lst['s']=0 OPT_VALUE_lst['s']=1 |
| 33 | + |
| 34 | +func_opt_parse_option $* |
| 35 | + |
| 36 | +tplg=${OPT_VALUE_lst['t']} |
| 37 | +duration=${OPT_VALUE_lst['d']} |
| 38 | +interval=${OPT_VALUE_lst['i']} |
| 39 | + |
| 40 | +[[ ${OPT_VALUE_lst['s']} -eq 1 ]] && func_lib_start_log_collect |
| 41 | + |
| 42 | +func_lib_setup_kernel_last_line |
| 43 | +func_lib_check_sudo |
| 44 | +func_pipeline_export $tplg "type:playback,capture,both" |
| 45 | + |
| 46 | +declare -A CMD FILE |
| 47 | +CMD['playback,both']='aplay' |
| 48 | +FILE['playback,both']='/dev/zero' |
| 49 | +CMD['capture,both']='arecord' |
| 50 | +FILE['capture,both']='/dev/null' |
| 51 | + |
| 52 | +func_xrun_injection() |
| 53 | +{ |
| 54 | + count=1 |
| 55 | + while(true) |
| 56 | + do |
| 57 | + ps -ef |grep "$pid" |grep -v grep |
| 58 | + if [ $? -eq 0 ]; then |
| 59 | + dlogi "XRUN injection: $count" |
| 60 | + sudo bash -c "'echo 1 > $xrun_injection'" |
| 61 | + sleep $interval |
| 62 | + let count++ |
| 63 | + else |
| 64 | + break # aplay/arecord is finished, stop xrun injection |
| 65 | + fi |
| 66 | + done |
| 67 | +} |
| 68 | + |
| 69 | +func_test_pipeline_with_type() |
| 70 | +{ |
| 71 | + func_pipeline_export $tplg "type:$1" |
| 72 | + for idx in $(seq 0 $(expr $PIPELINE_COUNT - 1)) |
| 73 | + do |
| 74 | + channel=$(func_pipeline_parse_value $idx channel) |
| 75 | + rate=$(func_pipeline_parse_value $idx rate) |
| 76 | + fmt=$(func_pipeline_parse_value $idx fmt) |
| 77 | + dev=$(func_pipeline_parse_value $idx dev) |
| 78 | + pcm=$(func_pipeline_parse_value $idx pcm) |
| 79 | + id=$(func_pipeline_parse_value $idx id) |
| 80 | + pipeline_type=$(func_pipeline_parse_value $idx "type") |
| 81 | + pcm=pcm${id}${2} |
| 82 | + xrun_injection="/proc/asound/card0/$pcm/sub0/xrun_injection" |
| 83 | + |
| 84 | + # check xrun injection file |
| 85 | + [[ ! -e $xrun_injection ]] && dloge "XRUN DEBUG is not enabled in kernel, skip the test." && exit 2 |
| 86 | + dlogi "Testing: test xrun injection on PCM:$pcm,$pipeline_type. Interval time: $interval" |
| 87 | + dlogc "${CMD[$1]}" -D$dev -r $rate -c $channel -f $fmt -d $duration "${FILE[$1]}" -q |
| 88 | + "${CMD[$1]}" -D$dev -r $rate -c $channel -f $fmt -d $duration "${FILE[$1]}" -q & |
| 89 | + pid=$! |
| 90 | + # do xrun injection |
| 91 | + dlogc "echo 1 > $xrun_injection" |
| 92 | + func_xrun_injection |
| 93 | + # check aplay/arecord return value |
| 94 | + wait $pid |
| 95 | + if [ $? != 0 ]; then |
| 96 | + dloge "$pipeline_type on $pcm failed." |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | + done |
| 100 | +} |
| 101 | + |
| 102 | +func_test_pipeline_with_type "playback,both" "p" |
| 103 | +func_test_pipeline_with_type "capture,both" "c" |
| 104 | + |
| 105 | +sof-kernel-log-check.sh $KERNEL_LAST_LINE |
| 106 | +exit $? |
0 commit comments