mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: HyeongJun An <sammiee5311@gmail.com>
To: broonie@kernel.org, tiwai@suse.com
Cc: perex@perex.cz, shuah@kernel.org, ivan.orlov0322@gmail.com,
	ben.copeland@linaro.org, linux-sound@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	HyeongJun An <sammiee5311@gmail.com>
Subject: [PATCH v2 2/2] selftests: ALSA: pcmtest: Load the module when it is missing
Date: Sat, 28 Nov 2026 15:52:27 +0900	[thread overview]
Message-ID: <20261128065228.3628550-3-sammiee5311@gmail.com> (raw)
In-Reply-To: <20261126035526.1779288-1-sammiee5311@gmail.com>

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.

Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
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(+)

diff --git a/tools/testing/selftests/alsa/test-pcmtest-driver.c b/tools/testing/selftests/alsa/test-pcmtest-driver.c
index b796a5613c6f..3bd6f75ac6f6 100644
--- a/tools/testing/selftests/alsa/test-pcmtest-driver.c
+++ b/tools/testing/selftests/alsa/test-pcmtest-driver.c
@@ -6,6 +6,7 @@
  * Copyright 2023 Ivan Orlov <ivan.orlov0322@gmail.com>
  */
 #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");
 
-- 
2.43.0


      parent reply	other threads:[~2026-11-28  6:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  3:55 [PATCH 0/2] selftests/alsa: Let the pcmtest test run on kselftest kernels HyeongJun An
2026-11-26  3:55 ` [PATCH 1/2] selftests/alsa: Add a config file for the test-only options HyeongJun An
2026-11-26 16:08   ` Mark Brown
2026-11-26  3:55 ` [PATCH 2/2] selftests: ALSA: pcmtest: Load the module when it is missing HyeongJun An
2026-11-26 16:11   ` Mark Brown
2026-11-28  6:52 ` [PATCH v2 0/2] selftests/alsa: Let the pcmtest test run on kselftest kernels HyeongJun An
2026-11-28  6:52 ` [PATCH v2 1/2] selftests/alsa: Add a config file for the test-only options HyeongJun An
2026-11-28  6:52 ` HyeongJun An [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128065228.3628550-3-sammiee5311@gmail.com \
    --to=sammiee5311@gmail.com \
    --cc=ben.copeland@linaro.org \
    --cc=broonie@kernel.org \
    --cc=ivan.orlov0322@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=shuah@kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®