From 0f73690b33624e16355f2b2e66303cfd4663b59f Mon Sep 17 00:00:00 2001 From: Artur Wilczak Date: Mon, 20 Oct 2025 12:15:58 +0200 Subject: [PATCH 1/3] test: Skip before enabling logs to avoid failure The test ends with FAIL status despite the method skip_test being called next enabling logs. Reason of a fail: "Empty logfile" Signed-off-by: Artur Wilczak --- test-case/test-jack-detection-playback-capture.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test-case/test-jack-detection-playback-capture.sh b/test-case/test-jack-detection-playback-capture.sh index 8ebeb2f0..0811d6cf 100755 --- a/test-case/test-jack-detection-playback-capture.sh +++ b/test-case/test-jack-detection-playback-capture.sh @@ -171,14 +171,14 @@ 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." } + logger_disabled || func_lib_start_log_collect + # display current status of relays usbrelay --debug From da7bcbdca1cc9ddb71d9c5975c0841bfe60fb1b9 Mon Sep 17 00:00:00 2001 From: Artur Wilczak Date: Mon, 20 Oct 2025 13:51:43 +0200 Subject: [PATCH 2/3] test: fix checking state of a mixer device Add the three new test parameters: 1. headphone device name. 2. headset mic device name. 3. waiting time for change device state. Fix the function for checking a device state. Signed-off-by: Artur Wilczak --- case-lib/control_state.awk | 22 +++++++ .../test-jack-detection-playback-capture.sh | 65 ++++++++++--------- 2 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 case-lib/control_state.awk diff --git a/case-lib/control_state.awk b/case-lib/control_state.awk new file mode 100644 index 00000000..a462d51c --- /dev/null +++ b/case-lib/control_state.awk @@ -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 +} diff --git a/test-case/test-jack-detection-playback-capture.sh b/test-case/test-jack-detection-playback-capture.sh index 0811d6cf..c5d3be5c 100755 --- a/test-case/test-jack-detection-playback-capture.sh +++ b/test-case/test-jack-detection-playback-capture.sh @@ -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() { @@ -77,16 +87,8 @@ 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]; - } - ') + 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 @@ -116,7 +118,7 @@ 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 || { @@ -124,19 +126,19 @@ testing_one_pcm() 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 || { @@ -144,12 +146,12 @@ testing_one_pcm() 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 @@ -185,6 +187,9 @@ main() 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" From a7c0c666831fcf605b6d9ccb3232f6b40f8441bf Mon Sep 17 00:00:00 2001 From: Artur Wilczak Date: Tue, 21 Oct 2025 15:32:02 +0200 Subject: [PATCH 3/3] test: fix skipping: test jack detection Fix skip if no module named: usbrelay. Add skip if no relays hardware are detected. Signed-off-by: Artur Wilczak --- case-lib/relay.sh | 12 +++++++----- test-case/test-jack-detection-playback-capture.sh | 12 ++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/case-lib/relay.sh b/case-lib/relay.sh index 04034702..cc0d52dc 100644 --- a/case-lib/relay.sh +++ b/case-lib/relay.sh @@ -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 diff --git a/test-case/test-jack-detection-playback-capture.sh b/test-case/test-jack-detection-playback-capture.sh index c5d3be5c..f2533cdb 100755 --- a/test-case/test-jack-detection-playback-capture.sh +++ b/test-case/test-jack-detection-playback-capture.sh @@ -87,6 +87,7 @@ check_control_switch_state() local expected_control_state="$2" local control_state + 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" @@ -94,6 +95,7 @@ check_control_switch_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 } @@ -176,13 +178,15 @@ main() 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." } - logger_disabled || func_lib_start_log_collect - # 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