summaryrefslogtreecommitdiff
path: root/test/test-libevdev-events.c
Commit message (Collapse)AuthorAgeFilesLines
* test: silence some valgrind warningsPeter Hutterer2014-04-281-0/+1
| | | | | | | ioctl points to uninitialized bytes - correct but we didn't use those anyway. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Drain all events before synchronizing after SYN_DROPPEDPeter Hutterer2014-04-241-0/+219
| | | | | | | | | | | | | | | | | | | | The kernel ring buffer drops all events on SYN_DROPPED, but then continues to fill up again. So by the time we read the events, the kernel's client buffer is essentially like this: SYN_DROPPED, ev1, ev2, ev3, ...., evN The kernel's device state represents the device after evN, and that is what the ioctls return. For EV_KEY, EV_SND, EV_LED and EV_SW the kernel removes potential duplicates from the client buffer [1], it doesn't do so for EV_ABS. So we can't actually sync while there are events on the wire because the events represent an earlier state. So simply discard all events in the kernel buffer, synchronize, and then start processing again. We lose some granularity but at least the events are correct. [1] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/drivers/input/evdev.c?id=483180281f0ac60d1138710eb21f4b9961901294 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Drop invalid ABS_MT_TRACKING_ID changesPeter Hutterer2014-04-031-0/+160
| | | | | | | | | | | | | | | | | | | | | | Follow-up to commit 41334b5b40cd5456f5f584b55d8888aaafa1f26e Author: Peter Hutterer <peter.hutterer@who-t.net> Date: Thu Mar 6 11:54:00 2014 +1000 If the tracking ID changes during SYN_DROPPED, terminate the touch first In normal mode, we may get double tracking ID events in the same slot, but only if we either have a user-generated event sequence (uinput) or a malicious device that tries to send data on a slot > dev->num_slots. Since the client is unlikely to be able to handle these events, discard the ABS_MT_TRACKING_ID completely. This is a bug somewhere in the stack, so complain and hobble on along. Note: the kernel doesn't allow that, but we cap to num_slots anyway, see 66fee1bec4c4b021e1b54adcd775cf6e2aa84869. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Drop hardcoded MAX_SLOTS in favour of pre-allocated memoryPeter Hutterer2014-04-031-107/+0
| | | | | | | | | | | | | | | | | | | | | We can't allocate in sync_mt_state since it may be called in the signal handler. So pre-allocate based on the device's number of slots, store that in the libevdev struct and use it for the sync process. This fixes a remaining bug with the handling of ABS_MT_TRACKING_ID. If a device had > MAX_SLOTS and a slot above that limit would start or stop during a SYN_DROPPED event, the slot would not be synced, and a subsequent touch in that slot may double-terminate or double-open a touchpoint in the client. For the effects of that see commit 41334b5b40cd5456f5f584b55d8888aaafa1f26e Author: Peter Hutterer <peter.hutterer@who-t.net> Date: Thu Mar 6 11:54:00 2014 +1000 If the tracking ID changes during SYN_DROPPED, terminate the touch first Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* test: remove checks for test device creation failurePeter Hutterer2014-04-021-212/+175
| | | | | | test_create_... fails on a non-zero return code anyway Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: fix the tracking_id sync testPeter Hutterer2014-04-011-1/+1
| | | | | | | A max of num_slots -1 caused the first MT_SLOT event to be skipped, leading to wrong tracking IDs in the slots. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: shut up compiler warningPeter Hutterer2014-03-191-1/+1
| | | | | | | | | | | | test-libevdev-events.c: In function ‘test_double_syn_dropped_event’: test-libevdev-events.c:187:2: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result] This read was there to drain events even when there shouldn't be any on the pipe anyway. So let's add an assert. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* test: fix distcheckPeter Hutterer2014-03-111-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* If the tracking ID changes during SYN_DROPPED, terminate the touch firstPeter Hutterer2014-03-071-0/+163
| | | | | | | | | | Most clients can't deal with tracking ID changes unless a -1 is sent first. So if we notice that the tracking ID has changed during the sync process, send a set of ABS_MT_TRACKING_ID -1 events for each of those, then send the rest of the events. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Send an extra ABS_MT_SLOT event to sync the client up with the current slotBenjamin Tissoires2014-03-071-0/+93
| | | | | | | | | If multiple slots have changed during the sync handling, the client must be re-set to the current slot before continuing with normal events. Signed-off-by: Benjamin Tissoires <btissoir@redhat.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Don't sync the MT state for fake MT devicesPeter Hutterer2014-03-061-0/+82
| | | | | | | | | | | | | Devices with ABS_MT_SLOT-1 are fake MT devices, they merely overlap the axis range but don't actually provide slots. The EVIOCGABS ioctl won't work to retrieve the current value - the kernel does not store values for those axes and the return value is always 0. Thus, simply ignore those axes for fake MT devices and instead rely on the next event to update the caller with the correct state for each axis. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Cap slot values to the announced maximumPeter Hutterer2014-03-061-0/+78
| | | | | | | | | | | | | | A malicious device may announce N slots but then send a slot index >= N. The slot state is almost always allocated (definitely the case in libevdev and true for most callers), so providing a slot number higher than the announced maximum is likely to lead to invalid dereferences. Don't allow that. Likewise, don't allow negative slot numbers. Note that the kernel filters these events anyway, the only way to trigger this is to change the device fd to something outside the kernel's control. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* test: add two more checks for the current slotPeter Hutterer2014-03-061-0/+3
| | | | | | | When syncing, we expect the slot to stay the same until the client has processed the events. This already worked, just add a check to make sure. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Increase MAX_SLOTS to 60Peter Hutterer2014-03-061-1/+1
| | | | | | | | | As seen on 3M devices, which seems to be the maximum seen so far. Some Stantum devices report 255 touches but are only capable of 10, so the are not affected by our limits. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* test: add a test for > MAX_SLOTS mt valuesPeter Hutterer2014-03-061-0/+102
| | | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* test: whitespace fixes (newlines)Peter Hutterer2014-03-051-1/+2
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: plug more memory leaksPeter Hutterer2014-02-271-0/+3
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Warn about a SYN_DROPPED right after finishing a syncPeter Hutterer2014-01-221-0/+108
| | | | | | | | | | | | If the first event after a completed device sync is a SYN_DROPPED, warn the user that they're not fast enough handling this device. The test for this is rather complicated since we can't write SYN_DROPPED through uinput so we have to juggle the device fd and a pipe and switch between the two at the right time (taking into account that libevdev will read events from the fd whenever it can). Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: fix typoPeter Hutterer2014-01-171-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: rename a test to match what it's testing betterPeter Hutterer2014-01-171-2/+2
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Merge branch 'ev-rep-handling'Peter Hutterer2013-12-091-0/+26
|\
| * Support EV_REP values through libevdev_get_event_valuePeter Hutterer2013-12-091-0/+26
| | | | | | | | | | | | | | | | | | We shouldn't have a separate API for that, the whole point of libevdev is to abstract the quirkyness of the ioctls into a common interface. So let's export the two EV_REP values through libevdev_get_event_value. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* | State that the event is defined for a SYN_DROPPEDPeter Hutterer2013-12-091-0/+2
|/ | | | | | | | | | | | All clients that want to handle SYN_DROPPED correctly need to pass an EV_SYN through their own handlers before starting with the syn events. Rather than letting them synthesize that, guarantee that the event is defined the first time LIBEVDEV_READ_STATUS_SYNC is returned. This does not change existing behavior, it merely documents it so we can rely on it. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Name-space the read flags betterPeter Hutterer2013-09-111-60/+60
| | | | | | | | Rename from LIBEVDEV_READ_foo to LIBEVDEV_READ_FLAG_foo to differentiate better from LIBEVDEV_READ_STATUS_foo. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Enumerate libevdev_next_event() return codesPeter Hutterer2013-09-111-44/+44
| | | | | | | | | | | | | | | | Improved readability in callers, changing magic numbers 0 and 1 to rc = libevdev_next_event(); if (rc == LIBEVDEV_READ_STATUS_SUCCESS) do_something(); else if (rc == LIBEVDEV_READ_STATUS_SYNC) do_something_else() No ABI changes, the enum values are the previously documented values, this is just a readability improvement. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* test: update to test for the various _MAX valuesPeter Hutterer2013-08-311-2/+34
| | | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Use AC_USE_SYSTEM_EXTENSIONSPeter Hutterer2013-08-291-1/+0
| | | | | | | Defines _GNU_SOURCE for us. http://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Posix-Variants.html Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Add support for EV_SWPeter Hutterer2013-08-291-0/+55
| | | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Store the abs value after handling mt eventsPeter Hutterer2013-08-261-0/+54
| | | | | | | | | | | This way any ABS_MT_ event value that comes in will also be stored in abs_info. That always corresponds to "current slot", so if a user calls libevdev_set_event_value() or libevdev_get_event_value() they're actually modifying the current slot value. When the current slot changes, sync the state back into the absinfo values. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Keep the LED state and sync it after SYN_DROPPEDPeter Hutterer2013-08-151-0/+55
| | | | | | | | This enables libevdev_get_event_value(dev, EV_LED, LED_NUML); to check if a LED is on or off. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Add setters for an event or slot valuePeter Hutterer2013-08-151-0/+180
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Add libevdev_has_event_pending()Peter Hutterer2013-08-011-0/+40
| | | | | | | | Returns non-zero if there are events avialable to be read. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* test: add a few sync test cases for incomplete syncsPeter Hutterer2013-07-021-0/+127
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: add test for abs and mt syncingPeter Hutterer2013-07-011-0/+167
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: add tests for mt event valuesPeter Hutterer2013-07-011-0/+119
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: add tests for checking event valuesPeter Hutterer2013-07-011-0/+119
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: add test for filtered event deliveryPeter Hutterer2013-07-011-1/+79
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: use new convenience function for uinput device creationPeter Hutterer2013-06-291-46/+25
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: prepare a common header file for all testsPeter Hutterer2013-06-291-4/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: close the right pipe fdsPeter Hutterer2013-06-281-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: fix a bunch of memory leaksPeter Hutterer2013-06-281-0/+3
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: add test case for button deltas after SYN_DROPPEDPeter Hutterer2013-06-281-0/+59
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Require a flag for normal mode tooPeter Hutterer2013-06-271-5/+5
| | | | | | Makes the whole thing more explicit. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* test: add test for event polling and SYN_DROPPED handlingPeter Hutterer2013-06-271-0/+155
Rudimentary only, but it's a start Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>