Merge lp:~cemil-azizoglu/mir/separate_out_render_surface_tests into lp:mir
- separate_out_render_surface_tests
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Daniel van Vugt |
Approved revision: | no longer in the source branch. |
Merged at revision: | 3857 |
Proposed branch: | lp:~cemil-azizoglu/mir/separate_out_render_surface_tests |
Merge into: | lp:mir |
Diff against target: |
777 lines (+411/-245) 4 files modified
tests/acceptance-tests/staging/test_render_surface.cpp (+4/-10) tests/unit-tests/client/CMakeLists.txt (+1/-0) tests/unit-tests/client/test_mir_connection.cpp (+3/-235) tests/unit-tests/client/test_mir_render_surface.cpp (+403/-0) |
To merge this branch: | bzr merge lp:~cemil-azizoglu/mir/separate_out_render_surface_tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel van Vugt | Approve | ||
Mir CI Bot | continuous-integration | Approve | |
Alan Griffiths | Approve | ||
Review via email: mp+312101@code.launchpad.net |
Commit message
Separate out render surface unit tests into their own file. General cleanups. No functional changes.
Description of the change
Mir CI Bot (mir-ci-bot) wrote : | # |
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
^^ mir_demo_
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3854
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
FAILURE: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Alan Griffiths (alan-griffiths) wrote : | # |
+struct MockRpcChannel : public mir::client:
+ public mir::dispatch:
Seems to be a a copy with bits cut out, seems like some further cleanup is in order.
Alan Griffiths (alan-griffiths) wrote : | # |
Apart from the probable DRY violation seems OK.
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3855
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
^ 1606418
Rebuilding
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:3855
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'tests/acceptance-tests/staging/test_render_surface.cpp' |
2 | --- tests/acceptance-tests/staging/test_render_surface.cpp 2016-11-23 00:09:04 +0000 |
3 | +++ tests/acceptance-tests/staging/test_render_surface.cpp 2016-11-30 16:59:20 +0000 |
4 | @@ -98,6 +98,7 @@ |
5 | physical_size.width.as_int(), physical_size.height.as_int(), |
6 | mir_pixel_format_abgr_8888, |
7 | mir_buffer_usage_hardware); |
8 | + |
9 | ASSERT_THAT(bs, NotNull()); |
10 | EXPECT_TRUE(mir_buffer_stream_is_valid(bs)); |
11 | EXPECT_THAT(mir_buffer_stream_get_error_message(bs), StrEq("")); |
12 | @@ -109,26 +110,22 @@ |
13 | TEST_F(RenderSurfaceTest, render_surfaces_without_content_can_be_added_to_spec) |
14 | { |
15 | auto physical_size = logical_size; |
16 | - |
17 | auto connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); |
18 | |
19 | auto rs = mir_connection_create_render_surface_sync( |
20 | connection, logical_size.width.as_int(), logical_size.height.as_int()); |
21 | - |
22 | auto spec = mir_connection_create_spec_for_normal_surface( |
23 | connection, |
24 | physical_size.width.as_int(), physical_size.height.as_int(), |
25 | mir_pixel_format_invalid); |
26 | - |
27 | mir_surface_spec_add_render_surface( |
28 | spec, rs, logical_size.width.as_int(), logical_size.height.as_int(), 0, 0); |
29 | - |
30 | auto surface = mir_surface_create_sync(spec); |
31 | mir_surface_spec_release(spec); |
32 | |
33 | EXPECT_THAT(surface, IsValid()); |
34 | - |
35 | EXPECT_THAT(mir_surface_get_buffer_stream(surface), Eq(nullptr)); |
36 | + |
37 | mir_render_surface_release(rs); |
38 | mir_surface_release_sync(surface); |
39 | mir_connection_release(connection); |
40 | @@ -143,25 +140,22 @@ |
41 | auto connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); |
42 | |
43 | auto rs = mir_connection_create_render_surface_sync( |
44 | - connection, logical_size.width.as_int(), logical_size.height.as_int()); |
45 | + connection, logical_size.width.as_int(), logical_size.height.as_int()); |
46 | auto spec = mir_connection_create_spec_for_normal_surface(connection, |
47 | width, height, |
48 | format); |
49 | - |
50 | mir_surface_spec_add_render_surface(spec, rs, width, height, 0, 0); |
51 | - |
52 | auto surface = mir_surface_create_sync(spec); |
53 | mir_surface_spec_release(spec); |
54 | - |
55 | auto bs = mir_render_surface_get_buffer_stream(rs, |
56 | 640, 480, |
57 | format, |
58 | usage); |
59 | |
60 | EXPECT_THAT(surface, IsValid()); |
61 | - |
62 | EXPECT_THAT(mir_surface_get_buffer_stream(surface), Eq(nullptr)); |
63 | EXPECT_TRUE(mir_buffer_stream_is_valid(bs)); |
64 | + |
65 | mir_render_surface_release(rs); |
66 | mir_surface_release_sync(surface); |
67 | mir_connection_release(connection); |
68 | |
69 | === modified file 'tests/unit-tests/client/CMakeLists.txt' |
70 | --- tests/unit-tests/client/CMakeLists.txt 2016-10-26 05:15:38 +0000 |
71 | +++ tests/unit-tests/client/CMakeLists.txt 2016-11-30 16:59:20 +0000 |
72 | @@ -23,6 +23,7 @@ |
73 | ${CMAKE_CURRENT_SOURCE_DIR}/test_error_buffer.cpp |
74 | ${CMAKE_CURRENT_SOURCE_DIR}/test_client_mir_error.cpp |
75 | ${CMAKE_CURRENT_SOURCE_DIR}/test_no_tls_future.cpp |
76 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_mir_render_surface.cpp |
77 | ) |
78 | |
79 | if (NOT MIR_DISABLE_INPUT) |
80 | |
81 | === modified file 'tests/unit-tests/client/test_mir_connection.cpp' |
82 | --- tests/unit-tests/client/test_mir_connection.cpp 2016-11-23 00:09:04 +0000 |
83 | +++ tests/unit-tests/client/test_mir_connection.cpp 2016-11-30 16:59:20 +0000 |
84 | @@ -23,8 +23,6 @@ |
85 | #include "src/client/mir_surface.h" |
86 | #include "src/client/buffer_factory.h" |
87 | #include "src/client/presentation_chain.h" |
88 | -#include "src/client/render_surface.h" |
89 | -#include "src/client/connection_surface_map.h" |
90 | |
91 | #include "mir/client_platform.h" |
92 | #include "mir/client_platform_factory.h" |
93 | @@ -36,7 +34,6 @@ |
94 | #include "mir_toolkit/mir_presentation_chain.h" |
95 | |
96 | #include "src/server/frontend/resource_cache.h" /* needed by test_server.h */ |
97 | -#include "mir/test/fake_shared.h" |
98 | #include "mir/test/test_protobuf_server.h" |
99 | #include "mir/test/stub_server_tool.h" |
100 | #include "mir/test/doubles/mock_mir_buffer.h" |
101 | @@ -57,31 +54,11 @@ |
102 | namespace mev = mir::events; |
103 | namespace md = mir::dispatch; |
104 | namespace geom = mir::geometry; |
105 | -namespace mt = mir::test; |
106 | -namespace mtd = mt::doubles; |
107 | +namespace mtd = mir::test::doubles; |
108 | using namespace testing; |
109 | |
110 | namespace |
111 | { |
112 | - |
113 | -void assign_result(void* result, void** context) |
114 | -{ |
115 | - if (context) |
116 | - *context = result; |
117 | -} |
118 | - |
119 | -struct RenderSurfaceCallback |
120 | -{ |
121 | - static void created(MirRenderSurface* render_surface, void *client_context) |
122 | - { |
123 | - auto const context = reinterpret_cast<RenderSurfaceCallback*>(client_context); |
124 | - context->invoked = true; |
125 | - context->resulting_render_surface = render_surface; |
126 | - } |
127 | - bool invoked = false; |
128 | - MirRenderSurface* resulting_render_surface = nullptr; |
129 | -}; |
130 | - |
131 | struct BufferStreamCallback |
132 | { |
133 | static void created(MirBufferStream* stream, void *client_context) |
134 | @@ -202,15 +179,12 @@ |
135 | auto native_display = std::make_shared<EGLNativeDisplayType>(); |
136 | *native_display = reinterpret_cast<EGLNativeDisplayType>(0x0); |
137 | |
138 | - auto native_window = std::make_shared<EGLNativeWindowType>(); |
139 | - *native_window = reinterpret_cast<EGLNativeWindowType>(0x12345678); |
140 | - |
141 | ON_CALL(*this, create_egl_native_display()) |
142 | .WillByDefault(Return(native_display)); |
143 | ON_CALL(*this, create_buffer_factory()) |
144 | .WillByDefault(Return(std::make_shared<mtd::StubClientBufferFactory>())); |
145 | ON_CALL(*this, create_egl_native_window(_)) |
146 | - .WillByDefault(Return(native_window)); |
147 | + .WillByDefault(Return(std::shared_ptr<EGLNativeWindowType>())); |
148 | ON_CALL(*this, platform_operation(_)) |
149 | .WillByDefault(Return(nullptr)); |
150 | } |
151 | @@ -232,8 +206,7 @@ |
152 | MOCK_METHOD2(use_egl_native_window, void(std::shared_ptr<void>, mcl::EGLNativeSurface*)); |
153 | MOCK_METHOD1(create_egl_native_window, std::shared_ptr<void>(mcl::EGLNativeSurface*)); |
154 | MOCK_METHOD0(create_egl_native_display, std::shared_ptr<EGLNativeDisplayType>()); |
155 | - MOCK_CONST_METHOD2(get_egl_pixel_format, |
156 | - MirPixelFormat(EGLDisplay, EGLConfig)); |
157 | + MOCK_CONST_METHOD2(get_egl_pixel_format, MirPixelFormat(EGLDisplay, EGLConfig)); |
158 | MOCK_METHOD2(request_interface, void*(char const*, int)); |
159 | |
160 | mcl::ClientContext* client_context = nullptr; |
161 | @@ -877,208 +850,3 @@ |
162 | |
163 | connection->release_buffer(&mock_buffer); |
164 | } |
165 | - |
166 | -TEST_F(MirConnectionTest, render_surface_can_be_created_and_released) |
167 | -{ |
168 | - EXPECT_CALL(*mock_channel, on_buffer_stream_create(_,_)) |
169 | - .WillOnce(Invoke([](mp::BufferStream& stream, google::protobuf::Closure*) |
170 | - { |
171 | - stream.mutable_id()->set_value(1); |
172 | - })); |
173 | - |
174 | - connection->connect("MirConnectionTest", connected_callback, 0)->wait_for_all(); |
175 | - |
176 | - void* nw = nullptr; |
177 | - MirRenderSurface* render_surface = nullptr; |
178 | - connection->create_render_surface_with_content( |
179 | - {10, 10}, |
180 | - reinterpret_cast<mir_render_surface_callback>(assign_result), |
181 | - &render_surface, |
182 | - &nw); |
183 | - EXPECT_THAT(render_surface, NotNull()); |
184 | - EXPECT_THAT(nw, NotNull()); |
185 | - EXPECT_THAT(render_surface, Eq(nw)); |
186 | - EXPECT_NO_THROW(connection->release_render_surface_with_content(nw)); |
187 | - |
188 | - connection->disconnect(); |
189 | -} |
190 | - |
191 | -TEST_F(MirConnectionTest, creation_of_render_surface_creates_egl_native_window) |
192 | -{ |
193 | - RenderSurfaceCallback callback; |
194 | - |
195 | - connection->connect("MirConnectionTest", connected_callback, 0)->wait_for_all(); |
196 | - |
197 | - EXPECT_CALL(*mock_platform, create_egl_native_window(nullptr)); |
198 | - EXPECT_CALL(*mock_channel, on_buffer_stream_create(_,_)) |
199 | - .WillOnce(Invoke([](mp::BufferStream& stream, google::protobuf::Closure*) |
200 | - { |
201 | - stream.mutable_id()->set_value(1); |
202 | - })); |
203 | - |
204 | - void* nw = nullptr; |
205 | - connection->create_render_surface_with_content( |
206 | - {10, 10}, |
207 | - &RenderSurfaceCallback::created, |
208 | - &callback, |
209 | - &nw); |
210 | - EXPECT_THAT(nw, NotNull()); |
211 | - EXPECT_TRUE(callback.invoked); |
212 | - EXPECT_THAT(callback.resulting_render_surface, NotNull()); |
213 | - auto rs = connection->connection_surface_map()->render_surface( |
214 | - static_cast<void*>(callback.resulting_render_surface)); |
215 | - EXPECT_TRUE(reinterpret_cast<mcl::RenderSurface*>(rs->valid())); |
216 | -} |
217 | - |
218 | -TEST_F(MirConnectionTest, render_surface_returns_connection) |
219 | -{ |
220 | - MirConnection* conn{ reinterpret_cast<MirConnection*>(0x12345678) }; |
221 | - |
222 | - mcl::RenderSurface rs( |
223 | - conn, nullptr, nullptr, nullptr, {}); |
224 | - EXPECT_THAT(rs.connection(), Eq(conn)); |
225 | -} |
226 | - |
227 | -TEST_F(MirConnectionTest, render_surface_has_correct_id_before_content_creation) |
228 | -{ |
229 | - MirConnection* conn{ reinterpret_cast<MirConnection*>(0x12345678) }; |
230 | - auto id = 123; |
231 | - |
232 | - mp::BufferStream protobuf_bs; |
233 | - mp::BufferStreamId bs_id; |
234 | - |
235 | - bs_id.set_value(id); |
236 | - *protobuf_bs.mutable_id() = bs_id; |
237 | - |
238 | - mcl::RenderSurface rs( |
239 | - conn, nullptr, nullptr, mt::fake_shared(protobuf_bs), {}); |
240 | - EXPECT_THAT(rs.stream_id().as_value(), Eq(id)); |
241 | -} |
242 | - |
243 | -TEST_F(MirConnectionTest, render_surface_can_create_buffer_stream) |
244 | -{ |
245 | - connection->connect("MirConnectionTest", connected_callback, 0)->wait_for_all(); |
246 | - auto id = 123; |
247 | - |
248 | - mp::BufferStream protobuf_bs; |
249 | - mp::BufferStreamId bs_id; |
250 | - |
251 | - bs_id.set_value(id); |
252 | - *protobuf_bs.mutable_id() = bs_id; |
253 | - |
254 | - auto native_window = mock_platform->create_egl_native_window(nullptr); |
255 | - |
256 | - mcl::RenderSurface rs( |
257 | - connection.get(), native_window, nullptr, mt::fake_shared(protobuf_bs), {}); |
258 | - |
259 | - auto bs = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
260 | - mir_buffer_usage_software); |
261 | - |
262 | - EXPECT_THAT(bs, NotNull()); |
263 | -} |
264 | - |
265 | -TEST_F(MirConnectionTest, render_surface_creation_of_buffer_stream_more_than_once_returns_same_object) |
266 | -{ |
267 | - connection->connect("MirConnectionTest", connected_callback, 0)->wait_for_all(); |
268 | - auto id = 123; |
269 | - |
270 | - mp::BufferStream protobuf_bs; |
271 | - mp::BufferStreamId bs_id; |
272 | - |
273 | - bs_id.set_value(id); |
274 | - *protobuf_bs.mutable_id() = bs_id; |
275 | - |
276 | - auto native_window = mock_platform->create_egl_native_window(nullptr); |
277 | - |
278 | - mcl::RenderSurface rs( |
279 | - connection.get(), native_window, mock_platform, mt::fake_shared(protobuf_bs), {}); |
280 | - |
281 | - EXPECT_CALL(*mock_platform, use_egl_native_window(native_window,_)); |
282 | - |
283 | - auto bs1 = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
284 | - mir_buffer_usage_hardware); |
285 | - |
286 | - auto bs2 = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
287 | - mir_buffer_usage_hardware); |
288 | - |
289 | - EXPECT_THAT(bs1, NotNull()); |
290 | - EXPECT_THAT(bs2, NotNull()); |
291 | - EXPECT_THAT(bs1, Eq(bs2)); |
292 | -} |
293 | - |
294 | -TEST_F(MirConnectionTest, render_surface_creation_of_buffer_stream_with_hardware_usage_installs_new_native_window) |
295 | -{ |
296 | - connection->connect("MirConnectionTest", connected_callback, 0)->wait_for_all(); |
297 | - auto id = 123; |
298 | - |
299 | - mp::BufferStream protobuf_bs; |
300 | - mp::BufferStreamId bs_id; |
301 | - |
302 | - bs_id.set_value(id); |
303 | - *protobuf_bs.mutable_id() = bs_id; |
304 | - |
305 | - auto native_window = mock_platform->create_egl_native_window(nullptr); |
306 | - |
307 | - mcl::RenderSurface rs( |
308 | - connection.get(), native_window, mock_platform, mt::fake_shared(protobuf_bs), {}); |
309 | - |
310 | - EXPECT_CALL(*mock_platform, use_egl_native_window(native_window,_)); |
311 | - |
312 | - auto bs = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
313 | - mir_buffer_usage_hardware); |
314 | - |
315 | - EXPECT_THAT(bs, NotNull()); |
316 | -} |
317 | - |
318 | -TEST_F(MirConnectionTest, render_surface_creation_of_buffer_stream_with_software_usage_does_not_install_new_native_window) |
319 | -{ |
320 | - connection->connect("MirConnectionTest", connected_callback, 0)->wait_for_all(); |
321 | - auto id = 123; |
322 | - |
323 | - mp::BufferStream protobuf_bs; |
324 | - mp::BufferStreamId bs_id; |
325 | - |
326 | - bs_id.set_value(id); |
327 | - *protobuf_bs.mutable_id() = bs_id; |
328 | - |
329 | - auto native_window = mock_platform->create_egl_native_window(nullptr); |
330 | - |
331 | - mcl::RenderSurface rs( |
332 | - connection.get(), native_window, mock_platform, mt::fake_shared(protobuf_bs), {}); |
333 | - |
334 | - EXPECT_CALL(*mock_platform, use_egl_native_window(_,_)).Times(0); |
335 | - |
336 | - auto bs = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
337 | - mir_buffer_usage_software); |
338 | - |
339 | - EXPECT_THAT(bs, NotNull()); |
340 | -} |
341 | - |
342 | -TEST_F(MirConnectionTest, render_surface_object_is_invalid_after_creation_exception) |
343 | -{ |
344 | - RenderSurfaceCallback callback; |
345 | - |
346 | - connection->connect("MirConnectionTest", connected_callback, 0)->wait_for_all(); |
347 | - |
348 | - EXPECT_CALL(*mock_channel, on_buffer_stream_create(_,_)) |
349 | - .WillOnce(DoAll( |
350 | - Invoke([](mp::BufferStream&, google::protobuf::Closure* c){ c->Run(); }), |
351 | - Throw(std::runtime_error("Eeek!")))); |
352 | - |
353 | - void* nw = nullptr; |
354 | - connection->create_render_surface_with_content( |
355 | - {10, 10}, |
356 | - &RenderSurfaceCallback::created, |
357 | - &callback, |
358 | - &nw); |
359 | - |
360 | - EXPECT_TRUE(callback.invoked); |
361 | - EXPECT_THAT(callback.resulting_render_surface, NotNull()); |
362 | - auto rs = connection->connection_surface_map()->render_surface( |
363 | - static_cast<void*>(callback.resulting_render_surface)); |
364 | - |
365 | - EXPECT_THAT(rs->get_error_message(), |
366 | - StrEq("Error processing buffer stream response during render " |
367 | - "surface creation: no ID in response (disconnected?)")); |
368 | - EXPECT_FALSE(reinterpret_cast<mcl::RenderSurface*>(rs->valid())); |
369 | -} |
370 | |
371 | === added file 'tests/unit-tests/client/test_mir_render_surface.cpp' |
372 | --- tests/unit-tests/client/test_mir_render_surface.cpp 1970-01-01 00:00:00 +0000 |
373 | +++ tests/unit-tests/client/test_mir_render_surface.cpp 2016-11-30 16:59:20 +0000 |
374 | @@ -0,0 +1,403 @@ |
375 | +/* |
376 | + * Copyright © 2016 Canonical Ltd. |
377 | + * |
378 | + * This program is free software: you can redistribute it and/or modify |
379 | + * it under the terms of the GNU General Public License version 3 as |
380 | + * published by the Free Software Foundation. |
381 | + * |
382 | + * This program is distributed in the hope that it will be useful, |
383 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
384 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
385 | + * GNU General Public License for more details. |
386 | + * |
387 | + * You should have received a copy of the GNU General Public License |
388 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
389 | + * |
390 | + * Authored by: Cemil Azizoglu <cemil.azizoglu@canonical.com> |
391 | + */ |
392 | + |
393 | +#include "src/client/mir_connection.h" |
394 | +#include "src/client/default_connection_configuration.h" |
395 | +#include "src/client/rpc/mir_basic_rpc_channel.h" |
396 | +#include "src/client/render_surface.h" |
397 | +#include "src/client/connection_surface_map.h" |
398 | + |
399 | +#include "mir/client_platform_factory.h" |
400 | +#include "mir/dispatch/dispatchable.h" |
401 | + |
402 | +#include "mir/test/fake_shared.h" |
403 | +#include "mir/test/doubles/stub_client_buffer_factory.h" |
404 | + |
405 | +#include <sys/eventfd.h> |
406 | + |
407 | +#include <gtest/gtest.h> |
408 | +#include <gmock/gmock.h> |
409 | + |
410 | +namespace mcl = mir::client; |
411 | +namespace mclr = mcl::rpc; |
412 | +namespace mp = mir::protobuf; |
413 | +namespace md = mir::dispatch; |
414 | +namespace mt = mir::test; |
415 | +namespace mtd = mt::doubles; |
416 | + |
417 | +using namespace testing; |
418 | + |
419 | +namespace |
420 | +{ |
421 | +void assign_result(void* result, void** context) |
422 | +{ |
423 | + if (context) |
424 | + *context = result; |
425 | +} |
426 | + |
427 | +struct RenderSurfaceCallback |
428 | +{ |
429 | + static void created(MirRenderSurface* render_surface, void *client_context) |
430 | + { |
431 | + auto const context = reinterpret_cast<RenderSurfaceCallback*>(client_context); |
432 | + context->invoked = true; |
433 | + context->resulting_render_surface = render_surface; |
434 | + } |
435 | + bool invoked = false; |
436 | + MirRenderSurface* resulting_render_surface = nullptr; |
437 | +}; |
438 | + |
439 | +struct MockRpcChannel : public mir::client::rpc::MirBasicRpcChannel, |
440 | + public mir::dispatch::Dispatchable |
441 | +{ |
442 | + MockRpcChannel() |
443 | + : pollable_fd{eventfd(0, EFD_CLOEXEC)} |
444 | + { |
445 | + ON_CALL(*this, watch_fd()).WillByDefault(testing::Return(pollable_fd)); |
446 | + } |
447 | + |
448 | + virtual void call_method(std::string const& name, |
449 | + google::protobuf::MessageLite const* /*parameters*/, |
450 | + google::protobuf::MessageLite* response, |
451 | + google::protobuf::Closure* complete) |
452 | + { |
453 | + if (name == "create_buffer_stream") |
454 | + { |
455 | + auto response_message = static_cast<mp::BufferStream*>(response); |
456 | + on_buffer_stream_create(*response_message, complete); |
457 | + } |
458 | + |
459 | + complete->Run(); |
460 | + } |
461 | + |
462 | + MOCK_METHOD2(on_buffer_stream_create, void(mp::BufferStream&, google::protobuf::Closure* complete)); |
463 | + |
464 | + MOCK_CONST_METHOD0(watch_fd, mir::Fd()); |
465 | + MOCK_METHOD1(dispatch, bool(md::FdEvents)); |
466 | + MOCK_CONST_METHOD0(relevant_events, md::FdEvents()); |
467 | +private: |
468 | + mir::Fd pollable_fd; |
469 | +}; |
470 | + |
471 | +struct MockClientPlatform : public mcl::ClientPlatform |
472 | +{ |
473 | + MockClientPlatform() |
474 | + { |
475 | + auto native_window = std::make_shared<EGLNativeWindowType>(); |
476 | + *native_window = reinterpret_cast<EGLNativeWindowType>(0x12345678); |
477 | + |
478 | + ON_CALL(*this, create_buffer_factory()) |
479 | + .WillByDefault(Return(std::make_shared<mtd::StubClientBufferFactory>())); |
480 | + ON_CALL(*this, create_egl_native_window(_)) |
481 | + .WillByDefault(Return(native_window)); |
482 | + } |
483 | + |
484 | + void set_client_context(mcl::ClientContext* ctx) |
485 | + { |
486 | + client_context = ctx; |
487 | + } |
488 | + |
489 | + void populate(MirPlatformPackage& pkg) const override |
490 | + { |
491 | + client_context->populate_server_package(pkg); |
492 | + } |
493 | + |
494 | + MOCK_CONST_METHOD1(convert_native_buffer, MirNativeBuffer*(mir::graphics::NativeBuffer*)); |
495 | + MOCK_CONST_METHOD0(platform_type, MirPlatformType()); |
496 | + MOCK_METHOD1(platform_operation, MirPlatformMessage*(MirPlatformMessage const*)); |
497 | + MOCK_METHOD0(create_buffer_factory, std::shared_ptr<mcl::ClientBufferFactory>()); |
498 | + MOCK_METHOD2(use_egl_native_window, void(std::shared_ptr<void>, mcl::EGLNativeSurface*)); |
499 | + MOCK_METHOD1(create_egl_native_window, std::shared_ptr<void>(mcl::EGLNativeSurface*)); |
500 | + MOCK_METHOD0(create_egl_native_display, std::shared_ptr<EGLNativeDisplayType>()); |
501 | + MOCK_CONST_METHOD2(get_egl_pixel_format, MirPixelFormat(EGLDisplay, EGLConfig)); |
502 | + MOCK_METHOD2(request_interface, void*(char const*, int)); |
503 | + |
504 | + mcl::ClientContext* client_context = nullptr; |
505 | +}; |
506 | + |
507 | +struct StubClientPlatformFactory : public mcl::ClientPlatformFactory |
508 | +{ |
509 | + StubClientPlatformFactory(std::shared_ptr<mcl::ClientPlatform> const& platform) |
510 | + : platform{platform} |
511 | + { |
512 | + } |
513 | + |
514 | + std::shared_ptr<mcl::ClientPlatform> create_client_platform(mcl::ClientContext*) |
515 | + { |
516 | + return platform; |
517 | + } |
518 | + |
519 | + std::shared_ptr<mcl::ClientPlatform> platform; |
520 | +}; |
521 | + |
522 | +void connected_callback(MirConnection* /*connection*/, void* /*client_context*/) |
523 | +{ |
524 | +} |
525 | + |
526 | +class TestConnectionConfiguration : public mcl::DefaultConnectionConfiguration |
527 | +{ |
528 | +public: |
529 | + TestConnectionConfiguration( |
530 | + std::shared_ptr<mcl::ClientPlatform> const& platform, |
531 | + std::shared_ptr<mclr::MirBasicRpcChannel> const& channel) |
532 | + : DefaultConnectionConfiguration(""), |
533 | + platform{platform}, |
534 | + channel{channel} |
535 | + { |
536 | + } |
537 | + |
538 | + std::shared_ptr<mclr::MirBasicRpcChannel> the_rpc_channel() override |
539 | + { |
540 | + return channel; |
541 | + } |
542 | + |
543 | + std::shared_ptr<mcl::ClientPlatformFactory> the_client_platform_factory() override |
544 | + { |
545 | + return std::make_shared<StubClientPlatformFactory>(platform); |
546 | + } |
547 | + |
548 | +private: |
549 | + std::shared_ptr<mcl::ClientPlatform> const platform; |
550 | + std::shared_ptr<mclr::MirBasicRpcChannel> const channel; |
551 | +}; |
552 | +} |
553 | + |
554 | +struct MirRenderSurfaceTest : public testing::Test |
555 | +{ |
556 | + MirRenderSurfaceTest() |
557 | + : mock_platform{std::make_shared<testing::NiceMock<MockClientPlatform>>()}, |
558 | + mock_channel{std::make_shared<testing::NiceMock<MockRpcChannel>>()}, |
559 | + conf{mock_platform, mock_channel}, |
560 | + connection{std::make_shared<MirConnection>(conf)} |
561 | + { |
562 | + mock_platform->set_client_context(connection.get()); |
563 | + } |
564 | + |
565 | + std::shared_ptr<testing::NiceMock<MockClientPlatform>> const mock_platform; |
566 | + std::shared_ptr<testing::NiceMock<MockRpcChannel>> const mock_channel; |
567 | + TestConnectionConfiguration conf; |
568 | + std::shared_ptr<MirConnection> const connection; |
569 | +}; |
570 | + |
571 | +TEST_F(MirRenderSurfaceTest, render_surface_can_be_created_and_released) |
572 | +{ |
573 | + EXPECT_CALL(*mock_channel, on_buffer_stream_create(_,_)) |
574 | + .WillOnce(Invoke([](mp::BufferStream& stream, google::protobuf::Closure*) |
575 | + { |
576 | + stream.mutable_id()->set_value(1); |
577 | + })); |
578 | + |
579 | + connection->connect("MirRenderSurfaceTest", connected_callback, 0)->wait_for_all(); |
580 | + |
581 | + void* nw = nullptr; |
582 | + MirRenderSurface* render_surface = nullptr; |
583 | + connection->create_render_surface_with_content( |
584 | + {10, 10}, |
585 | + reinterpret_cast<mir_render_surface_callback>(assign_result), |
586 | + &render_surface, |
587 | + &nw); |
588 | + |
589 | + EXPECT_THAT(render_surface, NotNull()); |
590 | + EXPECT_THAT(nw, NotNull()); |
591 | + EXPECT_THAT(render_surface, Eq(nw)); |
592 | + EXPECT_NO_THROW(connection->release_render_surface_with_content(nw)); |
593 | + |
594 | + connection->disconnect(); |
595 | +} |
596 | + |
597 | +TEST_F(MirRenderSurfaceTest, creation_of_render_surface_creates_egl_native_window) |
598 | +{ |
599 | + RenderSurfaceCallback callback; |
600 | + |
601 | + connection->connect("MirRenderSurfaceTest", connected_callback, 0)->wait_for_all(); |
602 | + |
603 | + EXPECT_CALL(*mock_platform, create_egl_native_window(nullptr)); |
604 | + EXPECT_CALL(*mock_channel, on_buffer_stream_create(_,_)) |
605 | + .WillOnce(Invoke([](mp::BufferStream& stream, google::protobuf::Closure*) |
606 | + { |
607 | + stream.mutable_id()->set_value(1); |
608 | + })); |
609 | + |
610 | + void* nw = nullptr; |
611 | + connection->create_render_surface_with_content({10, 10}, |
612 | + &RenderSurfaceCallback::created, |
613 | + &callback, |
614 | + &nw); |
615 | + |
616 | + EXPECT_THAT(nw, NotNull()); |
617 | + EXPECT_TRUE(callback.invoked); |
618 | + EXPECT_THAT(callback.resulting_render_surface, NotNull()); |
619 | + |
620 | + auto rs = connection->connection_surface_map()->render_surface( |
621 | + static_cast<void*>(callback.resulting_render_surface)); |
622 | + |
623 | + EXPECT_TRUE(reinterpret_cast<mcl::RenderSurface*>(rs->valid())); |
624 | +} |
625 | + |
626 | +TEST_F(MirRenderSurfaceTest, render_surface_returns_connection) |
627 | +{ |
628 | + MirConnection* conn{ reinterpret_cast<MirConnection*>(0x12345678) }; |
629 | + |
630 | + mcl::RenderSurface rs( |
631 | + conn, nullptr, nullptr, nullptr, {}); |
632 | + |
633 | + EXPECT_THAT(rs.connection(), Eq(conn)); |
634 | +} |
635 | + |
636 | +TEST_F(MirRenderSurfaceTest, render_surface_has_correct_id_before_content_creation) |
637 | +{ |
638 | + MirConnection* conn{ reinterpret_cast<MirConnection*>(0x12345678) }; |
639 | + auto id = 123; |
640 | + |
641 | + mp::BufferStream protobuf_bs; |
642 | + mp::BufferStreamId bs_id; |
643 | + |
644 | + bs_id.set_value(id); |
645 | + *protobuf_bs.mutable_id() = bs_id; |
646 | + |
647 | + mcl::RenderSurface rs( |
648 | + conn, nullptr, nullptr, mt::fake_shared(protobuf_bs), {}); |
649 | + |
650 | + EXPECT_THAT(rs.stream_id().as_value(), Eq(id)); |
651 | +} |
652 | + |
653 | +TEST_F(MirRenderSurfaceTest, render_surface_can_create_buffer_stream) |
654 | +{ |
655 | + connection->connect("MirRenderSurfaceTest", connected_callback, 0)->wait_for_all(); |
656 | + auto id = 123; |
657 | + |
658 | + mp::BufferStream protobuf_bs; |
659 | + mp::BufferStreamId bs_id; |
660 | + |
661 | + bs_id.set_value(id); |
662 | + *protobuf_bs.mutable_id() = bs_id; |
663 | + |
664 | + auto native_window = mock_platform->create_egl_native_window(nullptr); |
665 | + |
666 | + mcl::RenderSurface rs( |
667 | + connection.get(), native_window, nullptr, mt::fake_shared(protobuf_bs), {}); |
668 | + |
669 | + auto bs = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
670 | + mir_buffer_usage_software); |
671 | + |
672 | + EXPECT_THAT(bs, NotNull()); |
673 | +} |
674 | + |
675 | +TEST_F(MirRenderSurfaceTest, render_surface_creation_of_buffer_stream_more_than_once_returns_same_object) |
676 | +{ |
677 | + connection->connect("MirRenderSurfaceTest", connected_callback, 0)->wait_for_all(); |
678 | + auto id = 123; |
679 | + |
680 | + mp::BufferStream protobuf_bs; |
681 | + mp::BufferStreamId bs_id; |
682 | + |
683 | + bs_id.set_value(id); |
684 | + *protobuf_bs.mutable_id() = bs_id; |
685 | + |
686 | + auto native_window = mock_platform->create_egl_native_window(nullptr); |
687 | + |
688 | + mcl::RenderSurface rs( |
689 | + connection.get(), native_window, mock_platform, mt::fake_shared(protobuf_bs), {}); |
690 | + |
691 | + EXPECT_CALL(*mock_platform, use_egl_native_window(native_window,_)); |
692 | + |
693 | + auto bs1 = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
694 | + mir_buffer_usage_hardware); |
695 | + |
696 | + auto bs2 = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
697 | + mir_buffer_usage_hardware); |
698 | + |
699 | + EXPECT_THAT(bs1, NotNull()); |
700 | + EXPECT_THAT(bs2, NotNull()); |
701 | + EXPECT_THAT(bs1, Eq(bs2)); |
702 | +} |
703 | + |
704 | +TEST_F(MirRenderSurfaceTest, render_surface_creation_of_buffer_stream_with_hardware_usage_installs_new_native_window) |
705 | +{ |
706 | + connection->connect("MirRenderSurfaceTest", connected_callback, 0)->wait_for_all(); |
707 | + auto id = 123; |
708 | + |
709 | + mp::BufferStream protobuf_bs; |
710 | + mp::BufferStreamId bs_id; |
711 | + |
712 | + bs_id.set_value(id); |
713 | + *protobuf_bs.mutable_id() = bs_id; |
714 | + |
715 | + auto native_window = mock_platform->create_egl_native_window(nullptr); |
716 | + |
717 | + mcl::RenderSurface rs( |
718 | + connection.get(), native_window, mock_platform, mt::fake_shared(protobuf_bs), {}); |
719 | + |
720 | + EXPECT_CALL(*mock_platform, use_egl_native_window(native_window,_)); |
721 | + |
722 | + auto bs = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
723 | + mir_buffer_usage_hardware); |
724 | + |
725 | + EXPECT_THAT(bs, NotNull()); |
726 | +} |
727 | + |
728 | +TEST_F(MirRenderSurfaceTest, render_surface_creation_of_buffer_stream_with_software_usage_does_not_install_new_native_window) |
729 | +{ |
730 | + connection->connect("MirRenderSurfaceTest", connected_callback, 0)->wait_for_all(); |
731 | + auto id = 123; |
732 | + |
733 | + mp::BufferStream protobuf_bs; |
734 | + mp::BufferStreamId bs_id; |
735 | + |
736 | + bs_id.set_value(id); |
737 | + *protobuf_bs.mutable_id() = bs_id; |
738 | + |
739 | + auto native_window = mock_platform->create_egl_native_window(nullptr); |
740 | + |
741 | + mcl::RenderSurface rs( |
742 | + connection.get(), native_window, mock_platform, mt::fake_shared(protobuf_bs), {}); |
743 | + |
744 | + EXPECT_CALL(*mock_platform, use_egl_native_window(_,_)).Times(0); |
745 | + |
746 | + auto bs = rs.get_buffer_stream(2, 2, mir_pixel_format_abgr_8888, |
747 | + mir_buffer_usage_software); |
748 | + |
749 | + EXPECT_THAT(bs, NotNull()); |
750 | +} |
751 | + |
752 | +TEST_F(MirRenderSurfaceTest, render_surface_object_is_invalid_after_creation_exception) |
753 | +{ |
754 | + RenderSurfaceCallback callback; |
755 | + |
756 | + connection->connect("MirRenderSurfaceTest", connected_callback, 0)->wait_for_all(); |
757 | + |
758 | + EXPECT_CALL(*mock_channel, on_buffer_stream_create(_,_)) |
759 | + .WillOnce(DoAll( |
760 | + Invoke([](mp::BufferStream&, google::protobuf::Closure* c){ c->Run(); }), |
761 | + Throw(std::runtime_error("Eeek!")))); |
762 | + |
763 | + void* nw = nullptr; |
764 | + connection->create_render_surface_with_content({10, 10}, |
765 | + &RenderSurfaceCallback::created, |
766 | + &callback, |
767 | + &nw); |
768 | + |
769 | + EXPECT_TRUE(callback.invoked); |
770 | + EXPECT_THAT(callback.resulting_render_surface, NotNull()); |
771 | + auto rs = connection->connection_surface_map()->render_surface( |
772 | + static_cast<void*>(callback.resulting_render_surface)); |
773 | + EXPECT_THAT(rs->get_error_message(), |
774 | + StrEq("Error processing buffer stream response during render " |
775 | + "surface creation: no ID in response (disconnected?)")); |
776 | + EXPECT_FALSE(reinterpret_cast<mcl::RenderSurface*>(rs->valid())); |
777 | +} |
FAILED: Continuous integration, rev:3854 /mir-jenkins. ubuntu. com/job/ mir-ci/ 2282/ /mir-jenkins. ubuntu. com/job/ build-mir/ 2963/console /mir-jenkins. ubuntu. com/job/ build-0- fetch/3028 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= vivid+overlay/ 3020 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= xenial+ overlay/ 3020 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= yakkety/ 3020 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= yakkety/ 2992 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= yakkety/ 2992/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2992 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2992/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= yakkety/ 2992 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= yakkety/ 2992/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= android, release= vivid+overlay/ 2992/console /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= android, release= vivid+overlay/ 2992/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= android, release= vivid+overlay/ 2992 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= android, release= vivid+overlay/ 2992/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2992 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2992/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /mir-jenkins. ubuntu. com/job/ mir-ci/ 2282/rebuild
https:/