Skip to content

Commit e548c1d

Browse files
committed
test: add test: jack detection if DSP is in D3
Add a new test case to test jack detection during DSP is in D3 state. The test will check if the jack detection status is updated correctly when the jack is plugged in and unplugged and also if DSP status is changing correctly as well. For unplug/plug headset jack is using a USB relay. https://github.com/darrylb123/usbrelay Signed-off-by: Artur Wilczak <arturx.wilczak@intel.com>
1 parent 2a5fa11 commit e548c1d

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#!/bin/bash
2+
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
# Copyright(c) 2025 Intel Corporation. All rights reserved.
5+
6+
##
7+
## Preconditions
8+
# USB relay switch is available and configured.
9+
# Jack detection header should be connected to the USB relay switch
10+
# to the port HURTM_2 (NC) connector.
11+
12+
## Test Description
13+
# Verify jack detection functionality by simulating plugging and unplugging
14+
# of audio jack using a USB relay switch.
15+
# The unplugging and plugging of the jack is when DSP is in D3 state (suspend)
16+
# to ensure the system can handle jack detection events correctly.
17+
# The test will check if the jack detection status is updated correctly
18+
# when the jack is plugged in and unplugged and if DSP status is changing
19+
# correctly as well.
20+
21+
22+
TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
23+
TESTLIB="${TESTDIR}/case-lib"
24+
25+
# shellcheck disable=SC1091 source=case-lib/lib.sh
26+
source "${TESTLIB}/lib.sh"
27+
# shellcheck disable=SC1091 source=case-lib/relay.sh
28+
source "${TESTLIB}/relay.sh"
29+
30+
# shellcheck disable=SC2153
31+
OPT_NAME['t']='tplg' OPT_DESC['t']="tplg file, default value is env TPLG: $TPLG"
32+
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"
33+
34+
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
35+
OPT_HAS_ARG['l']=1 OPT_VAL['l']=1
36+
37+
OPT_NAME['s']='sof-logger' OPT_DESC['s']="open sof-logger trace the data will store at $LOG_ROOT"
38+
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
39+
40+
OPT_NAME['d']='dsp-settle-sleep' OPT_DESC['d']="waiting time to change DSP state"
41+
OPT_HAS_ARG['d']=1 OPT_VAL['d']=5
42+
43+
OPT_NAME['r']='relay-settle-sleep' OPT_DESC['r']="waiting time to stable after relay change state"
44+
OPT_HAS_ARG['r']=1 OPT_VAL['r']=1
45+
46+
OPT_NAME['u']='relay' OPT_DESC['u']='name of usbrelay switch, default value is HURTM_2'
47+
OPT_HAS_ARG['u']=1 OPT_VAL['u']="HURTM_2"
48+
49+
OPT_NAME['H']='headphone' OPT_DESC['H']='name of pcm control for headphone jack'
50+
OPT_HAS_ARG['H']=1 OPT_VAL['H']="headphone jack"
51+
52+
OPT_NAME['M']='headset' OPT_DESC['M']='name of pcm control for headset mic jack'
53+
OPT_HAS_ARG['M']=1 OPT_VAL['M']="headset [a-z ]*jack"
54+
55+
func_opt_parse_option "$@"
56+
57+
tplg=${OPT_VAL['t']}
58+
relay=${OPT_VAL['u']}
59+
loop_cnt=${OPT_VAL['l']}
60+
dsp_settle_time=${OPT_VAL['d']}
61+
relay_settle_time=${OPT_VAL['r']}
62+
headphone_jack_name=${OPT_VAL['H']}
63+
headset_mic_jack_name=${OPT_VAL['M']}
64+
65+
66+
func_check_dsp_status()
67+
{
68+
dlogi "Wait DSP power status to become suspended"
69+
for i in $(seq 1 $1)
70+
do
71+
# Here we pass a hardcoded 0 to python script, and need to ensure
72+
# DSP is the first audio pci device in 'lspci', this is true unless
73+
# we have a third-party pci sound card installed.
74+
[[ $(sof-dump-status.py --dsp_status 0) == "suspended" ]] && break
75+
sleep 1
76+
if [ $i -eq $1 ]; then
77+
die "DSP is not suspended after $1s, end test"
78+
fi
79+
done
80+
dlogi "DSP suspended in ${i}s"
81+
}
82+
83+
check_control_switch_state()
84+
{
85+
# Check the state of the switch using amixer.
86+
# The switch name is passed as the first argument, and the expected state (on/off)
87+
# is passed as the second argument.
88+
# Returns 0 if the state matches, 1 otherwise.
89+
local control_name="$1"
90+
local expected_control_state="$2"
91+
local control_state
92+
93+
dlogi "Check if the state of control: $control_name is correct."
94+
control_state=$(amixer -c "$SOFCARD" contents | \
95+
gawk -v name="$control_name" -f "${TESTLIB}/control_state.awk")
96+
dlogi "$control_name switch is: $control_state"
97+
98+
if [[ "$expected_control_state" == "$control_state" ]]; then
99+
return 0
100+
else
101+
dloge "Expected control state ($expected_control_state) but got ($control_state)."
102+
return 1
103+
fi
104+
}
105+
106+
testing_one_pcm()
107+
{
108+
dlogi "===== Testing: (Round: $i/$loop_cnt) (PCM: $pcm [$dev]<$type>) ====="
109+
dlogi "DEVICE: $dev, TYPE: $type, PCM: $pcm, RATE: $rate, CHANNEL: $channel"
110+
111+
[[ $(sof-dump-status.py --dsp_status 0) == "suspended" ]] || {
112+
die "Current DSP status is not suspended."
113+
}
114+
115+
dlogi "Unplug jack audio."
116+
usbrelay_switch "$relay" 1
117+
118+
dlogi "Wait for ${relay_settle_time}s to ensure jack detection is off"
119+
sleep "$relay_settle_time"
120+
121+
check_control_switch_state "$headset_mic_jack_name" "off" || {
122+
die "unplug $headset_mic_jack_name failed."
123+
}
124+
125+
check_control_switch_state "$headphone_jack_name" 'off' || {
126+
die "unplug $headphone_jack_name failed."
127+
}
128+
129+
func_check_dsp_status "$dsp_settle_time"
130+
131+
dlogi "Plug jack audio."
132+
usbrelay_switch "$relay" 0
133+
134+
dlogi "Wait for ${relay_settle_time}s to ensure jack detection is on"
135+
sleep "$relay_settle_time"
136+
137+
check_control_switch_state "$headset_mic_jack_name" "on" || {
138+
die "Plug $headset_mic_jack_name failed."
139+
}
140+
141+
check_control_switch_state "$headphone_jack_name" "on" || {
142+
die "Plug $headphone_jack_name failed."
143+
}
144+
145+
func_check_dsp_status "$dsp_settle_time"
146+
}
147+
148+
main()
149+
{
150+
func_pipeline_export "$tplg" "type:playback"
151+
152+
setup_kernel_check_point
153+
154+
start_test
155+
156+
dlogi "Checking usbrelay availability..."
157+
command -v usbrelay || {
158+
# If usbrelay package is not installed
159+
skip_test "usbrelay command not found."
160+
}
161+
162+
usbrelay_switch --debug || {
163+
skip_test "Failed to get usbrelay status."
164+
}
165+
166+
dlogi "Reset USB Relay - plug jack audio."
167+
usbrelay_switch "$relay" 0
168+
169+
for idx in $(seq 0 $((PIPELINE_COUNT - 1)))
170+
do
171+
initialize_audio_params "$idx"
172+
173+
[[ "$pcm" == *Jack* ]] || {
174+
dlogi "PCM $pcm is not a Jack, skipping..."
175+
continue
176+
}
177+
178+
for i in $(seq 1 "$loop_cnt")
179+
do
180+
testing_one_pcm
181+
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT"
182+
setup_kernel_check_point
183+
done
184+
done
185+
}
186+
187+
{
188+
main "$@"; exit "$?"
189+
}

0 commit comments

Comments
 (0)