Commit graph

182 commits

Author SHA1 Message Date
Peter Hutterer
24dafff909 configure.ac: enable subdir-objects
The main thing holding us back here was our gcov hacks. We used to rebuild the
libevdev sources locally inside test/ with the gcov flags so that we could
leave the main libevdev sources untouched. This doesn't work well with
subdir-objects - we have to link to libevdev.la instead.

To enable gcov, we now have to apply the gcov flags to the main library
object. But this also means that when running, the notes files will be
somewhere within the libevdev/ directory, not the test/ directory. Working
around this in automake gets nasty quickly, so just add a script that knows
how to search for things.

No functional changes unless --enable-gcov is given at configure time - then
don't install the library.

The gcov reports are now in test/gcov-reports/

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2017-01-09 09:40:28 +10:00
Peter Hutterer
1ee17e18ac test: fix a Makefile.am comment
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-06 11:28:58 +10:00
Peter Hutterer
b261868b0a Disable test runs on make distcheck
The tests all need root, but running distcheck as root is not ideal. Disable
the test runs (but not the build) to make it easier to verify distcheck works
as intended.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2016-11-30 20:34:46 +10:00
Peter Hutterer
46b8381f0c test: ignore a failure to UI_DEV_DESTROY the device
Coverity complains about it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2016-03-04 07:26:53 +10:00
Peter Hutterer
2a27abf824 test: drop unnecessary return value
We abort if anything goes wrong anyway, so we never returned anything but
success.

Found by coverity.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2016-03-04 07:10:33 +10:00
Peter Hutterer
97da13c3c4 Accept LIBEVDEV_READ_FLAG_BLOCKING as valid flag
https://bugs.freedesktop.org/show_bug.cgi?id=89798

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2015-04-08 12:48:43 +10:00
Peter Seiderer
bc428e0211 Disable test-static-link in case of shared only build.
Fixes the following buildroot compile failure:

libtool: link: [..]/host/usr/bin/arm-buildroot-linux-uclibcgnueabi-gcc -std=gnu99 -I.. -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -static -o test-static-link test_static_link-test-link.o  ../libevdev/.libs/libevdev.so -Wl,-rpath -Wl,[...]/build/libevdev-1.4/libevdev/.libs
[...]/arm-buildroot-linux-uclibcgnueabi/bin/ld: attempted static link of dynamic object `../libevdev/.libs/libevdev.so'
collect2: error: ld returned 1 exit status
Makefile:719: recipe for target 'test-static-link' failed

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-03-16 08:57:42 +10:00
Peter Hutterer
4160d94baf cosmetic: fix a couple of duplicate/missing empty lines
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-03-04 08:41:33 +10:00
Peter Hutterer
4ba296cf90 test: use -std=c89 instead of c90 for the build test
They're identical, but RHEL6 doesn't support -std=c90

https://gcc.gnu.org/onlinedocs/gcc/Standards.html
https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-02-09 12:54:36 +10:00
Peter Hutterer
def17850d1 test: always build the build-tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-02-04 10:42:42 +10:00
Peter Hutterer
a669ac1faf configure: rename BUILD_TESTS to ENABLE_RUNTIME_TESTS
Avoids confusion when we build tests in the future even though BUILD_TESTS is
disabled.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-02-04 10:42:41 +10:00
Peter Hutterer
cc3b81f15a test: add test for clock id setting on an invalid device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-11-18 09:05:14 +10:00
Peter Hutterer
1fc31fba92 test: add test for setting absinfo on invalid devices
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-11-18 09:04:29 +10:00
Peter Hutterer
cf4adee09b test: add test case for grab calls on invalid devices
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-11-18 09:04:03 +10:00
Peter Hutterer
d68eb35378 test: add missing tests for invalid calls on next_event/has_event_pending
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-11-18 09:03:35 +10:00
Peter Hutterer
69b77b896a test: fix EVIOCREVOKE test on non-supporting kernels
The ioctl-returned errno is positive.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-08-25 10:28:09 +10:00
Peter Hutterer
31113e6038 Hook up nm to check for leaking symbols in the static library
We ignore anything that starts with an underscore, anything that starts with
libevdev and main (since we test the test-static-link binary) and a couple of
gcov-related functions. This should catch any functions we accidentally
export.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-08-25 10:06:48 +10:00
Peter Hutterer
6d3c994694 test: handle the GCOV_LDFLAGS in all tests
We rebuild the libevdev object files with the gcov flags for the tests, so we
need to make sure those flags are present on all binaries.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-08-25 10:06:48 +10:00
Peter Hutterer
1e264b6e94 test: override check-local instead of check
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-08-25 10:06:48 +10:00
Peter Hutterer
f46737726b test: add basic static link test
Same as the dynamic link test, just with the -static flag

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-08-25 10:06:48 +10:00
Peter Hutterer
8742e1e346 Add libevdev_property_from_name()
12717d79 "Add libevdev_event_type/code_from_name() resolvers" added the
lookup functions for types and codes, this commit adds the missing ones for
input properties.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-08-20 08:43:15 +10:00
Peter Hutterer
d856a85cda test: drop include of libevdev-int.h
Not needed, and shouldn't be used in a test anyway

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-08-18 10:36:08 +10:00
Peter Hutterer
c0248818e6 test: use ck_assert_int_eq() where comparing integers
A simple ck_assert() just fails, a ck_assert_int_eq() also shows the two
values. Makes failures a bit easier to debug.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-08-18 10:36:08 +10:00
Peter Hutterer
aa201a4737 test: ignore any timer_create errors in valgrind
Drop the rest of the stack trace, we know whenever check calls this we get a
valgrind error if sevp in timer_create(2) is NULL.

https://bugs.freedesktop.org/show_bug.cgi?id=79921

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-06-12 09:50:22 +10:00
Peter Hutterer
93bc9a329d Add per-device log handlers
The global log handler isn't a good choice for a low-level library. In the
caser of the X server, both evdev and synaptics are now using the libevdev but
are loaded from the same server process. Thus, there's only one log handler,
but evdev and synaptics don't talk to each other (a bit childish, I know).

Add a per-device log handler that overrides the global log handler, and fall
back to the global log handler if no device log handler is set. The log
macros take care of that automatically, especially as we can't do per-device
log handlers for the uinput code.

Note that we use the same struct for the global and device logging, so in each
instance one of the two function pointers is NULL. Suicide triggers are in
place in case we mess that up.

This also makes libevdev_new_from_fd() a bit less useful since we can't set
the log handler beforehand.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
2014-06-05 15:16:06 +10:00
Peter Hutterer
067426385e test: unconditionally distribute the valgrind suppressions
Reported-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-05-07 18:55:02 +10:00
Peter Hutterer
a93baace89 test: run all tests through valgrind
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-04-29 10:49:10 +10:00
Peter Hutterer
974e330ac2 test: disable parallel testing
The tests create devices on the host system, avoid running them in parallel to
avoid interference between the test devices.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-04-29 10:48:36 +10:00
Peter Hutterer
9d22a52383 test: silence some valgrind warnings
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>
2014-04-28 08:27:06 +10:00
Peter Hutterer
050bca91a1 Drain all events before synchronizing after SYN_DROPPED
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>
2014-04-24 08:17:01 +10:00
Peter Hutterer
6721131eaf test: restore default log priority after tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-04-08 09:01:50 +10:00
Peter Hutterer
6cbf971b39 Drop invalid ABS_MT_TRACKING_ID changes
Follow-up to
commit 41334b5b40
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
66fee1bec4.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-04-03 13:31:40 +10:00
Peter Hutterer
f8fba5b588 Drop hardcoded MAX_SLOTS in favour of pre-allocated memory
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 41334b5b40
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>
2014-04-03 13:30:49 +10:00
Peter Hutterer
c97839a81e test: remove checks for test device creation failure
test_create_... fails on a non-zero return code anyway

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-04-02 11:35:56 +10:00
Peter Hutterer
befe33620b test: the kernel test build doesn't need to link to libevdev
We statically compile libevdev in anyway through $(common_sources)

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-04-02 11:35:12 +10:00
Peter Hutterer
f90c038a2d test: fix kernel test for revoke after
dev2 by definition doesn't initialize, we expect it to fail. Freeing it after
is a bad idea. Also initialize it to NULL so this is a bit more obvious now.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-04-02 11:35:12 +10:00
Peter Hutterer
9fa89aabba test: fix the tracking_id sync test
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>
2014-04-01 17:05:53 +10:00
Peter Hutterer
2ad8980c5a test: shut up compiler warning
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>
2014-03-19 09:36:41 +10:00
Peter Hutterer
9b0d1f708a test: fix distcheck
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-03-11 08:31:12 +10:00
Peter Hutterer
41334b5b40 If the tracking ID changes during SYN_DROPPED, terminate the touch first
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>
2014-03-07 10:16:16 +10:00
Benjamin Tissoires
d3ae3da90f Send an extra ABS_MT_SLOT event to sync the client up with the current slot
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>
2014-03-07 10:16:11 +10:00
Peter Hutterer
12ff51b871 Don't sync the MT state for fake MT devices
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>
2014-03-06 14:30:03 +10:00
Peter Hutterer
66fee1bec4 Cap slot values to the announced maximum
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>
2014-03-06 14:30:03 +10:00
Peter Hutterer
4ba56ac309 test: add two more checks for the current slot
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>
2014-03-06 09:21:02 +10:00
Peter Hutterer
f3f31b47fc Increase MAX_SLOTS to 60
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>
2014-03-06 09:21:02 +10:00
Peter Hutterer
d596bd7a32 test: add a test for > MAX_SLOTS mt values
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2014-03-06 09:21:02 +10:00
Peter Hutterer
b08ed615d3 test: whitespace fixes (newlines)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-03-05 19:16:08 +10:00
Peter Hutterer
05c061c2bc test: plug more memory leaks
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-27 13:19:12 +10:00
Peter Hutterer
128cdcf105 test: fix memleak when using the test-uinput device
The libevdev-created uinput device was never freed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-27 11:08:51 +10:00
Peter Hutterer
061927dd76 Add a test for EVIOCREVOKE
New in 3.12, EVIOCREVOKE revokes access to an evdev device. This is unlikely
to be used by a libevdev user, see.
http://lists.freedesktop.org/archives/input-tools/2014-January/000688.html

This patch adds a new test-kernel binary that tests the kernel API directly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
2014-02-26 07:22:04 +10:00