blob: 9b74564cf91be8785eb179a9b564b950961832f3 [file] [log] [blame]
Alexandros Frantzis27d7c392018-10-19 12:14:11 +03001/*
2 * Copyright © 2018 Collabora, Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <string.h>
Alexandros Frantzisacff29b2018-10-19 12:14:11 +030029#include <unistd.h>
Alexandros Frantzis27d7c392018-10-19 12:14:11 +030030
31#include "linux-explicit-synchronization-unstable-v1-client-protocol.h"
32#include "weston-test-client-helper.h"
33#include "wayland-server-protocol.h"
34
35static struct zwp_linux_explicit_synchronization_v1 *
36get_linux_explicit_synchronization(struct client *client)
37{
38 struct global *g;
39 struct global *global_sync = NULL;
40 struct zwp_linux_explicit_synchronization_v1 *sync = NULL;
41
42 wl_list_for_each(g, &client->global_list, link) {
43 if (strcmp(g->interface,
44 zwp_linux_explicit_synchronization_v1_interface.name))
45 continue;
46
47 if (global_sync)
48 assert(!"Multiple linux explicit sync objects");
49
50 global_sync = g;
51 }
52
53 assert(global_sync);
54 assert(global_sync->version == 1);
55
56 sync = wl_registry_bind(
57 client->wl_registry, global_sync->name,
58 &zwp_linux_explicit_synchronization_v1_interface, 1);
59 assert(sync);
60
61 return sync;
62}
63
64static struct client *
65create_test_client(void)
66{
67 struct client *cl = create_client_and_test_surface(0, 0, 100, 100);
68 assert(cl);
69 return cl;
70}
71
72TEST(second_surface_synchronization_on_surface_raises_error)
73{
74 struct client *client = create_test_client();
75 struct zwp_linux_explicit_synchronization_v1 *sync =
76 get_linux_explicit_synchronization(client);
77 struct zwp_linux_surface_synchronization_v1 *surface_sync1;
78 struct zwp_linux_surface_synchronization_v1 *surface_sync2;
79
80 surface_sync1 =
81 zwp_linux_explicit_synchronization_v1_get_synchronization(
82 sync, client->surface->wl_surface);
83 client_roundtrip(client);
84
85 /* Second surface_synchronization creation should fail */
86 surface_sync2 =
87 zwp_linux_explicit_synchronization_v1_get_synchronization(
88 sync, client->surface->wl_surface);
89 expect_protocol_error(
90 client,
91 &zwp_linux_explicit_synchronization_v1_interface,
92 ZWP_LINUX_EXPLICIT_SYNCHRONIZATION_V1_ERROR_SYNCHRONIZATION_EXISTS);
93
94 zwp_linux_surface_synchronization_v1_destroy(surface_sync2);
95 zwp_linux_surface_synchronization_v1_destroy(surface_sync1);
96 zwp_linux_explicit_synchronization_v1_destroy(sync);
97}
Alexandros Frantzisacff29b2018-10-19 12:14:11 +030098
99TEST(set_acquire_fence_with_invalid_fence_raises_error)
100{
101 struct client *client = create_test_client();
102 struct zwp_linux_explicit_synchronization_v1 *sync =
103 get_linux_explicit_synchronization(client);
104 struct zwp_linux_surface_synchronization_v1 *surface_sync =
105 zwp_linux_explicit_synchronization_v1_get_synchronization(
106 sync, client->surface->wl_surface);
107 int pipefd[2] = { -1, -1 };
108
109 assert(pipe(pipefd) == 0);
110
111 zwp_linux_surface_synchronization_v1_set_acquire_fence(surface_sync,
112 pipefd[0]);
113 expect_protocol_error(
114 client,
115 &zwp_linux_surface_synchronization_v1_interface,
116 ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_INVALID_FENCE);
117
118 close(pipefd[0]);
119 close(pipefd[1]);
120 zwp_linux_surface_synchronization_v1_destroy(surface_sync);
121 zwp_linux_explicit_synchronization_v1_destroy(sync);
122}
123
124TEST(set_acquire_fence_on_destroyed_surface_raises_error)
125{
126 struct client *client = create_test_client();
127 struct zwp_linux_explicit_synchronization_v1 *sync =
128 get_linux_explicit_synchronization(client);
129 struct zwp_linux_surface_synchronization_v1 *surface_sync =
130 zwp_linux_explicit_synchronization_v1_get_synchronization(
131 sync, client->surface->wl_surface);
132 int pipefd[2] = { -1, -1 };
133
134 assert(pipe(pipefd) == 0);
135
136 wl_surface_destroy(client->surface->wl_surface);
137 zwp_linux_surface_synchronization_v1_set_acquire_fence(surface_sync,
138 pipefd[0]);
139 expect_protocol_error(
140 client,
141 &zwp_linux_surface_synchronization_v1_interface,
142 ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_SURFACE);
143
144 close(pipefd[0]);
145 close(pipefd[1]);
146 zwp_linux_surface_synchronization_v1_destroy(surface_sync);
147 zwp_linux_explicit_synchronization_v1_destroy(sync);
148}