Debian Codegraph @

test/litest.h

raw
1 /*
2 * Copyright © 2013 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "config.h"
25
26 #include "litest-config.h"
27
28 #ifndef LITEST_H
29 #define LITEST_H
30
31 #include <libevdev/libevdev-uinput.h>
32 #include <libevdev/libevdev.h>
33 #include <libinput.h>
34 #include <math.h>
35 #include <stdarg.h>
36 #include <stdbool.h>
37
38 #include "libinput-private-config.h"
39 #include "libinput-util.h"
40 #include "litest-runner.h"
41 #include "quirks.h"
42
43 DEFINE_DESTROY_CLEANUP_FUNC(libevdev_uinput);
44
45 #define START_TEST(func_) \
46 static enum litest_runner_result func_(const struct litest_runner_test_env *test_env) { \
47 int _i _unused_ = test_env->rangeval;
48
49 #define END_TEST \
50 return LITEST_PASS; \
51 }
52
53 struct test_device {
54 const char *name;
55 struct litest_test_device *device;
56 } __attribute__((aligned(16)));
57
58 #define TEST_DEVICE(which, ...) \
59 static struct litest_test_device _device; \
60 \
61 static void _setup(void) { \
62 struct litest_device *d = litest_create_device(_device.type); \
63 litest_set_current_device(d); \
64 } \
65 \
66 static const struct test_device _test_device \
67 __attribute__ ((used)) \
68 __attribute__ ((section ("test_device_section"))) = { \
69 #which, &_device \
70 }; \
71 static struct litest_test_device _device = { \
72 .setup = _setup, \
73 .shortname = #which, \
74 .type = which, \
75 __VA_ARGS__ \
76 };
77
78 struct test_collection {
79 const char *name;
80 void (*setup)(void);
81 } __attribute__((aligned(16)));
82
83 #define TEST_COLLECTION(name_) \
84 static void (CONCAT(name_ , __LINE__))(void); \
85 static const struct test_collection CONCAT(_test_collection_, __LINE__) \
86 __attribute__ ((used)) \
87 __attribute__ ((section ("test_collection_section"))) = { \
88 #name_, CONCAT(name_, __LINE__) \
89 }; \
90 static void (CONCAT(name_, __LINE__))(void)
91
92 #define litest_mark_test_start() \
93 litest_checkpoint("==================== BOILERPLATE END. TEST CONTENT STARTING NOW ====================");
94
95 __attribute__((format(printf, 3, 0))) void
96 _litest_checkpoint(const char *func,
97 int line,
98 const char *color,
99 const char *format,
100 ...);
101 #define litest_checkpoint(...) \
102 _litest_checkpoint(__func__, __LINE__, ANSI_GREEN, __VA_ARGS__)
103
104 #define litest_log_group(...) \
105 for (bool i_ = ({ \
106 litest_checkpoint("🭋🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂 %s:%3d 🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🬂🭀", __func__, __LINE__); \
107 litest_checkpoint(" " __VA_ARGS__); true; }); \
108 i_; \
109 i_ = ({litest_checkpoint("🭦🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭 %s:%3d 🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🬭🭛", __func__, __LINE__); \
110 false; }))
111
112 /**
113 * litest itself needs the user_data to store some test-suite-specific
114 * information. Tests must not override this pointer, any data they need
115 * they can hang off the private pointer in this struct.
116 */
117 struct litest_user_data {
118 void *private;
119 };
120
121 void
122 litest_fail_condition(const char *file,
123 int line,
124 const char *func,
125 const char *condition,
126 const char *message,
127 ...);
128 void
129 litest_fail_comparison_int(const char *file,
130 int line,
131 const char *func,
132 const char *operator,
133 int a,
134 int b,
135 const char *astr,
136 const char *bstr);
137 void
138 litest_fail_comparison_double(const char *file,
139 int line,
140 const char *func,
141 const char *operator,
142 double a,
143 double b,
144 const char *astr,
145 const char *bstr);
146 void
147 litest_fail_comparison_ptr(const char *file,
148 int line,
149 const char *func,
150 const char *comparison);
151
152 void
153 litest_fail_comparison_str(const char *file,
154 int line,
155 const char *func,
156 const char *comparison,
157 const char *operator,
158 const char * astr,
159 const char *bstr);
160
161 #define litest_assert(cond) \
162 do { \
163 if (!(cond)) \
164 litest_fail_condition(__FILE__, __LINE__, __func__, \
165 #cond, NULL); \
166 } while(0)
167
168 #define litest_assert_msg(cond, ...) \
169 do { \
170 if (!(cond)) \
171 litest_fail_condition(__FILE__, __LINE__, __func__, \
172 #cond, __VA_ARGS__); \
173 } while(0)
174
175 #define litest_assert_not_reached() \
176 litest_abort_msg("Triggered unreachable code\n")
177
178 #define _litest_abort_msg(file_, line_, func_, ...) do {\
179 litest_fail_condition(file_, line_, func_, \
180 "aborting", __VA_ARGS__); \
181 abort(); \
182 } while (0)
183
184 #define litest_abort_msg(...) \
185 _litest_abort_msg(__FILE__, __LINE__, __func__, __VA_ARGS__)
186
187 #define litest_assert_notnull(cond) \
188 do { \
189 if ((cond) == NULL) \
190 litest_fail_condition(__FILE__, __LINE__, __func__, \
191 #cond " != NULL", "\n"); \
192 } while(0)
193
194 #define litest_assert_comparison_int_(a_, op_, b_) \
195 do { \
196 __typeof__(a_) _a = a_; \
197 __typeof__(b_) _b = b_; \
198 if (trunc(_a) != _a || trunc(_b) != _b) \
199 litest_abort_msg("litest_assert_int_* used for non-integer value\n"); \
200 if (!((_a) op_ (_b))) \
201 litest_fail_comparison_int(__FILE__, __LINE__, __func__,\
202 #op_, _a, _b, \
203 #a_, #b_); \
204 } while(0)
205
206 #define litest_assert_neg_errno_success(a_) \
207 do { \
208 __typeof__(a_) _a = a_; \
209 if (_a < 0) \
210 litest_abort_msg("Unexpected negative errno: %d (%s)", _a, strerror(-_a)); \
211 } while(0);
212
213 #define litest_assert_errno_success(a_) \
214 do { \
215 __typeof__(a_) _a = a_; \
216 __typeof__(a_) _e = errno; \
217 if (_a < 0) \
218 litest_abort_msg("Unexpected errno: %d (%s)", _e, strerror(_e)); \
219 } while(0);
220
221 #define litest_assert_comparison_enum_(a_, op_, b_) \
222 do { \
223 __typeof__(a_) _a = a_; \
224 __typeof__(a_) _b = b_; \
225 if (!((_a) op_ (_b))) \
226 litest_fail_comparison_int(__FILE__, __LINE__, __func__,\
227 #op_, (int)_a, (int)_b, \
228 #a_, #b_); \
229 } while(0)
230
231 #define litest_assert_enum_eq(a_, b_) \
232 litest_assert_comparison_enum_(a_, ==, b_)
233
234 #define litest_assert_enum_ne(a_, b_) \
235 litest_assert_comparison_enum_(a_, !=, b_)
236
237 #define litest_assert_int_eq(a_, b_) \
238 litest_assert_comparison_int_(a_, ==, b_)
239
240 #define litest_assert_int_ne(a_, b_) \
241 litest_assert_comparison_int_(a_, !=, b_)
242
243 #define litest_assert_int_lt(a_, b_) \
244 litest_assert_comparison_int_(a_, <, b_)
245
246 #define litest_assert_int_le(a_, b_) \
247 litest_assert_comparison_int_(a_, <=, b_)
248
249 #define litest_assert_int_ge(a_, b_) \
250 litest_assert_comparison_int_(a_, >=, b_)
251
252 #define litest_assert_int_gt(a_, b_) \
253 litest_assert_comparison_int_(a_, >, b_)
254
255 #define litest_assert_comparison_ptr_(a_, op_, b_) \
256 do { \
257 __typeof__(a_) _a = a_; \
258 __typeof__(b_) _b = b_; \
259 if (!((_a) op_ (_b))) \
260 litest_fail_comparison_ptr(__FILE__, __LINE__, __func__,\
261 #a_ " " #op_ " " #b_); \
262 } while(0)
263
264 #define litest_assert_ptr_eq(a_, b_) \
265 litest_assert_comparison_ptr_(a_, ==, b_)
266
267 #define litest_assert_ptr_ne(a_, b_) \
268 litest_assert_comparison_ptr_(a_, !=, b_)
269
270 #define litest_assert_ptr_null(a_) \
271 litest_assert_comparison_ptr_(a_, ==, NULL)
272
273 #define litest_assert_ptr_notnull(a_) \
274 litest_assert_comparison_ptr_(a_, !=, NULL)
275
276 #define litest_assert_str_eq(a_, b_) \
277 do { \
278 const char *_a = a_; \
279 const char *_b = b_; \
280 if (!streq(_a, _b)) \
281 litest_fail_comparison_str(__FILE__, __LINE__, __func__,\
282 #a_ " == " #b_, \
283 "==", \
284 _a, _b); \
285 } while(0)
286
287 #define litest_assert_str_ne(a_, b_) \
288 do { \
289 const char *_a = a_; \
290 const char *_b = b_; \
291 if (streq(_a, _b)) \
292 litest_fail_comparison_str(__FILE__, __LINE__, __func__,\
293 #a_ " != " #b_, \
294 "!=", \
295 _a, _b); \
296 } while(0)
297
298 #define litest_assert_str_in(needle_, haystack_) \
299 do { \
300 const char *_needle = needle_; \
301 const char *_haystack = haystack_; \
302 if (!strstr(_haystack, _needle)) \
303 litest_fail_comparison_str(__FILE__, __LINE__, __func__,\
304 "'" #needle_ "' in: '" #haystack_ "'", \
305 "in", \
306 _needle, _haystack); \
307 } while(0)
308
309 #define litest_assert_str_not_in(needle_, haystack_) \
310 do { \
311 const char *_needle = needle_; \
312 const char *_haystack = haystack_; \
313 if (strstr(_haystack, _needle)) \
314 litest_fail_comparison_str(__FILE__, __LINE__, __func__,\
315 "'" #needle_ "' not in: '" #haystack_ "'", \
316 "not in", \
317 _needle, _haystack); \
318 } while(0)
319
320 #define LITEST_DEFAULT_EPSILON 0.001
321
322 #define litest_assert_double_eq_epsilon(a_, b_, epsilon_)\
323 do { \
324 __typeof__(a_) _a = a_; \
325 __typeof__(b_) _b = b_; \
326 if (!(fabs((_a) - (_b)) < epsilon_)) \
327 litest_fail_comparison_double(__FILE__, __LINE__, __func__,\
328 "==", _a, _b, \
329 #a_, #b_); \
330 } while(0)
331
332 #define litest_assert_double_ne_epsilon(a_, b_, epsilon_)\
333 do { \
334 __typeof__(a_) _a = a_; \
335 __typeof__(b_) _b = b_; \
336 if (!(fabs((_a) - (_b)) > epsilon_)) \
337 litest_fail_comparison_double(__FILE__, __LINE__, __func__,\
338 "!=", _a, _b, \
339 #a_, #b_); \
340 } while(0)
341
342 #define litest_assert_double_gt_epsilon(a_, b_, epsilon_)\
343 do { \
344 __typeof__(a_) _a = a_; \
345 __typeof__(b_) _b = b_; \
346 if (!(_a - (epsilon_) > _b)) \
347 litest_fail_comparison_double(__FILE__, __LINE__, __func__,\
348 ">", _a, _b, \
349 #a_, #b_); \
350 } while(0)
351
352 #define litest_assert_double_ge_epsilon(a_, b_, epsilon_)\
353 do { \
354 __typeof__(a_) _a = a_; \
355 __typeof__(b_) _b = b_; \
356 if (!(_a > _b || fabs((_a) - (_b)) < epsilon_)) \
357 litest_fail_comparison_double(__FILE__, __LINE__, __func__,\
358 ">=", _a, _b, \
359 #a_, #b_); \
360 } while(0)
361
362 #define litest_assert_double_lt_epsilon(a_, b_, epsilon_)\
363 do { \
364 __typeof__(a_) _a = a_; \
365 __typeof__(b_) _b = b_; \
366 if (!(_a < _b - (epsilon_))) \
367 litest_fail_comparison_double(__FILE__, __LINE__, __func__,\
368 "<", _a, _b, \
369 #a_, #b_); \
370 } while(0)
371
372 #define litest_assert_double_le_epsilon(a_, b_, epsilon_)\
373 do { \
374 __typeof__(a_) _a = a_; \
375 __typeof__(b_) _b = b_; \
376 if (!(_a < _b || fabs((_a) - (_b)) < epsilon_)) \
377 litest_fail_comparison_double(__FILE__, __LINE__, __func__,\
378 "<=", _a, _b, \
379 #a_, #b_); \
380 } while(0)
381
382 #define litest_assert_comparison_double_(a_, op_, b_) \
383 litest_assert_comparison_double_epsilon_(a_, op_, b_, LITEST_DEFAULT_EPSILON)
384
385 #define litest_assert_double_eq(a_, b_)\
386 litest_assert_double_eq_epsilon((a_), (b_), LITEST_DEFAULT_EPSILON)
387
388 #define litest_assert_double_ne(a_, b_)\
389 litest_assert_double_ne_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON)
390
391 #define litest_assert_double_lt(a_, b_)\
392 litest_assert_double_lt_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON)
393
394 #define litest_assert_double_le(a_, b_)\
395 litest_assert_double_le_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON)
396
397 #define litest_assert_double_gt(a_, b_)\
398 litest_assert_double_gt_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON)
399
400 #define litest_assert_double_ge(a_, b_)\
401 litest_assert_double_ge_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON)
402
403 void
404 _litest_assert_strv_substring(char **strv,
405 char *substring,
406 const char *file,
407 const char *func,
408 int line);
409
410 #define litest_assert_strv_substring(strv_, substring_) \
411 _litest_assert_strv_substring(strv_, substring_, __FILE__, __func__, __LINE__)
412
413 void
414 _litest_assert_strv_no_substring(char **strv,
415 char *substring,
416 const char *file,
417 const char *func,
418 int line);
419
420 #define litest_assert_strv_no_substring(strv_, substring_) \
421 _litest_assert_strv_no_substring(strv_, substring_, __FILE__, __func__, __LINE__)
422
423 void
424 litest_backtrace(const char *func);
425
426 enum litest_device_type {
427 LITEST_NO_DEVICE = -1,
428 /* Touchpads and associated devices */
429 LITEST_ACER_HAWAII_TOUCHPAD = -1000,
430 LITEST_GENERIC_USBCOMBO_TOUCHPAD,
431 LITEST_AIPTEK,
432 LITEST_ALPS_3FG,
433 LITEST_ALPS_DUALPOINT,
434 LITEST_ALPS_SEMI_MT,
435 LITEST_APPLETOUCH,
436 LITEST_ATMEL_HOVER,
437 LITEST_BCM5974,
438 LITEST_ELANTECH_TOUCHPAD,
439 LITEST_GENERIC_PRESSUREPAD,
440 LITEST_MAGIC_TRACKPAD,
441 LITEST_SYNAPTICS_CLICKPAD_X220,
442 LITEST_SYNAPTICS_HOVER_SEMI_MT,
443 LITEST_SYNAPTICS_I2C,
444 LITEST_SYNAPTICS_PHANTOMCLICKS,
445 LITEST_SYNAPTICS_PRESSUREPAD,
446 LITEST_SYNAPTICS_RMI4,
447 LITEST_SYNAPTICS_TOPBUTTONPAD,
448 LITEST_SYNAPTICS_TOUCHPAD,
449 LITEST_TOUCHPAD_PALMPRESSURE_ZERO,
450 LITEST_WACOM_INTUOS5_FINGER,
451
452 /* Touchscreens */
453 LITEST_CALIBRATED_TOUCHSCREEN,
454 LITEST_GENERIC_MULTITOUCH_SCREEN,
455 LITEST_GENERIC_SINGLETOUCH,
456 LITEST_MS_SURFACE_COVER,
457 LITEST_MULTITOUCH_FUZZ_SCREEN,
458 LITEST_NEXUS4_TOUCH_SCREEN,
459 LITEST_PROTOCOL_A_SCREEN,
460 LITEST_TOUCHSCREEN_INVALID_RANGE,
461 LITEST_TOUCHSCREEN_MT_TOOL_TYPE,
462 LITEST_WACOM_ISDV4_E6_FINGER,
463
464 /* Pointing devices and keyboards */
465 LITEST_MOUSE,
466 LITEST_MOUSE_PS2,
467 LITEST_KEYBOARD,
468 LITEST_TRACKPOINT,
469 LITEST_ABSINFO_OVERRIDE,
470 LITEST_ACER_HAWAII_KEYBOARD,
471 LITEST_GENERIC_USBCOMBO_KEYBOARD,
472 LITEST_ANKER_MOUSE_KBD,
473 LITEST_APPLE_KEYBOARD,
474 LITEST_CYBORG_RAT,
475 LITEST_HP_WMI_HOTKEYS,
476 LITEST_IGNORED_MOUSE,
477 LITEST_KEYBOARD_ALL_CODES,
478 LITEST_KEYBOARD_BLACKWIDOW,
479 LITEST_KEYBOARD_BLADE_STEALTH,
480 LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH,
481 LITEST_KEYBOARD_LOGITECH_MEDIA_KEYBOARD_ELITE,
482 LITEST_KEYBOARD_QUIRKED,
483 LITEST_LENOVO_SCROLLPOINT,
484 LITEST_LOGITECH_TRACKBALL,
485 LITEST_MAGICMOUSE,
486 LITEST_MOUSE_FORMAT_STRING,
487 LITEST_MOUSE_GLADIUS,
488 LITEST_MOUSE_LOW_DPI,
489 LITEST_MOUSE_ROCCAT,
490 LITEST_MOUSE_VIRTUAL,
491 LITEST_MOUSE_WHEEL_CLICK_ANGLE,
492 LITEST_MOUSE_WHEEL_CLICK_COUNT,
493 LITEST_MOUSE_WHEEL_TILT,
494 LITEST_MOUSE_WHEEL_HIRES_DISABLED,
495 LITEST_MS_NANO_TRANSCEIVER_MOUSE,
496 LITEST_SONY_VAIO_KEYS,
497 LITEST_SYNAPTICS_TRACKPOINT_BUTTONS,
498 LITEST_THINKPAD_EXTRABUTTONS,
499 LITEST_VMWARE_VIRTMOUSE,
500 LITEST_WHEEL_ONLY,
501 LITEST_XEN_VIRTUAL_POINTER,
502
503 /* Switches */
504 LITEST_LID_SWITCH,
505 LITEST_LID_SWITCH_SURFACE3,
506 LITEST_KEYPAD_SLIDE_SWITCH,
507 LITEST_TABLET_MODE_UNRELIABLE,
508
509 /* Special devices */
510 LITEST_DELL_CANVAS_TOTEM,
511 LITEST_DELL_CANVAS_TOTEM_TOUCH,
512 LITEST_GPIO_KEYS,
513 LITEST_YUBIKEY,
514
515 /* Tablets */
516 LITEST_ELAN_TABLET,
517 LITEST_HUION_TABLET,
518 LITEST_HUION_Q620M_DIAL,
519 LITEST_PLOOPY_PAVONIS_STYLUS,
520 LITEST_QEMU_TABLET,
521 LITEST_TABLET_DOUBLEDIAL_PAD,
522 LITEST_TABLET_REL_DIAL_PAD,
523 LITEST_UCLOGIC_TABLET,
524 LITEST_WACOM_BAMBOO_16FG_PEN,
525 LITEST_WACOM_BAMBOO_2FG_FINGER,
526 LITEST_WACOM_BAMBOO_2FG_PAD,
527 LITEST_WACOM_BAMBOO_2FG_PEN,
528 LITEST_WACOM_CALIBRATED_TABLET_PEN,
529 LITEST_WACOM_CINTIQ_12WX_PEN,
530 LITEST_WACOM_CINTIQ_13HDT_FINGER,
531 LITEST_WACOM_CINTIQ_13HDT_PAD,
532 LITEST_WACOM_CINTIQ_13HDT_PEN,
533 LITEST_WACOM_CINTIQ_24HDT_PAD,
534 LITEST_WACOM_CINTIQ_24HD_PEN,
535 LITEST_WACOM_CINTIQ_PRO16_FINGER,
536 LITEST_WACOM_CINTIQ_PRO16_PAD,
537 LITEST_WACOM_CINTIQ_PRO16_PEN,
538 LITEST_WACOM_EKR,
539 LITEST_WACOM_HID4800_PEN,
540 LITEST_WACOM_INTUOS3_PAD,
541 LITEST_WACOM_INTUOS5_PAD,
542 LITEST_WACOM_INTUOS5_PEN,
543 LITEST_WACOM_ISDV4_4200_PEN,
544 LITEST_WACOM_ISDV4_524C_PEN,
545 LITEST_WACOM_ISDV4_E6_PEN,
546 LITEST_WACOM_MOBILESTUDIO_PRO_16_PAD,
547 LITEST_WALTOP,
548 };
549
550 #define LITEST_DEVICELESS -2
551 #define LITEST_DISABLE_DEVICE -1
552 #define LITEST_ANY 0
553 #define LITEST_TOUCHPAD bit(0)
554 #define LITEST_CLICKPAD bit(1)
555 #define LITEST_BUTTON bit(2)
556 #define LITEST_KEYS bit(3)
557 #define LITEST_RELATIVE bit(4)
558 #define LITEST_WHEEL bit(5)
559 #define LITEST_TOUCH bit(6)
560 #define LITEST_SINGLE_TOUCH bit(7)
561 #define LITEST_APPLE_CLICKPAD bit(8)
562 #define LITEST_TOPBUTTONPAD bit(9)
563 #define LITEST_SEMI_MT bit(10)
564 #define LITEST_POINTINGSTICK bit(11)
565 #define LITEST_FAKE_MT bit(12)
566 #define LITEST_ABSOLUTE bit(13)
567 #define LITEST_PROTOCOL_A bit(14)
568 #define LITEST_HOVER bit(15)
569 #define LITEST_ELLIPSE bit(16)
570 #define LITEST_TABLET bit(17)
571 #define LITEST_DISTANCE bit(18)
572 #define LITEST_TOOL_SERIAL bit(19)
573 #define LITEST_TILT bit(20)
574 #define LITEST_TABLET_PAD bit(21)
575 #define LITEST_RING bit(22)
576 #define LITEST_STRIP bit(23)
577 #define LITEST_TRACKBALL bit(24)
578 #define LITEST_LEDS bit(25)
579 #define LITEST_SWITCH bit(26)
580 #define LITEST_IGNORED bit(27)
581 #define LITEST_NO_DEBOUNCE bit(28)
582 #define LITEST_TOOL_MOUSE bit(29)
583 #define LITEST_DIRECT bit(30)
584 #define LITEST_TOTEM bit(31)
585 #define LITEST_FORCED_PROXOUT bit(32)
586 #define LITEST_PRECALIBRATED bit(33)
587 #define LITEST_DIAL bit(34)
588
589 /* this is a semi-mt device, so we keep track of the touches that the tests
590 * send and modify them so that the first touch is always slot 0 and sends
591 * the top-left of the bounding box, the second is always slot 1 and sends
592 * the bottom-right of the bounding box.
593 * Lifting any of two fingers terminates slot 1
594 */
595 struct litest_semi_mt {
596 bool is_semi_mt;
597
598 int tracking_id;
599 /* The actual touches requested by the test for the two slots
600 * in the 0..100 range used by litest */
601 struct {
602 double x, y;
603 } touches[2];
604 };
605
606 struct litest_device {
607 enum litest_device_type which;
608 struct libevdev *evdev;
609 struct libevdev_uinput *uinput;
610 struct libinput *libinput;
611 struct quirks *quirks;
612 bool owns_context;
613 struct libinput_device *libinput_device;
614 struct litest_device_interface *interface;
615
616 struct {
617 struct input_event events[64];
618 size_t nevents;
619 } frame;
620
621 int ntouches_down;
622 int skip_ev_syn;
623 struct litest_semi_mt semi_mt; /** only used for semi-mt device */
624
625 void *private; /* device-specific data */
626 };
627
628 struct axis_replacement {
629 int32_t evcode;
630 double value;
631 };
632
633 /**
634 * Same as litest_axis_set_value but allows for ranges outside 0..100%
635 */
636 static inline void
637 litest_axis_set_value_unchecked(struct axis_replacement *axes, int code, double value)
638 {
639 while (axes->evcode != -1) { /* NOLINT(clang-analyzer-security.ArrayBound) */
640 if (axes->evcode == code) {
641 axes->value = value;
642 return;
643 }
644 axes++;
645 }
646
647 litest_abort_msg("Missing axis code %d\n", code);
648 }
649
650 /**
651 * Takes a value in percent and sets the given axis to that code.
652 */
653 static inline void
654 litest_axis_set_value(struct axis_replacement *axes, int code, double value)
655 {
656 litest_assert_double_ge(value, 0.0);
657 litest_assert_double_le(value, 100.0);
658
659 litest_axis_set_value_unchecked(axes, code, value);
660 }
661
662 struct libinput *
663 litest_create_context(void);
664
665 /* Adds the given plugin dir to the context but does *not* initialize
666 * the plugins */
667 struct libinput *
668 litest_create_context_with_plugindir(const char *plugindir);
669
670 void
671 litest_destroy_context(struct libinput *li);
672 DEFINE_TRIVIAL_CLEANUP_FUNC(struct libinput *, litest_destroy_context);
673
674 #define _litest_context_destroy_ _cleanup_(litest_destroy_contextp)
675
676 void
677 litest_context_set_user_data(struct libinput *li, void *data);
678 void *
679 litest_context_get_user_data(struct libinput *li);
680
681 void
682 litest_disable_log_handler(struct libinput *libinput);
683 void
684 litest_restore_log_handler(struct libinput *libinput);
685 void
686 litest_set_log_handler_bug(struct libinput *libinput);
687
688 struct litest_parameters;
689
690 /**
691 * Create a new set of parameters for a test case.
692 *
693 * This function takes a variable set of arguments in the format
694 * [name, type, count, arg1, arg2, arg3, ..], for example:
695 *
696 * litest_parameter_new("axis", 'u', 2, ABS_X, ABS_Y,
697 * "direction", 's', 4, "north", "south", "east", "west",
698 * NULL);
699 *
700 * Parsing stops at the first null name argument.
701 */
702 struct litest_parameters *
703 _litest_parameters_new(const char *name, ...);
704
705 /* Helper to ensure it's always null-terminated */
706 #define litest_parameters_new(name_, ...) \
707 _litest_parameters_new(name_, __VA_ARGS__, NULL)
708
709 #define litest_with_parameters(params_, ...) \
710 for (struct litest_parameters *params_ = litest_parameters_new(__VA_ARGS__); \
711 params_; \
712 params_ = litest_parameters_unref(params_))
713
714 #define _LITEST_NAMED_I32(v_, n_, ...) (struct litest_named_i32){ .value = v_, .name = n_ }
715 /* Helper to default second argument to stringification of first argument.
716 * This allows for two uses of this macro:
717 * - litest_named_i32(0) expands to { 0, "0" }
718 * - litest_named_i32(0, "zero") expands to (effectively) { 0, "zero" }
719 */
720 #define litest_named_i32(...) _LITEST_NAMED_I32(__VA_ARGS__, #__VA_ARGS__)
721
722 struct litest_named_i32 {
723 int32_t value;
724 const char *name;
725 };
726
727 struct litest_parameters_permutation_value {
728 struct list link;
729 char name[128];
730 const struct multivalue value;
731 };
732
733 /**
734 * Argument for the callback function to litest_parameters_permutations().
735 * This is simple wrapper around a linked list that contains all elements
736 * of the current permutation.
737 */
738 struct litest_parameters_permutation {
739 struct list values; /* struct litest_parameters_permutation_value */
740 };
741
742 /**
743 * Callback function invoked for each permutation of a struct litest_parameters.
744 */
745 typedef int (*litest_parameters_permutation_func_t)(
746 struct litest_parameters_permutation *permutation,
747 void *userdata);
748
749 /**
750 * Permutates the given parameters and calls func for every possible
751 * permutation. If func returns a nonzero status, permutation stops
752 * and that nonzero status is returned to the caller.
753 *
754 * Userdata is passed through as-is.
755 */
756 int
757 litest_parameters_permutations(struct litest_parameters *params,
758 litest_parameters_permutation_func_t func,
759 void *userdata);
760
761 struct litest_parameters *
762 litest_parameters_ref(struct litest_parameters *p);
763
764 struct litest_parameters *
765 litest_parameters_unref(struct litest_parameters *params);
766
767 #define litest_add(func_, ...) \
768 _litest_add(__FILE__, #func_, func_, __VA_ARGS__)
769 #define litest_add_ranged(func_, ...) \
770 _litest_add_ranged(__FILE__, #func_, func_, __VA_ARGS__)
771 #define litest_add_parametrized(func_, ...) \
772 _litest_add_parametrized(__FILE__, #func_, func_, __VA_ARGS__)
773 #define litest_add_for_device(func_, ...) \
774 _litest_add_for_device(__FILE__, #func_, func_, __VA_ARGS__)
775 #define litest_add_ranged_for_device(func_, ...) \
776 _litest_add_ranged_for_device(__FILE__, #func_, func_, __VA_ARGS__)
777 #define litest_add_parametrized_for_device(func_, ...) \
778 _litest_add_parametrized_for_device(__FILE__, #func_, func_, __VA_ARGS__)
779 #define litest_add_no_device(func_) \
780 _litest_add_no_device(__FILE__, #func_, func_)
781 #define litest_add_parametrized_no_device(func_, ...) \
782 _litest_add_parametrized_no_device(__FILE__, #func_, func_, __VA_ARGS__)
783 #define litest_add_ranged_no_device(func_, ...) \
784 _litest_add_ranged_no_device(__FILE__, #func_, func_, __VA_ARGS__)
785 #define litest_add_deviceless(func_) \
786 _litest_add_deviceless(__FILE__, #func_, func_)
787 #define litest_add_parametrized_deviceless(func_, params) \
788 _litest_add_parametrize_deviceless(__FILE__, #func_, func_, params)
789
790 void
791 _litest_add(const char *name,
792 const char *funcname,
793 const void *func,
794 int64_t required_feature,
795 int64_t excluded_feature);
796 void
797 _litest_add_ranged(const char *name,
798 const char *funcname,
799 const void *func,
800 int64_t required,
801 int64_t excluded,
802 const struct range *range);
803 void
804 _litest_add_parametrized(const char *name,
805 const char *funcname,
806 const void *func,
807 int64_t required,
808 int64_t excluded,
809 struct litest_parameters *params);
810 void
811 _litest_add_for_device(const char *name,
812 const char *funcname,
813 const void *func,
814 enum litest_device_type type);
815 void
816 _litest_add_ranged_for_device(const char *name,
817 const char *funcname,
818 const void *func,
819 enum litest_device_type type,
820 const struct range *range);
821 void
822 _litest_add_parametrized_for_device(const char *name,
823 const char *funcname,
824 const void *func,
825 enum litest_device_type type,
826 struct litest_parameters *params);
827 void
828 _litest_add_no_device(const char *name, const char *funcname, const void *func);
829 void
830 _litest_add_parametrized_no_device(const char *name,
831 const char *funcname,
832 const void *func,
833 struct litest_parameters *params);
834 void
835 _litest_add_ranged_no_device(const char *name,
836 const char *funcname,
837 const void *func,
838 const struct range *range);
839 void
840 _litest_add_deviceless(const char *name, const char *funcname, const void *func);
841 void
842 _litest_add_parametrized_deviceless(const char *name,
843 const char *funcname,
844 const void *func,
845 struct litest_parameters *params);
846
847 struct litest_device *
848 litest_create_device(enum litest_device_type which);
849
850 struct litest_device *
851 litest_add_device(struct libinput *libinput, enum litest_device_type which);
852 struct libevdev_uinput *
853 litest_create_uinput_device_from_description(const char *name,
854 const struct input_id *id,
855 const struct input_absinfo *abs,
856 const int *events);
857 struct litest_device *
858 litest_create(enum litest_device_type which,
859 const char *name_override,
860 struct input_id *id_override,
861 const struct input_absinfo *abs_override,
862 const int *events_override);
863
864 struct litest_device *
865 litest_create_device_with_overrides(enum litest_device_type which,
866 const char *name_override,
867 struct input_id *id_override,
868 const struct input_absinfo *abs_override,
869 const int *events_override);
870 struct litest_device *
871 litest_add_device_with_overrides(struct libinput *libinput,
872 enum litest_device_type which,
873 const char *name_override,
874 struct input_id *id_override,
875 const struct input_absinfo *abs_override,
876 const int *events_override);
877
878 struct litest_device *
879 litest_current_device(void);
880
881 void
882 litest_grab_device(struct litest_device *d);
883
884 void
885 litest_ungrab_device(struct litest_device *d);
886
887 void
888 litest_device_destroy(struct litest_device *d);
889
890 DEFINE_DESTROY_CLEANUP_FUNC(litest_device);
891
892 const char *
893 litest_event_type_str(enum libinput_event_type type);
894
895 int
896 _litest_dispatch(struct libinput *li, const char *func, int line);
897
898 #define litest_dispatch(li_) \
899 _litest_dispatch(li_, __func__, __LINE__)
900
901 void
902 litest_event(struct litest_device *t, unsigned int type, unsigned int code, int value);
903
904 void
905 litest_event_unchecked(struct litest_device *d,
906 unsigned int type,
907 unsigned int code,
908 int value);
909
910 int
911 litest_auto_assign_value(struct litest_device *d,
912 const struct input_event *ev,
913 int slot,
914 double x,
915 double y,
916 struct axis_replacement *axes,
917 bool touching);
918 void
919 litest_touch_up(struct litest_device *d, unsigned int slot);
920
921 void
922 litest_touch_move(struct litest_device *d, unsigned int slot, double x, double y);
923
924 void
925 litest_touch_move_extended(struct litest_device *d,
926 unsigned int slot,
927 double x,
928 double y,
929 struct axis_replacement *axes);
930
931 void
932 litest_touch_sequence(struct litest_device *d,
933 unsigned int slot,
934 double x1,
935 double y1,
936 double x2,
937 double y2,
938 int steps);
939
940 void
941 litest_touch_down(struct litest_device *d, unsigned int slot, double x, double y);
942
943 void
944 litest_touch_down_extended(struct litest_device *d,
945 unsigned int slot,
946 double x,
947 double y,
948 struct axis_replacement *axes);
949
950 void
951 litest_touch_move_to(struct litest_device *d,
952 unsigned int slot,
953 double x_from,
954 double y_from,
955 double x_to,
956 double y_to,
957 int steps);
958
959 void
960 litest_touch_move_to_extended(struct litest_device *d,
961 unsigned int slot,
962 double x_from,
963 double y_from,
964 double x_to,
965 double y_to,
966 struct axis_replacement *axes,
967 int steps);
968
969 void
970 litest_touch_move_two_touches(struct litest_device *d,
971 double x0,
972 double y0,
973 double x1,
974 double y1,
975 double dx,
976 double dy,
977 int steps);
978
979 void
980 litest_touch_move_three_touches(struct litest_device *d,
981 double x0,
982 double y0,
983 double x1,
984 double y1,
985 double x2,
986 double y2,
987 double dx,
988 double dy,
989 int steps);
990
991 void
992 litest_tablet_set_tool_type(struct litest_device *d, unsigned int code);
993
994 void
995 litest_tablet_proximity_in(struct litest_device *d,
996 double x,
997 double y,
998 struct axis_replacement *axes);
999
1000 void
1001 litest_tablet_proximity_out(struct litest_device *d);
1002
1003 void
1004 litest_tablet_tip_down(struct litest_device *d,
1005 double x,
1006 double y,
1007 struct axis_replacement *axes);
1008
1009 void
1010 litest_tablet_tip_up(struct litest_device *d,
1011 double x,
1012 double y,
1013 struct axis_replacement *axes);
1014
1015 void
1016 litest_tablet_motion(struct litest_device *d,
1017 double x,
1018 double y,
1019 struct axis_replacement *axes);
1020
1021 void
1022 litest_pad_ring_start(struct litest_device *d, double value);
1023
1024 void
1025 litest_pad_ring_change(struct litest_device *d, double value);
1026
1027 void
1028 litest_pad_ring_end(struct litest_device *d);
1029
1030 void
1031 litest_pad_strip_start(struct litest_device *d, double value);
1032
1033 void
1034 litest_pad_strip_change(struct litest_device *d, double value);
1035
1036 void
1037 litest_pad_strip_end(struct litest_device *d);
1038
1039 void
1040 litest_hover_start(struct litest_device *d, unsigned int slot, double x, double y);
1041
1042 void
1043 litest_hover_end(struct litest_device *d, unsigned int slot);
1044
1045 void
1046 litest_hover_move(struct litest_device *d, unsigned int slot, double x, double y);
1047
1048 void
1049 litest_hover_move_to(struct litest_device *d,
1050 unsigned int slot,
1051 double x_from,
1052 double y_from,
1053 double x_to,
1054 double y_to,
1055 int steps);
1056
1057 void
1058 litest_hover_move_two_touches(struct litest_device *d,
1059 double x0,
1060 double y0,
1061 double x1,
1062 double y1,
1063 double dx,
1064 double dy,
1065 int steps);
1066
1067 void
1068 litest_button_click_debounced(struct litest_device *d,
1069 struct libinput *li,
1070 unsigned int button,
1071 bool is_press);
1072
1073 void
1074 litest_button_click(struct litest_device *d, unsigned int button, bool is_press);
1075
1076 void
1077 litest_button_scroll(struct litest_device *d,
1078 unsigned int button,
1079 double dx,
1080 double dy);
1081 void
1082 litest_button_scroll_locked(struct litest_device *d,
1083 unsigned int button,
1084 double dx,
1085 double dy);
1086
1087 void
1088 litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press);
1089
1090 void
1091 litest_switch_action(struct litest_device *d,
1092 enum libinput_switch sw,
1093 enum libinput_switch_state state);
1094
1095 void
1096 litest_wait_for_event(struct libinput *li);
1097
1098 void
1099 _litest_wait_for_event_of_type(struct libinput *li, const char *func, int lineno, ...);
1100
1101 #define litest_wait_for_event_of_type(li_, ...) \
1102 _litest_wait_for_event_of_type(li_, __func__, __LINE__, __VA_ARGS__, -1)
1103
1104 void
1105 litest_drain_events(struct libinput *li);
1106
1107 void
1108 _litest_drain_events_of_type(struct libinput *li, ...);
1109
1110 #define litest_drain_events_of_type(li_, ...) \
1111 _litest_drain_events_of_type(li_, __VA_ARGS__, -1)
1112
1113 #define litest_assert_event_type(e_, want_) \
1114 _litest_assert_event_type(e_, want_, __func__, __LINE__)
1115 void
1116 _litest_assert_event_type(struct libinput_event *event,
1117 enum libinput_event_type want,
1118 const char *func,
1119 int lineno);
1120
1121 #define litest_assert_event_type_is_one_of(ev_, ...) \
1122 _litest_assert_event_type_is_one_of(ev_, __func__, __LINE__, __VA_ARGS__, -1)
1123 void
1124 _litest_assert_event_type_is_one_of(struct libinput_event *event,
1125 const char *func,
1126 int lineno,
1127 ...);
1128
1129 #define litest_assert_event_type_not_one_of(ev_, ...) \
1130 _litest_assert_event_type_not_one_of(ev_, __func__, __LINE__, __VA_ARGS__, -1)
1131
1132 void
1133 _litest_assert_event_type_not_one_of(struct libinput_event *event,
1134 const char *func,
1135 int lineno,
1136 ...);
1137
1138 #define litest_assert_empty_queue(li_) \
1139 _litest_assert_empty_queue(li_, __func__, __LINE__)
1140
1141 void
1142 _litest_assert_empty_queue(struct libinput *li, const char *func, int line);
1143
1144 void
1145 litest_assert_touch_sequence(struct libinput *li);
1146
1147 void
1148 litest_assert_touch_motion_frame(struct libinput *li);
1149 void
1150 litest_assert_touch_down_frame(struct libinput *li);
1151 void
1152 litest_assert_touch_up_frame(struct libinput *li);
1153 void
1154 litest_assert_touch_cancel(struct libinput *li);
1155
1156 struct libinput_event_pointer *
1157 litest_is_button_event(struct libinput_event *event,
1158 unsigned int button,
1159 enum libinput_button_state state);
1160
1161 struct libinput_event_pointer *
1162 litest_is_axis_event(struct libinput_event *event,
1163 enum libinput_event_type axis_type,
1164 enum libinput_pointer_axis axis,
1165 enum libinput_pointer_axis_source source);
1166
1167 bool
1168 litest_is_high_res_axis_event(struct libinput_event *event);
1169
1170 struct libinput_event_pointer *
1171 litest_is_motion_event(struct libinput_event *event);
1172
1173 struct libinput_event_touch *
1174 litest_is_touch_event(struct libinput_event *event, enum libinput_event_type type);
1175
1176 struct libinput_event_keyboard *
1177 litest_is_keyboard_event(struct libinput_event *event,
1178 unsigned int key,
1179 enum libinput_key_state state);
1180
1181 struct libinput_event_gesture *
1182 litest_is_gesture_event(struct libinput_event *event,
1183 enum libinput_event_type type,
1184 int nfingers);
1185
1186 struct libinput_event_tablet_tool *
1187 litest_is_tablet_event(struct libinput_event *event, enum libinput_event_type type);
1188
1189 struct libinput_event_tablet_pad *
1190 litest_is_pad_button_event(struct libinput_event *event,
1191 unsigned int button,
1192 enum libinput_button_state state);
1193 struct libinput_event_tablet_pad *
1194 litest_is_pad_dial_event(struct libinput_event *event, unsigned int number);
1195 struct libinput_event_tablet_pad *
1196 litest_is_pad_ring_event(struct libinput_event *event,
1197 unsigned int number,
1198 enum libinput_tablet_pad_ring_axis_source source);
1199 struct libinput_event_tablet_pad *
1200 litest_is_pad_strip_event(struct libinput_event *event,
1201 unsigned int number,
1202 enum libinput_tablet_pad_strip_axis_source source);
1203 struct libinput_event_tablet_pad *
1204 litest_is_pad_key_event(struct libinput_event *event,
1205 unsigned int key,
1206 enum libinput_key_state state);
1207
1208 struct libinput_event_switch *
1209 litest_is_switch_event(struct libinput_event *event,
1210 enum libinput_switch sw,
1211 enum libinput_switch_state state);
1212
1213 struct libinput_event_tablet_tool *
1214 litest_is_proximity_event(struct libinput_event *event,
1215 enum libinput_tablet_tool_proximity_state state);
1216
1217 double
1218 litest_event_pointer_get_value(struct libinput_event_pointer *ptrev,
1219 enum libinput_pointer_axis axis);
1220
1221 enum libinput_pointer_axis_source
1222 litest_event_pointer_get_axis_source(struct libinput_event_pointer *event);
1223
1224 #define litest_assert_key_event(li_, key_, state_) \
1225 _litest_assert_key_event(li_, key_, state_, __func__, __LINE__)
1226
1227 void
1228 _litest_assert_key_event(struct libinput *li,
1229 unsigned int key,
1230 enum libinput_key_state state,
1231 const char *func,
1232 int lineno);
1233
1234 #define litest_assert_button_event(li_, button_, state_) \
1235 _litest_assert_button_event(li_, button_, state_, __func__, __LINE__)
1236
1237 void
1238 _litest_assert_button_event(struct libinput *li,
1239 unsigned int button,
1240 enum libinput_button_state state,
1241 const char *func,
1242 int line);
1243
1244 #define litest_assert_switch_event(li_, sw_, state_) \
1245 _litest_assert_switch_event(li_, sw_, state_, __func__, __LINE__)
1246
1247 void
1248 _litest_assert_switch_event(struct libinput *li,
1249 enum libinput_switch sw,
1250 enum libinput_switch_state state,
1251 const char *func,
1252 int lineno);
1253
1254 void
1255 litest_assert_scroll(struct libinput *li,
1256 enum libinput_event_type axis_type,
1257 enum libinput_pointer_axis axis,
1258 int minimum_movement);
1259
1260 void
1261 litest_assert_axis_end_sequence(struct libinput *li,
1262 enum libinput_event_type axis_type,
1263 enum libinput_pointer_axis axis,
1264 enum libinput_pointer_axis_source source);
1265
1266 #define litest_assert_only_typed_events(...) \
1267 _litest_assert_only_typed_events(__VA_ARGS__, __func__, __LINE__)
1268 void
1269 _litest_assert_only_typed_events(struct libinput *li,
1270 enum libinput_event_type type,
1271 const char *func,
1272 int line);
1273
1274 void
1275 litest_assert_only_axis_events(struct libinput *li, enum libinput_event_type axis_type);
1276
1277 void
1278 litest_assert_no_typed_events(struct libinput *li, enum libinput_event_type type);
1279
1280 #define litest_assert_tablet_button_event(li_, button_, state_) \
1281 _litest_assert_tablet_button_event(li_, button_, state_, __func__, __LINE__)
1282
1283 void
1284 _litest_assert_tablet_button_event(struct libinput *li,
1285 unsigned int button,
1286 enum libinput_button_state state,
1287 const char *func,
1288 int lineno);
1289
1290 #define litest_assert_tablet_axis_event(li_) \
1291 _litest_assert_tablet_axis_event(li_, __func__, __LINE__)
1292
1293 void
1294 _litest_assert_tablet_axis_event(struct libinput *li, const char *func, int lineno);
1295
1296 #define litest_assert_tablet_proximity_event(li_, state_) \
1297 _litest_assert_tablet_proximity_event(li_, state_, __func__, __LINE__)
1298
1299 void
1300 _litest_assert_tablet_proximity_event(struct libinput *li,
1301 enum libinput_tablet_tool_proximity_state state,
1302 const char *func,
1303 int lineno);
1304
1305 #define litest_assert_tablet_tip_event(li_, state_) \
1306 _litest_assert_tablet_tip_event(li_, state_, __func__, __LINE__)
1307
1308 void
1309 _litest_assert_tablet_tip_event(struct libinput *li,
1310 enum libinput_tablet_tool_tip_state state,
1311 const char *func,
1312 int lineno);
1313
1314 #define litest_assert_pad_button_event(li_, button_, state_) \
1315 _litest_assert_pad_button_event(li_, button_, state_, __func__, __LINE__)
1316
1317 void
1318 _litest_assert_pad_button_event(struct libinput *li,
1319 unsigned int button,
1320 enum libinput_button_state state,
1321 const char *func,
1322 int lineno);
1323
1324 #define litest_assert_pad_key_event(li_, key_, state_) \
1325 _litest_assert_pad_key_event(li_, key_, state_, __func__, __LINE__)
1326
1327 void
1328 _litest_assert_pad_key_event(struct libinput *li,
1329 unsigned int key,
1330 enum libinput_key_state state,
1331 const char *func,
1332 int lineno);
1333
1334 #define litest_assert_gesture_event(...) \
1335 _litest_assert_gesture_event(__VA_ARGS__, __func__, __LINE__)
1336
1337 void
1338 _litest_assert_gesture_event(struct libinput *li,
1339 enum libinput_event_type type,
1340 int nfingers,
1341 const char *func,
1342 int line);
1343
1344 struct libevdev_uinput *
1345 litest_create_uinput_device(const char *name, struct input_id *id, ...);
1346
1347 struct libevdev_uinput *
1348 litest_create_uinput_abs_device(const char *name,
1349 struct input_id *id,
1350 const struct input_absinfo *abs,
1351 ...);
1352
1353 void
1354 _litest_timeout(struct libinput *li, const char *func, int lineno, int millis);
1355
1356 #define litest_timeout(li_, millis) \
1357 _litest_timeout(li_, __func__, __LINE__, millis)
1358
1359 #define litest_timeout_tap(li_) litest_timeout(li_, 300)
1360 #define litest_timeout_tapndrag(li_) litest_timeout(li_, 520)
1361 #define litest_timeout_debounce(li_) litest_timeout(li_, 30)
1362 #define litest_timeout_softbuttons(li_) litest_timeout(li_, 300)
1363 #define litest_timeout_buttonscroll(li_) litest_timeout(li_, 300)
1364 #define litest_timeout_wheel_scroll(li_) litest_timeout(li_, 600)
1365 #define litest_timeout_edgescroll(li_) litest_timeout(li_, 300)
1366 #define litest_timeout_finger_switch(li_) litest_timeout(li_, 140)
1367 #define litest_timeout_middlebutton(li_) litest_timeout(li_, 70)
1368 #define litest_timeout_dwt_short(li_) litest_timeout(li_, 220)
1369 #define litest_timeout_dwt_long(li_) litest_timeout(li_, 520)
1370 #define litest_timeout_gesture(li_) litest_timeout(li_, 120)
1371 #define litest_timeout_gesture_scroll(li_) litest_timeout(li_, 180)
1372 #define litest_timeout_gesture_hold(li_) litest_timeout(li_, 300)
1373 #define litest_timeout_gesture_quick_hold(li_) litest_timeout(li_, 60)
1374 #define litest_timeout_trackpoint(li_) litest_timeout(li_, 320)
1375 #define litest_timeout_tablet_proxout(li_) litest_timeout(li_, 170)
1376 #define litest_timeout_touch_arbitration(li_) litest_timeout(li_, 100)
1377 #define litest_timeout_hysteresis(li_) litest_timeout(li_, 90)
1378 #define litest_timeout_3fg_drag_or_swipe(li_) litest_timeout(li_, 90)
1379 #define litest_timeout_3fg_drag(li_) litest_timeout(li_, 800)
1380 #define litest_timeout_eraser_button(li_) litest_timeout(li_, 50)
1381
1382 struct litest_logcapture {
1383 char **errors;
1384 char **infos;
1385 char **debugs;
1386 char **bugs;
1387 };
1388
1389 void
1390 litest_logcapture_destroy(struct litest_logcapture *c);
1391
1392 DEFINE_DESTROY_CLEANUP_FUNC(litest_logcapture);
1393
1394 struct litest_logcapture *
1395 litest_logcapture_setup(struct libinput *li);
1396
1397 struct litest_logcapture *
1398 litest_logcapture_remove(struct libinput *li, struct litest_logcapture *capture);
1399
1400 #define litest_with_logcapture(li_, capture_) \
1401 for (struct litest_logcapture *capture_ = litest_logcapture_setup(li_); \
1402 capture_ != NULL; \
1403 capture_ = litest_logcapture_remove(li_, capture_))
1404
1405 void
1406 _litest_assert_logcapture_no_errors(struct litest_logcapture *c,
1407 const char *file,
1408 const char *func,
1409 int lineno);
1410
1411 #define litest_assert_logcapture_no_errors(c_) \
1412 _litest_assert_logcapture_no_errors(c_, __FILE__, __func__, __LINE__)
1413
1414 #define litest_with_event_frame(dev_) \
1415 for (bool _i = ({litest_push_event_frame(dev_); true; }); \
1416 _i; \
1417 ({ litest_pop_event_frame(dev_); _i = false; }))
1418
1419 void
1420 litest_push_event_frame(struct litest_device *dev);
1421
1422 void
1423 litest_pop_event_frame(struct litest_device *dev);
1424
1425 void
1426 litest_filter_event(struct litest_device *dev, unsigned int type, unsigned int code);
1427
1428 void
1429 litest_unfilter_event(struct litest_device *dev, unsigned int type, unsigned int code);
1430 void
1431 litest_semi_mt_touch_down(struct litest_device *d,
1432 struct litest_semi_mt *semi_mt,
1433 unsigned int slot,
1434 double x,
1435 double y);
1436
1437 void
1438 litest_semi_mt_touch_move(struct litest_device *d,
1439 struct litest_semi_mt *semi_mt,
1440 unsigned int slot,
1441 double x,
1442 double y);
1443
1444 void
1445 litest_semi_mt_touch_up(struct litest_device *d,
1446 struct litest_semi_mt *semi_mt,
1447 unsigned int slot);
1448
1449 static inline void
1450 litest_enable_3fg_drag(struct libinput_device *device, unsigned int nfingers)
1451 {
1452 enum libinput_config_3fg_drag_state enabled;
1453
1454 switch (nfingers) {
1455 case 3:
1456 enabled = LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG;
1457 break;
1458 case 4:
1459 enabled = LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG;
1460 break;
1461 default:
1462 litest_abort_msg("Invalid finger count");
1463 break;
1464 }
1465
1466 enum libinput_config_status status =
1467 libinput_device_config_3fg_drag_set_enabled(device, enabled);
1468 litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
1469 }
1470
1471 static inline void
1472 litest_enable_tap(struct libinput_device *device)
1473 {
1474 enum libinput_config_status status, expected;
1475
1476 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1477 status = libinput_device_config_tap_set_enabled(device,
1478 LIBINPUT_CONFIG_TAP_ENABLED);
1479
1480 litest_assert_int_eq(status, expected);
1481 }
1482
1483 static inline void
1484 litest_disable_tap(struct libinput_device *device)
1485 {
1486 enum libinput_config_status status, expected;
1487
1488 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1489 status = libinput_device_config_tap_set_enabled(device,
1490 LIBINPUT_CONFIG_TAP_DISABLED);
1491
1492 litest_assert_int_eq(status, expected);
1493 }
1494
1495 static inline void
1496 litest_set_tap_map(struct libinput_device *device,
1497 enum libinput_config_tap_button_map map)
1498 {
1499 enum libinput_config_status status, expected;
1500
1501 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1502 status = libinput_device_config_tap_set_button_map(device, map);
1503 litest_assert_int_eq(status, expected);
1504 }
1505
1506 static inline void
1507 litest_enable_tap_drag(struct libinput_device *device)
1508 {
1509 enum libinput_config_status status, expected;
1510
1511 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1512 status = libinput_device_config_tap_set_drag_enabled(
1513 device,
1514 LIBINPUT_CONFIG_DRAG_ENABLED);
1515
1516 litest_assert_int_eq(status, expected);
1517 }
1518
1519 static inline void
1520 litest_disable_tap_drag(struct libinput_device *device)
1521 {
1522 enum libinput_config_status status, expected;
1523
1524 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1525 status = libinput_device_config_tap_set_drag_enabled(
1526 device,
1527 LIBINPUT_CONFIG_DRAG_DISABLED);
1528
1529 litest_assert_int_eq(status, expected);
1530 }
1531
1532 static inline bool
1533 litest_has_2fg_scroll(struct litest_device *dev)
1534 {
1535 struct libinput_device *device = dev->libinput_device;
1536
1537 return !!(libinput_device_config_scroll_get_methods(device) &
1538 LIBINPUT_CONFIG_SCROLL_2FG);
1539 }
1540
1541 static inline void
1542 litest_enable_2fg_scroll(struct litest_device *dev)
1543 {
1544 enum libinput_config_status status, expected;
1545 struct libinput_device *device = dev->libinput_device;
1546
1547 status = libinput_device_config_scroll_set_method(device,
1548 LIBINPUT_CONFIG_SCROLL_2FG);
1549
1550 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1551 litest_assert_int_eq(status, expected);
1552
1553 libinput_device_config_scroll_set_natural_scroll_enabled(device, 0);
1554 }
1555
1556 static inline void
1557 litest_enable_edge_scroll(struct litest_device *dev)
1558 {
1559 enum libinput_config_status status, expected;
1560 struct libinput_device *device = dev->libinput_device;
1561
1562 status = libinput_device_config_scroll_set_method(device,
1563 LIBINPUT_CONFIG_SCROLL_EDGE);
1564
1565 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1566 litest_assert_int_eq(status, expected);
1567
1568 libinput_device_config_scroll_set_natural_scroll_enabled(device, 0);
1569 }
1570
1571 static inline bool
1572 litest_has_clickfinger(struct litest_device *dev)
1573 {
1574 struct libinput_device *device = dev->libinput_device;
1575 uint32_t methods = libinput_device_config_click_get_methods(device);
1576
1577 return methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
1578 }
1579
1580 static inline bool
1581 litest_has_btnareas(struct litest_device *dev)
1582 {
1583 struct libinput_device *device = dev->libinput_device;
1584 uint32_t methods = libinput_device_config_click_get_methods(device);
1585
1586 return methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
1587 }
1588
1589 static inline void
1590 litest_enable_clickfinger(struct litest_device *dev)
1591 {
1592 enum libinput_config_status status, expected;
1593 struct libinput_device *device = dev->libinput_device;
1594
1595 status = libinput_device_config_click_set_method(
1596 device,
1597 LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
1598 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1599 litest_assert_int_eq(status, expected);
1600 }
1601
1602 static inline void
1603 litest_set_clickfinger_map(struct litest_device *dev,
1604 enum libinput_config_clickfinger_button_map map)
1605 {
1606 enum libinput_config_status status, expected;
1607 struct libinput_device *device = dev->libinput_device;
1608
1609 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1610 status = libinput_device_config_click_set_clickfinger_button_map(device, map);
1611 litest_assert_int_eq(status, expected);
1612 }
1613
1614 static inline void
1615 litest_enable_buttonareas(struct litest_device *dev)
1616 {
1617 enum libinput_config_status status, expected;
1618 struct libinput_device *device = dev->libinput_device;
1619
1620 status = libinput_device_config_click_set_method(
1621 device,
1622 LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
1623 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1624 litest_assert_int_eq(status, expected);
1625 }
1626
1627 static inline void
1628 litest_enable_drag_lock_sticky(struct libinput_device *device)
1629 {
1630 enum libinput_config_status status, expected;
1631
1632 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1633 status = libinput_device_config_tap_set_drag_lock_enabled(
1634 device,
1635 LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY);
1636
1637 litest_assert_int_eq(status, expected);
1638 }
1639
1640 static inline void
1641 litest_enable_drag_lock(struct libinput_device *device)
1642 {
1643 enum libinput_config_status status, expected;
1644
1645 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1646 status = libinput_device_config_tap_set_drag_lock_enabled(
1647 device,
1648 LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT);
1649
1650 litest_assert_int_eq(status, expected);
1651 }
1652
1653 static inline void
1654 litest_disable_drag_lock(struct libinput_device *device)
1655 {
1656 enum libinput_config_status status, expected;
1657
1658 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1659 status = libinput_device_config_tap_set_drag_lock_enabled(
1660 device,
1661 LIBINPUT_CONFIG_DRAG_LOCK_DISABLED);
1662
1663 litest_assert_int_eq(status, expected);
1664 }
1665
1666 static inline void
1667 litest_enable_middleemu(struct litest_device *dev)
1668 {
1669 struct libinput_device *device = dev->libinput_device;
1670 enum libinput_config_status status, expected;
1671
1672 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1673 status = libinput_device_config_middle_emulation_set_enabled(
1674 device,
1675 LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED);
1676
1677 litest_assert_int_eq(status, expected);
1678 }
1679
1680 static inline void
1681 litest_disable_middleemu(struct litest_device *dev)
1682 {
1683 struct libinput_device *device = dev->libinput_device;
1684 enum libinput_config_status status, expected;
1685
1686 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1687 status = libinput_device_config_middle_emulation_set_enabled(
1688 device,
1689 LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED);
1690
1691 litest_assert_int_eq(status, expected);
1692 }
1693
1694 static inline void
1695 litest_sendevents_off(struct litest_device *dev)
1696 {
1697 struct libinput_device *device = dev->libinput_device;
1698 enum libinput_config_status status, expected;
1699
1700 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1701 status = libinput_device_config_send_events_set_mode(
1702 device,
1703 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
1704 litest_assert_int_eq(status, expected);
1705 }
1706
1707 static inline void
1708 litest_sendevents_on(struct litest_device *dev)
1709 {
1710 struct libinput_device *device = dev->libinput_device;
1711 enum libinput_config_status status, expected;
1712
1713 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1714 status = libinput_device_config_send_events_set_mode(
1715 device,
1716 LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
1717 litest_assert_int_eq(status, expected);
1718 }
1719
1720 static inline void
1721 litest_sendevents_ext_mouse(struct litest_device *dev)
1722 {
1723 struct libinput_device *device = dev->libinput_device;
1724 enum libinput_config_status status, expected;
1725
1726 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1727 status = libinput_device_config_send_events_set_mode(
1728 device,
1729 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE);
1730 litest_assert_int_eq(status, expected);
1731 }
1732
1733 static inline void
1734 litest_enable_hold_gestures(struct libinput_device *device)
1735 {
1736 enum libinput_config_status status, expected;
1737
1738 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1739 status = libinput_device_config_gesture_set_hold_enabled(
1740 device,
1741 LIBINPUT_CONFIG_HOLD_ENABLED);
1742
1743 litest_assert_int_eq(status, expected);
1744 }
1745
1746 static inline void
1747 litest_disable_hold_gestures(struct libinput_device *device)
1748 {
1749 enum libinput_config_status status, expected;
1750
1751 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1752 status = libinput_device_config_gesture_set_hold_enabled(
1753 device,
1754 LIBINPUT_CONFIG_HOLD_DISABLED);
1755
1756 litest_assert_int_eq(status, expected);
1757 }
1758
1759 static inline bool
1760 litest_touchpad_is_external(struct litest_device *dev)
1761 {
1762 struct udev_device *udev_device;
1763 const char *prop;
1764 bool is_external;
1765
1766 if (libinput_device_get_id_vendor(dev->libinput_device) == VENDOR_ID_WACOM)
1767 return true;
1768
1769 udev_device = libinput_device_get_udev_device(dev->libinput_device);
1770 prop = udev_device_get_property_value(udev_device,
1771 "ID_INPUT_TOUCHPAD_INTEGRATION");
1772 is_external = prop && streq(prop, "external");
1773 udev_device_unref(udev_device);
1774
1775 return is_external;
1776 }
1777
1778 static inline int
1779 litest_send_file(int sock, int fd)
1780 {
1781 char buf[40960];
1782 int n = read(fd, buf, 40960);
1783 litest_assert_int_gt(n, 0);
1784 return write(sock, buf, n);
1785 }
1786
1787 static inline int
1788 litest_slot_count(struct litest_device *dev)
1789 {
1790 if (dev->which == LITEST_ALPS_3FG)
1791 return 2;
1792
1793 return libevdev_get_num_slots(dev->evdev);
1794 }
1795
1796 static inline bool
1797 litest_has_palm_detect_size(struct litest_device *dev)
1798 {
1799 double width, height;
1800 unsigned int vendor;
1801 unsigned int bustype;
1802 int rc;
1803
1804 vendor = libinput_device_get_id_vendor(dev->libinput_device);
1805 bustype = libevdev_get_id_bustype(dev->evdev);
1806 if (vendor == VENDOR_ID_WACOM)
1807 return 0;
1808 if (bustype == BUS_BLUETOOTH)
1809 return 0;
1810 if (vendor == VENDOR_ID_APPLE)
1811 return 0;
1812
1813 rc = libinput_device_get_size(dev->libinput_device, &width, &height);
1814
1815 return rc == 0 && width >= 70;
1816 }
1817
1818 #endif /* LITEST_H */