|
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; |
@@ -456,6 +456,44 @@ static void test_ctl_get_value(struct ctl_data *ctl) |
456 | 456 | ctl->card->card, ctl->elem); |
457 | 457 | } |
458 | 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", |
| 494 | + ctl->card->card, ctl->elem); |
| 495 | +} |
| 496 | + |
459 | 497 | static bool show_mismatch(struct ctl_data *ctl, int index, |
460 | 498 | snd_ctl_elem_value_t *read_val, |
461 | 499 | snd_ctl_elem_value_t *expected_val) |
@@ -1062,6 +1100,7 @@ int main(void) |
1062 | 1100 | * test stores the default value for later cleanup. |
1063 | 1101 | */ |
1064 | 1102 | test_ctl_get_value(ctl); |
| 1103 | + test_ctl_name(ctl); |
1065 | 1104 | test_ctl_write_default(ctl); |
1066 | 1105 | test_ctl_write_valid(ctl); |
1067 | 1106 | test_ctl_write_invalid(ctl); |
|
0 commit comments