mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
kselftest: alsa: Use private alsa-lib configuration in mixer test
As mentined by Takashi Sakamoto, the system-wide alsa-lib configuration may override the standard device declarations. This patch use the private alsa-lib configuration to set the predictable environment. Signed-off-by: Jaroslav Kysela <perex@perex.cz> Link: https://lore.kernel.org/r/20211208095209.1772296-1-perex@perex.cz [Restructure version test to keep the preprocessor happy -- broonie] Reviewed-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20211210185410.740009-4-broonie@kernel.org Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
7cc994f27e
commit
b73dad8065
1 changed files with 55 additions and 1 deletions
|
@ -46,22 +46,74 @@ struct ctl_data {
|
||||||
struct ctl_data *next;
|
struct ctl_data *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *alsa_config =
|
||||||
|
"ctl.hw {\n"
|
||||||
|
" @args [ CARD ]\n"
|
||||||
|
" @args.CARD.type string\n"
|
||||||
|
" type hw\n"
|
||||||
|
" card $CARD\n"
|
||||||
|
"}\n"
|
||||||
|
;
|
||||||
|
|
||||||
int num_cards = 0;
|
int num_cards = 0;
|
||||||
int num_controls = 0;
|
int num_controls = 0;
|
||||||
struct card_data *card_list = NULL;
|
struct card_data *card_list = NULL;
|
||||||
struct ctl_data *ctl_list = NULL;
|
struct ctl_data *ctl_list = NULL;
|
||||||
|
|
||||||
|
#ifdef SND_LIB_VER
|
||||||
|
#if SND_LIB_VERSION >= SND_LIB_VER(1, 2, 6)
|
||||||
|
#define LIB_HAS_LOAD_STRING
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LIB_HAS_LOAD_STRING
|
||||||
|
int snd_config_load_string(snd_config_t **config, const char *s, size_t size)
|
||||||
|
{
|
||||||
|
snd_input_t *input;
|
||||||
|
snd_config_t *dst;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
assert(config && s);
|
||||||
|
if (size == 0)
|
||||||
|
size = strlen(s);
|
||||||
|
err = snd_input_buffer_open(&input, s, size);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
err = snd_config_top(&dst);
|
||||||
|
if (err < 0) {
|
||||||
|
snd_input_close(input);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
err = snd_config_load(dst, input);
|
||||||
|
snd_input_close(input);
|
||||||
|
if (err < 0) {
|
||||||
|
snd_config_delete(dst);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
*config = dst;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void find_controls(void)
|
void find_controls(void)
|
||||||
{
|
{
|
||||||
char name[32];
|
char name[32];
|
||||||
int card, ctl, err;
|
int card, ctl, err;
|
||||||
struct card_data *card_data;
|
struct card_data *card_data;
|
||||||
struct ctl_data *ctl_data;
|
struct ctl_data *ctl_data;
|
||||||
|
snd_config_t *config;
|
||||||
|
|
||||||
card = -1;
|
card = -1;
|
||||||
if (snd_card_next(&card) < 0 || card < 0)
|
if (snd_card_next(&card) < 0 || card < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
err = snd_config_load_string(&config, alsa_config, strlen(alsa_config));
|
||||||
|
if (err < 0) {
|
||||||
|
ksft_print_msg("Unable to parse custom alsa-lib configuration: %s\n",
|
||||||
|
snd_strerror(err));
|
||||||
|
ksft_exit_fail();
|
||||||
|
}
|
||||||
|
|
||||||
while (card >= 0) {
|
while (card >= 0) {
|
||||||
sprintf(name, "hw:%d", card);
|
sprintf(name, "hw:%d", card);
|
||||||
|
|
||||||
|
@ -69,7 +121,7 @@ void find_controls(void)
|
||||||
if (!card_data)
|
if (!card_data)
|
||||||
ksft_exit_fail_msg("Out of memory\n");
|
ksft_exit_fail_msg("Out of memory\n");
|
||||||
|
|
||||||
err = snd_ctl_open(&card_data->handle, name, 0);
|
err = snd_ctl_open_lconf(&card_data->handle, name, 0, config);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
ksft_print_msg("Failed to get hctl for card %d: %s\n",
|
ksft_print_msg("Failed to get hctl for card %d: %s\n",
|
||||||
card, snd_strerror(err));
|
card, snd_strerror(err));
|
||||||
|
@ -137,6 +189,8 @@ void find_controls(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snd_config_delete(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue