Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions case-lib/control_state.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/gawk -f

# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2025 Intel Corporation. All rights reserved.

BEGIN {
IGNORECASE = 1
found = 0
}

# Detect the line with the control name
/name='/ {
if (tolower($0) ~ tolower(name)) found = 1
else found = 0
}

# When in a matching section, extract the "values" field
found && /: values=/ {
sub(/^.*: values=/, "", $0)
print $0
found = 0
}
12 changes: 7 additions & 5 deletions case-lib/relay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ usbrelay_switch()
{
if [[ "$1" == "--debug" ]]; then
dlogi "Debug mode: Current status of all relays:"
usbrelay || {
die "Failed to get usbrelay status.
The usbrelay hw module is not responding or no relays detected.
Check hardware connection."
}
if usbrelay --debug 2>&1 | grep -q "Found 0 devices"; then
dloge "No relays detected. Found 0 devices. Check hardware connection."
dloge "The usbrelay hw module is not responding or no relays detected. Check hardware connection."
# Skip the test if no relays are detected
exit 2
fi
return 0
fi

# Declare a constant for the relay settle time
Expand Down
79 changes: 44 additions & 35 deletions test-case/test-jack-detection-playback-capture.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit subject and message are quite vague. You could be more specific, something like: "Skip before enabling logs to avoid failure".

Also: why does the moved line fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because in this case the log is empty, and an error is raised:
[ERROR] Empty logfile

commit msg - I'll change

Copy link
Collaborator

@marc-hb marc-hb Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because in this case the log is empty, and an error is raised:
[ERROR] Empty logfile

This is still not clear; there are multiple tests that do that in the same order and they never failed like this.

git grep -e skip_test -e start_log_

test-case/volume-basic-test.sh
test-case/multiple-pause-resume.sh
test-case/test-jack-detection-playback-capture.sh
test-case/test-mic-privacy.sh

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think this commit is just hiding another, unknown issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark this is not the same case. For example volume-basic-test.sh
Between a logger_disabled and first appearance of skip_test there are many of commands generate logs to log file.

start_test

[[ -z $tplg ]] && die "Missing tplg file needed to run"
func_pipeline_export "$tplg" "type:playback"
logger_disabled || func_lib_start_log_collect

[[ $PIPELINE_COUNT -eq 0 ]] && die "Missing playback pipeline for aplay to run"

initialize_audio_params "0"
# play into background, this will wake up DSP and IPC. Need to clean after the test
aplay_opts -D "$dev" -c "$channel" -r "$rate" -f "$fmts" /dev/zero &
sleep 1
check_alsa_tool_process
sofcard=${SOFCARD:-0}

# https://mywiki.wooledge.org/BashFAQ/024 why cant I pipe data to read?
readarray -t pgalist < <("$TOPDIR"/tools/topo_vol_kcontrols.py "$tplg")

# This (1) provides some logging (2) avoids skip_test if amixer fails
get_sof_controls "$sofcard"
dlogi "pgalist number = ${#pgalist[@]}"
[[ ${#pgalist[@]} -ne 0 ]] || skip_test "No PGA control is available"

Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,35 @@ source "${TESTLIB}/lib.sh"
source "${TESTLIB}/relay.sh"

# shellcheck disable=SC2153
OPT_NAME['t']='tplg' OPT_DESC['t']="tplg file, default value is env TPLG: $TPLG"
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"
OPT_NAME['t']='tplg' OPT_DESC['t']="tplg file, default value is env TPLG: $TPLG"
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"

OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
OPT_HAS_ARG['l']=1 OPT_VAL['l']=1
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
OPT_HAS_ARG['l']=1 OPT_VAL['l']=1

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['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['u']='relay' OPT_DESC['u']='name of usbrelay switch, default value is HURTM_2'
OPT_HAS_ARG['u']=1 OPT_VAL['u']="HURTM_2"
OPT_NAME['d']='dsp-settle-sleep' OPT_DESC['d']="Waitng time to change control state"
OPT_HAS_ARG['d']=1 OPT_VAL['d']=3

OPT_NAME['u']='relay' OPT_DESC['u']='name of usbrelay switch, default value is HURTM_2'
OPT_HAS_ARG['u']=1 OPT_VAL['u']="HURTM_2"

OPT_NAME['H']='headphone' OPT_DESC['H']='name of pcm control for headphone jack'
OPT_HAS_ARG['H']=1 OPT_VAL['H']="headphone jack"

OPT_NAME['M']='headset' OPT_DESC['M']='name of pcm control for headset mic jack'
OPT_HAS_ARG['M']=1 OPT_VAL['M']="headset [a-z ]*jack"

func_opt_parse_option "$@"

tplg=${OPT_VAL['t']}
relay=${OPT_VAL['u']}
loop_cnt=${OPT_VAL['l']}

DSP_SETTLE_TIME=2
dsp_settle_time=${OPT_VAL['d']}
headphone_jack_name=${OPT_VAL['H']}
headset_mic_jack_name=${OPT_VAL['M']}

check_control_switch_state()
{
Expand All @@ -77,21 +87,15 @@ check_control_switch_state()
local expected_control_state="$2"
local control_state

control_state=$(amixer -c "$SOFCARD" contents | awk -v name="$control_name" '
BEGIN {
RS = "";
IGNORECASE = 1;
split(name, parts, " ");
};
$0 ~ parts[1] && $0 ~ parts[2] {
if (match($0, /values=(on|off)/, m)) print m[1];
}
')
dlogi "Check if the state of control: $control_name is correct."
control_state=$(amixer -c "$SOFCARD" contents | \
gawk -v name="$control_name" -f "${TESTLIB}/control_state.awk")
dlogi "$control_name switch is: $control_state"

if [[ "$expected_control_state" == "$control_state" ]]; then
return 0
else
dloge "Expected control state ($expected_control_state) but got ($control_state)."
return 1
fi
}
Expand All @@ -116,40 +120,40 @@ testing_one_pcm()
usbrelay_switch "$relay" 1

# Wait for a short period to allow the system to detect the unplug event
sleep $DSP_SETTLE_TIME
sleep "$dsp_settle_time"

# check if the aplay process is still running after unplugging the jack
ps -p "$pid_playback" > /dev/null || {
func_lib_lsof_error_dump "$snd"
die "Playback process terminated unexpectedly after unplugging the jack."
}

check_control_switch_state "headset" "off" || {
die "unplug headset jack failed."
check_control_switch_state "$headset_mic_jack_name" "off" || {
die "unplug $headset_mic_jack_name jack failed."
}

check_control_switch_state "headphone" 'off' || {
die "unplug headphone jack failed."
check_control_switch_state "$headphone_jack_name" "off" || {
die "unplug $headphone_jack_name jack failed."
}

dlogi "Plug jack audio."
usbrelay_switch "$relay" 0

# Wait for a short period to allow the system to detect the plug event
sleep $DSP_SETTLE_TIME
sleep "$dsp_settle_time"

# check if the aplay process is still running after unplugging the jack
ps -p "$pid_playback" > /dev/null || {
func_lib_lsof_error_dump "$snd"
die "Playback process terminated unexpectedly after plugging the jack."
}

check_control_switch_state "headset" "on" || {
die "Plug headset jack failed."
check_control_switch_state "$headset_mic_jack_name" "on" || {
die "Plug $headset_mic_jack_name failed."
}

check_control_switch_state "headphone" "on" || {
die "Plug headphone jack failed."
check_control_switch_state "$headphone_jack_name" "on" || {
die "Plug $headphone_jack_name jack failed."
}

kill -9 $pid_playback > /dev/null 2>&1
Expand All @@ -171,20 +175,25 @@ main()

start_test

logger_disabled || func_lib_start_log_collect

# Check if usbrelay tool is installed
dlogi "Checking usbrelay availability..."
command -v usbrelay || {
# If usbrelay package is not installed
skip_test "usbrelay command not found. Please install usbrelay package."
skip_test "usbrelay command not found."
}

# display current status of relays
usbrelay --debug
usbrelay_switch --debug || {
skip_test "Failed to get usbrelay status."
}

logger_disabled || func_lib_start_log_collect

dlogi "Reset - plug jack audio"
usbrelay_switch "$relay" 0

dlogi "Headphone patten: $headphone_jack_name"
dlogi "Headset mic pattern: $headset_mic_jack_name"

for idx in $(seq 0 $((PIPELINE_COUNT - 1)))
do
initialize_audio_params "$idx"
Expand Down