-
Notifications
You must be signed in to change notification settings - Fork 59
test-case: add test jack detection playback #1280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test-case: add test jack detection playback #1280
Conversation
b5952dd to
61a5222
Compare
fd37446 to
2859a70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't look at the code much but there is seems to be some duplication with #1278?
| # Repeat for both headphone and headset jacks. | ||
| # Repeat for all pipelines. | ||
|
|
||
| source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing this line, see other scripts.
shellcheck source=...
case-lib/lib.sh
Outdated
| local switch_name=$1 | ||
| local state=$2 | ||
| dlogi "Setting usbrelay switch $switch_name to $state." | ||
| usbrelay "$switch_name=$state" >/dev/null 2>&1 || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discarding stderr is still very wrong:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you right Marc I missed it
2859a70 to
6b859f9
Compare
marc-hb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are very close to fixing ALL shellcheck warnings!
| local expected_switch_state="$2" | ||
| local switch_state | ||
|
|
||
| switch_state=$(echo -e $(amixer -c 0 contents | grep -i "$switch_name .* *jack" -A 2) | sed -n '1s/^.*values=//p') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use $SOFCARD instead of hardcoding to 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the echo -e achieve?
BTW: https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo
But better use none if none needed in the first place.
| dlogi "Reset - plug jack audio" | ||
| usbrelay_switch "$relay" 0 | ||
|
|
||
| for round in $(seq 1 "$round_cnt") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use while or shellcheck disable=SC2034
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should I use while?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you never use shellcheck?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very strange: in https://github.com/thesofproject/sof-test/actions/runs/16506744373/job/46679195194 shellcheck complained like this:
In test-case/test-jack-detection-playback-capture.sh line 108:
for round in $(seq 1 "$round_cnt")
^-^ SC2034 (warning): round appears unused. Verify use (or export if used externally).
But now it's gone in newer https://github.com/thesofproject/sof-test/actions/runs/16507901117/job/46683162054?pr=1280
EDIT: maybe that went away when you added shellcheck source=?
(The dubious echo on line 79 is flagged in both)
| done | ||
| done | ||
|
|
||
| sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check after each iteration to "fail fast"?
| for round in $(seq 1 "$round_cnt") | ||
| do | ||
| for idx in $(seq 0 $((PIPELINE_COUNT - 1))) | ||
| do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more readable to move this to some new test_one_idx() function (better name wanted), that would avoid a lot of indentation and a lot of distance between the start and end of the for loops.
4fcce37 to
4ecdc5c
Compare
case-lib/lib.sh
Outdated
| die "Error: Unknown format: %s\n" | ||
| fi | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep git clean, don't mix pure whitespace changes with code changes; especially not when it's far away in a completely different file.
https://wiki.openstack.org/wiki/GitCommitMessages#Things_to_avoid_when_creating_commits
case-lib/relay.sh
Outdated
| local state=$2 | ||
|
|
||
| dlogi "Setting usbrelay switch $switch_name to $state." | ||
| usbrelay "$switch_name=$state" > /dev/null || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How verbose is usbrelay, can you share an example of what is getting discarded here?
This is test code; as long as their size stays reasonable, logs files should have as much information as possible. Imagine trying to make sense of test logs captured on a system you don't have access to.
BTW usbrelay has a --quiet option, why not just use it instead of /dev/null ? Only if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ubuntu@gk-ptlh-rvp-05:~$ usbrelay HURTM_1=1
HURTM_1=0
HURTM_2=0
the verbose is unnecessary for us and it is confused because display previous state of the relay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the verbose is unnecessary for us and it is confused because display previous state of the relay.
so just call it twice then: before and after to log the change is done (as it is at line 35 already)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the current state after switching is verified in this line
[[ "$current_state" == "$state" ]]
case-lib/relay.sh
Outdated
| sleep "$USBRELAY_SETTLE_TIME" | ||
|
|
||
| # Display current state of the switch | ||
| current_state=$(usbrelay | grep "$switch_name" | awk -F= '{print $2}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awk has grep built-in.
| current_state=$(usbrelay | grep "$switch_name" | awk -F= '{print $2}') | |
| current_state=$(usbrelay | awk -F= "/$switch_name/ {print \$2}") |
Or, if you prefer
| current_state=$(usbrelay | grep "$switch_name" | awk -F= '{print $2}') | |
| current_state=$(usbrelay | awk -F= "/$switch_name/"' {print $2}') |
| dlogi "Reset - plug jack audio" | ||
| usbrelay_switch "$relay" 0 | ||
|
|
||
| for round in $(seq 1 "$round_cnt") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very strange: in https://github.com/thesofproject/sof-test/actions/runs/16506744373/job/46679195194 shellcheck complained like this:
In test-case/test-jack-detection-playback-capture.sh line 108:
for round in $(seq 1 "$round_cnt")
^-^ SC2034 (warning): round appears unused. Verify use (or export if used externally).
But now it's gone in newer https://github.com/thesofproject/sof-test/actions/runs/16507901117/job/46683162054?pr=1280
EDIT: maybe that went away when you added shellcheck source=?
(The dubious echo on line 79 is flagged in both)
4ecdc5c to
5f74c00
Compare
|
Thank you @marc-hb for your review, it was very helpful. I hope the code now meets your requirements. |
marc-hb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was very helpful.
My pleasure.
I hope the code now meets your requirements.
I don't have any requirement; I just try to spot common shell mistakes (after shellcheck caught most of them).
The shell is quirky, everyone keeps making the same mistakes.
| } | ||
|
|
||
| kill -9 $pid_playback > /dev/null 2>&1 | ||
| wait $pid_playback 2>/dev/null || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope we already have some code for this, maybe in case-lib/
(every script tries to re-invent this)
| sleep $TWO_SECONDS | ||
|
|
||
| # check if the aplay process is still running after unplugging the jack | ||
| ps -p "$pid_playback" > /dev/null || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope we already have some code for this, maybe in case-lib/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO ps -p is more explicit about checking for a process
f4090f4 to
13d9d4e
Compare
|
|
||
| ## | ||
| ## Preconditions | ||
| # 1. Runtime PM status is on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # 1. Runtime PM status is on. | |
| # 1. Runtime PM status is on. |
please elaborate what is PM here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PM is power management but this point was required in previous version. Should be removed.
| ## Preconditions | ||
| # 1. Runtime PM status is on. | ||
| # 2. aplay (playback) is running. | ||
| # 3. USB relay switch is available and configured. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be any USB relay switch or of some particular type is required ?
How it should be configured ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It must be same type of USB relay switch
https://github.com/darrylb123/usbrelay
if change type of USB relay switch we will must update the usbrelay_switch() function.
| ## Test Description | ||
| # Verify jack detection functionality by simulating plugging and unplugging | ||
| # of audio jack using a USB relay switch. | ||
| # The unplugging and plugging of the jack will be during playback operations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the test also try jack detection while no playback is running and its handling is correct in this mode ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this scenario will test in a different test - test_jack_detection_during_suspend
case-lib/relay.sh
Outdated
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # Copyright(c) 2021-2025 Intel Corporation. All rights reserved. | ||
|
|
||
| # test-mic_privacy.sh needs to control mic privacy settings (on/off) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # test-mic_privacy.sh needs to control mic privacy settings (on/off) |
| # Declare a constant for the relay settle time | ||
| USBRELAY_SETTLE_TIME=0.5 | ||
|
|
||
| local switch_name=$1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it run with $1 == --debug ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case-lib/relay.sh
Outdated
| } | ||
|
|
||
| # Declare a constant for the relay settle time | ||
| USBRELAY_SETTLE_TIME=0.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| USBRELAY_SETTLE_TIME=0.5 | |
| local USBRELAY_SETTLE_TIME=0.5 |
case-lib/relay.sh
Outdated
| local state=$2 | ||
|
|
||
| dlogi "Setting usbrelay switch $switch_name to $state." | ||
| usbrelay "$switch_name=$state" > /dev/null || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the verbose is unnecessary for us and it is confused because display previous state of the relay.
so just call it twice then: before and after to log the change is done (as it is at line 35 already)
| # Check if usbrelay tool is installed | ||
| command -v usbrelay || { | ||
| # If usbrelay package is not installed | ||
| skip_test "usbrelay command not found. Please install usbrelay package." | ||
| } | ||
|
|
||
| # display current status of relays | ||
| usbrelay --debug || die "usbrelay actual state read failed." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a good function at relay.sh
| for i in $(seq 1 "$loop_cnt") | ||
| do | ||
| testing_one_pcm | ||
| sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in these two nested loops it should either die on the first errors here, or set new kernel check point on each iteration.
13d9d4e to
739afef
Compare
739afef to
4651e82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new test case to verify jack detection functionality during audio playback operations using a USB relay switch to simulate physical plugging/unplugging of audio jacks.
- Adds test script that uses USB relay to simulate jack plug/unplug events during playback
- Creates relay utility library for controlling USB relay switches
- Updates environment check to include usbrelay package dependency
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test-case/test-jack-detection-playback-capture.sh | Main test script implementing jack detection testing during playback |
| env-check.sh | Adds usbrelay package check to environment validation |
| case-lib/relay.sh | Utility library for controlling USB relay switches |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| # 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." |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message refers to 'unplugging' but this code path is executed after plugging the jack (line 136). The message should say 'after plugging the jack' to match the actual context.
| die "Playback process terminated unexpectedly after unplugging the jack." | |
| die "Playback process terminated unexpectedly after plugging the jack." |
case-lib/relay.sh
Outdated
| # param1: --debug | ||
| # param1: switch name | ||
| # param2: switch state |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter documentation is inconsistent. Both lines refer to 'param1' but they describe different parameters. The first should be 'param1: --debug' and the second should be 'param2: switch name' or document the overloaded behavior more clearly.
| # param1: --debug | |
| # param1: switch name | |
| # param2: switch state | |
| # param1: Either '--debug' to show relay status, or switch name to set state | |
| # param2: switch state (required if param1 is switch name) |
case-lib/relay.sh
Outdated
| usbrelay_switch() | ||
| { | ||
| [[ "$1" == "--debug" ]] && { | ||
| dlogi "Debug mode: Current status of all relays is:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| dlogi "Debug mode: Current status of all relays is:" | |
| dlogi "Debug mode: Current status of all relays:" |
| # | ||
| # Repeat steps 3-11 for all pcm jack playback devices. | ||
|
|
||
| TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) | |
| TESTDIR=$(realpath -e "$(dirname "${BASH_SOURCE[0]}")/..") |
| 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['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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inconsistent indents between OPTS.
4651e82 to
ae2db23
Compare
ae2db23 to
60ed279
Compare
60ed279 to
91dfa5c
Compare
|
This has the same |
The file is added in the separate PR 1280: thesofproject#1280 Signed-off-by: Artur Wilczak <arturx.wilczak@intel.com>
Add a new test case to test jack detection during playback. The test checks all playback Jack PCM devices For unplug/plug headset jack is using a USB relay. https://github.com/darrylb123/usbrelay Signed-off-by: Artur Wilczak <arturx.wilczak@intel.com>
The file is added in the separate PR 1278: thesofproject#1278 Signed-off-by: Artur Wilczak <arturx.wilczak@intel.com>
91dfa5c to
ce0d396
Compare
The file is added in the separate PR 1280: #1280 Signed-off-by: Artur Wilczak <arturx.wilczak@intel.com>
Add a new test case to test jack detection during playback.
Verify jack detection functionality by simulating plugging and unplugging of audio jack using a USB relay switch.
The unplugging and plugging of the jack will be during playback operations to ensure the system can handle jack detection events correctly.
The test will check if the jack detection status is updated correctly when the jack is plugged in and unplugged.
For unplug/plug headset jack is using a USB relay. https://github.com/darrylb123/usbrelay