Skip to content

Conversation

@golowanow
Copy link
Member

Reset ALSA settings with alsactl init and alsactl restore at set_alsa() before it calls set_alsa_settings which runs HW model-specific configuration scripts.

This way a test case can expect that the set_alsa call will apply the DUT's default ALSA settings as the baseline configuration to avoid side-effects possible after the previous tests execution (either passed, or failed) as well as other unexpected changes.

Reuse set_alsa() function in test cases:

  check-alsa-conformance.sh
  check-alsabat.sh
  latency-metrics.sh

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
@golowanow golowanow force-pushed the alsa_reset_20250721 branch 2 times, most recently from 3ec5054 to 00a2d21 Compare July 23, 2025 12:38
Add log message to `reset_sof_volume()`. Stop with `die`
on incorrect ALSA tool the same way, as at the other places.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
@golowanow golowanow force-pushed the alsa_reset_20250721 branch from 00a2d21 to 1a82c40 Compare July 23, 2025 12:45
@golowanow golowanow added the improvement The issue or pull request improves already existing functionalities label Jul 23, 2025
Fix `shellcheck` warinings in check-alsabat.sh

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
@golowanow golowanow force-pushed the alsa_reset_20250721 branch from b319db5 to 3919ac5 Compare July 23, 2025 16:16
case-lib/lib.sh Outdated
dlogi "Try to initialize all devices to their default ALSA state (alsactl init)."
printf '%s\n' '-vv------- ALSA init -------vv-' > "${alsa_log}"
alsactl -d init >> "${alsa_log}" 2>&1 || rc=$?
[[ "${rc}" -ne 0 ]] && dlogw "alsactl init error=${rc}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just:

Suggested change
[[ "${rc}" -ne 0 ]] && dlogw "alsactl init error=${rc}"
alsactl -d init ... || dlogw "alsactl init error=$?"

Copy link
Member Author

Choose a reason for hiding this comment

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

dlogw clears $?, so it looks like

ls /foo || dloge "error=$?"

ls: cannot access '/foo': No such file or directory
2025-07-23 18:44:58 UTC [ERROR] error=0

vs.
ls /foo || rc=$? ; dloge "error=$rc"

ls: cannot access '/foo': No such file or directory
2025-07-23 18:43:36 UTC [ERROR] error=2

Copy link
Collaborator

Choose a reason for hiding this comment

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

OMG, they are aliases! Could you try to submit this fix that converts aliases to proper functions? I tested this change in isolation and it fixes the issue but I don't have time to submit it to CI.

Don't take the second diff hunk, it's just a hack to test locally.

--- a/case-lib/logging_ctl.sh
+++ b/case-lib/logging_ctl.sh
@@ -44,14 +44,15 @@ _func_log_cmd()
 
     for key in "${!LOG_LIST[@]}";
     do
-        # dymaic alias the command with different content
-        cmd="alias $key='echo \$(date -u \"+%F %T %Z\")$ext_message ${LOG_LIST[$key]}'"
+        # shellcheck disable=SC2016
+        local date_cmd='$(date -u "+%F %T %Z")'
+        local cmd="$key() { printf '%s%s %s\n' \"$date_cmd\" '$ext_message ${LOG_LIST[$key]}' \"\$*\" ; }"
         eval "$cmd"
     done
 }
 
 # without setting up the LOG_ROOT keyword, now create the log directory for it
-_func_log_directory()
+_Xfunc_log_directory()
 {
     # LOG_ROOT is the top of a single test run. SOF_LOGS_BASE is higher
     # up and for all tests and all runs.
source case-lib/logging_ctl.sh 
( exit 5 ) || dlogw "hello $?"
2025-07-23 20:01:08 UTC [WARNING] hello 5

Copy link
Member Author

@golowanow golowanow Jul 24, 2025

Choose a reason for hiding this comment

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

OMG, they are aliases! Could you try to submit this fix that converts aliases to proper functions?

Copy link
Collaborator

Choose a reason for hiding this comment

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

#1286 just merged, now this could be fixed.

At least it won't be needed elsewhere now...

@golowanow golowanow changed the title [SKIP SOF-TEST] ALSA reset ALSA reset Jul 23, 2025
@golowanow
Copy link
Member Author

SOFCI TEST

@golowanow golowanow force-pushed the alsa_reset_20250721 branch 2 times, most recently from 4da8136 to 1307ec7 Compare July 24, 2025 13:36
@golowanow
Copy link
Member Author

SOFCI TEST

@golowanow golowanow force-pushed the alsa_reset_20250721 branch 3 times, most recently from a5b87c8 to bd17598 Compare July 24, 2025 20:23
@golowanow golowanow changed the title ALSA reset [SKIP SOF-TEST] ALSA reset Jul 24, 2025
Reset ALSA settings with `alsactl init` and `alsactl restore`
at `set_alsa()` before it calls `set_alsa_settings` which runs
HW model-specific configuration scripts.

This way a test case can expect that the `set_alsa` call will apply
the DUT's ALSA mixer settings as the baseline configuration
to avoid side-effects possible after the previous tests execution
(either passed, or failed) as well as other unexpected changes.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
@golowanow golowanow force-pushed the alsa_reset_20250721 branch from bd17598 to 549d7ba Compare July 24, 2025 21:17
@golowanow golowanow changed the title [SKIP SOF-TEST] ALSA reset ALSA reset Jul 25, 2025
@golowanow golowanow marked this pull request as ready for review July 25, 2025 06:04
@golowanow golowanow requested review from a team and lgirdwood as code owners July 25, 2025 06:04
@golowanow
Copy link
Member Author

dear reviewers, do you have comments or objections ?
next is #1270 adjusted, to follow

Copy link
Contributor

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

Looks good @golowanow !

local rc=0

# Read the ALSA restore service status
systemctl --no-pager status alsa-restore.service > "${alsa_log}" 2>&1 || rc=$?
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose you could just rc=$? unconditionally after the systemctl call and remove the initialisation of rc

Copy link
Member Author

Choose a reason for hiding this comment

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

right, its my intent to deal with rc explicitly and to tie command calls and rc set, so it is declared as a local variable at this function with init value and, despite any change in the following command calls, it will have the default value.

With command || rc=$? the script works the same way if it runs with bash -e - continue its execution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You could probably do this but && has many pitfalls and is best avoided

systemctl --no-pager status alsa-restore.service > "${alsa_log}" 2>&1 && local rc=$?

@lyakh check the && pitfalls in #312


# Read the ALSA restore service status
systemctl --no-pager status alsa-restore.service > "${alsa_log}" 2>&1 || rc=$?
[[ "${rc}" -ne 0 ]] && dlogw "alsa-restore check error=${rc}" && rc=0
Copy link
Contributor

Choose a reason for hiding this comment

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

if for whatever reason dlogw exits with an error, rc won't be reset. I'd just use if here for determinism. More of these below, I'd be more explicit with rc

Copy link
Member Author

Choose a reason for hiding this comment

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

when dlogw fails (something really bad ? hopefully with some stderr output) the rc should not reset to zero as well.

Copy link
Contributor

@majunkier majunkier left a comment

Choose a reason for hiding this comment

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

LGTM

@golowanow golowanow merged commit d675ecf into thesofproject:main Aug 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement The issue or pull request improves already existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants