From: HyeongJun An <sammiee5311@gmail.com>
To: Takashi Iwai <tiwai@suse.com>
Cc: Ivan Orlov <ivan.orlov0322@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Shuah Khan <shuah@kernel.org>,
linux-sound@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
HyeongJun An <sammiee5311@gmail.com>
Subject: [PATCH 3/3] selftests: ALSA: pcmtest: Test pausing a capture stream
Date: Thu, 22 Oct 2026 20:12:44 +0900 [thread overview]
Message-ID: <906d65ff1cf78f5e173a5476eadcbca285aa2b17.1792660433.git.sammiee5311@gmail.com> (raw)
In-Reply-To: <cover.1792660433.git.sammiee5311@gmail.com>
The driver supports pause, but no test uses it.
Add a capture test that pauses the stream halfway for half a second.
The core does not read the hardware pointer while the stream is
paused, so a driver that keeps running shows up only at the release,
as a jump of the pointer. Check that the jump is under a tenth of a
second, and that the data carries on from where it stopped.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
.../selftests/alsa/test-pcmtest-driver.c | 49 +++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/tools/testing/selftests/alsa/test-pcmtest-driver.c b/tools/testing/selftests/alsa/test-pcmtest-driver.c
index 380364ee7924..b796a5613c6f 100644
--- a/tools/testing/selftests/alsa/test-pcmtest-driver.c
+++ b/tools/testing/selftests/alsa/test-pcmtest-driver.c
@@ -7,6 +7,7 @@
*/
#include <errno.h>
#include <string.h>
+#include <unistd.h>
#include <alsa/asoundlib.h>
#include "kselftest_harness.h"
@@ -362,6 +363,54 @@ TEST_F(pcmtest, reset_ioctl) {
snd_pcm_close(handle);
}
+/*
+ * Here we pause a capture stream halfway. The core does not read the hardware pointer while
+ * the stream is paused, so a driver that keeps running only shows up after the release, as a
+ * jump of the pointer. The data must also continue where it stopped, so the whole buffer still
+ * matches the patterns.
+ */
+TEST_F(pcmtest, capture_pause) {
+ snd_pcm_t *handle;
+ snd_pcm_sframes_t read_res, paused_avail, avail, frames, half;
+ unsigned char *samples;
+ struct pcmtest_test_params *params = &self->params;
+
+ samples = calloc(params->sec_buf_len * params->time, 1);
+ ASSERT_NE(samples, NULL);
+
+ snd_pcm_sw_params_alloca(&self->swparams);
+ snd_pcm_hw_params_alloca(&self->hwparams);
+ ASSERT_EQ(setup_handle(&handle, self->swparams, self->hwparams, params,
+ self->card, SND_PCM_STREAM_CAPTURE), 0);
+
+ frames = params->rate * params->time;
+ half = frames / 2;
+ read_res = snd_pcm_readi(handle, samples, half);
+ ASSERT_EQ(read_res, half);
+
+ ASSERT_EQ(snd_pcm_pause(handle, 1), 0);
+ ASSERT_EQ(snd_pcm_state(handle), SND_PCM_STATE_PAUSED);
+ paused_avail = snd_pcm_avail(handle);
+ ASSERT_GE(paused_avail, 0);
+ usleep(500000);
+
+ /*
+ * At 8000 Hz the pause is 4000 frames long. Allow a tenth of a second (800 frames) for
+ * the release.
+ */
+ ASSERT_EQ(snd_pcm_pause(handle, 0), 0);
+ avail = snd_pcm_avail(handle);
+ ASSERT_GE(avail, 0);
+ ASSERT_LT(avail - paused_avail, (snd_pcm_sframes_t)params->rate / 10);
+ read_res = snd_pcm_readi(handle, samples + snd_pcm_frames_to_bytes(handle, half),
+ frames - half);
+ ASSERT_EQ(read_res, frames - half);
+ snd_pcm_close(handle);
+
+ ASSERT_EQ(find_capture_mismatch(samples, params), -1);
+ free(samples);
+}
+
/*
* Here we check that an error from each PCM callback reaches user space. The driver returns
* the error while the matching 'inject_*_err' parameter is set, and works again once it is
--
2.43.0
prev parent reply other threads:[~2026-10-22 11:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 11:12 [PATCH 0/3] selftests: ALSA: pcmtest: Test error injection and pause HyeongJun An
2026-10-22 11:12 ` [PATCH 1/3] selftests: ALSA: pcmtest: Move the capture data check into a helper HyeongJun An
2026-10-22 11:12 ` [PATCH 2/3] selftests: ALSA: pcmtest: Test errors from the PCM callbacks HyeongJun An
2026-10-22 11:12 ` 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=906d65ff1cf78f5e173a5476eadcbca285aa2b17.1792660433.git.sammiee5311@gmail.com \
--to=sammiee5311@gmail.com \
--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®