summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2017-01-30 12:58:37 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2017-01-30 15:26:45 +1000
commitdc15a42d6cae4195d327253f6f05b65665eb3a93 (patch)
tree4d792347568fa7812ee71c0dcf68e0e5959a4550 /test
parent078564ce7a590454c6bb9663d3a3017c56b0b7e2 (diff)
switch: for surface 3 tablets, write the lid open to the device
These tablets only ever give us a close event, the open event is broken. So when we detect keyboard events, fix the kernel device's state by writing the event to the fd. We still sync the lid state manually, in case this fails and we don't get the SW_LID through the normal event sequence. If it works fine, the real open event will just be ignored. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am1
-rw-r--r--test/litest-device-lid-switch-surface3.c71
-rw-r--r--test/litest.c2
-rw-r--r--test/litest.h1
-rw-r--r--test/test-lid.c98
5 files changed, 173 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index ce1973f..2e565de 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -33,6 +33,7 @@ liblitest_la_SOURCES = \
litest-device-keyboard-all-codes.c \
litest-device-keyboard-razer-blackwidow.c \
litest-device-lid-switch.c \
+ litest-device-lid-switch-surface3.c \
litest-device-logitech-trackball.c \
litest-device-nexus4-touch-screen.c \
litest-device-magic-trackpad.c \
diff --git a/test/litest-device-lid-switch-surface3.c b/test/litest-device-lid-switch-surface3.c
new file mode 100644
index 0000000..fde15c2
--- /dev/null
+++ b/test/litest-device-lid-switch-surface3.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2017 James Ye <jye836@gmail.com>
+ * 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_lid_switch_setup(void)
+{
+ struct litest_device *d = litest_create_device(LITEST_LID_SWITCH_SURFACE3);
+ litest_set_current_device(d);
+}
+
+static struct input_id input_id = {
+ .bustype = 0x19,
+ .vendor = 0x0,
+ .product = 0x5,
+};
+
+static int events[] = {
+ EV_SW, SW_LID,
+ -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 Surface3*\",\\\n"
+" ENV{ID_INPUT_SWITCH}=\"1\",\\\n"
+" ENV{LIBINPUT_ATTR_LID_SWITCH_RELIABILITY}=\"write_open\"\n"
+"\n"
+"LABEL=\"switch_end\"";
+
+struct litest_test_device litest_lid_switch_surface3_device = {
+ .type = LITEST_LID_SWITCH_SURFACE3,
+ .features = LITEST_SWITCH,
+ .shortname = "lid-switch-surface3",
+ .setup = litest_lid_switch_setup,
+ .interface = NULL,
+
+ .name = "Lid Switch Surface3",
+ .id = &input_id,
+ .events = events,
+ .absinfo = NULL,
+
+ .udev_rule = udev_rule,
+};
diff --git a/test/litest.c b/test/litest.c
index 7a5ec57..1756940 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -409,6 +409,7 @@ extern struct litest_test_device litest_acer_hawaii_touchpad_device;
extern struct litest_test_device litest_synaptics_rmi4_device;
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;
struct litest_test_device* devices[] = {
&litest_synaptics_clickpad_device,
@@ -472,6 +473,7 @@ struct litest_test_device* devices[] = {
&litest_synaptics_rmi4_device,
&litest_mouse_wheel_tilt_device,
&litest_lid_switch_device,
+ &litest_lid_switch_surface3_device,
NULL,
};
diff --git a/test/litest.h b/test/litest.h
index 0075604..d779f0f 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -230,6 +230,7 @@ enum litest_device_type {
LITEST_SYNAPTICS_RMI4,
LITEST_MOUSE_WHEEL_TILT,
LITEST_LID_SWITCH,
+ LITEST_LID_SWITCH_SURFACE3,
};
enum litest_device_feature {
diff --git a/test/test-lid.c b/test/test-lid.c
index 6577d23..a5f439a 100644
--- a/test/test-lid.c
+++ b/test/test-lid.c
@@ -87,12 +87,32 @@ START_TEST(lid_switch_double)
}
END_TEST
+static bool
+lid_switch_is_reliable(struct litest_device *dev)
+{
+ struct udev_device *udev_device;
+ const char *prop;
+ bool is_reliable = false;
+
+ udev_device = libinput_device_get_udev_device(dev->libinput_device);
+ prop = udev_device_get_property_value(udev_device,
+ "LIBINPUT_ATTR_LID_SWITCH_RELIABILITY");
+
+ is_reliable = prop && streq(prop, "reliable");
+ udev_device_unref(udev_device);
+
+ return is_reliable;
+}
+
START_TEST(lid_switch_down_on_init)
{
struct litest_device *sw = litest_current_device();
struct libinput *li;
struct libinput_event *event;
+ if (!lid_switch_is_reliable(sw))
+ return;
+
litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON);
/* need separate context to test */
@@ -128,6 +148,35 @@ START_TEST(lid_switch_down_on_init)
}
END_TEST
+START_TEST(lid_switch_not_down_on_init)
+{
+ struct litest_device *sw = litest_current_device();
+ struct libinput *li;
+ struct libinput_event *event;
+
+ if (lid_switch_is_reliable(sw))
+ return;
+
+ litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON);
+
+ /* need separate context to test */
+ li = litest_create_context();
+ libinput_path_add_device(li,
+ libevdev_uinput_get_devnode(sw->uinput));
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li)) != NULL) {
+ ck_assert_int_ne(libinput_event_get_type(event),
+ LIBINPUT_EVENT_SWITCH_TOGGLE);
+ libinput_event_destroy(event);
+ }
+
+ litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF);
+ litest_assert_empty_queue(li);
+ libinput_unref(li);
+}
+END_TEST
+
static inline struct litest_device *
lid_init_paired_touchpad(struct libinput *li)
{
@@ -358,12 +407,59 @@ START_TEST(lid_open_on_key_touchpad_enabled)
}
END_TEST
+START_TEST(lid_update_hw_on_key)
+{
+ struct litest_device *sw = litest_current_device();
+ struct libinput *li = sw->libinput;
+ struct libinput *li2;
+ struct litest_device *keyboard;
+ struct libinput_event *event;
+
+ sleep(5);
+ keyboard = litest_add_device(li, LITEST_KEYBOARD);
+
+ /* separate context to listen to the fake hw event */
+ li2 = litest_create_context();
+ libinput_path_add_device(li2,
+ libevdev_uinput_get_devnode(sw->uinput));
+ litest_drain_events(li2);
+
+ litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON);
+ litest_drain_events(li);
+
+ libinput_dispatch(li2);
+ event = libinput_get_event(li2);
+ litest_is_switch_event(event,
+ LIBINPUT_SWITCH_LID,
+ LIBINPUT_SWITCH_STATE_ON);
+ libinput_event_destroy(event);
+
+ litest_event(keyboard, EV_KEY, KEY_A, 1);
+ litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
+ litest_event(keyboard, EV_KEY, KEY_A, 0);
+ litest_event(keyboard, EV_SYN, SYN_REPORT, 0);
+ litest_drain_events(li);
+
+ libinput_dispatch(li2);
+ event = libinput_get_event(li2);
+ litest_is_switch_event(event,
+ LIBINPUT_SWITCH_LID,
+ LIBINPUT_SWITCH_STATE_OFF);
+ libinput_event_destroy(event);
+ litest_assert_empty_queue(li);
+
+ libinput_unref(li2);
+ litest_delete_device(keyboard);
+}
+END_TEST
+
void
litest_setup_tests_lid(void)
{
litest_add("lid:switch", lid_switch, LITEST_SWITCH, LITEST_ANY);
litest_add("lid:switch", lid_switch_double, LITEST_SWITCH, LITEST_ANY);
litest_add("lid:switch", lid_switch_down_on_init, LITEST_SWITCH, LITEST_ANY);
+ litest_add("lid:switch", lid_switch_not_down_on_init, LITEST_SWITCH, LITEST_ANY);
litest_add("lid:disable_touchpad", lid_disable_touchpad, LITEST_SWITCH, LITEST_ANY);
litest_add("lid:disable_touchpad", lid_disable_touchpad_during_touch, LITEST_SWITCH, LITEST_ANY);
litest_add("lid:disable_touchpad", lid_disable_touchpad_edge_scroll, LITEST_SWITCH, LITEST_ANY);
@@ -372,4 +468,6 @@ litest_setup_tests_lid(void)
litest_add("lid:keyboard", lid_open_on_key, LITEST_SWITCH, LITEST_ANY);
litest_add("lid:keyboard", lid_open_on_key_touchpad_enabled, LITEST_SWITCH, LITEST_ANY);
+
+ litest_add_for_device("lid:buggy", lid_update_hw_on_key, LITEST_LID_SWITCH_SURFACE3);
}