2013-12-09 16:36:11 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Red Hat, Inc.
|
|
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2013-12-09 16:36:11 +10:00
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2013-12-09 16:36:11 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <libinput.h>
|
2015-05-26 08:46:05 +10:00
|
|
|
#include <libinput-util.h>
|
2013-12-09 16:36:11 +10:00
|
|
|
#include <libudev.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "litest.h"
|
|
|
|
|
|
|
|
|
|
static int open_restricted(const char *path, int flags, void *data)
|
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
fd = open(path, flags);
|
|
|
|
|
return fd < 0 ? -errno : fd;
|
|
|
|
|
}
|
|
|
|
|
static void close_restricted(int fd, void *data)
|
|
|
|
|
{
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 13:07:38 +10:00
|
|
|
static const struct libinput_interface simple_interface = {
|
2013-12-09 16:36:11 +10:00
|
|
|
.open_restricted = open_restricted,
|
|
|
|
|
.close_restricted = close_restricted,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
START_TEST(udev_create_NULL)
|
|
|
|
|
{
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2013-12-09 16:36:11 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(NULL, NULL, NULL);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(li == NULL);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
2016-03-04 07:50:49 +10:00
|
|
|
li = libinput_udev_create_context(&simple_interface, NULL, NULL);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(li == NULL);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
2014-06-12 11:44:31 +10:00
|
|
|
li = libinput_udev_create_context(NULL, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(li == NULL);
|
2014-06-12 11:44:31 +10:00
|
|
|
|
2016-03-04 07:50:49 +10:00
|
|
|
li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, NULL), -1);
|
2013-12-09 16:36:11 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(udev_create_seat0)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int fd;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
|
|
|
|
fd = libinput_get_fd(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(fd, 0);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
|
|
|
|
/* expect at least one event */
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2013-12-09 16:36:11 +10:00
|
|
|
event = libinput_get_event(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(event);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(udev_create_empty_seat)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int fd;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
|
|
|
|
/* expect a libinput reference, but no events */
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seatdoesntexist"), 0);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
|
|
|
|
fd = libinput_get_fd(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(fd, 0);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2013-12-09 16:36:11 +10:00
|
|
|
event = libinput_get_event(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == NULL);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2019-02-08 11:07:15 +10:00
|
|
|
START_TEST(udev_create_seat_too_long)
|
|
|
|
|
{
|
|
|
|
|
char seatname[258];
|
|
|
|
|
|
|
|
|
|
memset(seatname, 'a', sizeof(seatname) - 1);
|
|
|
|
|
seatname[sizeof(seatname) - 1] = '\0';
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2019-02-08 11:07:15 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
2019-02-08 11:07:15 +10:00
|
|
|
litest_set_log_handler_bug(li);
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, seatname), -1);
|
2019-02-08 11:07:15 +10:00
|
|
|
|
|
|
|
|
litest_assert_empty_queue(li);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-12-23 13:37:28 +10:00
|
|
|
START_TEST(udev_set_user_data)
|
|
|
|
|
{
|
|
|
|
|
int data1, data2;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2014-12-23 13:37:28 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, &data1, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert(libinput_get_user_data(li) == &data1);
|
2014-12-23 13:37:28 +10:00
|
|
|
libinput_set_user_data(li, &data2);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_get_user_data(li) == &data2);
|
2014-12-23 13:37:28 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-12-09 16:36:11 +10:00
|
|
|
START_TEST(udev_added_seat_default)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
2014-01-15 16:31:29 +10:00
|
|
|
struct libinput_device *device;
|
2013-12-09 16:36:11 +10:00
|
|
|
struct libinput_seat *seat;
|
|
|
|
|
const char *seat_name;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
2021-08-04 08:53:47 +10:00
|
|
|
/* Drop any events from other devices */
|
|
|
|
|
litest_drain_events(li);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
2021-08-04 08:53:47 +10:00
|
|
|
/* Now create our own device, it should be in the "default"
|
|
|
|
|
* logical seat. This test may fail if there is a local rule changing
|
|
|
|
|
* that, but it'll be fine for the 99% case. */
|
2025-04-07 15:46:51 +10:00
|
|
|
_unused_ _destroy_(litest_device) *dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL);
|
2024-09-11 16:23:08 +10:00
|
|
|
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
|
2021-08-04 08:53:47 +10:00
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
seat = libinput_device_get_seat(device);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(seat);
|
2013-12-09 16:36:11 +10:00
|
|
|
|
2021-08-04 08:53:47 +10:00
|
|
|
seat_name = libinput_seat_get_logical_name(seat);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_str_eq(seat_name, "default");
|
2021-08-04 08:53:47 +10:00
|
|
|
libinput_event_destroy(event);
|
2013-12-09 16:36:11 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-11-19 15:42:54 +10:00
|
|
|
START_TEST(udev_change_seat)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput_seat *seat1, *seat2;
|
|
|
|
|
const char *seat1_name;
|
|
|
|
|
const char *seat2_name = "new seat";
|
|
|
|
|
int rc;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2014-11-19 15:42:54 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-11-19 15:42:54 +10:00
|
|
|
|
2021-08-04 08:53:47 +10:00
|
|
|
/* Drop any events from other devices */
|
|
|
|
|
litest_drain_events(li);
|
2014-11-19 15:42:54 +10:00
|
|
|
|
2021-08-04 08:53:47 +10:00
|
|
|
/* Now create our own device, it should be in the "default"
|
|
|
|
|
* logical seat. This test may fail if there is a local rule changing
|
|
|
|
|
* that, but it'll be fine for the 99% case. */
|
2025-04-07 15:31:46 +10:00
|
|
|
_unused_ _destroy_(litest_device) *dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL);
|
2024-09-11 16:23:08 +10:00
|
|
|
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
|
2021-08-04 08:53:47 +10:00
|
|
|
event = libinput_get_event(li);
|
2014-11-19 15:42:54 +10:00
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
libinput_device_ref(device);
|
|
|
|
|
|
|
|
|
|
seat1 = libinput_device_get_seat(device);
|
|
|
|
|
libinput_seat_ref(seat1);
|
|
|
|
|
|
|
|
|
|
seat1_name = libinput_seat_get_logical_name(seat1);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
2021-08-04 08:53:47 +10:00
|
|
|
/* Changing the logical seat name will remove and re-add the device */
|
2014-11-19 15:42:54 +10:00
|
|
|
rc = libinput_device_set_seat_logical_name(device,
|
|
|
|
|
seat2_name);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(rc, 0);
|
2014-11-19 15:42:54 +10:00
|
|
|
|
2025-04-07 20:09:20 +10:00
|
|
|
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_REMOVED);
|
2014-11-19 15:42:54 +10:00
|
|
|
event = libinput_get_event(li);
|
2025-04-08 07:40:27 +10:00
|
|
|
litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED);
|
|
|
|
|
litest_assert_ptr_eq(libinput_event_get_device(event), device);
|
2014-11-19 15:42:54 +10:00
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
2025-04-07 20:09:20 +10:00
|
|
|
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
|
2014-11-19 15:42:54 +10:00
|
|
|
event = libinput_get_event(li);
|
2025-04-08 07:40:27 +10:00
|
|
|
litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
litest_assert_ptr_ne(libinput_event_get_device(event), device);
|
2014-11-19 15:42:54 +10:00
|
|
|
libinput_device_unref(device);
|
|
|
|
|
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
seat2 = libinput_device_get_seat(device);
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_str_ne(libinput_seat_get_logical_name(seat2),
|
2014-11-19 15:42:54 +10:00
|
|
|
seat1_name);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_str_eq(libinput_seat_get_logical_name(seat2),
|
2014-11-19 15:42:54 +10:00
|
|
|
seat2_name);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
libinput_seat_unref(seat1);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-01-08 17:39:27 +10:00
|
|
|
START_TEST(udev_double_suspend)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int fd;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2014-01-08 17:39:27 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2014-01-08 17:39:27 +10:00
|
|
|
|
|
|
|
|
fd = libinput_get_fd(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(fd, 0);
|
2014-01-08 17:39:27 +10:00
|
|
|
|
|
|
|
|
/* expect at least one event */
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(litest_dispatch(li), 0);
|
2014-01-08 17:39:27 +10:00
|
|
|
event = libinput_get_event(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(event);
|
2014-01-08 17:39:27 +10:00
|
|
|
|
|
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(udev_double_resume)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int fd;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2014-01-08 17:39:27 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2014-01-08 17:39:27 +10:00
|
|
|
|
|
|
|
|
fd = libinput_get_fd(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(fd, 0);
|
2014-01-08 17:39:27 +10:00
|
|
|
|
|
|
|
|
/* expect at least one event */
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(litest_dispatch(li), 0);
|
2014-01-08 17:39:27 +10:00
|
|
|
event = libinput_get_event(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(event);
|
2014-01-08 17:39:27 +10:00
|
|
|
|
|
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-01-15 21:33:00 +01:00
|
|
|
static void
|
|
|
|
|
process_events_count_devices(struct libinput *li, int *device_count)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
switch (libinput_event_get_type(event)) {
|
2013-12-19 12:04:24 +10:00
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
2014-01-15 21:33:00 +01:00
|
|
|
(*device_count)++;
|
|
|
|
|
break;
|
2013-12-19 12:04:24 +10:00
|
|
|
case LIBINPUT_EVENT_DEVICE_REMOVED:
|
2014-01-15 21:33:00 +01:00
|
|
|
(*device_count)--;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
START_TEST(udev_suspend_resume)
|
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
int num_devices = 0;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2014-01-15 21:33:00 +01:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2014-01-15 21:33:00 +01:00
|
|
|
|
|
|
|
|
fd = libinput_get_fd(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(fd, 0);
|
2014-01-15 21:33:00 +01:00
|
|
|
|
|
|
|
|
/* Check that at least one device was discovered after creation. */
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(litest_dispatch(li), 0);
|
2014-01-15 21:33:00 +01:00
|
|
|
process_events_count_devices(li, &num_devices);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(num_devices, 0);
|
2014-01-15 21:33:00 +01:00
|
|
|
|
|
|
|
|
/* Check that after a suspend, no devices are left. */
|
|
|
|
|
libinput_suspend(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(litest_dispatch(li), 0);
|
2014-01-15 21:33:00 +01:00
|
|
|
process_events_count_devices(li, &num_devices);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(num_devices, 0);
|
2014-01-15 21:33:00 +01:00
|
|
|
|
|
|
|
|
/* Check that after a resume, at least one device is discovered. */
|
|
|
|
|
libinput_resume(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(litest_dispatch(li), 0);
|
2014-01-15 21:33:00 +01:00
|
|
|
process_events_count_devices(li, &num_devices);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(num_devices, 0);
|
2014-01-15 21:33:00 +01:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2018-02-16 16:42:00 +10:00
|
|
|
START_TEST(udev_resume_before_seat)
|
|
|
|
|
{
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2018-02-16 16:42:00 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
2018-02-16 16:42:00 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
int rc = libinput_resume(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(rc, 0);
|
2018-02-16 16:42:00 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(udev_suspend_resume_before_seat)
|
|
|
|
|
{
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2018-02-16 16:42:00 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
2018-02-16 16:42:00 +10:00
|
|
|
|
|
|
|
|
libinput_suspend(li);
|
2025-04-07 15:46:51 +10:00
|
|
|
int rc = libinput_resume(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(rc, 0);
|
2018-02-16 16:42:00 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-01-28 15:54:34 +10:00
|
|
|
START_TEST(udev_device_sysname)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *ev;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
const char *sysname;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2014-01-28 15:54:34 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2014-01-28 15:54:34 +10:00
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-01-28 15:54:34 +10:00
|
|
|
|
|
|
|
|
while ((ev = libinput_get_event(li))) {
|
2015-07-09 16:46:00 +10:00
|
|
|
if (libinput_event_get_type(ev) !=
|
|
|
|
|
LIBINPUT_EVENT_DEVICE_ADDED) {
|
|
|
|
|
libinput_event_destroy(ev);
|
2014-01-28 15:54:34 +10:00
|
|
|
continue;
|
2015-07-09 16:46:00 +10:00
|
|
|
}
|
2014-01-28 15:54:34 +10:00
|
|
|
|
|
|
|
|
device = libinput_event_get_device(ev);
|
|
|
|
|
sysname = libinput_device_get_sysname(device);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(sysname);
|
2024-10-11 13:55:56 +10:00
|
|
|
litest_assert_int_gt(strlen(sysname), 1U);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(strchr(sysname, '/') == NULL);
|
2025-01-09 09:04:54 +10:00
|
|
|
litest_assert(strstartswith(sysname, "event"));
|
2014-01-28 15:54:34 +10:00
|
|
|
libinput_event_destroy(ev);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-02-10 11:40:55 +10:00
|
|
|
START_TEST(udev_seat_recycle)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *ev;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput_seat *saved_seat = NULL;
|
|
|
|
|
struct libinput_seat *seat;
|
|
|
|
|
int data = 0;
|
|
|
|
|
int found = 0;
|
|
|
|
|
void *user_data;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2014-02-10 11:40:55 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2014-02-10 11:40:55 +10:00
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-02-10 11:40:55 +10:00
|
|
|
while ((ev = libinput_get_event(li))) {
|
|
|
|
|
switch (libinput_event_get_type(ev)) {
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
|
|
|
|
if (saved_seat)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
device = libinput_event_get_device(ev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(device);
|
2014-02-10 11:40:55 +10:00
|
|
|
saved_seat = libinput_device_get_seat(device);
|
|
|
|
|
libinput_seat_set_user_data(saved_seat, &data);
|
|
|
|
|
libinput_seat_ref(saved_seat);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(ev);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(saved_seat);
|
2014-02-10 11:40:55 +10:00
|
|
|
|
|
|
|
|
libinput_suspend(li);
|
|
|
|
|
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-02-10 11:40:55 +10:00
|
|
|
while ((ev = libinput_get_event(li))) {
|
|
|
|
|
switch (libinput_event_get_type(ev)) {
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
|
|
|
|
device = libinput_event_get_device(ev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(device);
|
2014-02-10 11:40:55 +10:00
|
|
|
|
|
|
|
|
seat = libinput_device_get_seat(device);
|
|
|
|
|
user_data = libinput_seat_get_user_data(seat);
|
|
|
|
|
if (user_data == &data) {
|
|
|
|
|
found = 1;
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(seat == saved_seat);
|
2014-02-10 11:40:55 +10:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(ev);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(found == 1);
|
2014-02-10 11:40:55 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-01-13 11:46:38 +10:00
|
|
|
START_TEST(udev_path_add_device)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2017-01-13 11:46:38 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2017-01-13 11:46:38 +10:00
|
|
|
|
|
|
|
|
litest_set_log_handler_bug(li);
|
|
|
|
|
device = libinput_path_add_device(li, "/dev/input/event0");
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(device == NULL);
|
2017-01-13 11:46:38 +10:00
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(udev_path_remove_device)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2017-01-13 11:46:38 +10:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-01-13 11:46:38 +10:00
|
|
|
|
2024-09-11 16:23:08 +10:00
|
|
|
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
|
2017-01-13 11:46:38 +10:00
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
device = libinput_event_get_device(event);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(device);
|
2017-01-13 11:46:38 +10:00
|
|
|
|
|
|
|
|
/* no effect bug a bug log msg */
|
|
|
|
|
litest_set_log_handler_bug(li);
|
|
|
|
|
libinput_path_remove_device(device);
|
|
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-08-17 01:25:24 +02:00
|
|
|
START_TEST(udev_ignore_device)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
const char *devname;
|
|
|
|
|
|
2025-04-07 15:31:46 +10:00
|
|
|
_destroy_(litest_device) *dev = litest_create(LITEST_IGNORED_MOUSE, NULL, NULL, NULL, NULL);
|
2017-08-17 01:25:24 +02:00
|
|
|
devname = libevdev_get_name(dev->evdev);
|
|
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(udev) *udev = udev_new();
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(udev);
|
2017-08-17 01:25:24 +02:00
|
|
|
|
2025-04-07 15:46:51 +10:00
|
|
|
_unref_(libinput) *li = libinput_udev_create_context(&simple_interface, NULL, udev);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
2017-08-17 01:25:24 +02:00
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-08-17 01:25:24 +02:00
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(event);
|
2017-08-17 01:25:24 +02:00
|
|
|
while (event) {
|
|
|
|
|
if (libinput_event_get_type(event) ==
|
|
|
|
|
LIBINPUT_EVENT_DEVICE_ADDED) {
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
name = libinput_device_get_name(device);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_str_ne(devname, name);
|
2017-08-17 01:25:24 +02:00
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-08-17 01:25:24 +02:00
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2018-03-21 12:54:10 +10:00
|
|
|
TEST_COLLECTION(udev)
|
2014-07-14 00:01:10 +02:00
|
|
|
{
|
2021-02-05 14:51:02 +10:00
|
|
|
litest_add_no_device(udev_create_NULL);
|
|
|
|
|
litest_add_no_device(udev_create_seat0);
|
|
|
|
|
litest_add_no_device(udev_create_empty_seat);
|
|
|
|
|
litest_add_no_device(udev_create_seat_too_long);
|
|
|
|
|
litest_add_no_device(udev_set_user_data);
|
|
|
|
|
|
|
|
|
|
litest_add_no_device(udev_added_seat_default);
|
|
|
|
|
litest_add_no_device(udev_change_seat);
|
|
|
|
|
|
|
|
|
|
litest_add_for_device(udev_double_suspend, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
litest_add_for_device(udev_double_resume, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
litest_add_for_device(udev_suspend_resume, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
litest_add_for_device(udev_resume_before_seat, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
litest_add_for_device(udev_suspend_resume_before_seat, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
litest_add_for_device(udev_device_sysname, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
litest_add_for_device(udev_seat_recycle, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
|
|
|
|
|
litest_add_no_device(udev_path_add_device);
|
|
|
|
|
litest_add_for_device(udev_path_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
|
|
|
|
|
litest_add_no_device(udev_ignore_device);
|
2013-12-09 16:36:11 +10:00
|
|
|
}
|