Mir

Merge lp:~raof/mir/client-release-simplifications into lp:mir

Proposed by Chris Halse Rogers
Status: Work in progress
Proposed branch: lp:~raof/mir/client-release-simplifications
Merge into: lp:mir
Diff against target: 352 lines (+122/-59)
8 files modified
include/test/mir/test/validity_matchers.h (+8/-0)
src/client/atomic_callback.h (+15/-10)
src/client/mir_buffer_stream_api.cpp (+8/-1)
src/client/mir_connection.cpp (+11/-46)
src/client/mir_connection.h (+0/-2)
tests/acceptance-tests/staging/test_render_surface.cpp (+45/-0)
tests/mir_test/CMakeLists.txt (+4/-0)
tests/mir_test/validity_matchers.cpp (+31/-0)
To merge this branch: bzr merge lp:~raof/mir/client-release-simplifications
Reviewer Review Type Date Requested Status
Cemil Azizoglu (community) Needs Fixing
Andreas Pokorny (community) Approve
Mir CI Bot continuous-integration Needs Fixing
Review via email: mp+312995@code.launchpad.net

Commit message

Simplify the release operations for RenderSurface, BufferStream, and PresentationChain.

None of these require waiting for the server to acknowledge release, so don't.

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:3879
https://mir-jenkins.ubuntu.com/job/mir-ci/2371/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/3091/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/3158
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/3150
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/3150
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/3150
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3120/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3120
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3120/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3120
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3120/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3120
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3120/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3120
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3120/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3120
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3120/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/2371/rebuild

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

07:40:09 /<<BUILDDIR>>/mir-0.25.0+yakkety3150bzr3879/src/client/mir_buffer_stream_api.cpp:97:5: error: no matching function for call to 'mir_buffer_stream_release'
07:40:09 mir_buffer_stream_release(buffer_stream, [](auto, auto){}, nullptr);
07:40:09 ^~~~~~~~~~~~~~~~~~~~~~~~~
07:40:09 /<<BUILDDIR>>/mir-0.25.0+yakkety3150bzr3879/src/client/mir_buffer_stream_api.cpp:86:16: note: candidate function not viable: no known conversion from '(lambda at /<<BUILDDIR>>/mir-0.25.0+yakkety3150bzr3879/src/client/mir_buffer_stream_api.cpp:97:46)' to 'mir_buffer_stream_callback' (aka 'void (*)(MirBufferStream *, void *)') for 2nd argument
07:40:09 MirWaitHandle* mir_buffer_stream_release(
07:40:09 ^
07:40:09 1 error generated.

Guess Yakkety isn't as up to date as the code. :(

3880. By Chris Halse Rogers

Try hand-holding Yakkety compilers

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:3880
https://mir-jenkins.ubuntu.com/job/mir-ci/2380/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/3102/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/3169
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/3161
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/3161
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/3161
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3131/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3131
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3131/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3131
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3131/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3131
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3131/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3131
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3131/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3131
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3131/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/2380/rebuild

review: Needs Fixing (continuous-integration)
3881. By Chris Halse Rogers

Merge trunk

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:3881
https://mir-jenkins.ubuntu.com/job/mir-ci/2383/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/3107/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/3174
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/3166
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/3166
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/3166
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3136
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/3136/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3136
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/3136/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/3136/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3136
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/3136/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3136
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/3136/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3136
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/3136/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/2383/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

This looks like the right thing to do.

But you also need to update the mir_buffer_stream_release in:

include/client/mir_toolkit/mir_buffer_stream.h

review: Approve
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

In this case, it no longer makes sense to have mir_buffer_stream_release_sync() so this should be deprecated. The mir_buffer_stream_release() should no longer have the callback and the context parameters (in other words, mir_buffer_stream_release_sync() should become mir_buffer_stream_release()).

The callback can then be eliminated.
169 + callback(stream, context);

I'm ok with following this up in another MP due to compatibility concerns. If you can make a note of this deprecation in alberto's client-api-deprecation branch, consider this approved.

review: Needs Fixing
Revision history for this message
Chris Halse Rogers (raof) wrote :

Ok, so this is actually hilariously unsafe because BufferVault, despite being full of locking, will fall over hilariously if you try to call functions from different threads.

I still think this is the right thing to do, but I need some more infrastructure to do it.

Unmerged revisions

3881. By Chris Halse Rogers

Merge trunk

3880. By Chris Halse Rogers

Try hand-holding Yakkety compilers

3879. By Chris Halse Rogers

Remove now-vestigial MirConnection::StreamRelease and ::released

3878. By Chris Halse Rogers

Eagerly destroy MirPresentationChain resources in _release()

Just like MirBufferStream and MirRenderSurface, there's no need to wait for the
server to acknowledge.

3877. By Chris Halse Rogers

Eagerly destroy MirBufferStream resources in _release()

Like MirRenderSurface, there's nothing to do client-side after sending the
release RPC message. Simplify things by deleting up-front.

3876. By Chris Halse Rogers

Fix unsafe locking in AtomicCallback.

AtomicCallback was calling the underlying callback while holding a lock. Someone
clearly knew this was a bad idea, because they changed it to a std::recursive_mutex,
but that's not the only way this could deadlock.

Since I've just seen a deadlock caused by this, fix it :)

3875. By Chris Halse Rogers

Eagerly destroy RenderSurface resources in _release()

There's no need to wait for the server to acknowledge our RPC request.
The client-side never uses any of the RenderSurface resources after sending
the release request, and there's no meaningfull error handling possible.

3874. By Chris Halse Rogers

Add IsValid() implementations for MirBufferStream and MirRenderSurface

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/test/mir/test/validity_matchers.h'
--- include/test/mir/test/validity_matchers.h 2016-01-29 08:18:22 +0000
+++ include/test/mir/test/validity_matchers.h 2016-12-13 05:39:59 +0000
@@ -23,6 +23,8 @@
2323
24#include "mir_toolkit/mir_client_library.h"24#include "mir_toolkit/mir_client_library.h"
2525
26class MirRenderSurface;
27
26using ::testing::MakePolymorphicMatcher;28using ::testing::MakePolymorphicMatcher;
27using ::testing::MatchResultListener;29using ::testing::MatchResultListener;
28using ::testing::NotNull;30using ::testing::NotNull;
@@ -54,6 +56,12 @@
54template<>56template<>
55bool IsValidMatcher::MatchAndExplain(MirSurface* surface, MatchResultListener* listener) const;57bool IsValidMatcher::MatchAndExplain(MirSurface* surface, MatchResultListener* listener) const;
5658
59template<>
60bool IsValidMatcher::MatchAndExplain(MirBufferStream* stream, MatchResultListener* listener) const;
61
62template<>
63bool IsValidMatcher::MatchAndExplain(MirRenderSurface* stream, MatchResultListener* listener) const;
64
57// To construct a polymorphic matcher, pass an instance of the class65// To construct a polymorphic matcher, pass an instance of the class
58// to MakePolymorphicMatcher(). Note the return type.66// to MakePolymorphicMatcher(). Note the return type.
59inline PolymorphicMatcher<IsValidMatcher> IsValid()67inline PolymorphicMatcher<IsValidMatcher> IsValid()
6068
=== modified file 'src/client/atomic_callback.h'
--- src/client/atomic_callback.h 2016-12-01 19:18:27 +0000
+++ src/client/atomic_callback.h 2016-12-13 05:39:59 +0000
@@ -19,6 +19,7 @@
19#ifndef MIR_CLIENT_ATOMIC_CALLBACK_H_19#ifndef MIR_CLIENT_ATOMIC_CALLBACK_H_
20#define MIR_CLIENT_ATOMIC_CALLBACK_H_20#define MIR_CLIENT_ATOMIC_CALLBACK_H_
2121
22#include <memory>
22#include <functional>23#include <functional>
23#include <mutex>24#include <mutex>
2425
@@ -31,12 +32,12 @@
31{32{
32public:33public:
33 AtomicCallback()34 AtomicCallback()
34 : callback{[](Args...){}}35 : AtomicCallback([](Args...){})
35 {36 {
36 }37 }
3738
38 AtomicCallback(std::function<void(Args...)> const& fn)39 AtomicCallback(std::function<void(Args...)> const& fn)
39 : callback(fn)40 : callback{std::make_shared<std::function<void(Args...)>>(fn)}
40 {41 {
41 }42 }
4243
@@ -44,21 +45,25 @@
4445
45 void set_callback(std::function<void(Args...)> const& fn)46 void set_callback(std::function<void(Args...)> const& fn)
46 {47 {
47 std::lock_guard<std::recursive_mutex> lk(guard);48 std::lock_guard<std::mutex> lock{mutex};
4849 callback = std::make_shared<std::function<void(Args...)>>(fn);
49 callback = fn;
50 }50 }
5151
52 void operator()(Args&&... args) const52 void operator()(Args&&... args) const
53 {53 {
54 std::lock_guard<std::recursive_mutex> lk(guard);54 decltype(callback) callback_copy;
5555
56 callback(std::forward<Args>(args)...);56 {
57 std::lock_guard<std::mutex> lock{mutex};
58 callback_copy = callback;
59 }
60
61 (*callback)(std::forward<Args>(args)...);
57 }62 }
5863
59private:64private:
60 std::recursive_mutex mutable guard;65 std::mutex mutable mutex;
61 std::function<void(Args...)> callback;66 std::shared_ptr<std::function<void(Args...)>> callback;
62};67};
63}68}
64}69}
6570
=== modified file 'src/client/mir_buffer_stream_api.cpp'
--- src/client/mir_buffer_stream_api.cpp 2016-12-12 03:34:50 +0000
+++ src/client/mir_buffer_stream_api.cpp 2016-12-13 05:39:59 +0000
@@ -92,9 +92,16 @@
92 return connection->release_buffer_stream(buffer_stream, callback, context);92 return connection->release_buffer_stream(buffer_stream, callback, context);
93}93}
9494
95namespace
96{
97void ignored_callback(MirBufferStream*, void*)
98{
99}
100}
101
95void mir_buffer_stream_release_sync(MirBufferStream *buffer_stream)102void mir_buffer_stream_release_sync(MirBufferStream *buffer_stream)
96{103{
97 mir_buffer_stream_release(buffer_stream, nullptr, nullptr)->wait_for_all();104 mir_buffer_stream_release(buffer_stream, &ignored_callback, nullptr);
98}105}
99106
100void mir_buffer_stream_get_current_buffer(MirBufferStream* buffer_stream, MirNativeBuffer** buffer_package_out)107void mir_buffer_stream_get_current_buffer(MirBufferStream* buffer_stream, MirNativeBuffer** buffer_package_out)
101108
=== modified file 'src/client/mir_connection.cpp'
--- src/client/mir_connection.cpp 2016-12-12 11:43:17 +0000
+++ src/client/mir_connection.cpp 2016-12-13 05:39:59 +0000
@@ -463,31 +463,6 @@
463 void* context;463 void* context;
464};464};
465465
466struct MirConnection::StreamRelease
467{
468 MirBufferStream* stream;
469 MirWaitHandle* handle;
470 mir_buffer_stream_callback callback;
471 void* context;
472 int rpc_id;
473 void* rs;
474};
475
476void MirConnection::released(StreamRelease data)
477{
478 if (data.callback)
479 data.callback(data.stream, data.context);
480 if (data.handle)
481 data.handle->result_received();
482
483 {
484 std::unique_lock<decltype(mutex)> lk(mutex);
485 if (data.rs)
486 surface_map->erase(data.rs);
487 surface_map->erase(mf::BufferStreamId(data.rpc_id));
488 }
489}
490
491void MirConnection::released(SurfaceRelease data)466void MirConnection::released(SurfaceRelease data)
492{467{
493 data.callback(data.surface, data.context);468 data.callback(data.surface, data.context);
@@ -1143,23 +1118,17 @@
1143 mir_buffer_stream_callback callback,1118 mir_buffer_stream_callback callback,
1144 void *context)1119 void *context)
1145{1120{
1146 auto new_wait_handle = new MirWaitHandle;
1147
1148 StreamRelease stream_release{stream, new_wait_handle, callback, context, stream->rpc_id().as_value(), nullptr };
1149
1150 mp::BufferStreamId buffer_stream_id;1121 mp::BufferStreamId buffer_stream_id;
1151 buffer_stream_id.set_value(stream->rpc_id().as_value());1122 buffer_stream_id.set_value(stream->rpc_id().as_value());
11521123
1153 {1124 surface_map->erase(mf::BufferStreamId{stream->rpc_id().as_value()});
1154 std::lock_guard<decltype(release_wait_handle_guard)> rel_lock(release_wait_handle_guard);
1155 release_wait_handles.push_back(new_wait_handle);
1156 }
11571125
1158 new_wait_handle->expect_result();
1159 server.release_buffer_stream(1126 server.release_buffer_stream(
1160 &buffer_stream_id, void_response.get(),1127 &buffer_stream_id, void_response.get(),
1161 google::protobuf::NewCallback(this, &MirConnection::released, stream_release));1128 google::protobuf::NewCallback(&google::protobuf::DoNothing));
1162 return new_wait_handle;1129
1130 callback(stream, context);
1131 return nullptr;
1163}1132}
11641133
1165void MirConnection::release_consumer_stream(MirBufferStream* stream)1134void MirConnection::release_consumer_stream(MirBufferStream* stream)
@@ -1282,12 +1251,12 @@
1282 auto id = chain->rpc_id();1251 auto id = chain->rpc_id();
1283 if (id >= 0)1252 if (id >= 0)
1284 {1253 {
1285 StreamRelease stream_release{nullptr, nullptr, nullptr, nullptr, chain->rpc_id(), nullptr};
1286 mp::BufferStreamId buffer_stream_id;1254 mp::BufferStreamId buffer_stream_id;
1287 buffer_stream_id.set_value(chain->rpc_id());1255 buffer_stream_id.set_value(chain->rpc_id());
1256 surface_map->erase(mf::BufferStreamId{chain->rpc_id()});
1288 server.release_buffer_stream(1257 server.release_buffer_stream(
1289 &buffer_stream_id, void_response.get(),1258 &buffer_stream_id, void_response.get(),
1290 google::protobuf::NewCallback(this, &MirConnection::released, stream_release));1259 google::protobuf::NewCallback(&google::protobuf::DoNothing));
1291 }1260 }
1292 else1261 else
1293 {1262 {
@@ -1335,19 +1304,15 @@
1335{1304{
1336 auto rs = surface_map->render_surface(render_surface);1305 auto rs = surface_map->render_surface(render_surface);
13371306
1338 StreamRelease stream_release{nullptr,
1339 nullptr,
1340 nullptr,
1341 nullptr,
1342 rs->stream_id().as_value(),
1343 render_surface};
1344
1345 mp::BufferStreamId buffer_stream_id;1307 mp::BufferStreamId buffer_stream_id;
1346 buffer_stream_id.set_value(rs->stream_id().as_value());1308 buffer_stream_id.set_value(rs->stream_id().as_value());
13471309
1310 surface_map->erase(mf::BufferStreamId(rs->stream_id().as_value()));
1311 surface_map->erase(render_surface);
1312
1348 server.release_buffer_stream(1313 server.release_buffer_stream(
1349 &buffer_stream_id, void_response.get(),1314 &buffer_stream_id, void_response.get(),
1350 google::protobuf::NewCallback(this, &MirConnection::released, stream_release));1315 google::protobuf::NewCallback(&google::protobuf::DoNothing));
1351}1316}
13521317
1353void MirConnection::render_surface_created(RenderSurfaceCreationRequest* request_raw)1318void MirConnection::render_surface_created(RenderSurfaceCreationRequest* request_raw)
13541319
=== modified file 'src/client/mir_connection.h'
--- src/client/mir_connection.h 2016-12-12 11:43:17 +0000
+++ src/client/mir_connection.h 2016-12-13 05:39:59 +0000
@@ -376,7 +376,6 @@
376 376
377377
378 struct SurfaceRelease;378 struct SurfaceRelease;
379 struct StreamRelease;
380379
381 MirConnection* next_valid{nullptr};380 MirConnection* next_valid{nullptr};
382381
@@ -384,7 +383,6 @@
384 void done_disconnect();383 void done_disconnect();
385 void connected(mir_connected_callback callback, void * context);384 void connected(mir_connected_callback callback, void * context);
386 void released(SurfaceRelease);385 void released(SurfaceRelease);
387 void released(StreamRelease);
388 void done_platform_operation(mir_platform_operation_callback, void* context);386 void done_platform_operation(mir_platform_operation_callback, void* context);
389 bool validate_user_display_config(MirDisplayConfiguration const* config);387 bool validate_user_display_config(MirDisplayConfiguration const* config);
390388
391389
=== modified file 'tests/acceptance-tests/staging/test_render_surface.cpp'
--- tests/acceptance-tests/staging/test_render_surface.cpp 2016-12-12 21:58:01 +0000
+++ tests/acceptance-tests/staging/test_render_surface.cpp 2016-12-13 05:39:59 +0000
@@ -25,6 +25,7 @@
25#include "mir_test_framework/using_stub_client_platform.h"25#include "mir_test_framework/using_stub_client_platform.h"
26#include "mir/test/validity_matchers.h"26#include "mir/test/validity_matchers.h"
2727
28#include <atomic>
28#include <gtest/gtest.h>29#include <gtest/gtest.h>
29#include <gmock/gmock.h>30#include <gmock/gmock.h>
3031
@@ -316,3 +317,47 @@
316 mir_render_surface_release(rs);317 mir_render_surface_release(rs);
317 mir_connection_release(connection);318 mir_connection_release(connection);
318}319}
320
321TEST_F(RenderSurfaceTest, buffer_stream_callback_isnt_called_after_render_surface_release)
322{
323 auto connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__);
324
325 auto rs = mir_connection_create_render_surface_sync(
326 connection, logical_size.width.as_int(), logical_size.height.as_int());
327
328 auto determine_physical_size = [](MirRenderSurface* rs) -> geom::Size
329 {
330 int width = -1;
331 int height = -1;
332 mir_render_surface_get_size(rs, &width, &height);
333 return {width, height};
334 };
335 auto physical_size = determine_physical_size(rs);
336 auto bs = mir_render_surface_get_buffer_stream(
337 rs,
338 physical_size.width.as_int(), physical_size.height.as_int(),
339 mir_pixel_format_abgr_8888,
340 mir_buffer_usage_hardware);
341
342 EXPECT_THAT(bs, IsValid());
343
344 std::atomic<bool> called{false};
345 mir_buffer_stream_swap_buffers(
346 bs,
347 [](MirBufferStream*, void* called)
348 {
349 *reinterpret_cast<std::atomic<bool>*>(called) = true;
350 },
351 &called);
352
353 // Unavoidably racy; we want to test that the swap_buffers callback is never called
354 // after mir_render_surface_release returns.
355 mir_render_surface_release(rs);
356 bool called_post_release = called.load();
357
358 mir_connection_release(connection);
359
360 // We don't care whether or the swap_buffers callback was called, just that
361 // it didn't get called *after* mir_render_surface_release.
362 EXPECT_THAT(called, Eq(called_post_release));
363}
319364
=== modified file 'tests/mir_test/CMakeLists.txt'
--- tests/mir_test/CMakeLists.txt 2016-11-09 02:30:14 +0000
+++ tests/mir_test/CMakeLists.txt 2016-12-13 05:39:59 +0000
@@ -2,6 +2,10 @@
2string (REPLACE " -flto " " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS})2string (REPLACE " -flto " " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
3string (REPLACE " -flto " " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})3string (REPLACE " -flto " " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
44
5include_directories(
6 ${PROJECT_SOURCE_DIR}/src/include/client
7)
8
5add_library(mir-public-test OBJECT9add_library(mir-public-test OBJECT
6 cross_process_action.cpp10 cross_process_action.cpp
7 cross_process_sync.cpp11 cross_process_sync.cpp
812
=== modified file 'tests/mir_test/validity_matchers.cpp'
--- tests/mir_test/validity_matchers.cpp 2015-06-25 03:00:08 +0000
+++ tests/mir_test/validity_matchers.cpp 2016-12-13 05:39:59 +0000
@@ -1,5 +1,6 @@
1#include "mir/test/validity_matchers.h"1#include "mir/test/validity_matchers.h"
2#include "mir_toolkit/mir_client_library.h"2#include "mir_toolkit/mir_client_library.h"
3#include "mir_toolkit/mir_render_surface.h"
34
4template<>5template<>
5bool IsValidMatcher::MatchAndExplain(MirConnection* connection, MatchResultListener* listener) const6bool IsValidMatcher::MatchAndExplain(MirConnection* connection, MatchResultListener* listener) const
@@ -30,3 +31,33 @@
30 }31 }
31 return true;32 return true;
32}33}
34
35template<>
36bool IsValidMatcher::MatchAndExplain(MirBufferStream* stream, MatchResultListener* listener) const
37{
38 if (stream == nullptr)
39 {
40 return false;
41 }
42 if (!mir_buffer_stream_is_valid(stream))
43 {
44 *listener << "error is: " << mir_buffer_stream_get_error_message(stream);
45 return false;
46 }
47 return true;
48}
49
50template<>
51bool IsValidMatcher::MatchAndExplain(MirRenderSurface* rs, MatchResultListener* listener) const
52{
53 if (rs == nullptr)
54 {
55 return false;
56 }
57 if (!mir_render_surface_is_valid(rs))
58 {
59 *listener << "error is: " << mir_render_surface_get_error_message(rs);
60 return false;
61 }
62 return true;
63}

Subscribers

People subscribed via source and target branches