From patchwork Thu Mar 18 10:30:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 404842 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E079BC433DB for ; Thu, 18 Mar 2021 10:34:02 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id DE6C164F18 for ; Thu, 18 Mar 2021 10:34:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE6C164F18 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 4E45016D2; Thu, 18 Mar 2021 11:33:10 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4E45016D2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616063640; bh=l7n+8hfAB/JYeYFL5oFJlNo5w6gQ8m3lBYP8Ij19vrg=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pKGkjpwiTtfdxOkP8+C/jA/88dpaDvt7neTuYGdRniF4J0FJ/kj6hcUUGWrMcrEft jqFYGciHBVDumtJEBtOMMysCRdc8PUdPOn14oeFHJ0UUqua7wjU6MZgVy+YODUXURx wbY5gpcz1ZaecpmB26xfjaZ7mZenV7yOVd3UOtQE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 588C7F804B1; Thu, 18 Mar 2021 11:30:48 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C9F69F8032D; Thu, 18 Mar 2021 11:30:42 +0100 (CET) Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id C04C0F80171 for ; Thu, 18 Mar 2021 11:30:22 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C04C0F80171 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="rJkKlJ6c"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LbsLUohU" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id D0A191AD5; Thu, 18 Mar 2021 06:30:20 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 18 Mar 2021 06:30:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=OvphCkYMlzC+s TR4NuN56kjC2Ei6zNmNLQaDc58oywg=; b=rJkKlJ6cI43cip9iW8C/IVc2S/+h5 c4rVPHU7XrE6TwGP/qLwwbzvFDgHe5dPJnU5vjdJrMWx4Y0E+8eNZQRtkPvweUN/ 1y+G+nNFUml34cMKIHm4aimOvBAaXfAyJEnjrpL3XkxW1/0mWEiUQApujJUeqfXe bA9KYeCaUVbNcHe92KS5GJIQXr+aw0ZPuNcbMwbw+wYCHDPNRJyFoGXTREFbjlYv 40hBYzYs7An3lGrNbiLQEplENC281NEYyXgLjZ1z0njA3Oo+FRfVzRLhxvTMsESe nHvh8WRfIvay61Ppa46M4EqVUEyiML6/NdXABEWii6u4Elz0jRVH6iEBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=OvphCkYMlzC+sTR4NuN56kjC2Ei6zNmNLQaDc58oywg=; b=LbsLUohU 1rY78fKG7VQEyQ9UpUUdQzDQrbK8rwNIULEA6+SQyiPYqTFo+51ha8Bfwzfap3/i wVaFmrRtZJ/ZJFDH0RtwsrpT71KNwVA5OqLOytRWOESfwcVhzGA7q1dKKV7Lct2R O3ayaYn7tlxindW1KatF+ScD9EKas7EJjvoiI3AaInaz48V9rooQU12hynb0Zu3h B45zq0VSsfZaY+jojPTT+lBTR0jwW1dbZC8mEsFIyIITu6uXi5K6V8CMI7GrmCOF QsGQUknRbAOUV6cJiUafuRona85Wu3JnPmxEnm3/SqxSsJGgCo328t/735mwV2xd jut6fUTELins2A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefiedgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecukfhppedugedr fedrieehrddujeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: from workstation.flets-east.jp (ae065175.dynamic.ppp.asahi-net.or.jp [14.3.65.175]) by mail.messagingengine.com (Postfix) with ESMTPA id 6FF371080057; Thu, 18 Mar 2021 06:30:18 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de, perex@perex.cz Subject: [alsa-lib][PATCH 1/6] test: ctl-elem-id: add test program for future APIs relevant to control element ID Date: Thu, 18 Mar 2021 19:30:08 +0900 Message-Id: <20210318103013.265264-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210318103013.265264-1-o-takashi@sakamocchi.jp> References: <20210318103013.265264-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, tanjeff@cccmz.de 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" Some APIs are planned to add for equality check and comparison of a pair of control element IDs. The equality check and comparison are quite basic methods to operate data, thus it's preferable not to include any bug. This commit adds skeleton of test program for the APIs. Signed-off-by: Takashi Sakamoto --- test/lsb/Makefile.am | 6 +++-- test/lsb/ctl-elem-id.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 test/lsb/ctl-elem-id.c diff --git a/test/lsb/Makefile.am b/test/lsb/Makefile.am index ceb4d715..7d5f754d 100644 --- a/test/lsb/Makefile.am +++ b/test/lsb/Makefile.am @@ -1,5 +1,7 @@ -TESTS = config -TESTS += midi_event +TESTS = \ + config \ + midi_event \ + ctl-elem-id check_PROGRAMS = $(TESTS) noinst_HEADERS = test.h diff --git a/test/lsb/ctl-elem-id.c b/test/lsb/ctl-elem-id.c new file mode 100644 index 00000000..ae416698 --- /dev/null +++ b/test/lsb/ctl-elem-id.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// +// ctl-elem-id.c - a test program for equality and some comparison algorithms +// for control element ID structure. +// +// Copyright (c) 2021 Takashi Sakamoto +// +// Licensed under the terms of the GNU General Public License, version 2. + +#include +#include + +#include +#include +#include + +#include + +#include "../include/asoundlib.h" + +int main() +{ + void (*entries[])(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) = { + }; + int count = sizeof(entries) / sizeof(*entries); + int fd; + uint8_t *buf; + int i; + + fd = open("/dev/urandom", O_RDONLY); + if (fd < 0) + return EXIT_FAILURE; + + buf = calloc(snd_ctl_elem_id_sizeof(), 2); + if (buf == NULL) + goto error_urandom; + + for (i = 0; i < count; ++i) { + snd_ctl_elem_id_t *l, *r; + ssize_t len; +randomize: + len = read(fd, buf, snd_ctl_elem_id_sizeof() * 2); + if (len < 0) + goto error_memory; + l = (snd_ctl_elem_id_t *)buf; + r = (snd_ctl_elem_id_t *)(buf + snd_ctl_elem_id_sizeof()); + if (!memcmp(l, r, snd_ctl_elem_id_sizeof())) + goto randomize; + + entries[i](l, r); + } + + free(buf); + + return EXIT_SUCCESS; +error_memory: + free(buf); +error_urandom: + close(fd); + return EXIT_FAILURE; +} From patchwork Thu Mar 18 10:30:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 404074 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9F4BC433DB for ; Thu, 18 Mar 2021 10:32:21 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C927864E89 for ; Thu, 18 Mar 2021 10:32:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C927864E89 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 7161B16B6; Thu, 18 Mar 2021 11:31:28 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7161B16B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616063538; bh=GtXTi+eyJtEmY4W0fWnvMDKsiDHBmqs032tVSRiHrOo=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=bEDUI+EcT+cVc1zPUv0GbKtQH5+D9EkfHAfPlarNh/RTsYIw3A7X6GNWcUZ/Iqg6n RYipnK86frwdXsZPeyg3WZPomAX7fuoqho0dlq8BN85y5iiRzxwquoq114sBBt3II6 XhKcpC2wAbJUlEcbsAOhg7AcGb29iihxhZuPJ0RM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 6423DF8027D; Thu, 18 Mar 2021 11:30:38 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8594CF802E3; Thu, 18 Mar 2021 11:30:33 +0100 (CET) Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id BCA16F80165 for ; Thu, 18 Mar 2021 11:30:23 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz BCA16F80165 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="06rCZUHR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lPbCB88t" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id A62081B40; Thu, 18 Mar 2021 06:30:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 18 Mar 2021 06:30:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=u3b4u7AhBKvmx GxRH3d8Y/f0H1IDxZKY6QNRVYncw/Q=; b=06rCZUHRO1ZXqiG1sHqZyN9rdxN8r 83eXcJ3mNNfbVMAm0/jUiZD6fMkw9UywmgdP+KthMYBg9U524sAbO1JH2ah+yRnF NNJvnKEupdOzQYsgzB8i6FA2/rdP94sgnaTVCW92YTknypn3u2uqymJq0PjulGKm yD59dIz25FWVeQhjx4LqCeVl45BJnLp8eCud4ELLzEa1u5HjKrqf/jaiVITiYqq6 myd7uI4BJA5ItDABr5wpZ/cQ/tZ04lVUfr921KcOlZ3YGUrN68SKHOnTbGDv4Oqk R6rrfUwNtjrmdQA3XWdb62HtsP1WiX0GI+yp5iYy5pHXKaiZ4NLdD+xag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=u3b4u7AhBKvmxGxRH3d8Y/f0H1IDxZKY6QNRVYncw/Q=; b=lPbCB88t amWb4z56bSqYoX6AiWuZvd40GAHzbBgsBW/YEj8sTEJDrokOl0qGqgSQZ/YPID29 xEBEmSnR7fvh+pYcqHkzU7p3w7JprsKly0rUN8blPUUkrWMXgKQIOz6+ZTCgnMl4 JwL+5GHsXyf6I0JSwuEvtr861cMWvWg9nlIL6PKCsDkv2L58XQIhZBsIhUXy9PhU AExQEO2N5Z98Ynu+v3a9oVjrY663RalW4uDKSxxgwvSDTuXP8+D5iCw7SSXDHHFY FJQTCQZOFZjAgNi5U6/U/y0WGJgB+yo4SGQdrUdzdMsi9iQEATsp1M0efw+LZyxW ppv3TuSau0vpfA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefiedgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecukfhppedugedr fedrieehrddujeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: from workstation.flets-east.jp (ae065175.dynamic.ppp.asahi-net.or.jp [14.3.65.175]) by mail.messagingengine.com (Postfix) with ESMTPA id C7BA91080069; Thu, 18 Mar 2021 06:30:19 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de, perex@perex.cz Subject: [alsa-lib][PATCH 2/6] ctl: add API to check equality between a pair of control element IDs by numid Date: Thu, 18 Mar 2021 19:30:09 +0900 Message-Id: <20210318103013.265264-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210318103013.265264-1-o-takashi@sakamocchi.jp> References: <20210318103013.265264-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, tanjeff@cccmz.de 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 structure for control element ID is hybrid. It has two ways to check equality; e.g. equality of numid field, and equality of the other fields. Just checking equality according to numid field, current alsa-lib take userspace applications to call snd_ctl_elem_id_get_numid() twice. It's better to add optimized version of the equality check. This commit adds API to check equality of numid field for a pair of control element IDs. Signed-off-by: Takashi Sakamoto --- include/control.h | 1 + src/control/control.c | 19 ++++++++++++++++ test/lsb/ctl-elem-id.c | 50 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/include/control.h b/include/control.h index 40ac2e97..260d7f30 100644 --- a/include/control.h +++ b/include/control.h @@ -424,6 +424,7 @@ int snd_ctl_elem_id_malloc(snd_ctl_elem_id_t **ptr); void snd_ctl_elem_id_free(snd_ctl_elem_id_t *obj); void snd_ctl_elem_id_clear(snd_ctl_elem_id_t *obj); void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src); +int snd_ctl_elem_id_equal_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_compare(snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2); unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj); snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj); diff --git a/src/control/control.c b/src/control/control.c index 197d4f52..6d1eda15 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -83,6 +83,8 @@ the same (driver updates can change it, but in practice this is rare). The numid can change on each boot. In case of an USB sound card, the numid can also change when it is reconnected. +For equality check between a pair of #snd_ctl_elem_id_t according to the numid, +snd_ctl_elem_id_equal_by_numid() is available. \section element_lists Element Lists @@ -1818,6 +1820,23 @@ void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src) *dst = *src; } +/** + * \brief check equality between two arguments according to numid. + * \param l opaque pointer to element ID structure. + * \param r opaque pointer to another element ID structure. + * \retval zero if they equal, else zero. + * + * The structure underlying #snd_ctl_elem_id_t is hybrid one. It has two ways to + * check equality. The API implements one of the ways, according to the value of + * numid field. + */ +int snd_ctl_elem_id_equal_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + assert(l && r); + + return l->numid == r->numid; +} + /** * \brief compare one #snd_ctl_elem_id_t to another * \param id1 pointer to first id diff --git a/test/lsb/ctl-elem-id.c b/test/lsb/ctl-elem-id.c index ae416698..f499b268 100644 --- a/test/lsb/ctl-elem-id.c +++ b/test/lsb/ctl-elem-id.c @@ -18,9 +18,59 @@ #include "../include/asoundlib.h" +static void set_elem_id_by_tuple(snd_ctl_elem_id_t *elem_id, + snd_ctl_elem_iface_t iface, + unsigned int device_id, + unsigned int subdevice_id, + const char *name, + unsigned int index) +{ + snd_ctl_elem_id_set_interface(elem_id, iface); + snd_ctl_elem_id_set_device(elem_id, device_id); + snd_ctl_elem_id_set_subdevice(elem_id, subdevice_id); + snd_ctl_elem_id_set_name(elem_id, name); + snd_ctl_elem_id_set_index(elem_id, index); +} + +// Case 0.0. The same value of numid field should result in true positive. +static void equality_by_numid_0(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + snd_ctl_elem_id_set_numid(l, 33); + snd_ctl_elem_id_set_numid(r, 33); + assert(snd_ctl_elem_id_equal_by_numid(l, r)); +} + +// Case 0.1. The different value of numid field should result in false positive. +static void equality_by_numid_1(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + snd_ctl_elem_id_set_numid(l, 333); + snd_ctl_elem_id_set_numid(r, 444); + assert(!snd_ctl_elem_id_equal_by_numid(l, r)); +} + +// Case 0.2. The same tuple should result in false positive. +static void equality_by_numid_2(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_CARD, 0, 1, "something", 2); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_CARD, 0, 1, "something", 2); + assert(!snd_ctl_elem_id_equal_by_numid(l, r)); +} + +// Case 0.3. The tuple should result in false positive. +static void equality_by_numid_3(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_CARD, 300, 400, "something", 500); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_MIXER, 600, 700, "something", 800); + assert(!snd_ctl_elem_id_equal_by_numid(l, r)); +} + int main() { void (*entries[])(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) = { + equality_by_numid_0, + equality_by_numid_1, + equality_by_numid_2, + equality_by_numid_3, }; int count = sizeof(entries) / sizeof(*entries); int fd; From patchwork Thu Mar 18 10:30:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 404845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB1E4C433E0 for ; Thu, 18 Mar 2021 10:31:30 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 65AD864F18 for ; Thu, 18 Mar 2021 10:31:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 65AD864F18 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 0A7C116A6; Thu, 18 Mar 2021 11:30:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 0A7C116A6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616063486; bh=+bf65RS+gRw1mHwHB+jQfeOipEbN2r4u1pCLQOZElbw=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=hUAEkrWEWAGSRKYbeb5BaXgwZmx/WZSNp/F2GOpGq5SDRT9OQDtqo6ZO9QQ8i+xh3 WMRAt4cXGTtn29GdytUTb2J5bbu3Xl+a4R/qbrwfXVdQ+mZGXGCz4xXe7+D3NgeYkF eELZ9Jb3knBuiIhz1oLWZCYtAEyTTtms2Th/Tr1c= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 6D915F80224; Thu, 18 Mar 2021 11:30:35 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9E625F80165; Thu, 18 Mar 2021 11:30:33 +0100 (CET) Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B9B8CF80163 for ; Thu, 18 Mar 2021 11:30:24 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B9B8CF80163 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="ASjv7rIV"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="u6/iFno2" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 94D9A1B30; Thu, 18 Mar 2021 06:30:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 18 Mar 2021 06:30:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=vPPAzM9Nrw0k0 Th4S6xkOXo+qRGQvJLxs+A0lxcZ0Og=; b=ASjv7rIVh2tIgaMdlBoklHXdPlGI8 SY1Olo+mdCQ7p/mlgLLR3fwN+hxEW1aeL+vq/kjgOW3rrlAP/3ectgLCPHlbfOBv 06lVeqdT0gc7uvLPIvRHljVYGyduQWDWD0WNNvtXIaffGtStDGksbjm4VYZosBXK 2B+O/V92EVMizAZBaOolbzf6YcK+e349DaJwrEoiZz45C2ZfR390zgS0uX4ZVfxy Akvi4IsGIR2lhuquy65yzpkxMyfMVd/K0jz2WqYOdjGF4cQD9SlJkR2GrDCNQ+GG r4xLy/G87N39nydvxtW/BI9DpCZRH+d4C/e5tfDJ7bGsTleU54vVsweUA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=vPPAzM9Nrw0k0Th4S6xkOXo+qRGQvJLxs+A0lxcZ0Og=; b=u6/iFno2 A5NATgeCtGx0LlR6x+wv4oOTBbfw5ZIzoIw2AQHMF2QxiBQC1uHfiNeRnE2xrH9g R5+D23UTkb5aeEBAz89yyqRn2/n20ZsLqhpqdnW8kI7dTPyNokzxzmG3puk2N9Yb OKplEBg882fHurQ5+uC72BO175XbFh5dnPJUg/8raSFASYclTjeq94bCBFk/UsQ4 w0scispSnVY4h172vef4bV8pqMqQ55UF1QjAcHC1um2EGq91XeJbVk0atnDulUEL wZGbHBAJOo13xZpDrq8BSkgU4uzCkgf3nrWwke+GZlXw/Z5LqHhwRJ3GpMqkt40x Vos3cZnJYzusrQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefiedgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecukfhppedugedr fedrieehrddujeehnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilh hfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: from workstation.flets-east.jp (ae065175.dynamic.ppp.asahi-net.or.jp [14.3.65.175]) by mail.messagingengine.com (Postfix) with ESMTPA id 2E1B71080068; Thu, 18 Mar 2021 06:30:21 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de, perex@perex.cz Subject: [alsa-lib][PATCH 3/6] ctl: add API to check equality between a pair of control element IDs by tuple Date: Thu, 18 Mar 2021 19:30:10 +0900 Message-Id: <20210318103013.265264-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210318103013.265264-1-o-takashi@sakamocchi.jp> References: <20210318103013.265264-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, tanjeff@cccmz.de 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 structure for control element ID is hybrid. It has two ways to check equality; e.g. equality of fields except for numid. Just checking equality according to the fields, current alsa-lib take userspace applications to call functions referring to the fields several times. It's better to add optimized version of the equality check. This commit adds API to check the equality of fields for a pair of control element IDs. Signed-off-by: Takashi Sakamoto --- include/control.h | 1 + src/control/control.c | 26 +++++++++++++++++++++++++- test/lsb/ctl-elem-id.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/include/control.h b/include/control.h index 260d7f30..8aca67e6 100644 --- a/include/control.h +++ b/include/control.h @@ -425,6 +425,7 @@ void snd_ctl_elem_id_free(snd_ctl_elem_id_t *obj); void snd_ctl_elem_id_clear(snd_ctl_elem_id_t *obj); void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src); int snd_ctl_elem_id_equal_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); +int snd_ctl_elem_id_equal_by_tuple(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_compare(snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2); unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj); snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj); diff --git a/src/control/control.c b/src/control/control.c index 6d1eda15..93f8f93d 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -84,7 +84,9 @@ rare). The numid can change on each boot. In case of an USB sound card, the numid can also change when it is reconnected. For equality check between a pair of #snd_ctl_elem_id_t according to the numid, -snd_ctl_elem_id_equal_by_numid() is available. +snd_ctl_elem_id_equal_by_numid() is available. For equality check between a pair +of #snd_ctl_elem_id_t according to the tuple, snd_ctl_elem_id_equal_by_tuple() +is available. \section element_lists Element Lists @@ -1837,6 +1839,28 @@ int snd_ctl_elem_id_equal_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) return l->numid == r->numid; } +/** + * \brief check equality between two arguments according to iface, device, + * subdevice, name, and index fields. + * \param l opaque pointer to element ID structure. + * \param r opaque pointer to another element ID structure. + * \retval zero if they equal, else zero. + * + * The structure underlying #snd_ctl_elem_id_t is hybrid one. It has two ways to + * check equality. The API implements one of the ways, according to the values + * of iface, device, subdevice, name, and index fields. + */ +int snd_ctl_elem_id_equal_by_tuple(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + assert(l && r); + + return (l->iface == r->iface) && + (l->device == r->device) && + (l->subdevice == r->subdevice) && + !strcmp((const char *)l->name, (const char *)r->name) && + (l->index == r->index); +} + /** * \brief compare one #snd_ctl_elem_id_t to another * \param id1 pointer to first id diff --git a/test/lsb/ctl-elem-id.c b/test/lsb/ctl-elem-id.c index f499b268..39060a8e 100644 --- a/test/lsb/ctl-elem-id.c +++ b/test/lsb/ctl-elem-id.c @@ -64,6 +64,38 @@ static void equality_by_numid_3(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) assert(!snd_ctl_elem_id_equal_by_numid(l, r)); } +// Case 1.0. The same tuple should result in true positive. +static void equality_by_tuple_0(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_CARD, 1000, 1010, "something", 1020); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_CARD, 1000, 1010, "something", 1020); + assert(snd_ctl_elem_id_equal_by_tuple(l, r)); +} + +// Case 1.1. The different conpounds should result in true positive. +static void equality_by_tuple_1(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_CARD, 1030, 1040, "something", 1050); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_MIXER, 1031, 1042, "something", 1053); + assert(!snd_ctl_elem_id_equal_by_tuple(l, r)); +} + +// Case 1.2. The same value of numid field should result in false positive. +static void equality_by_tuple_2(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + snd_ctl_elem_id_set_numid(l, 0xfeedc0de); + snd_ctl_elem_id_set_numid(r, 0xfeedc0de); + assert(!snd_ctl_elem_id_equal_by_tuple(l, r)); +} + +// Case 1.3. The different value of numid field should result in false positive. +static void equality_by_tuple_3(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + snd_ctl_elem_id_set_numid(l, 0xfeedc0de); + snd_ctl_elem_id_set_numid(r, 0xdeadbeef); + assert(!snd_ctl_elem_id_equal_by_tuple(l, r)); +} + int main() { void (*entries[])(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) = { @@ -71,6 +103,10 @@ int main() equality_by_numid_1, equality_by_numid_2, equality_by_numid_3, + equality_by_tuple_0, + equality_by_tuple_1, + equality_by_tuple_2, + equality_by_tuple_3, }; int count = sizeof(entries) / sizeof(*entries); int fd; From patchwork Thu Mar 18 10:30:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 404844 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CAC6C433E6 for ; Thu, 18 Mar 2021 10:32:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 525E864F18 for ; Thu, 18 Mar 2021 10:32:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 525E864F18 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 C1C1216B0; Thu, 18 Mar 2021 11:31:31 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C1C1216B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616063541; bh=VelX9uALV9t7Sj6UQGnLe1hVD7pZAgx1N3HYuS6zsnI=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=g8xSmTMyOS+2CJYgkVN47p17saVfnwsvslXs+AJFrK6DiHArVBHXlwmKrSy34GlIt pjhlX2jdot1NN13FWLVrkOgHHlPRycFGH3O+/jPKU0x4fTkaoaDjcSWpKmMapsiLSY cCpw5HfVWsD3tupvA6+5zPC41UxNYDqzr1LDQjrM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1D136F800C8; Thu, 18 Mar 2021 11:30:42 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0482EF802E3; Thu, 18 Mar 2021 11:30:39 +0100 (CET) Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id C4616F80218 for ; Thu, 18 Mar 2021 11:30:25 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C4616F80218 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="l+DFRx3S"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fFP6Da4R" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id F19CA1B35; Thu, 18 Mar 2021 06:30:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 18 Mar 2021 06:30:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=BRVXpS5Lo+p0e NUL8b/+gXXlnZjnzgI5UEULIR9o/84=; b=l+DFRx3StCFtzhZ1i/M2mUHFEpigi E3i/5q9w6pZTJdtHy2//ap3mGsIO3/SjQOP8uYH61NeYg7kHIU7jftWIJOBcv5c/ 9rhOJq5VSAOARgWJ7Ko9e6w23BgRdGaxbOLHZsAB86gAhWPSArtGBhC5YHAL5lX8 LdXsEsnmT27smlq6qhNYe8x8nNV9NdsUlUl379T8GvSxDmS9+UtWOBdbEdlOUMxy JydZ5Uqch8PtminZZRrNJo0WJcSbCwn68o/vC0atqdCjzw4Zw2PA6/9t4Djz9yR2 OcwIwr3Mn1h4CWKxYwJkYze42VjyDhHB/mbOzHZXPij0r2MCe/8WXx74A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=BRVXpS5Lo+p0eNUL8b/+gXXlnZjnzgI5UEULIR9o/84=; b=fFP6Da4R znZilypEy4SAJA5wisfS16kLgEGZsO6P/cLKGTq8W4beiLMQUzhTq5F8yRqgIUAF Csm/r3RMSNpH0G4UNGixDeCWwom36rE5E29OimkisUmh0ut96TMYzNYD9lyLKCpF G9eahkIXeMxsOyPMjHMeCJByH3/rcgbLCssmMQm2/XnxDfyqe5Ks1Oi58z3BMW3J MUTHdTDYGVCPVMETpzusw2yYkyrOhkcok1dEtOswKFNcRqUzj5zQ/lIoiW9j5XTV wkH857EkBuxIldF+lwl9jPoSWk/yWVhjH9A/1FdekWbqjInJv3dR97elmMpw1P5N 3fnQthMV6SzE7g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefiedgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecukfhppedugedr fedrieehrddujeehnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilh hfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: from workstation.flets-east.jp (ae065175.dynamic.ppp.asahi-net.or.jp [14.3.65.175]) by mail.messagingengine.com (Postfix) with ESMTPA id 88912108006D; Thu, 18 Mar 2021 06:30:22 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de, perex@perex.cz Subject: [alsa-lib][PATCH 4/6] ctl: add API to compare a pair of control element IDs by numid Date: Thu, 18 Mar 2021 19:30:11 +0900 Message-Id: <20210318103013.265264-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210318103013.265264-1-o-takashi@sakamocchi.jp> References: <20210318103013.265264-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, tanjeff@cccmz.de 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 structure for control element ID is compound one. It means that it's not possible to decide single algorithm to find order of a pair of control element IDs. For convenience of application developers, it's better to produce API to decide the order by useful algorithm. This commit adds API for one of comparison algorithms. The value of numid field is used for the comparison. I note that the structure includes some 'unsigned integer' type of fields. The subtraction of the fields brings integer overflow as long as the calculation is done in the same storage size of the type itself. Signed-off-by: Takashi Sakamoto --- include/control.h | 1 + src/control/control.c | 32 +++++++++++++++++++++++++++++++ test/lsb/ctl-elem-id.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/include/control.h b/include/control.h index 8aca67e6..36953423 100644 --- a/include/control.h +++ b/include/control.h @@ -426,6 +426,7 @@ void snd_ctl_elem_id_clear(snd_ctl_elem_id_t *obj); void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src); int snd_ctl_elem_id_equal_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_equal_by_tuple(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); +int snd_ctl_elem_id_compare_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_compare(snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2); unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj); snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj); diff --git a/src/control/control.c b/src/control/control.c index 93f8f93d..00009614 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -88,6 +88,10 @@ snd_ctl_elem_id_equal_by_numid() is available. For equality check between a pair of #snd_ctl_elem_id_t according to the tuple, snd_ctl_elem_id_equal_by_tuple() is available. +Many algorithms can be defined to find ordered pair of #snd_ctl_elem_id_t. +For one of the comparison algorithms according to the numid, +snd_ctl_elem_id_compare_by_numid() is available. + \section element_lists Element Lists An element list can be used to obtain a list of all elements of the @@ -1861,6 +1865,34 @@ int snd_ctl_elem_id_equal_by_tuple(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) (l->index == r->index); } +static int compare_unsigned_integer(unsigned int l, unsigned int r) +{ + if (l == r) + return 0; + else if (l < r) + return -1; + else + return 1; +} + +/** + * \brief compare two arguments as orderd items by algorithm according to numid. + * \param l opaque pointer to element ID structure. + * \param r opaque pointer to another element ID structure. + * \retval positive if left is greater than right, negative if left is less + * than right, zero if they equal. + * + * The structure underlying #snd_ctl_elem_id_t is compound one. The + * comparison algorithm for it is not single and unique. The API implements + * one of comparison algorithms, according to the value of numid field. + */ +int snd_ctl_elem_id_compare_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + assert(l && r); + + return compare_unsigned_integer(l->numid, r->numid); +} + /** * \brief compare one #snd_ctl_elem_id_t to another * \param id1 pointer to first id diff --git a/test/lsb/ctl-elem-id.c b/test/lsb/ctl-elem-id.c index 39060a8e..670ec252 100644 --- a/test/lsb/ctl-elem-id.c +++ b/test/lsb/ctl-elem-id.c @@ -16,6 +16,8 @@ #include +#include + #include "../include/asoundlib.h" static void set_elem_id_by_tuple(snd_ctl_elem_id_t *elem_id, @@ -96,6 +98,43 @@ static void equality_by_tuple_3(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) assert(!snd_ctl_elem_id_equal_by_tuple(l, r)); } +// Case 2.0. The left object with less value in numid field than right object +// should result in negative value. +static void comparison_by_numid_0(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + snd_ctl_elem_id_set_numid(l, 0xdeadbeef); + snd_ctl_elem_id_set_numid(r, 0xfeedc0de); + assert(snd_ctl_elem_id_compare_by_numid(l, r) < 0); +} + +// Case 2.1. The left object with the same value in numid field as right object +// should result in zero. +static void comparison_by_numid_1(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + snd_ctl_elem_id_set_numid(l, 0xfeedc0de); + snd_ctl_elem_id_set_numid(r, 0xfeedc0de); + assert(snd_ctl_elem_id_compare_by_numid(l, r) == 0); +} + +// Case 2.2. The left object with greater value in numid field than right object +// should result in positive. +static void comparison_by_numid_2(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + snd_ctl_elem_id_set_numid(l, 0xfeedc0de); + snd_ctl_elem_id_set_numid(r, 0xdeadbeef); + assert(snd_ctl_elem_id_compare_by_numid(l, r) > 0); +} + +// Case 2.3. The left object with lesser value in numid field than right object +// should result in negative. The subtraction shoud be calculated in +// storage larger than the storage of 'unsigned int'. +static void comparison_by_numid_3(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + snd_ctl_elem_id_set_numid(l, 0); + snd_ctl_elem_id_set_numid(r, UINT_MAX); + assert(snd_ctl_elem_id_compare_by_numid(l, r) < 0); +} + int main() { void (*entries[])(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) = { @@ -107,6 +146,10 @@ int main() equality_by_tuple_1, equality_by_tuple_2, equality_by_tuple_3, + comparison_by_numid_0, + comparison_by_numid_1, + comparison_by_numid_2, + comparison_by_numid_3, }; int count = sizeof(entries) / sizeof(*entries); int fd; From patchwork Thu Mar 18 10:30:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 404843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CBC0C433DB for ; Thu, 18 Mar 2021 10:33:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id BB2CA64F40 for ; Thu, 18 Mar 2021 10:33:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB2CA64F40 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 D3E2A16BE; Thu, 18 Mar 2021 11:32:32 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D3E2A16BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616063602; bh=c9tLkcNIu5z/bkjAcPED5azNQrJVYIrVhlBaKivHoM4=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YaKYx5HysYFQC3uXlzuFrkkNhak1SYxu8Fn+wnau+GxAzaE53ZafjfC7tjIpiG/ZE ZaUPgDVU4jtumiP1aPyO3fD276x1YZecvKQ64JwCXeb+5t2frcuG15/Lh1erpe4l/d qiG0TWH9yovqEWZ3q+D7EYokHXxEA4/dPrbDxXQ4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 64564F804A9; Thu, 18 Mar 2021 11:30:45 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3121EF8032C; Thu, 18 Mar 2021 11:30:41 +0100 (CET) Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 04832F800C8 for ; Thu, 18 Mar 2021 11:30:29 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 04832F800C8 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="SVYH42K4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pxuTF8rw" Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 6E71B1B14; Thu, 18 Mar 2021 06:30:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Thu, 18 Mar 2021 06:30:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=AjOYXZ58Q+cr+ VClUUQ+0tm0jJD4/Rzv0HK7sxaudHc=; b=SVYH42K4JXDMbQXqbBJkGHgtc9zYF 5k4KdEUvI7nHpeOvyhbbkvZbgUBsxQkIFGQlxThbpqCCqpnLSa15D9+KxcLhPmx4 li4m4sHmz2rorQNVfmlAipzIjt3gMtLANst24xMbfdwMRLqEmC3M7Nrxi57g2fqP jpdS/9Ia4symh+am0SIkRoG8+Inua073rheiVfb7nEQp/OfIvlFQUltaYL813BBn eW0bViDUwNtRzn3QxQe5z6PewRLaRRmx/UMtc+ddnQVXBDv9J3KgqOaROLH9/o7+ pT5Kpp1UT3O4s0k6BJ8NwnGIyZccYxDNxRDUt5C9qv1PzoAGyvSffXo/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=AjOYXZ58Q+cr+VClUUQ+0tm0jJD4/Rzv0HK7sxaudHc=; b=pxuTF8rw shPOn68uyUmJq/vZpgNDhL19TzvJyEZyR+NkuYg/p+ij9voSpc3zhbFHgZT5Q07j p7Irat0IGcdWIgibAE/DTVBfNdIbbS4VXNn5q49mRIpumExiQgCfAUWCGBOthnqJ 0fZnM+gkwBc3NWl1qWxFRF+/eFhUStuM92jHbuaGjPpqRBkl22Y1a1Bj3AAE6ubb KG3Fz7SedenjHLg7Z/Td3VL3Xtj2ssGL0GNJ7Gnp/z1erU/HUKBOhOQKN8VExmdR CsSEIBm61SNspM56+5YhtU2rXrq24tDmHrSTbDzhMvcMX1Q9WpEulAhOEJ0WMSi6 nPKJyaZXK4WIOQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefiedgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecukfhppedugedr fedrieehrddujeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: from workstation.flets-east.jp (ae065175.dynamic.ppp.asahi-net.or.jp [14.3.65.175]) by mail.messagingengine.com (Postfix) with ESMTPA id E202C1080057; Thu, 18 Mar 2021 06:30:23 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de, perex@perex.cz Subject: [alsa-lib][PATCH 5/6] ctl: add API to compare a pair of control element IDs by one of algorithms according to tuple Date: Thu, 18 Mar 2021 19:30:12 +0900 Message-Id: <20210318103013.265264-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210318103013.265264-1-o-takashi@sakamocchi.jp> References: <20210318103013.265264-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, tanjeff@cccmz.de 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 structure for control element ID is compound one. It means that it's not possible to decide single algorithm to find order of a pair of control element IDs. For convenience of application developers, it's better to produce API to decide the order by useful algorithm. This commit adds API for one of comparison algorithms. The fields except for numid are used for the algorithm. The iface, device, subdevice, name, and index fields are compared in the order, by arithmetic way. I note that the structure includes some 'unsigned integer' type of fields. The subtraction of the fields brings integer overflow as long as the calculation is done in the same storage size of the type itself. Signed-off-by: Takashi Sakamoto --- include/control.h | 1 + src/control/control.c | 45 ++++++++++++++++- test/lsb/ctl-elem-id.c | 111 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-) diff --git a/include/control.h b/include/control.h index 36953423..1b2cc0c6 100644 --- a/include/control.h +++ b/include/control.h @@ -427,6 +427,7 @@ void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src); int snd_ctl_elem_id_equal_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_equal_by_tuple(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_compare_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); +int snd_ctl_elem_id_compare_by_tuple_arithmetic(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_compare(snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2); unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj); snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj); diff --git a/src/control/control.c b/src/control/control.c index 00009614..fbc6aeb7 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -90,7 +90,9 @@ is available. Many algorithms can be defined to find ordered pair of #snd_ctl_elem_id_t. For one of the comparison algorithms according to the numid, -snd_ctl_elem_id_compare_by_numid() is available. +snd_ctl_elem_id_compare_by_numid() is available. For one of the comparison +algorithms according to the tuple, snd_ctl_elem_id_compare_by_tuple_arithmetic() +is available. They are useful for qsort(3). \section element_lists Element Lists @@ -1893,6 +1895,47 @@ int snd_ctl_elem_id_compare_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) return compare_unsigned_integer(l->numid, r->numid); } +/** + * \brief compare two arguments as ordered pair by one of algorithms according + * to iface, device, subdevice, name, index fields. + * \param l opaque pointer to element ID structure. + * \param r opaque pointer to another element ID structure. + * \retval positive if left is greater than right, negative if left is less + * than right, zero if they equal. + * + * The structure underlying #snd_ctl_elem_id_t is compound one. The comparison + * algorithm for it is not single and unique. The API implements one of + * algorithm to find order in a pair of control element IDs, according to the + * values of iface, device, subdevice, name, and index fields, by below logic: + * + * - find order in iface field by this order; card, hwdep, mixer, pcm, rawmidi, + * timer, and sequencer. + * - find order in device field by arithmetic comparison of its value. + * - find order in subdevice field by arithmetic comparison of its value. + * - find order in name field by using unsigned characters, implemented in strcmp(3). + * - find order in index field by arithmetic comparison of its value. + */ +int snd_ctl_elem_id_compare_by_tuple_arithmetic(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + int res; + + assert(l && r); + + res = l->iface - r->iface; + if (res != 0) + return res; + res = compare_unsigned_integer(l->device, r->device); + if (res != 0) + return res; + res = compare_unsigned_integer(l->subdevice, r->subdevice); + if (res != 0) + return res; + res = strcmp((const char *)l->name, (const char *)r->name); + if (res != 0) + return res; + return compare_unsigned_integer(l->index, r->index); +} + /** * \brief compare one #snd_ctl_elem_id_t to another * \param id1 pointer to first id diff --git a/test/lsb/ctl-elem-id.c b/test/lsb/ctl-elem-id.c index 670ec252..02eb24fc 100644 --- a/test/lsb/ctl-elem-id.c +++ b/test/lsb/ctl-elem-id.c @@ -135,6 +135,106 @@ static void comparison_by_numid_3(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) assert(snd_ctl_elem_id_compare_by_numid(l, r) < 0); } +// Case 3.0. The left object with lesser entry in iface field than right object +// should result in negative. +static void comparison_by_tuple_arithmetic_0(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_CARD, 0, 1, "A", 2); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_HWDEP, 0, 1, "A", 2); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) < 0); +} + +// Case 3.1. The left object with greater entry in iface field than right object +// should result in positive. +static void comparison_by_tuple_arithmetic_1(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_SEQUENCER, 3, 4, "B", 5); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_TIMER, 3, 4, "B", 5); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) > 0); +} + +// Case 3.2. The left object with lesser value in device field than right object +// should result in negative. +static void comparison_by_tuple_arithmetic_2(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_CARD, 1, 7, "C", 8); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_CARD, 6, 7, "C", 8); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) < 0); +} + + +// Case 3.3. The left object with greater value in device field than right object +// should result in positive. +static void comparison_by_tuple_arithmetic_3(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_HWDEP, 9, 10, "D", 11); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_HWDEP, 1, 10, "D", 11); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) > 0); +} + +// Case 3.3. The left object with lesser value in subdevice field than right object +// should result in negative. +static void comparison_by_tuple_arithmetic_4(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_MIXER, 12, 1, "E", 14); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_MIXER, 12, 13, "E", 14); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) < 0); +} + +// Case 3.4. The left object with greater value in subdevice field than right object +// should result in positive. +static void comparison_by_tuple_arithmetic_5(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_PCM, 15, 16, "F", 17); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_PCM, 15, 1, "F", 17); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) > 0); +} + +// Case 3.5. The left object with name beginning lesser character in name field +// than right object should result in negative. +static void comparison_by_tuple_arithmetic_6(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_RAWMIDI, 18, 19, "A", 20); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_RAWMIDI, 18, 19, "H", 20); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) < 0); +} + +// Case 3.6. The left object with name beginning greater character in name field +// than right object should result in positive. +static void comparison_by_tuple_arithmetic_7(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_TIMER, 21, 22, "I", 23); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_TIMER, 21, 22, "A", 23); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) > 0); +} + +// Case 3.7. The left object with lesser value in index field than right object +// should result in negative. +static void comparison_by_tuple_arithmetic_8(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_SEQUENCER, 24, 25, "J", 1); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_SEQUENCER, 24, 25, "J", 26); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) < 0); +} + +// Case 3.8. The left object with greater value in index field than right object +// should result in positive. +static void comparison_by_tuple_arithmetic_9(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_CARD, 27, 28, "K", 29); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_CARD, 27, 28, "K", 1); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) > 0); +} + +// Case 3.9. The left object with the same values in iface, device, subdevice, +// name, and index fields as right object should result in zero. +static void comparison_by_tuple_arithmetic_10(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) +{ + set_elem_id_by_tuple(l, SND_CTL_ELEM_IFACE_HWDEP, 30, 31, "L", 32); + set_elem_id_by_tuple(r, SND_CTL_ELEM_IFACE_HWDEP, 30, 31, "L", 32); + assert(snd_ctl_elem_id_compare_by_tuple_arithmetic(l, r) == 0); +} + int main() { void (*entries[])(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) = { @@ -150,6 +250,17 @@ int main() comparison_by_numid_1, comparison_by_numid_2, comparison_by_numid_3, + comparison_by_tuple_arithmetic_0, + comparison_by_tuple_arithmetic_1, + comparison_by_tuple_arithmetic_2, + comparison_by_tuple_arithmetic_3, + comparison_by_tuple_arithmetic_4, + comparison_by_tuple_arithmetic_5, + comparison_by_tuple_arithmetic_6, + comparison_by_tuple_arithmetic_7, + comparison_by_tuple_arithmetic_8, + comparison_by_tuple_arithmetic_9, + comparison_by_tuple_arithmetic_10, }; int count = sizeof(entries) / sizeof(*entries); int fd; From patchwork Thu Mar 18 10:30:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 404073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A91B3C433DB for ; Thu, 18 Mar 2021 10:33:11 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 21D8264F18 for ; Thu, 18 Mar 2021 10:33:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21D8264F18 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 62C9116CB; Thu, 18 Mar 2021 11:32:17 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 62C9116CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616063587; bh=cxAscVz+agLs2HVe72q50Jcm1ehLDwk3XflI/3OP7gg=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EkRT6c0gMfUOvkVl9prSvlZ3rF1ngpkRPMrWGBhATvRI+k1uKnzfGDkO4dVoygE5k irfQIipdRyjumNcMl+EzHNzZP53rJkOxqw7b/x+ZHOuO34LzvOFCDbAfXKh3tHAyAq R8AK76cwia04/DHsFBZvW49Z+rS6rD48Px57UGUE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9B0EBF80425; Thu, 18 Mar 2021 11:30:44 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E4607F8032D; Thu, 18 Mar 2021 11:30:40 +0100 (CET) Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 193A4F8023B for ; Thu, 18 Mar 2021 11:30:29 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 193A4F8023B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="Hne3fn9I"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WYlq/7s5" Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id C29AE1B58; Thu, 18 Mar 2021 06:30:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Thu, 18 Mar 2021 06:30:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=f6L1YIn1G7z89 hWlf3nQMmoJAA+CRalKervkbdlyh18=; b=Hne3fn9ILzOFsdKDEKa2j+1dFjRXp bqLUgwgO9O9ywmvnyR4Zc0Dg+F+se5zmbkQzJp8UbmKRUgU1A/ApSFVReSHG3/ao iKcMhrEWOIOmG9jKGR1fJDmklBjvZVxthjF3HsiuIFDg4dgS8SGUk1EIXCtnT5L+ k5Y6G92z79Lj/Gzr9VyuuzfyNqvK1wk1GQ4ZH+dkkkOmXbi5gFDB/4nlsfK9IMj8 zoxSnJLrfVAN4QWlcqRSdu4dgPBWoT8d6bficA8kmqlCw4gajTs/6GHf4dVLGLcG 5Cfr12+XyDqxZ1p6mIfkOkWiG0IBS2JiZj7pYQ3UHAe94m3yXxu1FSl3w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=f6L1YIn1G7z89hWlf3nQMmoJAA+CRalKervkbdlyh18=; b=WYlq/7s5 ZQDfbkBVjFtBd8luVdpgP/2hEBGpTvav7xSCcj84wfSS49GDwiY0ED7jqqYxtYOW eTrah3Oj337Pgz/5D1Firg4t3jsoC2uEdlzflmaRiIjV+pL+VpynhWXU4gvqTucZ o78QKtXKn0PKRDcKvL1cq0bRZ1fICHgSx+ktkIFdXendItZ1w/9p+wxM2KvlYjE/ Qgim3oKhT/WJCRLz5mPY2qVN7AF3kt+VlPM5hAkASdpM1yT1aKYsBSZG+g9T6ZCc sMUhL3CpkPG/TI12Qv+oT7StA6mt4tr6UoDscwo5Ids+Lb5QCCVVFwY1izEc6xrf fk+X3x9i5mwBAQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefiedgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecukfhppedugedr fedrieehrddujeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: from workstation.flets-east.jp (ae065175.dynamic.ppp.asahi-net.or.jp [14.3.65.175]) by mail.messagingengine.com (Postfix) with ESMTPA id 449B61080068; Thu, 18 Mar 2021 06:30:25 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de, perex@perex.cz Subject: [alsa-lib][PATCH 6/6] ctl: drop deprecated API to compare a pair of control element IDs Date: Thu, 18 Mar 2021 19:30:13 +0900 Message-Id: <20210318103013.265264-7-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210318103013.265264-1-o-takashi@sakamocchi.jp> References: <20210318103013.265264-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, tanjeff@cccmz.de 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" A commit 2cfe6addaef6 ("control: add snd_ctl_elem_id_compare() function") adds 'snd_ctl_elem_id_compare()' API, however the implementation has several bugs. At first, the name is not inappropriate since it implements one of comparison algorithms. The name itself implies the algorithm is single and unique for control element ID. Secondary, it subtracts a pair of values in fields of 'unsigned int' type in storage size of the type. It brings integer overflow. Tertiary, it compares subdevice field in the same structure. Fortunately, the issued API is not public in any release. An alternative API, 'snd_ctl_elem_id_compare_by_name_arithmetic()', is already added with enough tests. This commit drops the issued API. Signed-off-by: Takashi Sakamoto --- include/control.h | 1 - src/control/control.c | 35 ----------------------------------- 2 files changed, 36 deletions(-) diff --git a/include/control.h b/include/control.h index 1b2cc0c6..3975f4b7 100644 --- a/include/control.h +++ b/include/control.h @@ -428,7 +428,6 @@ int snd_ctl_elem_id_equal_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_equal_by_tuple(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_compare_by_numid(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); int snd_ctl_elem_id_compare_by_tuple_arithmetic(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r); -int snd_ctl_elem_id_compare(snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2); unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj); snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj); unsigned int snd_ctl_elem_id_get_device(const snd_ctl_elem_id_t *obj); diff --git a/src/control/control.c b/src/control/control.c index fbc6aeb7..1d83cb6a 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -1936,41 +1936,6 @@ int snd_ctl_elem_id_compare_by_tuple_arithmetic(snd_ctl_elem_id_t *l, snd_ctl_el return compare_unsigned_integer(l->index, r->index); } -/** - * \brief compare one #snd_ctl_elem_id_t to another - * \param id1 pointer to first id - * \param id2 pointer to second id - * \retval zero when values are identical, other value on a difference (like strcmp) - * - * This comparison ignores the numid part. The numid comparison can be easily - * implemented using snd_ctl_elem_id_get_numid() calls. - * - * The identifier fields are compared in this order: interface, device, - * subdevice, name, index. - * - * The return value can be used for sorting like qsort(). It gives persistent - * results. - */ -int snd_ctl_elem_id_compare(snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2) -{ - int d; - - assert(id1 && id2); - d = id1->iface - id2->iface; - if (d != 0) - return d; - d = id1->device - id2->device; - if (d != 0) - return d; - d = id2->subdevice - id2->subdevice; - if (d != 0) - return d; - d = strcmp((const char *)id1->name, (const char *)id2->name); - if (d != 0) - return d; - return id1->index - id2->index; -} - /** * \brief Get numeric identifier from a CTL element identifier * \param obj CTL element identifier