blob: e94e8f52d4eeea6dc4faf8107cc45e5bee28c0c3 [file] [log] [blame]
Tiago Vignatti19dadf22013-02-08 14:57:00 +02001/*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Author: Tiago Vignatti
23 *
24 * xwayland-test: the idea is to guarantee that XWayland infrastructure in
25 * general works with Weston.
26 */
27
Bryce Harrington12cc4052014-11-19 17:18:33 -080028#include "config.h"
Tiago Vignatti19dadf22013-02-08 14:57:00 +020029
30#include <assert.h>
31#include <unistd.h>
32#include <stdlib.h>
33#include <stdio.h>
34#include <fcntl.h>
35#include <string.h>
36#include <xcb/xcb.h>
37#include <xcb/dri2.h>
38#include <xf86drm.h>
39
Bryce Harrington12cc4052014-11-19 17:18:33 -080040#include "weston-test-runner.h"
41
Tiago Vignatti19dadf22013-02-08 14:57:00 +020042
43static int
44dri2_open(xcb_connection_t *c, xcb_screen_t *screen)
45{
46 xcb_dri2_connect_cookie_t cookie;
47 xcb_dri2_connect_reply_t *reply;
48 xcb_dri2_authenticate_cookie_t cookie_auth;
49 xcb_dri2_authenticate_reply_t *reply_auth;
50 char *driver, *device;
51 int fd;
52 drm_magic_t magic;
53
54 cookie = xcb_dri2_connect(c, screen->root, XCB_DRI2_DRIVER_TYPE_DRI);
55 reply = xcb_dri2_connect_reply(c, cookie, 0);
56 assert(reply);
57
58 driver = strndup(xcb_dri2_connect_driver_name (reply),
59 xcb_dri2_connect_driver_name_length (reply));
60 device = strndup(xcb_dri2_connect_device_name (reply),
61 xcb_dri2_connect_device_name_length (reply));
62
63 fd = open(device, O_RDWR);
64 printf ("Trying connect to %s driver on %s\n", driver, device);
65 free(driver);
66 free(device);
67
68 if (fd < 0)
69 return -1;
70
71 drmGetMagic(fd, &magic);
72
73 cookie_auth = xcb_dri2_authenticate(c, screen->root, magic);
74 reply_auth = xcb_dri2_authenticate_reply(c, cookie_auth, 0);
75 assert(reply_auth);
76
77 return fd;
78}
79
80static int
81create_window(void)
82{
83 xcb_connection_t *c;
84 xcb_screen_t *screen;
85 xcb_window_t win;
86 int fd;
87
88 c = xcb_connect (NULL, NULL);
89 if (c == NULL) {
90 printf("failed to get X11 connection\n");
91 return -1;
92 }
93
94 screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
95
96 win = xcb_generate_id(c);
97 xcb_create_window(c, XCB_COPY_FROM_PARENT, win, screen->root,
98 0, 0, 150, 150, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT,
99 screen->root_visual, 0, NULL);
100
101 xcb_change_property (c, XCB_PROP_MODE_REPLACE, win,
102 XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
103 5, "title");
104 xcb_map_window(c, win);
105 xcb_flush(c);
106
107 fd = dri2_open(c, screen);
108 if (fd < 0)
109 return -1;
110
111 xcb_destroy_window(c, win);
112 xcb_disconnect(c);
113 return 0;
114}
115
116/*
117 * Ideally, the X Window Manager (XWM) and Weston Wayland compositor shouldn't
118 * be in the same process because they are using two different protocol
119 * streams in which one does not interface with the other. Probably the
120 * biggest problem with such architecture are the potentials dead locks that
121 * it may occur. So hypothetically, an X client might issue an X11 blocking
122 * request via X (DRI2Authenticate) which in turn sends a Wayland blocking
123 * request for Weston process it. X is blocked. At the same time, XWM might be
124 * trying to process an XChangeProperty, so it requests a blocking X11 call to
125 * the X server (xcb_get_property_reply -> xcb_wait_for_reply) which therefore
126 * will blocks there. It's a deadlock situation and this test is trying to
127 * catch that.
128 */
129static void
130check_dri2_authenticate(void)
131{
132 int i, num_tests;
133
134 /* TODO: explain why num_tests times */
135 num_tests = 10;
136 for (i = 0; i < num_tests; i++)
137 assert(create_window() == 0);
138}
139
140TEST(xwayland_client_test)
141{
142 check_dri2_authenticate();
143 exit(EXIT_SUCCESS);
144}