mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: ALSA: Skip tests when devices are unavailable
@ 2026-09-26  9:57 Alireza Feyzabadi Farahani
  2026-09-26 16:55 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Alireza Feyzabadi Farahani @ 2026-09-26  9:57 UTC (permalink / raw)
  To: Mark Brown
  Cc: Jaroslav Kysela, Takashi Iwai, Shuah Khan, linux-sound,
	linux-kselftest, linux-kernel, Alireza Feyzabadi Farahani

A kernel built without CONFIG_SND exposes no ALSA devices. In that
environment, the mixer and PCM tests currently report success with a
zero-test plan, while the userspace timer tests fail when opening
/dev/snd/timer. Neither result accurately describes an unsupported test
environment.

Report KSFT_SKIP when no sound cards are detected and when the timer
device is unavailable. Keep the PCM missing-card failures when a matching
hardware configuration says that a card should exist, and continue to
fail timer opens for unexpected errors.

Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218479
Signed-off-by: Alireza Feyzabadi Farahani <arfa79lg@gmail.com>
---
 tools/testing/selftests/alsa/mixer-test.c  | 2 ++
 tools/testing/selftests/alsa/pcm-test.c    | 2 ++
 tools/testing/selftests/alsa/utimer-test.c | 6 ++++++
 3 files changed, 10 insertions(+)

diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c
index 6edffcd6f..ab70645d5 100644
--- a/tools/testing/selftests/alsa/mixer-test.c
+++ b/tools/testing/selftests/alsa/mixer-test.c
@@ -1378,6 +1378,8 @@ int main(void)
 	ksft_print_header();
 
 	find_controls();
+	if (!card_list)
+		ksft_exit_skip("No sound cards detected\n");
 
 	ksft_set_plan(num_controls * TESTS_PER_CONTROL);
 
diff --git a/tools/testing/selftests/alsa/pcm-test.c b/tools/testing/selftests/alsa/pcm-test.c
index ee04ccef7..de07de650 100644
--- a/tools/testing/selftests/alsa/pcm-test.c
+++ b/tools/testing/selftests/alsa/pcm-test.c
@@ -613,6 +613,8 @@ int main(void)
 	conf_load();
 
 	find_pcms();
+	if (!card_list && !conf_cards)
+		ksft_exit_skip("No sound cards detected\n");
 
 	for (conf = conf_cards; conf; conf = conf->next)
 		if (conf->card < 0)
diff --git a/tools/testing/selftests/alsa/utimer-test.c b/tools/testing/selftests/alsa/utimer-test.c
index 1a9ff010c..07aeaa777 100644
--- a/tools/testing/selftests/alsa/utimer-test.c
+++ b/tools/testing/selftests/alsa/utimer-test.c
@@ -51,6 +51,9 @@ FIXTURE_SETUP(timer_f) {
 	self->utimer_info->resolution = (NANO / FRAME_RATE * PERIOD_SIZE);
 
 	timer_dev_fd = open("/dev/snd/timer", O_RDONLY);
+	if (timer_dev_fd < 0 &&
+	    (errno == ENOENT || errno == ENODEV || errno == ENXIO))
+		SKIP(return, "ALSA timer device unavailable");
 	ASSERT_GE(timer_dev_fd, 0);
 
 	if (ioctl(timer_dev_fd, SNDRV_TIMER_IOCTL_CREATE, self->utimer_info) < 0) {
@@ -156,6 +159,9 @@ TEST(wrong_timers_test) {
 	};
 
 	timer_dev_fd = open("/dev/snd/timer", O_RDONLY);
+	if (timer_dev_fd < 0 &&
+	    (errno == ENOENT || errno == ENODEV || errno == ENXIO))
+		SKIP(return, "ALSA timer device unavailable");
 	ASSERT_GE(timer_dev_fd, 0);
 
 	utimer_fd = ioctl(timer_dev_fd, SNDRV_TIMER_IOCTL_CREATE, &wrong_timer);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests: ALSA: Skip tests when devices are unavailable
  2026-09-26  9:57 [PATCH] selftests: ALSA: Skip tests when devices are unavailable Alireza Feyzabadi Farahani
@ 2026-09-26 16:55 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-09-26 16:55 UTC (permalink / raw)
  To: Alireza Feyzabadi Farahani
  Cc: Jaroslav Kysela, Takashi Iwai, Shuah Khan, linux-sound,
	linux-kselftest, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1320 bytes --]

On Sat, Sep 26, 2026 at 09:57:56AM +0000, Alireza Feyzabadi Farahani wrote:
> A kernel built without CONFIG_SND exposes no ALSA devices. In that
> environment, the mixer and PCM tests currently report success with a
> zero-test plan, while the userspace timer tests fail when opening
> /dev/snd/timer. Neither result accurately describes an unsupported test
> environment.
> 
> Report KSFT_SKIP when no sound cards are detected and when the timer
> device is unavailable. Keep the PCM missing-card failures when a matching
> hardware configuration says that a card should exist, and continue to
> fail timer opens for unexpected errors.
> 
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218479

The timer tests are clearly a good fix here but the other two programs
are a lot less clear - they aren't reporting any false errors, they're
just reporting a pass as they found no sound cards and therefore no
problems on them.  Or to put it another way all the available sound
cards were fine.  We don't know if this was due to missing configs, or
just that the machine physically has no sound cards (eg, a VM).  I'd at
least make this two patches, or TBH just leave the PCM and mixer tests
alone.  They certainly don't have an issue that needs fixing in the same
way that the timer test does.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-26 16:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-26  9:57 [PATCH] selftests: ALSA: Skip tests when devices are unavailable Alireza Feyzabadi Farahani
2026-09-26 16:55 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®