Commit graph

77 commits

Author SHA1 Message Date
Peter Hutterer
2a1095924b Run clang-format over the code
This uses the .clang-format file in the follow-up commit, but committed
prior to that to ease review of said file and various integrations.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1246>
2025-07-01 16:42:44 +10:00
Peter Hutterer
ed29a4f200 test: disable clang-format in test collections
It's too much effort fighting clang-format for these snippets which
all don't really do much anyway but are important to be read easily.

Let's categorically disable all formatting in the test collections and
move on.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1246>
2025-07-01 16:36:14 +10:00
Peter Hutterer
aebf3cd491 Add trailing commas to prevent clang-format oddities
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1246>
2025-07-01 16:36:14 +10:00
Peter Hutterer
6cbe4568de test: rename litest_delete_device to litest_device_destroy
To be closer to the common free/destroy/unref pattern

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +10:00
Peter Hutterer
5a652e5116 test: make the timeout functions auto-dispatching
The overwhelmingly vast majority of invocations want to have a dispatch
before/after, so let's automate that. In case NULL is passed, that
dispatch is skipped.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1169>
2025-04-04 05:13:00 +00:00
Peter Hutterer
58315eb9d4 test: remove duplicate empty lines from the test/ directory
We've had a CI job for checking this since but it omitted the test
directory.

Fixes: bb6ff0ec00 ("gitlab CI: add a job to check for whitespace issues")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1154>
2025-03-11 11:41:34 +00:00
satrmb
a71f560f3e test: fix off-by-ones in two ranges, prevent the same in remaining ranged tests
touchpad_move_after_touch contains support for up to 5 fingers but was only run
with 2..4 fingers.
touchpad_multitap and several others using the same parameter definition were
long ago tested with 3..7 taps. In 8f92b091 this was reduced to 3..4 for CI
performance, while the commit message indicates 3..5 were intended.

The common theme is that the upper bound of `struct range` is interpreted
as exclusive, while some uses assumed it would be inclusive.
There are relatively recent helper functions range_init_inclusive and
range_init_exclusive (since 817dc423) to avoid this trap. Use them on the
remaining two ranged tests.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1142>
2025-02-20 09:34:20 +01:00
satrmb
6f9a54c573 test: convert most ranged tests to parametrized ones
The two remaining ranged tests (abs_device_no_range, abs_mt_device_no_range)
are better served staying with ranges because parametrized tests need to
explicitly list all members of the range, which for these tests is not only
pretty big, but also contains abs axes reserved for future use. Those axes
have no names yet, making a future-proof conversion pretty much impossible.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1142>
2025-02-20 09:34:14 +01:00
satrmb
3a60c47e33 test: add optional value names to parametrized tests
Only implemented for i32 values so far, used for enums and enum-like constants,
replaces a runtime lookup from stringly-typed parameters.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1141>
2025-02-20 08:18:48 +01:00
Peter Hutterer
114af53824 test: fix the touchpad finger positions for a test
The 5th finger was placed in the same position as the 4th finger which
doesn't have an effect in libinput but it looks wrong.

And the first finger was put down at 40/30 but then moved from 70/30 to
the new position, causing pointer jumps on some touchpads.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1145>
2025-02-18 05:40:44 +00:00
Peter Hutterer
5ed75e7e9f test: make litest_parameters fetching more type-safe
Require the type to be added in the litest_test_params_fetch() so we can
easily detect a mismatch. And add some type-safe getters that are much
easier to use for all the tests that only have a single parameter to
fetch anyway.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1139>
2025-02-12 09:11:51 +00:00
Peter Hutterer
d9f121b4d1 test: add a litest_with_parameters helper macro
Magic for loop that takes care of the creation and unref for us,
hopefully improving readability a bit.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1138>
2025-02-12 11:41:56 +10:00
Peter Hutterer
6ee8e8d9b6 test: change tap tests to use parameters
This also fixes the invocation of the
touchpad_3fg_tap_btntool_pointerjump which was written as ranged test
but never got invoked with a range (but _i defaults to zero).

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1119>
2025-01-08 10:50:52 +10:00
Peter Hutterer
41c08f0816 test: add litest-runner as test suite runner
This replaces check. The code is a copy of pwtest which I wrote years
ago for pipewire but adjusted for us here the last few days.

There are a few advantages over check:
- Ability to SKIP tests or mark them as NOT_APPLICABLE, the latter
  of which is used for early checks if a device doesn't meet
  requirements.
- it captures stdout/stderr separately
- colors!
- YAML output format makes it a lot easier to read the results and
  eventually parse them for e.g. "restart failed tests"

Less abstraction: we set up the tests, pass them to the runner and run
them with the given number of forks. This is an improvement over before
where we forked into N test suites which each called check which then
forked again. Since we're now keeping track of those processes
ourselves we can also write tests that are expected to fail with
signals.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>
2024-10-30 23:20:42 +00:00
Peter Hutterer
a67dbefc0f test: split out the touchpad tap tests into multiple collections
These take a long time and have a reasonable high chance of failure due
to the timing constraints. Let's split them up so they don't hog the
runners for that long and in case they fail, we only need to re-run a
short test.

Before: one test running approx 21 min, now 3 tests running approx 7 +
11 + 4 min.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1065>
2024-10-18 10:49:47 +10:00
Peter Hutterer
57a3313d33 test: switch a bunch of tests from abort() to one with a message
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1062>
2024-10-16 18:03:03 +10:00
Peter Hutterer
bd62da11e4 test: switch the tests to use enum comparisons
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1059>
2024-10-15 12:44:27 +10:00
Peter Hutterer
f89fd6d924 test: switch ck_assert over to litest_assert
This is the first step in switching away from the check framework.
Our litest macros already do almost exactly the same anyway so most of
this is a simple sed with a few compiler fixes where things mismatch
(nonnull -> notnull) and (_tol -> _epsilon).

This now generates a whole bunch of integer mismatch warnings: check
casts everything to intmax_t whereas we use typeof, so lots of warnings
especially for enums.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1059>
2024-10-15 12:44:27 +10:00
Peter Hutterer
3ed70e864f test: add litest_assert_event_type_not_one_of
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1059>
2024-10-15 12:44:27 +10:00
Peter Hutterer
86c47be816 test: add litest_dispatch() for better test debugging
Wraps libinput_dispatch() with a location which will make things a bit
easier to track. Output (in --verbose) is something like:

  gestures_swipe_3fg_unaccel_fn():1346 - dispatching

Which makes it easier to associate the various calls to libinput
dispatch with the other output from libinput.

This patch switches all uses of libinput_dispatch() in test cases over
but not the litest functions that may call dispatch too. Remains to be
seen if that is necessary.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1048>
2024-09-19 15:21:04 +10:00
satrmb
910d59e836 touchpad: add sticky mode to drag-lock
Sticky mode removes the timeout from drag-lock, only a tap ends a drag.
Timeout mode remains available without changes.

Sticky mode is exposed as a new value for the existing drag-lock setting.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1037>
2024-09-05 00:47:47 +00:00
Peter Hutterer
bb1b1304df test: fix two wrong timeout calls
This are tests with drag lock enabled, so our timeout needs to be
be the tap and drag timeout (which is higher than the normal tap timeout).
Only worked because they're similar enough that if there's a bit of a
delay, the extra ms push us over the line.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/984>
2024-03-18 16:25:47 +00:00
Peter Hutterer
6bb02aaf30 High-resolution scroll wheel support
Starting with kernel v5.0 two new axes are available for high-resolution wheel
scrolling: REL_WHEEL_HI_RES and REL_HWHEEL_HI_RES. Both axes send data in
fractions of 120 where each multiple of 120 amounts to one logical scroll
event. Fractions of 120 indicate a wheel movement less than one detent.

This commit adds a new API for scroll events. Three new event types that encode
the axis source in the event type name and a new API to get a normalized-to-120
value that also used by Windows and the kernel (each multiple of 120 represents
a logical scroll click).

This addresses a main shortcoming with the existing API - it was unreliable to
calculate the click angle based on the axis value+discrete events and thus any
caller using the axis value alone would be left with some ambiguity. With the
v120 API it's now possible to (usually) calculate the click angle, but more
importantly it provides the simplest hw-independent way of scrolling by a
click or a fraction of a click.

A new event type is required, the only way to integrate the v120 value
otherwise was to start sending events with a discrete value of 0. This
would break existing xf86-input-libinput (divide by zero, fixed in 0.28.2) and
weston (general confusion). mutter, kwin are unaffected.

With the new API, the old POINTER_AXIS event are deprecated - callers should use
the new API where available and discard any POINTER_AXIS events.

Notable: REL_WHEEL/REL_HWHEEL are emulated by the kernel but there's no
guarantee that they'll come every accumulated 120 values, e.g. Logitech mice
often send events that don't add up to 120 per detent.

We use the kernel's wheel click emulation instead of doing our own.

libinput guarantees high-resolution events even on pre-5.0 kernels.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-08-31 08:45:01 +02:00
Peter Hutterer
234eeabe2f Replace fallthrough comments with __attribute__((fallthrough))
This has recently been endorsed by the linux kernel, it should be good
enough for us.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-07-22 23:14:43 +00:00
José Expósito
8a180b52d6 gestures: add hold gesture implementation
Hold gestures are notifications about fingers on the touchpad.
There is no coordinate attached to a hold gesture, merely the number of fingers.
A hold gesture starts when the user places a finger on the touchpad and
ends when all fingers are lifted. It is cancelled when the finger(s) move
past applicable thresholds and trigger some other interaction like pointer
movement or scrolling.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-06-09 01:18:58 +00:00
José Expósito
624041c09b test: cleanup: remove fallthrough followed by break
Remove fallthrough comments followed by a break statement.
No functional changes.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-05-24 05:35:27 +00:00
satrmb
dc936707a9 test: add test cases for 2/3 finger movement after drag-lock
Same as after a tap, just with a short drag between tap and 2/3 finger movement.
Also fixes a finger coord typo in one of the previously added test cases.

Signed-off-by: satrmb <10471-satrmb@users.noreply.gitlab.freedesktop.org>
2021-02-17 08:14:11 +01:00
Peter Hutterer
e96852ac37 test: add test cases for 2/3 finger movement after tap
We have two behaviors here:
- tap + 2fg -> scrolling
- tap + 1fg move + 2f down -> dragging

Let's document this. The 3fg case only has one situation, so let's test that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-15 18:03:34 +10:00
satrmb
37e6e89ed5 test: fix a few missing or wrong drag-lock timeouts
These had no consequences apart from occasional "system is too slow" messages,
because the test suite's shorter tap timeout is just barely long enough
for drag-lock, and/or because litest_assert_button_event waits for an event
anyway.

Signed-off-by: satrmb <10471-satrmb@users.noreply.gitlab.freedesktop.org>
2021-02-15 05:46:46 +00:00
satrmb
4ccdacaf95 touchpad: permit only one finger on the touchpad at the start of a tap-drag
This only affects the actual dragging part of the tap-and-drag interaction;
n-finger tap-and-drag is supposed to be performed with a n-finger tap
followed by a 1-finger drag.
Allowing a second finger in the middle of a drag is still necessary for a
finger swap, which users may need in long-distance drags, especially when
drag-lock is disabled.

Signed-off-by: satrmb <10471-satrmb@users.noreply.gitlab.freedesktop.org>
2021-02-15 05:46:46 +00:00
Peter Hutterer
d3115f4875 test: drop the custom group names
The group names are forced by check (they are called suite names there) but
for our test suite they provide very little benefit. Much easier to just
use the filename a test is in as group name.

This removes the pure substring match for --filter-group, it's now fnmatch
only. group names are short enough that the typing isn't an issue and we don't
want to run tests twice (e.g. 'pad' is also in 'touchpad').

This patch caused #574 until it got fixed in d838e3a3a4

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-12 15:24:15 +10:00
Peter Hutterer
61e41df901 touchpad: disable the pressure axes wherever the resolution is nonzero
The kernel/udev set the pressure resolution to nonzero to indicate the value
is in a known scale (units/g). We use that information to disable the
pressure axis on such devices - real pressure cannot be translated to
contact size.

For the kernel patch see:
https://www.spinics.net/lists/linux-input/msg71237.html

Fixes #569

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-08 03:38:26 +00:00
Peter Hutterer
53595cb232 quirks: disable pressure on the Lenovo Yoga 9i touchpad
This touchpad is a true pressurepad and the pressure axis gives us physical
pressure down. Using it as contact size gives flaky touch detection, so let's
just disable the axis until we do something with that value.

Fixes #562

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-14 13:42:59 +10:00
satrmb
f2faf370e0 test: expand drag and multitap tests to tap with up to 3 fingers
This covers the addition of two- and three-finger tap-and-drag,
as well as the fix for multitaps with more than one finger in later taps
and the multifinger enhancement to the tap ending drag-lock.

Signed-off-by: satrmb <10471-satrmb@users.noreply.gitlab.freedesktop.org>
2020-09-25 06:01:28 +00:00
satrmb
0e569077fe touchpad: allow tap-and-drag for two-finger and three-finger taps
This commit duplicates the tap states responsible for tap-and drag (TAPPED
and all DRAGGING* states) to cover two-finger and three-finger taps;
the code for the new states is shared with the existing machinery for
one-finger tap-and-drag.

Signed-off-by: satrmb <10471-satrmb@users.noreply.gitlab.freedesktop.org>
2020-09-25 06:01:28 +00:00
Peter Hutterer
fc7b8d7948 touchpad: correct the tap state transitions for a palm on TOUCH_BEGIN
Where a touch is labelled as palm on TOUCH_BEGIN (edge palms) we would still
feed the touch through the tap state machine. This would trigger the PALM
transition for each state, usually reducing the touch count.

When the touches were later released, the touch count was out of sync,
resulting in an error message. In the case of #488, the trigger was
a single evdev frame with three fingers down, the third of which was an edge
palm:
- touch 1 transitions from IDLE to TOUCH
- touch 2 transitions from TOUCH to TOUCH_2
- touch 3 (the palm) transitioned from TOUCH_2 back to TOUCH

That third transition is invalid, the palm hasn't been seen by the tap state
machine so it should just be ignored.

Fix this by moving making the tap state processing conditional on a touch
state other than TOUCH_BEGIN.

Fixes #488

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-06-03 21:50:44 +00:00
Peter Hutterer
8fdeba9ea2 test: wrap slot counting into a helper function
This is prep work for future devices that announce a wrong slot count. For the
tests this can be a problem if we rely on the correct slot count to decided
whether to run a test or not.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-01-29 15:58:49 +10:00
Peter Hutterer
9149c09a3b test: switch from counting slot max to num_slots
Much more human-readable this way

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-01-09 05:58:53 +00:00
Peter Hutterer
62df51789b test: fix some wrong touchpad slot range checks
This was excluding tests from some touchpads due to slot count confusion.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-01-09 05:58:53 +00:00
satrmb
bba79754d6 test: fix a multitap test expecting one tap too few
The problem was masked by a missing timeout, causing one up / down pair to not yet be enqueued before reading the queue.
2019-11-26 02:34:44 +00:00
Peter Hutterer
271616265b touchpad: don't allow for multifinger tapping after a move
In the current implementation, movements > threshold and timeouts usually move
to HOLD state and continue from there. Where a finger is lifted, we go back
up the diagram into the previous finger count's HOLD state.

The side-effect of this is that a tap of a finger can be counted as tap even
after a movement:

- two fingers down, move to scroll, hold down
- third finger down, third finger up

This sequence triggers an erroneous three-finger tap. Once the motion
threshold is hit by any touch, no finger must trigger 2/3 finger tap events
while any touch is down.

The false tap is only triggered where the new finger can execute a tap without
any other finger changing any property. This can be triggered on the
reporter's Dell Precision 5520 but on most other touchpads, a new finger down
will trigger slight movement, pressure or touch size updates and thus the bug
cannot be triggered.

Fixes #382

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-15 00:24:00 +00:00
Peter Hutterer
d82f3b8798 test: replace a touch move with a timeout
We only care about the third-finger data here, the movement of the first two
was just to get out of the base tap states. A timeout will do the same thing
here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-19 11:08:40 +10:00
Peter Hutterer
fe8a0eee3f test: make all tap tests use the "tap" group prefix
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-05-27 21:02:33 +10:00
Peter Hutterer
803a99ac05 test: fix a bunch of tests expecting BTN_TOOL_TRIPLETAP
A device may have 1 or 2 slots without setting BTN_TOOL_TRIPLETAP, those
devices will fail those tests.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-05-08 14:09:28 +10:00
Paolo Giangrandi
a88d73cef4 touchpad: multitap state transitions use the same timing used for taps
Multitap sequences (more than 2 taps) had a 180ms timer set only on press,
not on release.
New taps within those 180ms could either trigger multitap+drag or another
multitap (for N+1 taps), resetting the timer on press once again.
If no new tap appears within those 180ms, the sequence was considered
complete.

This behavior differed from regular taps: for the very first tap of a
sequence the timer was set both on touch and on release.

The multitap timing caused misdetection of triple-tap-and-drag sequences as
the timer was hit frequently. Some of those were correctly detected, others
as tripletap only.

Changing the timer to be set on press **and** release gives us a more lenient
timeout. 180ms for tap-and-drag and 180ms for the next tap down after
release. This was also the behavior for the xorg synaptics driver.

Note that quadruple-tap-and-drag didn't suffer from this because the timeout
resulted in double-tap + double-tap-and-drag. Which has the same
user-visible effect.
2019-03-18 02:45:00 -06:00
Peter Hutterer
65f890a352 test: abort when we detect a touch jump during the tests
We never want to accidentally trigger this one. Where we trigger them on
purpose, we can swap the log handler out first.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-28 11:26:12 +10:00
Peter Hutterer
7768d7d981 test: drop the sleep_ms argument
This forces events for every ~10ms now. If we want a slower movement, we need
more steps - just like a real touchpad does it.

Cocinelle spatch files were variants of:
	@@
	expression A, B, C, D, E, F, G, H, I, J, K;
	@@

	- litest_touch_move_two_touches(A, B, C, D, E, F, G, H, I)
	+ litest_touch_move_two_touches(A, B, C, D, E, F, G, H)

The only test that needed a real fix was touchpad_no_palm_detect_2fg_scroll,
it used 12ms before, now it's using 10ms so on the bcm5974 touchpad the second
finger was a speed-thumb. Increasing the events and thus slowing down the
pointer means it's a normal finger and the test succeeds again.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-28 11:26:12 +10:00
Peter Hutterer
bdc7ef8bb2 test: change a few tests to use 10ms intervals
Change a number of tests to use 10ms intervals between finger events and fix
the coordinates up accordingly to avoid pointer jumps. This is in preparation
for a test-suite wide use of 10ms intervals.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-28 11:26:08 +10:00
Peter Hutterer
f1668b33f2 test: fix a touchpad test using the wrong coordinates
We moved to 60/60 before, not 50/50.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-28 10:50:14 +10:00
Peter Hutterer
ba603ea192 touchpad: improve finger counting for synaptics serial touchpads
A three-finger touch may cause slot N to end, in a frame after the
BTN_TOOL_TRIPLETAP. This causes tp->nfinger_down to be decremented to 2 as the
touch switches to MAYBE_END - which happens to be our num_slots. We exit early
and never restore the touch correctly.

Fix this by checking that the number of fake touches is equal to the slots, if
it is higher then we need to check for recovery.

Fixes https://gitlab.freedesktop.org/libinput/libinput/issues/99

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-03 15:01:55 +10:00