test: add an extra loop for slow udev initialization
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 26 May 2015 00:44:16 +0000 (20:44 -0400)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 27 May 2015 07:38:24 +0000 (17:38 +1000)
On slower machines, e.g. VMs, udev isn't fast enough to get the properties set
up by the time we're trying to get the device going. This fails when we try to
add the device with libinput_path_add_device().

We know that all litest devices will have ID_INPUT set, so check for that
before we continue.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
test/litest.c

index 8221a7a2a34434cba8e3a6a14b405f002f5579d2..96ea4ec7952fd5c04e4bbbe7fe4916077c81a405 100644 (file)
@@ -977,6 +977,32 @@ litest_restore_log_handler(struct libinput *libinput)
        libinput_log_set_handler(libinput, litest_log_handler);
 }
 
+static inline void
+litest_wait_for_udev(int fd)
+{
+       struct udev *udev;
+       struct udev_device *device;
+       struct stat st;
+       int loop_count = 0;
+
+       litest_assert_int_ge(fstat(fd, &st), 0);
+
+       udev = udev_new();
+       device = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
+       litest_assert_ptr_notnull(device);
+       while (device && !udev_device_get_property_value(device, "ID_INPUT")) {
+               loop_count++;
+               litest_assert_int_lt(loop_count, 300);
+
+               udev_device_unref(device);
+               msleep(2);
+               device = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
+       }
+
+       udev_device_unref(device);
+       udev_unref(udev);
+}
+
 struct litest_device *
 litest_add_device_with_overrides(struct libinput *libinput,
                                 enum litest_device_type which,
@@ -1004,6 +1030,8 @@ litest_add_device_with_overrides(struct libinput *libinput,
        rc = libevdev_new_from_fd(fd, &d->evdev);
        litest_assert_int_eq(rc, 0);
 
+       litest_wait_for_udev(fd);
+
        d->libinput = libinput;
        d->libinput_device = libinput_path_add_device(d->libinput, path);
        litest_assert(d->libinput_device != NULL);