Re: [PATCH weston 5/9] tests: Add weston test client helper methods

2012-12-05 Thread Pekka Paalanen
On Tue,  4 Dec 2012 14:22:11 -0800
"U. Artie Eoff"  wrote:

> From: "U. Artie Eoff" 
> 
> Add client boiler plate methods to simplify writing tests that use
> the weston test extension.
> 
> Signed-off-by: U. Artie Eoff 
> ---
>  tests/weston-test-client-helper.c | 488 
> ++
>  tests/weston-test-client-helper.h | 109 +
>  2 files changed, 597 insertions(+)
>  create mode 100644 tests/weston-test-client-helper.c
>  create mode 100644 tests/weston-test-client-helper.h
> 
> diff --git a/tests/weston-test-client-helper.c 
> b/tests/weston-test-client-helper.c
> new file mode 100644
> index 000..1859356
> --- /dev/null
> +++ b/tests/weston-test-client-helper.c
> @@ -0,0 +1,488 @@
> +/*
> + * Copyright © 2012 Intel Corporation
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and 
> its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that 
> copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided 
> "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS 
> SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 
> USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
> PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "../shared/os-compatibility.h"
> +#include "weston-test-client-helper.h"
> +
> +int
> +surface_contains(struct surface *surface, int x, int y)
> +{
> + /* test whether a global x,y point is contained in the surface */
> + int sx = surface->x;
> + int sy = surface->y;
> + int sw = surface->width;
> + int sh = surface->height;
> + return x >= sx && y >= sy && x < sx + sw && y < sy + sh;
> +}
> +
> +void
> +yield(struct client *client)
> +{
> + /*
> +  * FIXME: ugh! how do we ensure all events have finished
> +  * propagating to the client.  The calls to usleep seem to do a
> +  * pretty reasonable job... and without them, tests can fail
> +  * intermittently.
> +  */
> + usleep(0.02 * 1e6);
> + wl_display_flush(client->wl_display);
> + wl_display_roundtrip(client->wl_display);
> + usleep(0.02 * 1e6);

Hi Artie,

am I guessing the problem here right?

A roundtrip is not enough, because Weston does some of the processing
only during output repaint, like updating surface transforms and
something about input. Therefore you really want to wait until the next
repaint has completed (and hit the screen?).

Maybe you could add a callback request in the test protocol extension,
that works like roundtrip, except it is triggered only after repaint in
the compositor? Kind of like the frame callback, except without the
surface.

> +}
> +
> +void
> +move_pointer(struct client *client, int x, int y)
> +{
> + wl_test_move_pointer(client->test->wl_test, x, y);
> +
> + yield(client);
> +}
> +
> +void
> +move_client(struct client *client, int x, int y)
> +{
> + struct surface *surface = client->surface;
> +
> + client->surface->x = x;
> + client->surface->y = y;
> + wl_test_move_surface(client->test->wl_test, surface->wl_surface,
> +  surface->x, surface->y);
> + wl_surface_damage(surface->wl_surface, 0, 0, surface->width,
> +   surface->height);
> + wl_surface_commit(surface->wl_surface);
> +
> + yield(client);
> + yield(client);
> +}


Thanks,
pq
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 5/9] tests: Add weston test client helper methods

2012-12-04 Thread U. Artie Eoff
From: "U. Artie Eoff" 

Add client boiler plate methods to simplify writing tests that use
the weston test extension.

Signed-off-by: U. Artie Eoff 
---
 tests/weston-test-client-helper.c | 488 ++
 tests/weston-test-client-helper.h | 109 +
 2 files changed, 597 insertions(+)
 create mode 100644 tests/weston-test-client-helper.c
 create mode 100644 tests/weston-test-client-helper.h

diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
new file mode 100644
index 000..1859356
--- /dev/null
+++ b/tests/weston-test-client-helper.c
@@ -0,0 +1,488 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../shared/os-compatibility.h"
+#include "weston-test-client-helper.h"
+
+int
+surface_contains(struct surface *surface, int x, int y)
+{
+   /* test whether a global x,y point is contained in the surface */
+   int sx = surface->x;
+   int sy = surface->y;
+   int sw = surface->width;
+   int sh = surface->height;
+   return x >= sx && y >= sy && x < sx + sw && y < sy + sh;
+}
+
+void
+yield(struct client *client)
+{
+   /*
+* FIXME: ugh! how do we ensure all events have finished
+* propagating to the client.  The calls to usleep seem to do a
+* pretty reasonable job... and without them, tests can fail
+* intermittently.
+*/
+   usleep(0.02 * 1e6);
+   wl_display_flush(client->wl_display);
+   wl_display_roundtrip(client->wl_display);
+   usleep(0.02 * 1e6);
+}
+
+void
+move_pointer(struct client *client, int x, int y)
+{
+   wl_test_move_pointer(client->test->wl_test, x, y);
+
+   yield(client);
+}
+
+void
+move_client(struct client *client, int x, int y)
+{
+   struct surface *surface = client->surface;
+
+   client->surface->x = x;
+   client->surface->y = y;
+   wl_test_move_surface(client->test->wl_test, surface->wl_surface,
+surface->x, surface->y);
+   wl_surface_damage(surface->wl_surface, 0, 0, surface->width,
+ surface->height);
+   wl_surface_commit(surface->wl_surface);
+
+   yield(client);
+   yield(client);
+}
+
+static void
+pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
+uint32_t serial, struct wl_surface *wl_surface,
+wl_fixed_t x, wl_fixed_t y)
+{
+   struct pointer *pointer = data;
+
+   pointer->focus = wl_surface_get_user_data(wl_surface);
+   pointer->x = wl_fixed_to_int(x);
+   pointer->y = wl_fixed_to_int(y);
+
+   fprintf(stderr, "test-client: got pointer enter %d %d, surface %p\n",
+   pointer->x, pointer->y, pointer->focus);
+}
+
+static void
+pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
+uint32_t serial, struct wl_surface *wl_surface)
+{
+   struct pointer *pointer = data;
+
+   pointer->focus = NULL;
+
+   fprintf(stderr, "test-client: got pointer leave, surface %p\n",
+   wl_surface_get_user_data(wl_surface));
+}
+
+static void
+pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
+ uint32_t time, wl_fixed_t x, wl_fixed_t y)
+{
+   struct pointer *pointer = data;
+
+   pointer->x = wl_fixed_to_int(x);
+   pointer->y = wl_fixed_to_int(y);
+
+   fprintf(stderr, "test-client: got pointer motion %d %d\n",
+   pointer->x, pointer->y);
+}
+
+static void
+pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
+ uint32_t serial, uint32_t time, uint32_t button,
+ uint32_t state)
+{
+   struct pointer *pointer = data;
+
+   pointer->button = button;
+   pointer->state =