test: auto-assign the tool type for tablet tests

The current tool type test merely sends BTN_TOOL_RUBBER (and others) manually
and expects libinput to do the right thing. This only tests the perfect
sequence but not test weird devices that behave differently on a tool type
switch.

So let's fix this by setting the tool type as property on the libinput test
device itself, and then emulate the tool switch through litest.
For special devices this will need extra callbacks, this is just the initial
framework to handle those buttons.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-09-11 08:43:58 +10:00
parent 06e7adfca3
commit df2759706f
17 changed files with 88 additions and 41 deletions

View file

@ -30,13 +30,13 @@ static struct input_event proximity_in[] = {
{ .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_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
static struct input_event proximity_out[] = {
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -30,7 +30,7 @@ static struct input_event proximity_in[] = {
{ .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_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -31,7 +31,7 @@ static struct input_event proximity_in[] = {
{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
@ -40,7 +40,7 @@ static struct input_event proximity_out[] = {
{ .type = EV_ABS, .code = ABS_X, .value = 0 },
{ .type = EV_ABS, .code = ABS_Y, .value = 0 },
{ .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -31,7 +31,7 @@ static struct input_event proximity_in[] = {
{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
@ -40,7 +40,7 @@ static struct input_event proximity_out[] = {
{ .type = EV_ABS, .code = ABS_X, .value = 0 },
{ .type = EV_ABS, .code = ABS_Y, .value = 0 },
{ .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -35,7 +35,7 @@ static struct input_event proximity_in[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MISC, .value = 2083 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
@ -48,7 +48,7 @@ static struct input_event proximity_out[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 },
{ .type = EV_ABS, .code = ABS_MISC, .value = 0 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -35,7 +35,7 @@ static struct input_event proximity_in[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MISC, .value = 2083 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
@ -48,7 +48,7 @@ static struct input_event proximity_out[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 },
{ .type = EV_ABS, .code = ABS_MISC, .value = 0 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -35,7 +35,7 @@ static struct input_event proximity_in[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MISC, .value = 2083 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
@ -48,7 +48,7 @@ static struct input_event proximity_out[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 },
{ .type = EV_ABS, .code = ABS_MISC, .value = 0 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -37,7 +37,7 @@ static struct input_event proximity_in[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MISC, .value = 2083 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
@ -52,7 +52,7 @@ static struct input_event proximity_out[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 },
{ .type = EV_ABS, .code = ABS_MISC, .value = 0 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -30,7 +30,7 @@ static struct input_event proximity_in[] = {
{ .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_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
@ -40,7 +40,7 @@ static struct input_event proximity_out[] = {
{ .type = EV_ABS, .code = ABS_X, .value = 0 },
{ .type = EV_ABS, .code = ABS_Y, .value = 0 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -35,7 +35,7 @@ static struct input_event proximity_in[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MISC, .value = 1050626 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 578837976 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
@ -48,7 +48,7 @@ static struct input_event proximity_out[] = {
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 },
{ .type = EV_ABS, .code = ABS_MISC, .value = 0 },
{ .type = EV_MSC, .code = MSC_SERIAL, .value = 578837976 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -30,13 +30,13 @@ static struct input_event proximity_in[] = {
{ .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_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
static struct input_event proximity_out[] = {
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -30,13 +30,13 @@ static struct input_event proximity_in[] = {
{ .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_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
static struct input_event proximity_out[] = {
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -32,7 +32,7 @@ static struct input_event proximity_in[] = {
{ .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
@ -42,7 +42,7 @@ static struct input_event proximity_out[] = {
{ .type = EV_ABS, .code = ABS_Y, .value = 0 },
{ .type = EV_ABS, .code = ABS_TILT_X, .value = 0 },
{ .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 },
{ .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
{ .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};

View file

@ -31,6 +31,9 @@
/* Use as designater for litest to change the value */
#define LITEST_AUTO_ASSIGN INT_MIN
/* Special event code to auto-assign the BTN_TOOL_PEN and friends */
#define LITEST_BTN_TOOL_AUTO (KEY_MAX << 1)
struct litest_test_device {
struct list node; /* global test device list */
@ -129,6 +132,8 @@ struct litest_device_interface {
int min[2]; /* x/y axis minimum */
int max[2]; /* x/y axis maximum */
unsigned int tool_type;
};
struct path {

View file

@ -65,6 +65,8 @@
#include <linux/kd.h>
#define evbit(t, c) ((t) << 16U | (c & 0xffff))
#define UDEV_RULES_D "/run/udev/rules.d"
#define UDEV_FUZZ_OVERRIDE_RULE_FILE UDEV_RULES_D \
"/91-litest-fuzz-override-REMOVEME-XXXXXX.rules"
@ -1812,6 +1814,7 @@ litest_add_device_with_overrides(struct libinput *libinput,
d->interface->min[ABS_Y] = libevdev_get_abs_minimum(d->evdev, code);
d->interface->max[ABS_Y] = libevdev_get_abs_maximum(d->evdev, code);
}
d->interface->tool_type = BTN_TOOL_PEN;
}
return d;
}
@ -2443,6 +2446,33 @@ tablet_ignore_event(const struct input_event *ev, int value)
return value == -1 && (ev->code == ABS_PRESSURE || ev->code == ABS_DISTANCE);
}
void
litest_tablet_set_tool_type(struct litest_device *d, unsigned int code)
{
switch (code) {
case BTN_TOOL_PEN:
case BTN_TOOL_RUBBER:
case BTN_TOOL_BRUSH:
case BTN_TOOL_PENCIL:
case BTN_TOOL_AIRBRUSH:
case BTN_TOOL_MOUSE:
case BTN_TOOL_LENS:
break;
default:
abort();
}
d->interface->tool_type = code;
}
static void
litest_tool_event(struct litest_device *d, int value)
{
unsigned int tool = d->interface->tool_type;
litest_event(d, EV_KEY, tool, value);
}
void
litest_tablet_proximity_in(struct litest_device *d, int x, int y, struct axis_replacement *axes)
{
@ -2450,9 +2480,17 @@ litest_tablet_proximity_in(struct litest_device *d, int x, int y, struct axis_re
ev = d->interface->tablet_proximity_in_events;
while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
int value = auto_assign_tablet_value(d, ev, x, y, axes);
if (!tablet_ignore_event(ev, value))
litest_event(d, ev->type, ev->code, value);
int value;
switch (evbit(ev->type, ev->code)) {
case evbit(EV_KEY, LITEST_BTN_TOOL_AUTO):
litest_tool_event(d, ev->value);
break;
default:
value = auto_assign_tablet_value(d, ev, x, y, axes);
if (!tablet_ignore_event(ev, value))
litest_event(d, ev->type, ev->code, value);
}
ev++;
}
}
@ -2464,9 +2502,18 @@ litest_tablet_proximity_out(struct litest_device *d)
ev = d->interface->tablet_proximity_out_events;
while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
int value = auto_assign_tablet_value(d, ev, -1, -1, NULL);
if (!tablet_ignore_event(ev, value))
litest_event(d, ev->type, ev->code, value);
int value;
switch (evbit(ev->type, ev->code)) {
case evbit(EV_KEY, LITEST_BTN_TOOL_AUTO):
litest_tool_event(d, ev->value);
break;
default:
value = auto_assign_tablet_value(d, ev, -1, -1, NULL);
if (!tablet_ignore_event(ev, value))
litest_event(d, ev->type, ev->code, value);
break;
}
ev++;
}
}

View file

@ -603,6 +603,10 @@ litest_touch_move_three_touches(struct litest_device *d,
double dx, double dy,
int steps);
void
litest_tablet_set_tool_type(struct litest_device *d,
unsigned int code);
void
litest_tablet_proximity_in(struct litest_device *d,
int x, int y,

View file

@ -2820,12 +2820,8 @@ START_TEST(tool_type)
!tablet_has_mouse(dev))
continue;
litest_push_event_frame(dev);
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN);
litest_tablet_set_tool_type(dev, tt->code);
litest_tablet_proximity_in(dev, 50, 50, axes);
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN);
litest_event(dev, EV_KEY, tt->code, 1);
litest_pop_event_frame(dev);
libinput_dispatch(li);
event = libinput_get_event(li);
@ -2839,12 +2835,7 @@ START_TEST(tool_type)
libinput_event_destroy(event);
litest_assert_empty_queue(li);
litest_push_event_frame(dev);
litest_filter_event(dev, EV_KEY, BTN_TOOL_PEN);
litest_tablet_proximity_out(dev);
litest_unfilter_event(dev, EV_KEY, BTN_TOOL_PEN);
litest_event(dev, EV_KEY, tt->code, 0);
litest_pop_event_frame(dev);
litest_drain_events(li);
}
}