test: grab the device before any lid or tablet mode switches
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 3 Jul 2020 02:46:38 +0000 (12:46 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 7 Jul 2020 08:51:33 +0000 (18:51 +1000)
Putting an EVIOCGRAB on the device before sending those events means no-one
else sees those events - particularly upower. This means no-one else knows the
lid is on or off and thus we never blank the screen (or suspend/shut down but
those are inhibited anyway).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/litest.c
test/litest.h
test/test-switch.c
test/test-touchpad.c
test/valgrind.suppressions

index da634e0379f3858f61a741b8a783fdd3b369b98f..a10d50db5b99506a9ba1b5b2261cc61196f9f81f 100644 (file)
@@ -263,6 +263,49 @@ struct litest_device *litest_current_device(void)
        return current_device;
 }
 
+static void
+grab_device(struct litest_device *device, bool mode)
+{
+       struct libinput *li = libinput_device_get_context(device->libinput_device);
+       struct litest_context *ctx = libinput_get_user_data(li);
+       struct udev_device *udev_device;
+       const char *devnode;
+       struct path *p;
+
+       udev_device = libinput_device_get_udev_device(device->libinput_device);
+       litest_assert_ptr_notnull(udev_device);
+
+       devnode = udev_device_get_devnode(udev_device);
+
+       /* Note: in some tests we create multiple devices for the same path.
+        * This will only grab the first device in the list but we're using
+        * list_insert() so the first device is the latest that was
+        * initialized, so we should be good.
+        */
+       list_for_each(p, &ctx->paths, link) {
+               if (streq(p->path, devnode)) {
+                       int rc = ioctl(p->fd, EVIOCGRAB, (void*)mode ? 1 : 0);
+                       ck_assert_int_gt(rc, -1);
+                       udev_device_unref(udev_device);
+                       return;
+               }
+       }
+       litest_abort_msg("Failed to find device %s to %sgrab\n",
+                        devnode, mode ? "" : "un");
+}
+
+void
+litest_grab_device(struct litest_device *device)
+{
+       grab_device(device, true);
+}
+
+void
+litest_ungrab_device(struct litest_device *device)
+{
+       grab_device(device, false);
+}
+
 void litest_set_current_device(struct litest_device *device)
 {
        current_device = device;
@@ -784,7 +827,13 @@ open_restricted(const char *path, int flags, void *userdata)
                p = zalloc(sizeof *p);
                p->path = safe_strdup(path);
                p->fd = fd;
-               list_append(&ctx->paths, &p->link);
+               /* We specifically insert here so that the most-recently
+                * opened path is the first one in the list. This helps when
+                * we have multiple test devices with the same device path,
+                * the fd of the most recent device is the first one to get
+                * grabbed
+                */
+               list_insert(&ctx->paths, &p->link);
        }
 
        return fd;
index 0f8f188b35d63cddd5e615c53ea9eba3fb0d259d..5a43b19bfad538957f7d4411f2a4acb5af7bda52 100644 (file)
@@ -513,6 +513,12 @@ litest_add_device_with_overrides(struct libinput *libinput,
 struct litest_device *
 litest_current_device(void);
 
+void
+litest_grab_device(struct litest_device *d);
+
+void
+litest_ungrab_device(struct litest_device *d);
+
 void
 litest_delete_device(struct litest_device *d);
 
index e04341008052d37899f77031b342f67df60fa74d..3c6275a9eddd92ccdbf360f275ef420bb7fffce3 100644 (file)
@@ -24,6 +24,7 @@
 #include <config.h>
 
 #include <check.h>
+#include <fcntl.h>
 #include <libinput.h>
 
 #include "libinput-util.h"
@@ -113,6 +114,7 @@ START_TEST(switch_toggle)
 
        litest_drain_events(li);
 
+       litest_grab_device(dev);
        litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
        libinput_dispatch(li);
 
@@ -134,6 +136,7 @@ START_TEST(switch_toggle)
        }
 
        litest_assert_empty_queue(li);
+       litest_ungrab_device(dev);
 }
 END_TEST
 
@@ -149,6 +152,7 @@ START_TEST(switch_toggle_double)
 
        litest_drain_events(li);
 
+       litest_grab_device(dev);
        litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
        libinput_dispatch(li);
 
@@ -162,6 +166,7 @@ START_TEST(switch_toggle_double)
        libinput_dispatch(li);
 
        litest_assert_empty_queue(li);
+       litest_ungrab_device(dev);
 }
 END_TEST
 
@@ -194,7 +199,9 @@ START_TEST(switch_down_on_init)
        if (sw == LIBINPUT_SWITCH_LID && !lid_switch_is_reliable(dev))
                return;
 
+       litest_grab_device(dev);
        litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
+       litest_ungrab_device(dev);
 
        /* need separate context to test */
        li = litest_create_context();
@@ -237,7 +244,9 @@ START_TEST(switch_not_down_on_init)
        if (sw == LIBINPUT_SWITCH_LID && lid_switch_is_reliable(dev))
                return;
 
+       litest_grab_device(dev);
        litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
+       litest_ungrab_device(dev);
 
        /* need separate context to test */
        li = litest_create_context();
@@ -279,6 +288,8 @@ START_TEST(switch_disable_touchpad)
        litest_disable_tap(touchpad->libinput_device);
        litest_drain_events(li);
 
+       litest_grab_device(sw);
+
        /* switch is on - no events */
        litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
@@ -298,6 +309,7 @@ START_TEST(switch_disable_touchpad)
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
 
        litest_delete_device(touchpad);
+       litest_ungrab_device(sw);
 }
 END_TEST
 
@@ -319,8 +331,10 @@ START_TEST(switch_disable_touchpad_during_touch)
        litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
 
+       litest_grab_device(sw);
        litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
+       litest_ungrab_device(sw);
 
        litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5);
        litest_touch_up(touchpad, 0);
@@ -345,8 +359,10 @@ START_TEST(switch_disable_touchpad_edge_scroll)
 
        litest_drain_events(li);
 
+       litest_grab_device(sw);
        litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
+       litest_ungrab_device(sw);
 
        litest_touch_down(touchpad, 0, 99, 20);
        libinput_dispatch(li);
@@ -390,7 +406,9 @@ START_TEST(switch_disable_touchpad_edge_scroll_interrupt)
        libinput_dispatch(li);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
 
+       litest_grab_device(sw);
        litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
+       litest_ungrab_device(sw);
        libinput_dispatch(li);
 
        event = libinput_get_event(li);
@@ -458,7 +476,9 @@ START_TEST(switch_dont_resume_disabled_touchpad)
        litest_drain_events(li);
 
        /* switch is on - no events */
+       litest_grab_device(sw);
        litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
+       litest_ungrab_device(sw);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
 
        litest_touch_down(touchpad, 0, 50, 50);
@@ -502,7 +522,9 @@ START_TEST(switch_dont_resume_disabled_touchpad_external_mouse)
        litest_assert_empty_queue(li);
 
        /* switch is on - no events */
+       litest_grab_device(sw);
        litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
+       litest_ungrab_device(sw);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
 
        litest_touch_down(touchpad, 0, 50, 50);
@@ -536,6 +558,7 @@ START_TEST(lid_open_on_key)
 
        keyboard = litest_add_device(li, LITEST_KEYBOARD);
 
+       litest_grab_device(sw);
        for (int i = 0; i < 3; i++) {
                litest_switch_action(sw,
                                     LIBINPUT_SWITCH_LID,
@@ -561,6 +584,7 @@ START_TEST(lid_open_on_key)
                                     LIBINPUT_SWITCH_STATE_OFF);
                litest_assert_empty_queue(li);
        }
+       litest_ungrab_device(sw);
 
        litest_delete_device(keyboard);
 }
@@ -578,9 +602,11 @@ START_TEST(lid_open_on_key_touchpad_enabled)
        keyboard = litest_add_device(li, LITEST_KEYBOARD);
        touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
 
+       litest_grab_device(sw);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_LID,
                             LIBINPUT_SWITCH_STATE_ON);
+       litest_ungrab_device(sw);
        litest_drain_events(li);
 
        litest_event(keyboard, EV_KEY, KEY_A, 1);
@@ -627,10 +653,12 @@ START_TEST(switch_suspend_with_keyboard)
        keyboard = litest_add_device(li, LITEST_KEYBOARD);
        libinput_dispatch(li);
 
+       litest_grab_device(sw);
        litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
        litest_drain_events(li);
        litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF);
        litest_drain_events(li);
+       litest_ungrab_device(sw);
 
        litest_delete_device(keyboard);
        litest_drain_events(li);
@@ -681,49 +709,54 @@ START_TEST(lid_update_hw_on_key)
 {
        struct litest_device *sw = litest_current_device();
        struct libinput *li = sw->libinput;
-       struct libinput *li2;
        struct litest_device *keyboard;
-       struct libinput_event *event;
+       struct libevdev *evdev;
+       struct input_event event;
+       int fd;
+       int rc;
 
        if (!switch_has_lid(sw))
                return;
 
        keyboard = litest_add_device(li, LITEST_KEYBOARD);
 
-       /* separate context to listen to the fake hw event */
-       li2 = litest_create_context();
-       libinput_path_add_device(li2,
-                                libevdev_uinput_get_devnode(sw->uinput));
-       litest_drain_events(li2);
-
+       litest_grab_device(sw);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_LID,
                             LIBINPUT_SWITCH_STATE_ON);
        litest_drain_events(li);
+       litest_ungrab_device(sw);
 
-       libinput_dispatch(li2);
-       event = libinput_get_event(li2);
-       litest_is_switch_event(event,
-                              LIBINPUT_SWITCH_LID,
-                              LIBINPUT_SWITCH_STATE_ON);
-       libinput_event_destroy(event);
+       /* Separate direct libevdev context to check if the HW event goes
+        * through */
+       fd = open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY|O_NONBLOCK);
+       ck_assert_int_ge(fd, 0);
+       ck_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0);
+       ck_assert_int_eq(libevdev_get_event_value(evdev, EV_SW, SW_LID), 1);
 
+       /* Typing on the keyboard should trigger a lid open event */
        litest_event(keyboard, EV_KEY, KEY_A, 1);
        litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
        litest_event(keyboard, EV_KEY, KEY_A, 0);
        litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
        litest_drain_events(li);
 
-       litest_wait_for_event(li2);
-       event = libinput_get_event(li2);
-       litest_is_switch_event(event,
-                              LIBINPUT_SWITCH_LID,
-                              LIBINPUT_SWITCH_STATE_OFF);
-       libinput_event_destroy(event);
-       litest_assert_empty_queue(li2);
+       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
+       ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
+       ck_assert_int_eq(event.type, EV_SW);
+       ck_assert_int_eq(event.code, SW_LID);
+       ck_assert_int_eq(event.value, 0);
+       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
+       ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
+       ck_assert_int_eq(event.type, EV_SYN);
+       ck_assert_int_eq(event.code, SYN_REPORT);
+       ck_assert_int_eq(event.value, 0);
+       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
+       ck_assert_int_eq(rc, -EAGAIN);
 
-       litest_destroy_context(li2);
        litest_delete_device(keyboard);
+       close(fd);
+       libevdev_free(evdev);
 }
 END_TEST
 
@@ -733,17 +766,22 @@ START_TEST(lid_update_hw_on_key_closed_on_init)
        struct libinput *li;
        struct litest_device *keyboard;
        struct libevdev *evdev = sw->evdev;
-       struct input_event ev;
+       struct input_event event;
+       int fd;
+       int rc;
 
+       litest_grab_device(sw);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_LID,
                             LIBINPUT_SWITCH_STATE_ON);
+       litest_ungrab_device(sw);
 
-       /* Make sure kernel state is right */
-       libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev);
-       while (libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_SYNC, &ev) >= 0)
-               ;
-       ck_assert(libevdev_get_event_value(evdev, EV_SW, SW_LID));
+       /* Separate direct libevdev context to check if the HW event goes
+        * through */
+       fd = open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY|O_NONBLOCK);
+       ck_assert_int_ge(fd, 0);
+       ck_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0);
+       ck_assert_int_eq(libevdev_get_event_value(evdev, EV_SW, SW_LID), 1);
 
        keyboard = litest_add_device(sw->libinput, LITEST_KEYBOARD);
 
@@ -754,7 +792,8 @@ START_TEST(lid_update_hw_on_key_closed_on_init)
        libinput_path_add_device(li,
                                 libevdev_uinput_get_devnode(keyboard->uinput));
 
-       /* don't expect a switch waiting for us */
+       /* don't expect a switch waiting for us, this is run for an
+        * unreliable device */
        while (libinput_next_event_type(li) != LIBINPUT_EVENT_NONE) {
                ck_assert_int_ne(libinput_next_event_type(li),
                                 LIBINPUT_EVENT_SWITCH_TOGGLE);
@@ -769,13 +808,23 @@ START_TEST(lid_update_hw_on_key_closed_on_init)
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
 
        /* Make sure kernel state has updated */
-       libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev);
-       while (libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_SYNC, &ev) >= 0)
-               ;
-       ck_assert(!libevdev_get_event_value(evdev, EV_SW, SW_LID));
+       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
+       ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
+       ck_assert_int_eq(event.type, EV_SW);
+       ck_assert_int_eq(event.code, SW_LID);
+       ck_assert_int_eq(event.value, 0);
+       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
+       ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
+       ck_assert_int_eq(event.type, EV_SYN);
+       ck_assert_int_eq(event.code, SYN_REPORT);
+       ck_assert_int_eq(event.value, 0);
+       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
+       ck_assert_int_eq(rc, -EAGAIN);
 
        litest_destroy_context(li);
        litest_delete_device(keyboard);
+       close(fd);
+       libevdev_free(evdev);
 }
 END_TEST
 
@@ -783,9 +832,11 @@ START_TEST(lid_update_hw_on_key_multiple_keyboards)
 {
        struct litest_device *sw = litest_current_device();
        struct libinput *li = sw->libinput;
-       struct libinput *li2;
        struct litest_device *keyboard1, *keyboard2;
-       struct libinput_event *event;
+       struct libevdev *evdev = sw->evdev;
+       struct input_event event;
+       int fd;
+       int rc;
 
        if (!switch_has_lid(sw))
                return;
@@ -797,41 +848,44 @@ START_TEST(lid_update_hw_on_key_multiple_keyboards)
        keyboard2 = litest_add_device(li, LITEST_KEYBOARD_BLADE_STEALTH);
        libinput_dispatch(li);
 
-       /* separate context to listen to the fake hw event */
-       li2 = litest_create_context();
-       libinput_path_add_device(li2,
-                                libevdev_uinput_get_devnode(sw->uinput));
-       litest_drain_events(li2);
-
+       litest_grab_device(sw);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_LID,
                             LIBINPUT_SWITCH_STATE_ON);
        litest_drain_events(li);
+       litest_ungrab_device(sw);
 
-       libinput_dispatch(li2);
-       event = libinput_get_event(li2);
-       litest_is_switch_event(event,
-                              LIBINPUT_SWITCH_LID,
-                              LIBINPUT_SWITCH_STATE_ON);
-       libinput_event_destroy(event);
+       /* Separate direct libevdev context to check if the HW event goes
+        * through */
+       fd = open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY|O_NONBLOCK);
+       ck_assert_int_ge(fd, 0);
+       ck_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0);
+       ck_assert_int_eq(libevdev_get_event_value(evdev, EV_SW, SW_LID), 1);
 
+       /* Typing on the second keyboard should trigger a lid open event */
        litest_event(keyboard2, EV_KEY, KEY_A, 1);
        litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
        litest_event(keyboard2, EV_KEY, KEY_A, 0);
        litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
        litest_drain_events(li);
 
-       litest_wait_for_event(li2);
-       event = libinput_get_event(li2);
-       litest_is_switch_event(event,
-                              LIBINPUT_SWITCH_LID,
-                              LIBINPUT_SWITCH_STATE_OFF);
-       libinput_event_destroy(event);
-       litest_assert_empty_queue(li2);
+       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
+       ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
+       ck_assert_int_eq(event.type, EV_SW);
+       ck_assert_int_eq(event.code, SW_LID);
+       ck_assert_int_eq(event.value, 0);
+       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
+       ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
+       ck_assert_int_eq(event.type, EV_SYN);
+       ck_assert_int_eq(event.code, SYN_REPORT);
+       ck_assert_int_eq(event.value, 0);
+       rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
+       ck_assert_int_eq(rc, -EAGAIN);
 
-       litest_destroy_context(li2);
        litest_delete_device(keyboard1);
        litest_delete_device(keyboard2);
+       close(fd);
+       libevdev_free(evdev);
 }
 END_TEST
 
@@ -860,6 +914,7 @@ START_TEST(tablet_mode_disable_touchpad_on_init)
        if (!switch_has_tablet_mode(sw))
                return;
 
+       litest_grab_device(sw);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_TABLET_MODE,
                             LIBINPUT_SWITCH_STATE_ON);
@@ -884,6 +939,7 @@ START_TEST(tablet_mode_disable_touchpad_on_init)
        litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 10);
        litest_touch_up(touchpad, 0);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
+       litest_ungrab_device(sw);
 
        litest_delete_device(touchpad);
 }
@@ -1098,9 +1154,14 @@ START_TEST(tablet_mode_disable_keyboard_on_resume)
        litest_drain_events(li);
        libinput_suspend(li);
 
+       /* We cannot grab this device because libinput doesn't have an open
+        * fd to this device, we need an independent grab.
+        */
+       libevdev_grab(sw->evdev, LIBEVDEV_GRAB);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_TABLET_MODE,
                             LIBINPUT_SWITCH_STATE_ON);
+       libevdev_grab(sw->evdev, LIBEVDEV_UNGRAB);
        litest_drain_events(li);
 
        libinput_resume(li);
@@ -1131,9 +1192,11 @@ START_TEST(tablet_mode_disable_keyboard_on_resume)
        litest_keyboard_key(keyboard, KEY_A, false);
        litest_assert_empty_queue(li);
 
+       litest_grab_device(sw);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_TABLET_MODE,
                             LIBINPUT_SWITCH_STATE_OFF);
+       litest_ungrab_device(sw);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
 
        litest_keyboard_key(keyboard, KEY_A, true);
@@ -1154,10 +1217,12 @@ START_TEST(tablet_mode_enable_keyboard_on_resume)
                return;
 
        keyboard = litest_add_device(li, LITEST_KEYBOARD);
+       litest_grab_device(sw);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_TABLET_MODE,
                             LIBINPUT_SWITCH_STATE_ON);
        litest_drain_events(li);
+       litest_ungrab_device(sw);
        libinput_suspend(li);
        litest_drain_events(li);
 
@@ -1204,6 +1269,7 @@ START_TEST(tablet_mode_disable_trackpoint)
        litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
 
+       litest_grab_device(sw);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_TABLET_MODE,
                             LIBINPUT_SWITCH_STATE_ON);
@@ -1225,6 +1291,7 @@ START_TEST(tablet_mode_disable_trackpoint)
        litest_event(trackpoint, EV_REL, REL_Y, -1);
        litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
+       litest_ungrab_device(sw);
 
        litest_delete_device(trackpoint);
 }
@@ -1239,6 +1306,7 @@ START_TEST(tablet_mode_disable_trackpoint_on_init)
        if (!switch_has_tablet_mode(sw))
                return;
 
+       litest_grab_device(sw);
        litest_switch_action(sw,
                             LIBINPUT_SWITCH_TABLET_MODE,
                             LIBINPUT_SWITCH_STATE_ON);
@@ -1264,6 +1332,7 @@ START_TEST(tablet_mode_disable_trackpoint_on_init)
        litest_event(trackpoint, EV_REL, REL_Y, -1);
        litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
        litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
+       litest_ungrab_device(sw);
 
        litest_delete_device(trackpoint);
 }
@@ -1279,11 +1348,13 @@ START_TEST(dock_toggle)
 
        litest_drain_events(li);
 
+       litest_grab_device(sw);
        litest_event(sw, EV_SW, SW_DOCK, 1);
        libinput_dispatch(li);
 
        litest_event(sw, EV_SW, SW_DOCK, 0);
        libinput_dispatch(li);
+       litest_ungrab_device(sw);
 
        litest_assert_empty_queue(li);
 }
index 89d6c8ab24ce424ba59fa39f6cfe50aeaa226ae5..96cb8db59c186b65c322bec5d2b6636d5f3bf379 100644 (file)
@@ -6650,6 +6650,9 @@ START_TEST(touchpad_suspend_abba)
        tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
        extmouse = litest_add_device(li, LITEST_MOUSE);
 
+       litest_grab_device(lid);
+       litest_grab_device(tabletmode);
+
        litest_disable_tap(tp->libinput_device);
 
        /* ABBA test for touchpad internal suspend:
@@ -6763,6 +6766,8 @@ START_TEST(touchpad_suspend_abba)
        }
 
 out:
+       litest_ungrab_device(lid);
+       litest_ungrab_device(tabletmode);
        litest_delete_device(lid);
        litest_delete_device(tabletmode);
        litest_delete_device(extmouse);
@@ -6783,6 +6788,8 @@ START_TEST(touchpad_suspend_abab)
        lid = litest_add_device(li, LITEST_LID_SWITCH);
        tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
        extmouse = litest_add_device(li, LITEST_MOUSE);
+       litest_grab_device(lid);
+       litest_grab_device(tabletmode);
 
        litest_disable_tap(tp->libinput_device);
 
@@ -6914,6 +6921,8 @@ START_TEST(touchpad_suspend_abab)
        }
 
 out:
+       litest_ungrab_device(lid);
+       litest_ungrab_device(tabletmode);
        litest_delete_device(lid);
        litest_delete_device(tabletmode);
        litest_delete_device(extmouse);
index 7ca3b5b5c7bf49397610834727fcd09c50af1076..e75414563da06de8802359e2b7a05aa4eb7fb354 100644 (file)
    fun:ioctl
    fun:libevdev_grab
 }
+{
+   ioctl:grab
+   Memcheck:Param
+   ioctl(generic)
+   fun:ioctl
+   fun:grab_device
+}
 {
    bash:execute_command
    Memcheck:Cond