Skip to content

Commit c92b576

Browse files
broonietiwai
authored andcommitted
selftests: alsa: Start validating control names
Not much of a test but we keep on getting problems with boolean controls not being called Switches so let's add a few basic checks to help people spot problems. Signed-off-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20220421115020.14118-1-broonie@kernel.org Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 67d6406 commit c92b576

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

tools/testing/selftests/alsa/mixer-test.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#include "../kselftest.h"
2929

30-
#define TESTS_PER_CONTROL 6
30+
#define TESTS_PER_CONTROL 7
3131

3232
struct card_data {
3333
snd_ctl_t *handle;
@@ -456,6 +456,44 @@ static void test_ctl_get_value(struct ctl_data *ctl)
456456
ctl->card->card, ctl->elem);
457457
}
458458

459+
static bool strend(const char *haystack, const char *needle)
460+
{
461+
size_t haystack_len = strlen(haystack);
462+
size_t needle_len = strlen(needle);
463+
464+
if (needle_len > haystack_len)
465+
return false;
466+
return strcmp(haystack + haystack_len - needle_len, needle) == 0;
467+
}
468+
469+
static void test_ctl_name(struct ctl_data *ctl)
470+
{
471+
bool name_ok = true;
472+
bool check;
473+
474+
/* Only boolean controls should end in Switch */
475+
if (strend(ctl->name, " Switch")) {
476+
if (snd_ctl_elem_info_get_type(ctl->info) != SND_CTL_ELEM_TYPE_BOOLEAN) {
477+
ksft_print_msg("%d.%d %s ends in Switch but is not boolean\n",
478+
ctl->card->card, ctl->elem, ctl->name);
479+
name_ok = false;
480+
}
481+
}
482+
483+
/* Writeable boolean controls should end in Switch */
484+
if (snd_ctl_elem_info_get_type(ctl->info) == SND_CTL_ELEM_TYPE_BOOLEAN &&
485+
snd_ctl_elem_info_is_writable(ctl->info)) {
486+
if (!strend(ctl->name, " Switch")) {
487+
ksft_print_msg("%d.%d %s is a writeable boolean but not a Switch\n",
488+
ctl->card->card, ctl->elem, ctl->name);
489+
name_ok = false;
490+
}
491+
}
492+
493+
ksft_test_result(name_ok, "name.%d.%d\n",
494+
ctl->card->card, ctl->elem);
495+
}
496+
459497
static bool show_mismatch(struct ctl_data *ctl, int index,
460498
snd_ctl_elem_value_t *read_val,
461499
snd_ctl_elem_value_t *expected_val)
@@ -1062,6 +1100,7 @@ int main(void)
10621100
* test stores the default value for later cleanup.
10631101
*/
10641102
test_ctl_get_value(ctl);
1103+
test_ctl_name(ctl);
10651104
test_ctl_write_default(ctl);
10661105
test_ctl_write_valid(ctl);
10671106
test_ctl_write_invalid(ctl);

0 commit comments

Comments
 (0)