[PATCH libinput 4/5] test: allow partial overriding the test devices

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 3 21:24:28 PDT 2014


On Thu, Apr 03, 2014 at 10:40:50PM +0200, Jonas Ådahl wrote:
> On Tue, Apr 01, 2014 at 01:47:08PM +1000, Peter Hutterer wrote:
> > For specific tests we need something that e.g. looks like a touchpad, but has
> > a different name, a different number of slots, etc. In this case, the
> > following code will do exactly that:
> > 
> > struct input_absinfo overrides[] = {
> >  { .value = ABS_MT_SLOT, .minimum = 0, .maximum = 100 },
> >  { .value = -1 },
> > };
> > 
> > litest_create_device_with_overrides(LITEST_SYNAPTICS_CLICKPAD,
> > 				    NULL, NULL, &overrides, NULL);
> > 
> > For general event codes, overrides can only add to the set of events, they
> > can't remove.
> 
> I have gone through the patches as well and overall I think its a good
> approach. Anyhow, I have some comments, some here, some inline:
> 
> This is a quite nice API for creating custom devices, we can probably
> replace highres device with using wacom-touch with overrides. What is
> currently lacking is to adding multiple devices to the same libinput
> context. We could either just add two more variants of these functions
> taking a libinput context, or we could change the behavior to implicitly
> append to the same context during a test run. Preferences or other
> ideas?

While I think automatically adding it is more convenient I do tend towards
the extra API to make it implicit what is added to which context.
A simple litest_add_device_... should suffice here.

> > ---
> >  test/litest.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
> >  test/litest.h |   7 +++
> >  2 files changed, 144 insertions(+), 21 deletions(-)
> > 
> > diff --git a/test/litest.c b/test/litest.c
> > index 23ba76b..3a69a09 100644
> > --- a/test/litest.c
> > +++ b/test/litest.c
> > @@ -334,39 +334,149 @@ const struct libinput_interface interface = {
> >  	.close_restricted = close_restricted,
> >  };
> >  
> > -struct litest_device *
> > -litest_create_device(enum litest_device_type which)
> > +
> > +static struct input_absinfo *
> > +merge_absinfo(const struct input_absinfo *orig,
> > +	      const struct input_absinfo *override)
> >  {
> > -	struct litest_device *d = zalloc(sizeof(*d));
> > -	int fd;
> > -	int rc;
> > -	const char *path;
> > +	struct input_absinfo *abs;
> > +	int nelem, i;
> > +	size_t sz = ABS_MAX + 1;
> > +
> > +	if (!orig)
> > +		return NULL;
> > +
> > +	abs = calloc(sz, sizeof(*abs));
> > +	ck_assert(abs != NULL);
> > +
> > +	nelem = 0;
> > +	while(orig[nelem].value != -1) {
> 
> Space between while and (.

all amended, thanks.
 
> > +		abs[nelem] = orig[nelem];
> > +		nelem++;
> > +		ck_assert_int_lt(nelem, sz);
> > +	}
> > +
> > +	/* just append, if the same axis is present twice, libevdev will
> > +	   only use the last value anyway */
> 
> I can't find this specified in the libevdev API. For events, I would
> assume that it ignores extra enabled events as its a binary state, but
> for abs values it's unclear if its the first or the last abs values that
> is will be used.

I'll add that to the libevdev documentation. All we do here is call
libevdev_enable_event_code() in a loop. For most types that doesn't do much
but for abs it does override the previously set value.

Cheers,
   Peter



More information about the wayland-devel mailing list