@@ -47,25 +47,35 @@ source "${TESTLIB}/lib.sh"
4747source " ${TESTLIB} /relay.sh"
4848
4949# shellcheck disable=SC2153
50- OPT_NAME[' t' ]=' tplg' OPT_DESC[' t' ]=" tplg file, default value is env TPLG: $TPLG "
51- OPT_HAS_ARG[' t' ]=1 OPT_VAL[' t' ]=" $TPLG "
50+ OPT_NAME[' t' ]=' tplg' OPT_DESC[' t' ]=" tplg file, default value is env TPLG: $TPLG "
51+ OPT_HAS_ARG[' t' ]=1 OPT_VAL[' t' ]=" $TPLG "
5252
53- OPT_NAME[' l' ]=' loop' OPT_DESC[' l' ]=' loop count'
54- OPT_HAS_ARG[' l' ]=1 OPT_VAL[' l' ]=1
53+ OPT_NAME[' l' ]=' loop' OPT_DESC[' l' ]=' loop count'
54+ OPT_HAS_ARG[' l' ]=1 OPT_VAL[' l' ]=1
5555
56- OPT_NAME[' s' ]=' sof-logger' OPT_DESC[' s' ]=" Open sof-logger trace the data will store at $LOG_ROOT "
57- OPT_HAS_ARG[' s' ]=0 OPT_VAL[' s' ]=1
56+ OPT_NAME[' s' ]=' sof-logger' OPT_DESC[' s' ]=" Open sof-logger trace the data will store at $LOG_ROOT "
57+ OPT_HAS_ARG[' s' ]=0 OPT_VAL[' s' ]=1
5858
59- OPT_NAME[' u' ]=' relay' OPT_DESC[' u' ]=' name of usbrelay switch, default value is HURTM_2'
60- OPT_HAS_ARG[' u' ]=1 OPT_VAL[' u' ]=" HURTM_2"
59+ OPT_NAME[' d' ]=' dsp-settle-sleep' OPT_DESC[' d' ]=" Waitng time to change control state"
60+ OPT_HAS_ARG[' d' ]=1 OPT_VAL[' d' ]=3
61+
62+ OPT_NAME[' u' ]=' relay' OPT_DESC[' u' ]=' name of usbrelay switch, default value is HURTM_2'
63+ OPT_HAS_ARG[' u' ]=1 OPT_VAL[' u' ]=" HURTM_2"
64+
65+ OPT_NAME[' h' ]=' headphone' OPT_DESC[' h' ]=' name of pcm control for headphone jack'
66+ OPT_HAS_ARG[' h' ]=1 OPT_VAL[' h' ]=" headphone jack"
67+
68+ OPT_NAME[' m' ]=' headset' OPT_DESC[' m' ]=' name of pcm control for headset mic jack'
69+ OPT_HAS_ARG[' m' ]=1 OPT_VAL[' m' ]=" headset [a-z ]*jack"
6170
6271func_opt_parse_option " $@ "
6372
6473tplg=${OPT_VAL['t']}
6574relay=${OPT_VAL['u']}
6675loop_cnt=${OPT_VAL['l']}
67-
68- DSP_SETTLE_TIME=2
76+ dsp_settle_time=${OPT_VAL['d']}
77+ headphone_jack_name=${OPT_VAL['h']}
78+ headset_mic_jack_name=${OPT_VAL['m']}
6979
7080check_control_switch_state ()
7181{
@@ -78,15 +88,16 @@ check_control_switch_state()
7888 local control_state
7989
8090 control_state=$( amixer -c " $SOFCARD " contents | awk -v name=" $control_name " '
81- BEGIN {
82- RS = "";
83- IGNORECASE = 1;
84- split(name, parts, " ");
85- };
86- $0 ~ parts[1] && $0 ~ parts[2] {
87- if (match($0, /values=(on|off)/, m)) print m[1];
91+ BEGIN { IGNORECASE=1; found=0 }
92+ /name=' \' ' / {
93+ if (tolower($0) ~ tolower(name)) found=1
94+ else found=0
8895 }
89- ' )
96+ found && /: values=/ {
97+ sub(/^.*: values=/, "", $0)
98+ print $0
99+ found=0
100+ }' )
90101 dlogi " $control_name switch is: $control_state "
91102
92103 if [[ " $expected_control_state " == " $control_state " ]]; then
@@ -116,40 +127,40 @@ testing_one_pcm()
116127 usbrelay_switch " $relay " 1
117128
118129 # Wait for a short period to allow the system to detect the unplug event
119- sleep $DSP_SETTLE_TIME
130+ sleep " $dsp_settle_time "
120131
121132 # check if the aplay process is still running after unplugging the jack
122133 ps -p " $pid_playback " > /dev/null || {
123134 func_lib_lsof_error_dump " $snd "
124135 die " Playback process terminated unexpectedly after unplugging the jack."
125136 }
126137
127- check_control_switch_state " headset " " off" || {
128- die " unplug headset jack failed."
138+ check_control_switch_state " $headset_mic_jack_name " " off" || {
139+ die " unplug $headset_mic_jack_name jack failed."
129140 }
130141
131- check_control_switch_state " headphone " ' off' || {
132- die " unplug headphone jack failed."
142+ check_control_switch_state " $headphone_jack_name " " off" || {
143+ die " unplug $headphone_jack_name jack failed."
133144 }
134145
135146 dlogi " Plug jack audio."
136147 usbrelay_switch " $relay " 0
137148
138149 # Wait for a short period to allow the system to detect the plug event
139- sleep $DSP_SETTLE_TIME
150+ sleep " $dsp_settle_time "
140151
141152 # check if the aplay process is still running after unplugging the jack
142153 ps -p " $pid_playback " > /dev/null || {
143154 func_lib_lsof_error_dump " $snd "
144155 die " Playback process terminated unexpectedly after plugging the jack."
145156 }
146157
147- check_control_switch_state " headset " " on" || {
148- die " Plug headset jack failed."
158+ check_control_switch_state " $headset_mic_jack_name " " on" || {
159+ die " Plug $headset_mic_jack_name failed."
149160 }
150161
151- check_control_switch_state " headphone " " on" || {
152- die " Plug headphone jack failed."
162+ check_control_switch_state " $headphone_jack_name " " on" || {
163+ die " Plug $headphone_jack_name jack failed."
153164 }
154165
155166 kill -9 $pid_playback > /dev/null 2>&1
0 commit comments