-
Notifications
You must be signed in to change notification settings - Fork 59
ALSA reset #1284
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
ALSA reset #1284
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -828,7 +828,7 @@ set_sof_volume() | |
| tinymix -D"$device" set "$control_name" "$value" | ||
| ;; | ||
| *) | ||
| die "Unknown alsa tool $SOF_ALSA_TOOL" | ||
| die "Unknown ALSA tool ${SOF_ALSA_TOOL}" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
@@ -847,7 +847,7 @@ get_sof_controls() | |
| tinymix --card "$sofcard" controls | ||
| ;; | ||
| *) | ||
| die "Unknown alsa tool $SOF_ALSA_TOOL" | ||
| die "Unknown ALSA tool ${SOF_ALSA_TOOL}" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
@@ -863,7 +863,7 @@ kill_play_record() | |
| pkill -9 tinyplay | ||
| ;; | ||
| *) | ||
| die "Unknown alsa tool $SOF_ALSA_TOOL" | ||
| die "Unknown ALSA tool ${SOF_ALSA_TOOL}" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
@@ -888,7 +888,7 @@ check_alsa_tool_process() | |
| die "tinyplay process is terminated too early" | ||
| ;; | ||
| *) | ||
| die "Unknown alsa tool $SOF_ALSA_TOOL" | ||
| die "Unknown ALSA tool ${SOF_ALSA_TOOL}" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
@@ -911,7 +911,7 @@ aplay_opts() | |
| # shellcheck disable=SC2086 | ||
| aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@" | ||
| else | ||
| die "Unknown ALSA tool: $SOF_ALSA_TOOL" | ||
| die "Unknown ALSA tool: ${SOF_ALSA_TOOL}" | ||
| fi | ||
| } | ||
|
|
||
|
|
@@ -930,7 +930,7 @@ arecord_opts() | |
| # shellcheck disable=SC2086 | ||
| arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@" | ||
| else | ||
| die "Unknown ALSA tool: $SOF_ALSA_TOOL" | ||
| die "Unknown ALSA tool: ${SOF_ALSA_TOOL}" | ||
| fi | ||
| } | ||
|
|
||
|
|
@@ -1236,16 +1236,72 @@ reset_sof_volume() | |
| get_sof_controls "0" | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' | | ||
| while read -r mixer_name | ||
| do | ||
| dlogi "Reset volume to ${level_db} on ${mixer_name}" | ||
| if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then | ||
| amixer -Dhw:0 -- sset "$mixer_name" "$level_db" | ||
| elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then | ||
| elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then | ||
| tinymix -D0 set "$mixer_name" "$level_db" | ||
| else | ||
| echo "Unknown alsa tool $SOF_ALSA_TOOL" | ||
| break | ||
| die "Unknown ALSA tool ${SOF_ALSA_TOOL}" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| # Initialize and restore ALSA mixer state to the last saved on the DUT, | ||
| # reset volume, and apply the HW MODEL-specific settings, if defined. | ||
| # | ||
| # This initialization procedure assumes that the DUT's ALSA init files, | ||
| # UCM2, and default state (/var/lib/alsa/asound.state) are either kept | ||
| # unchanged as a 'golden' config, or _mostly_ consistent with the MODEL. | ||
| # The latter case is when the alsa-restore service is active on the DUT and | ||
| # the state file keeps the last active mixer settings persistent to restore | ||
| # them after the DUT's reboot. | ||
| # The init files and the persistent state file should diverge not more | ||
| # than set_alsa_settings() aligns and should be reset to a 'golden' config | ||
| # during the DUT's deployment step of the test plan execution, | ||
| # which is external to the test case scope of operations. | ||
| # | ||
| set_alsa() | ||
| { | ||
| local alsa_log="${LOG_ROOT}/alsa_setup.log" | ||
| local asound_state="${LOG_ROOT}/asound_state" | ||
| local rc=0 | ||
|
|
||
| # 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if for whatever reason
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when |
||
| [ -f /lib/systemd/system/alsa-restore.service ] && cat /lib/systemd/system/alsa-restore.service >> "${alsa_log}" | ||
|
|
||
| alsactl store -f "${asound_state}_old.txt" 2>&1 || rc=$? | ||
| [[ "${rc}" -ne 0 ]] && dlogw "alsactl store error=${rc}" && rc=0 | ||
|
|
||
| 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}" && rc=0 | ||
| printf '%s\n' '-^^------- ALSA init -------^^-' >> "${alsa_log}" | ||
|
|
||
| dlogi "Restore ALSA defaults from /var/lib/alsa/asound.state" | ||
| printf '%s\n' '-vv------- Restore ALSA defaults -------vv-' >> "${alsa_log}" | ||
| # We don't need in sudo to write our log file, but to call `alsactl` | ||
| # shellcheck disable=SC2024 | ||
| sudo alsactl -d restore >> "${alsa_log}" 2>&1 || rc=$? | ||
| [[ "${rc}" -ne 0 ]] && dlogw "alsactl restore error=${rc}" && rc=0 | ||
| printf '%s\n' '-^^------- Restore ALSA defaults -------^^-' >> "${alsa_log}" | ||
|
|
||
| reset_sof_volume | ||
|
|
||
| # If MODEL is defined, set proper gain for the platform | ||
| if [ -z "$MODEL" ]; then | ||
| dlogw "NO MODEL is defined. Please define MODEL to run alsa_settings/\${MODEL}.sh" | ||
| else | ||
| set_alsa_settings "$MODEL" | ||
| fi | ||
|
|
||
| alsactl store -f "${asound_state}.txt" 2>&1 || rc=$? | ||
| [[ "${rc}" -ne 0 ]] && dlogw "alsactl store error=${rc}" | ||
| } | ||
|
|
||
| DO_PERF_ANALYSIS=0 | ||
|
|
||
| perf_analyze() | ||
|
|
||
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 suppose you could just
rc=$?unconditionally after thesystemctlcall and remove the initialisation ofrcThere 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.
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 withbash -e- continue its execution.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 could probably do this but
&&has many pitfalls and is best avoided@lyakh check the
&&pitfalls in #312