[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230517153145.513095-1-dangel101@gmail.com>
Date: Wed, 17 May 2023 18:31:45 +0300
From: Dana Elfassy <delfassy@...hat.com>
To: eballetb@...hat.com, dmitry.torokhov@...il.com, javierm@...hat.com,
linux-input@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: Dana Elfassy <dangel101@...il.com>
Subject: [PATCH v2] Input: tests: add test to cover all input_grab_device() function
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@...il.com>
Tested-by: Javier Martinez Canillas <javierm@...hat.com>
Reviewed-by: Javier Martinez Canillas <javierm@...hat.com>
---
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 | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/input/tests/input_test.c b/drivers/input/tests/input_test.c
index 25bbf51b5c87..cea0167a74d2 100644
--- a/drivers/input/tests/input_test.c
+++ b/drivers/input/tests/input_test.c
@@ -124,10 +124,33 @@ 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_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, input_grab_device(&handle));
+
+ res = input_grab_device(&handle);
+ KUNIT_ASSERT_EQ(test, res, -EBUSY);
+ 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
Powered by blists - more mailing lists