Commit 22eeb8f5 authored by Mark Brown's avatar Mark Brown Committed by Takashi Iwai

kselftest/alsa: Refactor pcm-test to list the tests to run in a struct

In order to help make the list of tests a bit easier to maintain refactor
things so we pass the tests around as a struct with the parameters in,
enabling us to add new tests by adding to a table with comments saying
what each of the number are. We could also use named initializers if we get
more parameters.
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20221201170745.1111236-2-broonie@kernel.orgSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 4e9050e5
...@@ -37,6 +37,15 @@ struct pcm_data *pcm_list = NULL; ...@@ -37,6 +37,15 @@ struct pcm_data *pcm_list = NULL;
int num_missing = 0; int num_missing = 0;
struct pcm_data *pcm_missing = NULL; struct pcm_data *pcm_missing = NULL;
struct time_test_def {
const char *cfg_prefix;
const char *format;
long rate;
long channels;
long period_size;
long buffer_size;
};
void timestamp_now(timestamp_t *tstamp) void timestamp_now(timestamp_t *tstamp)
{ {
if (clock_gettime(CLOCK_MONOTONIC_RAW, tstamp)) if (clock_gettime(CLOCK_MONOTONIC_RAW, tstamp))
...@@ -220,9 +229,7 @@ static void find_pcms(void) ...@@ -220,9 +229,7 @@ static void find_pcms(void)
} }
static void test_pcm_time1(struct pcm_data *data, static void test_pcm_time1(struct pcm_data *data,
const char *cfg_prefix, const char *sformat, const struct time_test_def *test)
long srate, long schannels,
long speriod_size, long sbuffer_size)
{ {
char name[64], key[128], msg[256]; char name[64], key[128], msg[256];
const char *cs; const char *cs;
...@@ -244,20 +251,20 @@ static void test_pcm_time1(struct pcm_data *data, ...@@ -244,20 +251,20 @@ static void test_pcm_time1(struct pcm_data *data,
snd_pcm_hw_params_alloca(&hw_params); snd_pcm_hw_params_alloca(&hw_params);
snd_pcm_sw_params_alloca(&sw_params); snd_pcm_sw_params_alloca(&sw_params);
cs = conf_get_string(data->pcm_config, cfg_prefix, "format", sformat); cs = conf_get_string(data->pcm_config, test->cfg_prefix, "format", test->format);
format = snd_pcm_format_value(cs); format = snd_pcm_format_value(cs);
if (format == SND_PCM_FORMAT_UNKNOWN) if (format == SND_PCM_FORMAT_UNKNOWN)
ksft_exit_fail_msg("Wrong format '%s'\n", cs); ksft_exit_fail_msg("Wrong format '%s'\n", cs);
rate = conf_get_long(data->pcm_config, cfg_prefix, "rate", srate); rate = conf_get_long(data->pcm_config, test->cfg_prefix, "rate", test->rate);
channels = conf_get_long(data->pcm_config, cfg_prefix, "channels", schannels); channels = conf_get_long(data->pcm_config, test->cfg_prefix, "channels", test->channels);
period_size = conf_get_long(data->pcm_config, cfg_prefix, "period_size", speriod_size); period_size = conf_get_long(data->pcm_config, test->cfg_prefix, "period_size", test->period_size);
buffer_size = conf_get_long(data->pcm_config, cfg_prefix, "buffer_size", sbuffer_size); buffer_size = conf_get_long(data->pcm_config, test->cfg_prefix, "buffer_size", test->buffer_size);
automatic = strcmp(sformat, snd_pcm_format_name(format)) == 0 && automatic = strcmp(test->format, snd_pcm_format_name(format)) == 0 &&
srate == rate && test->rate == rate &&
schannels == channels && test->channels == channels &&
speriod_size == period_size && test->period_size == period_size &&
sbuffer_size == buffer_size; test->buffer_size == buffer_size;
samples = malloc((rate * channels * snd_pcm_format_physical_width(format)) / 8); samples = malloc((rate * channels * snd_pcm_format_physical_width(format)) / 8);
if (!samples) if (!samples)
...@@ -293,7 +300,7 @@ static void test_pcm_time1(struct pcm_data *data, ...@@ -293,7 +300,7 @@ static void test_pcm_time1(struct pcm_data *data,
if (automatic && format == SND_PCM_FORMAT_S16_LE) { if (automatic && format == SND_PCM_FORMAT_S16_LE) {
format = SND_PCM_FORMAT_S32_LE; format = SND_PCM_FORMAT_S32_LE;
ksft_print_msg("%s.%d.%d.%d.%s.%s format S16_LE -> S32_LE\n", ksft_print_msg("%s.%d.%d.%d.%s.%s format S16_LE -> S32_LE\n",
cfg_prefix, test->cfg_prefix,
data->card, data->device, data->subdevice, data->card, data->device, data->subdevice,
snd_pcm_stream_name(data->stream), snd_pcm_stream_name(data->stream),
snd_pcm_access_name(access)); snd_pcm_access_name(access));
...@@ -362,7 +369,7 @@ static void test_pcm_time1(struct pcm_data *data, ...@@ -362,7 +369,7 @@ static void test_pcm_time1(struct pcm_data *data,
} }
ksft_print_msg("%s.%d.%d.%d.%s hw_params.%s.%s.%ld.%ld.%ld.%ld sw_params.%ld\n", ksft_print_msg("%s.%d.%d.%d.%s hw_params.%s.%s.%ld.%ld.%ld.%ld sw_params.%ld\n",
cfg_prefix, test->cfg_prefix,
data->card, data->device, data->subdevice, data->card, data->device, data->subdevice,
snd_pcm_stream_name(data->stream), snd_pcm_stream_name(data->stream),
snd_pcm_access_name(access), snd_pcm_access_name(access),
...@@ -411,7 +418,7 @@ static void test_pcm_time1(struct pcm_data *data, ...@@ -411,7 +418,7 @@ static void test_pcm_time1(struct pcm_data *data,
pass = true; pass = true;
__close: __close:
ksft_test_result(pass, "%s.%d.%d.%d.%s%s%s\n", ksft_test_result(pass, "%s.%d.%d.%d.%s%s%s\n",
cfg_prefix, test->cfg_prefix,
data->card, data->device, data->subdevice, data->card, data->device, data->subdevice,
snd_pcm_stream_name(data->stream), snd_pcm_stream_name(data->stream),
msg[0] ? " " : "", msg); msg[0] ? " " : "", msg);
...@@ -420,11 +427,16 @@ static void test_pcm_time1(struct pcm_data *data, ...@@ -420,11 +427,16 @@ static void test_pcm_time1(struct pcm_data *data,
snd_pcm_close(handle); snd_pcm_close(handle);
} }
#define TESTS_PER_PCM 2 static const struct time_test_def time_tests[] = {
/* name format rate chan period buffer */
{ "test.time1", "S16_LE", 48000, 2, 512, 4096 },
{ "test.time2", "S16_LE", 48000, 2, 24000, 192000 },
};
int main(void) int main(void)
{ {
struct pcm_data *pcm; struct pcm_data *pcm;
int i;
ksft_print_header(); ksft_print_header();
...@@ -432,7 +444,7 @@ int main(void) ...@@ -432,7 +444,7 @@ int main(void)
find_pcms(); find_pcms();
ksft_set_plan(num_missing + num_pcms * TESTS_PER_PCM); ksft_set_plan(num_missing + num_pcms * ARRAY_SIZE(time_tests));
for (pcm = pcm_missing; pcm != NULL; pcm = pcm->next) { for (pcm = pcm_missing; pcm != NULL; pcm = pcm->next) {
ksft_test_result(false, "test.missing.%d.%d.%d.%s\n", ksft_test_result(false, "test.missing.%d.%d.%d.%s\n",
...@@ -441,8 +453,9 @@ int main(void) ...@@ -441,8 +453,9 @@ int main(void)
} }
for (pcm = pcm_list; pcm != NULL; pcm = pcm->next) { for (pcm = pcm_list; pcm != NULL; pcm = pcm->next) {
test_pcm_time1(pcm, "test.time1", "S16_LE", 48000, 2, 512, 4096); for (i = 0; i < ARRAY_SIZE(time_tests); i++) {
test_pcm_time1(pcm, "test.time2", "S16_LE", 48000, 2, 24000, 192000); test_pcm_time1(pcm, &time_tests[i]);
}
} }
conf_free(); conf_free();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment