Mir

Merge lp:~alan-griffiths/mir/rework-integration_tests-test_surfaceloop.cpp into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 1705
Proposed branch: lp:~alan-griffiths/mir/rework-integration_tests-test_surfaceloop.cpp
Merge into: lp:mir
Prerequisite: lp:~alan-griffiths/mir/dont-leak-surfaces-on-disconnect
Diff against target: 399 lines (+52/-277)
1 file modified
tests/integration-tests/test_surfaceloop.cpp (+52/-277)
To merge this branch: bzr merge lp:~alan-griffiths/mir/rework-integration_tests-test_surfaceloop.cpp
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Kevin DuBois (community) Approve
Alexandros Frantzis (community) Approve
Review via email: mp+222946@code.launchpad.net

Commit message

tests: rework integration-tests/test_surfaceloop.cpp using BasicClientServerFixture

Description of the change

tests: rework integration-tests/test_surfaceloop.cpp using BasicClientServerFixture

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
Alan Griffiths (alan-griffiths) wrote :

Environment fixed. Rebuilding.

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)
Revision history for this message
Kevin DuBois (kdub) wrote :

lgtm, question though:
115 -TEST_F(SurfaceLoopDefault, creating_a_client_surface_gets_surface_of_requested_size)

this seems to be testing that the surface that is returned matches the request made, should it be ported to the new fixture? Seems somewhat like a half-baked test in the current form, but there could still be something like it with the new fixture

review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> lgtm, question though:
> 115 -TEST_F(SurfaceLoopDefault,
> creating_a_client_surface_gets_surface_of_requested_size)
>
> this seems to be testing that the surface that is returned matches the request
> made, should it be ported to the new fixture? Seems somewhat like a half-baked
> test in the current form, but there could still be something like it with the
> new fixture

I agree. It is "half baked" in its current form and, as the useful aspects are covered by TEST_F(ClientLibrary, creates_surface) in the acceptance tests, I didn't feel it worth preserving.

If you want it ported then vote "Needs Fixing". ;)

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

Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

[0;32m[ RUN ] GLMark2Test.benchmark_fullscreen_default
Segmentation fault (core dumped)
/tmp/buildd/mir-0.2.0bzr1700pkg0utopic1687+autopilot0/tests/performance-tests/test_glmark2-es2-mir.cpp:59: Failure
Value of: score.length()

Seems unrelated

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

> > lgtm, question though:
> > 115 -TEST_F(SurfaceLoopDefault,
> > creating_a_client_surface_gets_surface_of_requested_size)
> >
> > this seems to be testing that the surface that is returned matches the
> request
> > made, should it be ported to the new fixture? Seems somewhat like a half-
> baked
> > test in the current form, but there could still be something like it with
> the
> > new fixture
>
> I agree. It is "half baked" in its current form and, as the useful aspects are
> covered by TEST_F(ClientLibrary, creates_surface) in the acceptance tests, I
> didn't feel it worth preserving.
>
> If you want it ported then vote "Needs Fixing". ;)

I'm okay with not porting it, doesn't seem to add much to the coverage. +`

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) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/integration-tests/test_surfaceloop.cpp'
2--- tests/integration-tests/test_surfaceloop.cpp 2014-06-12 11:47:41 +0000
3+++ tests/integration-tests/test_surfaceloop.cpp 2014-06-17 09:35:49 +0000
4@@ -16,20 +16,17 @@
5 * Authored by: Alan Griffiths <alan@octopull.co.uk>
6 */
7
8-#include "mir/graphics/buffer_properties.h"
9-#include "mir/graphics/buffer_id.h"
10-#include "mir/graphics/buffer_basic.h"
11-#include "mir/graphics/display.h"
12-
13 #include "mir_toolkit/mir_client_library.h"
14
15-#include "mir_test_framework/display_server_test_fixture.h"
16 #include "mir_test_doubles/stub_buffer.h"
17 #include "mir_test_doubles/stub_buffer_allocator.h"
18 #include "mir_test_doubles/null_platform.h"
19 #include "mir_test_doubles/null_display.h"
20 #include "mir_test_doubles/stub_display_buffer.h"
21
22+#include "mir_test_framework/stubbed_server_configuration.h"
23+#include "mir_test_framework/basic_client_server_fixture.h"
24+
25 #include <thread>
26 #include <atomic>
27 #include <mutex>
28@@ -47,8 +44,6 @@
29
30 namespace
31 {
32-char const* const mir_test_socket = mtf::test_socket_file().c_str();
33-
34 geom::Size const size{640, 480};
35 MirPixelFormat const format{mir_pixel_format_abgr_8888};
36 mg::BufferUsage const usage{mg::BufferUsage::hardware};
37@@ -78,13 +73,6 @@
38 ~MockGraphicBufferAllocator() noexcept {}
39 };
40
41-}
42-
43-namespace mir
44-{
45-namespace
46-{
47-
48 class StubDisplay : public mtd::NullDisplay
49 {
50 public:
51@@ -104,11 +92,6 @@
52
53 struct SurfaceSync
54 {
55- SurfaceSync() :
56- surface(0)
57- {
58- }
59-
60 void surface_created(MirSurface * new_surface)
61 {
62 std::unique_lock<std::mutex> lock(guard);
63@@ -126,40 +109,20 @@
64 void wait_for_surface_create()
65 {
66 std::unique_lock<std::mutex> lock(guard);
67- while (!surface)
68- wait_condition.wait(lock);
69+ wait_condition.wait(lock, [&]{ return !!surface; });
70 }
71
72 void wait_for_surface_release()
73 {
74 std::unique_lock<std::mutex> lock(guard);
75- while (surface)
76- wait_condition.wait(lock);
77+ wait_condition.wait(lock, [&]{ return !surface; });
78 }
79
80-
81 std::mutex guard;
82 std::condition_variable wait_condition;
83- MirSurface * surface;
84-};
85-
86-struct ClientConfigCommon : TestingClientConfiguration
87-{
88- static const int max_surface_count = 5;
89- SurfaceSync ssync[max_surface_count];
90-};
91-const int ClientConfigCommon::max_surface_count;
92-}
93-}
94-
95-using SurfaceLoop = BespokeDisplayServerTestFixture;
96-using SurfaceLoopDefault = DefaultDisplayServerTestFixture;
97-using mir::SurfaceSync;
98-using mir::ClientConfigCommon;
99-using mir::StubDisplay;
100-
101-namespace
102-{
103+ MirSurface * surface{nullptr};
104+};
105+
106 void create_surface_callback(MirSurface* surface, void * context)
107 {
108 SurfaceSync* config = reinterpret_cast<SurfaceSync*>(context);
109@@ -181,152 +144,8 @@
110 {
111 context->wait_for_surface_release();
112 }
113-}
114-
115-TEST_F(SurfaceLoopDefault, creating_a_client_surface_gets_surface_of_requested_size)
116-{
117- struct ClientConfig : TestingClientConfiguration
118- {
119- void exec()
120- {
121- auto const connection = mir_connect_sync(mir_test_socket, __PRETTY_FUNCTION__);
122-
123- ASSERT_TRUE(connection != NULL);
124- EXPECT_TRUE(mir_connection_is_valid(connection));
125- EXPECT_STREQ(mir_connection_get_error_message(connection), "");
126-
127- MirSurfaceParameters const request_params =
128- {
129- __PRETTY_FUNCTION__,
130- 640, 480,
131- mir_pixel_format_abgr_8888,
132- mir_buffer_usage_hardware,
133- mir_display_output_id_invalid
134- };
135-
136- auto const surface = mir_connection_create_surface_sync(connection, &request_params);
137-
138- ASSERT_TRUE(surface != NULL);
139- EXPECT_TRUE(mir_surface_is_valid(surface));
140- EXPECT_STREQ(mir_surface_get_error_message(surface), "");
141-
142- MirSurfaceParameters response_params;
143- mir_surface_get_parameters(surface, &response_params);
144- EXPECT_EQ(request_params.width, response_params.width);
145- EXPECT_EQ(request_params.height, response_params.height);
146- EXPECT_EQ(request_params.pixel_format, response_params.pixel_format);
147- EXPECT_EQ(request_params.buffer_usage, response_params.buffer_usage);
148-
149- mir_surface_release_sync(surface);
150- mir_connection_release(connection);
151- }
152- } client_config;
153-
154- launch_client_process(client_config);
155-}
156-
157-namespace
158-{
159-
160-/*
161- * Need to declare outside method, because g++ 4.4 doesn't support local types
162- * as template parameters (in std::make_shared<StubPlatform>()).
163- */
164-struct ServerConfigAllocatesBuffersOnServer : TestingServerConfiguration
165-{
166- class StubPlatform : public mtd::NullPlatform
167- {
168- public:
169- std::shared_ptr<mg::GraphicBufferAllocator> create_buffer_allocator(
170- const std::shared_ptr<mg::BufferInitializer>& /*buffer_initializer*/) override
171- {
172- using testing::AtMost;
173-
174- auto buffer_allocator = std::make_shared<testing::NiceMock<MockGraphicBufferAllocator>>();
175- EXPECT_CALL(*buffer_allocator, alloc_buffer(buffer_properties))
176- .Times(AtMost(3));
177- return buffer_allocator;
178- }
179-
180- std::shared_ptr<mg::Display> create_display(
181- std::shared_ptr<mg::DisplayConfigurationPolicy> const&,
182- std::shared_ptr<mg::GLProgramFactory> const&,
183- std::shared_ptr<mg::GLConfig> const&) override
184- {
185- return std::make_shared<StubDisplay>();
186- }
187- };
188-
189- std::shared_ptr<mg::Platform> the_graphics_platform()
190- {
191- if (!platform)
192- platform = std::make_shared<StubPlatform>();
193-
194- return platform;
195- }
196-
197- std::shared_ptr<mg::Platform> platform;
198-};
199-
200-}
201-
202-TEST_F(SurfaceLoop, creating_a_client_surface_allocates_buffers_on_server)
203-{
204-
205- ServerConfigAllocatesBuffersOnServer server_config;
206-
207- launch_server_process(server_config);
208-
209- struct ClientConfig : ClientConfigCommon
210- {
211- void exec()
212- {
213- auto connection = mir_connect_sync(mir_test_socket, __PRETTY_FUNCTION__);
214-
215- ASSERT_TRUE(connection != NULL);
216- EXPECT_TRUE(mir_connection_is_valid(connection));
217- EXPECT_STREQ(mir_connection_get_error_message(connection), "");
218-
219- MirSurfaceParameters const request_params =
220- {
221- __PRETTY_FUNCTION__,
222- 640, 480,
223- mir_pixel_format_abgr_8888,
224- mir_buffer_usage_hardware,
225- mir_display_output_id_invalid
226- };
227- mir_connection_create_surface(connection, &request_params, create_surface_callback, ssync);
228-
229- wait_for_surface_create(ssync);
230-
231- ASSERT_TRUE(ssync->surface != NULL);
232- EXPECT_TRUE(mir_surface_is_valid(ssync->surface));
233- EXPECT_STREQ(mir_surface_get_error_message(ssync->surface), "");
234-
235- MirSurfaceParameters response_params;
236- mir_surface_get_parameters(ssync->surface, &response_params);
237- EXPECT_EQ(request_params.width, response_params.width);
238- EXPECT_EQ(request_params.height, response_params.height);
239- EXPECT_EQ(request_params.pixel_format, response_params.pixel_format);
240- EXPECT_EQ(request_params.buffer_usage, response_params.buffer_usage);
241-
242-
243- mir_surface_release(ssync->surface, release_surface_callback, ssync);
244-
245- wait_for_surface_release(ssync);
246-
247- ASSERT_TRUE(ssync->surface == NULL);
248-
249- mir_connection_release(connection);
250- }
251- } client_config;
252-
253- launch_client_process(client_config);
254-}
255-
256-namespace
257-{
258-struct BufferCounterConfig : TestingServerConfiguration
259+
260+struct BufferCounterConfig : mtf::StubbedServerConfiguration
261 {
262 class CountingStubBuffer : public mtd::StubBuffer
263 {
264@@ -389,93 +208,49 @@
265 std::atomic<int> BufferCounterConfig::CountingStubBuffer::buffers_destroyed;
266 }
267
268-
269-TEST_F(SurfaceLoop, all_created_buffers_are_destoyed)
270-{
271- struct ServerConfig : BufferCounterConfig
272- {
273- void on_exit() override
274- {
275- EXPECT_EQ(CountingStubBuffer::buffers_created.load(),
276- CountingStubBuffer::buffers_destroyed.load());
277- }
278-
279- } server_config;
280-
281- launch_server_process(server_config);
282-
283- struct Client : ClientConfigCommon
284- {
285- void exec() override
286- {
287- auto connection = mir_connect_sync(mir_test_socket, __PRETTY_FUNCTION__);
288-
289- MirSurfaceParameters const request_params =
290- {
291- __PRETTY_FUNCTION__,
292- 640, 480,
293- mir_pixel_format_abgr_8888,
294- mir_buffer_usage_hardware,
295- mir_display_output_id_invalid
296- };
297-
298- for (int i = 0; i != max_surface_count; ++i)
299- mir_connection_create_surface(connection, &request_params, create_surface_callback, ssync+i);
300-
301- for (int i = 0; i != max_surface_count; ++i)
302- wait_for_surface_create(ssync+i);
303-
304- for (int i = 0; i != max_surface_count; ++i)
305- mir_surface_release(ssync[i].surface, release_surface_callback, ssync+i);
306-
307- for (int i = 0; i != max_surface_count; ++i)
308- wait_for_surface_release(ssync+i);
309-
310- mir_connection_release(connection);
311- }
312- } client_creates_surfaces;
313-
314- launch_client_process(client_creates_surfaces);
315+struct SurfaceLoop : mtf::BasicClientServerFixture<BufferCounterConfig>
316+{
317+ static const int max_surface_count = 5;
318+ SurfaceSync ssync[max_surface_count];
319+
320+ MirSurfaceParameters const request_params
321+ {
322+ "Arbitrary surface name",
323+ 640, 480,
324+ mir_pixel_format_abgr_8888,
325+ mir_buffer_usage_hardware,
326+ mir_display_output_id_invalid
327+ };
328+
329+ void TearDown() override
330+ {
331+ mtf::BasicClientServerFixture<BufferCounterConfig>::TearDown();
332+
333+ EXPECT_EQ(BufferCounterConfig::CountingStubBuffer::buffers_created.load(),
334+ BufferCounterConfig::CountingStubBuffer::buffers_destroyed.load());
335+ }
336+};
337+
338+TEST_F(SurfaceLoop, all_created_buffers_are_destroyed)
339+{
340+ for (int i = 0; i != max_surface_count; ++i)
341+ mir_connection_create_surface(connection, &request_params, create_surface_callback, ssync+i);
342+
343+ for (int i = 0; i != max_surface_count; ++i)
344+ wait_for_surface_create(ssync+i);
345+
346+ for (int i = 0; i != max_surface_count; ++i)
347+ mir_surface_release(ssync[i].surface, release_surface_callback, ssync+i);
348+
349+ for (int i = 0; i != max_surface_count; ++i)
350+ wait_for_surface_release(ssync+i);
351 }
352
353-TEST_F(SurfaceLoop, all_created_buffers_are_destoyed_if_client_disconnects_without_releasing_surfaces)
354+TEST_F(SurfaceLoop, all_created_buffers_are_destroyed_if_client_disconnects_without_releasing_surfaces)
355 {
356- struct ServerConfig : BufferCounterConfig
357- {
358- void on_exit() override
359- {
360- EXPECT_EQ(CountingStubBuffer::buffers_created.load(),
361- CountingStubBuffer::buffers_destroyed.load());
362- }
363-
364- } server_config;
365-
366- launch_server_process(server_config);
367-
368- struct Client : ClientConfigCommon
369- {
370- void exec() override
371- {
372- auto connection = mir_connect_sync(mir_test_socket, __PRETTY_FUNCTION__);
373-
374- MirSurfaceParameters const request_params =
375- {
376- __PRETTY_FUNCTION__,
377- 640, 480,
378- mir_pixel_format_abgr_8888,
379- mir_buffer_usage_hardware,
380- mir_display_output_id_invalid
381- };
382-
383- for (int i = 0; i != max_surface_count; ++i)
384- mir_connection_create_surface(connection, &request_params, create_surface_callback, ssync+i);
385-
386- for (int i = 0; i != max_surface_count; ++i)
387- wait_for_surface_create(ssync+i);
388-
389- mir_connection_release(connection);
390- }
391- } client_creates_surfaces;
392-
393- launch_client_process(client_creates_surfaces);
394+ for (int i = 0; i != max_surface_count; ++i)
395+ mir_connection_create_surface(connection, &request_params, create_surface_callback, ssync+i);
396+
397+ for (int i = 0; i != max_surface_count; ++i)
398+ wait_for_surface_create(ssync+i);
399 }

Subscribers

People subscribed via source and target branches