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#include "litest-config.h" 26 27#ifndef LITEST_H 28#define LITEST_H 29 30#include <stdbool.h> 31#include <stdarg.h> 32#include <check.h> 33#include <libevdev/libevdev.h> 34#include <libevdev/libevdev-uinput.h> 35#include <libinput.h> 36#include <math.h> 37 38#ifndef ck_assert_notnull 39#define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL) 40#endif 41 42#include "check-double-macros.h" 43 44#include "libinput-private-config.h" 45#include "libinput-util.h" 46#include "quirks.h" 47 48struct test_device { 49 const char *name; 50 struct litest_test_device *device; 51} __attribute__((aligned(16))); 52 53#define TEST_DEVICE(name, ...) \ 54 static struct litest_test_device _device; \ 55 \ 56 static void _setup(void) { \ 57 struct litest_device *d = litest_create_device(_device.type); \ 58 litest_set_current_device(d); \ 59 } \ 60 \ 61 static const struct test_device _test_device \ 62 __attribute__ ((used)) \ 63 __attribute__ ((section ("test_section"))) = { \ 64 name, &_device \ 65 }; \ 66 static struct litest_test_device _device = { \ 67 .setup = _setup, \ 68 .shortname = name, \ 69 __VA_ARGS__ \ 70 }; 71 72struct test_collection { 73 const char *name; 74 void (*setup)(void); 75} __attribute__((aligned(16))); 76 77#define TEST_COLLECTION(name) \ 78 static void (name##_setup)(void); \ 79 static const struct test_collection _test_collection \ 80 __attribute__ ((used)) \ 81 __attribute__ ((section ("test_collection_section"))) = { \ 82 #name, name##_setup \ 83 }; \ 84 static void (name##_setup)(void) 85 86 87/** 88 * litest itself needs the user_data to store some test-suite-specific 89 * information. Tests must not override this pointer, any data they need 90 * they can hang off the private pointer in this struct. 91 */ 92struct litest_user_data { 93 void *private; 94}; 95 96void 97litest_fail_condition(const char *file, 98 int line, 99 const char *func, 100 const char *condition, 101 const char *message, 102 ...); 103void 104litest_fail_comparison_int(const char *file, 105 int line, 106 const char *func, 107 const char *operator, 108 int a, 109 int b, 110 const char *astr, 111 const char *bstr); 112void 113litest_fail_comparison_double(const char *file, 114 int line, 115 const char *func, 116 const char *operator, 117 double a, 118 double b, 119 const char *astr, 120 const char *bstr); 121void 122litest_fail_comparison_ptr(const char *file, 123 int line, 124 const char *func, 125 const char *comparison); 126 127#define litest_assert(cond) \ 128 do { \ 129 if (!(cond)) \ 130 litest_fail_condition(__FILE__, __LINE__, __func__, \ 131 #cond, NULL); \ 132 } while(0) 133 134#define litest_assert_msg(cond, ...) \ 135 do { \ 136 if (!(cond)) \ 137 litest_fail_condition(__FILE__, __LINE__, __func__, \ 138 #cond, __VA_ARGS__); \ 139 } while(0) 140 141#define litest_abort_msg(...) \ 142 litest_fail_condition(__FILE__, __LINE__, __func__, \ 143 "aborting", __VA_ARGS__); \ 144 145#define litest_assert_notnull(cond) \ 146 do { \ 147 if ((cond) == NULL) \ 148 litest_fail_condition(__FILE__, __LINE__, __func__, \ 149 #cond, " expected to be not NULL\n"); \ 150 } while(0) 151 152#define litest_assert_comparison_int_(a_, op_, b_) \ 153 do { \ 154 __typeof__(a_) _a = a_; \ 155 __typeof__(b_) _b = b_; \ 156 if (trunc(_a) != _a || trunc(_b) != _b) \ 157 litest_abort_msg("litest_assert_int_* used for non-integer value\n"); \ 158 if (!((_a) op_ (_b))) \ 159 litest_fail_comparison_int(__FILE__, __LINE__, __func__,\ 160 #op_, _a, _b, \ 161 #a_, #b_); \ 162 } while(0) 163 164#define litest_assert_int_eq(a_, b_) \ 165 litest_assert_comparison_int_(a_, ==, b_) 166 167#define litest_assert_int_ne(a_, b_) \ 168 litest_assert_comparison_int_(a_, !=, b_) 169 170#define litest_assert_int_lt(a_, b_) \ 171 litest_assert_comparison_int_(a_, <, b_) 172 173#define litest_assert_int_le(a_, b_) \ 174 litest_assert_comparison_int_(a_, <=, b_) 175 176#define litest_assert_int_ge(a_, b_) \ 177 litest_assert_comparison_int_(a_, >=, b_) 178 179#define litest_assert_int_gt(a_, b_) \ 180 litest_assert_comparison_int_(a_, >, b_) 181 182#define litest_assert_comparison_ptr_(a_, op_, b_) \ 183 do { \ 184 __typeof__(a_) _a = a_; \ 185 __typeof__(b_) _b = b_; \ 186 if (!((_a) op_ (_b))) \ 187 litest_fail_comparison_ptr(__FILE__, __LINE__, __func__,\ 188 #a_ " " #op_ " " #b_); \ 189 } while(0) 190 191#define litest_assert_comparison_double_(a_, op_, b_) \ 192 do { \ 193 const double EPSILON = 1.0/256; \ 194 __typeof__(a_) _a = a_; \ 195 __typeof__(b_) _b = b_; \ 196 if (!((_a) op_ (_b)) && fabs((_a) - (_b)) > EPSILON) \ 197 litest_fail_comparison_double(__FILE__, __LINE__, __func__,\ 198 #op_, _a, _b, \ 199 #a_, #b_); \ 200 } while(0) 201 202#define litest_assert_ptr_eq(a_, b_) \ 203 litest_assert_comparison_ptr_(a_, ==, b_) 204 205#define litest_assert_ptr_ne(a_, b_) \ 206 litest_assert_comparison_ptr_(a_, !=, b_) 207 208#define litest_assert_ptr_null(a_) \ 209 litest_assert_comparison_ptr_(a_, ==, NULL) 210 211#define litest_assert_ptr_notnull(a_) \ 212 litest_assert_comparison_ptr_(a_, !=, NULL) 213 214#define litest_assert_double_eq(a_, b_)\ 215 litest_assert_comparison_double_((a_), ==, (b_)) 216 217#define litest_assert_double_ne(a_, b_)\ 218 litest_assert_comparison_double_((a_), !=, (b_)) 219 220#define litest_assert_double_lt(a_, b_)\ 221 litest_assert_comparison_double_((a_), <, (b_)) 222 223#define litest_assert_double_le(a_, b_)\ 224 litest_assert_comparison_double_((a_), <=, (b_)) 225 226#define litest_assert_double_gt(a_, b_)\ 227 litest_assert_comparison_double_((a_), >, (b_)) 228 229#define litest_assert_double_ge(a_, b_)\ 230 litest_assert_comparison_double_((a_), >=, (b_)) 231 232enum litest_device_type { 233 LITEST_NO_DEVICE = -1, 234 /* Touchpads and associated devices */ 235 LITEST_ACER_HAWAII_TOUCHPAD = -1000, 236 LITEST_AIPTEK, 237 LITEST_ALPS_3FG, 238 LITEST_ALPS_DUALPOINT, 239 LITEST_ALPS_SEMI_MT, 240 LITEST_APPLETOUCH, 241 LITEST_ATMEL_HOVER, 242 LITEST_BCM5974, 243 LITEST_ELANTECH_TOUCHPAD, 244 LITEST_GENERIC_PRESSUREPAD, 245 LITEST_MAGIC_TRACKPAD, 246 LITEST_SYNAPTICS_CLICKPAD_X220, 247 LITEST_SYNAPTICS_HOVER_SEMI_MT, 248 LITEST_SYNAPTICS_I2C, 249 LITEST_SYNAPTICS_PHANTOMCLICKS, 250 LITEST_SYNAPTICS_PRESSUREPAD, 251 LITEST_SYNAPTICS_RMI4, 252 LITEST_SYNAPTICS_TOPBUTTONPAD, 253 LITEST_SYNAPTICS_TOUCHPAD, 254 LITEST_TOUCHPAD_PALMPRESSURE_ZERO, 255 LITEST_WACOM_FINGER, 256 257 /* Touchscreens */ 258 LITEST_CALIBRATED_TOUCHSCREEN, 259 LITEST_GENERIC_MULTITOUCH_SCREEN, 260 LITEST_GENERIC_SINGLETOUCH, 261 LITEST_MS_SURFACE_COVER, 262 LITEST_MULTITOUCH_FUZZ_SCREEN, 263 LITEST_NEXUS4_TOUCH_SCREEN, 264 LITEST_PROTOCOL_A_SCREEN, 265 LITEST_TOUCHSCREEN_INVALID_RANGE, 266 LITEST_TOUCHSCREEN_MT_TOOL_TYPE, 267 LITEST_WACOM_TOUCH, 268 269 /* Pointing devices and keyboards */ 270 LITEST_MOUSE, 271 LITEST_KEYBOARD, 272 LITEST_TRACKPOINT, 273 LITEST_ABSINFO_OVERRIDE, 274 LITEST_ACER_HAWAII_KEYBOARD, 275 LITEST_ANKER_MOUSE_KBD, 276 LITEST_APPLE_KEYBOARD, 277 LITEST_CYBORG_RAT, 278 LITEST_HP_WMI_HOTKEYS, 279 LITEST_IGNORED_MOUSE, 280 LITEST_KEYBOARD_ALL_CODES, 281 LITEST_KEYBOARD_BLACKWIDOW, 282 LITEST_KEYBOARD_BLADE_STEALTH, 283 LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH, 284 LITEST_KEYBOARD_LOGITECH_MEDIA_KEYBOARD_ELITE, 285 LITEST_KEYBOARD_QUIRKED, 286 LITEST_LENOVO_SCROLLPOINT, 287 LITEST_LOGITECH_TRACKBALL, 288 LITEST_MAGICMOUSE, 289 LITEST_MOUSE_FORMAT_STRING, 290 LITEST_MOUSE_GLADIUS, 291 LITEST_MOUSE_LOW_DPI, 292 LITEST_MOUSE_ROCCAT, 293 LITEST_MOUSE_WHEEL_CLICK_ANGLE, 294 LITEST_MOUSE_WHEEL_CLICK_COUNT, 295 LITEST_MOUSE_WHEEL_TILT, 296 LITEST_MS_NANO_TRANSCEIVER_MOUSE, 297 LITEST_SONY_VAIO_KEYS, 298 LITEST_SYNAPTICS_TRACKPOINT_BUTTONS, 299 LITEST_THINKPAD_EXTRABUTTONS, 300 LITEST_VMWARE_VIRTMOUSE, 301 LITEST_WHEEL_ONLY, 302 LITEST_XEN_VIRTUAL_POINTER, 303 304 /* Switches */ 305 LITEST_LID_SWITCH, 306 LITEST_LID_SWITCH_SURFACE3, 307 LITEST_TABLET_MODE_UNRELIABLE, 308 309 /* Special devices */ 310 LITEST_DELL_CANVAS_TOTEM, 311 LITEST_DELL_CANVAS_TOTEM_TOUCH, 312 LITEST_GPIO_KEYS, 313 LITEST_YUBIKEY, 314 315 /* Tablets */ 316 LITEST_ELAN_TABLET, 317 LITEST_HUION_TABLET, 318 LITEST_QEMU_TABLET, 319 LITEST_UCLOGIC_TABLET, 320 LITEST_WACOM_BAMBOO, 321 LITEST_WACOM_BAMBOO_2FG_FINGER, 322 LITEST_WACOM_BAMBOO_2FG_PAD, 323 LITEST_WACOM_BAMBOO_2FG_PEN, 324 LITEST_WACOM_CALIBRATED_TABLET, 325 LITEST_WACOM_CINTIQ, 326 LITEST_WACOM_CINTIQ_13HDT_FINGER, 327 LITEST_WACOM_CINTIQ_13HDT_PAD, 328 LITEST_WACOM_CINTIQ_13HDT_PEN, 329 LITEST_WACOM_CINTIQ_24HD, 330 LITEST_WACOM_CINTIQ_24HDT_PAD, 331 LITEST_WACOM_CINTIQ_PRO16_FINGER, 332 LITEST_WACOM_CINTIQ_PRO16_PAD, 333 LITEST_WACOM_CINTIQ_PRO16_PEN, 334 LITEST_WACOM_EKR, 335 LITEST_WACOM_HID4800_PEN, 336 LITEST_WACOM_INTUOS, 337 LITEST_WACOM_INTUOS3_PAD, 338 LITEST_WACOM_INTUOS5_PAD, 339 LITEST_WACOM_ISDV4, 340 LITEST_WACOM_ISDV4_4200_PEN, 341 LITEST_WACOM_ISDV4_524C_PEN, 342 LITEST_WACOM_MOBILESTUDIO_PRO_16_PAD, 343 LITEST_WALTOP, 344}; 345 346#define LITEST_DEVICELESS -2 347#define LITEST_DISABLE_DEVICE -1 348#define LITEST_ANY 0 349#define LITEST_TOUCHPAD bit(0) 350#define LITEST_CLICKPAD bit(1) 351#define LITEST_BUTTON bit(2) 352#define LITEST_KEYS bit(3) 353#define LITEST_RELATIVE bit(4) 354#define LITEST_WHEEL bit(5) 355#define LITEST_TOUCH bit(6) 356#define LITEST_SINGLE_TOUCH bit(7) 357#define LITEST_APPLE_CLICKPAD bit(8) 358#define LITEST_TOPBUTTONPAD bit(9) 359#define LITEST_SEMI_MT bit(10) 360#define LITEST_POINTINGSTICK bit(11) 361#define LITEST_FAKE_MT bit(12) 362#define LITEST_ABSOLUTE bit(13) 363#define LITEST_PROTOCOL_A bit(14) 364#define LITEST_HOVER bit(15) 365#define LITEST_ELLIPSE bit(16) 366#define LITEST_TABLET bit(17) 367#define LITEST_DISTANCE bit(18) 368#define LITEST_TOOL_SERIAL bit(19) 369#define LITEST_TILT bit(20) 370#define LITEST_TABLET_PAD bit(21) 371#define LITEST_RING bit(22) 372#define LITEST_STRIP bit(23) 373#define LITEST_TRACKBALL bit(24) 374#define LITEST_LEDS bit(25) 375#define LITEST_SWITCH bit(26) 376#define LITEST_IGNORED bit(27) 377#define LITEST_NO_DEBOUNCE bit(28) 378#define LITEST_TOOL_MOUSE bit(29) 379#define LITEST_DIRECT bit(30) 380#define LITEST_TOTEM bit(31) 381#define LITEST_FORCED_PROXOUT bit(32) 382#define LITEST_PRECALIBRATED bit(33) 383 384/* this is a semi-mt device, so we keep track of the touches that the tests 385 * send and modify them so that the first touch is always slot 0 and sends 386 * the top-left of the bounding box, the second is always slot 1 and sends 387 * the bottom-right of the bounding box. 388 * Lifting any of two fingers terminates slot 1 389 */ 390struct litest_semi_mt { 391 bool is_semi_mt; 392 393 int tracking_id; 394 /* The actual touches requested by the test for the two slots 395 * in the 0..100 range used by litest */ 396 struct { 397 double x, y; 398 } touches[2]; 399}; 400 401struct litest_device { 402 enum litest_device_type which; 403 struct libevdev *evdev; 404 struct libevdev_uinput *uinput; 405 struct libinput *libinput; 406 struct quirks *quirks; 407 bool owns_context; 408 struct libinput_device *libinput_device; 409 struct litest_device_interface *interface; 410 411 int ntouches_down; 412 int skip_ev_syn; 413 struct litest_semi_mt semi_mt; /** only used for semi-mt device */ 414 415 void *private; /* device-specific data */ 416}; 417 418struct axis_replacement { 419 int32_t evcode; 420 double value; 421}; 422 423/** 424 * Same as litest_axis_set_value but allows for ranges outside 0..100% 425 */ 426static inline void 427litest_axis_set_value_unchecked(struct axis_replacement *axes, int code, double value) 428{ 429 while (axes->evcode != -1) { 430 if (axes->evcode == code) { 431 axes->value = value; 432 return; 433 } 434 axes++; 435 } 436 437 litest_abort_msg("Missing axis code %d\n", code); 438} 439 440/** 441 * Takes a value in percent and sets the given axis to that code. 442 */ 443static inline void 444litest_axis_set_value(struct axis_replacement *axes, int code, double value) 445{ 446 litest_assert_double_ge(value, 0.0); 447 litest_assert_double_le(value, 100.0); 448 449 litest_axis_set_value_unchecked(axes, code, value); 450} 451 452/* A loop range, resolves to: 453 for (i = lower; i < upper; i++) 454 */ 455struct range { 456 int lower; /* inclusive */ 457 int upper; /* exclusive */ 458}; 459 460struct libinput *litest_create_context(void); 461void litest_destroy_context(struct libinput *li); 462void litest_disable_log_handler(struct libinput *libinput); 463void litest_restore_log_handler(struct libinput *libinput); 464void litest_set_log_handler_bug(struct libinput *libinput); 465 466#define litest_add(func_, ...) \ 467 _litest_add(__FILE__, #func_, func_, __VA_ARGS__) 468#define litest_add_ranged(func_, ...) \ 469 _litest_add_ranged(__FILE__, #func_, func_, __VA_ARGS__) 470#define litest_add_for_device(func_, ...) \ 471 _litest_add_for_device(__FILE__, #func_, func_, __VA_ARGS__) 472#define litest_add_ranged_for_device(func_, ...) \ 473 _litest_add_ranged_for_device(__FILE__, #func_, func_, __VA_ARGS__) 474#define litest_add_no_device(func_) \ 475 _litest_add_no_device(__FILE__, #func_, func_) 476#define litest_add_ranged_no_device(func_, ...) \ 477 _litest_add_ranged_no_device(__FILE__, #func_, func_, __VA_ARGS__) 478#define litest_add_deviceless(func_) \ 479 _litest_add_deviceless(__FILE__, #func_, func_) 480 481void 482_litest_add(const char *name, 483 const char *funcname, 484 const void *func, 485 int64_t required_feature, 486 int64_t excluded_feature); 487void 488_litest_add_ranged(const char *name, 489 const char *funcname, 490 const void *func, 491 int64_t required, 492 int64_t excluded, 493 const struct range *range); 494void 495_litest_add_for_device(const char *name, 496 const char *funcname, 497 const void *func, 498 enum litest_device_type type); 499void 500_litest_add_ranged_for_device(const char *name, 501 const char *funcname, 502 const void *func, 503 enum litest_device_type type, 504 const struct range *range); 505void 506_litest_add_no_device(const char *name, 507 const char *funcname, 508 const void *func); 509void 510_litest_add_ranged_no_device(const char *name, 511 const char *funcname, 512 const void *func, 513 const struct range *range); 514void 515_litest_add_deviceless(const char *name, 516 const char *funcname, 517 const void *func); 518 519struct litest_device * 520litest_create_device(enum litest_device_type which); 521 522struct litest_device * 523litest_add_device(struct libinput *libinput, 524 enum litest_device_type which); 525struct libevdev_uinput * 526litest_create_uinput_device_from_description(const char *name, 527 const struct input_id *id, 528 const struct input_absinfo *abs, 529 const int *events); 530struct litest_device * 531litest_create(enum litest_device_type which, 532 const char *name_override, 533 struct input_id *id_override, 534 const struct input_absinfo *abs_override, 535 const int *events_override); 536 537struct litest_device * 538litest_create_device_with_overrides(enum litest_device_type which, 539 const char *name_override, 540 struct input_id *id_override, 541 const struct input_absinfo *abs_override, 542 const int *events_override); 543struct litest_device * 544litest_add_device_with_overrides(struct libinput *libinput, 545 enum litest_device_type which, 546 const char *name_override, 547 struct input_id *id_override, 548 const struct input_absinfo *abs_override, 549 const int *events_override); 550 551struct litest_device * 552litest_current_device(void); 553 554void 555litest_grab_device(struct litest_device *d); 556 557void 558litest_ungrab_device(struct litest_device *d); 559 560void 561litest_delete_device(struct litest_device *d); 562 563void 564litest_event(struct litest_device *t, 565 unsigned int type, 566 unsigned int code, 567 int value); 568int 569litest_auto_assign_value(struct litest_device *d, 570 const struct input_event *ev, 571 int slot, double x, double y, 572 struct axis_replacement *axes, 573 bool touching); 574void 575litest_touch_up(struct litest_device *d, unsigned int slot); 576 577void 578litest_touch_move(struct litest_device *d, 579 unsigned int slot, 580 double x, 581 double y); 582 583void 584litest_touch_move_extended(struct litest_device *d, 585 unsigned int slot, 586 double x, 587 double y, 588 struct axis_replacement *axes); 589 590void 591litest_touch_sequence(struct litest_device *d, 592 unsigned int slot, 593 double x1, 594 double y1, 595 double x2, 596 double y2, 597 int steps); 598 599void 600litest_touch_down(struct litest_device *d, 601 unsigned int slot, 602 double x, 603 double y); 604 605void 606litest_touch_down_extended(struct litest_device *d, 607 unsigned int slot, 608 double x, 609 double y, 610 struct axis_replacement *axes); 611 612void 613litest_touch_move_to(struct litest_device *d, 614 unsigned int slot, 615 double x_from, double y_from, 616 double x_to, double y_to, 617 int steps); 618 619void 620litest_touch_move_to_extended(struct litest_device *d, 621 unsigned int slot, 622 double x_from, double y_from, 623 double x_to, double y_to, 624 struct axis_replacement *axes, 625 int steps); 626 627void 628litest_touch_move_two_touches(struct litest_device *d, 629 double x0, double y0, 630 double x1, double y1, 631 double dx, double dy, 632 int steps); 633 634void 635litest_touch_move_three_touches(struct litest_device *d, 636 double x0, double y0, 637 double x1, double y1, 638 double x2, double y2, 639 double dx, double dy, 640 int steps); 641 642void 643litest_tablet_set_tool_type(struct litest_device *d, 644 unsigned int code); 645 646void 647litest_tablet_proximity_in(struct litest_device *d, 648 double x, double y, 649 struct axis_replacement *axes); 650 651void 652litest_tablet_proximity_out(struct litest_device *d); 653 654void 655litest_tablet_tip_down(struct litest_device *d, 656 double x, double y, 657 struct axis_replacement *axes); 658 659void 660litest_tablet_tip_up(struct litest_device *d, 661 double x, double y, 662 struct axis_replacement *axes); 663 664void 665litest_tablet_motion(struct litest_device *d, 666 double x, double y, 667 struct axis_replacement *axes); 668 669void 670litest_pad_ring_start(struct litest_device *d, double value); 671 672void 673litest_pad_ring_change(struct litest_device *d, double value); 674 675void 676litest_pad_ring_end(struct litest_device *d); 677 678void 679litest_pad_strip_start(struct litest_device *d, double value); 680 681void 682litest_pad_strip_change(struct litest_device *d, double value); 683 684void 685litest_pad_strip_end(struct litest_device *d); 686 687void 688litest_hover_start(struct litest_device *d, 689 unsigned int slot, 690 double x, 691 double y); 692 693void 694litest_hover_end(struct litest_device *d, unsigned int slot); 695 696void litest_hover_move(struct litest_device *d, 697 unsigned int slot, 698 double x, 699 double y); 700 701void 702litest_hover_move_to(struct litest_device *d, 703 unsigned int slot, 704 double x_from, double y_from, 705 double x_to, double y_to, 706 int steps); 707 708void 709litest_hover_move_two_touches(struct litest_device *d, 710 double x0, double y0, 711 double x1, double y1, 712 double dx, double dy, 713 int steps); 714 715void 716litest_button_click_debounced(struct litest_device *d, 717 struct libinput *li, 718 unsigned int button, 719 bool is_press); 720 721void 722litest_button_click(struct litest_device *d, 723 unsigned int button, 724 bool is_press); 725 726void 727litest_button_scroll(struct litest_device *d, 728 unsigned int button, 729 double dx, double dy); 730void 731litest_button_scroll_locked(struct litest_device *d, 732 unsigned int button, 733 double dx, double dy); 734 735void 736litest_keyboard_key(struct litest_device *d, 737 unsigned int key, 738 bool is_press); 739 740void litest_switch_action(struct litest_device *d, 741 enum libinput_switch sw, 742 enum libinput_switch_state state); 743 744void 745litest_wait_for_event(struct libinput *li); 746 747void 748litest_wait_for_event_of_type(struct libinput *li, ...); 749 750void 751litest_drain_events(struct libinput *li); 752 753void 754litest_drain_events_of_type(struct libinput *li, ...); 755 756void 757litest_assert_event_type(struct libinput_event *event, 758 enum libinput_event_type want); 759 760void 761litest_assert_empty_queue(struct libinput *li); 762 763void 764litest_assert_touch_sequence(struct libinput *li); 765 766void 767litest_assert_touch_motion_frame(struct libinput *li); 768void 769litest_assert_touch_down_frame(struct libinput *li); 770void 771litest_assert_touch_up_frame(struct libinput *li); 772void 773litest_assert_touch_cancel(struct libinput *li); 774 775struct libinput_event_pointer * 776litest_is_button_event(struct libinput_event *event, 777 unsigned int button, 778 enum libinput_button_state state); 779 780struct libinput_event_pointer * 781litest_is_axis_event(struct libinput_event *event, 782 enum libinput_event_type axis_type, 783 enum libinput_pointer_axis axis, 784 enum libinput_pointer_axis_source source); 785 786bool 787litest_is_high_res_axis_event(struct libinput_event *event); 788 789struct libinput_event_pointer * 790litest_is_motion_event(struct libinput_event *event); 791 792struct libinput_event_touch * 793litest_is_touch_event(struct libinput_event *event, 794 enum libinput_event_type type); 795 796struct libinput_event_keyboard * 797litest_is_keyboard_event(struct libinput_event *event, 798 unsigned int key, 799 enum libinput_key_state state); 800 801struct libinput_event_gesture * 802litest_is_gesture_event(struct libinput_event *event, 803 enum libinput_event_type type, 804 int nfingers); 805 806struct libinput_event_tablet_tool * 807litest_is_tablet_event(struct libinput_event *event, 808 enum libinput_event_type type); 809 810struct libinput_event_tablet_pad * 811litest_is_pad_button_event(struct libinput_event *event, 812 unsigned int button, 813 enum libinput_button_state state); 814struct libinput_event_tablet_pad * 815litest_is_pad_ring_event(struct libinput_event *event, 816 unsigned int number, 817 enum libinput_tablet_pad_ring_axis_source source); 818struct libinput_event_tablet_pad * 819litest_is_pad_strip_event(struct libinput_event *event, 820 unsigned int number, 821 enum libinput_tablet_pad_strip_axis_source source); 822struct libinput_event_tablet_pad * 823litest_is_pad_key_event(struct libinput_event *event, 824 unsigned int key, 825 enum libinput_key_state state); 826 827struct libinput_event_switch * 828litest_is_switch_event(struct libinput_event *event, 829 enum libinput_switch sw, 830 enum libinput_switch_state state); 831 832struct libinput_event_tablet_tool * 833litest_is_proximity_event(struct libinput_event *event, 834 enum libinput_tablet_tool_proximity_state state); 835 836double 837litest_event_pointer_get_value(struct libinput_event_pointer *ptrev, 838 enum libinput_pointer_axis axis); 839 840enum libinput_pointer_axis_source 841litest_event_pointer_get_axis_source(struct libinput_event_pointer *event); 842 843void 844litest_assert_key_event(struct libinput *li, unsigned int key, 845 enum libinput_key_state state); 846 847void 848litest_assert_button_event(struct libinput *li, 849 unsigned int button, 850 enum libinput_button_state state); 851 852void 853litest_assert_switch_event(struct libinput *li, 854 enum libinput_switch sw, 855 enum libinput_switch_state state); 856 857void 858litest_assert_scroll(struct libinput *li, 859 enum libinput_event_type axis_type, 860 enum libinput_pointer_axis axis, 861 int minimum_movement); 862 863void 864litest_assert_axis_end_sequence(struct libinput *li, 865 enum libinput_event_type axis_type, 866 enum libinput_pointer_axis axis, 867 enum libinput_pointer_axis_source source); 868 869void 870litest_assert_only_typed_events(struct libinput *li, 871 enum libinput_event_type type); 872 873void 874litest_assert_only_axis_events(struct libinput *li, 875 enum libinput_event_type axis_type); 876 877void 878litest_assert_no_typed_events(struct libinput *li, 879 enum libinput_event_type type); 880 881void 882litest_assert_tablet_button_event(struct libinput *li, 883 unsigned int button, 884 enum libinput_button_state state); 885 886void 887litest_assert_tablet_proximity_event(struct libinput *li, 888 enum libinput_tablet_tool_proximity_state state); 889 890void 891litest_assert_tablet_tip_event(struct libinput *li, 892 enum libinput_tablet_tool_tip_state state); 893 894void 895litest_assert_pad_button_event(struct libinput *li, 896 unsigned int button, 897 enum libinput_button_state state); 898void 899litest_assert_pad_key_event(struct libinput *li, 900 unsigned int key, 901 enum libinput_key_state state); 902 903void 904litest_assert_gesture_event(struct libinput *li, 905 enum libinput_event_type type, 906 int nfingers); 907 908struct libevdev_uinput * 909litest_create_uinput_device(const char *name, 910 struct input_id *id, 911 ...); 912 913struct libevdev_uinput * 914litest_create_uinput_abs_device(const char *name, 915 struct input_id *id, 916 const struct input_absinfo *abs, 917 ...); 918 919void 920litest_timeout_tap(void); 921 922void 923litest_timeout_tapndrag(void); 924 925void 926litest_timeout_debounce(void); 927 928void 929litest_timeout_softbuttons(void); 930 931void 932litest_timeout_buttonscroll(void); 933 934void 935litest_timeout_wheel_scroll(void); 936 937void 938litest_timeout_edgescroll(void); 939 940void 941litest_timeout_finger_switch(void); 942 943void 944litest_timeout_middlebutton(void); 945 946void 947litest_timeout_dwt_short(void); 948 949void 950litest_timeout_dwt_long(void); 951 952void 953litest_timeout_gesture(void); 954 955void 956litest_timeout_gesture_scroll(void); 957 958void 959litest_timeout_gesture_hold(void); 960 961void 962litest_timeout_gesture_quick_hold(void); 963 964void 965litest_timeout_trackpoint(void); 966 967void 968litest_timeout_tablet_proxout(void); 969 970void 971litest_timeout_touch_arbitration(void); 972 973void 974litest_timeout_hysteresis(void); 975 976void 977litest_push_event_frame(struct litest_device *dev); 978 979void 980litest_pop_event_frame(struct litest_device *dev); 981 982void 983litest_filter_event(struct litest_device *dev, 984 unsigned int type, 985 unsigned int code); 986 987void 988litest_unfilter_event(struct litest_device *dev, 989 unsigned int type, 990 unsigned int code); 991void 992litest_semi_mt_touch_down(struct litest_device *d, 993 struct litest_semi_mt *semi_mt, 994 unsigned int slot, 995 double x, double y); 996 997void 998litest_semi_mt_touch_move(struct litest_device *d, 999 struct litest_semi_mt *semi_mt, 1000 unsigned int slot, 1001 double x, double y); 1002 1003void 1004litest_semi_mt_touch_up(struct litest_device *d, 1005 struct litest_semi_mt *semi_mt, 1006 unsigned int slot); 1007 1008static inline void 1009litest_enable_tap(struct libinput_device *device) 1010{ 1011 enum libinput_config_status status, expected; 1012 1013 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1014 status = libinput_device_config_tap_set_enabled(device, 1015 LIBINPUT_CONFIG_TAP_ENABLED); 1016 1017 litest_assert_int_eq(status, expected); 1018} 1019 1020static inline void 1021litest_disable_tap(struct libinput_device *device) 1022{ 1023 enum libinput_config_status status, expected; 1024 1025 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1026 status = libinput_device_config_tap_set_enabled(device, 1027 LIBINPUT_CONFIG_TAP_DISABLED); 1028 1029 litest_assert_int_eq(status, expected); 1030} 1031 1032static inline void 1033litest_set_tap_map(struct libinput_device *device, 1034 enum libinput_config_tap_button_map map) 1035{ 1036 enum libinput_config_status status, expected; 1037 1038 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1039 status = libinput_device_config_tap_set_button_map(device, map); 1040 litest_assert_int_eq(status, expected); 1041} 1042 1043static inline void 1044litest_enable_tap_drag(struct libinput_device *device) 1045{ 1046 enum libinput_config_status status, expected; 1047 1048 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1049 status = libinput_device_config_tap_set_drag_enabled(device, 1050 LIBINPUT_CONFIG_DRAG_ENABLED); 1051 1052 litest_assert_int_eq(status, expected); 1053} 1054 1055static inline void 1056litest_disable_tap_drag(struct libinput_device *device) 1057{ 1058 enum libinput_config_status status, expected; 1059 1060 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1061 status = libinput_device_config_tap_set_drag_enabled(device, 1062 LIBINPUT_CONFIG_DRAG_DISABLED); 1063 1064 litest_assert_int_eq(status, expected); 1065} 1066 1067static inline bool 1068litest_has_2fg_scroll(struct litest_device *dev) 1069{ 1070 struct libinput_device *device = dev->libinput_device; 1071 1072 return !!(libinput_device_config_scroll_get_methods(device) & 1073 LIBINPUT_CONFIG_SCROLL_2FG); 1074} 1075 1076static inline void 1077litest_enable_2fg_scroll(struct litest_device *dev) 1078{ 1079 enum libinput_config_status status, expected; 1080 struct libinput_device *device = dev->libinput_device; 1081 1082 status = libinput_device_config_scroll_set_method(device, 1083 LIBINPUT_CONFIG_SCROLL_2FG); 1084 1085 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1086 litest_assert_int_eq(status, expected); 1087 1088 libinput_device_config_scroll_set_natural_scroll_enabled(device, 0); 1089} 1090 1091static inline void 1092litest_enable_edge_scroll(struct litest_device *dev) 1093{ 1094 enum libinput_config_status status, expected; 1095 struct libinput_device *device = dev->libinput_device; 1096 1097 status = libinput_device_config_scroll_set_method(device, 1098 LIBINPUT_CONFIG_SCROLL_EDGE); 1099 1100 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1101 litest_assert_int_eq(status, expected); 1102 1103 libinput_device_config_scroll_set_natural_scroll_enabled(device, 0); 1104} 1105 1106static inline bool 1107litest_has_clickfinger(struct litest_device *dev) 1108{ 1109 struct libinput_device *device = dev->libinput_device; 1110 uint32_t methods = libinput_device_config_click_get_methods(device); 1111 1112 return methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; 1113} 1114 1115static inline bool 1116litest_has_btnareas(struct litest_device *dev) 1117{ 1118 struct libinput_device *device = dev->libinput_device; 1119 uint32_t methods = libinput_device_config_click_get_methods(device); 1120 1121 return methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; 1122} 1123 1124static inline void 1125litest_enable_clickfinger(struct litest_device *dev) 1126{ 1127 enum libinput_config_status status, expected; 1128 struct libinput_device *device = dev->libinput_device; 1129 1130 status = libinput_device_config_click_set_method(device, 1131 LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER); 1132 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1133 litest_assert_int_eq(status, expected); 1134} 1135 1136static inline void 1137litest_enable_buttonareas(struct litest_device *dev) 1138{ 1139 enum libinput_config_status status, expected; 1140 struct libinput_device *device = dev->libinput_device; 1141 1142 status = libinput_device_config_click_set_method(device, 1143 LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS); 1144 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1145 litest_assert_int_eq(status, expected); 1146} 1147 1148static inline void 1149litest_enable_drag_lock(struct libinput_device *device) 1150{ 1151 enum libinput_config_status status, expected; 1152 1153 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1154 status = libinput_device_config_tap_set_drag_lock_enabled(device, 1155 LIBINPUT_CONFIG_DRAG_LOCK_ENABLED); 1156 1157 litest_assert_int_eq(status, expected); 1158} 1159 1160static inline void 1161litest_disable_drag_lock(struct libinput_device *device) 1162{ 1163 enum libinput_config_status status, expected; 1164 1165 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1166 status = libinput_device_config_tap_set_drag_lock_enabled(device, 1167 LIBINPUT_CONFIG_DRAG_LOCK_DISABLED); 1168 1169 litest_assert_int_eq(status, expected); 1170} 1171 1172static inline void 1173litest_enable_middleemu(struct litest_device *dev) 1174{ 1175 struct libinput_device *device = dev->libinput_device; 1176 enum libinput_config_status status, expected; 1177 1178 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1179 status = libinput_device_config_middle_emulation_set_enabled(device, 1180 LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); 1181 1182 litest_assert_int_eq(status, expected); 1183} 1184 1185static inline void 1186litest_disable_middleemu(struct litest_device *dev) 1187{ 1188 struct libinput_device *device = dev->libinput_device; 1189 enum libinput_config_status status, expected; 1190 1191 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1192 status = libinput_device_config_middle_emulation_set_enabled(device, 1193 LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED); 1194 1195 litest_assert_int_eq(status, expected); 1196} 1197 1198static inline void 1199litest_sendevents_off(struct litest_device *dev) 1200{ 1201 struct libinput_device *device = dev->libinput_device; 1202 enum libinput_config_status status, expected; 1203 1204 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1205 status = libinput_device_config_send_events_set_mode(device, 1206 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); 1207 litest_assert_int_eq(status, expected); 1208} 1209 1210static inline void 1211litest_sendevents_on(struct litest_device *dev) 1212{ 1213 struct libinput_device *device = dev->libinput_device; 1214 enum libinput_config_status status, expected; 1215 1216 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1217 status = libinput_device_config_send_events_set_mode(device, 1218 LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); 1219 litest_assert_int_eq(status, expected); 1220} 1221 1222static inline void 1223litest_sendevents_ext_mouse(struct litest_device *dev) 1224{ 1225 struct libinput_device *device = dev->libinput_device; 1226 enum libinput_config_status status, expected; 1227 1228 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1229 status = libinput_device_config_send_events_set_mode(device, 1230 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE); 1231 litest_assert_int_eq(status, expected); 1232} 1233 1234static inline void 1235litest_enable_hold_gestures(struct libinput_device *device) 1236{ 1237 enum libinput_config_status status, expected; 1238 1239 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1240 status = libinput_device_config_gesture_set_hold_enabled(device, 1241 LIBINPUT_CONFIG_HOLD_ENABLED); 1242 1243 litest_assert_int_eq(status, expected); 1244} 1245 1246static inline void 1247litest_disable_hold_gestures(struct libinput_device *device) 1248{ 1249 enum libinput_config_status status, expected; 1250 1251 expected = LIBINPUT_CONFIG_STATUS_SUCCESS; 1252 status = libinput_device_config_gesture_set_hold_enabled(device, 1253 LIBINPUT_CONFIG_HOLD_DISABLED); 1254 1255 litest_assert_int_eq(status, expected); 1256} 1257 1258static inline bool 1259litest_touchpad_is_external(struct litest_device *dev) 1260{ 1261 struct udev_device *udev_device; 1262 const char *prop; 1263 bool is_external; 1264 1265 if (libinput_device_get_id_vendor(dev->libinput_device) == VENDOR_ID_WACOM) 1266 return true; 1267 1268 udev_device = libinput_device_get_udev_device(dev->libinput_device); 1269 prop = udev_device_get_property_value(udev_device, 1270 "ID_INPUT_TOUCHPAD_INTEGRATION"); 1271 is_external = prop && streq(prop, "external"); 1272 udev_device_unref(udev_device); 1273 1274 return is_external; 1275} 1276 1277static inline int 1278litest_send_file(int sock, int fd) 1279{ 1280 char buf[40960]; 1281 int n = read(fd, buf, 40960); 1282 litest_assert_int_gt(n, 0); 1283 return write(sock, buf, n); 1284} 1285 1286static inline int 1287litest_slot_count(struct litest_device *dev) 1288{ 1289 if (dev->which == LITEST_ALPS_3FG) 1290 return 2; 1291 1292 return libevdev_get_num_slots(dev->evdev); 1293} 1294 1295static inline bool 1296litest_has_palm_detect_size(struct litest_device *dev) 1297{ 1298 double width, height; 1299 unsigned int vendor; 1300 unsigned int bustype; 1301 int rc; 1302 1303 vendor = libinput_device_get_id_vendor(dev->libinput_device); 1304 bustype = libevdev_get_id_bustype(dev->evdev); 1305 if (vendor == VENDOR_ID_WACOM) 1306 return 0; 1307 if (bustype == BUS_BLUETOOTH) 1308 return 0; 1309 if (vendor == VENDOR_ID_APPLE) 1310 return 0; 1311 1312 rc = libinput_device_get_size(dev->libinput_device, &width, &height); 1313 1314 return rc == 0 && width >= 70; 1315} 1316 1317#endif /* LITEST_H */ 1318