Skip to content

Commit a5b87c8

Browse files
committed
lib.sh: Reset ALSA settings at set_alsa()
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>
1 parent 61d513c commit a5b87c8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

case-lib/lib.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,42 @@ reset_sof_volume()
12471247
done
12481248
}
12491249

1250+
# Initialize and restore ALSA mixer state to the last saved on the DUT,
1251+
# reset volume, and apply the HW MODEL-specific settings, if defined.
1252+
#
1253+
# This initialization procedure assumes that the DUT's ALSA init files,
1254+
# UCM2, and default state (/var/lib/alsa/asound.state) are either kept
1255+
# unchanged as a 'golden' config, or _mostly_ consistent with the MODEL.
1256+
# The latter case is when the alsa-restore service is active on the DUT and
1257+
# the state file keeps the last active mixer settings persistent to restore
1258+
# them after the DUT's reboot.
1259+
# The init files and the persistent state file should diverge not more
1260+
# than set_alsa_settings() aligns and should be reset to a 'golden' config
1261+
# during the DUT's deployment step of the test plan execution,
1262+
# which is external to the test case scope of operations.
1263+
#
12501264
set_alsa()
12511265
{
1266+
local alsa_log="${LOG_ROOT}/alsa_setup.log"
1267+
local asound_state="${LOG_ROOT}/asound_state"
1268+
1269+
alsactl store -f "${asound_state}_old.txt" 2>&1 || rc=$?
1270+
[[ "${rc}" -ne 0 ]] && dlogw "alsactl store error=${rc}"
1271+
1272+
dlogi "Try to initialize all devices to their default ALSA state (alsactl init)."
1273+
printf '%s\n' '-vv------- ALSA init -------vv-' > "${alsa_log}"
1274+
alsactl -d init >> "${alsa_log}" 2>&1 || rc=$?
1275+
[[ "${rc}" -ne 0 ]] && dlogw "alsactl init error=${rc}"
1276+
printf '%s\n' '-^^------- ALSA init -------^^-' >> "${alsa_log}"
1277+
1278+
dlogi "Restore ALSA defaults from /var/lib/alsa/asound.state"
1279+
printf '%s\n' '-vv------- Restore ALSA defaults -------vv-' >> "${alsa_log}"
1280+
# We don't need in sudo to write our log file, but to call `alsactl`
1281+
# shellcheck disable=SC2024
1282+
sudo alsactl -d restore >> "${alsa_log}" 2>&1 || rc=$?
1283+
[[ "${rc}" -ne 0 ]] && dlogw "alsactl restore error=${rc}"
1284+
printf '%s\n' '-^^------- Restore ALSA defaults -------^^-' >> "${alsa_log}"
1285+
12521286
reset_sof_volume
12531287

12541288
# If MODEL is defined, set proper gain for the platform
@@ -1257,6 +1291,9 @@ set_alsa()
12571291
else
12581292
set_alsa_settings "$MODEL"
12591293
fi
1294+
1295+
alsactl store -f "${asound_state}.txt" 2>&1 || rc=$?
1296+
[[ "${rc}" -ne 0 ]] && dlogw "alsactl store error=${rc}"
12601297
}
12611298

12621299
DO_PERF_ANALYSIS=0

0 commit comments

Comments
 (0)