* [PATCH v3] Input: tests: add test to cover all input_grab_device() function
@ 2023-05-22 21:55 Dana Elfassy
2023-05-23 0:00 ` Dmitry Torokhov
2023-05-23 21:58 ` Dmitry Torokhov
0 siblings, 2 replies; 3+ messages in thread
From: Dana Elfassy @ 2023-05-22 21:55 UTC (permalink / raw)
To: eballetb, dmitry.torokhov, javierm, linux-input, linux-kernel
Cc: Dana Elfassy
Currently input_grab_device() isn't covered by any tests
Thus, adding a test to cover the cases:
1. The device is grabbed successfully
2. Trying to grab a device that is already grabbed by another input
handle
Signed-off-by: Dana Elfassy <dangel101@gmail.com>
Tested-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
Changes in v3:
1. Retrieve test_handle variable to try and grab the device that's
currently grabbed by another handle
2. Add verification that test_handle can indeed grab the device after
it's released by the handle that grabbed it
3. Remove duplicated call for input_grab_device() in KUNIT_ASSERT_TRUE()
functions
Changes in v2:
- Use input_put_device() to decrement the refcount increased by get().
- Remove unnecessary struct input_handle test_handle variable.
drivers/input/tests/input_test.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/input/tests/input_test.c b/drivers/input/tests/input_test.c
index 25bbf51b5c87..1939cc12bae0 100644
--- a/drivers/input/tests/input_test.c
+++ b/drivers/input/tests/input_test.c
@@ -124,10 +124,42 @@ static void input_test_match_device_id(struct kunit *test)
KUNIT_ASSERT_FALSE(test, input_match_device_id(input_dev, &id));
}
+static void input_test_grab(struct kunit *test)
+{
+ struct input_dev *input_dev = test->priv;
+ struct input_handle test_handle;
+ struct input_handler handler;
+ struct input_handle handle;
+ struct input_device_id id;
+ int res;
+
+ handler.name = "handler";
+ handler.id_table = &id;
+
+ handle.dev = input_get_device(input_dev);
+ handle.name = dev_name(&input_dev->dev);
+ handle.handler = &handler;
+ res = input_grab_device(&handle);
+ KUNIT_ASSERT_TRUE(test, res == 0);
+
+ test_handle.dev = input_get_device(input_dev);
+ test_handle.name = dev_name(&input_dev->dev);
+ test_handle.handler = &handler;
+ res = input_grab_device(&test_handle);
+ KUNIT_ASSERT_EQ(test, res, -EBUSY);
+
+ input_release_device(&handle);
+ input_put_device(input_dev);
+ res = input_grab_device(&test_handle);
+ KUNIT_ASSERT_TRUE(test, res == 0);
+ input_put_device(input_dev);
+}
+
static struct kunit_case input_tests[] = {
KUNIT_CASE(input_test_polling),
KUNIT_CASE(input_test_timestamp),
KUNIT_CASE(input_test_match_device_id),
+ KUNIT_CASE(input_test_grab),
{ /* sentinel */ }
};
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] Input: tests: add test to cover all input_grab_device() function
2023-05-22 21:55 [PATCH v3] Input: tests: add test to cover all input_grab_device() function Dana Elfassy
@ 2023-05-23 0:00 ` Dmitry Torokhov
2023-05-23 21:58 ` Dmitry Torokhov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2023-05-23 0:00 UTC (permalink / raw)
To: Dana Elfassy; +Cc: eballetb, javierm, linux-input, linux-kernel, Dana Elfassy
On Tue, May 23, 2023 at 12:55:14AM +0300, Dana Elfassy wrote:
> Currently input_grab_device() isn't covered by any tests
> Thus, adding a test to cover the cases:
> 1. The device is grabbed successfully
> 2. Trying to grab a device that is already grabbed by another input
> handle
>
> Signed-off-by: Dana Elfassy <dangel101@gmail.com>
> Tested-by: Javier Martinez Canillas <javierm@redhat.com>
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
> Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> Changes in v3:
> 1. Retrieve test_handle variable to try and grab the device that's
> currently grabbed by another handle
> 2. Add verification that test_handle can indeed grab the device after
> it's released by the handle that grabbed it
> 3. Remove duplicated call for input_grab_device() in KUNIT_ASSERT_TRUE()
> functions
> Changes in v2:
> - Use input_put_device() to decrement the refcount increased by get().
> - Remove unnecessary struct input_handle test_handle variable.
>
> drivers/input/tests/input_test.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/drivers/input/tests/input_test.c b/drivers/input/tests/input_test.c
> index 25bbf51b5c87..1939cc12bae0 100644
> --- a/drivers/input/tests/input_test.c
> +++ b/drivers/input/tests/input_test.c
> @@ -124,10 +124,42 @@ static void input_test_match_device_id(struct kunit *test)
> KUNIT_ASSERT_FALSE(test, input_match_device_id(input_dev, &id));
> }
>
> +static void input_test_grab(struct kunit *test)
> +{
> + struct input_dev *input_dev = test->priv;
> + struct input_handle test_handle;
> + struct input_handler handler;
> + struct input_handle handle;
> + struct input_device_id id;
> + int res;
> +
> + handler.name = "handler";
> + handler.id_table = &id;
> +
> + handle.dev = input_get_device(input_dev);
> + handle.name = dev_name(&input_dev->dev);
> + handle.handler = &handler;
> + res = input_grab_device(&handle);
> + KUNIT_ASSERT_TRUE(test, res == 0);
Could you please tell me why you are using KUNIT_ASSERT_TRUE() here but
KUNIT_ASSERT_EQ() below?
> +
> + test_handle.dev = input_get_device(input_dev);
> + test_handle.name = dev_name(&input_dev->dev);
> + test_handle.handler = &handler;
> + res = input_grab_device(&test_handle);
> + KUNIT_ASSERT_EQ(test, res, -EBUSY);
> +
> + input_release_device(&handle);
> + input_put_device(input_dev);
> + res = input_grab_device(&test_handle);
> + KUNIT_ASSERT_TRUE(test, res == 0);
> + input_put_device(input_dev);
> +}
> +
> static struct kunit_case input_tests[] = {
> KUNIT_CASE(input_test_polling),
> KUNIT_CASE(input_test_timestamp),
> KUNIT_CASE(input_test_match_device_id),
> + KUNIT_CASE(input_test_grab),
> { /* sentinel */ }
> };
>
> --
> 2.40.1
>
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] Input: tests: add test to cover all input_grab_device() function
2023-05-22 21:55 [PATCH v3] Input: tests: add test to cover all input_grab_device() function Dana Elfassy
2023-05-23 0:00 ` Dmitry Torokhov
@ 2023-05-23 21:58 ` Dmitry Torokhov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2023-05-23 21:58 UTC (permalink / raw)
To: Dana Elfassy; +Cc: eballetb, javierm, linux-input, linux-kernel, Dana Elfassy
On Tue, May 23, 2023 at 12:55:14AM +0300, Dana Elfassy wrote:
> Currently input_grab_device() isn't covered by any tests
> Thus, adding a test to cover the cases:
> 1. The device is grabbed successfully
> 2. Trying to grab a device that is already grabbed by another input
> handle
>
> Signed-off-by: Dana Elfassy <dangel101@gmail.com>
> Tested-by: Javier Martinez Canillas <javierm@redhat.com>
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
> Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Applied, thank you.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-23 21:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-22 21:55 [PATCH v3] Input: tests: add test to cover all input_grab_device() function Dana Elfassy
2023-05-23 0:00 ` Dmitry Torokhov
2023-05-23 21:58 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).