test: auto-assign the tool type for tablet tests
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 10 Sep 2020 22:43:58 +0000 (08:43 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 22 Sep 2020 07:35:41 +0000 (17:35 +1000)
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>
17 files changed:
test/litest-device-elan-tablet.c
test/litest-device-huion-pentablet.c
test/litest-device-wacom-bamboo-16fg-pen.c
test/litest-device-wacom-bamboo-2fg-pen.c
test/litest-device-wacom-cintiq-12wx-pen.c
test/litest-device-wacom-cintiq-13hdt-pen.c
test/litest-device-wacom-cintiq-24hd-pen.c
test/litest-device-wacom-cintiq-pro-16-pen.c
test/litest-device-wacom-hid4800-pen.c
test/litest-device-wacom-intuos5-pen.c
test/litest-device-wacom-isdv4-4200-pen.c
test/litest-device-wacom-isdv4-e6-pen.c
test/litest-device-waltop-tablet.c
test/litest-int.h
test/litest.c
test/litest.h
test/test-tablet.c

index 7b8e702..433a03c 100644 (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 },
 };
index 976d670..8e81bc1 100644 (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 },
 };
index 2427fc7..cc65afe 100644 (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 },
 };
index aa1e3c2..6889ff3 100644 (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 },
 };
index ca33137..e9c4f68 100644 (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 },
 };
index 5975510..4adf0ef 100644 (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 },
 };
index 2e47df9..f8b9a57 100644 (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 },
 };
index 35997ae..3b9dc1a 100644 (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 },
 };
index 3f42485..85f091b 100644 (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 },
 };
index ae8439c..4970909 100644 (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 },
 };
index 2627138..59bf866 100644 (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 },
 };
index 07c250a..d1e291c 100644 (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 },
 };
index 1952286..62561e1 100644 (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 },
 };
index c5b05e6..5bc62d9 100644 (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 {
index a10d50d..4011123 100644 (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;
 }
@@ -2444,15 +2447,50 @@ tablet_ignore_event(const struct input_event *ev, int value)
 }
 
 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)
 {
        struct input_event *ev;
 
        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++;
        }
 }
index 1f4e609..dcbb47b 100644 (file)
@@ -604,6 +604,10 @@ litest_touch_move_three_touches(struct litest_device *d,
                                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,
                           struct axis_replacement *axes);
index bfc2573..d0b728e 100644 (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);
        }
 }