[PATCH weston] tests: Add XWayland test
Tiago Vignatti
tiago.vignatti at intel.com
Tue Jan 22 14:19:11 PST 2013
Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
configure.ac | 2 +
tests/.gitignore | 1 +
tests/Makefile.am | 7 ++-
tests/weston-tests-env | 4 +-
tests/xwayland-test.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 145 insertions(+), 3 deletions(-)
create mode 100644 tests/xwayland-test.c
diff --git a/configure.ac b/configure.ac
index 64505dd..b343e6e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,6 +57,8 @@ if test x$enable_xwayland = xyes; then
PKG_CHECK_MODULES([XWAYLAND], xcb xcb-xfixes xcursor cairo-xcb)
AC_DEFINE([BUILD_XWAYLAND], [1], [Build the X server launcher])
+ PKG_CHECK_MODULES([XWAYLAND_TEST], xcb xcb-dri2 libdrm)
+
AC_ARG_WITH(xserver-path, AS_HELP_STRING([--with-xserver-path=PATH],
[Path to X server]), [XSERVER_PATH="$withval"],
[XSERVER_PATH="$bindir/Xorg"])
diff --git a/tests/.gitignore b/tests/.gitignore
index d8086a9..05bc024 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -10,3 +10,4 @@ text-test
keyboard-test
event-test
button-test
+xwayland-test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7d6b6e0..477cb96 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,7 +8,8 @@ weston_tests = \
keyboard-test \
event-test \
button-test \
- text-test
+ text-test \
+ xwayland-test
TESTS_ENVIRONMENT = $(SHELL) $(top_srcdir)/tests/weston-tests-env
@@ -74,6 +75,10 @@ text_test_SOURCES = \
$(weston_test_client_src)
text_test_LDADD = $(weston_test_client_libs)
+xwayland_test_SOURCES = xwayland-test.c $(weston_test_client_src)
+
+xwayland_test_LDADD = $(weston_test_client_libs) $(XWAYLAND_TEST_LIBS)
+
matrix_test_SOURCES = \
matrix-test.c \
$(top_srcdir)/shared/matrix.c \
diff --git a/tests/weston-tests-env b/tests/weston-tests-env
index dae1cda..159709e 100755
--- a/tests/weston-tests-env
+++ b/tests/weston-tests-env
@@ -21,7 +21,7 @@ fi
case $1 in
*.la|*.so)
$WESTON --backend=$BACKEND \
- --modules=$abs_builddir/.libs/${1/.la/.so} \
+ --modules=$abs_builddir/.libs/${1/.la/.so},xwayland.so \
--log="$SERVERLOG" \
&> "$OUTLOG"
;;
@@ -29,6 +29,6 @@ case $1 in
WESTON_TEST_CLIENT_PATH=$abs_builddir/$1 $WESTON \
--backend=$BACKEND \
--log="$SERVERLOG" \
- --modules=$abs_builddir/.libs/weston-test.so \
+ --modules=$abs_builddir/.libs/weston-test.so,xwayland.so \
&> "$OUTLOG"
esac
diff --git a/tests/xwayland-test.c b/tests/xwayland-test.c
new file mode 100644
index 0000000..000491a
--- /dev/null
+++ b/tests/xwayland-test.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright © 2013 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.
+ *
+ * Author: Tiago Vignatti
+ *
+ * xwayland-test: the test idea is to guarantee that XWayland infrastructure
+ * in general works with Weston.
+ *
+ * In particular, the create_window() test tries to catch a tricky situation
+ * where an X11 client performs a blocking request (DRI2Authentication) while
+ * the window manager is busy in another blocking call (xcb_get_property_reply
+ * -> xcb_wait_for_reply) that was just triggered by client's
+ * xcb_change_property(). If the implementation consists of three independent
+ * processes (Weston, the XWM and X server) then everything should
+ * be okay and no deadlock state would happen. If the implementation is two
+ * single threaded processes (Weston + XWM together and X server) then a
+ * carefully solution needs to be designed.
+ */
+
+#include "weston-test-runner.h"
+
+#include <assert.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+#include <xcb/xcb.h>
+#include <xcb/dri2.h>
+#include <xf86drm.h>
+
+
+static int
+dri2_open(xcb_connection_t *c, xcb_screen_t *screen)
+{
+ xcb_dri2_connect_cookie_t cookie;
+ xcb_dri2_connect_reply_t *reply;
+ xcb_dri2_authenticate_cookie_t cookie_auth;
+ xcb_dri2_authenticate_reply_t *reply_auth;
+ char *driver, *device;
+ int fd;
+ drm_magic_t magic;
+
+ cookie = xcb_dri2_connect(c, screen->root, XCB_DRI2_DRIVER_TYPE_DRI);
+ reply = xcb_dri2_connect_reply(c, cookie, 0);
+ assert(reply);
+
+ driver = strndup(xcb_dri2_connect_driver_name (reply),
+ xcb_dri2_connect_driver_name_length (reply));
+ device = strndup(xcb_dri2_connect_device_name (reply),
+ xcb_dri2_connect_device_name_length (reply));
+
+ printf ("Connecting to %s driver on %s\n", driver, device);
+ free(driver);
+ free(device);
+
+ fd = open("/dev/dri/card0", O_RDWR);
+ if (fd < 0)
+ return -1;
+
+ drmGetMagic(fd, &magic);
+
+ cookie_auth = xcb_dri2_authenticate(c, screen->root, magic);
+ reply_auth = xcb_dri2_authenticate_reply(c, cookie_auth, 0);
+ assert(reply_auth);
+
+ return fd;
+}
+
+static int
+create_window(void)
+{
+ xcb_connection_t *c;
+ xcb_screen_t *screen;
+ xcb_window_t win;
+ int fd;
+
+ c = xcb_connect (NULL, NULL);
+ if (c == NULL) {
+ printf("failed to get X11 connection\n");
+ return -1;
+ }
+
+ screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
+
+ win = xcb_generate_id(c);
+ xcb_create_window(c, XCB_COPY_FROM_PARENT, win, screen->root,
+ 0, 0, 150, 150, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ screen->root_visual, 0, NULL);
+
+ xcb_change_property (c, XCB_PROP_MODE_REPLACE, win,
+ XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
+ 5, "title");
+ xcb_map_window(c, win);
+ xcb_flush(c);
+
+ fd = dri2_open(c, screen);
+ if (fd < 0)
+ return -1;
+
+ xcb_destroy_window(c, win);
+ xcb_disconnect(c);
+ return 0;
+}
+
+TEST(xwayland_client_test)
+{
+ int i, num_tests;
+
+ /* TODO: explain why num_tests times */
+ num_tests = 10;
+ for (i = 0; i < num_tests; i++)
+ assert(create_window() == 0);
+
+ exit(EXIT_SUCCESS);
+}
--
1.7.9.5
More information about the wayland-devel
mailing list