[PATCH libinput 2/7] test: set the abs resolution after creating the device

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 15 22:18:41 PDT 2014


Until uinput gets that capability (likely not before 3.17) all we can do is a
racy approach of setting it after creating it. That won't work well for
anything test where libinput is already listening to udev when the device is
created, but it does work for those cases where libinput is started after the
device was initialized.

And it's a better alternative than not testing anything dependent on
resolution settings.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/litest.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/test/litest.c b/test/litest.c
index adcbf3e..f32f346 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -808,13 +808,14 @@ litest_assert_empty_queue(struct libinput *li)
 struct libevdev_uinput *
 litest_create_uinput_device_from_description(const char *name,
 					     const struct input_id *id,
-					     const struct input_absinfo *abs,
+					     const struct input_absinfo *abs_info,
 					     const int *events)
 {
 	struct libevdev_uinput *uinput;
 	struct libevdev *dev;
 	int type, code;
-	int rc;
+	int rc, fd;
+	const struct input_absinfo *abs;
 	const struct input_absinfo default_abs = {
 		.value = 0,
 		.minimum = 0,
@@ -824,6 +825,7 @@ litest_create_uinput_device_from_description(const char *name,
 		.resolution = 100
 	};
 	char buf[512];
+	const char *devnode;
 
 	dev = libevdev_new();
 	ck_assert(dev != NULL);
@@ -836,6 +838,7 @@ litest_create_uinput_device_from_description(const char *name,
 		libevdev_set_id_product(dev, id->product);
 	}
 
+	abs = abs_info;
 	while (abs && abs->value != -1) {
 		rc = libevdev_enable_event_code(dev, EV_ABS,
 						abs->value, abs);
@@ -864,6 +867,31 @@ litest_create_uinput_device_from_description(const char *name,
 
 	libevdev_free(dev);
 
+	/* uinput does not yet support setting the resolution, so we set it
+	 * afterwards. This is of course racy as hell but the way we
+	 * _generally_ use this function by the time libinput uses the
+	 * device, we're finished here */
+
+	devnode = libevdev_uinput_get_devnode(uinput);
+	ck_assert_notnull(devnode);
+	fd = open(devnode, O_RDONLY);
+	ck_assert_int_gt(fd, -1);
+	rc = libevdev_new_from_fd(fd, &dev);
+	ck_assert_int_eq(rc, 0);
+
+	abs = abs_info;
+	while (abs && abs->value != -1) {
+		if (abs->resolution != 0) {
+			rc = libevdev_kernel_set_abs_info(dev,
+							  abs->value,
+							  abs);
+			ck_assert_int_eq(rc, 0);
+		}
+		abs++;
+	}
+	close(fd);
+	libevdev_free(dev);
+
 	return uinput;
 }
 
-- 
1.9.3



More information about the wayland-devel mailing list