Ignore test devices for libinput contexts not run from the test suite
authorJonas Ådahl <jadahl@gmail.com>
Mon, 27 Jul 2015 08:08:04 +0000 (16:08 +0800)
committerJonas Ådahl <jadahl@gmail.com>
Tue, 28 Jul 2015 09:42:32 +0000 (17:42 +0800)
Add a LIBINPUT_TEST_DEVICE udev parameter to test devices created by
the test suite. When an application tries to add such a device to the
path backend or when the udev backend discovers such a device, it will
be ignored. Only the context when run via the test suite will actually
handle these devices.

Doing this will enable a user to run the libinput test suite on a system
running libinput without having the test suite devices interfering with
the actual system.

Note that X.org users running an input device driver that is not the
libinput X input driver will still need to manually configure the X
server to ignore such devices (see test/50-litest.conf).

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
src/libinput-private.h
src/libinput.c
src/path.c
src/udev-seat.c
test/Makefile.am
test/litest.c
udev/.gitignore
udev/80-libinput-test-device.rules [new file with mode: 0644]

index e0ba51b..5d0826d 100644 (file)
@@ -292,6 +292,9 @@ open_restricted(struct libinput *libinput,
 void
 close_restricted(struct libinput *libinput, int fd);
 
+bool
+ignore_litest_test_suite_device(struct udev_device *device);
+
 void
 libinput_seat_init(struct libinput_seat *seat,
                   struct libinput *libinput,
index 69a6aef..7d017e3 100644 (file)
@@ -1020,6 +1020,16 @@ close_restricted(struct libinput *libinput, int fd)
        return libinput->interface->close_restricted(fd, libinput->user_data);
 }
 
+bool
+ignore_litest_test_suite_device(struct udev_device *device)
+{
+       if (!getenv("LIBINPUT_RUNNING_TEST_SUITE") &&
+           udev_device_get_property_value(device, "LIBINPUT_TEST_DEVICE"))
+               return true;
+
+       return false;
+}
+
 void
 libinput_seat_init(struct libinput_seat *seat,
                   struct libinput *libinput,
index 04c703c..b14d8b6 100644 (file)
@@ -343,6 +343,11 @@ libinput_path_add_device(struct libinput *libinput,
                return NULL;
        }
 
+       if (ignore_litest_test_suite_device(udev_device)) {
+               udev_device_unref(udev_device);
+               return NULL;
+       }
+
        device = path_create_device(libinput, udev_device, NULL);
        udev_device_unref(udev_device);
        return device;
index 6b019da..6bf85de 100644 (file)
@@ -62,6 +62,9 @@ device_added(struct udev_device *udev_device,
        if (!streq(device_seat, input->seat_id))
                return 0;
 
+       if (ignore_litest_test_suite_device(udev_device))
+               return 0;
+
        devnode = udev_device_get_devnode(udev_device);
 
        /* Search for matching logical seat */
index a9ddc85..cde93b3 100644 (file)
@@ -46,7 +46,8 @@ liblitest_la_SOURCES = \
 liblitest_la_LIBADD = $(top_builddir)/src/libinput-util.la
 liblitest_la_CFLAGS = $(AM_CFLAGS) \
              -DLIBINPUT_MODEL_QUIRKS_UDEV_RULES_FILE="\"$(abs_top_builddir)/udev/90-libinput-model-quirks-litest.rules\"" \
-             -DLIBINPUT_MODEL_QUIRKS_UDEV_HWDB_FILE="\"$(abs_top_srcdir)/udev/90-libinput-model-quirks.hwdb\""
+             -DLIBINPUT_MODEL_QUIRKS_UDEV_HWDB_FILE="\"$(abs_top_srcdir)/udev/90-libinput-model-quirks.hwdb\"" \
+             -DLIBINPUT_TEST_DEVICE_RULES_FILE="\"$(abs_top_srcdir)/udev/80-libinput-test-device.rules\""
 if HAVE_LIBUNWIND
 liblitest_la_LIBADD += $(LIBUNWIND_LIBS) -ldl
 liblitest_la_CFLAGS += $(LIBUNWIND_CFLAGS)
index 45dabaa..676485e 100644 (file)
@@ -57,6 +57,8 @@
        "/91-litest-model-quirks-REMOVEME.rules"
 #define UDEV_MODEL_QUIRKS_HWDB_FILE UDEV_HWDB_D \
        "/91-litest-model-quirks-REMOVEME.hwdb"
+#define UDEV_TEST_DEVICE_RULE_FILE UDEV_RULES_D \
+       "/91-litest-test-device-REMOVEME.rules"
 
 static int in_debugger = -1;
 static int verbose = 0;
@@ -955,6 +957,9 @@ litest_install_model_quirks(void)
        litest_copy_file(UDEV_MODEL_QUIRKS_HWDB_FILE,
                         LIBINPUT_MODEL_QUIRKS_UDEV_HWDB_FILE,
                         warning);
+       litest_copy_file(UDEV_TEST_DEVICE_RULE_FILE,
+                        LIBINPUT_TEST_DEVICE_RULES_FILE,
+                        warning);
 }
 
 static inline void
@@ -962,6 +967,7 @@ litest_remove_model_quirks(void)
 {
        unlink(UDEV_MODEL_QUIRKS_RULE_FILE);
        unlink(UDEV_MODEL_QUIRKS_HWDB_FILE);
+       unlink(UDEV_TEST_DEVICE_RULE_FILE);
 }
 
 static void
@@ -2551,6 +2557,7 @@ main(int argc, char **argv)
        list_init(&all_tests);
 
        setenv("CK_DEFAULT_TIMEOUT", "10", 0);
+       setenv("LIBINPUT_RUNNING_TEST_SUITE", "1", 1);
 
        mode = litest_parse_argv(argc, argv);
        if (mode == LITEST_MODE_ERROR)
index 2fdaedc..cad377a 100644 (file)
@@ -1,3 +1,6 @@
 libinput-device-group
 libinput-model-quirks
-*.rules
+80-libinput-device-groups-litest.rules
+80-libinput-device-groups.rules
+90-libinput-model-quirks-litest.rules
+90-libinput-model-quirks.rules
diff --git a/udev/80-libinput-test-device.rules b/udev/80-libinput-test-device.rules
new file mode 100644 (file)
index 0000000..d37b2ab
--- /dev/null
@@ -0,0 +1 @@
+KERNELS=="*input*", ATTRS{name}=="litest *", ENV{LIBINPUT_TEST_DEVICE}="1"