From 7c79b10bea7a9dc1b74e2dbf4a35c19455371662 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 6 Mar 2023 14:20:03 +0000 Subject: kselftest/alsa - mixer-test: Don't fail tests if we can't restore default If a control has an invalid default value then we might fail to set it when restoring the default value after our write tests, for example due to correctly implemented range checks in put() operations. Currently this causes us to report the tests we were running as failed even when the operation we were trying to test is successful, making it look like there are problems where none really exist. Stop doing this, only reporting any issues during the actual test. We already have validation for the initial readback being in spec and for writing the default value back so failed tests will be reported for these controls, and we log an error on the operation that failed when we write so there will be a diagnostic warning the user that there is a problem. Signed-off-by: Mark Brown Link: https://lore.kernel.org/r/20230224-alsa-mixer-test-restore-invalid-v1-1-454f0f1f2c4b@kernel.org Signed-off-by: Takashi Iwai --- tools/testing/selftests/alsa/mixer-test.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c index 05f1749ae19d..ac5efa42d488 100644 --- a/tools/testing/selftests/alsa/mixer-test.c +++ b/tools/testing/selftests/alsa/mixer-test.c @@ -755,7 +755,6 @@ static bool test_ctl_write_valid_enumerated(struct ctl_data *ctl) static void test_ctl_write_valid(struct ctl_data *ctl) { bool pass; - int err; /* If the control is turned off let's be polite */ if (snd_ctl_elem_info_is_inactive(ctl->info)) { @@ -797,9 +796,7 @@ static void test_ctl_write_valid(struct ctl_data *ctl) } /* Restore the default value to minimise disruption */ - err = write_and_verify(ctl, ctl->def_val, NULL); - if (err < 0) - pass = false; + write_and_verify(ctl, ctl->def_val, NULL); ksft_test_result(pass, "write_valid.%d.%d\n", ctl->card->card, ctl->elem); @@ -1015,9 +1012,7 @@ static void test_ctl_write_invalid(struct ctl_data *ctl) } /* Restore the default value to minimise disruption */ - err = write_and_verify(ctl, ctl->def_val, NULL); - if (err < 0) - pass = false; + write_and_verify(ctl, ctl->def_val, NULL); ksft_test_result(pass, "write_invalid.%d.%d\n", ctl->card->card, ctl->elem); -- cgit v1.2.3 From eae872516214366274c983dd942a85c97e099dfe Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 6 Mar 2023 15:33:28 +0000 Subject: kselftest/alsa - mixer: Always log control names Currently we only log the names of controls on error but it can be useful to know what control we're testing (for example, when looking at why the tests are taking a while to run). People looking at test logs may not have direct access to the target system. This will increase the amount we write to the console, hopefully that's buffered. Signed-off-by: Mark Brown Link: https://lore.kernel.org/r/20230223-alsa-log-ctl-name-v1-1-ac0f10cc4db2@kernel.org Signed-off-by: Takashi Iwai --- tools/testing/selftests/alsa/mixer-test.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools') diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c index ac5efa42d488..e9066ef43eb6 100644 --- a/tools/testing/selftests/alsa/mixer-test.c +++ b/tools/testing/selftests/alsa/mixer-test.c @@ -422,6 +422,9 @@ static void test_ctl_name(struct ctl_data *ctl) bool name_ok = true; bool check; + ksft_print_msg("%d.%d %s\n", ctl->card->card, ctl->elem, + ctl->name); + /* Only boolean controls should end in Switch */ if (strend(ctl->name, " Switch")) { if (snd_ctl_elem_info_get_type(ctl->info) != SND_CTL_ELEM_TYPE_BOOLEAN) { -- cgit v1.2.3 From 1a0cc0520b14c345b16b4af366de4dc238da1e6c Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 6 Mar 2023 15:33:29 +0000 Subject: kselftest/alsa: Log card names during startup It can be helpful to know which card numbers apply to which cards in a multi-card system so log the card names when we start the test programs. People looking at the logs may not have direct access to the systems being tested. Signed-off-by: Mark Brown Link: https://lore.kernel.org/r/20230223-alsa-log-ctl-name-v1-2-ac0f10cc4db2@kernel.org Signed-off-by: Takashi Iwai --- tools/testing/selftests/alsa/mixer-test.c | 10 ++++++++++ tools/testing/selftests/alsa/pcm-test.c | 10 ++++++++++ 2 files changed, 20 insertions(+) (limited to 'tools') diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c index e9066ef43eb6..321c36f79279 100644 --- a/tools/testing/selftests/alsa/mixer-test.c +++ b/tools/testing/selftests/alsa/mixer-test.c @@ -63,6 +63,7 @@ static void find_controls(void) struct card_data *card_data; struct ctl_data *ctl_data; snd_config_t *config; + char *card_name, *card_longname; card = -1; if (snd_card_next(&card) < 0 || card < 0) @@ -84,6 +85,15 @@ static void find_controls(void) goto next_card; } + err = snd_card_get_name(card, &card_name); + if (err != 0) + card_name = "Unknown"; + err = snd_card_get_longname(card, &card_longname); + if (err != 0) + card_longname = "Unknown"; + ksft_print_msg("Card %d - %s (%s)\n", card, + card_name, card_longname); + /* Count controls */ snd_ctl_elem_list_malloc(&card_data->ctls); snd_ctl_elem_list(card_data->handle, card_data->ctls); diff --git a/tools/testing/selftests/alsa/pcm-test.c b/tools/testing/selftests/alsa/pcm-test.c index 58b525a4a32c..d73600e93e83 100644 --- a/tools/testing/selftests/alsa/pcm-test.c +++ b/tools/testing/selftests/alsa/pcm-test.c @@ -149,6 +149,7 @@ static void missing_devices(int card, snd_config_t *card_config) static void find_pcms(void) { char name[32], key[64]; + char *card_name, *card_longname; int card, dev, subdev, count, direction, err; snd_pcm_stream_t stream; struct pcm_data *pcm_data; @@ -175,6 +176,15 @@ static void find_pcms(void) goto next_card; } + err = snd_card_get_name(card, &card_name); + if (err != 0) + card_name = "Unknown"; + err = snd_card_get_longname(card, &card_longname); + if (err != 0) + card_longname = "Unknown"; + ksft_print_msg("Card %d - %s (%s)\n", card, + card_name, card_longname); + card_config = conf_by_card(card); card_data = calloc(1, sizeof(*card_data)); -- cgit v1.2.3 From 05a2cdfef02595cf1ec843c814cac5d57290ad35 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 22 Mar 2023 15:18:07 +0000 Subject: kselftest/alsa - mixer-test: Log values associated with event issues While it is common for driver bugs with events to apply to all events there are some issues which only trigger for specific values. Understanding these is easier if we know what we were trying to do when configuring the control so add logging for the specific values involved in the spurious event. Signed-off-by: Mark Brown Link: https://lore.kernel.org/r/20230322-alsa-mixer-event-values-v1-1-78189fcf6655@kernel.org Signed-off-by: Takashi Iwai --- tools/testing/selftests/alsa/mixer-test.c | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tools') diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c index 321c36f79279..c95d63e553f4 100644 --- a/tools/testing/selftests/alsa/mixer-test.c +++ b/tools/testing/selftests/alsa/mixer-test.c @@ -458,6 +458,48 @@ static void test_ctl_name(struct ctl_data *ctl) ctl->card->card, ctl->elem); } +static void show_values(struct ctl_data *ctl, snd_ctl_elem_value_t *orig_val, + snd_ctl_elem_value_t *read_val) +{ + long long orig_int, read_int; + int i; + + for (i = 0; i < snd_ctl_elem_info_get_count(ctl->info); i++) { + switch (snd_ctl_elem_info_get_type(ctl->info)) { + case SND_CTL_ELEM_TYPE_BOOLEAN: + orig_int = snd_ctl_elem_value_get_boolean(orig_val, i); + read_int = snd_ctl_elem_value_get_boolean(read_val, i); + break; + + case SND_CTL_ELEM_TYPE_INTEGER: + orig_int = snd_ctl_elem_value_get_integer(orig_val, i); + read_int = snd_ctl_elem_value_get_integer(read_val, i); + break; + + case SND_CTL_ELEM_TYPE_INTEGER64: + orig_int = snd_ctl_elem_value_get_integer64(orig_val, + i); + read_int = snd_ctl_elem_value_get_integer64(read_val, + i); + break; + + case SND_CTL_ELEM_TYPE_ENUMERATED: + orig_int = snd_ctl_elem_value_get_enumerated(orig_val, + i); + read_int = snd_ctl_elem_value_get_enumerated(read_val, + i); + break; + + default: + return; + } + + ksft_print_msg("%s.%d orig %lld read %lld, is_volatile %d\n", + ctl->name, i, orig_int, read_int, + snd_ctl_elem_info_is_volatile(ctl->info)); + } +} + static bool show_mismatch(struct ctl_data *ctl, int index, snd_ctl_elem_value_t *read_val, snd_ctl_elem_value_t *expected_val) @@ -597,12 +639,14 @@ static int write_and_verify(struct ctl_data *ctl, 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++; } } -- cgit v1.2.3 From 38bd221a9c974636dd255d15d7b710f8f4a66009 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 23 Mar 2023 18:48:28 +0000 Subject: kselftest/alsa - pcm-test: Don't include diagnostic message in test name When reporting errors or skips we currently include the diagnostic message indicating why we're failing or skipping. This isn't ideal since KTAP defines the entire print as the test name, so if there's an error then test systems won't detect the test as being the same one as a passing test. Move the diagnostic to a separate ksft_print_msg() to avoid this issue, the test name part will always be the same for passes, fails and skips and the diagnostic information is still displayed. Signed-off-by: Mark Brown Link: https://lore.kernel.org/r/20230323-alsa-pcm-test-names-v1-1-8be67a8885ff@kernel.org Signed-off-by: Takashi Iwai --- tools/testing/selftests/alsa/pcm-test.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/testing/selftests/alsa/pcm-test.c b/tools/testing/selftests/alsa/pcm-test.c index d73600e93e83..3e390fe67eb9 100644 --- a/tools/testing/selftests/alsa/pcm-test.c +++ b/tools/testing/selftests/alsa/pcm-test.c @@ -499,17 +499,18 @@ __close: } if (!skip) - ksft_test_result(pass, "%s.%s.%d.%d.%d.%s%s%s\n", + ksft_test_result(pass, "%s.%s.%d.%d.%d.%s\n", test_class_name, test_name, data->card, data->device, data->subdevice, - snd_pcm_stream_name(data->stream), - msg[0] ? " " : "", msg); + snd_pcm_stream_name(data->stream)); else - ksft_test_result_skip("%s.%s.%d.%d.%d.%s%s%s\n", + ksft_test_result_skip("%s.%s.%d.%d.%d.%s\n", test_class_name, test_name, data->card, data->device, data->subdevice, - snd_pcm_stream_name(data->stream), - msg[0] ? " " : "", msg); + snd_pcm_stream_name(data->stream)); + + if (msg[0]) + ksft_print_msg("%s\n", msg); pthread_mutex_unlock(&results_lock); -- cgit v1.2.3