Skip to contentSkip to conversation

selftests/alsa: Let the pcmtest test run on kselftest kernels

PATCH Superseded HyeongJun An 2 participants 9 messages Nov 26 – Nov 28

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

cover selftests/alsa: Let the pcmtest test run on kselftest kernels

On the kernels that CI labs such as KernelCI build for kselftest, every test-pcmtest-driver case skips. The KernelCI arm64 kselftest kernel has CONFIG_SND_PCMTEST, CONFIG_SND_SEQ_UMP and CONFIG_SND_UTIMER off, and nothing would load the pcmtest module even if it were built.

Patch 1 adds a config file for make kselftest-merge with only the options the tests themselves need. When Ben sent a config file in March [1], Mark pointed out that mixer-test and pcm-test check whatever drivers a system has, while test-pcmtest-driver does need a config option for its module. So no drivers are listed here. Patch 2 lets test-pcmtest-driver load the module itself.

Tested in QEMU (x86_64) on sound/for-next 0dfd513a1557, with a kernel from defconfig and make kselftest-merge and no sound modules loaded at boot. All four options are on with patch 1 and off without it. On the kernel with patch 1, test-pcmtest-driver goes from 10 skipped to 10 passed with patch 2, and seq-ump-test, which skips without CONFIG_SND_SEQ_UMP, passes.

[1] https://lore.kernel.org/all/[email protected]/

Prepared with Claude Code (Claude Opus 5.5).

HyeongJun An (2):
selftests/alsa: Add a config file for the test-only options
selftests: ALSA: pcmtest: Load the module when it is missing

 tools/testing/selftests/alsa/config                | 6 ++++++
 tools/testing/selftests/alsa/test-pcmtest-driver.c | 4 ++++
 2 files changed, 10 insertions(+)
 create mode 100644 tools/testing/selftests/alsa/config
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 selftests/alsa: Add a config file for the test-only options

Some of the ALSA selftests need kernel options that a normal config does not enable. test-pcmtest-driver needs the pcmtest driver, seq-ump-test needs CONFIG_SND_SEQ_UMP, utimer-test needs CONFIG_SND_UTIMER, and aloop-test needs snd-aloop. Without them these tests skip.

CI systems build their kselftest kernels with make kselftest-merge, which merges the config file of each selftest directory, and alsa has none. On the KernelCI arm64 kselftest kernel all four options are off, and every test-pcmtest-driver case skips.

Add a config file with only these options. mixer-test and pcm-test check whatever sound drivers a system has, so no drivers are listed.

---
 tools/testing/selftests/alsa/config | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 tools/testing/selftests/alsa/config
tools/testing/selftests/alsa/config new file +6 -0
new file mode 100644
index 000000000000..67fa26a87217
@@ -0,0 +1,6 @@
+CONFIG_DEBUG_FS=y
+CONFIG_SND_ALOOP=m
+CONFIG_SND_PCMTEST=m
+CONFIG_SND_SEQUENCER=m
+CONFIG_SND_SEQ_UMP=y
+CONFIG_SND_UTIMER=y
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH 1/2] selftests/alsa: Add a config file for the test-only options

Quoted 6 lines · HyeongJun An

Some of the ALSA selftests need kernel options that a normal config does not enable. test-pcmtest-driver needs the pcmtest driver, seq-ump-test needs CONFIG_SND_SEQ_UMP, utimer-test needs CONFIG_SND_UTIMER, and aloop-test needs snd-aloop. Without them these tests skip.

+CONFIG_SND_PCMTEST=m

This is inside CONFIG_SND_DRIVERS, you need to select that in case the underlying config has disabled it.

#3 lore raw

PATCH 2/2 selftests: ALSA: pcmtest: Load the module when it is missing

In reply to HyeongJun An

test-pcmtest-driver skips when the pcmtest debugfs files are missing. The driver has no device to bind to, so nothing loads the module, and the test skips even on a kernel that builds it.

Run modprobe once before skipping, as the net pktgen test does. The module stays loaded. In the default order the test runs after mixer-test and pcm-test, so the extra card does not change what they check.

---
 tools/testing/selftests/alsa/test-pcmtest-driver.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/alsa/test-pcmtest-driver.c +4 -0
index b796a5613c6f..ea6a9e0f7483 100644
@@ -6,6 +6,7 @@
  * Copyright 2023 Ivan Orlov <[email protected]>
  */
 #include <errno.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <alsa/asoundlib.h>
@@ -171,6 +172,9 @@ FIXTURE_SETUP(pcmtest) {
 		SKIP(return, "This test needs root to run!");
 
 	err = read_patterns();
+	/* nothing loads the module on its own, so ask for it */
+	if (err && !system("modprobe -q snd-pcmtest"))
+		err = read_patterns();
 	if (err)
 		SKIP(return, "Can't read patterns. Probably, module isn't loaded");
 
Signature · 1 line
2.43.0
maintainer
#4 lore raw

Re: [PATCH 2/2] selftests: ALSA: pcmtest: Load the module when it is missing

Quoted 9 lines · HyeongJun An

test-pcmtest-driver skips when the pcmtest debugfs files are missing. The driver has no device to bind to, so nothing loads the module, and the test skips even on a kernel that builds it.

Run modprobe once before skipping, as the net pktgen test does. The module stays loaded. In the default order the test runs after mixer-test and pcm-test, so the extra card does not change what they check.

tools/testing/selftests/alsa/test-pcmtest-driver.c FIXTURE_SETUP(pcmtest) { · line 177

Quoted 6 lines
tools/testing/selftests/alsa/test-pcmtest-driver.c +3 -0
@@ -171,6 +172,9 @@ FIXTURE_SETUP(pcmtest) {
 		SKIP(return, "This test needs root to run!");
 
 	err = read_patterns();
+	/* nothing loads the module on its own, so ask for it */
+	if (err && !system("modprobe -q snd-pcmtest"))
+		err = read_patterns();

It'd be polite to unload the module if we caused it to be loaded, though potentially more trouble than it's worth. I'm also not sure if this does the right thing if someone decided to build the driver in (to make it easier to deploy onto a test system for example).

#5 lore raw

v2 cover selftests/alsa: Let the pcmtest test run on kselftest kernels

In reply to HyeongJun An

On the kernels that CI labs such as KernelCI build for kselftest, every test-pcmtest-driver case skips. The KernelCI arm64 kselftest kernel has CONFIG_SND_PCMTEST, CONFIG_SND_SEQ_UMP and CONFIG_SND_UTIMER off, and nothing would load the pcmtest module even if it were built.

Patch 1 adds a config file for make kselftest-merge with only the options the tests themselves need. Patch 2 lets test-pcmtest-driver load the module itself and unload it again at exit.

Tested in QEMU on sound/for-next 486060b97284, on x86_64 from x86_64_defconfig and on arm64 from defconfig, each followed by make kselftest-merge. On both, test-pcmtest-driver passes all 10 cases. The module is gone after the run when it was not loaded before, and stays loaded when it was. With a base config that turns off CONFIG_SND_DRIVERS, the v1 config file lost CONFIG_SND_PCMTEST and CONFIG_SND_ALOOP in the merge, and this one keeps them.

Changes in v2:
- Patch 1: Enable CONFIG_SND_DRIVERS, which pcmtest and aloop are under (Mark). Name the options that are off on KernelCI. snd-aloop is on there, so v1 was wrong to say all four were off.
- Patch 2: Unload the module at exit if the test loaded it (Mark).

v1: https://lore.kernel.org/all/[email protected]/

Prepared with Claude Code (Claude Opus 5.5).

HyeongJun An (2):
selftests/alsa: Add a config file for the test-only options
selftests: ALSA: pcmtest: Load the module when it is missing

 tools/testing/selftests/alsa/config           |  7 +++++++
 .../selftests/alsa/test-pcmtest-driver.c      | 20 +++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 tools/testing/selftests/alsa/config
Signature · 1 line
2.43.0
maintainer Reviewed-by on the v2 series
#6 lore raw
Quoted 4 lines · HyeongJun An

On the kernels that CI labs such as KernelCI build for kselftest, every test-pcmtest-driver case skips. The KernelCI arm64 kselftest kernel has CONFIG_SND_PCMTEST, CONFIG_SND_SEQ_UMP and CONFIG_SND_UTIMER off, and nothing would load the pcmtest module even if it were built.

#7 lore raw

PATCH v2 1/2 selftests/alsa: Add a config file for the test-only options

In reply to HyeongJun An

Some of the ALSA selftests need kernel options that a normal config does not enable. test-pcmtest-driver needs the pcmtest driver, seq-ump-test needs CONFIG_SND_SEQ_UMP, utimer-test needs CONFIG_SND_UTIMER, and aloop-test needs snd-aloop. Without them these tests skip.

CI systems build their kselftest kernels with make kselftest-merge, which merges the config file of each selftest directory, and alsa has none. On the KernelCI arm64 kselftest kernel CONFIG_SND_PCMTEST, CONFIG_SND_SEQ_UMP and CONFIG_SND_UTIMER are off, and every test-pcmtest-driver case skips.

Add a config file with only these options. pcmtest and aloop are under CONFIG_SND_DRIVERS, so enable that too in case the base config turns it off. mixer-test and pcm-test check whatever sound drivers a system has, so no drivers are listed.

---
 tools/testing/selftests/alsa/config | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 tools/testing/selftests/alsa/config
tools/testing/selftests/alsa/config new file +7 -0
new file mode 100644
index 000000000000..23ea0ccfdfa6
@@ -0,0 +1,7 @@
+CONFIG_DEBUG_FS=y
+CONFIG_SND_ALOOP=m
+CONFIG_SND_DRIVERS=y
+CONFIG_SND_PCMTEST=m
+CONFIG_SND_SEQUENCER=m
+CONFIG_SND_SEQ_UMP=y
+CONFIG_SND_UTIMER=y
Signature · 1 line
2.43.0
#8 lore raw

PATCH v2 2/2 selftests: ALSA: pcmtest: Load the module when it is missing

In reply to HyeongJun An

test-pcmtest-driver skips when the pcmtest debugfs files are missing. The driver has no device to bind to, so nothing loads the module, and the test skips even on a kernel that builds it.

Run modprobe once before skipping, as the net pktgen test does. Each test runs in a child process, so record whether the module was loaded before the tests start, and unload it at exit if the tests loaded it.

---
A built-in pcmtest creates its debugfs files at boot, so read_patterns() succeeds and modprobe is not run. If debugfs is not mounted, modprobe of a built-in module returns 0, the second read fails, and the test skips as before.

 .../selftests/alsa/test-pcmtest-driver.c      | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/testing/selftests/alsa/test-pcmtest-driver.c +20 -0
index b796a5613c6f..3bd6f75ac6f6 100644
@@ -6,6 +6,7 @@
  * Copyright 2023 Ivan Orlov <[email protected]>
  */
 #include <errno.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <alsa/asoundlib.h>
@@ -149,6 +150,22 @@ static int setup_handle(snd_pcm_t **handle, snd_pcm_sw_params_t *swparams,
 	return 0;
 }
 
+static bool module_was_loaded;
+
+/* remember whether snd-pcmtest was loaded before the tests ran */
+static void __attribute__((constructor)) check_module(void)
+{
+	module_was_loaded = !access("/sys/module/snd_pcmtest", F_OK);
+}
+
+/* each test runs in a child, so unload in the parent once all are done */
+static void __attribute__((destructor)) unload_module(void)
+{
+	if (!module_was_loaded && !access("/sys/module/snd_pcmtest", F_OK) &&
+	    system("modprobe -r -q snd-pcmtest"))
+		ksft_print_msg("Failed to unload snd-pcmtest\n");
+}
+
 FIXTURE(pcmtest) {
 	int card;
 	snd_pcm_sw_params_t *swparams;
@@ -171,6 +188,9 @@ FIXTURE_SETUP(pcmtest) {
 		SKIP(return, "This test needs root to run!");
 
 	err = read_patterns();
+	/* nothing loads the module on its own, so ask for it */
+	if (err && !system("modprobe -q snd-pcmtest"))
+		err = read_patterns();
 	if (err)
 		SKIP(return, "Can't read patterns. Probably, module isn't loaded");
 
Signature · 1 line
2.43.0