[PATCH libinput 1/4] test: allow for a default value on LITEST_AUTO_ASSIGNS

Hans de Goede hdegoede at redhat.com
Wed Jul 8 06:11:20 PDT 2015


Hi,

On 08-07-15 08:56, Peter Hutterer wrote:
> The touchpads currently all send a default value of 30 for ABS_PRESSURE. For
> some tests we want to have a custom pressure but changing all tests isn't
> sensible. So hook each device up to send a default value of 30 if it isn't
> overridden in the test itself.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

This feels somwhat adventurous, but I cannot find anything wrong with it, so:

Reviewed-by: Hans de Goede <hdegoede at redhat.com>

Regards,

Hans

> ---
>   test/litest-bcm5974.c                 | 19 ++++++++++++++++++-
>   test/litest-int.h                     |  6 ++++++
>   test/litest-synaptics-t440.c          | 19 ++++++++++++++++++-
>   test/litest-synaptics-x1-carbon-3rd.c | 19 ++++++++++++++++++-
>   test/litest-synaptics.c               | 19 ++++++++++++++++++-
>   test/litest.c                         | 22 +++++++++++++++-------
>   6 files changed, 93 insertions(+), 11 deletions(-)
>
> diff --git a/test/litest-bcm5974.c b/test/litest-bcm5974.c
> index f84d1d0..cbf2a74 100644
> --- a/test/litest-bcm5974.c
> +++ b/test/litest-bcm5974.c
> @@ -37,11 +37,12 @@ static void litest_bcm5974_setup(void)
>   static struct input_event down[] = {
>   	{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
> -	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = 30  },
> +	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
>   	{ .type = -1, .code = -1 },
>   };
> @@ -50,15 +51,31 @@ static struct input_event move[] = {
>   	{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
>   	{ .type = -1, .code = -1 },
>   };
>
> +static int
> +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
> +{
> +	switch (evcode) {
> +	case ABS_PRESSURE:
> +	case ABS_MT_PRESSURE:
> +		*value = 30;
> +		return 0;
> +	}
> +	return 1;
> +}
> +
>   static struct litest_device_interface interface = {
>   	.touch_down_events = down,
>   	.touch_move_events = move,
> +
> +	.get_axis_default = get_axis_default,
>   };
>
>   static struct input_absinfo absinfo[] = {
> diff --git a/test/litest-int.h b/test/litest-int.h
> index 666c5ff..ab611a5 100644
> --- a/test/litest-int.h
> +++ b/test/litest-int.h
> @@ -80,6 +80,12 @@ struct litest_device_interface {
>   	void (*touch_up)(struct litest_device *d, unsigned int slot);
>
>   	/**
> +	 * Default value for the given EV_ABS axis.
> +	 * @return 0 on success, nonzero otherwise
> +	 */
> +	int (*get_axis_default)(struct litest_device *d, unsigned int code, int32_t *value);
> +
> +	/**
>   	 * Set of of events to execute on touch down, terminated by a .type
>   	 * and .code value of -1. If the event value is LITEST_AUTO_ASSIGN,
>   	 * it will be automatically assigned by the framework (valid for x,
> diff --git a/test/litest-synaptics-t440.c b/test/litest-synaptics-t440.c
> index 4247a0c..fa56185 100644
> --- a/test/litest-synaptics-t440.c
> +++ b/test/litest-synaptics-t440.c
> @@ -38,11 +38,12 @@ litest_synaptics_t440_setup(void)
>   static struct input_event down[] = {
>   	{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
> -	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = 30  },
> +	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
>   	{ .type = -1, .code = -1 },
>   };
> @@ -51,15 +52,31 @@ static struct input_event move[] = {
>   	{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
>   	{ .type = -1, .code = -1 },
>   };
>
> +static int
> +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
> +{
> +	switch (evcode) {
> +	case ABS_PRESSURE:
> +	case ABS_MT_PRESSURE:
> +		*value = 30;
> +		return 0;
> +	}
> +	return 1;
> +}
> +
>   static struct litest_device_interface interface = {
>   	.touch_down_events = down,
>   	.touch_move_events = move,
> +
> +	.get_axis_default = get_axis_default,
>   };
>
>   static struct input_id input_id = {
> diff --git a/test/litest-synaptics-x1-carbon-3rd.c b/test/litest-synaptics-x1-carbon-3rd.c
> index bb50f4a..2005c8c 100644
> --- a/test/litest-synaptics-x1-carbon-3rd.c
> +++ b/test/litest-synaptics-x1-carbon-3rd.c
> @@ -38,11 +38,12 @@ litest_synaptics_carbon3rd_setup(void)
>   static struct input_event down[] = {
>   	{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
> -	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = 30  },
> +	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
>   	{ .type = -1, .code = -1 },
>   };
> @@ -51,15 +52,31 @@ static struct input_event move[] = {
>   	{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
>   	{ .type = -1, .code = -1 },
>   };
>
> +static int
> +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
> +{
> +	switch (evcode) {
> +	case ABS_PRESSURE:
> +	case ABS_MT_PRESSURE:
> +		*value = 30;
> +		return 0;
> +	}
> +	return 1;
> +}
> +
>   static struct litest_device_interface interface = {
>   	.touch_down_events = down,
>   	.touch_move_events = move,
> +
> +	.get_axis_default = get_axis_default,
>   };
>
>   static struct input_id input_id = {
> diff --git a/test/litest-synaptics.c b/test/litest-synaptics.c
> index c35ad3d..4dcdebf 100644
> --- a/test/litest-synaptics.c
> +++ b/test/litest-synaptics.c
> @@ -38,11 +38,12 @@ litest_synaptics_clickpad_setup(void)
>   static struct input_event down[] = {
>   	{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
> -	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = 30  },
> +	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
>   	{ .type = -1, .code = -1 },
>   };
> @@ -51,15 +52,31 @@ static struct input_event move[] = {
>   	{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
>   	{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
> +	{ .type = EV_ABS, .code = ABS_MT_PRESSURE, .value = LITEST_AUTO_ASSIGN  },
>   	{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
>   	{ .type = -1, .code = -1 },
>   };
>
> +static int
> +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
> +{
> +	switch (evcode) {
> +	case ABS_PRESSURE:
> +	case ABS_MT_PRESSURE:
> +		*value = 30;
> +		return 0;
> +	}
> +	return 1;
> +}
> +
>   static struct litest_device_interface interface = {
>   	.touch_down_events = down,
>   	.touch_move_events = move,
> +
> +	.get_axis_default = get_axis_default,
>   };
>
>   static struct input_id input_id = {
> diff --git a/test/litest.c b/test/litest.c
> index 86079c2..8cde52f 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -1212,19 +1212,22 @@ litest_event(struct litest_device *d, unsigned int type,
>   	litest_assert_int_eq(ret, 0);
>   }
>
> -static int32_t
> +static bool
>   axis_replacement_value(struct axis_replacement *axes,
> -		       int32_t evcode)
> +		       int32_t evcode,
> +		       int32_t *value)
>   {
>   	struct axis_replacement *axis = axes;
>
>   	while (axis->evcode != -1) {
> -		if (axis->evcode == evcode)
> -			return axis->value;
> +		if (axis->evcode == evcode) {
> +			*value = axis->value;
> +			return true;
> +		}
>   		axis++;
>   	}
>
> -	return -1;
> +	return false;
>   }
>
>   int
> @@ -1259,8 +1262,13 @@ litest_auto_assign_value(struct litest_device *d,
>   		value = touching ? 0 : 1;
>   		break;
>   	default:
> -		if (axes)
> -			value = axis_replacement_value(axes, ev->code);
> +		value = -1;
> +		if (!axes)
> +			break;
> +
> +		if (!axis_replacement_value(axes, ev->code, &value) &&
> +		    d->interface->get_axis_default)
> +			d->interface->get_axis_default(d, ev->code, &value);
>   		break;
>   	}
>
>


More information about the wayland-devel mailing list