All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Mark Brown <broonie@kernel.org>
Cc: Takashi Iwai <tiwai@suse.de>, Shuah Khan <shuah@kernel.org>,
	Jaroslav Kysela <perex@perex.cz>,
	alsa-devel@alsa-project.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2] kselftest: alsa: Add simplistic test for ALSA mixer controls kselftest
Date: Tue, 7 Dec 2021 12:20:32 +0900	[thread overview]
Message-ID: <Ya7TAHdMe9i41bsC@workstation> (raw)
In-Reply-To: <20211206160305.194011-1-broonie@kernel.org>

Hi Mark,

On Mon, Dec 06, 2021 at 04:03:05PM +0000, Mark Brown wrote:
> Add a basic test for the mixer control interface. For every control on
> every sound card in the system it checks that it can read and write the
> default value where the control supports that and for writeable controls
> attempts to write all valid values, restoring the default values after
> each test to minimise disruption for users.
> 
> There are quite a few areas for improvement - currently no coverage of the
> generation of notifications, several of the control types don't have any
> coverage for the values and we don't have any testing of error handling
> when we attempt to write out of range values - but this provides some basic
> coverage.
> 
> This is added as a kselftest since unlike other ALSA test programs it does
> not require either physical setup of the device or interactive monitoring
> by users and kselftest is one of the test suites that is frequently run by
> people doing general automated testing so should increase coverage. It is
> written in terms of alsa-lib since tinyalsa is not generally packaged for
> distributions which makes things harder for general users interested in
> kselftest as a whole but it will be a barrier to people with Android.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
> 
> v2: Use pkg-config to get CFLAGS and LDLIBS for alsa-lib.
> 
>  MAINTAINERS                               |   7 +
>  tools/testing/selftests/Makefile          |   3 +-
>  tools/testing/selftests/alsa/.gitignore   |   1 +
>  tools/testing/selftests/alsa/Makefile     |   9 +
>  tools/testing/selftests/alsa/mixer-test.c | 616 ++++++++++++++++++++++
>  5 files changed, 635 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/alsa/.gitignore
>  create mode 100644 tools/testing/selftests/alsa/Makefile
>  create mode 100644 tools/testing/selftests/alsa/mixer-test.c

I think it safer to take care of volatile attribute when comparing read
value to written value. I'm glad if you review below patch.

As another topic, the runtime of alsa-lib application largely differs
between process user due to the result of parsing text files for
configuration space. I can easily imagine that developers unfamiliar to
alsa-lib carelessly adds invalid or inadequate configurations to files
under target path of alsa-lib configuration space, and they are puzzled
since they are unaware of the fact that the kselftest is affected by
userspace stuffs for the runtime.

If we respect the basic theory of test (idempotence), we can use ioctl(2)
with requests for ALSA control interface since it's not so complicated
(at least it is easier than ALSA PCM interface). The purpose of
kselftest is to test kernel stuffs, not to test userspace stuffs
including alsa-lib implementation and variety of plugins.

======== 8< --------

From 0052f48a931d93b993e406ffaf4c8fbecac15e84 Mon Sep 17 00:00:00 2001
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Date: Tue, 7 Dec 2021 11:43:56 +0900
Subject: [PATCH] kselftest: alsa: optimization for
 SNDRV_CTL_ELEM_ACCESS_VOLATILE

The volatile attribute of control element means that the hardware can
voluntarily change the state of control element independent of any
operation by software. ALSA control core necessarily sends notification
to userspace subscribers for any change from userspace application, while
it doesn't for the hardware's voluntary change.

This commit adds optimization for the attribute. Even if read value is
different from written value, the test reports success as long as the
target control element has the attribute. On the other hand, the
difference is itself reported for developers' convenience.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 tools/testing/selftests/alsa/mixer-test.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c
index 6082efa0b426..b87475fb7372 100644
--- a/tools/testing/selftests/alsa/mixer-test.c
+++ b/tools/testing/selftests/alsa/mixer-test.c
@@ -317,9 +317,13 @@ bool show_mismatch(struct ctl_data *ctl, int index,
 	}
 
 	if (expected_int != read_int) {
-		ksft_print_msg("%s.%d expected %lld but read %lld\n",
-			       ctl->name, index, expected_int, read_int);
-		return true;
+		// NOTE: The volatile attribute means that the hardware can voluntarily change the
+		// state of control element independent of any operation by software.
+		bool is_volatile = snd_ctl_elem_info_is_volatile(ctl->info);
+
+		ksft_print_msg("%s.%d expected %lld but read %lld, is_volatile %d\n",
+			       ctl->name, index, expected_int, read_int, is_volatile);
+		return !is_volatile;
 	} else {
 		return false;
 	}
-- 
2.32.0

======== 8< --------


Cheers

Takashi Sakamoto

WARNING: multiple messages have this Message-ID (diff)
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Mark Brown <broonie@kernel.org>
Cc: Takashi Iwai <tiwai@suse.de>,
	alsa-devel@alsa-project.org, Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2] kselftest: alsa: Add simplistic test for ALSA mixer controls kselftest
Date: Tue, 7 Dec 2021 12:20:32 +0900	[thread overview]
Message-ID: <Ya7TAHdMe9i41bsC@workstation> (raw)
In-Reply-To: <20211206160305.194011-1-broonie@kernel.org>

Hi Mark,

On Mon, Dec 06, 2021 at 04:03:05PM +0000, Mark Brown wrote:
> Add a basic test for the mixer control interface. For every control on
> every sound card in the system it checks that it can read and write the
> default value where the control supports that and for writeable controls
> attempts to write all valid values, restoring the default values after
> each test to minimise disruption for users.
> 
> There are quite a few areas for improvement - currently no coverage of the
> generation of notifications, several of the control types don't have any
> coverage for the values and we don't have any testing of error handling
> when we attempt to write out of range values - but this provides some basic
> coverage.
> 
> This is added as a kselftest since unlike other ALSA test programs it does
> not require either physical setup of the device or interactive monitoring
> by users and kselftest is one of the test suites that is frequently run by
> people doing general automated testing so should increase coverage. It is
> written in terms of alsa-lib since tinyalsa is not generally packaged for
> distributions which makes things harder for general users interested in
> kselftest as a whole but it will be a barrier to people with Android.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
> 
> v2: Use pkg-config to get CFLAGS and LDLIBS for alsa-lib.
> 
>  MAINTAINERS                               |   7 +
>  tools/testing/selftests/Makefile          |   3 +-
>  tools/testing/selftests/alsa/.gitignore   |   1 +
>  tools/testing/selftests/alsa/Makefile     |   9 +
>  tools/testing/selftests/alsa/mixer-test.c | 616 ++++++++++++++++++++++
>  5 files changed, 635 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/alsa/.gitignore
>  create mode 100644 tools/testing/selftests/alsa/Makefile
>  create mode 100644 tools/testing/selftests/alsa/mixer-test.c

I think it safer to take care of volatile attribute when comparing read
value to written value. I'm glad if you review below patch.

As another topic, the runtime of alsa-lib application largely differs
between process user due to the result of parsing text files for
configuration space. I can easily imagine that developers unfamiliar to
alsa-lib carelessly adds invalid or inadequate configurations to files
under target path of alsa-lib configuration space, and they are puzzled
since they are unaware of the fact that the kselftest is affected by
userspace stuffs for the runtime.

If we respect the basic theory of test (idempotence), we can use ioctl(2)
with requests for ALSA control interface since it's not so complicated
(at least it is easier than ALSA PCM interface). The purpose of
kselftest is to test kernel stuffs, not to test userspace stuffs
including alsa-lib implementation and variety of plugins.

======== 8< --------

From 0052f48a931d93b993e406ffaf4c8fbecac15e84 Mon Sep 17 00:00:00 2001
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Date: Tue, 7 Dec 2021 11:43:56 +0900
Subject: [PATCH] kselftest: alsa: optimization for
 SNDRV_CTL_ELEM_ACCESS_VOLATILE

The volatile attribute of control element means that the hardware can
voluntarily change the state of control element independent of any
operation by software. ALSA control core necessarily sends notification
to userspace subscribers for any change from userspace application, while
it doesn't for the hardware's voluntary change.

This commit adds optimization for the attribute. Even if read value is
different from written value, the test reports success as long as the
target control element has the attribute. On the other hand, the
difference is itself reported for developers' convenience.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 tools/testing/selftests/alsa/mixer-test.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/alsa/mixer-test.c b/tools/testing/selftests/alsa/mixer-test.c
index 6082efa0b426..b87475fb7372 100644
--- a/tools/testing/selftests/alsa/mixer-test.c
+++ b/tools/testing/selftests/alsa/mixer-test.c
@@ -317,9 +317,13 @@ bool show_mismatch(struct ctl_data *ctl, int index,
 	}
 
 	if (expected_int != read_int) {
-		ksft_print_msg("%s.%d expected %lld but read %lld\n",
-			       ctl->name, index, expected_int, read_int);
-		return true;
+		// NOTE: The volatile attribute means that the hardware can voluntarily change the
+		// state of control element independent of any operation by software.
+		bool is_volatile = snd_ctl_elem_info_is_volatile(ctl->info);
+
+		ksft_print_msg("%s.%d expected %lld but read %lld, is_volatile %d\n",
+			       ctl->name, index, expected_int, read_int, is_volatile);
+		return !is_volatile;
 	} else {
 		return false;
 	}
-- 
2.32.0

======== 8< --------


Cheers

Takashi Sakamoto

  parent reply	other threads:[~2021-12-07  3:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 16:03 [PATCH v2] kselftest: alsa: Add simplistic test for ALSA mixer controls kselftest Mark Brown
2021-12-06 16:03 ` Mark Brown
2021-12-06 16:27 ` Pierre-Louis Bossart
2021-12-06 16:31   ` Pierre-Louis Bossart
2021-12-06 16:39   ` Mark Brown
2021-12-06 16:39     ` Mark Brown
2021-12-06 17:01     ` Pierre-Louis Bossart
2021-12-06 18:17       ` Mark Brown
2021-12-07  3:20 ` Takashi Sakamoto [this message]
2021-12-07  3:20   ` Takashi Sakamoto
2021-12-07  8:05   ` Jaroslav Kysela
2021-12-07 14:25   ` Mark Brown
2021-12-07 14:36     ` Takashi Iwai
2021-12-07 14:36       ` Takashi Iwai
2021-12-07 14:49       ` Mark Brown
2021-12-07 14:49         ` Mark Brown
2021-12-08 14:26     ` Takashi Sakamoto
2021-12-08 14:31       ` Takashi Sakamoto
2021-12-08 16:07       ` Mark Brown
2021-12-08 16:07         ` Mark Brown
2021-12-08 17:42 ` Shuah Khan
2021-12-08 17:42   ` Shuah Khan
2021-12-08 18:39   ` Mark Brown
2021-12-08 18:39     ` Mark Brown
2021-12-08 18:59     ` Shuah Khan
2021-12-08 18:59       ` Shuah Khan
2021-12-08 20:12       ` Mark Brown
2021-12-08 20:12         ` Mark Brown
2021-12-08 21:14         ` Shuah Khan
2021-12-08 21:14           ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Ya7TAHdMe9i41bsC@workstation \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=shuah@kernel.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.