kselftest: alsa: Use private alsa-lib configuration in mixer test
Subsystems (3)
Jaroslav Kysela
maintainerPATCH 1/1 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.
--- tools/testing/selftests/alsa/mixer-test.c | 50 ++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-)
tools/testing/selftests/alsa/mixer-test.c +49 -1
@@ -46,22 +46,68 @@ struct ctl_data {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_controls =0 ;struct card_data *card_list =NULL ;struct ctl_data *ctl_list =NULL ; +#if !defined(SND_LIB_VER ) ||SND_LIB_VERSION <SND_LIB_VER (1 ,2 ,6 ) +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 ) {char name[32 ];int card, ctl, err;struct card_data *card_data;struct ctl_data *ctl_data; +snd_config_t *config; card =-1 ;if (snd_card_next (&card) <0 || card <0 )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 ) {sprintf (name,"hw:%d" , card);
@@ -71,7 +117,7 @@ void find_controls(void)ksft_exit_fail (); } - err =snd_ctl_open (&card_data->handle, name,0 ); + err =snd_ctl_open_lconf (&card_data->handle, name,0 , config);if (err <0 ) {ksft_print_msg ("Failed to get hctl for card %d: %s\n" , card,snd_strerror (err));
@@ -147,6 +193,8 @@ void find_controls(void)break ; } } + +snd_config_delete (config); }/*
Signature · 1 line
2.31.1
Quoted 3 lines · Jaroslav Kysela
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.
Quoted 11 lines · Jaroslav Kysela
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.
Cc Mark Brown <[email protected]>Cc Shuah Khan <[email protected]>Cc Takashi Sakamoto <[email protected]>Cc Pierre-Louis Bossart <[email protected]>Signed-off-by Jaroslav Kysela <[email protected]>
Quoted 3 lines
--- tools/testing/selftests/alsa/mixer-test.c | 50 ++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-)
I'm not positively for the patch since it can take developers puzzled due to the symbol dependency newly introduced in unreleased version of alsa-lib. It's better to check the version of alsa-lib in Makefile to avoid developers’dole if we have enough respect to embedded developers, especially forced to work with legacy userspace. (and it often occurs).
As a side note, I think it better to change symbol table (alsa-lib/src/Versions.in) if introducing new public symbol of c library.
Regards
Takashi Sakamoto
Mark Brown
maintainerQuoted 2 lines · Takashi Sakamoto
I'm not positively for the patch since it can take developers puzzled due to the symbol dependency newly introduced in unreleased version of alsa-lib.
Shouldn't the version check and local definition avoid that issue - if the version of alsa-lib doesn't have snd_config_load_string() then we'll use a locally defined version of snd_config_load_string() and not depend on the alsa-lib symbol?
Quoted 3 lines
It's better to check the version of alsa-lib in
Makefileto avoid developers’dole if we have enough respect to embedded developers, especially forced to work with legacy userspace. (and it often occurs).
Or just avoid using fancy new library features - if we need to limit the test to only building with bleeding edge versions that gets restrictive. TBH this is probably even more painful for people working with enterprise distros than embedded systems, if you're building everything for your target it's not usually too bad to drop in an updated version of something like alsa-lib but if you're using disro binaries it's less idiomatic. Either way it's a barrier though.
Jaroslav Kysela
maintainerQuoted 9 lines · Mark Brown
Quoted 2 lines · Takashi Sakamoto
I'm not positively for the patch since it can take developers puzzled due to the symbol dependency newly introduced in unreleased version of alsa-lib.
Shouldn't the version check and local definition avoid that issue - if the version of alsa-lib doesn't have
snd_config_load_string()then we'll use a locally defined version ofsnd_config_load_string()and not depend on the alsa-lib symbol?
The 1.2.6 library is released. The goal was to allow to run code with the older libraries until the new version is more spread. It's just one #if in the source code and a 1:1 code copy. The kselftest packagers should define the proper package dependencies for the downgrade possibility - it's distribution specific thing.
Anyway, the dynamic linker will print the correct error when the user tries to run the test program compiled using the new library on the system with the older library.
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Mark Brown
maintainerQuoted 1 line · Jaroslav Kysela
+#if !defined(SND_LIB_VER) ||
SND_LIB_VERSION<SND_LIB_VER(1, 2, 6)
This barfs if the local definition is used since the preprocessor will try to evaluate SND_LIB_VER even if the macro is not defined and the left hand side of the || is true:
mixer-test.c:66:60: error: missing binary operator before token "("
66 | #if !defined(SND_LIB_VER) || (SND_LIB_VERSION < SND_LIB_VER(1, 2, 6))
| ^
SND_LIB_VER was only added in v1.2.5 so currently used distros run into this. I've restructured to:
#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
which is a bit ugly but splits the use of SND_LIB_VER into a separate if statement which causes the preprocessor to do the right thing.