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=100057 Signed-off-by: Peter Hutterer <[email protected]> --- meson.build | 1 + src/evdev-lid.c | 8 ++++ test/litest-device-lid-switch-power.c | 71 +++++++++++++++++++++++++++++++++++ test/litest.c | 2 + test/litest.h | 1 + test/test-lid.c | 20 ++++++++++ 6 files changed, 103 insertions(+) create mode 100644 test/litest-device-lid-switch-power.c diff --git a/meson.build b/meson.build index cf10b35f..224ff9ce 100644 --- a/meson.build +++ b/meson.build @@ -538,6 +538,7 @@ if get_option('tests') 'test/litest-device-keyboard-all-codes.c', 'test/litest-device-keyboard-razer-blackwidow.c', 'test/litest-device-lid-switch.c', + 'test/litest-device-lid-switch-power.c', 'test/litest-device-lid-switch-surface3.c', 'test/litest-device-logitech-trackball.c', 'test/litest-device-nexus4-touch-screen.c', diff --git a/src/evdev-lid.c b/src/evdev-lid.c index b3df37c2..6c438e00 100644 --- a/src/evdev-lid.c +++ b/src/evdev-lid.c @@ -298,6 +298,7 @@ struct evdev_dispatch * evdev_lid_switch_dispatch_create(struct evdev_device *lid_device) { struct lid_switch_dispatch *dispatch; + int type; dispatch = zalloc(sizeof *dispatch); dispatch->base.dispatch_type = DISPATCH_LID_SWITCH; @@ -309,5 +310,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-lid-switch-power.c b/test/litest-device-lid-switch-power.c new file mode 100644 index 00000000..c7a3d557 --- /dev/null +++ b/test/litest-device-lid-switch-power.c @@ -0,0 +1,71 @@ +/* + * Copyright © 2017 James Ye <[email protected]> + * + * 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_lid_switch_setup(void) +{ + struct litest_device *d = litest_create_device(LITEST_LID_SWITCH); + litest_set_current_device(d); +} + +static struct input_id input_id = { + .bustype = 0x19, + .vendor = 0x0, + .product = 0x5, +}; + +static int events[] = { + EV_SW, SW_LID, + 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 Lid Switch*\",\\\n" +" ENV{ID_INPUT_SWITCH}=\"1\",\\\n" +" ENV{LIBINPUT_ATTR_LID_SWITCH_RELIABILITY}=\"reliable\"\n" +"\n" +"LABEL=\"switch_end\""; + +struct litest_test_device litest_lid_switch_power_device = { + .type = LITEST_LID_SWITCH_POWER, + .features = LITEST_SWITCH, + .shortname = "lid switch power", + .setup = litest_lid_switch_setup, + .interface = NULL, + + .name = "Lid Switch", + .id = &input_id, + .events = events, + .absinfo = NULL, + + .udev_rule = udev_rule, +}; diff --git a/test/litest.c b/test/litest.c index f3f71448..29b821a4 100644 --- a/test/litest.c +++ b/test/litest.c @@ -414,6 +414,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_lid_switch_power_device; struct litest_test_device* devices[] = { &litest_synaptics_clickpad_device, @@ -479,6 +480,7 @@ struct litest_test_device* devices[] = { &litest_lid_switch_device, &litest_lid_switch_surface3_device, &litest_appletouch_device, + &litest_lid_switch_power_device, NULL, }; diff --git a/test/litest.h b/test/litest.h index 7086804e..a6f8098c 100644 --- a/test/litest.h +++ b/test/litest.h @@ -234,6 +234,7 @@ enum litest_device_type { LITEST_LID_SWITCH, LITEST_LID_SWITCH_SURFACE3, LITEST_APPLETOUCH, + LITEST_LID_SWITCH_POWER, }; enum litest_device_feature { diff --git a/test/test-lid.c b/test/test-lid.c index 4bf4c059..fee8440e 100644 --- a/test/test-lid.c +++ b/test/test-lid.c @@ -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_LID_SWITCH_POWER); } -- 2.13.3 _______________________________________________ wayland-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/wayland-devel
