[PATCH libinput 2/2] Ignore test devices for libinput contexts not run from the test suite

Peter Hutterer peter.hutterer at who-t.net
Mon Jul 27 23:20:29 PDT 2015


On Tue, Jul 28, 2015 at 12:52:45PM +0800, Jonas Ådahl wrote:
> 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 discoveres such a device, it will

typo, "discovers"

> 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 at gmail.com>
> ---
>  src/libinput-private.h             |  3 +++
>  src/libinput.c                     | 10 ++++++++++
>  src/path.c                         |  5 +++++
>  src/udev-seat.c                    |  3 +++
>  test/Makefile.am                   |  3 ++-
>  test/litest.c                      |  7 +++++++
>  udev/.gitignore                    |  5 ++++-
>  udev/80-libinput-test-device.rules |  1 +
>  8 files changed, 35 insertions(+), 2 deletions(-)
>  create mode 100644 udev/80-libinput-test-device.rules
> 
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index dc9cc66..9db106c 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -292,6 +292,9 @@ open_restricted(struct libinput *libinput,
>  void
>  close_restricted(struct libinput *libinput, int fd);
>  
> +bool
> +should_ignore_device(struct udev_device *device);

can we make this more specific? we already have a evdev_reject_device so
this looks like it does the same thing.

ignore_litest_test_suite_device() or so? that's about as specific as it
gets.


> +
>  void
>  libinput_seat_init(struct libinput_seat *seat,
>  		   struct libinput *libinput,
> diff --git a/src/libinput.c b/src/libinput.c
> index fe4df46..54fabe5 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -1020,6 +1020,16 @@ close_restricted(struct libinput *libinput, int fd)
>  	return libinput->interface->close_restricted(fd, libinput->user_data);
>  }
>  
> +bool
> +should_ignore_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,
> diff --git a/src/path.c b/src/path.c
> index 04c703c..01a6549 100644
> --- a/src/path.c
> +++ b/src/path.c
> @@ -343,6 +343,11 @@ libinput_path_add_device(struct libinput *libinput,
>  		return NULL;
>  	}
>  
> +	if (should_ignore_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;
> diff --git a/src/udev-seat.c b/src/udev-seat.c
> index 6b019da..de5fc2d 100644
> --- a/src/udev-seat.c
> +++ b/src/udev-seat.c
> @@ -62,6 +62,9 @@ device_added(struct udev_device *udev_device,
>  	if (!streq(device_seat, input->seat_id))
>  		return 0;
>  
> +	if (should_ignore_device(udev_device))
> +		return 0;
> +
>  	devnode = udev_device_get_devnode(udev_device);
>  
>  	/* Search for matching logical seat */
> diff --git a/test/Makefile.am b/test/Makefile.am
> index a9ddc85..516493e 100644
> --- a/test/Makefile.am
> +++ b/test/Makefile.am
> @@ -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_builddir)/udev/80-libinput-test-device.rules\""

this needs to be abs_top_srcdir, you're not generating this file

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net> to the rest, and the
first one.

Cheers,
   Peter

>  if HAVE_LIBUNWIND
>  liblitest_la_LIBADD += $(LIBUNWIND_LIBS) -ldl
>  liblitest_la_CFLAGS += $(LIBUNWIND_CFLAGS)
> diff --git a/test/litest.c b/test/litest.c
> index 45dabaa..676485e 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -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)
> diff --git a/udev/.gitignore b/udev/.gitignore
> index 2fdaedc..cad377a 100644
> --- a/udev/.gitignore
> +++ b/udev/.gitignore
> @@ -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
> index 0000000..d37b2ab
> --- /dev/null
> +++ b/udev/80-libinput-test-device.rules
> @@ -0,0 +1 @@
> +KERNELS=="*input*", ATTRS{name}=="litest *", ENV{LIBINPUT_TEST_DEVICE}="1"
> -- 
> 2.1.0
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 


More information about the wayland-devel mailing list