Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Mark Brown and committed by
Takashi Iwai
c92b576a 67d64069

+40 -1
+40 -1
tools/testing/selftests/alsa/mixer-test.c
··· 27 27 28 28 #include "../kselftest.h" 29 29 30 - #define TESTS_PER_CONTROL 6 30 + #define TESTS_PER_CONTROL 7 31 31 32 32 struct card_data { 33 33 snd_ctl_t *handle; ··· 453 453 454 454 out: 455 455 ksft_test_result(err >= 0, "get_value.%d.%d\n", 456 + ctl->card->card, ctl->elem); 457 + } 458 + 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", 456 494 ctl->card->card, ctl->elem); 457 495 } 458 496 ··· 1100 1062 * test stores the default value for later cleanup. 1101 1063 */ 1102 1064 test_ctl_get_value(ctl); 1065 + test_ctl_name(ctl); 1103 1066 test_ctl_write_default(ctl); 1104 1067 test_ctl_write_valid(ctl); 1105 1068 test_ctl_write_invalid(ctl);