#include <config.h>
#include <check.h>
+#include <fcntl.h>
#include <libinput.h>
#include "libinput-util.h"
litest_drain_events(li);
+ litest_grab_device(dev);
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
libinput_dispatch(li);
}
litest_assert_empty_queue(li);
+ litest_ungrab_device(dev);
}
END_TEST
litest_drain_events(li);
+ litest_grab_device(dev);
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_ON);
libinput_dispatch(li);
libinput_dispatch(li);
litest_assert_empty_queue(li);
+ litest_ungrab_device(dev);
}
END_TEST
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();
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();
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);
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
litest_delete_device(touchpad);
+ litest_ungrab_device(sw);
}
END_TEST
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);
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);
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);
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);
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);
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,
LIBINPUT_SWITCH_STATE_OFF);
litest_assert_empty_queue(li);
}
+ litest_ungrab_device(sw);
litest_delete_device(keyboard);
}
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);
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);
{
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
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);
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);
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
{
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;
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
if (!switch_has_tablet_mode(sw))
return;
+ litest_grab_device(sw);
litest_switch_action(sw,
LIBINPUT_SWITCH_TABLET_MODE,
LIBINPUT_SWITCH_STATE_ON);
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);
}
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);
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);
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);
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);
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);
}
if (!switch_has_tablet_mode(sw))
return;
+ litest_grab_device(sw);
litest_switch_action(sw,
LIBINPUT_SWITCH_TABLET_MODE,
LIBINPUT_SWITCH_STATE_ON);
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);
}
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);
}