Skip to content

Commit b310092

Browse files
perexgtiwai
authored andcommitted
selftests: alsa - move shared library configuration code to conf.c
The minimal alsa-lib configuration code is similar in both mixer and pcm tests. Move this code to the shared conf.c source file. Also, fix the build rules inspired by rseq tests. Build libatest.so which is linked to the both test utilities dynamically. Also, set the TEST_FILES variable for lib.mk. Cc: [email protected] Cc: Shuah Khan <[email protected]> Reported-by: Mark Brown <[email protected]> Signed-off-by: Jaroslav Kysela <[email protected]> Tested-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 67df411 commit b310092

File tree

5 files changed

+85
-122
lines changed

5 files changed

+85
-122
lines changed

tools/testing/selftests/alsa/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ LDLIBS += $(shell pkg-config --libs alsa)
66
ifeq ($(LDLIBS),)
77
LDLIBS += -lasound
88
endif
9+
CFLAGS += -L$(OUTPUT) -Wl,-rpath=./
10+
11+
OVERRIDE_TARGETS = 1
912

1013
TEST_GEN_PROGS := mixer-test pcm-test
1114

12-
pcm-test: pcm-test.c conf.c
15+
TEST_GEN_PROGS_EXTENDED := libatest.so
16+
17+
TEST_FILES := conf.d
1318

1419
include ../lib.mk
20+
21+
$(OUTPUT)/libatest.so: conf.c alsa-local.h
22+
$(CC) $(CFLAGS) -shared -fPIC $< $(LDLIBS) -o $@
23+
24+
$(OUTPUT)/%: %.c $(TEST_GEN_PROGS_EXTENDED) alsa-local.h
25+
$(CC) $(CFLAGS) $< $(LDLIBS) -latest -o $@

tools/testing/selftests/alsa/alsa-local.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include <alsa/asoundlib.h>
1212

13+
snd_config_t *get_alsalib_config(void);
14+
1315
void conf_load(void);
1416
void conf_free(void);
1517
snd_config_t *conf_by_card(int card);

tools/testing/selftests/alsa/conf.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,75 @@ struct card_data {
2828

2929
static struct card_data *conf_cards;
3030

31+
static const char *alsa_config =
32+
"ctl.hw {\n"
33+
" @args [ CARD ]\n"
34+
" @args.CARD.type string\n"
35+
" type hw\n"
36+
" card $CARD\n"
37+
"}\n"
38+
"pcm.hw {\n"
39+
" @args [ CARD DEV SUBDEV ]\n"
40+
" @args.CARD.type string\n"
41+
" @args.DEV.type integer\n"
42+
" @args.SUBDEV.type integer\n"
43+
" type hw\n"
44+
" card $CARD\n"
45+
" device $DEV\n"
46+
" subdevice $SUBDEV\n"
47+
"}\n"
48+
;
49+
50+
#ifdef SND_LIB_VER
51+
#if SND_LIB_VERSION >= SND_LIB_VER(1, 2, 6)
52+
#define LIB_HAS_LOAD_STRING
53+
#endif
54+
#endif
55+
56+
#ifndef LIB_HAS_LOAD_STRING
57+
static int snd_config_load_string(snd_config_t **config, const char *s,
58+
size_t size)
59+
{
60+
snd_input_t *input;
61+
snd_config_t *dst;
62+
int err;
63+
64+
assert(config && s);
65+
if (size == 0)
66+
size = strlen(s);
67+
err = snd_input_buffer_open(&input, s, size);
68+
if (err < 0)
69+
return err;
70+
err = snd_config_top(&dst);
71+
if (err < 0) {
72+
snd_input_close(input);
73+
return err;
74+
}
75+
err = snd_config_load(dst, input);
76+
snd_input_close(input);
77+
if (err < 0) {
78+
snd_config_delete(dst);
79+
return err;
80+
}
81+
*config = dst;
82+
return 0;
83+
}
84+
#endif
85+
86+
snd_config_t *get_alsalib_config(void)
87+
{
88+
snd_config_t *config;
89+
int err;
90+
91+
err = snd_config_load_string(&config, alsa_config, strlen(alsa_config));
92+
if (err < 0) {
93+
ksft_print_msg("Unable to parse custom alsa-lib configuration: %s\n",
94+
snd_strerror(err));
95+
ksft_exit_fail();
96+
}
97+
return config;
98+
}
99+
31100
static struct card_data *conf_data_by_card(int card, bool msg)
32101
{
33102
struct card_data *conf;

tools/testing/selftests/alsa/mixer-test.c

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <stdint.h>
2727

2828
#include "../kselftest.h"
29+
#include "alsa-local.h"
2930

3031
#define TESTS_PER_CONTROL 7
3132

@@ -50,56 +51,11 @@ struct ctl_data {
5051
struct ctl_data *next;
5152
};
5253

53-
static const char *alsa_config =
54-
"ctl.hw {\n"
55-
" @args [ CARD ]\n"
56-
" @args.CARD.type string\n"
57-
" type hw\n"
58-
" card $CARD\n"
59-
"}\n"
60-
;
61-
6254
int num_cards = 0;
6355
int num_controls = 0;
6456
struct card_data *card_list = NULL;
6557
struct ctl_data *ctl_list = NULL;
6658

67-
#ifdef SND_LIB_VER
68-
#if SND_LIB_VERSION >= SND_LIB_VER(1, 2, 6)
69-
#define LIB_HAS_LOAD_STRING
70-
#endif
71-
#endif
72-
73-
#ifndef LIB_HAS_LOAD_STRING
74-
static int snd_config_load_string(snd_config_t **config, const char *s,
75-
size_t size)
76-
{
77-
snd_input_t *input;
78-
snd_config_t *dst;
79-
int err;
80-
81-
assert(config && s);
82-
if (size == 0)
83-
size = strlen(s);
84-
err = snd_input_buffer_open(&input, s, size);
85-
if (err < 0)
86-
return err;
87-
err = snd_config_top(&dst);
88-
if (err < 0) {
89-
snd_input_close(input);
90-
return err;
91-
}
92-
err = snd_config_load(dst, input);
93-
snd_input_close(input);
94-
if (err < 0) {
95-
snd_config_delete(dst);
96-
return err;
97-
}
98-
*config = dst;
99-
return 0;
100-
}
101-
#endif
102-
10359
static void find_controls(void)
10460
{
10561
char name[32];
@@ -112,12 +68,7 @@ static void find_controls(void)
11268
if (snd_card_next(&card) < 0 || card < 0)
11369
return;
11470

115-
err = snd_config_load_string(&config, alsa_config, strlen(alsa_config));
116-
if (err < 0) {
117-
ksft_print_msg("Unable to parse custom alsa-lib configuration: %s\n",
118-
snd_strerror(err));
119-
ksft_exit_fail();
120-
}
71+
config = get_alsalib_config();
12172

12273
while (card >= 0) {
12374
sprintf(name, "hw:%d", card);

tools/testing/selftests/alsa/pcm-test.c

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,6 @@ struct pcm_data {
3131
struct pcm_data *next;
3232
};
3333

34-
static const char *alsa_config =
35-
"ctl.hw {\n"
36-
" @args [ CARD ]\n"
37-
" @args.CARD.type string\n"
38-
" type hw\n"
39-
" card $CARD\n"
40-
"}\n"
41-
"pcm.hw {\n"
42-
" @args [ CARD DEV SUBDEV ]\n"
43-
" @args.CARD.type string\n"
44-
" @args.DEV.type integer\n"
45-
" @args.SUBDEV.type integer\n"
46-
" type hw\n"
47-
" card $CARD\n"
48-
" device $DEV\n"
49-
" subdevice $SUBDEV\n"
50-
"}\n"
51-
52-
;
53-
5434
int num_pcms = 0;
5535
struct pcm_data *pcm_list = NULL;
5636

@@ -77,56 +57,6 @@ long long timestamp_diff_ms(timestamp_t *tstamp)
7757
return (diff.tv_sec * 1000) + ((diff.tv_nsec + 500000L) / 1000000L);
7858
}
7959

80-
#ifdef SND_LIB_VER
81-
#if SND_LIB_VERSION >= SND_LIB_VER(1, 2, 6)
82-
#define LIB_HAS_LOAD_STRING
83-
#endif
84-
#endif
85-
86-
#ifndef LIB_HAS_LOAD_STRING
87-
static int snd_config_load_string(snd_config_t **config, const char *s,
88-
size_t size)
89-
{
90-
snd_input_t *input;
91-
snd_config_t *dst;
92-
int err;
93-
94-
assert(config && s);
95-
if (size == 0)
96-
size = strlen(s);
97-
err = snd_input_buffer_open(&input, s, size);
98-
if (err < 0)
99-
return err;
100-
err = snd_config_top(&dst);
101-
if (err < 0) {
102-
snd_input_close(input);
103-
return err;
104-
}
105-
err = snd_config_load(dst, input);
106-
snd_input_close(input);
107-
if (err < 0) {
108-
snd_config_delete(dst);
109-
return err;
110-
}
111-
*config = dst;
112-
return 0;
113-
}
114-
#endif
115-
116-
static snd_config_t *get_alsalib_config(void)
117-
{
118-
snd_config_t *config;
119-
int err;
120-
121-
err = snd_config_load_string(&config, alsa_config, strlen(alsa_config));
122-
if (err < 0) {
123-
ksft_print_msg("Unable to parse custom alsa-lib configuration: %s\n",
124-
snd_strerror(err));
125-
ksft_exit_fail();
126-
}
127-
return config;
128-
}
129-
13060
static long device_from_id(snd_config_t *node)
13161
{
13262
const char *id;

0 commit comments

Comments
 (0)