lid: disable all types but EV_SYN and EV_SW
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 24 Jul 2017 23:38:46 +0000 (09:38 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 6 Sep 2017 09:39:34 +0000 (19:39 +1000)
The lid dispatch interface is a one-trick pony and can only handle SW_LID. It
ignores other switches but crashes on any event type other than EV_SW and
EV_SYN. Disable those types so we just ignore the event instead of asserting.

https://bugs.freedesktop.org/show_bug.cgi?id=101853

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
(cherry picked from commit 6bb05c594a73cee2ed9cf62af88fdcab4011f57a)

meson.build
src/evdev-lid.c
test/litest-device-gpio-keys.c [new file with mode: 0644]
test/litest.c
test/litest.h
test/test-lid.c

index fbb1c4ee2ad5cae31149759e031fa6267621e258..93a20d5829b84c72703c5e3a829b6f405d3a3146 100644 (file)
@@ -512,6 +512,7 @@ if get_option('tests')
                'test/litest-device-cyborg-rat-5.c',
                'test/litest-device-elantech-touchpad.c',
                'test/litest-device-generic-singletouch.c',
+               'test/litest-device-gpio-keys.c',
                'test/litest-device-huion-pentablet.c',
                'test/litest-device-keyboard.c',
                'test/litest-device-keyboard-all-codes.c',
index fe98e6e117ff9059bcebdbf7e0307c769e02d47c..3de5fe4cc8c00bfe9257352d846470b9384ecae4 100644 (file)
@@ -298,6 +298,7 @@ struct evdev_dispatch *
 evdev_lid_switch_dispatch_create(struct evdev_device *lid_device)
 {
        struct lid_switch_dispatch *dispatch = zalloc(sizeof *dispatch);
+       int type;
 
        if (dispatch == NULL)
                return NULL;
@@ -311,5 +312,12 @@ evdev_lid_switch_dispatch_create(struct evdev_device *lid_device)
 
        dispatch->lid_is_closed = false;
 
+       for (type = EV_KEY; type < EV_CNT; type++) {
+               if (type == EV_SW)
+                       continue;
+
+               libevdev_disable_event_type(lid_device->evdev, type);
+       }
+
        return &dispatch->base;
 }
diff --git a/test/litest-device-gpio-keys.c b/test/litest-device-gpio-keys.c
new file mode 100644 (file)
index 0000000..37b058c
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2017 Red Hat, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "litest.h"
+#include "litest-int.h"
+
+static void
+litest_gpio_keys_setup(void)
+{
+       struct litest_device *d = litest_create_device(LITEST_GPIO_KEYS);
+       litest_set_current_device(d);
+}
+
+static struct input_id input_id = {
+       .bustype = 0x19,
+       .vendor = 0x1,
+       .product = 0x1,
+};
+
+static int events[] = {
+       EV_SW, SW_LID,
+       EV_SW, SW_TABLET_MODE,
+       EV_KEY, KEY_POWER,
+       EV_KEY, KEY_VOLUMEUP,
+       EV_KEY, KEY_VOLUMEDOWN,
+       EV_KEY, KEY_POWER,
+       -1, -1,
+};
+
+static const char udev_rule[] =
+"ACTION==\"remove\", GOTO=\"switch_end\"\n"
+"KERNEL!=\"event*\", GOTO=\"switch_end\"\n"
+"\n"
+"ATTRS{name}==\"litest gpio-keys*\",\\\n"
+"    ENV{ID_INPUT_SWITCH}=\"1\",\\\n"
+"    ENV{LIBINPUT_ATTR_gpio_keys_RELIABILITY}=\"reliable\"\n"
+"\n"
+"LABEL=\"switch_end\"";
+
+struct litest_test_device litest_gpio_keys_device = {
+       .type = LITEST_GPIO_KEYS,
+       .features = LITEST_SWITCH,
+       .shortname = "gpio keys",
+       .setup = litest_gpio_keys_setup,
+       .interface = NULL,
+
+       .name = "gpio-keys",
+       .id = &input_id,
+       .events = events,
+       .absinfo = NULL,
+
+       .udev_rule = udev_rule,
+};
index 3cb3f3865d2336ccf6223229e58da1aa0427f687..db14806b3dda73cee38aa424dc1b105ff44c4076 100644 (file)
@@ -416,6 +416,7 @@ extern struct litest_test_device litest_mouse_wheel_tilt_device;
 extern struct litest_test_device litest_lid_switch_device;
 extern struct litest_test_device litest_lid_switch_surface3_device;
 extern struct litest_test_device litest_appletouch_device;
+extern struct litest_test_device litest_gpio_keys_device;
 
 struct litest_test_device* devices[] = {
        &litest_synaptics_clickpad_device,
@@ -481,6 +482,7 @@ struct litest_test_device* devices[] = {
        &litest_lid_switch_device,
        &litest_lid_switch_surface3_device,
        &litest_appletouch_device,
+       &litest_gpio_keys_device,
        NULL,
 };
 
index a2cb6ee3e3a37b8bcb7ac90fb04732e6ed9f0011..8625d34baecf58e3cae391ed871845b83e80a6e4 100644 (file)
@@ -232,6 +232,7 @@ enum litest_device_type {
        LITEST_LID_SWITCH,
        LITEST_LID_SWITCH_SURFACE3,
        LITEST_APPLETOUCH,
+       LITEST_GPIO_KEYS,
 };
 
 enum litest_device_feature {
index 4bf4c05943d3bb9ea0be442a066c108804d8de8b..b5d3d586b781cf840fd256a6c354463296445afe 100644 (file)
@@ -555,6 +555,24 @@ START_TEST(lid_update_hw_on_key_closed_on_init)
 }
 END_TEST
 
+START_TEST(lid_key_press)
+{
+       struct litest_device *sw = litest_current_device();
+       struct libinput *li = sw->libinput;
+
+       litest_drain_events(li);
+
+       litest_keyboard_key(sw, KEY_POWER, true);
+       litest_keyboard_key(sw, KEY_POWER, false);
+       libinput_dispatch(li);
+
+       /* We should route the key events correctly, but for now we just
+        * ignore them. This test will fail once the key events are handled
+        * correctly. */
+       litest_assert_empty_queue(li);
+}
+END_TEST
+
 void
 litest_setup_tests_lid(void)
 {
@@ -576,4 +594,6 @@ litest_setup_tests_lid(void)
 
        litest_add_for_device("lid:buggy", lid_update_hw_on_key, LITEST_LID_SWITCH_SURFACE3);
        litest_add_for_device("lid:buggy", lid_update_hw_on_key_closed_on_init, LITEST_LID_SWITCH_SURFACE3);
+
+       litest_add_for_device("lid:keypress", lid_key_press, LITEST_GPIO_KEYS);
 }