Skip to contentSkip to conversation

selftests: ALSA: Skip tests when devices are unavailable

PATCH In review Alireza Feyzabadi Farahani 2 participants 2 messages Sep 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: ALSA: Skip tests when devices are unavailable

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.

---
 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(+)
tools/testing/selftests/alsa/mixer-test.c +2 -0
index 6edffcd6f..ab70645d5 100644
@@ -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);
 
tools/testing/selftests/alsa/pcm-test.c +2 -0
index ee04ccef7..de07de650 100644
@@ -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)
tools/testing/selftests/alsa/utimer-test.c +6 -0
index 1a9ff010c..07aeaa777 100644
@@ -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);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 6 lines · 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.

Quoted 6 lines

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.

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.