-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathcheck-alsabat.sh
More file actions
executable file
·143 lines (115 loc) · 4.39 KB
/
check-alsabat.sh
File metadata and controls
executable file
·143 lines (115 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
##
## Case Name: check alsabat
## Preconditions:
## This test case requires physical loopback between playback and capture.
## playback <=====> capture
## nocodec : no need to use hw loopback cable, It support DSP loopback by quirk
## Description:
## run alsabat test on the specified pipelines
## Case step:
## 1. Specify the pcm IDs for playback and catpure
## 3. run alsabat test
## Expect result:
## The return value of alsabat is 0
##
# remove the existing alsabat wav files
rm -f /tmp/bat.wav.*
# shellcheck source=case-lib/lib.sh
TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$TESTDIR/case-lib/lib.sh"
OPT_NAME['p']='pcm_p' OPT_DESC['p']='pcm for playback. Example: hw:0,0'
OPT_HAS_ARG['p']=1 OPT_VAL['p']=''
OPT_NAME['C']='channel_c' OPT_DESC['C']='channel number for capture.'
OPT_HAS_ARG['C']=1 OPT_VAL['C']='1'
OPT_NAME['r']='rate' OPT_DESC['r']='sample rate'
OPT_HAS_ARG['r']=1 OPT_VAL['r']=48000
OPT_NAME['c']='pcm_c' OPT_DESC['c']='pcm for capture. Example: hw:1,0'
OPT_HAS_ARG['c']=1 OPT_VAL['c']=''
OPT_NAME['f']='format' OPT_DESC['f']='target format'
OPT_HAS_ARG['f']=1 OPT_VAL['f']="S16_LE"
OPT_NAME['F']='frequency' OPT_DESC['F']='target frequency'
OPT_HAS_ARG['F']=1 OPT_VAL['F']=821
OPT_NAME['k']='sigmak' OPT_DESC['k']='sigma k value'
OPT_HAS_ARG['k']=1 OPT_VAL['k']=2.1
OPT_NAME['n']='frames' OPT_DESC['n']='test frames'
OPT_HAS_ARG['n']=1 OPT_VAL['n']=240000
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['q']='min_snr' OPT_DESC['q']='Mininimum SNR value dB to pass test, recommend 80 for high quality DUT'
OPT_HAS_ARG['q']=1 OPT_VAL['q']=46
func_opt_parse_option "$@"
setup_kernel_check_point
pcm_p=${OPT_VAL['p']}
pcm_c=${OPT_VAL['c']}
rate=${OPT_VAL['r']}
channel_c=${OPT_VAL['C']}
format=${OPT_VAL['f']}
frequency=${OPT_VAL['F']}
sigmak=${OPT_VAL['k']}
frames=${OPT_VAL['n']}
min_snr=${OPT_VAL['q']}
if [ "$pcm_p" = "" ]||[ "$pcm_c" = "" ];
then
dloge "No playback or capture PCM is specified. Skip the alsabat test"
exit 2
fi
check_locale_for_alsabat
# reset sof volume to 0dB
reset_sof_volume
# If MODEL is defined, set proper gain for the platform
if [ -z "$MODEL" ]; then
# treat as warning only
dlogw "NO MODEL is defined. Please define MODEL to run alsa_settings/MODEL.sh"
else
#dlogi "apply alsa settings for alsa_settings/MODEL.sh"
set_alsa_settings "$MODEL"
fi
logger_disabled || func_lib_start_log_collect
function __upload_wav_file
{
# upload the alsabat wav file
for file in /tmp/bat.wav.*
do
# alsabat has a bug where it creates an empty record in playback
# mode
if test -s "$file"; then
cp "$file" "$LOG_ROOT/"
fi
done
}
function check_wav_file_snr
{
for file in /tmp/bat.wav.*
do
if test -s "$file"; then
dlogi "Checking wav file $file"
cd "$TESTDIR"/tools
octave --silent --no-gui --eval "check_wav_file_snr('$file', $frequency, $min_snr, '$LOG_ROOT/');" || {
die "Error: Script check_wav_file_snr.m found issues in $file"
}
fi
done
}
# 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"
# alsabat test
# hardcode the channel number of playback to 2, as sof doesnot support mono wav.
dlogc "alsabat -P$pcm_p --standalone -n $frames -r $rate -c 2 -f $format -F $frequency -k $sigmak"
alsabat -P$pcm_p --standalone -n $frames -c 2 -r $rate -f $format -F $frequency -k $sigmak & playPID=$!
# playback may have low latency, add one second delay to aviod recording zero at beginning.
sleep 1
# We use different USB sound cards in CI, part of them only support 1 channel for capture,
# so make the channel as an option and config it in alsabat-playback.csv
dlogc "alsabat -C$pcm_c -c $channel_c -r $rate -f $format -F $frequency -k $sigmak"
alsabat -C$pcm_c -c $channel_c -r $rate -f $format -F $frequency -k $sigmak || {
# upload failed wav file
__upload_wav_file
# dump amixer contents for more debugging
amixer contents > "$LOG_ROOT"/amixer_settings.txt
exit 1
}
check_wav_file_snr
wait $playPID