Skip to content

Commit b003156

Browse files
dangel101dtor
authored andcommitted
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 <[email protected]> Tested-by: Javier Martinez Canillas <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]> Reviewed-by: Dmitry Torokhov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 3615536 commit b003156

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

drivers/input/tests/input_test.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,42 @@ static void input_test_match_device_id(struct kunit *test)
130130
KUNIT_ASSERT_FALSE(test, input_match_device_id(input_dev, &id));
131131
}
132132

133+
static void input_test_grab(struct kunit *test)
134+
{
135+
struct input_dev *input_dev = test->priv;
136+
struct input_handle test_handle;
137+
struct input_handler handler;
138+
struct input_handle handle;
139+
struct input_device_id id;
140+
int res;
141+
142+
handler.name = "handler";
143+
handler.id_table = &id;
144+
145+
handle.dev = input_get_device(input_dev);
146+
handle.name = dev_name(&input_dev->dev);
147+
handle.handler = &handler;
148+
res = input_grab_device(&handle);
149+
KUNIT_ASSERT_TRUE(test, res == 0);
150+
151+
test_handle.dev = input_get_device(input_dev);
152+
test_handle.name = dev_name(&input_dev->dev);
153+
test_handle.handler = &handler;
154+
res = input_grab_device(&test_handle);
155+
KUNIT_ASSERT_EQ(test, res, -EBUSY);
156+
157+
input_release_device(&handle);
158+
input_put_device(input_dev);
159+
res = input_grab_device(&test_handle);
160+
KUNIT_ASSERT_TRUE(test, res == 0);
161+
input_put_device(input_dev);
162+
}
163+
133164
static struct kunit_case input_tests[] = {
134165
KUNIT_CASE(input_test_polling),
135166
KUNIT_CASE(input_test_timestamp),
136167
KUNIT_CASE(input_test_match_device_id),
168+
KUNIT_CASE(input_test_grab),
137169
{ /* sentinel */ }
138170
};
139171

0 commit comments

Comments
 (0)