drivers/input/tests/input_test.c
Source file repositories/reference/linux-study-clean/drivers/input/tests/input_test.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/tests/input_test.c- Extension
.c- Size
- 4955 bytes
- Lines
- 184
- Domain
- Driver Families
- Bucket
- drivers/input
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/input.hkunit/test.h
Detected Declarations
function Copyrightfunction input_test_exitfunction input_test_pollfunction input_test_timestampfunction input_test_match_device_idfunction input_test_grab
Annotated Snippet
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;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/input.h`, `kunit/test.h`.
- Detected declarations: `function Copyright`, `function input_test_exit`, `function input_test_poll`, `function input_test_timestamp`, `function input_test_match_device_id`, `function input_test_grab`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.