Commit graph

29 commits

Author SHA1 Message Date
Peter Hutterer
8336721dc0 test: fix the keycode obfuscation test
An earlier version of 73103a5c38 only obfuscated the plugin key codes,
not the "Queuing ..." message libinput itself uses. The test didn't get
updated when the queuing message was updated to obfuscate.

Fixes: 73103a5c38 ("plugin: always obfuscate keycodes")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1284>
2025-08-01 04:02:57 +00:00
Peter Hutterer
68dbb98f04 clang-format: add litest_with_logcapture to foreach macros
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1284>
2025-08-01 04:02:56 +00:00
Peter Hutterer
3ca34aa88a evdev: move the SYN_REPORT 1 filtering to the touchpad backend
In commit 9a9466b6a9 ("evdev: discard any frame with EV_SYN SYN_REPORT 1")
all frames with a SYN_REPORT 1 were discarded on the assumption of those
being key repeat frames. Unfortunately the kernel uses the same sequence
to simply mark *any* injected/emulated event, regardless of the cause. Key repeat
events are merely the most numerous ones but as shown in commit
7140f13d82 ("evdev: track KEY_SYSRQ frames and pass them even as repeat frames")
Alt+PrintScreen is also an emulated event.

Issue #1165 details another case: keyboards with n-key rollover can
exceed the kernel-internal event buffer, typically 8 events for devices
without EV_REL/EV_ABS. Those events will be broken up by the kernel into
multiple frames - once nevents == buffer_size the current state is
flushed as SYN_REPORT 1 frame. Then, if any more events are pending
those are flushed as SYN_REPORT 0 frame. In the case of exactly 8
events, the second frame is never present, so we cannot easily detect if
another one is coming.

Issue #1145 only affects us in the touchpad code, the rest of the
backends seem to (so far) be fine. So let's move the discarding of
SYN_REPORT 1 to the touchpad backend and leave the rest of the code
as-is.

This effectively
Reverts: 7140f13d82 ("evdev: track KEY_SYSRQ frames and pass them even as repeat frames")
Reverts: 9a9466b6a9 ("evdev: discard any frame with EV_SYN SYN_REPORT 1")

Closes #1165

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1282>
2025-07-31 00:50:30 +00:00
Peter Hutterer
73103a5c38 plugin: always obfuscate keycodes
Same approach as chosen in libinput-record, this leaves the F1-F10 out
but otherwise prints every other "normal" key (including modifiers) as
KEY_A.

In the future we may need some more specific approach but for now this
will do. For the use-cases where we do need some specific approach,
libinput record and libinput debug-events will still show the full
keycode on request anyway.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1276>
2025-07-21 13:02:43 +10:00
Peter Hutterer
7140f13d82 evdev: track KEY_SYSRQ frames and pass them even as repeat frames
Alt+Printscreen aka KEY_LEFTALT + KEY_SYSRQ is emulated by the kernel
and always posted with SYN_REPORT 1, see
drivers/tty/sysrq.c:sysrq_reinject_alt_sysrq()

The actual sequence when pressing Alt + Printscreen is to release Alt
first, then press it again:
- evdev:
    - [ 10, 674010,   1,  56,       0] # EV_KEY / KEY_LEFTALT               0
    - [ 10, 674010,   0,   0,       0] # ------------ SYN_REPORT (0) ---------- +2861ms
  - evdev:
    - [ 10, 674030,   1,  56,       1] # EV_KEY / KEY_LEFTALT               1
    - [ 10, 674030,   1,  99,       1] # EV_KEY / KEY_SYSRQ                 1
    - [ 10, 674030,   0,   0,       1] # ------------ SYN_REPORT (1) ---------- +0ms
  - evdev:
    - [ 10, 674031,   1,  99,       0] # EV_KEY / KEY_SYSRQ                 0
    - [ 10, 674031,   1,  56,       0] # EV_KEY / KEY_LEFTALT               0
    - [ 10, 674031,   0,   0,       1] # ------------ SYN_REPORT (1) ---------- +0ms

Handle that special case so we get our printscreen key to work as
expected anymore.

Fixes: 9a9466b6a9 ("evdev: discard any frame with EV_SYN SYN_REPORT 1")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1273>
2025-07-16 09:36:10 +10:00
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
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
6f6bba9588 test: use __attribute__(cleanup) for the test libinput contexts
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +10:00
Peter Hutterer
2c0c4a6516 Replace strneq() with hardcoded lengths with strstartswith()
Slightly less efficient but easier to read and it's not possible to
accidentally provide the wrong length. Plus it handles null pointers
correctly so get to skip the checks (which weren't needed for strneq()
either, but still).

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1121>
2025-01-20 10:29:47 +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
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
Martin Rys
a191a46a78 Include COMPOSE and KANA keys in tests
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/990>
2024-04-28 23:59:14 +00:00
Peter Hutterer
395d12d634 util: auto-declare the element variable in ARRAY_FOR_EACH
All cases we have in our code base have an otherwise unused variable to
loop through the array. Let's auto-declare this as part of the loop.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-03-09 10:16:07 +10: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
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
ce80e40006 test: move all the _setup() functions into a special section
This way we can loop through them instead of having to add them manually.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-03-23 10:17:52 +10:00
Peter Hutterer
1c8636923b fallback: send key events out immediately upon receiving them
Commit db3b6fe5f7 "fallback: change to handle the state at EV_SYN time"
introduced regressions for two types of event sequences.

One is a kernel bug - some devices/drivers like the asus-wireless send a key
press + release within the same event frame which now cancels out and
disappears into the ether. This should be fixed in the kernel drivers but
there appear to be enough of them that we can't just pretend it's an outlier.

The second issue is a libinput bug. If we get two key events in the same frame
(e.g. shift + A) we update the state correctly but the events are sent in the
order of the event codes. KEY_A sorts before KEY_LEFTSHIFT and our shift + A
becomes A + shift.

Fix this by treating key events as before db3b6fe5f7 - by sending them out
as we get them.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-12-08 10:09:26 +10:00
Peter Hutterer
7b5ca6204b Fix a few things scan-build complains about
Uninitialized variables, potential NULL dereferences, dead assignments and an
unused return value.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-10 10:37:58 +10:00
Peter Hutterer
3108653e0a test: tighten some test cases
Instead of just waiting for events, use a libinput_dispatch() and assume the
event is there when we want it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-06-01 09:52:31 +10:00
Peter Hutterer
96f0140749 test: test absence of scroll events on keyboards
Executes the paths to set invalid scroll methods.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-20 10:35:45 +10:00
Peter Hutterer
50dfd52cd7 test: add a test for keyboard LED updates
Not much we can check for here anyway, but at least we can trigger the code.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-20 10:35:43 +10:00
Peter Hutterer
a9016f7e15 test: remove some untriggered code from the keyboard tests
The second condition was never triggered because we shouldn't get anything but
keyboard events here. Drain the initial event burst and remove the two
skipping conditions that won't happen anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-17 07:53:49 +10:00
Peter Hutterer
5d66edc9f4 test: prefix all test source files with "test-"
They weren't originally prefixed but the various tests were, but now that we
only have one test runner binary anyway, the prefix helps sorting the files
easily within e.g. gcov results.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-16 08:59:00 +10:00
Renamed from test/keyboard.c (Browse further)