[PATCH weston v2 6/6] tests: Add test for touch event timestamps

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


Add test to verify that the server correctly sets the timestamps of
touch events. This requires updating the weston-test protocol with a new
request for touch events.

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

Changes in v2:
 - Add unit suffix "msec" to variables that hold event time.

 Makefile.am                       |  7 +++-
 protocol/weston-test.xml          |  9 +++++
 tests/touch-test.c                | 71 +++++++++++++++++++++++++++++++++++++++
 tests/weston-test-client-helper.c | 13 ++++---
 tests/weston-test-client-helper.h |  3 ++
 tests/weston-test.c               | 16 +++++++++
 6 files changed, 114 insertions(+), 5 deletions(-)
 create mode 100644 tests/touch-test.c

diff --git a/Makefile.am b/Makefile.am
index 7adc6254..4eb4f0da 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1233,7 +1233,8 @@ weston_tests =					\
 	roles.weston				\
 	subsurface.weston			\
 	subsurface-shot.weston			\
-	devices.weston
+	devices.weston				\
+	touch.weston
 
 ivi_tests =
 
@@ -1428,6 +1429,10 @@ nodist_viewporter_weston_SOURCES =		\
 viewporter_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
 viewporter_weston_LDADD = libtest-client.la
 
+touch_weston_SOURCES = tests/touch-test.c
+touch_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
+touch_weston_LDADD = libtest-client.la
+
 if ENABLE_XWAYLAND_TEST
 weston_tests +=	xwayland-test.weston
 xwayland_test_weston_SOURCES = tests/xwayland-test.c
diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index 37fa221f..00b7185d 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -96,6 +96,15 @@
 		provided buffer.
 	  </description>
     </event>
+    <request name="send_touch">
+      <arg name="tv_sec_hi" type="uint"/>
+      <arg name="tv_sec_lo" type="uint"/>
+      <arg name="tv_nsec" type="uint"/>
+      <arg name="touch_id" type="int"/>
+      <arg name="x" type="fixed"/>
+      <arg name="y" type="fixed"/>
+      <arg name="touch_type" type="uint"/>
+    </request>
   </interface>
 
   <interface name="weston_test_runner" version="1">
diff --git a/tests/touch-test.c b/tests/touch-test.c
new file mode 100644
index 00000000..9635257f
--- /dev/null
+++ b/tests/touch-test.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2017 Collabora, Ltd.
+ *
+ * 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 <time.h>
+
+#include "shared/timespec-util.h"
+#include "weston-test-client-helper.h"
+#include "wayland-server-protocol.h"
+
+static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 1000001 };
+static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 2000001 };
+static const struct timespec t3 = { .tv_sec = 3, .tv_nsec = 3000001 };
+
+static struct client *
+create_touch_test_client(void)
+{
+	struct client *cl = create_client_and_test_surface(0, 0, 100, 100);
+	assert(cl);
+	return cl;
+}
+
+static void
+send_touch(struct client *client, const struct timespec *time,
+	   uint32_t touch_type)
+{
+	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_touch(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+			       tv_nsec, 1, 1, 1, touch_type);
+	client_roundtrip(client);
+}
+
+TEST(touch_events)
+{
+	struct client *client = create_touch_test_client();
+	struct touch *touch = client->input->touch;
+
+	send_touch(client, &t1, WL_TOUCH_DOWN);
+	assert(touch->down_time_msec == timespec_to_msec(&t1));
+
+	send_touch(client, &t2, WL_TOUCH_MOTION);
+	assert(touch->motion_time_msec == timespec_to_msec(&t2));
+
+	send_touch(client, &t3, WL_TOUCH_UP);
+	assert(touch->up_time_msec == timespec_to_msec(&t3));
+}
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index 1ddb5454..6e0a5246 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -326,14 +326,16 @@ static const struct wl_keyboard_listener keyboard_listener = {
 
 static void
 touch_handle_down(void *data, struct wl_touch *wl_touch,
-		  uint32_t serial, uint32_t time, struct wl_surface *surface,
-		  int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
+		  uint32_t serial, uint32_t time_msec,
+		  struct wl_surface *surface, int32_t id,
+		  wl_fixed_t x_w, wl_fixed_t y_w)
 {
 	struct touch *touch = data;
 
 	touch->down_x = wl_fixed_to_int(x_w);
 	touch->down_y = wl_fixed_to_int(y_w);
 	touch->id = id;
+	touch->down_time_msec = time_msec;
 
 	fprintf(stderr, "test-client: got touch down %d %d, surf: %p, id: %d\n",
 		touch->down_x, touch->down_y, surface, id);
@@ -341,21 +343,24 @@ touch_handle_down(void *data, struct wl_touch *wl_touch,
 
 static void
 touch_handle_up(void *data, struct wl_touch *wl_touch,
-		uint32_t serial, uint32_t time, int32_t id)
+		uint32_t serial, uint32_t time_msec, int32_t id)
 {
 	struct touch *touch = data;
 	touch->up_id = id;
+	touch->up_time_msec = time_msec;
 
 	fprintf(stderr, "test-client: got touch up, id: %d\n", id);
 }
 
 static void
 touch_handle_motion(void *data, struct wl_touch *wl_touch,
-		    uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
+		    uint32_t time_msec, int32_t id,
+		    wl_fixed_t x_w, wl_fixed_t y_w)
 {
 	struct touch *touch = data;
 	touch->x = wl_fixed_to_int(x_w);
 	touch->y = wl_fixed_to_int(y_w);
+	touch->motion_time_msec = time_msec;
 
 	fprintf(stderr, "test-client: got touch motion, %d %d, id: %d\n",
 		touch->x, touch->y, id);
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index 74c1dbbb..643c07b9 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -124,6 +124,9 @@ struct touch {
 	int up_id; /* id of last wl_touch.up event */
 	int frame_no;
 	int cancel_no;
+	uint32_t down_time_msec;
+	uint32_t up_time_msec;
+	uint32_t motion_time_msec;
 };
 
 struct output {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index d07d84c4..80b3d65b 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -519,6 +519,21 @@ capture_screenshot(struct wl_client *client,
 				     capture_screenshot_done, resource);
 }
 
+static void
+send_touch(struct wl_client *client, struct wl_resource *resource,
+	   uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
+	   int32_t touch_id, wl_fixed_t x, wl_fixed_t y, uint32_t touch_type)
+{
+	struct weston_test *test = wl_resource_get_user_data(resource);
+	struct weston_seat *seat = get_seat(test);
+	struct timespec time;
+
+	timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
+
+	notify_touch(seat, &time, touch_id, wl_fixed_to_double(x),
+		     wl_fixed_to_double(y), touch_type);
+}
+
 static const struct weston_test_interface test_implementation = {
 	move_surface,
 	move_pointer,
@@ -529,6 +544,7 @@ static const struct weston_test_interface test_implementation = {
 	device_release,
 	device_add,
 	capture_screenshot,
+	send_touch,
 };
 
 static void
-- 
2.14.1



More information about the wayland-devel mailing list