Mir

Merge lp:~kdub/mir/fix-1239577 into lp:mir

Proposed by Kevin DuBois
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 1142
Proposed branch: lp:~kdub/mir/fix-1239577
Merge into: lp:mir
Diff against target: 1010 lines (+211/-450)
10 files modified
include/test/mir_test/draw/android_graphics.h (+0/-2)
include/test/mir_test/draw/draw_pattern_checkered-inl.h (+12/-12)
include/test/mir_test/draw/patterns.h (+6/-6)
include/test/mir_test/stub_server_tool.h (+2/-1)
tests/draw/android_graphics.cpp (+0/-6)
tests/draw/patterns.cpp (+12/-12)
tests/integration-tests/client/test_client_render.cpp (+154/-385)
tests/integration-tests/graphics/android/test_buffer_integration.cpp (+2/-2)
tests/integration-tests/graphics/android/test_display_integration.cpp (+0/-3)
tests/unit-tests/draw/test_draw_patterns.cpp (+23/-21)
To merge this branch: bzr merge lp:~kdub/mir/fix-1239577
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Daniel van Vugt Approve
Review via email: mp+191049@code.launchpad.net

Commit message

fix: lp 1239577

TestClientIPCRender (an android-only gfx driver test) was hanging due to changes in signal handling. refactor the test, changing the cross-process sync mechanism so it doesn't use sigcont.

Description of the change

fix: lp 1239577

TestClientIPCRender (an android-only gfx driver test) was hanging due to changes in signal handling. refactor the test, changing the cross-process sync mechanism so it doesn't use sigcont.

this test was messy to begin with. It now passes reliably, and is cleaner after the refactor, although I'll admit there still is room to improve it.

also, I rm-ed the fragile check this test was doing for surfaceflinger. Now that mir is on the system images, it would compete for resources with unity8 (and detecting the running processes from /proc is fragile anyways). Just better to remove

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

1. I would have recommended keeping share_ptr's as regular pointers at least, to keep the diff down. But not important now that it's done.

2. This should have been an if statement: switch (i % 2)

3. Using braces{
    like this}; // is a minor style violation, I think

4. CI is showing some test failures on amd64 (see above).

I'm seeing some other newish failures, but they're on development-branch too (!?)

What's important though is bug 1239577 and that indeed seems to be fixed. Only bug 1239955 is holding up integration-tests on Nexus 4 now.

So #4 needs fixing. But otherwise approved.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
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 'include/test/mir_test/draw/android_graphics.h'
2--- include/test/mir_test/draw/android_graphics.h 2013-10-15 02:59:59 +0000
3+++ include/test/mir_test/draw/android_graphics.h 2013-10-16 23:18:17 +0000
4@@ -53,8 +53,6 @@
5 alloc_device_t* alloc_dev;
6 };
7
8-bool is_surface_flinger_running();
9-
10 }
11 }
12 }
13
14=== modified file 'include/test/mir_test/draw/draw_pattern_checkered-inl.h'
15--- include/test/mir_test/draw/draw_pattern_checkered-inl.h 2013-04-24 05:22:20 +0000
16+++ include/test/mir_test/draw/draw_pattern_checkered-inl.h 2013-10-16 23:18:17 +0000
17@@ -24,37 +24,37 @@
18 }
19
20 template<size_t Rows, size_t Cols>
21-void DrawPatternCheckered<Rows,Cols>::draw(std::shared_ptr<MirGraphicsRegion>& region) const
22+void DrawPatternCheckered<Rows,Cols>::draw(MirGraphicsRegion const& region) const
23 {
24- if (region->pixel_format != mir_pixel_format_abgr_8888 )
25+ if (region.pixel_format != mir_pixel_format_abgr_8888)
26 throw(std::runtime_error("cannot draw region, incorrect format"));
27
28- uint32_t *pixel = (uint32_t*) region->vaddr;
29- for(int i=0; i< region->width; i++)
30+ uint32_t *pixel = (uint32_t*) region.vaddr;
31+ for(int i=0; i< region.width; i++)
32 {
33- for(int j=0; j<region->height; j++)
34+ for(int j=0; j<region.height; j++)
35 {
36 int key_row = i % Rows;
37 int key_col = j % Cols;
38- pixel[j*region->stride + i] = color_pattern[key_row][key_col];
39+ pixel[j*region.stride + i] = color_pattern[key_row][key_col];
40 }
41 }
42 }
43
44 template<size_t Rows, size_t Cols>
45-bool DrawPatternCheckered<Rows, Cols>::check(const std::shared_ptr<MirGraphicsRegion>& region) const
46+bool DrawPatternCheckered<Rows, Cols>::check(MirGraphicsRegion const& region) const
47 {
48- if (region->pixel_format != mir_pixel_format_abgr_8888 )
49+ if (region.pixel_format != mir_pixel_format_abgr_8888)
50 throw(std::runtime_error("cannot check region, incorrect format"));
51
52- uint32_t *pixel = (uint32_t*) region->vaddr;
53- for(int i=0; i< region->width; i++)
54+ uint32_t *pixel = (uint32_t*) region.vaddr;
55+ for(int i=0; i< region.width; i++)
56 {
57- for(int j=0; j<region->height; j++)
58+ for(int j=0; j<region.height; j++)
59 {
60 int key_row = i % Rows;
61 int key_col = j % Cols;
62- if (pixel[j*region->stride + i] != color_pattern[key_row][key_col])
63+ if (pixel[j*region.stride + i] != color_pattern[key_row][key_col])
64 {
65 return false;
66 }
67
68=== modified file 'include/test/mir_test/draw/patterns.h'
69--- include/test/mir_test/draw/patterns.h 2013-04-24 05:22:20 +0000
70+++ include/test/mir_test/draw/patterns.h 2013-10-16 23:18:17 +0000
71@@ -37,8 +37,8 @@
72 {
73 public:
74 virtual ~DrawPattern() {};
75- virtual void draw(std::shared_ptr<MirGraphicsRegion>& region) const = 0;
76- virtual bool check(const std::shared_ptr<MirGraphicsRegion>& region) const = 0;
77+ virtual void draw(MirGraphicsRegion const& region) const = 0;
78+ virtual bool check(MirGraphicsRegion const& region) const = 0;
79
80 protected:
81 DrawPattern() = default;
82@@ -52,8 +52,8 @@
83 /* todo: should construct with a color value type, not an uint32 */
84 DrawPatternSolid(uint32_t color_value);
85
86- void draw(std::shared_ptr<MirGraphicsRegion>& region) const;
87- bool check(const std::shared_ptr<MirGraphicsRegion>& region) const;
88+ void draw(MirGraphicsRegion const& region) const;
89+ bool check(MirGraphicsRegion const& region) const;
90
91 private:
92 const uint32_t color_value;
93@@ -66,8 +66,8 @@
94 /* todo: should construct with a color value type, not an uint32 */
95 DrawPatternCheckered(uint32_t (&pattern) [Rows][Cols]);
96
97- void draw(std::shared_ptr<MirGraphicsRegion>& region) const;
98- bool check(const std::shared_ptr<MirGraphicsRegion>& region) const;
99+ void draw(MirGraphicsRegion const& region) const;
100+ bool check(MirGraphicsRegion const& region) const;
101
102 private:
103 uint32_t color_pattern [Rows][Cols];
104
105=== modified file 'include/test/mir_test/stub_server_tool.h'
106--- include/test/mir_test/stub_server_tool.h 2013-08-28 03:41:48 +0000
107+++ include/test/mir_test/stub_server_tool.h 2013-10-16 23:18:17 +0000
108@@ -80,10 +80,11 @@
109 virtual void connect(
110 ::google::protobuf::RpcController*,
111 const ::mir::protobuf::ConnectParameters* request,
112- ::mir::protobuf::Connection*,
113+ ::mir::protobuf::Connection* connect_msg,
114 ::google::protobuf::Closure* done) override
115 {
116 app_name = request->application_name();
117+ connect_msg->set_error("");
118 done->Run();
119 }
120
121
122=== modified file 'tests/draw/android_graphics.cpp'
123--- tests/draw/android_graphics.cpp 2013-10-15 02:59:59 +0000
124+++ tests/draw/android_graphics.cpp 2013-10-16 23:18:17 +0000
125@@ -113,9 +113,3 @@
126
127 return std::shared_ptr<MirGraphicsRegion>(region, del);
128 }
129-
130-bool mtd::is_surface_flinger_running()
131-{
132- struct dirent **namelist;
133- return 0 < scandir(proc_dir, &namelist, surface_flinger_filter, 0);
134-}
135
136=== modified file 'tests/draw/patterns.cpp'
137--- tests/draw/patterns.cpp 2013-02-04 19:24:07 +0000
138+++ tests/draw/patterns.cpp 2013-10-16 23:18:17 +0000
139@@ -25,34 +25,34 @@
140 {
141 }
142
143-void mtd::DrawPatternSolid::draw(std::shared_ptr<MirGraphicsRegion>& region) const
144+void mtd::DrawPatternSolid::draw(MirGraphicsRegion const& region) const
145 {
146- if (region->pixel_format != mir_pixel_format_abgr_8888 )
147+ if (region.pixel_format != mir_pixel_format_abgr_8888 )
148 throw(std::runtime_error("cannot draw region, incorrect format"));
149
150- uint32_t *pixel = (uint32_t*) region->vaddr;
151+ uint32_t *pixel = (uint32_t*) region.vaddr;
152 int i,j;
153- for(i=0; i<region->height; i++)
154+ for(i=0; i<region.height; i++)
155 {
156- for(j=0; j< region->width; j++)
157+ for(j=0; j< region.width; j++)
158 {
159- pixel[i*region->stride + j] = color_value;
160+ pixel[i*region.stride + j] = color_value;
161 }
162 }
163 }
164
165-bool mtd::DrawPatternSolid::check(const std::shared_ptr<MirGraphicsRegion>& region) const
166+bool mtd::DrawPatternSolid::check(MirGraphicsRegion const& region) const
167 {
168- if (region->pixel_format != mir_pixel_format_abgr_8888 )
169+ if (region.pixel_format != mir_pixel_format_abgr_8888 )
170 throw(std::runtime_error("cannot check region, incorrect format"));
171
172- uint32_t *pixel = (uint32_t*) region->vaddr;
173+ uint32_t *pixel = (uint32_t*) region.vaddr;
174 int i,j;
175- for(i=0; i< region->width; i++)
176+ for(i=0; i< region.width; i++)
177 {
178- for(j=0; j<region->height; j++)
179+ for(j=0; j<region.height; j++)
180 {
181- if (pixel[j*region->stride + i] != color_value)
182+ if (pixel[j*region.stride + i] != color_value)
183 {
184 return false;
185 }
186
187=== modified file 'tests/integration-tests/client/test_client_render.cpp'
188--- tests/integration-tests/client/test_client_render.cpp 2013-10-15 02:59:59 +0000
189+++ tests/integration-tests/client/test_client_render.cpp 2013-10-16 23:18:17 +0000
190@@ -20,9 +20,11 @@
191
192 #include "mir/graphics/buffer_properties.h"
193 #include "mir/graphics/buffer_initializer.h"
194+#include "src/server/graphics/android/buffer.h"
195 #include "mir/graphics/android/native_buffer.h"
196 #include "src/server/graphics/android/android_graphic_buffer_allocator.h"
197
198+#include "mir_test_framework/cross_process_sync.h"
199 #include "mir_test/draw/android_graphics.h"
200 #include "mir_test/draw/patterns.h"
201 #include "mir_test/stub_server_tool.h"
202@@ -48,156 +50,62 @@
203 {
204 static int test_width = 300;
205 static int test_height = 200;
206-}
207-
208-namespace mir
209-{
210-namespace test
211-{
212-/* client code */
213-static void connected_callback(MirConnection *connection, void* context)
214-{
215- MirConnection** tmp = (MirConnection**) context;
216- *tmp = connection;
217-}
218-static void create_callback(MirSurface *surface, void*context)
219-{
220- MirSurface** surf = (MirSurface**) context;
221- *surf = surface;
222-}
223-
224-static void next_callback(MirSurface *, void*)
225-{
226-}
227
228 static uint32_t pattern0 [2][2] = {{0x12345678, 0x23456789},
229 {0x34567890, 0x45678901}};
230-
231 static uint32_t pattern1 [2][2] = {{0xFFFFFFFF, 0xFFFF0000},
232 {0xFF00FF00, 0xFF0000FF}};
233+static mtd::DrawPatternCheckered<2,2> draw_pattern0(pattern0);
234+static mtd::DrawPatternCheckered<2,2> draw_pattern1(pattern1);
235+static const char socket_file[] = "./test_client_ipc_render_socket";
236+
237 struct TestClient
238 {
239-
240- static void sig_handle(int)
241- {
242- }
243-
244- static int render_single()
245- {
246- if (signal(SIGCONT, sig_handle) == SIG_ERR)
247- return -1;
248- pause();
249-
250- MirConnection* connection = NULL;
251- MirSurface* surface;
252- MirSurfaceParameters surface_parameters;
253-
254- /* establish connection. wait for server to come up */
255- while (connection == NULL)
256- {
257- mir_wait_for(mir_connect("./test_socket_surface", "test_renderer",
258- &connected_callback, &connection));
259- std::this_thread::sleep_for(std::chrono::milliseconds(10));
260- }
261- /* make surface */
262- surface_parameters.name = "testsurface";
263- surface_parameters.width = test_width;
264- surface_parameters.height = test_height;
265- surface_parameters.pixel_format = mir_pixel_format_abgr_8888;
266- mir_wait_for(mir_connection_create_surface(connection,
267- &surface_parameters,
268- &create_callback,
269- &surface));
270-
271- auto graphics_region = std::make_shared<MirGraphicsRegion>();
272- /* grab a buffer*/
273- mir_surface_get_graphics_region(surface, graphics_region.get());
274-
275- /* render pattern */
276- mtd::DrawPatternCheckered<2,2> draw_pattern0(mt::pattern0);
277- draw_pattern0.draw(graphics_region);
278-
279- mir_wait_for(mir_surface_release(surface, &create_callback, &surface));
280-
281- /* release */
282- mir_connection_release(connection);
283- return 0;
284- }
285-
286- static int render_double()
287- {
288- if (signal(SIGCONT, sig_handle) == SIG_ERR)
289- return -1;
290- pause();
291-
292- MirConnection* connection = NULL;
293- MirSurface* surface;
294- MirSurfaceParameters surface_parameters;
295-
296- /* establish connection. wait for server to come up */
297- while (connection == NULL)
298- {
299- mir_wait_for(mir_connect("./test_socket_surface", "test_renderer",
300- &connected_callback, &connection));
301- std::this_thread::sleep_for(std::chrono::milliseconds(10));
302- }
303- /* make surface */
304- surface_parameters.name = "testsurface";
305- surface_parameters.width = test_width;
306- surface_parameters.height = test_height;
307- surface_parameters.pixel_format = mir_pixel_format_abgr_8888;
308-
309- mir_wait_for(mir_connection_create_surface(connection,
310- &surface_parameters,
311- &create_callback,
312- &surface));
313-
314- auto graphics_region = std::make_shared<MirGraphicsRegion>();
315- mir_surface_get_graphics_region( surface, graphics_region.get());
316- mtd::DrawPatternCheckered<2,2> draw_pattern0(mt::pattern0);
317- draw_pattern0.draw(graphics_region);
318-
319- mir_wait_for(mir_surface_swap_buffers(surface, &next_callback, (void*) NULL));
320- mir_surface_get_graphics_region( surface, graphics_region.get());
321- mtd::DrawPatternCheckered<2,2> draw_pattern1(mt::pattern1);
322- draw_pattern1.draw(graphics_region);
323-
324- mir_wait_for(mir_surface_release(surface, &create_callback, &surface));
325-
326- /* release */
327- mir_connection_release(connection);
328- return 0;
329- }
330-
331- static int render_accelerated()
332- {
333- if (signal(SIGCONT, sig_handle) == SIG_ERR)
334- return -1;
335- pause();
336-
337- /* only use C api */
338- MirConnection* connection = NULL;
339- MirSurface* surface;
340- MirSurfaceParameters surface_parameters;
341-
342- /* establish connection. wait for server to come up */
343- while (connection == NULL)
344- {
345- mir_wait_for(mir_connect("./test_socket_surface", "test_renderer",
346- &connected_callback, &connection));
347- std::this_thread::sleep_for(std::chrono::milliseconds(10));
348- }
349- /* make surface */
350- surface_parameters.name = "testsurface";
351- surface_parameters.width = test_width;
352- surface_parameters.height = test_height;
353- surface_parameters.pixel_format = mir_pixel_format_abgr_8888;
354-
355- mir_wait_for(mir_connection_create_surface(connection,
356- &surface_parameters,
357- &create_callback,
358- &surface));
359-
360+ static int render_cpu_pattern(mtf::CrossProcessSync& process_sync, int num_frames)
361+ {
362+ process_sync.wait_for_signal_ready_for();
363+
364+ MirSurfaceParameters surface_parameters
365+ {
366+ "testsurface", test_width, test_height, mir_pixel_format_abgr_8888,
367+ mir_buffer_usage_software, mir_display_output_id_invalid
368+ };
369+ auto connection = mir_connect_sync(socket_file, "test_renderer");
370+ auto surface = mir_connection_create_surface_sync(connection, &surface_parameters);
371+ MirGraphicsRegion graphics_region;
372+ for(int i=0u; i < num_frames; i++)
373+ {
374+ mir_surface_get_graphics_region(surface, &graphics_region);
375+ if (i % 2)
376+ {
377+ draw_pattern1.draw(graphics_region);
378+ }
379+ else
380+ {
381+ draw_pattern0.draw(graphics_region);
382+ }
383+ mir_surface_swap_buffers_sync(surface);
384+ }
385+
386+ mir_surface_release_sync(surface);
387+ mir_connection_release(connection);
388+ return 0;
389+ }
390+
391+ //performs num_frames renders, in red, green, blue repeating pattern
392+ static int render_rgb_with_gl(mtf::CrossProcessSync& process_sync, int num_frames)
393+ {
394+ process_sync.wait_for_signal_ready_for();
395+
396+ MirSurfaceParameters surface_parameters
397+ {
398+ "testsurface", test_width, test_height, mir_pixel_format_abgr_8888,
399+ mir_buffer_usage_hardware, mir_display_output_id_invalid
400+ };
401+ auto connection = mir_connect_sync(socket_file, "test_renderer");
402+ auto surface = mir_connection_create_surface_sync(connection, &surface_parameters);
403+
404+ /* set up egl context */
405 int major, minor, n;
406 EGLDisplay disp;
407 EGLContext context;
408@@ -221,83 +129,27 @@
409 context = eglCreateContext(disp, egl_config, EGL_NO_CONTEXT, context_attribs);
410 eglMakeCurrent(disp, egl_surface, egl_surface, context);
411
412- glClearColor(1.0, 0.0, 0.0, 1.0);
413- glClear(GL_COLOR_BUFFER_BIT);
414-
415- eglSwapBuffers(disp, egl_surface);
416- mir_wait_for(mir_surface_release(surface, &create_callback, &surface));
417-
418- /* release */
419- mir_connection_release(connection);
420- return 0;
421-
422- }
423-
424- static int render_accelerated_double()
425- {
426- if (signal(SIGCONT, sig_handle) == SIG_ERR)
427- return -1;
428- pause();
429-
430- /* only use C api */
431- MirConnection* connection = NULL;
432- MirSurface* surface;
433- MirSurfaceParameters surface_parameters;
434-
435- /* establish connection. wait for server to come up */
436- while (connection == NULL)
437+ for (auto i=0; i < num_frames; i++)
438 {
439- mir_wait_for(mir_connect("./test_socket_surface", "test_renderer",
440- &connected_callback, &connection));
441- std::this_thread::sleep_for(std::chrono::milliseconds(10));
442+ switch (i % 3)
443+ {
444+ case 0: //red
445+ glClearColor(1.0, 0.0, 0.0, 1.0);
446+ break;
447+ case 1: //green
448+ glClearColor(0.0, 1.0, 0.0, 1.0);
449+ break;
450+ case 2: //blue
451+ default:
452+ glClearColor(0.0, 0.0, 1.0, 1.0);
453+ break;
454+ }
455+ glClear(GL_COLOR_BUFFER_BIT);
456+
457+ eglSwapBuffers(disp, egl_surface);
458 }
459- /* make surface */
460- surface_parameters.name = "testsurface";
461- surface_parameters.width = test_width;
462- surface_parameters.height = test_height;
463- surface_parameters.pixel_format = mir_pixel_format_abgr_8888;
464-
465- mir_wait_for(mir_connection_create_surface(connection,
466- &surface_parameters,
467- &create_callback,
468- &surface));
469-
470- int major, minor, n;
471- EGLDisplay disp;
472- EGLContext context;
473- EGLSurface egl_surface;
474- EGLConfig egl_config;
475- EGLint attribs[] = {
476- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
477- EGL_GREEN_SIZE, 8,
478- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
479- EGL_NONE };
480- EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
481-
482- EGLNativeDisplayType native_display = (EGLNativeDisplayType)mir_connection_get_egl_native_display(connection);
483- EGLNativeWindowType native_window = (EGLNativeWindowType)mir_surface_get_egl_native_window(surface);
484-
485- disp = eglGetDisplay(native_display);
486- eglInitialize(disp, &major, &minor);
487-
488- eglChooseConfig(disp, attribs, &egl_config, 1, &n);
489- egl_surface = eglCreateWindowSurface(disp, egl_config, native_window, NULL);
490- context = eglCreateContext(disp, egl_config, EGL_NO_CONTEXT, context_attribs);
491- eglMakeCurrent(disp, egl_surface, egl_surface, context);
492-
493- glClearColor(1.0, 0.0, 0.0, 1.0);
494- glClear(GL_COLOR_BUFFER_BIT);
495-
496- eglSwapBuffers(disp, egl_surface);
497-
498- glClearColor(0.0, 1.0, 0.0, 1.0);
499- glClear(GL_COLOR_BUFFER_BIT);
500-
501- eglSwapBuffers(disp, egl_surface);
502-
503- mir_wait_for(mir_surface_release(surface, &create_callback, &surface));
504-
505- /* release */
506+
507+ mir_surface_release_sync(surface);
508 mir_connection_release(connection);
509 return 0;
510
511@@ -312,13 +164,16 @@
512 /* server code */
513 struct StubServerGenerator : public mt::StubServerTool
514 {
515- StubServerGenerator(std::shared_ptr<mg::NativeBuffer> const& handle, int id)
516- : handle(handle),
517- next_received(false),
518- next_allowed(false),
519- handle_id(id)
520+ StubServerGenerator()
521+ : next_received(false),
522+ next_allowed(false)
523 {
524-
525+ auto initializer = std::make_shared<mg::NullBufferInitializer>();
526+ allocator = std::make_shared<mga::AndroidGraphicBufferAllocator> (initializer);
527+ auto size = geom::Size{test_width, test_height};
528+ auto pf = geom::PixelFormat::abgr_8888;
529+ last_posted = allocator->alloc_buffer_platform(size, pf, mga::BufferUsage::use_hardware);
530+ client_buffer = allocator->alloc_buffer_platform(size, pf, mga::BufferUsage::use_hardware);
531 }
532
533 void create_surface(google::protobuf::RpcController* /*controller*/,
534@@ -326,15 +181,17 @@
535 mir::protobuf::Surface* response,
536 google::protobuf::Closure* done)
537 {
538- response->mutable_id()->set_value(13); // TODO distinct numbers & tracking
539+ response->mutable_id()->set_value(13);
540 response->set_width(test_width);
541 response->set_height(test_height);
542 response->set_pixel_format(request->pixel_format());
543- response->mutable_buffer()->set_buffer_id(handle_id);
544- response->mutable_buffer()->set_stride(handle->anwb()->stride);
545+ response->mutable_buffer()->set_buffer_id(client_buffer->id().as_uint32_t());
546+
547+ auto buf = client_buffer->native_buffer_handle();
548+ response->mutable_buffer()->set_stride(buf->anwb()->stride);
549
550 response->mutable_buffer()->set_fds_on_side_channel(1);
551- native_handle_t const* native_handle = handle->handle();
552+ native_handle_t const* native_handle = buf->handle();
553 for(auto i=0; i<native_handle->numFds; i++)
554 response->mutable_buffer()->add_fd(native_handle->data[i]);
555 for(auto i=0; i<native_handle->numInts; i++)
556@@ -353,56 +210,43 @@
557 ::mir::protobuf::Buffer* response,
558 ::google::protobuf::Closure* done)
559 {
560- {
561- std::unique_lock<std::mutex> lk(next_guard);
562- next_received = true;
563- next_cv.notify_all();
564-
565- while (!next_allowed) {
566- allow_cv.wait(lk);
567- }
568- next_allowed = false;
569- }
570-
571- response->set_buffer_id(handle_id);
572+ std::unique_lock<std::mutex> lk(buffer_mutex);
573+ std::swap(last_posted, client_buffer);
574+
575+ response->set_buffer_id(client_buffer->id().as_uint32_t());
576+
577+ auto buf = client_buffer->native_buffer_handle();
578
579 response->set_fds_on_side_channel(1);
580- native_handle_t const* native_handle = handle->handle();
581- response->set_stride(handle->anwb()->stride);
582+ native_handle_t const* native_handle = buf->handle();
583+ response->set_stride(buf->anwb()->stride);
584 for(auto i=0; i<native_handle->numFds; i++)
585 response->add_fd(native_handle->data[i]);
586 for(auto i=0; i<native_handle->numInts; i++)
587 response->add_data(native_handle->data[native_handle->numFds+i]);
588
589+
590 done->Run();
591 }
592
593- void wait_on_next_buffer()
594- {
595- std::unique_lock<std::mutex> lk(next_guard);
596- while (!next_received)
597- next_cv.wait(lk);
598- next_received = false;
599- }
600-
601- void allow_next_continue()
602- {
603- std::unique_lock<std::mutex> lk(next_guard);
604- next_allowed = true;
605- allow_cv.notify_all();
606- lk.unlock();
607- }
608-
609- void set_handle(std::shared_ptr<mg::NativeBuffer> const& pack, int id)
610- {
611- handle = pack;
612- handle_id = id;
613+ std::shared_ptr<mga::Buffer> second_to_last_posted_buffer()
614+ {
615+ std::unique_lock<std::mutex> lk(buffer_mutex);
616+ return client_buffer;
617+ }
618+
619+ std::shared_ptr<mga::Buffer> last_posted_buffer()
620+ {
621+ std::unique_lock<std::mutex> lk(buffer_mutex);
622+ return last_posted;
623 }
624
625 private:
626- std::shared_ptr<mg::NativeBuffer> handle;
627+ std::shared_ptr<mga::AndroidGraphicBufferAllocator> allocator;
628+ std::shared_ptr<mga::Buffer> client_buffer;
629+ std::shared_ptr<mga::Buffer> last_posted;
630
631- std::mutex next_guard;
632+ std::mutex buffer_mutex;
633 std::condition_variable next_cv;
634 std::condition_variable allow_cv;
635 bool next_received;
636@@ -411,195 +255,120 @@
637 int handle_id;
638 };
639
640-
641-}
642 }
643
644 struct TestClientIPCRender : public testing::Test
645 {
646- /* kdub -- some of the (less thoroughly tested) android blob drivers annoyingly keep
647- static state about what process they are in. Once you fork, this info is invalid,
648- yet the driver uses the info and bad things happen.
649- Fork all needed processes before touching the blob! */
650+ /* note: we fork here so that the loaded driver code does not fork */
651 static void SetUpTestCase() {
652+
653 render_single_client_process = mtf::fork_and_run_in_a_different_process(
654- mt::TestClient::render_single,
655- mt::TestClient::exit_function);
656-
657+ std::bind(TestClient::render_cpu_pattern, std::ref(sync1), 1),
658+ TestClient::exit_function);
659 render_double_client_process = mtf::fork_and_run_in_a_different_process(
660- mt::TestClient::render_double,
661- mt::TestClient::exit_function);
662-
663- second_render_with_same_buffer_client_process
664- = mtf::fork_and_run_in_a_different_process(
665- mt::TestClient::render_double,
666- mt::TestClient::exit_function);
667-
668- render_accelerated_process
669- = mtf::fork_and_run_in_a_different_process(
670- mt::TestClient::render_accelerated,
671- mt::TestClient::exit_function);
672-
673- render_accelerated_process_double
674- = mtf::fork_and_run_in_a_different_process(
675- mt::TestClient::render_accelerated_double,
676- mt::TestClient::exit_function);
677+ std::bind(TestClient::render_cpu_pattern, std::ref(sync2), 2),
678+ TestClient::exit_function);
679+ render_accelerated_process = mtf::fork_and_run_in_a_different_process(
680+ std::bind(TestClient::render_rgb_with_gl, std::ref(sync3), 1),
681+ TestClient::exit_function);
682+ render_accelerated_process_double = mtf::fork_and_run_in_a_different_process(
683+ std::bind(TestClient::render_rgb_with_gl, std::ref(sync4), 2),
684+ TestClient::exit_function);
685 }
686
687 void SetUp() {
688- ASSERT_FALSE(mtd::is_surface_flinger_running());
689-
690- size = geom::Size{test_width, test_height};
691- pf = geom::PixelFormat::abgr_8888;
692-
693- auto initializer = std::make_shared<mg::NullBufferInitializer>();
694- allocator = std::make_shared<mga::AndroidGraphicBufferAllocator> (initializer);
695- mg::BufferProperties properties(size, pf, mg::BufferUsage::hardware);
696- android_buffer = allocator->alloc_buffer(properties);
697- second_android_buffer = allocator->alloc_buffer(properties);
698-
699 buffer_converter = std::make_shared<mtd::TestGrallocMapper>();
700
701- handle = android_buffer->native_buffer_handle();
702- second_handle = second_android_buffer->native_buffer_handle();
703-
704 /* start a server */
705- mock_server = std::make_shared<mt::StubServerGenerator>(handle, 14);
706- test_server = std::make_shared<mt::TestProtobufServer>("./test_socket_surface", mock_server);
707+ mock_server = std::make_shared<StubServerGenerator>();
708+ test_server = std::make_shared<mt::TestProtobufServer>(socket_file, mock_server);
709 test_server->comm->start();
710 }
711
712 void TearDown()
713 {
714 test_server.reset();
715+ std::remove(socket_file);
716 }
717
718- mir::protobuf::Connection response;
719-
720 std::shared_ptr<mt::TestProtobufServer> test_server;
721- std::shared_ptr<mt::StubServerGenerator> mock_server;
722+ std::shared_ptr<StubServerGenerator> mock_server;
723
724- geom::Size size;
725- geom::PixelFormat pf;
726- mg::BufferID id1;
727- mg::BufferID id2;
728 std::shared_ptr<mtd::TestGrallocMapper> buffer_converter;
729- std::shared_ptr<mtf::Process> client_process;
730-
731- std::shared_ptr<mg::NativeBuffer> handle;
732- std::shared_ptr<mg::NativeBuffer> second_handle;
733-
734- std::shared_ptr<mg::Buffer> android_buffer;
735- std::shared_ptr<mg::Buffer> second_android_buffer;
736- std::shared_ptr<mga::AndroidGraphicBufferAllocator> allocator;
737
738 static std::shared_ptr<mtf::Process> render_single_client_process;
739 static std::shared_ptr<mtf::Process> render_double_client_process;
740- static std::shared_ptr<mtf::Process> second_render_with_same_buffer_client_process;
741 static std::shared_ptr<mtf::Process> render_accelerated_process;
742 static std::shared_ptr<mtf::Process> render_accelerated_process_double;
743+ static mtf::CrossProcessSync sync1, sync2, sync3, sync4;
744 };
745+
746+mtf::CrossProcessSync TestClientIPCRender::sync1;
747 std::shared_ptr<mtf::Process> TestClientIPCRender::render_single_client_process;
748+mtf::CrossProcessSync TestClientIPCRender::sync2;
749 std::shared_ptr<mtf::Process> TestClientIPCRender::render_double_client_process;
750-std::shared_ptr<mtf::Process> TestClientIPCRender::second_render_with_same_buffer_client_process;
751+mtf::CrossProcessSync TestClientIPCRender::sync3;
752 std::shared_ptr<mtf::Process> TestClientIPCRender::render_accelerated_process;
753+mtf::CrossProcessSync TestClientIPCRender::sync4;
754 std::shared_ptr<mtf::Process> TestClientIPCRender::render_accelerated_process_double;
755
756 TEST_F(TestClientIPCRender, test_render_single)
757 {
758- mtd::DrawPatternCheckered<2,2> rendered_pattern(mt::pattern0);
759- /* activate client */
760- render_single_client_process->cont();
761+ sync1.try_signal_ready_for();
762
763 /* wait for client to finish */
764 EXPECT_TRUE(render_single_client_process->wait_for_termination().succeeded());
765
766 /* check content */
767- auto region = buffer_converter->graphic_region_from_handle(handle->anwb());
768- EXPECT_TRUE(rendered_pattern.check(region));
769+ auto buf = mock_server->last_posted_buffer();
770+ auto region = buffer_converter->graphic_region_from_handle(buf->native_buffer_handle()->anwb());
771+ EXPECT_TRUE(draw_pattern0.check(*region));
772 }
773
774 TEST_F(TestClientIPCRender, test_render_double)
775 {
776- mtd::DrawPatternCheckered<2,2> rendered_pattern0(mt::pattern0);
777- mtd::DrawPatternCheckered<2,2> rendered_pattern1(mt::pattern1);
778- /* activate client */
779- render_double_client_process->cont();
780-
781- /* wait for next buffer */
782- mock_server->wait_on_next_buffer();
783- auto region = buffer_converter->graphic_region_from_handle(handle->anwb());
784- EXPECT_TRUE(rendered_pattern0.check(region));
785-
786- mock_server->set_handle(second_handle, 15);
787- mock_server->allow_next_continue();
788+ sync2.try_signal_ready_for();
789
790 /* wait for client to finish */
791 EXPECT_TRUE(render_double_client_process->wait_for_termination().succeeded());
792
793- auto second_region = buffer_converter->graphic_region_from_handle(second_handle->anwb());
794- EXPECT_TRUE(rendered_pattern1.check(second_region));
795-}
796-
797-TEST_F(TestClientIPCRender, test_second_render_with_same_buffer)
798-{
799- mtd::DrawPatternCheckered<2,2> rendered_pattern(mt::pattern1);
800- /* activate client */
801- second_render_with_same_buffer_client_process->cont();
802-
803- /* wait for next buffer */
804- mock_server->wait_on_next_buffer();
805- mock_server->allow_next_continue();
806-
807- /* wait for client to finish */
808- EXPECT_TRUE(second_render_with_same_buffer_client_process->wait_for_termination().succeeded());
809-
810- /* check content */
811- auto region = buffer_converter->graphic_region_from_handle(handle->anwb());
812- EXPECT_TRUE(rendered_pattern.check(region));
813+ auto buf0 = mock_server->second_to_last_posted_buffer();
814+ auto region0 = buffer_converter->graphic_region_from_handle(buf0->native_buffer_handle()->anwb());
815+ EXPECT_TRUE(draw_pattern0.check(*region0));
816+
817+ auto buf1 = mock_server->last_posted_buffer();
818+ auto region1 = buffer_converter->graphic_region_from_handle(buf1->native_buffer_handle()->anwb());
819+ EXPECT_TRUE(draw_pattern1.check(*region1));
820 }
821
822 TEST_F(TestClientIPCRender, test_accelerated_render)
823 {
824 mtd::DrawPatternSolid red_pattern(0xFF0000FF);
825
826- /* activate client */
827- render_accelerated_process->cont();
828-
829- /* wait for next buffer */
830- mock_server->wait_on_next_buffer();
831- mock_server->allow_next_continue();
832-
833+ sync3.try_signal_ready_for();
834 /* wait for client to finish */
835 EXPECT_TRUE(render_accelerated_process->wait_for_termination().succeeded());
836
837 /* check content */
838- auto region = buffer_converter->graphic_region_from_handle(handle->anwb());
839- EXPECT_TRUE(red_pattern.check(region));
840+ auto buf0 = mock_server->last_posted_buffer();
841+ auto region0 = buffer_converter->graphic_region_from_handle(buf0->native_buffer_handle()->anwb());
842+ EXPECT_TRUE(red_pattern.check(*region0));
843 }
844
845 TEST_F(TestClientIPCRender, test_accelerated_render_double)
846 {
847 mtd::DrawPatternSolid red_pattern(0xFF0000FF);
848 mtd::DrawPatternSolid green_pattern(0xFF00FF00);
849- /* activate client */
850- render_accelerated_process_double->cont();
851-
852- /* wait for next buffer */
853- mock_server->wait_on_next_buffer();
854- mock_server->set_handle(second_handle, 15);
855- mock_server->allow_next_continue();
856-
857- mock_server->wait_on_next_buffer();
858- mock_server->allow_next_continue();
859-
860+
861+ sync4.try_signal_ready_for();
862 /* wait for client to finish */
863 EXPECT_TRUE(render_accelerated_process_double->wait_for_termination().succeeded());
864
865- /* check content */
866- auto region = buffer_converter->graphic_region_from_handle(handle->anwb());
867- EXPECT_TRUE(red_pattern.check(region));
868+ auto buf0 = mock_server->second_to_last_posted_buffer();
869+ auto region0 = buffer_converter->graphic_region_from_handle(buf0->native_buffer_handle()->anwb());
870+ EXPECT_TRUE(red_pattern.check(*region0));
871
872- auto second_region = buffer_converter->graphic_region_from_handle(second_handle->anwb());
873- EXPECT_TRUE(green_pattern.check(second_region));
874+ auto buf1 = mock_server->last_posted_buffer();
875+ auto region1 = buffer_converter->graphic_region_from_handle(buf1->native_buffer_handle()->anwb());
876+ EXPECT_TRUE(green_pattern.check(*region1));
877 }
878
879=== modified file 'tests/integration-tests/graphics/android/test_buffer_integration.cpp'
880--- tests/integration-tests/graphics/android/test_buffer_integration.cpp 2013-10-15 02:59:59 +0000
881+++ tests/integration-tests/graphics/android/test_buffer_integration.cpp 2013-10-16 23:18:17 +0000
882@@ -68,8 +68,8 @@
883
884 auto region = sw_renderer.graphic_region_from_handle(test_buffer->native_buffer_handle()->anwb());
885 mtd::DrawPatternSolid red_pattern(0xFF0000FF);
886- red_pattern.draw(region);
887- EXPECT_TRUE(red_pattern.check(region));
888+ red_pattern.draw(*region);
889+ EXPECT_TRUE(red_pattern.check(*region));
890 }
891
892 TEST_F(AndroidBufferIntegration, allocator_can_create_hw_buffer)
893
894=== modified file 'tests/integration-tests/graphics/android/test_display_integration.cpp'
895--- tests/integration-tests/graphics/android/test_display_integration.cpp 2013-10-15 02:59:59 +0000
896+++ tests/integration-tests/graphics/android/test_display_integration.cpp 2013-10-16 23:18:17 +0000
897@@ -52,9 +52,6 @@
898 protected:
899 static void SetUpTestCase()
900 {
901- /* this is an important precondition for acquiring the display! */
902- ASSERT_FALSE(mir::test::draw::is_surface_flinger_running());
903-
904 /* note about fb_device: OMAP4 drivers seem to only be able to open fb once
905 per process (repeated framebuffer_{open,close}() doesn't seem to work). once we
906 figure out why, we can remove fb_device in the test fixture */
907
908=== modified file 'tests/unit-tests/draw/test_draw_patterns.cpp'
909--- tests/unit-tests/draw/test_draw_patterns.cpp 2013-04-24 05:22:20 +0000
910+++ tests/unit-tests/draw/test_draw_patterns.cpp 2013-10-16 23:18:17 +0000
911@@ -33,14 +33,17 @@
912
913 virtual void SetUp()
914 {
915- test_region = std::make_shared<MirGraphicsRegion>();
916- test_region->pixel_format = mir_pixel_format_abgr_8888;
917+
918+ test_region.pixel_format = mir_pixel_format_abgr_8888;
919 int bytes_pp = 4;
920- test_region->width = 100;
921+ test_region.width = 100;
922 /* misaligned stride to tease out stride problems */
923- test_region->stride = 102;
924- test_region->height = 50;
925- test_region->vaddr = (char*) malloc(sizeof(char) * bytes_pp * test_region->height * test_region->stride);
926+ test_region.stride = 102;
927+ test_region.height = 50;
928+ auto region_size =
929+ sizeof(char) * bytes_pp * test_region.height * test_region.stride;
930+ region = std::shared_ptr<char>(static_cast<char*>(::operator new(region_size)));
931+ test_region.vaddr = region.get();
932
933 uint32_t colors[2][2] = {{0x12345678, 0x23456789},
934 {0x34567890, 0x45678901}};
935@@ -51,34 +54,33 @@
936 virtual void TearDown()
937 {
938 EXPECT_TRUE(check_stride_region_unaltered());
939- free(test_region->vaddr);
940 }
941
942- std::shared_ptr<MirGraphicsRegion> test_region;
943+ MirGraphicsRegion test_region;
944 uint32_t pattern_colors [2][2];
945-
946+ std::shared_ptr<char> region;
947 private:
948 /* check that no pattern writes or checks the stride region */
949 void write_stride_region()
950 {
951- uint32_t* region = (uint32_t*) test_region->vaddr;
952- for(auto i=0; i < test_region->height; i++)
953+ uint32_t* region = (uint32_t*) test_region.vaddr;
954+ for(auto i=0; i < test_region.height; i++)
955 {
956- for(auto j=test_region->width; j<test_region->stride; j++)
957+ for(auto j=test_region.width; j<test_region.stride; j++)
958 {
959- region[ (i*test_region->stride) + j ] = stride_color;
960+ region[ (i*test_region.stride) + j ] = stride_color;
961 }
962 }
963 }
964
965 bool check_stride_region_unaltered()
966 {
967- uint32_t* region = (uint32_t*) test_region->vaddr;
968- for(auto i=0; i < test_region->height; i++)
969+ uint32_t* region = (uint32_t*) test_region.vaddr;
970+ for(auto i=0; i < test_region.height; i++)
971 {
972- for(auto j=test_region->width; j<test_region->stride; j++)
973+ for(auto j=test_region.width; j<test_region.stride; j++)
974 {
975- if(region[ ((i*test_region->stride) + j) ] != stride_color)
976+ if(region[ ((i*test_region.stride) + j) ] != stride_color)
977 {
978 return false;
979 }
980@@ -103,13 +105,13 @@
981 mtd::DrawPatternSolid pattern(0x43214321);
982
983 pattern.draw(test_region);
984- test_region->vaddr[0]++;
985+ test_region.vaddr[0]++;
986 EXPECT_FALSE(pattern.check(test_region));
987 }
988
989 TEST_F(DrawPatternsTest, solid_bad_pixel_formats)
990 {
991- test_region->pixel_format = mir_pixel_format_xbgr_8888;
992+ test_region.pixel_format = mir_pixel_format_xbgr_8888;
993
994 mtd::DrawPatternSolid pattern(0x43214321);
995
996@@ -135,13 +137,13 @@
997 mtd::DrawPatternCheckered<2,2> pattern(pattern_colors);
998
999 pattern.draw(test_region);
1000- test_region->vaddr[0]++;
1001+ test_region.vaddr[0]++;
1002 EXPECT_FALSE(pattern.check(test_region));
1003 }
1004
1005 TEST_F(DrawPatternsTest, checkered_bad_pixel_formats)
1006 {
1007- test_region->pixel_format = mir_pixel_format_xbgr_8888;
1008+ test_region.pixel_format = mir_pixel_format_xbgr_8888;
1009
1010 mtd::DrawPatternCheckered<2,2> pattern(pattern_colors);
1011

Subscribers

People subscribed via source and target branches