[PATCH libinput 3/5] test: allow for description-based test devices

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 3 20:56:11 PDT 2014


On Fri, Apr 04, 2014 at 01:52:09PM +1000, Peter Hutterer wrote:
> On Thu, Apr 03, 2014 at 10:43:03PM +0200, Jonas Ådahl wrote:
> [...]
> > > diff --git a/test/litest.c b/test/litest.c
> > > index 6767952..23ba76b 100644
> > > --- a/test/litest.c
> > > +++ b/test/litest.c
> > > @@ -61,6 +61,12 @@ struct suite {
> > >  
> > >  static struct litest_device *current_device;
> > >  
> > > +struct libevdev_uinput *
> > > +litest_create_uinput_device_from_description(const char *name,
> > > +					     struct input_id *id,
> > 
> > 'id' needs to have a const qualifier in order to not result in a
> > compiler warning.
> 
> amended, thanks
> 
> [...] 
> 
> > > @@ -421,23 +481,43 @@ litest_touch_up(struct litest_device *d, unsigned int slot)
> > >  {
> > >  	struct input_event *ev;
> > >  	struct input_event up[] = {
> > > -		{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = slot },
> > > +		{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
> > >  		{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = -1 },
> > >  		{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
> > > +		{ .type = -1, .code = -1 }
> > 
> > Do we really need to set code to -1 and compare both of them everywhere?
> > Is there any scenario when type can be -1 but code something relevant?
> 
> no, type cannot be -1. But good catch, the only reason I check both is to
> avoid an accidental offset error resulting in the varargs running out of
> bounds. I'll switch the checks to use ||, not &&.

sorry, ECOFFEE. The above reasoning holds, but the code already checks for
either being -1 and then bails, so no changes are needed.

Again, the main reason is to avoid issue like
    int events[] = { EV_REL, REL_X, REL_Y, -1 };

which looks valid on first glance but if we only check every second one we
skip over the -1. That's harder to do wrong in the abs handling code but I'd
prefer to leave it in for symmetry.

Cheers,
   Peter
 
> > >  	};
> > >  
> > >  	if (d->interface->touch_up) {
> > >  		d->interface->touch_up(d, slot);
> > > -	} else {
> > > -		ARRAY_FOR_EACH(up, ev)
> > > -			litest_event(d, ev->type, ev->code, ev->value);
> > > +		return;
> > > +	} else if (d->interface->touch_up_events) {
> > > +		ev = d->interface->touch_up_events;
> > > +	} else
> > > +		ev = up;
> > > +
> > > +	while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
> > > +		int value = auto_assign_value(d, ev, slot, 0, 0);
> > > +		litest_event(d, ev->type, ev->code, value);
> > > +		ev++;
> > >  	}
> > >  }
> > >  
> > >  void
> > >  litest_touch_move(struct litest_device *d, unsigned int slot, int x, int y)
> > >  {
> > > -	d->interface->touch_move(d, slot, x, y);
> > > +	struct input_event *ev;
> > > +
> > > +	if (d->interface->touch_move) {
> > > +		d->interface->touch_move(d, slot, x, y);
> > > +		return;
> > > +	}
> > > +
> > > +	ev = d->interface->touch_move_events;
> > > +	while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
> > > +		int value = auto_assign_value(d, ev, slot, x, y);
> > > +		litest_event(d, ev->type, ev->code, value);
> > > +		ev++;
> > > +	}
> > >  }
> > >  
> > >  void
> > > @@ -492,11 +572,11 @@ litest_drain_events(struct libinput *li)
> > >  	}
> > >  }
> > >  
> > > -static struct libevdev_uinput *
> > > -litest_create_uinput_abs_device_v(const char *name,
> > > -				  struct input_id *id,
> > > -				  const struct input_absinfo *abs,
> > > -				  va_list args)
> > > +struct libevdev_uinput *
> > > +litest_create_uinput_device_from_description(const char *name,
> > > +					     struct input_id *id,
> > > +					     const struct input_absinfo *abs,
> > > +					     const int *events)
> > >  {
> > >  	struct libevdev_uinput *uinput;
> > >  	struct libevdev *dev;
> > > @@ -528,8 +608,9 @@ litest_create_uinput_abs_device_v(const char *name,
> > >  		abs++;
> > >  	}
> > >  
> > > -	while ((type = va_arg(args, int)) != -1 &&
> > > -	       (code = va_arg(args, int)) != -1) {
> > > +	while (events &&
> > > +	       (type = *events++) != -1 &&
> > > +	       (code = *events++) != -1) {
> > >  		if (type == INPUT_PROP_MAX) {
> > >  			rc = libevdev_enable_property(dev, code);
> > >  		} else {
> > > @@ -551,6 +632,30 @@ litest_create_uinput_abs_device_v(const char *name,
> > >  	return uinput;
> > >  }
> > >  
> > > +static struct libevdev_uinput *
> > > +litest_create_uinput_abs_device_v(const char *name,
> > > +				  struct input_id *id,
> > > +				  const struct input_absinfo *abs,
> > > +				  va_list args)
> > > +{
> > > +	int events[KEY_MAX * 2 + 2]; /* increase this if not sufficient */
> > > +	int *event = events;
> > > +	int type, code;
> > > +
> > > +	while ((type = va_arg(args, int)) != -1 &&
> > > +	       (code = va_arg(args, int)) != -1) {
> > > +		*event++ = type;
> > > +		*event++ = code;
> > > +		ck_assert(event < &events[ARRAY_LENGTH(events) - 2]);
> > > +	}
> > > +
> > > +	*event++ = -1;
> > > +	*event++ = -1;
> > > +
> > > +	return litest_create_uinput_device_from_description(name, id,
> > > +							    abs, events);
> > > +}
> > > +
> > >  struct libevdev_uinput *
> > >  litest_create_uinput_abs_device(const char *name,
> > >  				struct input_id *id,
> > > -- 
> > > 1.9.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