Mir

Merge lp:~afrantzis/mir/fix-1347053 into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: no longer in the source branch.
Merged at revision: 1818
Proposed branch: lp:~afrantzis/mir/fix-1347053
Merge into: lp:mir
Diff against target: 650 lines (+232/-97)
4 files modified
src/client/mesa/native_surface.cpp (+27/-0)
src/shared/graphics/android/mir_native_window.cpp (+46/-3)
tests/unit-tests/client/android/test_android_native_window.cpp (+116/-78)
tests/unit-tests/client/mesa/test_native_surface.cpp (+43/-16)
To merge this branch: bzr merge lp:~afrantzis/mir/fix-1347053
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Kevin DuBois (community) Approve
Robert Carr (community) Approve
Daniel van Vugt Needs Fixing
Review via email: mp+229221@code.launchpad.net

Commit message

mesa,android: Don't propagate exceptions to graphics driver code

Description of the change

mesa,android: Don't propagate exceptions to graphics driver code

Report the error in a way the driver expects, in our specific cases by returning an error code.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

Sometimes these errors are useful to see when we get logs back... for the sake of debuggability, could we dump the message to stderr?

(this also reminds me that a native window logger would be pretty useful for android anyways...)

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

If possible, please replace:
   catch (...)
with:
   catch (std::exception)
so that we may in future define fatal error exception base classes that don't get accidentally caught by blanket catches like this.

review: Needs Fixing
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> could we dump the message to stderr?

Done. Just printing to stderr for now, I didn't introduce any special reporting or logging mechanism.

> catch (std::exception)

Done.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Carr (robertcarr) wrote :

Ok!

review: Approve
Revision history for this message
Kevin DuBois (kdub) wrote :

okay, lgtm, thanks

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Minor issue: The same string and expression is duplicated multiple times in a couple of source files. It could easily be un-duplicated on a per-file basis at least:

    std::cerr << "Caught exception at Mir/EGL driver boundary: "
              << boost::diagnostic_information(e) << std::endl;

Although I appreciate the benefit of seeing what's being emitted in-situ. You would lose that with a global or a function...

Think about it and optionally implement it. Then Approved for me.

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> It could easily be un-duplicated on a per-file basis at least:

Done.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/client/mesa/native_surface.cpp'
2--- src/client/mesa/native_surface.cpp 2014-03-06 06:05:17 +0000
3+++ src/client/mesa/native_surface.cpp 2014-08-05 07:09:25 +0000
4@@ -20,6 +20,9 @@
5 #include "../client_buffer.h"
6 #include "native_surface.h"
7
8+#include <iostream>
9+#include <boost/exception/diagnostic_information.hpp>
10+
11 namespace mclm=mir::client::mesa;
12
13 namespace
14@@ -43,6 +46,12 @@
15 auto s = static_cast<mclm::NativeSurface*>(surface);
16 return s->set_swapinterval(interval);
17 }
18+
19+void report_exception_at_driver_boundary(std::exception const& e)
20+{
21+ std::cerr << "Caught exception at Mir/EGL driver boundary: "
22+ << boost::diagnostic_information(e) << std::endl;
23+}
24 }
25
26 mclm::NativeSurface::NativeSurface(ClientSurface& surface)
27@@ -54,6 +63,7 @@
28 }
29
30 int mclm::NativeSurface::advance_buffer(MirBufferPackage* buffer_package)
31+try
32 {
33 /*
34 * At present dri2_create_mir_window_surface will trigger
35@@ -72,15 +82,27 @@
36 memcpy(buffer_package, buffer_to_driver.get(), sizeof(MirBufferPackage));
37 return MIR_MESA_TRUE;
38 }
39+catch (std::exception const& e)
40+{
41+ report_exception_at_driver_boundary(e);
42+ return MIR_MESA_FALSE;
43+}
44
45 int mclm::NativeSurface::get_parameters(MirSurfaceParameters* surface_parameters)
46+try
47 {
48 auto params = surface.get_parameters();
49 memcpy(surface_parameters, &params, sizeof(MirSurfaceParameters));
50 return MIR_MESA_TRUE;
51 }
52+catch (std::exception const& e)
53+{
54+ report_exception_at_driver_boundary(e);
55+ return MIR_MESA_FALSE;
56+}
57
58 int mclm::NativeSurface::set_swapinterval(int interval)
59+try
60 {
61 if ((interval < 0) || (interval > 1))
62 return MIR_MESA_FALSE;
63@@ -88,3 +110,8 @@
64 surface.request_and_wait_for_configure(mir_surface_attrib_swapinterval, interval);
65 return MIR_MESA_TRUE;
66 }
67+catch (std::exception const& e)
68+{
69+ report_exception_at_driver_boundary(e);
70+ return MIR_MESA_FALSE;
71+}
72
73=== modified file 'src/shared/graphics/android/mir_native_window.cpp'
74--- src/shared/graphics/android/mir_native_window.cpp 2014-06-17 18:24:48 +0000
75+++ src/shared/graphics/android/mir_native_window.cpp 2014-08-05 07:09:25 +0000
76@@ -20,13 +20,15 @@
77 #include "mir/graphics/android/android_driver_interpreter.h"
78 #include "mir/graphics/android/sync_fence.h"
79
80+#include <iostream>
81+#include <boost/exception/diagnostic_information.hpp>
82+
83 namespace mg=mir::graphics;
84 namespace mga=mir::graphics::android;
85
86 namespace
87 {
88
89-
90 static int query_static(const ANativeWindow* anw, int key, int* value);
91 static int perform_static(ANativeWindow* anw, int key, ...);
92 static int setSwapInterval_static (struct ANativeWindow* window, int interval);
93@@ -121,6 +123,12 @@
94 return self->cancelBuffer(buffer, fence_fd);
95 }
96
97+void report_exception_at_driver_boundary(std::exception const& e)
98+{
99+ std::cerr << "Caught exception at Mir/EGL driver boundary: "
100+ << boost::diagnostic_information(e) << std::endl;
101+}
102+
103 }
104
105 mga::MirNativeWindow::MirNativeWindow(std::shared_ptr<AndroidDriverInterpreter> const& interpreter)
106@@ -158,42 +166,73 @@
107 }
108
109 int mga::MirNativeWindow::dequeueBuffer(struct ANativeWindowBuffer** buffer_to_driver, int* fence_fd)
110+try
111 {
112 auto buffer = driver_interpreter->driver_requests_buffer();
113
114- //driver is responsible for closing this native handle
115+ //EGL driver is responsible for closing this native handle
116 *fence_fd = buffer->copy_fence();
117 *buffer_to_driver = buffer->anwb();
118 return 0;
119 }
120+catch (std::exception const& e)
121+{
122+ report_exception_at_driver_boundary(e);
123+ return -1;
124+}
125
126 int mga::MirNativeWindow::dequeueBufferAndWait(struct ANativeWindowBuffer** buffer_to_driver)
127+try
128 {
129 auto buffer = driver_interpreter->driver_requests_buffer();
130 *buffer_to_driver = buffer->anwb();
131 buffer->ensure_available_for(mga::BufferAccess::write);
132 return 0;
133 }
134+catch (std::exception const& e)
135+{
136+ report_exception_at_driver_boundary(e);
137+ return -1;
138+}
139
140 int mga::MirNativeWindow::queueBuffer(struct ANativeWindowBuffer* buffer, int fence)
141+try
142 {
143 driver_interpreter->driver_returns_buffer(buffer, fence);
144 return 0;
145 }
146+catch (std::exception const& e)
147+{
148+ report_exception_at_driver_boundary(e);
149+ return -1;
150+}
151
152 int mga::MirNativeWindow::cancelBuffer(struct ANativeWindowBuffer* buffer, int fence)
153+try
154 {
155 driver_interpreter->driver_returns_buffer(buffer, fence);
156 return 0;
157 }
158+catch (std::exception const& e)
159+{
160+ report_exception_at_driver_boundary(e);
161+ return -1;
162+}
163
164 int mga::MirNativeWindow::query(int key, int* value) const
165+try
166 {
167 *value = driver_interpreter->driver_requests_info(key);
168 return 0;
169 }
170+catch (std::exception const& e)
171+{
172+ report_exception_at_driver_boundary(e);
173+ return -1;
174+}
175
176 int mga::MirNativeWindow::perform(int key, va_list arg_list )
177+try
178 {
179 int ret = 0;
180 va_list args;
181@@ -213,4 +252,8 @@
182 va_end(args);
183 return ret;
184 }
185-
186+catch (std::exception const& e)
187+{
188+ report_exception_at_driver_boundary(e);
189+ return -1;
190+}
191
192=== modified file 'tests/unit-tests/client/android/test_android_native_window.cpp'
193--- tests/unit-tests/client/android/test_android_native_window.cpp 2014-07-11 13:20:14 +0000
194+++ tests/unit-tests/client/android/test_android_native_window.cpp 2014-08-05 07:09:25 +0000
195@@ -49,41 +49,37 @@
196
197 std::shared_ptr<mir::graphics::NativeBuffer> buffer;
198 };
199-}
200
201 class AndroidNativeWindowTest : public ::testing::Test
202 {
203 protected:
204- virtual void SetUp()
205- {
206- using namespace testing;
207-
208- mock_driver_interpreter = std::make_shared<NiceMock<MockAndroidDriverInterpreter>>();
209- }
210-
211- std::shared_ptr<MockAndroidDriverInterpreter> mock_driver_interpreter;
212+ std::shared_ptr<MockAndroidDriverInterpreter> const mock_driver_interpreter =
213+ std::make_shared<testing::NiceMock<MockAndroidDriverInterpreter>>();
214+ mga::MirNativeWindow mir_native_window{mock_driver_interpreter};
215+ ANativeWindow& window = mir_native_window;
216+ int const failure_code{-1};
217 };
218
219+}
220+
221 TEST_F(AndroidNativeWindowTest, native_window_swapinterval)
222 {
223 using namespace testing;
224
225- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
226-
227- ASSERT_NE(nullptr, window->setSwapInterval);
228- EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
229- .Times(1);
230- window->setSwapInterval(window.get(), 1);
231- Mock::VerifyAndClearExpectations(window.get());
232-
233- EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
234- .Times(1);
235- window->setSwapInterval(window.get(), 2);
236- Mock::VerifyAndClearExpectations(window.get());
237+ ASSERT_NE(nullptr, window.setSwapInterval);
238+ EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
239+ .Times(1);
240+ window.setSwapInterval(&window, 1);
241+ Mock::VerifyAndClearExpectations(mock_driver_interpreter.get());
242+
243+ EXPECT_CALL(*mock_driver_interpreter, sync_to_display(true))
244+ .Times(1);
245+ window.setSwapInterval(&window, 2);
246+ Mock::VerifyAndClearExpectations(mock_driver_interpreter.get());
247
248 EXPECT_CALL(*mock_driver_interpreter, sync_to_display(false))
249 .Times(1);
250- window->setSwapInterval(window.get(), 0);
251+ window.setSwapInterval(&window, 0);
252 }
253
254 /* Query hook tests */
255@@ -91,15 +87,15 @@
256 {
257 using namespace testing;
258
259- int returned_width, width = 271828;
260- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
261+ int returned_width;
262+ int const width = 271828;
263
264- ASSERT_NE(nullptr, window->query);
265+ ASSERT_NE(nullptr, window.query);
266 EXPECT_CALL(*mock_driver_interpreter, driver_requests_info(NATIVE_WINDOW_WIDTH))
267 .Times(1)
268 .WillOnce(Return(width));
269
270- window->query(window.get(), NATIVE_WINDOW_WIDTH ,&returned_width);
271+ window.query(&window, NATIVE_WINDOW_WIDTH ,&returned_width);
272
273 EXPECT_EQ(width, returned_width);
274 }
275@@ -107,24 +103,22 @@
276 /* perform hook tests */
277 TEST_F(AndroidNativeWindowTest, native_window_perform_hook_callable)
278 {
279- int format = 4;
280- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
281+ int const format = 4;
282
283 EXPECT_CALL(*mock_driver_interpreter, dispatch_driver_request_format(format))
284 .Times(1);
285
286- ASSERT_NE(nullptr, window->perform);
287- window->perform(window.get(), NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
288+ ASSERT_NE(nullptr, window.perform);
289+ window.perform(&window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
290 }
291
292 /* setSwapInterval hook tests */
293 TEST_F(AndroidNativeWindowTest, native_window_setswapinterval_hook_callable)
294 {
295- int swap = 2;
296- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
297+ int const swap = 2;
298
299- ASSERT_NE(nullptr, window->setSwapInterval);
300- window->setSwapInterval(window.get(), swap);
301+ ASSERT_NE(nullptr, window.setSwapInterval);
302+ window.setSwapInterval(&window, swap);
303 }
304
305 /* dequeue hook tests */
306@@ -132,10 +126,9 @@
307 {
308 ANativeWindowBuffer* returned_buffer;
309 int fence_fd;
310- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
311
312- ASSERT_NE(nullptr, window->dequeueBuffer);
313- window->dequeueBuffer(window.get(), &returned_buffer, &fence_fd);
314+ ASSERT_NE(nullptr, window.dequeueBuffer);
315+ window.dequeueBuffer(&window, &returned_buffer, &fence_fd);
316 }
317
318 TEST_F(AndroidNativeWindowTest, native_window_dequeue_returns_right_buffer)
319@@ -151,11 +144,9 @@
320 .Times(1)
321 .WillOnce(Return(mock_buffer.get()));
322
323- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
324-
325 int fence_fd;
326 ANativeWindowBuffer* returned_buffer;
327- window->dequeueBuffer(window.get(), &returned_buffer, &fence_fd);
328+ window.dequeueBuffer(&window, &returned_buffer, &fence_fd);
329
330 EXPECT_EQ(mock_buffer->anwb(), returned_buffer);
331 EXPECT_EQ(fake_fd, fence_fd);
332@@ -164,10 +155,9 @@
333 TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_hook_callable)
334 {
335 ANativeWindowBuffer* tmp;
336- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
337
338- ASSERT_NE(nullptr, window->dequeueBuffer_DEPRECATED);
339- window->dequeueBuffer_DEPRECATED(window.get(), &tmp);
340+ ASSERT_NE(nullptr, window.dequeueBuffer_DEPRECATED);
341+ window.dequeueBuffer_DEPRECATED(&window, &tmp);
342 }
343
344 TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_returns_right_buffer)
345@@ -176,7 +166,6 @@
346
347 ANativeWindowBuffer* returned_buffer;
348 auto mock_buffer = std::make_shared<NiceMock<mtd::MockAndroidNativeBuffer>>();
349- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
350
351 EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer())
352 .Times(1)
353@@ -186,7 +175,7 @@
354 EXPECT_CALL(*mock_buffer, copy_fence())
355 .Times(0);
356
357- window->dequeueBuffer_DEPRECATED(window.get(), &returned_buffer);
358+ window.dequeueBuffer_DEPRECATED(&window, &returned_buffer);
359 EXPECT_EQ(mock_buffer->anwb(), returned_buffer);
360 }
361
362@@ -194,10 +183,9 @@
363 TEST_F(AndroidNativeWindowTest, native_window_queue_hook_callable)
364 {
365 ANativeWindowBuffer* tmp = nullptr;
366- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
367
368- ASSERT_NE(nullptr, window->queueBuffer);
369- window->queueBuffer(window.get(), tmp, -1);
370+ ASSERT_NE(nullptr, window.queueBuffer);
371+ window.queueBuffer(&window, tmp, -1);
372 }
373
374 TEST_F(AndroidNativeWindowTest, native_window_queue_passes_buffer_back)
375@@ -205,79 +193,69 @@
376 using namespace testing;
377 ANativeWindowBuffer buffer;
378 int fence_fd = 33;
379- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
380
381 EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, fence_fd))
382 .Times(1);
383
384- window->queueBuffer(window.get(), &buffer, fence_fd);
385+ window.queueBuffer(&window, &buffer, fence_fd);
386 }
387
388 TEST_F(AndroidNativeWindowTest, native_window_queue_deprecated_hook_callable)
389 {
390 ANativeWindowBuffer* tmp = nullptr;
391- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
392
393- ASSERT_NE(nullptr, window->queueBuffer_DEPRECATED);
394- window->queueBuffer_DEPRECATED(window.get(), tmp);
395+ ASSERT_NE(nullptr, window.queueBuffer_DEPRECATED);
396+ window.queueBuffer_DEPRECATED(&window, tmp);
397 }
398
399 TEST_F(AndroidNativeWindowTest, native_window_queue_deprecated_passes_buffer_back)
400 {
401 using namespace testing;
402 ANativeWindowBuffer buffer;
403- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
404
405 EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer,_))
406 .Times(1);
407
408- window->queueBuffer_DEPRECATED(window.get(), &buffer);
409+ window.queueBuffer_DEPRECATED(&window, &buffer);
410 }
411
412 /* cancel hook tests */
413 TEST_F(AndroidNativeWindowTest, native_window_cancel_hooks_callable)
414 {
415 ANativeWindowBuffer* tmp = nullptr;
416- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
417
418- ASSERT_NE(nullptr, window->cancelBuffer_DEPRECATED);
419- ASSERT_NE(nullptr, window->cancelBuffer);
420- window->cancelBuffer_DEPRECATED(window.get(), tmp);
421- window->cancelBuffer(window.get(), tmp, -1);
422+ ASSERT_NE(nullptr, window.cancelBuffer_DEPRECATED);
423+ ASSERT_NE(nullptr, window.cancelBuffer);
424+ window.cancelBuffer_DEPRECATED(&window, tmp);
425+ window.cancelBuffer(&window, tmp, -1);
426 }
427
428 /* lock hook tests */
429 TEST_F(AndroidNativeWindowTest, native_window_lock_hook_callable)
430 {
431 ANativeWindowBuffer* tmp = 0x0;
432- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
433
434- ASSERT_NE(nullptr, window->lockBuffer_DEPRECATED);
435- window->lockBuffer_DEPRECATED(window.get(), tmp);
436+ ASSERT_NE(nullptr, window.lockBuffer_DEPRECATED);
437+ window.lockBuffer_DEPRECATED(&window, tmp);
438 }
439
440 TEST_F(AndroidNativeWindowTest, native_window_incref_hook_callable)
441 {
442- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
443-
444- ASSERT_NE(nullptr, window->common.incRef);
445- window->common.incRef(NULL);
446+ ASSERT_NE(nullptr, window.common.incRef);
447+ window.common.incRef(NULL);
448 }
449
450 TEST_F(AndroidNativeWindowTest, native_window_decref_hook_callable)
451 {
452- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
453-
454- ASSERT_NE(nullptr, window->common.decRef);
455- window->common.decRef(NULL);
456+ ASSERT_NE(nullptr, window.common.decRef);
457+ window.common.decRef(NULL);
458 }
459
460 TEST_F(AndroidNativeWindowTest, native_window_dequeue_deprecated_has_proper_rc)
461 {
462 ANativeWindowBuffer* tmp;
463- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
464
465- auto ret = window->dequeueBuffer_DEPRECATED(window.get(), &tmp);
466+ auto ret = window.dequeueBuffer_DEPRECATED(&window, &tmp);
467 EXPECT_EQ(0, ret);
468 }
469
470@@ -286,9 +264,7 @@
471 ANativeWindowBuffer* tmp;
472 int fencefd;
473
474- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
475-
476- auto ret = window->dequeueBuffer(window.get(), &tmp, &fencefd);
477+ auto ret = window.dequeueBuffer(&window, &tmp, &fencefd);
478 EXPECT_EQ(0, ret);
479 }
480
481@@ -301,7 +277,69 @@
482 EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(&buffer, _))
483 .Times(1);
484
485- std::shared_ptr<ANativeWindow> window = std::make_shared<mga::MirNativeWindow>(mock_driver_interpreter);
486- auto rc = window->cancelBuffer(window.get(), &buffer, fence_fd);
487+ auto rc = window.cancelBuffer(&window, &buffer, fence_fd);
488 EXPECT_EQ(0, rc);
489 }
490+
491+TEST_F(AndroidNativeWindowTest, returns_error_on_dequeue_buffer_failure)
492+{
493+ using namespace testing;
494+
495+ EXPECT_CALL(*mock_driver_interpreter, driver_requests_buffer())
496+ .WillOnce(Throw(std::runtime_error("")))
497+ .WillOnce(Throw(std::runtime_error("")));
498+
499+ EXPECT_THAT(window.dequeueBuffer(&window, nullptr, nullptr), Eq(failure_code));
500+ EXPECT_THAT(window.dequeueBuffer_DEPRECATED(&window, nullptr), Eq(failure_code));
501+}
502+
503+TEST_F(AndroidNativeWindowTest, returns_error_on_queue_buffer_failure)
504+{
505+ using namespace testing;
506+
507+ EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(_, _))
508+ .WillOnce(Throw(std::runtime_error("")))
509+ .WillOnce(Throw(std::runtime_error("")));
510+
511+ EXPECT_THAT(window.queueBuffer(&window, nullptr, 0), Eq(failure_code));
512+ EXPECT_THAT(window.queueBuffer_DEPRECATED(&window, nullptr), Eq(failure_code));
513+}
514+
515+TEST_F(AndroidNativeWindowTest, returns_error_on_cancel_buffer_failure)
516+{
517+ using namespace testing;
518+
519+ EXPECT_CALL(*mock_driver_interpreter, driver_returns_buffer(_, _))
520+ .WillOnce(Throw(std::runtime_error("")))
521+ .WillOnce(Throw(std::runtime_error("")));
522+
523+ EXPECT_THAT(window.cancelBuffer(&window, nullptr, 0), Eq(failure_code));
524+ EXPECT_THAT(window.cancelBuffer_DEPRECATED(&window, nullptr), Eq(failure_code));
525+}
526+
527+TEST_F(AndroidNativeWindowTest, returns_error_on_query_failure)
528+{
529+ using namespace testing;
530+
531+ EXPECT_CALL(*mock_driver_interpreter, driver_requests_info(_))
532+ .WillOnce(Throw(std::runtime_error("")));
533+
534+ EXPECT_THAT(window.query(&window, 0, nullptr), Eq(failure_code));
535+}
536+
537+TEST_F(AndroidNativeWindowTest, returns_error_on_perform_failure)
538+{
539+ using namespace testing;
540+
541+ EXPECT_CALL(*mock_driver_interpreter, dispatch_driver_request_format(_))
542+ .WillOnce(Throw(std::runtime_error("")));
543+
544+ auto perform = [this] (int key, ...)
545+ {
546+ va_list args;
547+ va_start(args, key);
548+ EXPECT_THAT(window.perform(&window, key, args), Eq(failure_code));
549+ va_end(args);
550+ };
551+ perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT, 0);
552+}
553
554=== modified file 'tests/unit-tests/client/mesa/test_native_surface.cpp'
555--- tests/unit-tests/client/mesa/test_native_surface.cpp 2014-07-11 03:33:03 +0000
556+++ tests/unit-tests/client/mesa/test_native_surface.cpp 2014-08-05 07:09:25 +0000
557@@ -74,14 +74,13 @@
558
559 MirSurfaceParameters surf_params;
560 testing::NiceMock<mtd::MockClientSurface> mock_surface;
561+ mclg::NativeSurface native_surface{mock_surface};
562 };
563
564 TEST_F(MesaClientNativeSurfaceTest, basic_parameters)
565 {
566- mclg::NativeSurface interpreter(mock_surface);
567-
568 MirSurfaceParameters params;
569- interpreter.surface_get_parameters(&interpreter, &params);
570+ native_surface.surface_get_parameters(&native_surface, &params);
571 EXPECT_EQ(surf_params.width, params.width);
572 EXPECT_EQ(surf_params.height, params.height);
573 EXPECT_EQ(surf_params.pixel_format, params.pixel_format);
574@@ -98,8 +97,7 @@
575 EXPECT_CALL(mock_surface, get_current_buffer())
576 .Times(1);
577
578- mclg::NativeSurface interpreter(mock_surface);
579- interpreter.surface_advance_buffer(&interpreter, &buffer_package);
580+ native_surface.surface_advance_buffer(&native_surface, &buffer_package);
581 }
582
583 TEST_F(MesaClientNativeSurfaceTest, basic_advance)
584@@ -115,9 +113,8 @@
585 EXPECT_CALL(mock_surface, get_current_buffer())
586 .Times(1);
587
588- mclg::NativeSurface interpreter(mock_surface);
589- interpreter.surface_advance_buffer(&interpreter, &buffer_package);
590- interpreter.surface_advance_buffer(&interpreter, &buffer_package);
591+ native_surface.surface_advance_buffer(&native_surface, &buffer_package);
592+ native_surface.surface_advance_buffer(&native_surface, &buffer_package);
593 }
594
595 TEST_F(MesaClientNativeSurfaceTest, swapinterval_request)
596@@ -130,16 +127,46 @@
597 EXPECT_CALL(mock_surface, request_and_wait_for_configure(mir_surface_attrib_swapinterval,1))
598 .InSequence(seq);
599
600- mclg::NativeSurface interpreter(mock_surface);
601- interpreter.set_swapinterval(0);
602- interpreter.set_swapinterval(1);
603+ native_surface.set_swapinterval(0);
604+ native_surface.set_swapinterval(1);
605 }
606
607 TEST_F(MesaClientNativeSurfaceTest, swapinterval_unsupported_request)
608 {
609- mclg::NativeSurface interpreter(mock_surface);
610- EXPECT_EQ(MIR_MESA_FALSE, interpreter.set_swapinterval(-1));
611- EXPECT_EQ(MIR_MESA_TRUE, interpreter.set_swapinterval(0));
612- EXPECT_EQ(MIR_MESA_TRUE, interpreter.set_swapinterval(1));
613- EXPECT_EQ(MIR_MESA_FALSE, interpreter.set_swapinterval(2));
614+ EXPECT_EQ(MIR_MESA_FALSE, native_surface.set_swapinterval(-1));
615+ EXPECT_EQ(MIR_MESA_TRUE, native_surface.set_swapinterval(0));
616+ EXPECT_EQ(MIR_MESA_TRUE, native_surface.set_swapinterval(1));
617+ EXPECT_EQ(MIR_MESA_FALSE, native_surface.set_swapinterval(2));
618+}
619+
620+TEST_F(MesaClientNativeSurfaceTest, returns_error_on_advance_buffer_failure)
621+{
622+ using namespace testing;
623+
624+ EXPECT_CALL(mock_surface, get_current_buffer())
625+ .WillOnce(Throw(std::runtime_error("")));
626+
627+ MirBufferPackage buffer_package;
628+ EXPECT_THAT(native_surface.advance_buffer(&buffer_package), Eq(MIR_MESA_FALSE));
629+}
630+
631+TEST_F(MesaClientNativeSurfaceTest, returns_error_on_get_parameters_failure)
632+{
633+ using namespace testing;
634+
635+ EXPECT_CALL(mock_surface, get_parameters())
636+ .WillOnce(Throw(std::runtime_error("")));
637+
638+ MirSurfaceParameters surface_params;
639+ EXPECT_THAT(native_surface.get_parameters(&surface_params), Eq(MIR_MESA_FALSE));
640+}
641+
642+TEST_F(MesaClientNativeSurfaceTest, returns_error_on_set_swap_interval_failure)
643+{
644+ using namespace testing;
645+
646+ EXPECT_CALL(mock_surface, request_and_wait_for_configure(_,_))
647+ .WillOnce(Throw(std::runtime_error("")));
648+
649+ EXPECT_THAT(native_surface.set_swapinterval(0), Eq(MIR_MESA_FALSE));
650 }

Subscribers

People subscribed via source and target branches