-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathverify-ucm-config.sh
More file actions
executable file
·184 lines (159 loc) · 6.08 KB
/
verify-ucm-config.sh
File metadata and controls
executable file
·184 lines (159 loc) · 6.08 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
##
## Case Name: verify-ucm-config
## Preconditions:
## N/A
## Description:
## verify the ucm configuration
## Case step:
## 1. load the ucm config file
## 2. check ucm can be run by alsaucm correctly or not:
## check the ucm configuration file meets the syntax or not
## check if the devices can be enabled or not
## check if the controls can be set correctly or not
## and so on. Details can be found in cmd 'alsaucm --help'
## Expect result:
## command line check with $? without error
## Example of alsaucm output of verbs:
## 0: HiFi
## Play HiFi quality Music.
## Example of alsaucm output of devices:
## 0: Speaker
## description of Speaker.
source $(dirname ${BASH_SOURCE[0]})/../case-lib/lib.sh
func_opt_parse_option "$@"
setup_kernel_check_point
start_test
save_alsa_state
declare -A verb_array
# get the cards all verbs. The verbs are the items of SectionUseCase in
# UCM config file.
# For example, There is:
# SectionUseCase."HiFi" {
# File "HiFi.conf"
# Comment "Play HiFi Music"
# }
# Then we will get the below information after we run `alsaucm -c "$cardname" list _verbs`
# 0: HiFi
# Play HiFi quality Music.
func_get_verbs()
{
dlogc "alsaucm -c '$cardname' list _verbs"
verbs=`alsaucm -c "$cardname" list _verbs 2>/dev/null`
[[ $? -ne 0 ]] && die "'$cardname' list _verbs failed!"
[[ -z "$verbs" ]] && die "'$cardname' ucm has no verbs!"
# save the verbs into array verb_array
local OLD_IFS="$IFS"
IFS=$'\n'
((verbs_desc_line=0))
# verb counter
((verb_i=0))
# $desc_line is used to define it is the even line (description line) or the odd line
# verb format: there are 2 lines in each verb.
# The first line is the verb's identifier;
# The second line is the verb's descriptor
# For example, run `alsaucm -c cardname list _verbs` and suppose we get:
# 0: HiFi
# Play HiFi quality Music.
# the verb is 'HiFi'
# the verb's description is "Play HiFi quality Music"
for verb in $verbs; do
if [ $verbs_desc_line -eq 0 ]; then
# get the verb identifier. In the upper example, it is "HiFi"
verb=`echo $verb|awk '{print $2}'`
[[ -z "$verb" ]] && dlogw "verb is null, skipping" && continue
dlogi "found verb: $verb"
verb_array[$verb_i]="$verb"
((verb_i++))
((verbs_desc_line=1))
else
# Let's skip the description
((verbs_desc_line=0))
fi
done
IFS="$OLD_IFS"
}
func_verify_verb_device()
{
local cardname=$1
local verb=$2
local -A dev_array
# 1. get all the devices used by the verb
# The device is defined in "SectionDevice". For example:
# SectionDevice."Speaker" {
# xxxx
# }
# Then the device is "Speaker"
dlogc "alsaucm -c '$cardname' set _verb $verb list _devices"
devices=$(alsaucm -c "$cardname" set _verb $verb list _devices 2>/dev/null)
[[ $? -ne 0 ]] && dloge "list device failed" && return 1
local OLD_IFS="$IFS"
IFS=$'\n'
((devs_desc_line=0))
# 2. save the devices into the array dev_array
# device counter
((device_i=0))
# After run $(alsaucm -c "$cardname" set _verb $verb list _devices),
# it will show all the devices it supports. Each device takes 2 lines output.
# The first line is the device identifier;
# The second line is the device description.
# For example:
# 0: Speaker
# description of Speaker.
for device in $devices; do
if [ $devs_desc_line -eq "0" ]; then
device=`echo $device |awk -F ": " '{print $2}'`
[[ -z "$verb" ]] && dlogw "device is null, skipping" && continue
dlogi "found device: $device"
dev_array[$device_i]="$device"
((device_i++))
((devs_desc_line=1))
else
# Let's skip the description
((devs_desc_line=0))
fi
done
IFS="$OLD_IFS"
# 3. alsaucm test on the devices
for device in "${dev_array[@]}"; do
# 3.1 enable the device and check if the device is really enabled or not
dlogc "alsaucm -c '$cardname' set _verb '$verb' set _enadev '$device' list1 _enadevs"
ret=`alsaucm -c "$cardname" set _verb "$verb" set _enadev "$device" list1 _enadevs 2>/dev/null`
[[ $? -ne 0 ]] && dloge "enable '$verb':'$device' failed" && return 1
ret=`echo $ret |grep "$device" 2>/dev/null`
[[ -z "$ret" ]] && dloge "'$verb':'$device' is not in the enabled device list" && return 1
# 3.2 enable the device and setup the controls to check if the controls can be set correctly or not
dlogc "alsaucm -c '$cardname' set _verb '$verb' set _enadev '$device' reload"
alsaucm -c "$cardname" set _verb "$verb" set _enadev "$device" reload 2>/dev/null
[[ $? -ne 0 ]] && dloge "reload '$verb':'$device' setting failed!" && return 1
done
return 0
}
sofcard=${SOFCARD:-0}
cardname=$(sof-dump-status.py -s $sofcard)
[[ $? -ne 0 ]] && exit 1
# 1. use alsaucm to open the card
dlogc "alsaucm -c ${cardname} open ${cardname}"
alsaucm -c "${cardname}" open "${cardname}" 2>/dev/null
[[ $? -ne 0 ]] && die "open card '$cardname' failed!"
# 2. try to reload the card to the initial settings.
# These setting is defined in 'SectionDefaults' in UCM config file.
dlogc "alsaucm -c "$cardname" reload"
alsaucm -c "$cardname" reload 2>/dev/null
[[ $? -ne 0 ]] && die "card '$cardname' reload failed."
# 3. get all the verbs
func_get_verbs
# 4. go through the verbs test
for verb in "${verb_array[@]}"; do
# 4.1 test setting verb works or not. In the upper example, it means to use 'HiFi' use case.
dlogc "alsaucm -c '$cardname' set _verb $verb get _verb"
ret=`alsaucm -c "$cardname" set _verb "$verb" get _verb 2>/dev/null`
[[ $? -ne 0 ]] && die "set verb: $verb failed!"
ret=`echo $ret |grep "$verb" 2>/dev/null`
[[ -z "$ret" ]] && die "'$verb' is not the selected verb"
# 4.2 Let's go through all the devices supported in the verb, e.g. "HiFi" use case.
func_verify_verb_device "$cardname" "$verb"
ret=$?
[[ $ret -ne 0 ]] && exit $ret
done
exit 0