From patchwork Tue Nov 29 08:53:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaroslav Kysela X-Patchwork-Id: 13058354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9A96FC4332F for ; Tue, 29 Nov 2022 08:54:22 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id D88D91663; Tue, 29 Nov 2022 09:53:29 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D88D91663 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1669712059; bh=OXJHGABVUryCsc0cQCu1OJiE8wYMy8xGVZqgKccRz10=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=saE54jQy7JhezMRQ1qhL3Mn/KyOfS+0Z43xF47ZC6bCcZmcg8ioDLXj4952eowlqy s4/y2RzXwAAWTPgzXiQbglEUYveAVHAgyft3hqTbOUKbUYDllFYJsAfkTrxvQpx2fU gmp7sa9+sPYUbK2sT4UZz6ydphN0m8FQ07U3xhlY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 851CAF801F5; Tue, 29 Nov 2022 09:53:29 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id ADBC3F801F7; Tue, 29 Nov 2022 09:53:27 +0100 (CET) Received: from mail1.perex.cz (mail1.perex.cz [77.48.224.245]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 74A75F80137 for ; Tue, 29 Nov 2022 09:53:16 +0100 (CET) Received: from mail1.perex.cz (localhost [127.0.0.1]) by smtp1.perex.cz (Perex's E-mail Delivery System) with ESMTP id B8315A003F; Tue, 29 Nov 2022 09:53:15 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.perex.cz B8315A003F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=perex.cz; s=default; t=1669711995; bh=ZuqTF/kXfHsbw0RNdeSEEjlfrwG1HBuYOcJUr8ozmoA=; h=From:To:Cc:Subject:Date:From; b=TUUoj/v8diqQRVMVro47GIJ+3Li0ah1ewNuG3GglLIOJyTVgTj6hZwzwzCdqYtchy i1n5YYCYVfTrSBzTqtfghK7GvUTFKz2zrVF50nW+IY7uUNpOwsWcupMPWpmDLw7j+6 lNkJjXDCxINFdmwoPs7vY5PT4iXbaX/rBcoVAN+E= Received: from p1gen2.perex-int.cz (unknown [192.168.100.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: perex) by mail1.perex.cz (Perex's E-mail Delivery System) with ESMTPSA; Tue, 29 Nov 2022 09:53:09 +0100 (CET) From: Jaroslav Kysela To: ALSA development Subject: [PATCH] selftests: alsa - move shared library configuration code to conf.c Date: Tue, 29 Nov 2022 09:53:06 +0100 Message-Id: <20221129085306.2345763-1-perex@perex.cz> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Cc: Takashi Iwai , Mark Brown , Shuah Khan , linux-kselftest@vger.kernel.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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: linux-kselftest@vger.kernel.org Cc: Shuah Khan Reported-by: Mark Brown Signed-off-by: Jaroslav Kysela Tested-by: Mark Brown --- tools/testing/selftests/alsa/Makefile | 13 ++++- tools/testing/selftests/alsa/alsa-local.h | 2 + tools/testing/selftests/alsa/conf.c | 69 ++++++++++++++++++++++ tools/testing/selftests/alsa/mixer-test.c | 53 +---------------- tools/testing/selftests/alsa/pcm-test.c | 70 ----------------------- 5 files changed, 85 insertions(+), 122 deletions(-) diff --git a/tools/testing/selftests/alsa/Makefile b/tools/testing/selftests/alsa/Makefile index 8ac22d2eb2ba..a8c0383878d3 100644 --- a/tools/testing/selftests/alsa/Makefile +++ b/tools/testing/selftests/alsa/Makefile @@ -6,9 +6,20 @@ LDLIBS += $(shell pkg-config --libs alsa) ifeq ($(LDLIBS),) LDLIBS += -lasound endif +CFLAGS += -L$(OUTPUT) -Wl,-rpath=./ + +OVERRIDE_TARGETS = 1 TEST_GEN_PROGS := mixer-test pcm-test -pcm-test: pcm-test.c conf.c +TEST_GEN_PROGS_EXTENDED := libatest.so + +TEST_FILES := conf.d include ../lib.mk + +$(OUTPUT)/libatest.so: conf.c alsa-local.h + $(CC) $(CFLAGS) -shared -fPIC $< $(LDLIBS) -o $@ + +$(OUTPUT)/%: %.c $(TEST_GEN_PROGS_EXTENDED) alsa-local.h + $(CC) $(CFLAGS) $< $(LDLIBS) -latest -o $@ diff --git a/tools/testing/selftests/alsa/alsa-local.h b/tools/testing/selftests/alsa/alsa-local.h index fd0771ac600d..65f197ea9773 100644 --- a/tools/testing/selftests/alsa/alsa-local.h +++ b/tools/testing/selftests/alsa/alsa-local.h @@ -10,6 +10,8 @@ #include +snd_config_t *get_alsalib_config(void); + void conf_load(void); void conf_free(void); snd_config_t *conf_by_card(int card); diff --git a/tools/testing/selftests/alsa/conf.c b/tools/testing/selftests/alsa/conf.c index dd6aa90deef9..c7ffc8f04195 100644 --- a/tools/testing/selftests/alsa/conf.c +++ b/tools/testing/selftests/alsa/conf.c @@ -28,6 +28,75 @@ struct card_data { static struct card_data *conf_cards; +static const char *alsa_config = +"ctl.hw {\n" +" @args [ CARD ]\n" +" @args.CARD.type string\n" +" type hw\n" +" card $CARD\n" +"}\n" +"pcm.hw {\n" +" @args [ CARD DEV SUBDEV ]\n" +" @args.CARD.type string\n" +" @args.DEV.type integer\n" +" @args.SUBDEV.type integer\n" +" type hw\n" +" card $CARD\n" +" device $DEV\n" +" subdevice $SUBDEV\n" +"}\n" +; + +#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 +static 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 + +snd_config_t *get_alsalib_config(void) +{ + snd_config_t *config; + int err; + + 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(); + } + return config; +} + static struct card_data *conf_data_by_card(int card, bool msg) { struct card_data *conf; diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c index a38b89c28030..05f1749ae19d 100644 --- a/tools/testing/selftests/alsa/mixer-test.c +++ b/tools/testing/selftests/alsa/mixer-test.c @@ -26,6 +26,7 @@ #include #include "../kselftest.h" +#include "alsa-local.h" #define TESTS_PER_CONTROL 7 @@ -50,56 +51,11 @@ 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; -#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 -static 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 - static void find_controls(void) { char name[32]; @@ -112,12 +68,7 @@ static void find_controls(void) 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(); - } + config = get_alsalib_config(); while (card >= 0) { sprintf(name, "hw:%d", card); diff --git a/tools/testing/selftests/alsa/pcm-test.c b/tools/testing/selftests/alsa/pcm-test.c index 2814d8f74f82..6e7dfc395b98 100644 --- a/tools/testing/selftests/alsa/pcm-test.c +++ b/tools/testing/selftests/alsa/pcm-test.c @@ -31,26 +31,6 @@ struct pcm_data { struct pcm_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" -"pcm.hw {\n" -" @args [ CARD DEV SUBDEV ]\n" -" @args.CARD.type string\n" -" @args.DEV.type integer\n" -" @args.SUBDEV.type integer\n" -" type hw\n" -" card $CARD\n" -" device $DEV\n" -" subdevice $SUBDEV\n" -"}\n" - -; - int num_pcms = 0; struct pcm_data *pcm_list = NULL; @@ -77,56 +57,6 @@ long long timestamp_diff_ms(timestamp_t *tstamp) return (diff.tv_sec * 1000) + ((diff.tv_nsec + 500000L) / 1000000L); } -#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 -static 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 - -static snd_config_t *get_alsalib_config(void) -{ - snd_config_t *config; - int err; - - 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(); - } - return config; -} - static long device_from_id(snd_config_t *node) { const char *id;