Skip to content

Commit

Permalink
kselftest/alsa: Fix validation of writes to volatile controls
Browse files Browse the repository at this point in the history
When validating writes to controls we check that whatever value we wrote
actually appears in the control.  For volatile controls we cannot assume
that this will be the case, the value may be changed at any time
including between our write and read.  Handle this by moving the check
for volatile controls that we currently do for events to a separate
block and just verifying that whatever value we read is valid for the
control.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20240614-alsa-selftest-volatile-v1-1-3874f02964b1@kernel.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/20240616073454.16512-5-tiwai@suse.de
  • Loading branch information
Mark Brown authored and Takashi Iwai committed Jun 18, 2024
1 parent 50ed081 commit 1b1285e
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions tools/testing/selftests/alsa/mixer-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,29 +625,42 @@ static int write_and_verify(struct ctl_data *ctl,
return err;
}

/*
* We can't verify any specific value for volatile controls
* but we should still check that whatever we read is a valid
* vale for the control.
*/
if (snd_ctl_elem_info_is_volatile(ctl->info)) {
if (!ctl_value_valid(ctl, read_val)) {
ksft_print_msg("Volatile control %s has invalid value\n",
ctl->name);
return -EINVAL;
}

return 0;
}

/*
* Check for an event if the value changed, or confirm that
* there was none if it didn't. We rely on the kernel
* generating the notification before it returns from the
* write, this is currently true, should that ever change this
* will most likely break and need updating.
*/
if (!snd_ctl_elem_info_is_volatile(ctl->info)) {
err = wait_for_event(ctl, 0);
if (snd_ctl_elem_value_compare(initial_val, read_val)) {
if (err < 1) {
ksft_print_msg("No event generated for %s\n",
ctl->name);
show_values(ctl, initial_val, read_val);
ctl->event_missing++;
}
} else {
if (err != 0) {
ksft_print_msg("Spurious event generated for %s\n",
ctl->name);
show_values(ctl, initial_val, read_val);
ctl->event_spurious++;
}
err = wait_for_event(ctl, 0);
if (snd_ctl_elem_value_compare(initial_val, read_val)) {
if (err < 1) {
ksft_print_msg("No event generated for %s\n",
ctl->name);
show_values(ctl, initial_val, read_val);
ctl->event_missing++;
}
} else {
if (err != 0) {
ksft_print_msg("Spurious event generated for %s\n",
ctl->name);
show_values(ctl, initial_val, read_val);
ctl->event_spurious++;
}
}

Expand Down

0 comments on commit 1b1285e

Please sign in to comment.