[PATCH weston v2 5/6] tests: Add test for keyboard key event timestamps

Alexandros Frantzis alexandros.frantzis at collabora.com
Wed Dec 13 11:27:57 UTC 2017


Add test to verify that the server correctly sets the timestamps of
keyboard key events. This requires updating the weston-test protocol to
support passing key event timestamps.

simple_keyboard_test now uses the create_client_with_keyboard_focus()
helper function which changes the initial state of the surface to be
focused. This leads to one additional iteration of the test loop when
starting, during which the surface is deactivated, i.e., loses focus.
After this initial iteration the test continues as before.

Furthermore, simple_keyboard_test now uses the send_key() helper
function which performs a roundtrip internally. To account for this, the
client_roundtrip() function is now directly called in the loop only when
it is still required, i.e., when deactivating the surface.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis at collabora.com>
---

Changes in v2:
 - Add unit suffix "msec" to variables that hold event time.
 - Avoid double roundtrips in simple_keyboard_test.
 - Justify test changes in commit message.
 - Use the known good value 1 instead of 0 (KEY_RESERVED) when
   sending keys in tests.

 protocol/weston-test.xml          |  3 ++
 tests/keyboard-test.c             | 61 ++++++++++++++++++++++++++++++---------
 tests/weston-test-client-helper.c |  3 +-
 tests/weston-test-client-helper.h |  1 +
 tests/weston-test.c               |  3 +-
 5 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index a4a7ad4e..37fa221f 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -64,6 +64,9 @@
       <arg name="surface" type="object" interface="wl_surface" allow-null="true"/>
     </request>
     <request name="send_key">
+      <arg name="tv_sec_hi" type="uint"/>
+      <arg name="tv_sec_lo" type="uint"/>
+      <arg name="tv_nsec" type="uint"/>
       <arg name="key" type="uint"/>
       <arg name="state" type="uint"/>
     </request>
diff --git a/tests/keyboard-test.c b/tests/keyboard-test.c
index 6b4ba19d..722bfd32 100644
--- a/tests/keyboard-test.c
+++ b/tests/keyboard-test.c
@@ -27,21 +27,45 @@
 
 #include <stdint.h>
 
+#include "shared/timespec-util.h"
 #include "weston-test-client-helper.h"
 
+static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 1000001 };
+static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 2000001 };
+
+static struct client *
+create_client_with_keyboard_focus(void)
+{
+	struct client *cl = create_client_and_test_surface(10, 10, 1, 1);
+	assert(cl);
+
+	weston_test_activate_surface(cl->test->weston_test,
+				     cl->surface->wl_surface);
+	client_roundtrip(cl);
+
+	return cl;
+}
+
+static void
+send_key(struct client *client, const struct timespec *time,
+	 uint32_t key, uint32_t state)
+{
+	uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+	timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+	weston_test_send_key(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+			     tv_nsec, key, state);
+	client_roundtrip(client);
+}
+
 TEST(simple_keyboard_test)
 {
-	struct client *client;
-	struct surface *expect_focus = NULL;
-	struct keyboard *keyboard;
+	struct client *client = create_client_with_keyboard_focus();
+	struct keyboard *keyboard = client->input->keyboard;
+	struct surface *expect_focus = client->surface;
 	uint32_t expect_key = 0;
 	uint32_t expect_state = 0;
 
-	client = create_client_and_test_surface(10, 10, 1, 1);
-	assert(client);
-
-	keyboard = client->input->keyboard;
-
 	while (1) {
 		assert(keyboard->key == expect_key);
 		assert(keyboard->state == expect_state);
@@ -49,12 +73,12 @@ TEST(simple_keyboard_test)
 
 		if (keyboard->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
 			expect_state = WL_KEYBOARD_KEY_STATE_RELEASED;
-			weston_test_send_key(client->test->weston_test,
-					     expect_key, expect_state);
+			send_key(client, &t1, expect_key, expect_state);
 		} else if (keyboard->focus) {
 			expect_focus = NULL;
 			weston_test_activate_surface(
 				client->test->weston_test, NULL);
+			client_roundtrip(client);
 		} else if (expect_key < 10) {
 			expect_key++;
 			expect_focus = client->surface;
@@ -62,12 +86,21 @@ TEST(simple_keyboard_test)
 			weston_test_activate_surface(
 				client->test->weston_test,
 				expect_focus->wl_surface);
-			weston_test_send_key(client->test->weston_test,
-					     expect_key, expect_state);
+			send_key(client, &t1, expect_key, expect_state);
 		} else {
 			break;
 		}
-
-		client_roundtrip(client);
 	}
 }
+
+TEST(keyboard_key_event_time)
+{
+	struct client *client = create_client_with_keyboard_focus();
+	struct keyboard *keyboard = client->input->keyboard;
+
+	send_key(client, &t1, 1, WL_KEYBOARD_KEY_STATE_PRESSED);
+	assert(keyboard->key_time_msec == timespec_to_msec(&t1));
+
+	send_key(client, &t2, 1, WL_KEYBOARD_KEY_STATE_RELEASED);
+	assert(keyboard->key_time_msec == timespec_to_msec(&t2));
+}
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index 0a6f2a41..1ddb5454 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -273,13 +273,14 @@ keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard,
 
 static void
 keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
-		    uint32_t serial, uint32_t time, uint32_t key,
+		    uint32_t serial, uint32_t time_msec, uint32_t key,
 		    uint32_t state)
 {
 	struct keyboard *keyboard = data;
 
 	keyboard->key = key;
 	keyboard->state = state;
+	keyboard->key_time_msec = time_msec;
 
 	fprintf(stderr, "test-client: got keyboard key %u %u\n", key, state);
 }
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index 76f07491..74c1dbbb 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -111,6 +111,7 @@ struct keyboard {
 		int rate;
 		int delay;
 	} repeat_info;
+	uint32_t key_time_msec;
 };
 
 struct touch {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index bb1a4cd4..d07d84c4 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -227,13 +227,14 @@ activate_surface(struct wl_client *client, struct wl_resource *resource,
 
 static void
 send_key(struct wl_client *client, struct wl_resource *resource,
+	 uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
 	 uint32_t key, enum wl_keyboard_key_state state)
 {
 	struct weston_test *test = wl_resource_get_user_data(resource);
 	struct weston_seat *seat = get_seat(test);
 	struct timespec time;
 
-	timespec_from_msec(&time, 100);
+	timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
 
 	notify_key(seat, &time, key, state, STATE_UPDATE_AUTOMATIC);
 }
-- 
2.14.1



More information about the wayland-devel mailing list