mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 05:40:04 +01:00
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 <peter.hutterer@who-t.net>
This commit is contained in:
parent
86946342fb
commit
2e25741061
5 changed files with 198 additions and 56 deletions
|
|
@ -263,6 +263,49 @@ struct litest_device *litest_current_device(void)
|
||||||
return current_device;
|
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)
|
void litest_set_current_device(struct litest_device *device)
|
||||||
{
|
{
|
||||||
current_device = device;
|
current_device = device;
|
||||||
|
|
@ -784,7 +827,13 @@ open_restricted(const char *path, int flags, void *userdata)
|
||||||
p = zalloc(sizeof *p);
|
p = zalloc(sizeof *p);
|
||||||
p->path = safe_strdup(path);
|
p->path = safe_strdup(path);
|
||||||
p->fd = fd;
|
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;
|
return fd;
|
||||||
|
|
|
||||||
|
|
@ -513,6 +513,12 @@ litest_add_device_with_overrides(struct libinput *libinput,
|
||||||
struct litest_device *
|
struct litest_device *
|
||||||
litest_current_device(void);
|
litest_current_device(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
litest_grab_device(struct litest_device *d);
|
||||||
|
|
||||||
|
void
|
||||||
|
litest_ungrab_device(struct litest_device *d);
|
||||||
|
|
||||||
void
|
void
|
||||||
litest_delete_device(struct litest_device *d);
|
litest_delete_device(struct litest_device *d);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <libinput.h>
|
#include <libinput.h>
|
||||||
|
|
||||||
#include "libinput-util.h"
|
#include "libinput-util.h"
|
||||||
|
|
@ -113,6 +114,7 @@ START_TEST(switch_toggle)
|
||||||
|
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
|
litest_grab_device(dev);
|
||||||
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
|
|
@ -134,6 +136,7 @@ START_TEST(switch_toggle)
|
||||||
}
|
}
|
||||||
|
|
||||||
litest_assert_empty_queue(li);
|
litest_assert_empty_queue(li);
|
||||||
|
litest_ungrab_device(dev);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
@ -149,6 +152,7 @@ START_TEST(switch_toggle_double)
|
||||||
|
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
|
litest_grab_device(dev);
|
||||||
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
|
|
@ -162,6 +166,7 @@ START_TEST(switch_toggle_double)
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
litest_assert_empty_queue(li);
|
litest_assert_empty_queue(li);
|
||||||
|
litest_ungrab_device(dev);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
@ -194,7 +199,9 @@ START_TEST(switch_down_on_init)
|
||||||
if (sw == LIBINPUT_SWITCH_LID && !lid_switch_is_reliable(dev))
|
if (sw == LIBINPUT_SWITCH_LID && !lid_switch_is_reliable(dev))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
litest_grab_device(dev);
|
||||||
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
|
||||||
|
litest_ungrab_device(dev);
|
||||||
|
|
||||||
/* need separate context to test */
|
/* need separate context to test */
|
||||||
li = litest_create_context();
|
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))
|
if (sw == LIBINPUT_SWITCH_LID && lid_switch_is_reliable(dev))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
litest_grab_device(dev);
|
||||||
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
|
||||||
|
litest_ungrab_device(dev);
|
||||||
|
|
||||||
/* need separate context to test */
|
/* need separate context to test */
|
||||||
li = litest_create_context();
|
li = litest_create_context();
|
||||||
|
|
@ -279,6 +288,8 @@ START_TEST(switch_disable_touchpad)
|
||||||
litest_disable_tap(touchpad->libinput_device);
|
litest_disable_tap(touchpad->libinput_device);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
|
|
||||||
/* switch is on - no events */
|
/* switch is on - no events */
|
||||||
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
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_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
||||||
|
|
||||||
litest_delete_device(touchpad);
|
litest_delete_device(touchpad);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
}
|
}
|
||||||
END_TEST
|
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_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
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_move_to(touchpad, 0, 70, 50, 50, 50, 5);
|
||||||
litest_touch_up(touchpad, 0);
|
litest_touch_up(touchpad, 0);
|
||||||
|
|
@ -345,8 +359,10 @@ START_TEST(switch_disable_touchpad_edge_scroll)
|
||||||
|
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
litest_touch_down(touchpad, 0, 99, 20);
|
litest_touch_down(touchpad, 0, 99, 20);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
@ -390,7 +406,9 @@ START_TEST(switch_disable_touchpad_edge_scroll_interrupt)
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
event = libinput_get_event(li);
|
event = libinput_get_event(li);
|
||||||
|
|
@ -458,7 +476,9 @@ START_TEST(switch_dont_resume_disabled_touchpad)
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
/* switch is on - no events */
|
/* switch is on - no events */
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
||||||
|
|
||||||
litest_touch_down(touchpad, 0, 50, 50);
|
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);
|
litest_assert_empty_queue(li);
|
||||||
|
|
||||||
/* switch is on - no events */
|
/* switch is on - no events */
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
||||||
|
|
||||||
litest_touch_down(touchpad, 0, 50, 50);
|
litest_touch_down(touchpad, 0, 50, 50);
|
||||||
|
|
@ -536,6 +558,7 @@ START_TEST(lid_open_on_key)
|
||||||
|
|
||||||
keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
litest_switch_action(sw,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_LID,
|
LIBINPUT_SWITCH_LID,
|
||||||
|
|
@ -561,6 +584,7 @@ START_TEST(lid_open_on_key)
|
||||||
LIBINPUT_SWITCH_STATE_OFF);
|
LIBINPUT_SWITCH_STATE_OFF);
|
||||||
litest_assert_empty_queue(li);
|
litest_assert_empty_queue(li);
|
||||||
}
|
}
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
litest_delete_device(keyboard);
|
litest_delete_device(keyboard);
|
||||||
}
|
}
|
||||||
|
|
@ -578,9 +602,11 @@ START_TEST(lid_open_on_key_touchpad_enabled)
|
||||||
keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
||||||
touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
|
touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_LID,
|
LIBINPUT_SWITCH_LID,
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
LIBINPUT_SWITCH_STATE_ON);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
litest_event(keyboard, EV_KEY, KEY_A, 1);
|
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);
|
keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_ON);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF);
|
litest_switch_action(sw, which, LIBINPUT_SWITCH_STATE_OFF);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
litest_delete_device(keyboard);
|
litest_delete_device(keyboard);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
@ -681,49 +709,54 @@ START_TEST(lid_update_hw_on_key)
|
||||||
{
|
{
|
||||||
struct litest_device *sw = litest_current_device();
|
struct litest_device *sw = litest_current_device();
|
||||||
struct libinput *li = sw->libinput;
|
struct libinput *li = sw->libinput;
|
||||||
struct libinput *li2;
|
|
||||||
struct litest_device *keyboard;
|
struct litest_device *keyboard;
|
||||||
struct libinput_event *event;
|
struct libevdev *evdev;
|
||||||
|
struct input_event event;
|
||||||
|
int fd;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (!switch_has_lid(sw))
|
if (!switch_has_lid(sw))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
||||||
|
|
||||||
/* separate context to listen to the fake hw event */
|
litest_grab_device(sw);
|
||||||
li2 = litest_create_context();
|
|
||||||
libinput_path_add_device(li2,
|
|
||||||
libevdev_uinput_get_devnode(sw->uinput));
|
|
||||||
litest_drain_events(li2);
|
|
||||||
|
|
||||||
litest_switch_action(sw,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_LID,
|
LIBINPUT_SWITCH_LID,
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
LIBINPUT_SWITCH_STATE_ON);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
libinput_dispatch(li2);
|
/* Separate direct libevdev context to check if the HW event goes
|
||||||
event = libinput_get_event(li2);
|
* through */
|
||||||
litest_is_switch_event(event,
|
fd = open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY|O_NONBLOCK);
|
||||||
LIBINPUT_SWITCH_LID,
|
ck_assert_int_ge(fd, 0);
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
ck_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0);
|
||||||
libinput_event_destroy(event);
|
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_KEY, KEY_A, 1);
|
||||||
litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
|
litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
|
||||||
litest_event(keyboard, EV_KEY, KEY_A, 0);
|
litest_event(keyboard, EV_KEY, KEY_A, 0);
|
||||||
litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
|
litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
litest_wait_for_event(li2);
|
rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
|
||||||
event = libinput_get_event(li2);
|
ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
|
||||||
litest_is_switch_event(event,
|
ck_assert_int_eq(event.type, EV_SW);
|
||||||
LIBINPUT_SWITCH_LID,
|
ck_assert_int_eq(event.code, SW_LID);
|
||||||
LIBINPUT_SWITCH_STATE_OFF);
|
ck_assert_int_eq(event.value, 0);
|
||||||
libinput_event_destroy(event);
|
rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
|
||||||
litest_assert_empty_queue(li2);
|
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);
|
litest_delete_device(keyboard);
|
||||||
|
close(fd);
|
||||||
|
libevdev_free(evdev);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
@ -733,17 +766,22 @@ START_TEST(lid_update_hw_on_key_closed_on_init)
|
||||||
struct libinput *li;
|
struct libinput *li;
|
||||||
struct litest_device *keyboard;
|
struct litest_device *keyboard;
|
||||||
struct libevdev *evdev = sw->evdev;
|
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,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_LID,
|
LIBINPUT_SWITCH_LID,
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
LIBINPUT_SWITCH_STATE_ON);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
/* Make sure kernel state is right */
|
/* Separate direct libevdev context to check if the HW event goes
|
||||||
libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev);
|
* through */
|
||||||
while (libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_SYNC, &ev) >= 0)
|
fd = open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY|O_NONBLOCK);
|
||||||
;
|
ck_assert_int_ge(fd, 0);
|
||||||
ck_assert(libevdev_get_event_value(evdev, EV_SW, SW_LID));
|
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);
|
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,
|
libinput_path_add_device(li,
|
||||||
libevdev_uinput_get_devnode(keyboard->uinput));
|
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) {
|
while (libinput_next_event_type(li) != LIBINPUT_EVENT_NONE) {
|
||||||
ck_assert_int_ne(libinput_next_event_type(li),
|
ck_assert_int_ne(libinput_next_event_type(li),
|
||||||
LIBINPUT_EVENT_SWITCH_TOGGLE);
|
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);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
|
||||||
|
|
||||||
/* Make sure kernel state has updated */
|
/* Make sure kernel state has updated */
|
||||||
libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev);
|
rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
|
||||||
while (libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_SYNC, &ev) >= 0)
|
ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
|
||||||
;
|
ck_assert_int_eq(event.type, EV_SW);
|
||||||
ck_assert(!libevdev_get_event_value(evdev, EV_SW, SW_LID));
|
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_destroy_context(li);
|
||||||
litest_delete_device(keyboard);
|
litest_delete_device(keyboard);
|
||||||
|
close(fd);
|
||||||
|
libevdev_free(evdev);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
@ -783,9 +832,11 @@ START_TEST(lid_update_hw_on_key_multiple_keyboards)
|
||||||
{
|
{
|
||||||
struct litest_device *sw = litest_current_device();
|
struct litest_device *sw = litest_current_device();
|
||||||
struct libinput *li = sw->libinput;
|
struct libinput *li = sw->libinput;
|
||||||
struct libinput *li2;
|
|
||||||
struct litest_device *keyboard1, *keyboard2;
|
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))
|
if (!switch_has_lid(sw))
|
||||||
return;
|
return;
|
||||||
|
|
@ -797,41 +848,44 @@ START_TEST(lid_update_hw_on_key_multiple_keyboards)
|
||||||
keyboard2 = litest_add_device(li, LITEST_KEYBOARD_BLADE_STEALTH);
|
keyboard2 = litest_add_device(li, LITEST_KEYBOARD_BLADE_STEALTH);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
/* separate context to listen to the fake hw event */
|
litest_grab_device(sw);
|
||||||
li2 = litest_create_context();
|
|
||||||
libinput_path_add_device(li2,
|
|
||||||
libevdev_uinput_get_devnode(sw->uinput));
|
|
||||||
litest_drain_events(li2);
|
|
||||||
|
|
||||||
litest_switch_action(sw,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_LID,
|
LIBINPUT_SWITCH_LID,
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
LIBINPUT_SWITCH_STATE_ON);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
libinput_dispatch(li2);
|
/* Separate direct libevdev context to check if the HW event goes
|
||||||
event = libinput_get_event(li2);
|
* through */
|
||||||
litest_is_switch_event(event,
|
fd = open(libevdev_uinput_get_devnode(sw->uinput), O_RDONLY|O_NONBLOCK);
|
||||||
LIBINPUT_SWITCH_LID,
|
ck_assert_int_ge(fd, 0);
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
ck_assert_int_eq(libevdev_new_from_fd(fd, &evdev), 0);
|
||||||
libinput_event_destroy(event);
|
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_KEY, KEY_A, 1);
|
||||||
litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
|
litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
|
||||||
litest_event(keyboard2, EV_KEY, KEY_A, 0);
|
litest_event(keyboard2, EV_KEY, KEY_A, 0);
|
||||||
litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
|
litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
litest_wait_for_event(li2);
|
rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
|
||||||
event = libinput_get_event(li2);
|
ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
|
||||||
litest_is_switch_event(event,
|
ck_assert_int_eq(event.type, EV_SW);
|
||||||
LIBINPUT_SWITCH_LID,
|
ck_assert_int_eq(event.code, SW_LID);
|
||||||
LIBINPUT_SWITCH_STATE_OFF);
|
ck_assert_int_eq(event.value, 0);
|
||||||
libinput_event_destroy(event);
|
rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
|
||||||
litest_assert_empty_queue(li2);
|
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(keyboard1);
|
||||||
litest_delete_device(keyboard2);
|
litest_delete_device(keyboard2);
|
||||||
|
close(fd);
|
||||||
|
libevdev_free(evdev);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
@ -860,6 +914,7 @@ START_TEST(tablet_mode_disable_touchpad_on_init)
|
||||||
if (!switch_has_tablet_mode(sw))
|
if (!switch_has_tablet_mode(sw))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_TABLET_MODE,
|
LIBINPUT_SWITCH_TABLET_MODE,
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
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_move_to(touchpad, 0, 50, 50, 70, 50, 10);
|
||||||
litest_touch_up(touchpad, 0);
|
litest_touch_up(touchpad, 0);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
litest_delete_device(touchpad);
|
litest_delete_device(touchpad);
|
||||||
}
|
}
|
||||||
|
|
@ -1098,9 +1154,14 @@ START_TEST(tablet_mode_disable_keyboard_on_resume)
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
libinput_suspend(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,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_TABLET_MODE,
|
LIBINPUT_SWITCH_TABLET_MODE,
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
LIBINPUT_SWITCH_STATE_ON);
|
||||||
|
libevdev_grab(sw->evdev, LIBEVDEV_UNGRAB);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
libinput_resume(li);
|
libinput_resume(li);
|
||||||
|
|
@ -1131,9 +1192,11 @@ START_TEST(tablet_mode_disable_keyboard_on_resume)
|
||||||
litest_keyboard_key(keyboard, KEY_A, false);
|
litest_keyboard_key(keyboard, KEY_A, false);
|
||||||
litest_assert_empty_queue(li);
|
litest_assert_empty_queue(li);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_TABLET_MODE,
|
LIBINPUT_SWITCH_TABLET_MODE,
|
||||||
LIBINPUT_SWITCH_STATE_OFF);
|
LIBINPUT_SWITCH_STATE_OFF);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
|
||||||
|
|
||||||
litest_keyboard_key(keyboard, KEY_A, true);
|
litest_keyboard_key(keyboard, KEY_A, true);
|
||||||
|
|
@ -1154,10 +1217,12 @@ START_TEST(tablet_mode_enable_keyboard_on_resume)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_TABLET_MODE,
|
LIBINPUT_SWITCH_TABLET_MODE,
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
LIBINPUT_SWITCH_STATE_ON);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
libinput_suspend(li);
|
libinput_suspend(li);
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
|
|
@ -1204,6 +1269,7 @@ START_TEST(tablet_mode_disable_trackpoint)
|
||||||
litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
|
litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_TABLET_MODE,
|
LIBINPUT_SWITCH_TABLET_MODE,
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
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_REL, REL_Y, -1);
|
||||||
litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
|
litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
litest_delete_device(trackpoint);
|
litest_delete_device(trackpoint);
|
||||||
}
|
}
|
||||||
|
|
@ -1239,6 +1306,7 @@ START_TEST(tablet_mode_disable_trackpoint_on_init)
|
||||||
if (!switch_has_tablet_mode(sw))
|
if (!switch_has_tablet_mode(sw))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_switch_action(sw,
|
litest_switch_action(sw,
|
||||||
LIBINPUT_SWITCH_TABLET_MODE,
|
LIBINPUT_SWITCH_TABLET_MODE,
|
||||||
LIBINPUT_SWITCH_STATE_ON);
|
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_REL, REL_Y, -1);
|
||||||
litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
|
litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
|
||||||
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
litest_delete_device(trackpoint);
|
litest_delete_device(trackpoint);
|
||||||
}
|
}
|
||||||
|
|
@ -1279,11 +1348,13 @@ START_TEST(dock_toggle)
|
||||||
|
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
|
litest_grab_device(sw);
|
||||||
litest_event(sw, EV_SW, SW_DOCK, 1);
|
litest_event(sw, EV_SW, SW_DOCK, 1);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
litest_event(sw, EV_SW, SW_DOCK, 0);
|
litest_event(sw, EV_SW, SW_DOCK, 0);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
litest_ungrab_device(sw);
|
||||||
|
|
||||||
litest_assert_empty_queue(li);
|
litest_assert_empty_queue(li);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6650,6 +6650,9 @@ START_TEST(touchpad_suspend_abba)
|
||||||
tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
|
tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
|
||||||
extmouse = litest_add_device(li, LITEST_MOUSE);
|
extmouse = litest_add_device(li, LITEST_MOUSE);
|
||||||
|
|
||||||
|
litest_grab_device(lid);
|
||||||
|
litest_grab_device(tabletmode);
|
||||||
|
|
||||||
litest_disable_tap(tp->libinput_device);
|
litest_disable_tap(tp->libinput_device);
|
||||||
|
|
||||||
/* ABBA test for touchpad internal suspend:
|
/* ABBA test for touchpad internal suspend:
|
||||||
|
|
@ -6763,6 +6766,8 @@ START_TEST(touchpad_suspend_abba)
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
litest_ungrab_device(lid);
|
||||||
|
litest_ungrab_device(tabletmode);
|
||||||
litest_delete_device(lid);
|
litest_delete_device(lid);
|
||||||
litest_delete_device(tabletmode);
|
litest_delete_device(tabletmode);
|
||||||
litest_delete_device(extmouse);
|
litest_delete_device(extmouse);
|
||||||
|
|
@ -6783,6 +6788,8 @@ START_TEST(touchpad_suspend_abab)
|
||||||
lid = litest_add_device(li, LITEST_LID_SWITCH);
|
lid = litest_add_device(li, LITEST_LID_SWITCH);
|
||||||
tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
|
tabletmode = litest_add_device(li, LITEST_THINKPAD_EXTRABUTTONS);
|
||||||
extmouse = litest_add_device(li, LITEST_MOUSE);
|
extmouse = litest_add_device(li, LITEST_MOUSE);
|
||||||
|
litest_grab_device(lid);
|
||||||
|
litest_grab_device(tabletmode);
|
||||||
|
|
||||||
litest_disable_tap(tp->libinput_device);
|
litest_disable_tap(tp->libinput_device);
|
||||||
|
|
||||||
|
|
@ -6914,6 +6921,8 @@ START_TEST(touchpad_suspend_abab)
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
litest_ungrab_device(lid);
|
||||||
|
litest_ungrab_device(tabletmode);
|
||||||
litest_delete_device(lid);
|
litest_delete_device(lid);
|
||||||
litest_delete_device(tabletmode);
|
litest_delete_device(tabletmode);
|
||||||
litest_delete_device(extmouse);
|
litest_delete_device(extmouse);
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,13 @@
|
||||||
fun:ioctl
|
fun:ioctl
|
||||||
fun:libevdev_grab
|
fun:libevdev_grab
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
ioctl:grab
|
||||||
|
Memcheck:Param
|
||||||
|
ioctl(generic)
|
||||||
|
fun:ioctl
|
||||||
|
fun:grab_device
|
||||||
|
}
|
||||||
{
|
{
|
||||||
bash:execute_command
|
bash:execute_command
|
||||||
Memcheck:Cond
|
Memcheck:Cond
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue