// SPDX-License-Identifier: GPL-2.0 /* * This is the test which covers PCM middle layer data transferring using * the virtual pcm test driver (snd-pcmtest). * * Copyright 2023 Ivan Orlov <ivan.orlov0322@gmail.com>
*/ #include <string.h> #include <alsa/asoundlib.h> #include"../kselftest_harness.h"
while (snd_card_next(&self->card) >= 0) { if (self->card == -1) break;
snd_card_get_name(self->card, &card_name); if (!strcmp(card_name, "PCM-Test")) break;
}
free(card_name);
ASSERT_NE(self->card, -1);
}
/* * Here we are trying to send the looped monotonically increasing sequence of bytes to the driver. * If our data isn't corrupted, the driver will set the content of 'pc_test' debugfs file to '1'
*/
TEST_F(pcmtest, playback) {
snd_pcm_t *handle; unsignedchar *it;
size_t write_res; int test_results; int i, cur_ch, pos_in_ch; void *samples; struct pcmtest_test_params *params = &self->params;
/* * Here we test that the virtual alsa driver returns looped and monotonically increasing sequence * of bytes. In the interleaved mode the buffer will contain samples in the following order: * C0, C1, C2, C3, C0, C1, ...
*/
TEST_F(pcmtest, capture) {
snd_pcm_t *handle; unsignedchar *it;
size_t read_res; int i, cur_ch, pos_in_ch; void *samples; struct pcmtest_test_params *params = &self->params;
ASSERT_EQ(setup_handle(&handle, self->swparams, self->hwparams,
params, self->card, SND_PCM_STREAM_CAPTURE), 0);
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);
snd_pcm_close(handle);
it = (unsignedchar *)samples; for (i = 0; i < self->params.sec_buf_len * self->params.time; i++) {
cur_ch = (i / params->sample_size) % CH_NUM;
pos_in_ch = i / params->sample_size / CH_NUM * params->sample_size
+ (i % params->sample_size);
ASSERT_EQ(it[i], patterns[cur_ch].buf[pos_in_ch % patterns[cur_ch].len]);
}
free(samples);
}
// Test capture in the non-interleaved access mode. The are buffers for each recorded channel
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;
for (i = 0; i < CH_NUM; i++)
free(chan_samples[i]);
free(chan_samples);
}
/* * Here we are testing the custom ioctl definition inside the virtual driver. If it triggers * successfully, the driver sets the content of 'ioctl_test' debugfs file to '1'.
*/
TEST_F(pcmtest, reset_ioctl) {
snd_pcm_t *handle; int test_res; struct pcmtest_test_params *params = &self->params;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.