mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 04:38:03 +00:00
8e5c0abfa0
- streamlined logic in input core for handling normal input handlers vs input filters - updates to input drivers to allocate memory with sizeof(*pointer) instead of sizeof(type) - change to ads7846 touchscreen driver to use hsync GPIO instead of requiring platform data with special method (which is not compatible with boards using device tree) - update to adc-joystick driver to handle inverted axes - cleanups in various drivers switching them to use the new "guard" and "__free()" facilities - changes to several drivers (adxl34x, atmel_mxt_ts, ati-remote2, omap-keypad, yealink) to stop creating driver-specific device attributes manually and use driver core facilities for this - update to Cypress PS/2 protocol driver to properly handle errors from the PS/2 transport as well as other cleanups - update to edt-ft5x06 driver to support ft5426 variant - update to ektf2127 driver to support ektf2232 variant - update to exc3000 driver to support EXC81W32 variant - update to imagis driver to support IST3038 variant - other assorted driver cleanups. -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQST2eWILY88ieB2DOtAj56VGEWXnAUCZpWmqQAKCRBAj56VGEWX nE00AQDsikkxIpF5GJo3mhHLHQc5noEB/zwwLNTqEmV/ThdffwD/bQmr0C0M1dhz fOM9NqeyhwKkgGd389AIzv/dV7KIGwI= =rQCl -----END PGP SIGNATURE----- Merge tag 'input-for-v6.11-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input Pull input updates from Dmitry Torokhov: - streamlined logic in input core for handling normal input handlers vs input filters - updates to input drivers to allocate memory with sizeof(*pointer) instead of sizeof(type) - change to ads7846 touchscreen driver to use hsync GPIO instead of requiring platform data with special method (which is not compatible with boards using device tree) - update to adc-joystick driver to handle inverted axes - cleanups in various drivers switching them to use the new "guard" and "__free()" facilities - changes to several drivers (adxl34x, atmel_mxt_ts, ati-remote2, omap-keypad, yealink) to stop creating driver-specific device attributes manually and use driver core facilities for this - update to Cypress PS/2 protocol driver to properly handle errors from the PS/2 transport as well as other cleanups - update to edt-ft5x06 driver to support ft5426 variant - update to ektf2127 driver to support ektf2232 variant - update to exc3000 driver to support EXC81W32 variant - update to imagis driver to support IST3038 variant - other assorted driver cleanups. * tag 'input-for-v6.11-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (71 commits) Input: yealink - simplify locking in sysfs attribute handling Input: yealink - use driver core to instantiate device attributes Input: ati-remote2 - use driver core to instantiate device attributes Input: omap-keypad - use driver core to instantiate device attributes Input: atmel_mxt_ts - use driver core to instantiate device attributes Input: exc3000 - add EXC81W32 support dt-bindings: input: touchscreen: exc3000: add EXC81W32 Input: twl4030-pwrbutton - fix kernel-doc warning Input: himax_hx83112b - add support for HX83100A Input: himax_hx83112b - add himax_chip struct for multi-chip support Input: himax_hx83112b - implement MCU register reading Input: himax_hx83112b - use more descriptive register defines dt-bindings: input: touchscreen: himax,hx83112b: add HX83100A Input: do not check number of events in input_pass_values() Input: preallocate memory to hold event values Input: rearrange input_alloc_device() to prepare for preallocating of vals Input: simplify event handling logic Input: make events() method return number of events processed Input: make sure input handlers define only one processing method Input: evdev - remove ->event() method ...
184 lines
4.8 KiB
C
184 lines
4.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* KUnit test for the input core.
|
|
*
|
|
* Copyright (c) 2023 Red Hat Inc
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/input.h>
|
|
|
|
#include <kunit/test.h>
|
|
|
|
#define POLL_INTERVAL 100
|
|
|
|
static int input_test_init(struct kunit *test)
|
|
{
|
|
struct input_dev *input_dev;
|
|
int ret;
|
|
|
|
input_dev = input_allocate_device();
|
|
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, input_dev);
|
|
|
|
input_dev->name = "Test input device";
|
|
input_dev->id.bustype = BUS_VIRTUAL;
|
|
input_dev->id.vendor = 1;
|
|
input_dev->id.product = 1;
|
|
input_dev->id.version = 1;
|
|
input_set_capability(input_dev, EV_KEY, BTN_LEFT);
|
|
input_set_capability(input_dev, EV_KEY, BTN_RIGHT);
|
|
|
|
ret = input_register_device(input_dev);
|
|
if (ret) {
|
|
input_free_device(input_dev);
|
|
KUNIT_FAIL_AND_ABORT(test, "Register device failed: %d", ret);
|
|
}
|
|
|
|
test->priv = input_dev;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void input_test_exit(struct kunit *test)
|
|
{
|
|
struct input_dev *input_dev = test->priv;
|
|
|
|
if (input_dev)
|
|
input_unregister_device(input_dev);
|
|
}
|
|
|
|
static void input_test_poll(struct input_dev *input) { }
|
|
|
|
static void input_test_polling(struct kunit *test)
|
|
{
|
|
struct input_dev *input_dev = test->priv;
|
|
|
|
/* Must fail because a poll handler has not been set-up yet */
|
|
KUNIT_ASSERT_EQ(test, input_get_poll_interval(input_dev), -EINVAL);
|
|
|
|
KUNIT_ASSERT_EQ(test, input_setup_polling(input_dev, input_test_poll), 0);
|
|
|
|
input_set_poll_interval(input_dev, POLL_INTERVAL);
|
|
|
|
/* Must succeed because poll handler was set-up and poll interval set */
|
|
KUNIT_ASSERT_EQ(test, input_get_poll_interval(input_dev), POLL_INTERVAL);
|
|
}
|
|
|
|
static void input_test_timestamp(struct kunit *test)
|
|
{
|
|
const ktime_t invalid_timestamp = ktime_set(0, 0);
|
|
struct input_dev *input_dev = test->priv;
|
|
ktime_t *timestamp, time;
|
|
|
|
timestamp = input_get_timestamp(input_dev);
|
|
time = timestamp[INPUT_CLK_MONO];
|
|
|
|
/* The returned timestamp must always be valid */
|
|
KUNIT_ASSERT_EQ(test, ktime_compare(time, invalid_timestamp), 1);
|
|
|
|
time = ktime_get();
|
|
input_set_timestamp(input_dev, time);
|
|
|
|
timestamp = input_get_timestamp(input_dev);
|
|
/* The timestamp must be the same than set before */
|
|
KUNIT_ASSERT_EQ(test, ktime_compare(timestamp[INPUT_CLK_MONO], time), 0);
|
|
}
|
|
|
|
static void input_test_match_device_id(struct kunit *test)
|
|
{
|
|
struct input_dev *input_dev = test->priv;
|
|
struct input_device_id id = { 0 };
|
|
|
|
/*
|
|
* Must match when the input device bus, vendor, product, version
|
|
* and events capable of handling are the same and fail to match
|
|
* otherwise.
|
|
*/
|
|
id.flags = INPUT_DEVICE_ID_MATCH_BUS;
|
|
id.bustype = BUS_VIRTUAL;
|
|
KUNIT_ASSERT_TRUE(test, input_match_device_id(input_dev, &id));
|
|
|
|
id.bustype = BUS_I2C;
|
|
KUNIT_ASSERT_FALSE(test, input_match_device_id(input_dev, &id));
|
|
|
|
id.flags = INPUT_DEVICE_ID_MATCH_VENDOR;
|
|
id.vendor = 1;
|
|
KUNIT_ASSERT_TRUE(test, input_match_device_id(input_dev, &id));
|
|
|
|
id.vendor = 2;
|
|
KUNIT_ASSERT_FALSE(test, input_match_device_id(input_dev, &id));
|
|
|
|
id.flags = INPUT_DEVICE_ID_MATCH_PRODUCT;
|
|
id.product = 1;
|
|
KUNIT_ASSERT_TRUE(test, input_match_device_id(input_dev, &id));
|
|
|
|
id.product = 2;
|
|
KUNIT_ASSERT_FALSE(test, input_match_device_id(input_dev, &id));
|
|
|
|
id.flags = INPUT_DEVICE_ID_MATCH_VERSION;
|
|
id.version = 1;
|
|
KUNIT_ASSERT_TRUE(test, input_match_device_id(input_dev, &id));
|
|
|
|
id.version = 2;
|
|
KUNIT_ASSERT_FALSE(test, input_match_device_id(input_dev, &id));
|
|
|
|
id.flags = INPUT_DEVICE_ID_MATCH_EVBIT;
|
|
__set_bit(EV_KEY, id.evbit);
|
|
KUNIT_ASSERT_TRUE(test, input_match_device_id(input_dev, &id));
|
|
|
|
__set_bit(EV_ABS, id.evbit);
|
|
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 */ }
|
|
};
|
|
|
|
static struct kunit_suite input_test_suite = {
|
|
.name = "input_core",
|
|
.init = input_test_init,
|
|
.exit = input_test_exit,
|
|
.test_cases = input_tests,
|
|
};
|
|
|
|
kunit_test_suite(input_test_suite);
|
|
|
|
MODULE_AUTHOR("Javier Martinez Canillas <javierm@redhat.com>");
|
|
MODULE_DESCRIPTION("KUnit test for the input core");
|
|
MODULE_LICENSE("GPL");
|