Commit 2e257410 authored by Peter Hutterer's avatar Peter Hutterer

test: grab the device before any lid or tablet mode switches

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's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 86946342
Pipeline #173053 passed with stages
in 18 minutes and 26 seconds
......@@ -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;
......
......@@ -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);
......
This diff is collapsed.
......@@ -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);
......
......@@ -59,6 +59,13 @@
fun:ioctl
fun:libevdev_grab
}
{
ioctl:grab
Memcheck:Param
ioctl(generic)
fun:ioctl
fun:grab_device
}
{
bash:execute_command
Memcheck:Cond
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment