Input: tests: add test to cover all input_grab_device() function
Subsystems (2)
PATCH v3 1/1 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
---
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(+)
drivers/input/tests/input_test.c +32 -0
@@ -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 */ } };
Signature · 1 line
2.40.1
Dmitry Torokhov
maintainerQuoted 40 lines · 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 handleSigned-off-by Dana Elfassy <[email protected]>Reviewed-by Javier Martinez Canillas <[email protected]>Reviewed-by Dmitry Torokhov <[email protected]>---
Changes in v3:
1. Retrievetest_handlevariable to try and grab the device that's currently grabbed by another handle
2. Add verification thattest_handlecan indeed grab the device after it's released by the handle that grabbed it
3. Remove duplicated call forinput_grab_device()inKUNIT_ASSERT_TRUE()functions
Changes in v2:
- Useinput_put_device()to decrement the refcount increased byget().
- Remove unnecessary structinput_handletest_handlevariable.drivers/input/tests/input_test.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)drivers/input/tests/input_test.c +7
-0@@ -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;
drivers/input/tests/input_test.c static void input_test_match_device_id(struct kunit *test) · line 143
Quoted 10 lines
drivers/input/tests/input_test.c +10
-0+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?
Quoted 25 lines
drivers/input/tests/input_test.c +15
-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 */ } };Signature · 1 line
2.40.1
Thanks.
Signature · 1 line
Dmitry
Quoted 10 lines · 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 handleSigned-off-by Dana Elfassy <[email protected]>Reviewed-by Javier Martinez Canillas <[email protected]>Reviewed-by Dmitry Torokhov <[email protected]>
Applied, thank you.
Signature · 1 line
Dmitry