* [PATCH 0/2] selftests: ALSA: pcmtest: Fix two test bugs
@ 2026-10-20 10:18 HyeongJun An
2026-10-20 10:18 ` [PATCH 1/2] selftests: ALSA: pcmtest: Check the frame count of each transfer HyeongJun An
2026-10-20 10:18 ` [PATCH 2/2] selftests: ALSA: pcmtest: Make room for the longest fill pattern HyeongJun An
0 siblings, 2 replies; 3+ messages in thread
From: HyeongJun An @ 2026-10-20 10:18 UTC (permalink / raw)
To: Takashi Iwai
Cc: Ivan Orlov, Mark Brown, Jaroslav Kysela, Shuah Khan, linux-sound,
linux-kselftest, linux-kernel, HyeongJun An
Two fixes for the pcmtest selftest. The first makes the playback tests
fail when a transfer fails. The second sizes the pattern buffer to the
4096 bytes the driver allows.
Tested on x86_64 with snd-pcmtest. All five tests pass as before. With
inject_trigger_err=1 the playback and ni_playback tests passed before
and now fail. With a 2000-byte pattern on channel 0 four tests failed
before and now pass.
HyeongJun An (2):
selftests: ALSA: pcmtest: Check the frame count of each transfer
selftests: ALSA: pcmtest: Make room for the longest fill pattern
.../selftests/alsa/test-pcmtest-driver.c | 25 +++++++++++--------
1 file changed, 15 insertions(+), 10 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] selftests: ALSA: pcmtest: Check the frame count of each transfer
2026-10-20 10:18 [PATCH 0/2] selftests: ALSA: pcmtest: Fix two test bugs HyeongJun An
@ 2026-10-20 10:18 ` HyeongJun An
2026-10-20 10:18 ` [PATCH 2/2] selftests: ALSA: pcmtest: Make room for the longest fill pattern HyeongJun An
1 sibling, 0 replies; 3+ messages in thread
From: HyeongJun An @ 2026-10-20 10:18 UTC (permalink / raw)
To: Takashi Iwai
Cc: Ivan Orlov, Mark Brown, Jaroslav Kysela, Shuah Khan, linux-sound,
linux-kselftest, linux-kernel, HyeongJun An
The tests keep the result of snd_pcm_writei(), snd_pcm_readi() and
their non-interleaved forms in a size_t. A size_t is never negative, so
ASSERT_GE(res, 0) always passes.
The capture tests still catch a failed read when they compare the data.
But the playback tests do not. The driver sets pc_test to 1 when it saw
no corrupted data, and that is also true when it saw no data at all. So
a playback test passes even when every write fails.
Store the result as snd_pcm_sframes_t and check that the whole request
was transferred. The calls block, so a short count means an error.
Fixes: 10b98a4db11a ("selftests: ALSA: Add test for the 'pcmtest' driver")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
.../selftests/alsa/test-pcmtest-driver.c | 21 +++++++++++--------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/alsa/test-pcmtest-driver.c b/tools/testing/selftests/alsa/test-pcmtest-driver.c
index 95065ef3b441..5bba17434a6b 100644
--- a/tools/testing/selftests/alsa/test-pcmtest-driver.c
+++ b/tools/testing/selftests/alsa/test-pcmtest-driver.c
@@ -166,7 +166,7 @@ FIXTURE_SETUP(pcmtest) {
TEST_F(pcmtest, playback) {
snd_pcm_t *handle;
unsigned char *it;
- size_t write_res;
+ snd_pcm_sframes_t write_res;
int test_results;
int i, cur_ch, pos_in_ch;
void *samples;
@@ -190,7 +190,7 @@ TEST_F(pcmtest, playback) {
it[i] = patterns[cur_ch].buf[pos_in_ch % patterns[cur_ch].len];
}
write_res = snd_pcm_writei(handle, samples, params->rate * params->time);
- ASSERT_GE(write_res, 0);
+ ASSERT_EQ(write_res, params->rate * params->time);
snd_pcm_close(handle);
free(samples);
@@ -206,7 +206,7 @@ TEST_F(pcmtest, playback) {
TEST_F(pcmtest, capture) {
snd_pcm_t *handle;
unsigned char *it;
- size_t read_res;
+ snd_pcm_sframes_t read_res;
int i, cur_ch, pos_in_ch;
void *samples;
struct pcmtest_test_params *params = &self->params;
@@ -222,7 +222,7 @@ TEST_F(pcmtest, capture) {
snd_pcm_format_set_silence(params->format, samples,
params->rate * params->channels * params->time);
read_res = snd_pcm_readi(handle, samples, params->rate * params->time);
- ASSERT_GE(read_res, 0);
+ ASSERT_EQ(read_res, params->rate * params->time);
snd_pcm_close(handle);
it = (unsigned char *)samples;
for (i = 0; i < self->params.sec_buf_len * self->params.time; i++) {
@@ -239,7 +239,8 @@ TEST_F(pcmtest, ni_capture) {
snd_pcm_t *handle;
struct pcmtest_test_params params = self->params;
char **chan_samples;
- size_t i, j, read_res;
+ snd_pcm_sframes_t read_res;
+ size_t i, j;
chan_samples = calloc(CH_NUM, sizeof(*chan_samples));
ASSERT_NE(chan_samples, NULL);
@@ -257,7 +258,7 @@ TEST_F(pcmtest, ni_capture) {
for (i = 0; i < 1; i++) {
read_res = snd_pcm_readn(handle, (void **)chan_samples, params.rate * params.time);
- ASSERT_GE(read_res, 0);
+ ASSERT_EQ(read_res, params.rate * params.time);
}
snd_pcm_close(handle);
@@ -273,7 +274,8 @@ TEST_F(pcmtest, ni_playback) {
snd_pcm_t *handle;
struct pcmtest_test_params params = self->params;
char **chan_samples;
- size_t i, j, read_res;
+ snd_pcm_sframes_t write_res;
+ size_t i, j;
int test_res;
chan_samples = calloc(CH_NUM, sizeof(*chan_samples));
@@ -294,8 +296,9 @@ TEST_F(pcmtest, ni_playback) {
}
for (i = 0; i < 1; i++) {
- read_res = snd_pcm_writen(handle, (void **)chan_samples, params.rate * params.time);
- ASSERT_GE(read_res, 0);
+ write_res = snd_pcm_writen(handle, (void **)chan_samples,
+ params.rate * params.time);
+ ASSERT_EQ(write_res, params.rate * params.time);
}
snd_pcm_close(handle);
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] selftests: ALSA: pcmtest: Make room for the longest fill pattern
2026-10-20 10:18 [PATCH 0/2] selftests: ALSA: pcmtest: Fix two test bugs HyeongJun An
2026-10-20 10:18 ` [PATCH 1/2] selftests: ALSA: pcmtest: Check the frame count of each transfer HyeongJun An
@ 2026-10-20 10:18 ` HyeongJun An
1 sibling, 0 replies; 3+ messages in thread
From: HyeongJun An @ 2026-10-20 10:18 UTC (permalink / raw)
To: Takashi Iwai
Cc: Ivan Orlov, Mark Brown, Jaroslav Kysela, Shuah Khan, linux-sound,
linux-kselftest, linux-kernel, HyeongJun An
The driver accepts fill patterns of up to 4096 bytes, as pcmtest.rst
documents. The test reads each pattern into a 1024-byte buffer, using
the length the driver reports. So a pattern longer than 1024 bytes
overflows the buffer into the next pattern and past the array.
Size the buffer to the driver's maximum.
Fixes: 10b98a4db11a ("selftests: ALSA: Add test for the 'pcmtest' driver")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
tools/testing/selftests/alsa/test-pcmtest-driver.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/alsa/test-pcmtest-driver.c b/tools/testing/selftests/alsa/test-pcmtest-driver.c
index 5bba17434a6b..e025a7bac26b 100644
--- a/tools/testing/selftests/alsa/test-pcmtest-driver.c
+++ b/tools/testing/selftests/alsa/test-pcmtest-driver.c
@@ -10,9 +10,11 @@
#include "kselftest_harness.h"
#define CH_NUM 4
+/* The driver accepts patterns of up to 4096 bytes */
+#define MAX_PATTERN_LEN 4096
struct pattern_buf {
- char buf[1024];
+ char buf[MAX_PATTERN_LEN];
int len;
};
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-20 10:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 10:18 [PATCH 0/2] selftests: ALSA: pcmtest: Fix two test bugs HyeongJun An
2026-10-20 10:18 ` [PATCH 1/2] selftests: ALSA: pcmtest: Check the frame count of each transfer HyeongJun An
2026-10-20 10:18 ` [PATCH 2/2] selftests: ALSA: pcmtest: Make room for the longest fill pattern HyeongJun An
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®