Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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@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>
Link: https://lore.kernel.org/r/20230522215514.722564-1-dangel101@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Dana Elfassy and committed by
Dmitry Torokhov
b0031562 3615536c

+32
+32
drivers/input/tests/input_test.c
··· 130 130 KUNIT_ASSERT_FALSE(test, input_match_device_id(input_dev, &id)); 131 131 } 132 132 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 + 133 164 static struct kunit_case input_tests[] = { 134 165 KUNIT_CASE(input_test_polling), 135 166 KUNIT_CASE(input_test_timestamp), 136 167 KUNIT_CASE(input_test_match_device_id), 168 + KUNIT_CASE(input_test_grab), 137 169 { /* sentinel */ } 138 170 }; 139 171