Commit graph

5362 commits

Author SHA1 Message Date
Peter Hutterer
d5e2bb1267 util: use cleanup in the event printing helpers
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +10:00
Peter Hutterer
bbbe757a26 Define a set of cleanup helpers
These are all data structs that are used in libinput and the tests,
let's declare them in a shared header so we can use them everywhere.

For udev and libevdev let's use an ifdef check for a known #define
so we don't have to add those deps everywhere.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +10:00
Peter Hutterer
ae423bc3fe util: define a cleanup for stringbuf
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +10:00
Peter Hutterer
829aec8055 util: add a list helper for handing a pointer to a list
Effectively a combination of list_append() and steal.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +10:00
Peter Hutterer
76c87d2486 util: add various helper functions to use __attribute__(cleanup)
Taken from libei, with slight modifications. The general approach is:
basic data types use _autofoo_ to call the maching foo function on
cleanup. Struct types use _unref_, _destory_, _free_, whichever applies
to that struct.

Notably: attribute syntax depends on where it's declared [1] so in the
following examles only a, b, and d have the autofree attribute:
   _autofree_ char *a, *b;
   char *c, _autofree *d;

Simplest way to ensure it's all correct to keep the declarations one per
line.

[1] https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
2025-04-16 17:04:58 +10:00
Peter Hutterer
436eb42044 CI: check for empty lines between closing braces
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1190>
2025-04-16 11:44:09 +10:00
Peter Hutterer
546debe926 Remove empty lines between closing braces
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1190>
2025-04-16 11:44:09 +10:00
Peter Hutterer
265cacb246 test: properly batch litest events
If we push/pop event frames and combine various functions we might end
up sending the same value in the same frame multiple times. This
*should* be fine with libinput but is different to what the kernel does
in that case and harder to debug.

Let's batch any litest_event() until an EV_SYN arrives, then write them
all to libinput in one go.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1187>
2025-04-15 05:06:53 +00:00
Peter Hutterer
c96ed7f6b8 test: convert push/pop event frames to with_event_frame
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1187>
2025-04-15 05:06:53 +00:00
Peter Hutterer
550ffc1160 test: combine two REL_WHEEL_HI_RES events into one
This would be a kernel bug to send wheel events like this so let's not
test it this way.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1187>
2025-04-15 05:06:53 +00:00
Peter Hutterer
42c685dbb0 test: fix missing SYN_REPORT events between events
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1187>
2025-04-15 05:06:53 +00:00
Peter Hutterer
95406b2182 test: print the full test result in the list of failed tests
When running several tests simply having the list of failed test names
is not very convenient. The actual error may be thousands of lines north
and worse, meson only prints the last 100 lines of a test log by default.

So let's print the full test data including backtrace etc. at the end
instead.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1189>
2025-04-15 14:05:21 +10:00
Peter Hutterer
6720c6899f test: annotate/shorten a test case
This test has a tendency to fail during recent development, let's make
it easier to debug.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:09:43 +10:00
Peter Hutterer
610cad7e82 test: disable the proximity timer for the touch arbitration test
Depending on race conditions we may get a proximity out event while
testing the touch arbitration timeout.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:09:39 +10:00
Peter Hutterer
8770c74394 test: mark a checkpoint when asserting a tip or button event
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:09:34 +10:00
Peter Hutterer
8c28783dd2 test: add litest_with_event_frame() to make things easier to visualize
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:09:27 +10:00
Peter Hutterer
c94276fd14 test: improve the direct tool switch test
Use better (newer) helpers and separate the pen/eraser for readability.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:09:18 +10:00
Peter Hutterer
d74b2adde5 test: indentation fixes
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:09:08 +10:00
Peter Hutterer
190b796794 test: modernize a test slightly
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:08:30 +10:00
Peter Hutterer
0e3bb4690a test: switch some xasprintf to strdup_printf()
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:07:24 +10:00
Peter Hutterer
589850e8df test: correct the libevdev initialization in two tests
These are used to create a new struct libevdev so let's not wrongly
initialize them to an existing struct.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:07:24 +10:00
Peter Hutterer
c59453e4ab test: remove a race condition
If the host is a tad slow we need to wait for the events instead of
assuming they're already waiting for us.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1186>
2025-04-15 11:07:24 +10:00
Subhaditya Nath
2ebb6d4a75 zsh: add missing backslash
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1183>
2025-04-07 18:13:17 +00:00
Peter Hutterer
ecd4ea3053 util: add a wrapper for the C23 auto keyword
C23 auto is basically __auto_type so let's wrap it if our compiler
doesn't provide it (yet).

This lets us use `auto` as type specifier, e.g. compare
   enum libinput_config_status status = libinput_device_config_set(...)
   auto status = libinput_device_config_set(...)

Note that as of now meson will never detect this as it requires -std=c23
to be passed to the compiler. This flag is only supported by Clang 18
(released 2024) and we don't want to break things for older compilers
for what is a bit of a niche feature right now.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1181>
2025-04-07 09:00:42 +00:00
Peter Hutterer
bf67c056df CI: replace the scan-build job with a clang-tidy job
Drop the scanbuild wrappers, especially the junit conversion script
which's results haven't been looked at for ages.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1182>
2025-04-07 08:43:36 +00:00
Peter Hutterer
6876d71a4d Add a clang-tidy file
This gives us the ninja clang-tidy command. clang-tidy replaces
scan-build and is more featureful (and picky).

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1182>
2025-04-07 08:43:36 +00:00
tokyo4j
cc0889bf2b gestures: fix acceleration in 3fg drag
Before this patch, tp_filter_motion() was called twice in pointer motion
handler during 3fg drag, causing the pointer speed to be much faster
than during 1fg motion when the acceleration profile is adaptive.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1180>
2025-04-05 12:16:25 +09:00
Peter Hutterer
e9f3fc080c tablet: revamp the tablet pressure range handling
Commit 48cd4c7287 ("tablet: track pressure ranges per tablet") added
tracking of pressure ranges per tablet by storing ranges for multiple
(up to 4) tablets in the tool. This doesn't scale well, had the
disadvantage of the range only being updated on out-of-proximity, and is
the wrong approach anyway.

Turns out we can update the pressure range on proximity in since we
haven't processed the pressure values yet at that stage. This gives us
better behavior when switching between tablet devices (including unplug)
as the pen will only lag behind once (when setting the range) instead
of once per new tablet.

However, since the offset (which is a tool issue) applies on top of the
pressure range (which is a tablet property) this requires that we now
track the offset as percent of the range.

So on proximity in we apply the new tablet range, then apply the e.g. 5%
pressure offset within this range.

This means we no longer have to track multiple tablets since it'll just
apply on the current tablet when in proximity.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1172>
2025-04-04 22:44:29 +00:00
Peter Hutterer
63a8ad2ead util: add some extra strv helpers
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1178>
2025-04-04 22:19:47 +00:00
Peter Hutterer
5c751491fa Add a few missing includes for config.h
This caused the headers to not haved _GNU_SOURCE set which in turn
caused clang-tidy to complain because util-strings.h didn't have
strtod_l.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
df8726b405 udev: remove accidentally-checked in file
Accidentally added in e7a9c07ffe but never hooked up to meson so it
never got built. And if it did it'd have failed.

Fixes: e7a9c07ffe ("udev: parse the EVDEV_ABS properties for a potential fuzz setting")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
e316e7c4b0 tools: disable clang-tidy warning about using floats for loop counters
Really doesn't matter here.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
6770131e94 util: fix a memleak in mkdir_p
In the error case path would leak.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
051ac26a20 util: shut up clang-tidy about our use of strcat
These are pre-counted strings, we're fine.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
0fc52abd79 util: change the builddir_lookup() to return a boolean
All but one callers of this function only care about yes/no, so let's
change it to only return the build dir in the one case it's needed.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
d8482a2540 util: use a late declaration to avoid one ifdef
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
a92d635af1 test: rename test-util-includes.c to .c.in
This way it doesn't get picked up by static analysis tools which are
then unhappy about the @FILE@ placeholder

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
097e947523 tools: add missing include
struct option is used in one of the static inlines here, so let's
include getopt.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
f123da174e Add a few 0 enum values to shut up clang-tidy
These are all internal API so having a NONE value means we can shut up
warnings about 0 not being an enum value without having those exposed in
our public API.

And they slightly improve readability in the callers anyway.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1175>
2025-04-04 15:47:23 +00:00
Peter Hutterer
a55dd604e1 util: add a newtype macro
In a valiant approach to introduce some type-safety (after spending time
debugging a int vs double confusion) this adds a DECLARE_NEWTYPE()
macro that declares a named struct with a single typed value field.

This is basically the C version of Rusts "struct Foo(u32)" with
a few accessors auto-generated by the macro.

C is happy to silently convert between base types but it doesn't do
so for structs so this allows us to have some type safety
when we accidentally assign two incompatible fields to each other (e.g.
an axis value in device units vs a percentage value).

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1171>
2025-04-04 11:05:20 +00:00
Peter Hutterer
000d9282cd test: split litest's main() into a separate file
Instead of having this ifdef'd out split the main and directly
associated functions out into a separate file.

That ifdef used to exist so we can use parts of litest in some other
files (the selftest and the utils test). Those tests care mostly
about the assertion helpers so long-term a split into
assert helpers and "rest of litest" would be better. For now, this will
do.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1174>
2025-04-04 06:28:07 +00:00
Peter Hutterer
bbd9df60de test: use the local variable for njobs, not the global one
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1174>
2025-04-04 06:28:07 +00: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
734ffea934 test: use a single litest_timeout function only
This can be easily wrapped with a macro that passes in the millis to
time out for.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1169>
2025-04-04 05:13:00 +00:00
Peter Hutterer
b43abaeacb test: allow passing func/line up from litest_abort_msg()
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1169>
2025-04-04 05:13:00 +00:00
Peter Hutterer
90dafb33b4 test: print drained events when draining typed events
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1169>
2025-04-04 05:13:00 +00:00
Peter Hutterer
b3471a960e test: add missing proximity timeouts to the tablet tests
A bunch of tests that left proximity but didn't wait for the proximity
timeout.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1169>
2025-04-04 05:13:00 +00:00
Peter Hutterer
7a9f4f1c38 test: switch to litest_dispatch()
litest_dispatch() was added in 86c47be816, the rectangle tests spawn
from the same time but didn't get updated before merging.

Fixes: 86c47be816 ("test: add litest_dispatch() for better test debugging")
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1169>
2025-04-04 05:13:00 +00:00
Peter Hutterer
978871c450 test: abort litest_wait_for_events() if we don't get events after 2s
Previously we kept polling but this just delays what will almost
certainly be a failure anyway - none of our tests require even 2000ms
for an event to arrive.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1169>
2025-04-04 05:13:00 +00:00
Peter Hutterer
35b223aa8e test: fix wacom test devices to use pressure 0 on proximity out
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1169>
2025-04-04 05:13:00 +00:00