Commit graph

80 commits

Author SHA1 Message Date
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
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
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
1e445f3f84 test: implement support for parametrizing tests
litest supports ranged tests but they are not enough, doubly so with
tests where we want to parametrize across multiple options.

This patch adds support for just that, in clunky C style.
The typical invocation for a test is by giving the test parameter
a name, a number of values and then the values themselves:

	struct litest_parameters *params = litest_parameters_new("axis", 's', 2, "ABS_X", "ABS_Y",
	                                                         "enabled", 'b', '2', true, false,
	                                                         "number", 'u', '2', 10, 11,
	                                                         NULL);
	litest_add_parametrized(sometest, LITEST_ANY, LITEST_ANY, params);
	litest_parameters_unref(params);

Currently supported are u (uint32), i (int32), d (double), b (bool),
c (char) and s (string).

In the test itself, the `test_env->params` variable is available and
retrieval of the parameters works like this:

	const char *axis;
	uint32_t number;
	bool enabled;
	litest_test_param_fetch(test_env->params,
	                        "axis", &axis,
	                        "enabled", &enabled,
	                        "number", &number,
	                        NULL);

Note that since this is an effectively internal test-suite only
functionality we don't do type-checking here, it's assumed that if you
write the code to pass parameters into a test you remember the type
of said params when you write the test code.

Because we don't have hashmaps or anything useful other than lists the
implementation is a bit clunky: we copy the parameter into the test
during litest_add_*, permutate it for our test list which gives us yet
another linked list C struct, and finally copy the actual value into
the test and test environment as it's executed. Not pretty, but it
works.

A few tests are switched as simple demonstration. The name of the
test has the parameters with their names and values appended now, e.g.:
   "pointer:pointer_scroll_wheel_hires_send_only_lores:ms-surface-cover:axis:ABS_X"
   "pointer:pointer_motion_relative_min_decel:mouse-roccat:direction:NW"

Filtering by parameters can be done via globs of their string
representation:
   libinput-test-suite --filter-params="axis:ABS_*,enabled:true,number:10*"

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1109>
2025-01-07 02:02:37 +00: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
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
5f4f72dca4 test: switch a bunch of integer comparisons to right sizes
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
237b15b401 test: fix some checks using ints to compare doubles
Theoretically we should be using ck_assert_double_eq here for
consistency but this patch  is part of a series eventually
replacing those calls, so let's jump to litest_assert_double
directly to avoid further rebase conflicts.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1059>
2024-10-15 12:44:27 +10:00
Peter Hutterer
25bdda0b8a test: use litest_assert_event_type instead of direct type check
This provides better debugging logs and is slightly less code in
the checks too.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1050>
2024-09-19 23:43:53 +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
Peter Hutterer
74f69dc9a0 test: replace an assert with double_ge
Better test debugging this way.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/986>
2024-03-18 23:02:05 +00:00
Peter Hutterer
d3481c8807 evdev: if a device's rotation is around 180 degrees, flip the wheel
For a device used upside-down, make sure the wheels correspond to the
new physical directions. There's a grace range of 20 degrees either way
since that seems like it makes sense.

For 90 degree rotation (or 270 degree) the wheel is left as-is, the
heuristics to guess what angle we want in this case is not clear enough.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-04-27 13:15:14 +10:00
Peter Hutterer
01a02d4033 fallback: don't double-map if any left-handed buttons are down
The key_count array for buttons records the logical button sent to the
client - for left-handed configurations that means a BTN_LEFT is
recorded as BTN_RIGHT.

When the device is suspended and we are releasing all keys we must thus
release the button code as-is without trying to map it again.

Fixes #881

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-03-29 16:37:24 +10:00
Peter Hutterer
40869bf11e test: minor cleanups
A whitespace fix, moving a check-related #define closer to the #include
and change a test that doesn't need a device to litest_add_no_device().

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-03-29 11:14:27 +10:00
Yinon Burgansky
93135c2012 filter: add scroll movement type to the custom acceleration profile
Adds a dedicated scroll movement type to the custom acceleration profile.
Supported by physical mouse and touchpad.
Other profiles remain the same by using the same unaccelerated filter for the scroll filter.

Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
2023-02-24 13:01:34 +02:00
Yinon Burgansky
886f1c6767 filter: validate custom acceleration function's points size
Adds min and max size limit for custom acceleration function's points.
Adds tests to make sure validation works properly.

Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
2023-02-02 04:56:18 +00:00
Yinon Burgansky
5324f425a1 Introduce custom acceleration profile
The custom acceleration profile allow the user to define custom
acceleration functions for each movement type per device, giving
full control over accelerations behavior at different speeds.

This commit introduces 2 movement types which corresponds to the
2 profiles currently in use by libinput.

regular filter is Motion type.
constant filter is Fallback type.

This allows possible expansion of new movement types for the
different devices.

The custom pointer acceleration profile gives the user full control over the
acceleration behavior at different speeds.
The user needs to provide a custom acceleration function f(x) where
the x-axis is the device speed and the y-axis is the pointer speed.

The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel of the acceleration.

The custom acceleration function is defined using n points which are spaced
uniformly along the x-axis, starting from 0 and continuing in constant steps.
There by the points defining the custom function are:
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
where f is a list of n unitless values defining the acceleration
factor for each velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.

Signed-off-by: Yinon Burgansky <51504-Yinon@users.noreply.gitlab.freedesktop.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-01-17 01:46:17 +00:00
satrmb
4a202a95c0 test: exclude the two high-delay debounce tests from the valgrind CI run
The `debounce_bounce_high_delay` and `debounce_spurious_trigger_high_delay`
tests are failing with annoying frequency in valgrind, but that is
entirely due to valgrind being too slow for the tight timing reqirements
of these tests. Skipping them in valgrind has next to no potential to hide
memory leaks because the code paths leading to success are also covered by
other tests which are less picky about timing, and the CI test suite run
without valgrind still tests for their success.

Signed-off-by: satrmb <10471-satrmb@users.noreply.gitlab.freedesktop.org>
2022-06-28 13:22:25 +02:00
Peter Hutterer
3542023996 test: fix a typo
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-06-08 09:25:59 +10:00
Peter Hutterer
d833f265c0 test: use a ranged test instead of a duplicated one
These two tests were identical except for the WHEEL/HWHEEL
differentiator, let's make this into a ranged test instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-06-08 09:25:02 +10:00
José Expósito
4ae72b6eb2 wheel: fix Lenovo Scrollpoint quirk
The IBM/Lenovo Scrollpoint mouse features a trackpoint-like stick that
sends a great amount of scroll deltas.

In order to handle the device, a quirk is in place to normalize the
scroll events as they were relative motion.

However, when high-resolution scroll was implemented, we started
normalizing the hi-res events instead of the lo-res events by mistake.

Fix the quirk by normalizing the right deltas.

Fixes: 6bb02aaf30 ("High-resolution scroll wheel support")
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Tested-by: Peter Ganzhorn <peter.ganzhorn@gmail.com>
2022-06-07 19:55:42 +02:00
Peter Hutterer
7688f35477 test: ensure we always have an axis event where we expect one
If we never got an event, we'd skip over the while loop and generate a
false positive.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-06-07 12:42:50 +10:00
Peter Hutterer
164227d193 test: fix the lowres-only wheel event tests
These tests gave us false positives for devices without a REL_WHEEL or
REL_HWHEEL because one of the helper functions papered over missing
events.

We have two tests here, one for horizontal, one for vertical but they
mixed WHEEL and HWHEEL in both tests. Fix this by splitting them
properly, so each test only checks that axis.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-06-07 12:42:50 +10:00
José Expósito
cf6c97119f wheel: allow to scroll while middle button is pressed
Since cd4f2f32b5 ("fallback: disable mouse scroll wheel while middle
button is pressed") the mouse wheel is inhibited while the mouse wheel
is pressed.

The original intention of this feature was to avoid unintended scroll
while pressing the scroll wheel. However, now that high-resolution
scroll is fully integrated in libinput we can improve this feature and
filter unintended scroll (below half a detent) and allow it when it is
intended (over half a detent).

Remove the "WHEEL_STATE_PRESSED" state from the wheel state machine and
let the general heuristics handle this case.

Also, remove the specific tests for this feature as now it is covered
by the general test cases.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-12-30 08:32:40 +01:00
José Expósito
d21f1ab7ab wheel: accumulate scroll when direction changes
Most mice with high-resolution support have a mechanism in place to
adjust the wheel to a detent. When scrolling, it is possible to stop
between two detents and this mechanism could generate a small amount of
scroll in the oposite direction.

Track the scroll direction in the wheel state machine and reset it when
the direction changes to avoid this issue.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-11-08 18:00:46 +01:00
José Expósito
b6a944bb80 wheel: ignore initial small scroll deltas
Mice with high-resolution support can generate deltas when the finger is
put on the wheel or when the user tries to click the wheel.

To avoid sending involuntary scroll events, add an extra state the the
wheel state machine to accumulate scroll deltas.
While the accumulated scroll is lower than a certain threshold, ignore
them until the threshold is reached.

Since no finish event is sent by the mouse, reset the state machine
after a period of scroll inactivity.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-11-08 18:00:46 +01:00
José Expósito
5bda716ebf fallback: hires scroll heuristics for buggy devices
Some devices might announce support for high-resolution scroll wheel
by enabling REL_WHEEL_HI_RES and/or REL_HWHEEL_HI_RES but never send
a high-resolution scroll event.

When the first low-resolution scroll event is received without any
previous high-resolution event, print a kernel bug warning and start
emulating high-resolution scroll events.

Fix #668

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-09-27 22:43:22 +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
satrmb
0cb570addd evdev: restart debouncing timers after every event
Signed-off-by: satrmb <10471-satrmb@users.noreply.gitlab.freedesktop.org>
2021-05-19 12:24:59 +02:00
JoseExposito
cd4f2f32b5 fallback: disable mouse scroll wheel while middle button is pressed
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-03-17 03:23:56 +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
52d6398753 test: use litest_destroy_context() for test-suite contexts
Symmetrical to litest_create_context(), this allows us to store special data
in that context that we have access to during the tests.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-07 18:51:33 +10:00
Evan Goode
034226d904 Allow the flat acceleration profile for touchpads
Signed-off-by: Evan Goode <mail@evangoo.de>
2020-05-27 06:21:00 +00:00
Peter Hutterer
4ff6d6e317 Deprecate wheel tilt as separate axis source
This has never been supported through the stack. No device ever had the
required MOUSE_WHEEL_TILT_VERTICAL/HORIZONTAL udev property set, so
libinput never set the right axis source. Neither weston nor mutter
added the code for it. Even if we added wheel tilt for devices now, it
would break those devices. And the benefit we get from having those
separate is miniscule at best.

So let's do the long-term thing and just deprecate this axis source.

The wheel tilt mouse test device remains in the test suite, with the
udev properties set just to verify that we do indeed ignore those now.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-05-21 07:29:44 +00:00
Peter Hutterer
63f9923013 Add a scroll button lock feature
Scroll button locking is an accessibility feature. When enabled, the scroll
button does not need to be held down, the first click holds it logically down,
to be released on the second click of that same button.

This is implemented as simple event filter, so we still get the same behavior
from the emulated logical button, i.e. a physical double click results in a
single logical click of that button provided no scrolling was triggered.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-10-17 12:21:41 +10:00
Peter Hutterer
67151ddcf5 test: don't use debounced clicks for the middle button emulation click
This used to work under valgrind up to F30 but with the F31 beta something is
now a tad slower so it triggers the timeouts before the middle emulation kicks
in.

The middlebutton timeout is 50ms and the first debounce timeout is 30ms, so if
we're late by 20ms, well, there goes the timeout.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-09-25 16:49:08 +10:00
Peter Hutterer
cc908b68a9 test: fix two coverity warnings
Alleged division by zero and use of an uninitialized variable. Both cannot
happen the way we call the tests, so let's just abort to make coverity happy.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-07-08 09:47:31 +10:00
Michael Forney
9d1b43d241 Avoid unnecessary VLAs
When the array length is fixed, or bounded by a fixed upper bound,
just use that fixed length.

Signed-off-by: Michael Forney <mforney@mforney.org>
2019-06-15 15:24:10 -07:00
Peter Hutterer
3b7b9ef682 test: adjust the relative pointer motion test for low-dpi devices
This escaped us before because the MOUSE_DPI setting on the low-dpi device was
ignored thanks to a broken udev rule (see a future commit for that).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-14 08:52:25 +10:00
Peter Hutterer
9484d13773 test: swap a few litest_assert() calls for their more precise cousins
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-11 15:49:02 +10:00
Peter Hutterer
34b49d5118 evdev: cancel the middle button timer on device removed
If a middle-button-emulating device is removed with one button down, the timer
never gets cancelled and triggers an assert during device removal.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-01-31 15:09:44 +10:00
Peter Hutterer
c75c00dac3 fallback: when force-releasing keys, release them directly
An emulated button is recorded as BTN_MIDDLE in the key down mask. If the
device is removed in that state, the BTN_MIDDLE event processed triggers
an assertion when we try to send out the event twice.

Fixes #201

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-01-31 15:09:44 +10:00
Peter Hutterer
507441537e evdev: cancel the button scroll timer on device removed
If a device was removed while a button was held down and within the timeout,
the timer was never cancelled (and removed from the timer list), triggering an
assert during device removal.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-01-31 15:09:44 +10:00
Greg V
cc029c7497 test: remove unused values.h include 2018-07-16 08:32:38 +10:00
Peter Hutterer
1f3f681fa7 fallback: cancel the debounce timers during device remove, not destroy
destroy isn't called until the last libinput_device_unref(), so we may trigger
a debounce timer after the device was removed. The same fix is neded for the
touchpad interface.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-06-29 13:52:17 +10:00
Peter Hutterer
eae33ffcf0 Revert "touchpad: allow custom profiles on touchpads"
This reverts commit f6d61dc314.
2018-05-21 12:09:20 +10:00
Peter Hutterer
f6d61dc314 touchpad: allow custom profiles on touchpads
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-26 14:48:37 +10:00